2 * Handle messages sent and received using XMPP (Jabber) protocol
4 * Copyright (c) 2007-2010 by Art Cancro
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
23 #include <sys/types.h>
25 #if TIME_WITH_SYS_TIME
26 # include <sys/time.h>
30 # include <sys/time.h>
41 #include <libcitadel.h>
44 #include "citserver.h"
47 #include "internet_addressing.h"
48 #include "ctdl_module.h"
49 #include "serv_xmpp.h"
53 * This function is called by the XMPP service's async loop.
54 * If the client session has instant messages waiting, it outputs
55 * unsolicited XML stanzas containing them.
57 void xmpp_output_incoming_messages(void) {
59 struct ExpressMessage *ptr;
63 while (CC->FirstExpressMessage != NULL) {
65 begin_critical_section(S_SESSION_TABLE);
66 ptr = CC->FirstExpressMessage;
67 CC->FirstExpressMessage = CC->FirstExpressMessage->next;
68 end_critical_section(S_SESSION_TABLE);
70 cprintf("<message to=\"%s\" from=\"%s\" type=\"chat\">",
71 xmlesc(xmlbuf1, XMPP->client_jid, sizeof xmlbuf1),
72 xmlesc(xmlbuf2, ptr->sender_email, sizeof xmlbuf2)
74 if (ptr->text != NULL) {
76 cprintf("<body>%s</body>", xmlesc(xmlbuf1, ptr->text, sizeof xmlbuf1));
79 cprintf("</message>");
86 * Client is sending a message.
88 void xmpp_send_message(char *message_to, char *message_body) {
90 struct CitContext *cptr;
92 if (message_body == NULL) return;
93 if (message_to == NULL) return;
94 if (IsEmptyStr(message_to)) return;
95 if (!CC->logged_in) return;
97 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
98 if ( (cptr->logged_in)
99 && (cptr->can_receive_im)
100 && (!strcasecmp(cptr->cs_inet_email, message_to))
102 recp = cptr->user.fullname;
107 PerformXmsgHooks(CC->user.fullname, CC->cs_inet_email, recp, message_body);
110 free(XMPP->message_body);
111 XMPP->message_body = NULL;
112 XMPP->message_to[0] = 0;