]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/xmpp/xmpp_presence.c
* more work on the dead buddies purge
[citadel.git] / citadel / modules / xmpp / xmpp_presence.c
index 141b2d3fdc65c5c3c048a6c9e962a7e10f1c82c0..3df2217c3b78e996da2240ff27ebd87dae88b24c 100644 (file)
@@ -81,7 +81,7 @@ void xmpp_wholist_presence_dump(void)
        struct CitContext *cptr = NULL;
        int nContexts, i;
        
-       int aide = (CC->user.axlevel >= 6);
+       int aide = (CC->user.axlevel >= AxAideU);
 
        cptr = CtdlGetContextArray(&nContexts);
        if (!cptr) {
@@ -143,7 +143,7 @@ void xmpp_presence_notify(char *presence_jid, int event_type) {
        static int unsolicited_id;
        int visible_sessions = 0;
        int nContexts, i;
-       int aide = (CC->user.axlevel >= 6);
+       int aide = (CC->user.axlevel >= AxAideU);
 
        if (IsEmptyStr(presence_jid)) return;
        if (CC->kill_me) return;
@@ -200,16 +200,73 @@ void xmpp_presence_notify(char *presence_jid, int event_type) {
 }
 
 
+/*
+ * Fetch the "mortuary" - a list of dead buddies which we keep around forever
+ * so we can remove them from any client's roster that still has them listed
+ */
+HashList *xmpp_fetch_mortuary(void) {
+       HashList *mortuary = NewHash(1, NULL);
+       if (!mortuary) {
+               CtdlLogPrintf(CTDL_ALERT, "NewHash() failed!\n");
+               return(NULL);
+       }
+
+       /* FIXME finish this */
+
+       return(mortuary);
+}
+
+
+
+/*
+ * Fetch the "mortuary" - a list of dead buddies which we keep around forever
+ * so we can remove them from any client's roster that still has them listed
+ */
+void xmpp_store_mortuary(HashList *mortuary) {
+       HashPos *HashPos;
+       long len;
+       void *Value;
+       const char *Key;
+       StrBuf *themsg;
+
+       themsg = NewStrBuf();
+       StrBufPrintf(themsg,    "Content-type: " XMPPMORTUARY "\n"
+                               "Content-transfer-encoding: 7bit\n"
+                               "\n"
+       );
+
+       HashPos = GetNewHashPos(mortuary, 0);
+       while (GetNextHashPos(mortuary, HashPos, &len, &Key, &Value) != 0)
+       {
+               StrBufAppendPrintf(themsg, "%s\n", (char *)Value);
+               /* note: don't free(Value) -- deleting the hash list will handle this for us */
+       }
+       DeleteHashPos(&HashPos);
+
+       /* Save it to disk */
+       quickie_message("Citadel", NULL, NULL, USERCONFIGROOM, ChrPtr(themsg), 4, "XMPP Mortuary");
+
+       /* Delete the old one */
+       CtdlDeleteMessages(USERCONFIGROOM, NULL, 0, XMPPMORTUARY);
+
+       FreeStrBuf(&themsg);
+}
+
+
 
 /*
  * Upon logout we make an attempt to delete the whole roster, in order to
  * try to keep "ghost" buddies from remaining in the client-side roster.
+ *
+ * Since the client is probably not still alive, also remember the current
+ * roster for next time so we can delete dead buddies then.
  */
 void xmpp_massacre_roster(void)
 {
        struct CitContext *cptr;
        int nContexts, i;
-       int aide = (CC->user.axlevel >= 6);
+       int aide = (CC->user.axlevel >= AxAideU);
+       HashList *mortuary = xmpp_fetch_mortuary();
 
        cptr = CtdlGetContextArray(&nContexts);
        if (cptr) {
@@ -220,11 +277,21 @@ void xmpp_massacre_roster(void)
                                        && (cptr[i].user.usernum != CC->user.usernum)
                                ) {
                                        xmpp_destroy_buddy(cptr[i].cs_inet_email);
+                                       if (mortuary) {
+                                               char *buddy = strdup(cptr[i].cs_inet_email);
+                                               Put(mortuary, buddy, strlen(buddy),
+                                                       buddy, generic_free_handler);
+                                       }
                                }
                        }
                }
                free (cptr);
        }
+
+       if (mortuary) {
+               xmpp_store_mortuary(mortuary);
+               DeleteHash(&mortuary);
+       }
 }