we have the iq-query-xmlns nonsense all framed up
authorArt Cancro <ajc@citadel.org>
Wed, 28 Nov 2007 04:51:40 +0000 (04:51 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 28 Nov 2007 04:51:40 +0000 (04:51 +0000)
and ready to deliver some results.  now we just have to populate it
with some data.

citadel/modules/jabber/serv_xmpp.c
citadel/modules/jabber/serv_xmpp.h
citadel/modules/jabber/xmpp_query_namespace.c [new file with mode: 0644]

index e24f1869b5581436aa45659856b22882d88ad7dc..b22b551cc7aa128aab1d448da582e2b58e6abd1f 100644 (file)
@@ -115,19 +115,21 @@ void xmpp_xml_start(void *data, const char *supplied_el, const char **attr) {
                xmpp_stream_start(data, supplied_el, attr);
        }
 
+       else if (!strcasecmp(el, "query")) {
+               XMPP->iq_query_xmlns[0] = 0;
+               safestrncpy(XMPP->iq_query_xmlns, supplied_el, sizeof XMPP->iq_query_xmlns);
+       }
+
        else if (!strcasecmp(el, "iq")) {
-               const char *iqtype = NULL;
-               const char *iqid = NULL;
                for (i=0; attr[i] != NULL; i+=2) {
-                       if (!strcasecmp(attr[i], "type")) iqtype = attr[i+1];
-                       if (!strcasecmp(attr[i], "id")) iqid = attr[i+1];
-               }
-               if (iqtype != NULL) {
-                       safestrncpy(XMPP->iq_type, iqtype, sizeof XMPP->iq_type);
-               }
-               if ((iqtype != NULL) && (iqid != NULL)) {
-                       if (!strcasecmp(iqtype, "set")) {
-                               safestrncpy(XMPP->iq_bind_id, iqid, sizeof XMPP->iq_bind_id);
+                       if (!strcasecmp(attr[i], "type")) {
+                               safestrncpy(XMPP->iq_type, attr[i+1], sizeof XMPP->iq_type);
+                       }
+                       else if (!strcasecmp(attr[i], "id")) {
+                               safestrncpy(XMPP->iq_id, attr[i+1], sizeof XMPP->iq_id);
+                       }
+                       else if (!strcasecmp(attr[i], "to")) {
+                               safestrncpy(XMPP->iq_to, attr[i+1], sizeof XMPP->iq_to);
                        }
                }
        }
@@ -169,16 +171,30 @@ void xmpp_xml_end(void *data, const char *supplied_el) {
        else if (!strcasecmp(el, "iq")) {
 
                /*
-                * iq type="get"
+                * iq type="get" (handle queries)
                 */
                if (!strcasecmp(XMPP->iq_type, "get")) {
-                       lprintf(CTDL_DEBUG, "\e[32m DISCO DUCK! \e[0m\n");
+
+                       /*
+                        * Query on a namespace
+                        */
+                       if (!IsEmptyStr(XMPP->iq_query_xmlns)) {
+                               xmpp_query_namespace(XMPP->iq_id, XMPP->iq_to, XMPP->iq_query_xmlns);
+                       }
+
+                       /*
+                        * Unknown queries ... return the XML equivalent of a blank stare
+                        */
+                       else {
+                               cprintf("<iq type=\"result\" id=\"%s\">", XMPP->iq_id);
+                               cprintf("</iq>");
+                       }
                }
 
                /*
                 * If this <iq> stanza was a "bind" attempt, process it ...
                 */
-               else if ( (!IsEmptyStr(XMPP->iq_bind_id)) && (!IsEmptyStr(XMPP->iq_client_resource)) ) {
+               else if ( (!IsEmptyStr(XMPP->iq_id)) && (!IsEmptyStr(XMPP->iq_client_resource)) ) {
 
                        /* Generate the "full JID" of the client resource */
 
@@ -191,7 +207,7 @@ void xmpp_xml_end(void *data, const char *supplied_el) {
 
                        /* Tell the client what its JID is */
 
-                       cprintf("<iq type=\"result\" id=\"%s\">", XMPP->iq_bind_id);
+                       cprintf("<iq type=\"result\" id=\"%s\">", XMPP->iq_id);
                        cprintf("<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">");
                        cprintf("<jid>%s</jid>", XMPP->client_jid);
                        cprintf("</bind>");
@@ -199,20 +215,23 @@ void xmpp_xml_end(void *data, const char *supplied_el) {
                }
 
                else if (XMPP->iq_session) {
-                       cprintf("<iq type=\"result\" id=\"%s\">", XMPP->iq_bind_id);
+                       cprintf("<iq type=\"result\" id=\"%s\">", XMPP->iq_id);
                        cprintf("</iq>");
                }
 
                else {
-                       cprintf("<iq type=\"error\" id=\"%s\">", XMPP->iq_bind_id);
+                       cprintf("<iq type=\"error\" id=\"%s\">", XMPP->iq_id);
                        cprintf("<error></error>");
                        cprintf("</iq>");
                }
 
                /* Now clear these fields out so they don't get used by a future stanza */
-               XMPP->iq_bind_id[0] = 0;
+               XMPP->iq_id[0] = 0;
+               XMPP->iq_to[0] = 0;
+               XMPP->iq_type[0] = 0;
                XMPP->iq_client_resource[0] = 0;
                XMPP->iq_session = 0;
+               XMPP->iq_query_xmlns[0] = 0;
        }
 
        else if (!strcasecmp(el, "auth")) {
index 7a902fcd6f9e36e869dfb3abf0c59d36a99f794a..33b1a74b655d6dfc846fd95131359c402479c4e0 100644 (file)
@@ -12,9 +12,11 @@ struct citxmpp {                     /* Information about the current session */
        char client_jid[256];           /* "full JID" of the client */
 
        char iq_type[256];
-       char iq_bind_id[256];           /* for <iq> stanzas */
+       char iq_id[256];                /* for <iq> stanzas */
+       char iq_to[256];                /* for <iq> stanzas */
        char iq_client_resource[256];   /* resource name requested by the client */
        int iq_session;                 /* nonzero == client is requesting a session */
+       char iq_query_xmlns[256];       /* Namespace of <query> */
 
        char sasl_auth_mech[32];        /* SASL auth mechanism requested by the client */
 };
@@ -26,3 +28,4 @@ void xmpp_greeting(void);
 void xmpp_command_loop(void);
 void xmpp_sasl_auth(char *, char *);
 void xmpp_output_auth_mechs(void);
+void xmpp_query_namespace(char *, char *, char *);
diff --git a/citadel/modules/jabber/xmpp_query_namespace.c b/citadel/modules/jabber/xmpp_query_namespace.c
new file mode 100644 (file)
index 0000000..bb5a5ab
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * $Id:  $ 
+ *
+ * Handle <iq> <get> <query> type situations (namespace queries)
+ *
+ * Copyright (c) 2007 by Art Cancro
+ * This code is released under the terms of the GNU General Public License.
+ *
+ */
+
+#include "sysdep.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <pwd.h>
+#include <errno.h>
+#include <sys/types.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+#include <sys/wait.h>
+#include <string.h>
+#include <limits.h>
+#include <ctype.h>
+#include <libcitadel.h>
+#include "citadel.h"
+#include "server.h"
+#include "citserver.h"
+#include "support.h"
+#include "config.h"
+#include "internet_addressing.h"
+#include "md5.h"
+#include "ctdl_module.h"
+
+#ifdef HAVE_EXPAT
+#include <expat.h>
+#include "serv_xmpp.h"
+
+/*
+ * TODO: handle queries on some or all of these namespaces
+
+xmpp_query_namespace(purple5b5c1e58, splorph.xand.com, http://jabber.org/protocol/disco#items:query)
+xmpp_query_namespace(purple5b5c1e59, splorph.xand.com, http://jabber.org/protocol/disco#info:query)
+xmpp_query_namespace(purple5b5c1e5a, , vcard-temp:query)
+xmpp_query_namespace(purple5b5c1e5b, , jabber:iq:roster:query)
+ */
+
+void xmpp_query_namespace(char *iq_id, char *iq_to, char *query_xmlns) {
+
+       lprintf(CTDL_DEBUG, "\e[31mxmpp_query_namespace(%s, %s, %s)\e[0m\n", iq_id, iq_to, query_xmlns);
+
+       /*
+        * Unknown query.  Return the XML equivalent of a blank stare (empty result)
+        */
+       cprintf("<iq type=\"result\" id=\"%s\">", iq_id);
+       cprintf("</iq>");
+
+}
+
+#endif /* HAVE_EXPAT */