2 * Handle messages sent and received using XMPP (Jabber) protocol
4 * Copyright (c) 2007-2010 by Art Cancro
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <sys/types.h>
32 #if TIME_WITH_SYS_TIME
33 # include <sys/time.h>
37 # include <sys/time.h>
48 #include <libcitadel.h>
51 #include "citserver.h"
54 #include "internet_addressing.h"
56 #include "ctdl_module.h"
57 #include "serv_xmpp.h"
61 * This function is called by the XMPP service's async loop.
62 * If the client session has instant messages waiting, it outputs
63 * unsolicited XML stanzas containing them.
65 void xmpp_output_incoming_messages(void) {
67 struct ExpressMessage *ptr;
71 while (CC->FirstExpressMessage != NULL) {
73 begin_critical_section(S_SESSION_TABLE);
74 ptr = CC->FirstExpressMessage;
75 CC->FirstExpressMessage = CC->FirstExpressMessage->next;
76 end_critical_section(S_SESSION_TABLE);
78 cprintf("<message to=\"%s\" from=\"%s\" type=\"chat\">",
79 xmlesc(xmlbuf1, XMPP->client_jid, sizeof xmlbuf1),
80 xmlesc(xmlbuf2, ptr->sender_email, sizeof xmlbuf2)
82 if (ptr->text != NULL) {
84 cprintf("<body>%s</body>", xmlesc(xmlbuf1, ptr->text, sizeof xmlbuf1));
87 cprintf("</message>");
93 * Client is sending a message.
95 void xmpp_send_message(char *message_to, char *message_body) {
98 struct CitContext *cptr;
100 if (message_body == NULL) return;
101 if (message_to == NULL) return;
102 if (IsEmptyStr(message_to)) return;
103 if (!CC->logged_in) return;
105 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
106 if ( (cptr->logged_in)
107 && (cptr->can_receive_im)
108 && (!strcasecmp(cptr->cs_inet_email, message_to))
110 recp = cptr->user.fullname;
115 message_sent = PerformXmsgHooks(CC->user.fullname, CC->cs_inet_email, recp, message_body);
118 free(XMPP->message_body);
119 XMPP->message_body = NULL;
120 XMPP->message_to[0] = 0;