2 * Handle messages sent and received using XMPP (Jabber) protocol
4 * Copyright (c) 2007-2014 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"
49 #include "ctdl_module.h"
50 #include "serv_xmpp.h"
54 * This function is called by the XMPP service's async loop.
55 * If the client session has instant messages waiting, it outputs
56 * unsolicited XML stanzas containing them.
58 void xmpp_output_incoming_messages(void)
60 struct CitContext *CCC = CC;
62 struct ExpressMessage *ptr;
64 while (CCC->FirstExpressMessage != NULL) {
66 begin_critical_section(S_SESSION_TABLE);
67 ptr = CCC->FirstExpressMessage;
68 CCC->FirstExpressMessage = CCC->FirstExpressMessage->next;
69 end_critical_section(S_SESSION_TABLE);
71 XPrint(HKEY("message"), 0,
72 XCPROPERTY("type", "chat"),
73 XPROPERTY("to", Xmpp->client_jid, strlen(Xmpp->client_jid)),
74 XPROPERTY("from", ptr->sender_email, strlen(ptr->sender_email)),
77 if (ptr->text != NULL) {
79 XPrint(HKEY("body"), XCLOSED,
80 XBODY(ptr->text, strlen(ptr->text)),
91 * Client is sending a message.
93 void xmpp_send_message(char *message_to, char *message_body) {
94 struct CitContext *CCC = CC;
96 struct CitContext *cptr;
98 if (message_body == NULL) return;
99 if (message_to == NULL) return;
100 if (IsEmptyStr(message_to)) return;
101 if (!CCC->logged_in) return;
103 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
104 if ( (cptr->logged_in)
105 && (cptr->can_receive_im)
106 && (!strcasecmp(cptr->cs_inet_email, message_to))
108 recp = cptr->user.fullname;
113 PerformXmsgHooks(CCC->user.fullname, CCC->cs_inet_email, recp, message_body);
116 free(XMPP->message_body);
117 XMPP->message_body = NULL;
118 XMPP->message_to[0] = 0;
119 time(&CCC->lastidle);
123 void xmpp_end_message(void *data, const char *supplied_el, const char **attr)
125 safestrncpy(XMPP->message_to, ChrPtr(XMPP->Message.to), sizeof(XMPP->message_to));
126 xmpp_send_message(XMPP->message_to, XMPP->message_body);
127 XMPP->html_tag_level = 0;
132 CTDL_MODULE_INIT(xmpp_message)
135 AddXMPPEndHandler(HKEY("message"), xmpp_end_message, 0);
137 return "xmpp_message";