X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=xmpp.c;h=283c68a4026a30be62b9a117a9c7d3ea7e9ac1eb;hb=1737bf08fa42284aa1a1c388594267b3b92fb0ec;hp=a6a0a09a60788e02d5667bee29bcf8644452a425;hpb=fda5401ec167ff1f13aabe4fa0bba5e788ee7cd7;p=cascardo%2Fchat.git diff --git a/xmpp.c b/xmpp.c index a6a0a09..283c68a 100644 --- a/xmpp.c +++ b/xmpp.c @@ -18,19 +18,26 @@ #include +#include +#include #include "xmpp.h" #include "xmpp_internal.h" #include "iksemel_extra.h" +#include "tcp_connect.h" hc_xmpp_t * -hc_xmpp_new (iksStreamHook *hook, char *server) +hc_xmpp_new (iksStreamHook *hook, char *server, char *user, char *pass) { hc_xmpp_t *xmpp = malloc (sizeof (hc_xmpp_t)); xmpp->server = strdup (server); + xmpp->user = strdup (user); + xmpp->password = strdup (pass); xmpp->parser = iks_extra_stream_new (xmpp, hook); + gsasl_init (&xmpp->sasl_ctx); xmpp->fd = hc_tcp_connect (server, "xmpp-client"); xmpp->tls = NONE; xmpp->sasl = NONE; + xmpp->status = HC_XMPP_NONE; return xmpp; } @@ -82,3 +89,63 @@ hc_xmpp_is_sasl_enabled (hc_xmpp_t *xmpp) return xmpp->sasl & ENABLED; } +int +hc_xmpp_is_bind_supported (hc_xmpp_t *xmpp) +{ + return xmpp->bind & SUPPORTED; +} + +int +hc_xmpp_is_session_supported (hc_xmpp_t *xmpp) +{ + return xmpp->session & SUPPORTED; +} + +int +hc_xmpp_is_session_required (hc_xmpp_t *xmpp) +{ + return xmpp->session & REQUIRED; +} + +char * +hc_xmpp_server (hc_xmpp_t *xmpp) +{ + return xmpp->server; +} + +int +hc_xmpp_fd (hc_xmpp_t *xmpp) +{ + return xmpp->fd; +} + +void +hc_xmpp_send_buffer (hc_xmpp_t *xmpp, char *buffer, size_t len) +{ + if (len == 0) + len = strlen (buffer); + write (xmpp->fd, buffer, len); +} + +void +hc_xmpp_send_iks (hc_xmpp_t *xmpp, iks *x) +{ + char *str; + str = iks_string (iks_stack (x), x); + write (xmpp->fd, str, strlen (str)); +} + +void +hc_xmpp_read_and_parse (hc_xmpp_t *xmpp) +{ + char buffer[4096]; + int r; + r = read (xmpp->fd, buffer, sizeof (buffer)); + iks_parse (xmpp->parser, buffer, r, 0); +} + +int +hc_xmpp_status (hc_xmpp_t *xmpp) +{ + return xmpp->status; +}