4 * Handle messages sent and received using XMPP (Jabber) protocol
6 * Copyright (c) 2007-2009 by Art Cancro
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include <sys/types.h>
34 #if TIME_WITH_SYS_TIME
35 # include <sys/time.h>
39 # include <sys/time.h>
50 #include <libcitadel.h>
53 #include "citserver.h"
56 #include "internet_addressing.h"
58 #include "ctdl_module.h"
59 #include "serv_xmpp.h"
63 * This function is called by the XMPP service's async loop.
64 * If the client session has instant messages waiting, it outputs
65 * unsolicited XML stanzas containing them.
67 void xmpp_output_incoming_messages(void) {
69 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\">",
81 if (ptr->text != NULL) {
83 cprintf("<body>%s</body>", ptr->text);
86 cprintf("</message>");
92 * Client is sending a message.
94 void xmpp_send_message(char *message_to, char *message_body) {
97 struct CitContext *cptr;
99 if (message_body == NULL) return;
100 if (message_to == NULL) return;
101 if (IsEmptyStr(message_to)) return;
102 if (!CC->logged_in) return;
104 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
105 if ( (cptr->logged_in)
106 && (cptr->can_receive_im)
107 && (!strcasecmp(cptr->cs_inet_email, message_to))
109 recp = cptr->user.fullname;
114 message_sent = PerformXmsgHooks(CC->user.fullname, CC->cs_inet_email, recp, message_body);
117 free(XMPP->message_body);
118 XMPP->message_body = NULL;
119 XMPP->message_to[0] = 0;