]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/jabber/xmpp_presence.c
libical, expat, and libsieve are now *required*.
[citadel.git] / citadel / modules / jabber / xmpp_presence.c
index 84b5662ed8606f9c46b6f3de8342040426428c0e..e3d9cc4665d09b789c9cb89f8a94e9b8481036a6 100644 (file)
@@ -33,6 +33,7 @@
 #include <string.h>
 #include <limits.h>
 #include <ctype.h>
+#include <expat.h>
 #include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
@@ -42,9 +43,6 @@
 #include "internet_addressing.h"
 #include "md5.h"
 #include "ctdl_module.h"
-
-#ifdef HAVE_EXPAT
-#include <expat.h>
 #include "serv_xmpp.h"
 
 
 void jabber_wholist_presence_dump(void)
 {
        struct CitContext *cptr = NULL;
+       int nContexts, i;
+       
        int aide = (CC->user.axlevel >= 6);
 
-       for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
-               if (cptr->logged_in) {
+       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->cs_flags&CS_STEALTH)==0) || (aide))         /* aides see everyone */
-                          && (cptr->user.usernum != CC->user.usernum)          /* don't show myself */
+                          (((cptr[i].cs_flags&CS_STEALTH)==0) || (aide))               /* aides see everyone */
+                          && (cptr[i].user.usernum != CC->user.usernum)                /* don't show myself */
                           ) {
                                cprintf("<presence type=\"available\" from=\"%s\"></presence>",
-                                       cptr->cs_inet_email);
+                                       cptr[i].cs_inet_email);
                        }
                }
        }
+       free(cptr);
 }
 
 
@@ -79,15 +84,20 @@ void xmpp_presence_notify(char *presence_jid, int event_type) {
        struct CitContext *cptr;
        static int unsolicited_id;
        int visible_sessions = 0;
+       int nContexts, i;
        int aide = (CC->user.axlevel >= 6);
 
        if (IsEmptyStr(presence_jid)) return;
 
+       cptr = CtdlGetContextArray(&nContexts);
+       if (!cptr)
+               return ; /** FIXME: Does jabber need to send something to maintain the protocol?  */
+               
        /* Count the visible sessions for this user */
-       for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
-               if (cptr->logged_in) {
-                       if (  (!strcasecmp(cptr->cs_inet_email, presence_jid)) 
-                          && (((cptr->cs_flags&CS_STEALTH)==0) || (aide))
+       for (i=0; i<nContexts; i++) {
+               if (cptr[i].logged_in) {
+                       if (  (!strcasecmp(cptr[i].cs_inet_email, presence_jid)) 
+                          && (((cptr[i].cs_flags&CS_STEALTH)==0) || (aide))
                           ) {
                                ++visible_sessions;
                        }
@@ -102,13 +112,13 @@ void xmpp_presence_notify(char *presence_jid, int event_type) {
                lprintf(CTDL_DEBUG, "Telling session %d that <%s> logged in\n", CC->cs_pid, presence_jid);
 
                /* Do an unsolicited roster update that adds a new contact. */
-               for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
-                       if (cptr->logged_in) {
-                               if (!strcasecmp(cptr->cs_inet_email, presence_jid)) {
+               for (i=0; i<nContexts; i++) {
+                       if (cptr[i].logged_in) {
+                               if (!strcasecmp(cptr[i].cs_inet_email, presence_jid)) {
                                        cprintf("<iq id=\"unsolicited_%x\" type=\"result\">",
                                                ++unsolicited_id);
                                        cprintf("<query xmlns=\"jabber:iq:roster\">");
-                                       jabber_roster_item(cptr);
+                                       jabber_roster_item(&cptr[i]);
                                        cprintf("</query>"
                                                "</iq>");
                                }
@@ -135,7 +145,5 @@ void xmpp_presence_notify(char *presence_jid, int event_type) {
                cprintf("</query>"
                        "</iq>");
        }
+       free(cptr);
 }
-
-
-#endif /* HAVE_EXPAT */