4 * Handle XMPP presence exchanges
6 * Copyright (c) 2007 by Art Cancro
7 * This code is released under the terms of the GNU General Public License.
19 #include <sys/types.h>
21 #if TIME_WITH_SYS_TIME
22 # include <sys/time.h>
26 # include <sys/time.h>
36 #include <libcitadel.h>
39 #include "citserver.h"
42 #include "internet_addressing.h"
44 #include "ctdl_module.h"
48 #include "serv_xmpp.h"
52 * Initial dump of the entire wholist
54 void jabber_wholist_presence_dump(void)
56 struct CitContext *cptr = NULL;
57 int aide = (CC->user.axlevel >= 6);
59 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
61 (((cptr->cs_flags&CS_STEALTH)==0) || (aide)) /* aides can see everyone */
62 && (cptr->user.usernum != CC->user.usernum) /* don't tell me about myself */
64 cprintf("<presence type=\"available\" from=\"%s\"></presence>", cptr->cs_inet_email);
72 * When a user logs in or out of the local Citadel system, notify all Jabber sessions
75 void xmpp_presence_notify(char *presence_jid, char *presence_type) {
76 struct CitContext *cptr;
77 static int unsolicited_id;
79 /* FIXME subject this to the same conditions as above */
81 /* FIXME make sure don't do this for multiple logins of the same user (login)
82 * or until the last concurrent login is logged out (logout)
85 if (IsEmptyStr(presence_jid)) return;
86 lprintf(CTDL_DEBUG, "Sending presence info about <%s> to session %d\n", presence_jid, CC->cs_pid);
88 /* Transmit an unsolicited roster update if the presence is anything other than "unavailable" */
89 if (strcasecmp(presence_type, "unavailable")) {
90 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
91 if (!strcasecmp(cptr->cs_inet_email, presence_jid)) {
92 cprintf("<iq id=\"unsolicited_%x\" type=\"result\">", ++unsolicited_id);
93 cprintf("<query xmlns=\"jabber:iq:roster\">");
94 jabber_roster_item(cptr);
101 /* Now transmit unsolicited presence information */
102 cprintf("<presence type=\"%s\" from=\"%s\"></presence>", presence_type, presence_jid);
104 /* For "unavailable" we do an unsolicited roster update that deletes the contact. */
105 if (!strcasecmp(presence_type, "unavailable")) {
106 cprintf("<iq id=\"unsolicited_%x\" type=\"result\">", ++unsolicited_id);
107 cprintf("<query xmlns=\"jabber:iq:roster\">");
108 cprintf("<item jid=\"%s\" subscription=\"none\">", presence_jid);
109 cprintf("<group>%s</group>", config.c_humannode);
117 #endif /* HAVE_EXPAT */