4 * Handle messages sent and received using XMPP (Jabber) protocol
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 * This function is called by the XMPP service's async loop.
53 * If the client session has instant messages waiting, it outputs
54 * unsolicited XML stanzas containing them.
56 void jabber_output_incoming_messages(void) {
58 struct ExpressMessage *ptr;
60 while (CC->FirstExpressMessage != NULL) {
62 begin_critical_section(S_SESSION_TABLE);
63 ptr = CC->FirstExpressMessage;
64 CC->FirstExpressMessage = CC->FirstExpressMessage->next;
65 end_critical_section(S_SESSION_TABLE);
67 cprintf("<message to=\"%s\" from=\"%s\" type=\"chat\">",
70 if (ptr->text != NULL) {
72 cprintf("<body>%s</body>", ptr->text);
75 cprintf("</message>");
81 * Client is sending a message.
83 void jabber_send_message(char *message_to, char *message_body) {
86 struct CitContext *cptr;
88 if (message_body == NULL) return;
89 if (message_to == NULL) return;
90 if (IsEmptyStr(message_to)) return;
91 if (!CC->logged_in) return;
93 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
94 if (cptr->logged_in) {
95 if (!strcasecmp(cptr->cs_inet_email, message_to)) {
96 recp = cptr->user.fullname;
102 message_sent = PerformXmsgHooks(CC->user.fullname, CC->cs_inet_email, recp, message_body);
105 free(XMPP->message_body);
106 XMPP->message_body = NULL;
107 XMPP->message_to[0] = 0;
112 #endif /* HAVE_EXPAT */