Removed the logging facility from citserver, use syslog instead
[citadel.git] / citadel / modules / xmpp / xmpp_query_namespace.c
index a94e6d6d1add77bdaa24f54a48a340761d39f274..993801bf880128e332872d10f2baa1cd78309595 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$ 
- *
  * Handle <iq> <get> <query> type situations (namespace queries)
  *
  * Copyright (c) 2007-2009 by Art Cancro
  * Output a single roster item, for roster queries or pushes
  */
 void xmpp_roster_item(struct CitContext *cptr) {
+       char xmlbuf1[256];
+       char xmlbuf2[256];
+
        cprintf("<item jid=\"%s\" name=\"%s\" subscription=\"both\">",
-               cptr->cs_inet_email,
-               cptr->user.fullname
+               xmlesc(xmlbuf1, cptr->cs_inet_email, sizeof xmlbuf1),
+               xmlesc(xmlbuf2, cptr->user.fullname, sizeof xmlbuf2)
        );
-       cprintf("<group>%s</group>", config.c_humannode);
+       cprintf("<group>%s</group>", xmlesc(xmlbuf1, config.c_humannode, sizeof xmlbuf1));
        cprintf("</item>");
 }
 
@@ -81,20 +82,14 @@ void xmpp_iq_roster_query(void)
 {
        struct CitContext *cptr;
        int nContexts, i;
-       int aide = (CC->user.axlevel >= AxAideU);
 
        cprintf("<query xmlns=\"jabber:iq:roster\">");
-
        cptr = CtdlGetContextArray(&nContexts);
        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)
-                               ) {
-                                       xmpp_roster_item(&cptr[i]);
-                               }
+                       if (xmpp_is_visible(&cptr[i], CC)) {
+                               syslog(LOG_DEBUG, "Rosterizing %s\n", cptr[i].user.fullname);
+                               xmpp_roster_item(&cptr[i]);
                        }
                }
                free (cptr);
@@ -115,6 +110,8 @@ xmpp_query_namespace(purple5b5c1e5a, , vcard-temp:query)
 void xmpp_query_namespace(char *iq_id, char *iq_from, char *iq_to, char *query_xmlns)
 {
        int supported_namespace = 0;
+       int roster_query = 0;
+       char xmlbuf[256];
 
        /* 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
@@ -127,7 +124,7 @@ void xmpp_query_namespace(char *iq_id, char *iq_from, char *iq_to, char *query_x
                supported_namespace = 1;
        }
 
-       CtdlLogPrintf(CTDL_DEBUG, "xmpp_query_namespace(%s, %s, %s, %s)\n", iq_id, iq_from, iq_to, query_xmlns);
+       syslog(LOG_DEBUG, "xmpp_query_namespace(%s, %s, %s, %s)\n", iq_id, iq_from, iq_to, query_xmlns);
 
        /*
         * Beginning of query result.
@@ -139,15 +136,16 @@ void xmpp_query_namespace(char *iq_id, char *iq_from, char *iq_to, char *query_x
                cprintf("<iq type=\"error\" ");
        }
        if (!IsEmptyStr(iq_from)) {
-               cprintf("to=\"%s\" ", iq_from);
+               cprintf("to=\"%s\" ", xmlesc(xmlbuf, iq_from, sizeof xmlbuf));
        }
-       cprintf("id=\"%s\">", iq_id);
+       cprintf("id=\"%s\">", xmlesc(xmlbuf, iq_id, sizeof xmlbuf));
 
        /*
         * Is this a query we know how to handle?
         */
 
        if (!strcasecmp(query_xmlns, "jabber:iq:roster:query")) {
+               roster_query = 1;
                xmpp_iq_roster_query();
        }
 
@@ -164,7 +162,7 @@ void xmpp_query_namespace(char *iq_id, char *iq_from, char *iq_to, char *query_x
         */
 
        else {
-               CtdlLogPrintf(CTDL_DEBUG,
+               syslog(LOG_DEBUG,
                        "Unknown query namespace '%s' - returning <service-unavailable/>\n",
                        query_xmlns
                );
@@ -175,4 +173,12 @@ void xmpp_query_namespace(char *iq_id, char *iq_from, char *iq_to, char *query_x
        }
 
        cprintf("</iq>");
+
+       /* If we told the client who is on the roster, we also need to tell the client
+        * who is *not* on the roster.  (It's down here because we can't do it in the same
+        * stanza; this will be an unsolicited push.)
+        */
+       if (roster_query) {
+               xmpp_delete_old_buddies_who_no_longer_exist_from_the_client_roster();
+       }
 }