Only send presence notifications when the first
authorArt Cancro <ajc@citadel.org>
Mon, 3 Dec 2007 07:22:43 +0000 (07:22 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 3 Dec 2007 07:22:43 +0000 (07:22 +0000)
concurrent session for a user logs in, or when the last
session logs out.  Also handle stealth mode semantics.

citadel/modules/jabber/serv_xmpp.c
citadel/modules/jabber/xmpp_presence.c
citadel/modules/rwho/serv_rwho.c
citadel/server.h

index 210d19820c2dada7c46dae4d476570aa489427ef..b7357925707b7051f4d15bdef7358ebeb5cdc060 100644 (file)
@@ -446,7 +446,8 @@ CTDL_MODULE_INIT(jabber)
                CtdlRegisterSessionHook(xmpp_cleanup_function, EVT_STOP);
                 CtdlRegisterSessionHook(xmpp_login_hook, EVT_LOGIN);
                 CtdlRegisterSessionHook(xmpp_logout_hook, EVT_LOGOUT);
-
+                CtdlRegisterSessionHook(xmpp_login_hook, EVT_UNSTEALTH);
+                CtdlRegisterSessionHook(xmpp_logout_hook, EVT_STEALTH);
        #else
                lprintf(CTDL_INFO, "This server is missing the Expat XML parser.  Jabber service will be disabled.\n");
 #endif
index 96b533c2a51201e5987e37bdfecda5a4727c6da0..0bce01b133e2c294d8428e8f99b652792b811960 100644 (file)
@@ -75,18 +75,27 @@ void jabber_wholist_presence_dump(void)
 void xmpp_presence_notify(char *presence_jid, char *presence_type) {
        struct CitContext *cptr;
        static int unsolicited_id;
+       int visible_sessions = 0;
+       int aide = (CC->user.axlevel >= 6);
+
+       if (IsEmptyStr(presence_jid)) return;
 
-       /* FIXME subject this to the same conditions as above */
+       /* Count the visible sessions for this user */
+       for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
+               if (  (!strcasecmp(cptr->cs_inet_email, presence_jid)) 
+                  && (((cptr->cs_flags&CS_STEALTH)==0) || (aide))
+                  ) {
+                       ++visible_sessions;
+               }
+       }
 
-       /* FIXME make sure don't do this for multiple logins of the same user (login)
-        * or until the last concurrent login is logged out (logout)
-        */
+       lprintf(CTDL_DEBUG, "%d sessions for <%s> are now visible to session %d\n",
+               visible_sessions, presence_jid, CC->cs_pid);
 
-       if (IsEmptyStr(presence_jid)) return;
-       lprintf(CTDL_DEBUG, "Sending presence info about <%s> to session %d\n", presence_jid, CC->cs_pid);
+       if ( (strcasecmp(presence_type, "unavailable")) && (visible_sessions == 1) ) {
+               lprintf(CTDL_DEBUG, "Telling session %d that <%s> logged in\n", CC->cs_pid, presence_jid);
 
-       /* Transmit an unsolicited roster update if the presence is anything other than "unavailable" */
-       if (strcasecmp(presence_type, "unavailable")) {
+               /* Do an unsolicited roster update that adds a new contact. */
                for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
                        if (!strcasecmp(cptr->cs_inet_email, presence_jid)) {
                                cprintf("<iq id=\"unsolicited_%x\" type=\"result\">", ++unsolicited_id);
@@ -96,13 +105,18 @@ void xmpp_presence_notify(char *presence_jid, char *presence_type) {
                                        "</iq>");
                        }
                }
+
+               /* Transmit presence information */
+               cprintf("<presence type=\"%s\" from=\"%s\"></presence>", presence_type, presence_jid);
        }
 
-       /* Now transmit unsolicited presence information */
-       cprintf("<presence type=\"%s\" from=\"%s\"></presence>", presence_type, presence_jid);
+       if ( (!strcasecmp(presence_type, "unavailable")) && (visible_sessions == 0) ) {
+               lprintf(CTDL_DEBUG, "Telling session %d that <%s> logged out\n", CC->cs_pid, presence_jid);
+
+               /* Transmit non-presence information */
+               cprintf("<presence type=\"%s\" from=\"%s\"></presence>", presence_type, presence_jid);
 
-       /* For "unavailable" we do an unsolicited roster update that deletes the contact. */
-       if (!strcasecmp(presence_type, "unavailable")) {
+               /* Do an unsolicited roster update that deletes the contact. */
                cprintf("<iq id=\"unsolicited_%x\" type=\"result\">", ++unsolicited_id);
                cprintf("<query xmlns=\"jabber:iq:roster\">");
                cprintf("<item jid=\"%s\" subscription=\"remove\">", presence_jid);
index b09605d1fb5a1d6b1d6871641c9ee89af11b8bb0..7932727736e5848280a6043a3cb8b218f85a0fb7 100644 (file)
@@ -238,9 +238,11 @@ void cmd_stel(char *cmdbuf)
 
        if (requested_mode == 1) {
                CC->cs_flags = CC->cs_flags | CS_STEALTH;
+               PerformSessionHooks(EVT_STEALTH);
        }
        if (requested_mode == 0) {
                CC->cs_flags = CC->cs_flags & ~CS_STEALTH;
+               PerformSessionHooks(EVT_UNSTEALTH);
        }
 
        cprintf("%d %d\n", CIT_OK,
index f88d37fd68c64da89fdd730ab5685ebc7ceef16f..d77726a4479f6d971ebca46223d1dded991afcf6 100644 (file)
@@ -308,6 +308,8 @@ struct cdbdata {
 #define EVT_CMD                6       /* Called after each server command */
 #define EVT_RWHO       7       /* An RWHO command is being executed */
 #define EVT_ASYNC      8       /* Doing asynchronous messages */
+#define EVT_STEALTH    9       /* Entering stealth mode */
+#define EVT_UNSTEALTH  10      /* Exiting stealth mode */
 
 #define EVT_TIMER      50      /* Timer events are called once per minute
                                   and are not tied to any session */