X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fjabber%2Fxmpp_presence.c;h=96b4504b8ba9a267448342e106a699728359ca13;hb=8c47559cb5ae97ec0fa35660ee16fd61a9451c72;hp=c4e86386b4c8bece74bf000e5a0022b708b2aad9;hpb=a4a539f7b5c10763dff969efa26ec49349c0363f;p=citadel.git diff --git a/citadel/modules/jabber/xmpp_presence.c b/citadel/modules/jabber/xmpp_presence.c index c4e86386b..96b4504b8 100644 --- a/citadel/modules/jabber/xmpp_presence.c +++ b/citadel/modules/jabber/xmpp_presence.c @@ -3,8 +3,21 @@ * * Handle XMPP presence exchanges * - * Copyright (c) 2007 by Art Cancro - * This code is released under the terms of the GNU General Public License. + * Copyright (c) 2007-2009 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ @@ -33,6 +46,7 @@ #include #include #include +#include #include #include "citadel.h" #include "server.h" @@ -42,9 +56,6 @@ #include "internet_addressing.h" #include "md5.h" #include "ctdl_module.h" - -#ifdef HAVE_EXPAT -#include #include "serv_xmpp.h" @@ -54,16 +65,27 @@ 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->cs_flags&CS_STEALTH)==0) || (aide)) /* aides can see everyone */ - && (cptr->user.usernum != CC->user.usernum) /* don't tell me about myself */ - ) { - cprintf("", cptr->cs_inet_email); + cptr = CtdlGetContextArray(&nContexts); + if (!cptr) + return ; /** FIXME: Does jabber need to send something to maintain the protocol? */ + + for (i=0; iuser.usernum) /* don't show myself */ + && (cptr[i].can_receive_im) /* IM-capable session */ + ) { + cprintf("", + cptr[i].cs_inet_email); + } } } + free(cptr); } @@ -72,52 +94,63 @@ 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; + int nContexts, i; int aide = (CC->user.axlevel >= 6); if (IsEmptyStr(presence_jid)) return; + cptr = CtdlGetContextArray(&nContexts); + if (!cptr) + return ; /** FIXME: Does jabber need to send something to maintain the protocol? */ + /* 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; + for (i=0; i are now visible to session %d\n", + CtdlLogPrintf(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); + CtdlLogPrintf(CTDL_DEBUG, "Telling session %d that <%s> logged in\n", CC->cs_pid, presence_jid); /* 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("", ++unsolicited_id); - cprintf(""); - jabber_roster_item(cptr); - cprintf("" - ""); + for (i=0; i", + ++unsolicited_id); + cprintf(""); + jabber_roster_item(&cptr[i]); + cprintf("" + ""); + } } } /* Transmit presence information */ - cprintf("", presence_type, presence_jid); + cprintf("", 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); + if (visible_sessions == 0) { + CtdlLogPrintf(CTDL_DEBUG, "Telling session %d that <%s> logged out\n", CC->cs_pid, presence_jid); /* Transmit non-presence information */ - cprintf("", presence_type, presence_jid); + cprintf("", presence_jid); + cprintf("", presence_jid); /* Do an unsolicited roster update that deletes the contact. */ cprintf("", ++unsolicited_id); @@ -128,7 +161,5 @@ void xmpp_presence_notify(char *presence_jid, char *presence_type) { cprintf("" ""); } + free(cptr); } - - -#endif /* HAVE_EXPAT */