Start supporting discovery
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 2 Nov 2008 13:17:13 +0000 (11:17 -0200)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 2 Nov 2008 13:17:13 +0000 (11:17 -0200)
Makefile
disco.c [new file with mode: 0644]
disco.h [new file with mode: 0644]
tictactoe.c
xmpp.h

index f45bdd9..fe90dbe 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 OBJECTS = sort_udns.o tcp_connect.o iksemel_extra.o tictactoe.o \
 OBJECTS = sort_udns.o tcp_connect.o iksemel_extra.o tictactoe.o \
-       xmpp.o features.o sasl.o bind.o
+       xmpp.o features.o sasl.o bind.o disco.o
 CC = gcc
 CFLAGS = -g -Wall `pkg-config --cflags iksemel libgsasl`
 LIBS = -ludns `pkg-config --libs iksemel libgsasl`
 CC = gcc
 CFLAGS = -g -Wall `pkg-config --cflags iksemel libgsasl`
 LIBS = -ludns `pkg-config --libs iksemel libgsasl`
diff --git a/disco.c b/disco.c
new file mode 100644 (file)
index 0000000..de1b4bc
--- /dev/null
+++ b/disco.c
@@ -0,0 +1,49 @@
+/*
+ *  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 "disco.h"
+
+void
+hc_xmpp_send_disco_info (hc_xmpp_t *xmpp, char *to)
+{
+  iks *disco;
+  iks *query;
+  disco = iks_new ("iq");
+  iks_insert_attrib (disco, "type", "get");
+  iks_insert_attrib (disco, "to", to);
+  query = iks_insert (disco, "query");
+  iks_insert_attrib (query, "xmlns", HC_XMPP_NS_DISCO_INFO);
+  hc_xmpp_send_iks (xmpp, disco);
+  iks_delete (disco);
+}
+
+void
+hc_xmpp_recv_disco (hc_xmpp_t *xmpp, iks *disco)
+{
+  char *ns = iks_find_attrib (iks_child (disco), "xmlns");
+  if (!iks_strcmp (ns, HC_XMPP_NS_DISCO_INFO))
+    {
+      iks *c;
+      for (c = iks_child (iks_child (disco)); c != NULL; c = iks_next (c))
+        {
+          fprintf (stdout, "%s\n", iks_find_attrib (c, "var"));
+        }
+    }
+}
diff --git a/disco.h b/disco.h
new file mode 100644 (file)
index 0000000..5ca0a36
--- /dev/null
+++ b/disco.h
@@ -0,0 +1,28 @@
+/*
+ *  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.
+ */
+
+
+#ifndef HC_XMPP_DISCO_H
+#define HC_XMPP_DISCO_H
+
+#include "xmpp.h"
+
+void hc_xmpp_send_disco_info (hc_xmpp_t *, char *);
+void hc_xmpp_recv_disco (hc_xmpp_t *, iks *);
+
+#endif
index b57c1b9..b774512 100644 (file)
 #include "xmpp.h"
 #include "sasl.h"
 #include "bind.h"
 #include "xmpp.h"
 #include "sasl.h"
 #include "bind.h"
+#include "disco.h"
 
 static void write_stream (hc_xmpp_t *);
 
 static void
 send_message_test (hc_xmpp_t *xmpp)
 {
 
 static void write_stream (hc_xmpp_t *);
 
 static void
 send_message_test (hc_xmpp_t *xmpp)
 {
-  iks *msg;
-  msg = iks_new ("message");
-  iks_insert_attrib (msg, "to", "metal@jabber-br.org");
-  iks_insert_cdata (iks_insert (msg, "body"), "pubsub", 0);
-  hc_xmpp_send_iks (xmpp, msg);
-  iks_delete (msg);
+  hc_xmpp_send_disco_info (xmpp, "");
 }
 
 static int
 }
 
 static int
@@ -61,6 +57,10 @@ myhook (void *data, int type, iks *stanza)
           if (hc_xmpp_status (data) == HC_XMPP_SESSION)
             send_message_test (data);
         }
           if (hc_xmpp_status (data) == HC_XMPP_SESSION)
             send_message_test (data);
         }
+      else if (!iks_strcmp (ns, HC_XMPP_NS_DISCO_INFO))
+        {
+          hc_xmpp_recv_disco (data, stanza);
+        }
     }
   else if (!iks_strcmp (iks_name (stanza), "stream:features"))
     {
     }
   else if (!iks_strcmp (iks_name (stanza), "stream:features"))
     {
diff --git a/xmpp.h b/xmpp.h
index 706f15c..c76bb06 100644 (file)
--- a/xmpp.h
+++ b/xmpp.h
@@ -36,6 +36,8 @@ typedef struct _hc_xmpp_t hc_xmpp_t;
 #define HC_XMPP_NS_SASL "urn:ietf:params:xml:ns:xmpp-sasl"
 #define HC_XMPP_NS_BIND "urn:ietf:params:xml:ns:xmpp-bind"
 #define HC_XMPP_NS_SESSION "urn:ietf:params:xml:ns:xmpp-session"
 #define HC_XMPP_NS_SASL "urn:ietf:params:xml:ns:xmpp-sasl"
 #define HC_XMPP_NS_BIND "urn:ietf:params:xml:ns:xmpp-bind"
 #define HC_XMPP_NS_SESSION "urn:ietf:params:xml:ns:xmpp-session"
+#define HC_XMPP_NS_DISCO "http://jabber.org/protocol/disco"
+#define HC_XMPP_NS_DISCO_INFO "http://jabber.org/protocol/disco#info"
 
 hc_xmpp_t * hc_xmpp_new (iksStreamHook *, char *, char *, char *);
 int hc_xmpp_is_tls_supported (hc_xmpp_t *);
 
 hc_xmpp_t * hc_xmpp_new (iksStreamHook *, char *, char *, char *);
 int hc_xmpp_is_tls_supported (hc_xmpp_t *);