Added support for resouce binding and session establishment
[cascardo/chat.git] / xmpp.c
diff --git a/xmpp.c b/xmpp.c
index a6a0a09..8e37c78 100644 (file)
--- a/xmpp.c
+++ b/xmpp.c
 
 
 #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 (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,57 @@ 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;
+}
+
+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;
+}