More reliable (hopefully) XMPP logout (unavailable +
authorArt Cancro <ajc@citadel.org>
Sat, 15 Mar 2008 03:54:55 +0000 (03:54 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 15 Mar 2008 03:54:55 +0000 (03:54 +0000)
unsubscribe + roster delete) notifications

citadel/modules/jabber/serv_xmpp.h
citadel/modules/jabber/xmpp_presence.c
citadel/modules/jabber/xmpp_queue.c

index 2b62606c28407ff38a50c108c7c8127b26403892..90a5127dafc74952f915b317315bd38d2c4b22b5 100644 (file)
@@ -61,7 +61,7 @@ void jabber_wholist_presence_dump(void);
 void jabber_output_incoming_messages(void);
 void xmpp_queue_event(int, char *);
 void xmpp_process_events(void);
-void xmpp_presence_notify(char *, char *);
+void xmpp_presence_notify(char *, int);
 void jabber_roster_item(struct CitContext *);
 void jabber_send_message(char *, char *);
 void jabber_non_sasl_authenticate(char *, char *, char *, char *);
index c4e86386b4c8bece74bf000e5a0022b708b2aad9..b5f088b48f749d7204e86d528328b46db9035f8e 100644 (file)
@@ -72,7 +72,7 @@ void jabber_wholist_presence_dump(void)
  * When a user logs in or out of the local Citadel system, notify all Jabber sessions
  * about it.
  */
-void xmpp_presence_notify(char *presence_jid, char *presence_type) {
+void xmpp_presence_notify(char *presence_jid, int event_type) {
        struct CitContext *cptr;
        static int unsolicited_id;
        int visible_sessions = 0;
@@ -92,9 +92,7 @@ void xmpp_presence_notify(char *presence_jid, char *presence_type) {
        lprintf(CTDL_DEBUG, "%d sessions for <%s> are now visible to session %d\n",
                visible_sessions, presence_jid, CC->cs_pid);
 
-       if (
-          ( (strcasecmp(presence_type, "unavailable")) || (strcasecmp(presence_type, "unsubscribed")) )
-          && (visible_sessions == 1) ) {
+       if ( (event_type == XMPP_EVT_LOGIN) && (visible_sessions == 1) ) {
 
                lprintf(CTDL_DEBUG, "Telling session %d that <%s> logged in\n", CC->cs_pid, presence_jid);
 
@@ -110,14 +108,15 @@ void xmpp_presence_notify(char *presence_jid, char *presence_type) {
                }
 
                /* Transmit presence information */
-               cprintf("<presence type=\"%s\" from=\"%s\"></presence>", presence_type, presence_jid);
+               cprintf("<presence type=\"available\" from=\"%s\"></presence>", presence_jid);
        }
 
-       if ( (!strcasecmp(presence_type, "unavailable")) && (visible_sessions == 0) ) {
+       if (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);
+               cprintf("<presence type=\"unavailable\" from=\"%s\"></presence>", presence_jid);
+               cprintf("<presence type=\"unsubscribed\" from=\"%s\"></presence>", presence_jid);
 
                /* Do an unsolicited roster update that deletes the contact. */
                cprintf("<iq id=\"unsolicited_%x\" type=\"result\">", ++unsolicited_id);
index a6e99bb1de40131126854c2e664d9a9c1eace932..866083393d136d69ff27a0b64c900a121bb57f54 100644 (file)
@@ -120,18 +120,11 @@ void xmpp_process_events(void) {
                        switch(xptr->event_type) {
 
                                case XMPP_EVT_LOGIN:
-                                       if (xptr->session_which_generated_this_event != CC->cs_pid) {
-                                               xmpp_presence_notify(xptr->event_jid, "available");
-                                       }
-                                       break;
-
                                case XMPP_EVT_LOGOUT:
                                        if (xptr->session_which_generated_this_event != CC->cs_pid) {
-                                               xmpp_presence_notify(xptr->event_jid, "unavailable");
-                                               xmpp_presence_notify(xptr->event_jid, "unsubscribed");
+                                               xmpp_presence_notify(xptr->event_jid, xptr->event_type);
                                        }
                                        break;
-
                        }
 
                        if (xptr->event_seq > highest_event) {