Added support for resouce binding and session establishment
[cascardo/hcxmpp.git] / bind.c
diff --git a/bind.c b/bind.c
new file mode 100644 (file)
index 0000000..f4a760e
--- /dev/null
+++ b/bind.c
@@ -0,0 +1,68 @@
+/*
+ *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#include "xmpp_internal.h"
+#include "bind.h"
+
+void
+hc_xmpp_bind (hc_xmpp_t *xmpp)
+{
+  iks *iqbind;
+  iks *query;
+  iqbind = iks_new ("iq");
+  iks_insert_attrib (iqbind, "type", "set");
+  query = iks_insert (iqbind, "bind");
+  iks_insert_attrib (query, "xmlns", HC_XMPP_NS_BIND);
+  hc_xmpp_send_iks (xmpp, iqbind);
+  iks_delete (iqbind);
+}
+
+void
+hc_xmpp_bind_result (hc_xmpp_t *xmpp, iks *result)
+{
+  if (!iks_strcmp (iks_find_attrib (result, "type"), "result"))
+    {
+      xmpp->status = HC_XMPP_BOUND;
+      xmpp->bind |= ENABLED;
+    }
+}
+
+void
+hc_xmpp_session (hc_xmpp_t *xmpp)
+{
+  iks *iqsession;
+  iks *query;
+  iqsession = iks_new ("iq");
+  iks_insert_attrib (iqsession, "type", "set");
+  query = iks_insert (iqsession, "session");
+  iks_insert_attrib (query, "xmlns", HC_XMPP_NS_SESSION);
+  hc_xmpp_send_iks (xmpp, iqsession);
+  iks_delete (iqsession);
+}
+
+void
+hc_xmpp_session_result (hc_xmpp_t *xmpp, iks *result)
+{
+  if (!iks_strcmp (iks_find_attrib (result, "type"), "result"))
+    {
+      xmpp->status = HC_XMPP_SESSION;
+      xmpp->session |= ENABLED;
+    }
+}
+