Jabber now reads the context list safely and it writes it safely too.
authorDave West <davew@uncensored.citadel.org>
Tue, 18 Mar 2008 15:00:28 +0000 (15:00 +0000)
committerDave West <davew@uncensored.citadel.org>
Tue, 18 Mar 2008 15:00:28 +0000 (15:00 +0000)
citadel/modules/jabber/xmpp_presence.c
citadel/modules/jabber/xmpp_query_namespace.c
citadel/modules/jabber/xmpp_queue.c

index 84b5662ed8606f9c46b6f3de8342040426428c0e..5c87cca3cd11237fa5009d2d91f490ce45c68b57 100644 (file)
 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);
 }
 
 
index fdec3135fe639a19703ae8dfbd3bab2aa9c7ee16..98f62285a1216989c3090a6e7ffcaee99f3e87a9 100644 (file)
@@ -70,21 +70,26 @@ void jabber_roster_item(struct CitContext *cptr) {
 void jabber_iq_roster_query(void)
 {
        struct CitContext *cptr;
+       int nContexts, i;
        int aide = (CC->user.axlevel >= 6);
 
        cprintf("<query xmlns=\"jabber:iq:roster\">");
 
-       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))
-                          && (cptr->user.usernum != CC->user.usernum)
+                          (((cptr[i].cs_flags&CS_STEALTH)==0) || (aide))
+                          && (cptr[i].user.usernum != CC->user.usernum)
                           ) {
-                               jabber_roster_item(cptr);
+                               jabber_roster_item(&cptr[i]);
                        }
                }
        }
-
+       free (cptr);
        cprintf("</query>");
 }
 
index 44540496bfc5f5d34903fcea00583d5b1cfe1186..2c97b8431a31fa1f51f966afa123e1adcf25ab72 100644 (file)
@@ -99,11 +99,13 @@ void xmpp_queue_event(int event_type, char *email_addr) {
        end_critical_section(S_XMPP_QUEUE);
 
        /* Tell the sessions that something is happening */
+       begin_critical_section(S_SESSION_TABLE);
        for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
                if ((cptr->logged_in) && (cptr->h_async_function == xmpp_async_loop)) {
                        cptr->async_waiting = 1;
                }
        }
+       end_critical_section(S_SESSION_TABLE);
 }