From c5931fff7cb33567d6fcedfea165a7a0437bd10d Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 23 Feb 2010 05:17:04 +0000 Subject: [PATCH] * More XMPP tweaks, none of which fixed our current batch of problems --- citadel/modules/xmpp/serv_xmpp.c | 3 +- citadel/modules/xmpp/serv_xmpp.h | 1 + citadel/modules/xmpp/xmpp_presence.c | 83 ++++++++++++++++----- citadel/modules/xmpp/xmpp_query_namespace.c | 2 +- 4 files changed, 68 insertions(+), 21 deletions(-) diff --git a/citadel/modules/xmpp/serv_xmpp.c b/citadel/modules/xmpp/serv_xmpp.c index 0ccf6861e..b3cdab14f 100644 --- a/citadel/modules/xmpp/serv_xmpp.c +++ b/citadel/modules/xmpp/serv_xmpp.c @@ -392,7 +392,8 @@ void xmpp_xml_end(void *data, const char *supplied_el) { else if (!strcasecmp(el, "stream")) { CtdlLogPrintf(CTDL_DEBUG, "XMPP client shut down their stream\n"); - cprintf("\n"); + xmpp_massacre_roster(); + cprintf("\n"); CC->kill_me = 1; } diff --git a/citadel/modules/xmpp/serv_xmpp.h b/citadel/modules/xmpp/serv_xmpp.h index dedc599ef..901ad883e 100644 --- a/citadel/modules/xmpp/serv_xmpp.h +++ b/citadel/modules/xmpp/serv_xmpp.h @@ -81,3 +81,4 @@ void xmpp_presence_notify(char *, int); void xmpp_roster_item(struct CitContext *); void xmpp_send_message(char *, char *); void xmpp_non_sasl_authenticate(char *, char *, char *, char *); +void xmpp_massacre_roster(void); diff --git a/citadel/modules/xmpp/xmpp_presence.c b/citadel/modules/xmpp/xmpp_presence.c index a60580fae..9eaf88728 100644 --- a/citadel/modules/xmpp/xmpp_presence.c +++ b/citadel/modules/xmpp/xmpp_presence.c @@ -3,7 +3,7 @@ * * Handle XMPP presence exchanges * - * Copyright (c) 2007-2009 by Art Cancro + * Copyright (c) 2007-2010 by Art Cancro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -70,16 +70,17 @@ void xmpp_wholist_presence_dump(void) int aide = (CC->user.axlevel >= 6); cptr = CtdlGetContextArray(&nContexts); - if (!cptr) - return ; /** FIXME: Does xmpp need to send something to maintain the protocol? */ - + if (!cptr) { + return; + } + for (i=0; iuser.usernum) /* don't show myself */ && (cptr[i].can_receive_im) /* IM-capable session */ - ) { + ) { cprintf("", cptr[i].cs_inet_email); } @@ -89,6 +90,28 @@ void xmpp_wholist_presence_dump(void) } +/* + * Function to remove a buddy subscription and delete from the roster + * (used in several places) + */ +void xmpp_destroy_buddy(char *presence_jid) { + static int unsolicited_id = 1; + + /* Transmit non-presence information */ + cprintf("", presence_jid); + cprintf("", presence_jid); + + /* Do an unsolicited roster update that deletes the contact. */ + cprintf("", ++unsolicited_id); + cprintf(""); + cprintf("", presence_jid); + cprintf("%s", config.c_humannode); + cprintf(""); + cprintf("" + "" + ); +} + /* * When a user logs in or out of the local Citadel system, notify all XMPP sessions about it. @@ -101,10 +124,12 @@ void xmpp_presence_notify(char *presence_jid, int event_type) { int aide = (CC->user.axlevel >= 6); if (IsEmptyStr(presence_jid)) return; + if (CC->kill_me) return; cptr = CtdlGetContextArray(&nContexts); - if (!cptr) - return ; /** FIXME: Does XMPP need to send something to maintain the protocol? */ + if (!cptr) { + return; + } /* Count the visible sessions for this user */ for (i=0; i logged out\n", CC->cs_pid, presence_jid); - /* Transmit non-presence information */ - cprintf("", presence_jid); - cprintf("", presence_jid); - - /* Do an unsolicited roster update that deletes the contact. */ - cprintf("", ++unsolicited_id); - cprintf(""); - cprintf("", presence_jid); - cprintf("%s", config.c_humannode); - cprintf(""); - cprintf("" - ""); + xmpp_destroy_buddy(presence_jid); } free(cptr); } + + + +/* + * 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. + */ +void xmpp_massacre_roster(void) +{ + struct CitContext *cptr; + int nContexts, i; + int aide = (CC->user.axlevel >= 6); + + cptr = CtdlGetContextArray(&nContexts); + if (cptr) { + for (i=0; iuser.usernum) + ) { + xmpp_destroy_buddy(cptr[i].cs_inet_email); + } + } + } + free (cptr); + } +} + + + diff --git a/citadel/modules/xmpp/xmpp_query_namespace.c b/citadel/modules/xmpp/xmpp_query_namespace.c index 6dad562b3..42875074e 100644 --- a/citadel/modules/xmpp/xmpp_query_namespace.c +++ b/citadel/modules/xmpp/xmpp_query_namespace.c @@ -122,7 +122,7 @@ void xmpp_query_namespace(char *iq_id, char *iq_from, char *iq_to, char *query_x */ if ( (!strcasecmp(query_xmlns, "jabber:iq:roster:query")) - && (!strcasecmp(query_xmlns, "jabber:iq:auth:query")) + || (!strcasecmp(query_xmlns, "jabber:iq:auth:query")) ) { supported_namespace = 1; } -- 2.30.2