From ca01f48055a0ea7668760258c7fc034c6cedf292 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 2 Dec 2007 05:46:40 +0000 Subject: [PATCH] Unsolicited presence push. Still doesn't seem to work. --- citadel/modules/jabber/serv_xmpp.h | 2 ++ citadel/modules/jabber/xmpp_presence.c | 27 +++++++++++++++++++++++++- citadel/modules/jabber/xmpp_queue.c | 9 +++++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/citadel/modules/jabber/serv_xmpp.h b/citadel/modules/jabber/serv_xmpp.h index 54bb87ea5..39030c8b7 100644 --- a/citadel/modules/jabber/serv_xmpp.h +++ b/citadel/modules/jabber/serv_xmpp.h @@ -31,6 +31,7 @@ struct xmpp_event { time_t event_time; int event_type; char event_jid[256]; + int session_which_generated_this_event; }; extern struct xmpp_event *xmpp_queue; @@ -52,3 +53,4 @@ void jabber_output_incoming_messages(void); void xmpp_queue_event(int, char *); void xmpp_process_events(void); void xmpp_presence_notify(char *, char *); +void jabber_roster_item(struct CitContext *); diff --git a/citadel/modules/jabber/xmpp_presence.c b/citadel/modules/jabber/xmpp_presence.c index 80e3e7096..bfb9776bf 100644 --- a/citadel/modules/jabber/xmpp_presence.c +++ b/citadel/modules/jabber/xmpp_presence.c @@ -67,9 +67,34 @@ 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) { + struct CitContext *cptr; + static int unsolicited_id; + /* FIXME subject this to the same conditions as above */ - cprintf("", presence_type, presence_jid); + + if (IsEmptyStr(presence_jid)) return; + lprintf(CTDL_DEBUG, "Sending presence info about <%s> to session %d\n", presence_jid, CC->cs_pid); + + /* Transmit an unsolicited roster update + 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("" + ""); + } + } */ + + /* Now transmit unsolicited presence information + cprintf("", presence_type, presence_jid); + */ } diff --git a/citadel/modules/jabber/xmpp_queue.c b/citadel/modules/jabber/xmpp_queue.c index 3191cac9d..8a0e79554 100644 --- a/citadel/modules/jabber/xmpp_queue.c +++ b/citadel/modules/jabber/xmpp_queue.c @@ -81,6 +81,7 @@ void xmpp_queue_event(int event_type, char *email_addr) { new_event->event_time = time(NULL); new_event->event_seq = ++seq; new_event->event_type = event_type; + new_event->session_which_generated_this_event = CC->cs_pid; safestrncpy(new_event->event_jid, email_addr, sizeof new_event->event_jid); /* Add it to the list */ @@ -120,11 +121,15 @@ void xmpp_process_events(void) { switch(xptr->event_type) { case XMPP_EVT_LOGIN: - xmpp_presence_notify(xptr->event_jid, "available"); + if (xptr->session_which_generated_this_event != CC->cs_pid) { + xmpp_presence_notify(xptr->event_jid, "available"); + } break; case XMPP_EVT_LOGOUT: - xmpp_presence_notify(xptr->event_jid, "unavailable"); + if (xptr->session_which_generated_this_event != CC->cs_pid) { + xmpp_presence_notify(xptr->event_jid, "unavailable"); + } break; } -- 2.39.2