#include <stdlib.h>
+#include <string.h>
+#include <gsasl.h>
#include "xmpp.h"
#include "xmpp_internal.h"
+#include "iksemel_extra.h"
+#include "tcp_connect.h"
hc_xmpp_t *
-hc_xmpp_new (void)
+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;
+ xmpp->msghook = NULL;
+ xmpp->nshooks = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_insert (xmpp->nshooks, HC_XMPP_NS_BIND, hc_xmpp_hook_bind);
+ g_hash_table_insert (xmpp->nshooks, HC_XMPP_NS_SESSION, hc_xmpp_hook_session);
+ g_hash_table_insert (xmpp->nshooks, HC_XMPP_NS_DISCO_INFO,
+ hc_xmpp_hook_disco);
return 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;
+}
+
+void
+hc_xmpp_register_ns_hook (hc_xmpp_t *xmpp, char *ns, hc_xmpp_hook_t hook)
+{
+ g_hash_table_insert (xmpp->nshooks, ns, hook);
+}
+
+void
+hc_xmpp_set_msg_hook (hc_xmpp_t *xmpp, hc_xmpp_hook_t hook)
+{
+ xmpp->msghook = hook;
+}
+
+void
+hc_xmpp_recv_message (hc_xmpp_t *xmpp, iks *stanza)
+{
+ if (xmpp->msghook)
+ xmpp->msghook (xmpp, stanza);
+}