* Reply to XMPP queries in unsupported namespaces with a <service-unavailable/> error...
authorArt Cancro <ajc@citadel.org>
Sun, 21 Feb 2010 05:37:32 +0000 (05:37 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 21 Feb 2010 05:37:32 +0000 (05:37 +0000)
citadel/modules/jabber/xmpp_query_namespace.c
citadel/modules/rssclient/serv_rssclient.c

index 0c34d5f7b68d8aa0297d6ae2d72606ac534b3323..64aba16c518fa2ddc593f956b7ad266ff9ce90f2 100644 (file)
@@ -86,20 +86,19 @@ void jabber_iq_roster_query(void)
        cprintf("<query xmlns=\"jabber:iq:roster\">");
 
        cptr = CtdlGetContextArray(&nContexts);
-       if (!cptr)
-               return ; /** FIXME: Does jabber need to send something to maintain the protocol?  */
-               
-       for (i=0; i<nContexts; i++) {
-               if (cptr[i].logged_in) {
-                       if (
-                          (((cptr[i].cs_flags&CS_STEALTH)==0) || (aide))
-                          && (cptr[i].user.usernum != CC->user.usernum)
-                          ) {
-                               jabber_roster_item(&cptr[i]);
+       if (cptr) {
+               for (i=0; i<nContexts; i++) {
+                       if (cptr[i].logged_in) {
+                               if (
+                                       (((cptr[i].cs_flags&CS_STEALTH)==0) || (aide))
+                                       && (cptr[i].user.usernum != CC->user.usernum)
+                               ) {
+                                       jabber_roster_item(&cptr[i]);
+                               }
                        }
                }
+               free (cptr);
        }
-       free (cptr);
        cprintf("</query>");
 }
 
@@ -113,14 +112,32 @@ xmpp_query_namespace(purple5b5c1e5a, , vcard-temp:query)
  *
  */
 
-void xmpp_query_namespace(char *iq_id, char *iq_from, char *iq_to, char *query_xmlns) {
+void xmpp_query_namespace(char *iq_id, char *iq_from, char *iq_to, char *query_xmlns)
+{
+       int supported_namespace = 0;
+
+       /* We need to know before we begin the response whether this is a supported namespace, so
+        * unfortunately all supported namespaces need to be defined here *and* down below where
+        * they are handled.
+        */
+       if (
+               (!strcasecmp(query_xmlns, "jabber:iq:roster:query"))
+               && (!strcasecmp(query_xmlns, "jabber:iq:auth:query"))
+       ) {
+               supported_namespace = 1;
+       }
 
        CtdlLogPrintf(CTDL_DEBUG, "xmpp_query_namespace(%s, %s, %s, %s)\n", iq_id, iq_from, iq_to, query_xmlns);
 
        /*
         * Beginning of query result.
         */
-       cprintf("<iq type=\"result\" ");
+       if (supported_namespace) {
+               cprintf("<iq type=\"result\" ");
+       }
+       else {
+               cprintf("<iq type=\"error\" ");
+       }
        if (!IsEmptyStr(iq_from)) {
                cprintf("to=\"%s\" ", iq_from);
        }
@@ -141,10 +158,17 @@ void xmpp_query_namespace(char *iq_id, char *iq_from, char *iq_to, char *query_x
                );
        }
 
+       else {
+               CtdlLogPrintf(CTDL_DEBUG, "Unknown namespace; returning <service-unavailable/>\n");
+               cprintf("<error code=\"503\" type=\"cancel\">"
+                       "<service-unavailable xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>"
+                       "</error>"
+               );
+       }
+
        /*
-        * End of query result.  If we didn't hit any known namespaces then we will
-        * have simply delivered an empty result stanza, which should be ok.
+        * End of query result.  If we didn't hit any known namespaces then we should
+        * deliver a "service unavailable" error (see RFC3921 section 2.4 and 11.1.5.4)
         */
        cprintf("</iq>");
-
 }
index 2a16edd8a215862978385267381991fdd75e4cce..b7cd4905667c5c340f11baa636feae11ad8bfe9f 100644 (file)
@@ -289,7 +289,6 @@ void rss_save_item(rsscollection *rssc) {
        int msglen = 0;
        rss_item *ri = rssc->Item;
 
-       CtdlLogPrintf(0, "RSS: saving item...\n");
        recp = (struct recptypes *) malloc(sizeof(struct recptypes));
        if (recp == NULL) return;
        memset(recp, 0, sizeof(struct recptypes));
@@ -334,7 +333,7 @@ void rss_save_item(rsscollection *rssc) {
        }
        else {
                /* Item has not been seen, so save it. */
-
+               CtdlLogPrintf(CTDL_DEBUG, "RSS: saving item...\n");
                if (ri->description == NULL) ri->description = strdup("");
                for (i=strlen(ri->description); i>=0; --i) {
                        if (isspace(ri->description[i])) {