From 663d4bcc6c6f5563b98d11e4893a80b11a3c8132 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 29 Nov 2007 23:00:44 +0000 Subject: [PATCH] Initial code to output any instant messages which have arrived for the user. The Citadel server's built-in infrastructure for asynchronous (unsolicited) protocol messages made this really easy. --- citadel/modules/jabber/serv_xmpp.c | 16 ++++- citadel/modules/jabber/serv_xmpp.h | 1 + citadel/modules/jabber/xmpp_messages.c | 84 ++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 citadel/modules/jabber/xmpp_messages.c diff --git a/citadel/modules/jabber/serv_xmpp.c b/citadel/modules/jabber/serv_xmpp.c index ecf73671c..31c0142bc 100644 --- a/citadel/modules/jabber/serv_xmpp.c +++ b/citadel/modules/jabber/serv_xmpp.c @@ -89,6 +89,8 @@ void xmpp_stream_start(void *data, const char *supplied_el, const char **attr) } cprintf(""); + + CC->is_async = 1; /* XMPP sessions are inherently async-capable */ } @@ -354,6 +356,15 @@ void xmpp_command_loop(void) { XML_Parse(XMPP->xp, cmdbuf, 1, 0); } + +/* + * Async loop for XMPP sessions (handles the transmission of unsolicited stanzas) + */ +void xmpp_async_loop(void) { + jabber_output_incoming_messages(); +} + + const char *CitadelServiceXMPP="XMPP"; #endif /* HAVE_EXPAT */ @@ -362,12 +373,11 @@ CTDL_MODULE_INIT(jabber) { #ifdef HAVE_EXPAT if (!threading) { - /* CtdlRegisterServiceHook(config.c_xmpp_port, FIXME */ - CtdlRegisterServiceHook(5222, + CtdlRegisterServiceHook(5222, /* FIXME change to config.c_xmpp_port */ NULL, xmpp_greeting, xmpp_command_loop, - NULL, + xmpp_async_loop, CitadelServiceXMPP); CtdlRegisterSessionHook(xmpp_cleanup_function, EVT_STOP); #else diff --git a/citadel/modules/jabber/serv_xmpp.h b/citadel/modules/jabber/serv_xmpp.h index e45a744bc..f6f3438a4 100644 --- a/citadel/modules/jabber/serv_xmpp.h +++ b/citadel/modules/jabber/serv_xmpp.h @@ -31,3 +31,4 @@ void xmpp_sasl_auth(char *, char *); void xmpp_output_auth_mechs(void); void xmpp_query_namespace(char *, char *, char *, char *); void jabber_wholist_presence_dump(void); +void jabber_output_incoming_messages(void); diff --git a/citadel/modules/jabber/xmpp_messages.c b/citadel/modules/jabber/xmpp_messages.c new file mode 100644 index 000000000..046f7586a --- /dev/null +++ b/citadel/modules/jabber/xmpp_messages.c @@ -0,0 +1,84 @@ +/* + * $Id$ + * + * Handle messages sent and received using XMPP (Jabber) protocol + * + * Copyright (c) 2007 by Art Cancro + * This code is released under the terms of the GNU General Public License. + * + */ + +#include "sysdep.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif + +#include +#include +#include +#include +#include +#include "citadel.h" +#include "server.h" +#include "citserver.h" +#include "support.h" +#include "config.h" +#include "internet_addressing.h" +#include "md5.h" +#include "ctdl_module.h" + +#ifdef HAVE_EXPAT +#include +#include "serv_xmpp.h" + + +/* + * This function is called by the XMPP service's async loop. + * If the client session has instant messages waiting, it outputs + * unsolicited XML stanzas containing them. + */ +void jabber_output_incoming_messages(void) { + + struct ExpressMessage *ptr; + + while (CC->FirstExpressMessage != NULL) { + + begin_critical_section(S_SESSION_TABLE); + ptr = CC->FirstExpressMessage; + CC->FirstExpressMessage = CC->FirstExpressMessage->next; + end_critical_section(S_SESSION_TABLE); + + /* FIXME we have to get the sender's email address. This may involve tweaking + * the core IM module a bit. + */ + cprintf("", XMPP->client_jid); + if (ptr->text != NULL) { + cprintf(""); + memfmout(ptr->text, 0, "\n"); + if (ptr->text[strlen(ptr->text)-1] != '\n') cprintf("\n"); + free(ptr->text); + cprintf(""); + } + cprintf(""); + free(ptr); + } +} + + +#endif /* HAVE_EXPAT */ -- 2.39.2