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.
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.
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 CitContext *CCC = CC;
69 struct ExpressMessage *ptr;
71 while (CCC->FirstExpressMessage != NULL) {
73 begin_critical_section(S_SESSION_TABLE);
74 ptr = CCC->FirstExpressMessage;
75 CCC->FirstExpressMessage = CCC->FirstExpressMessage->next;
76 end_critical_section(S_SESSION_TABLE);
79 XPUT("<message type=\"chat\" to=\"");
80 XPutProp(Xmpp->client_jid, strlen(Xmpp->client_jid));
82 XPutProp(ptr->sender_email, strlen(ptr->sender_email));
85 if (ptr->text != NULL) {
88 XPutBody(ptr->text, strlen(ptr->text));
99 * Client is sending a message.
101 void xmpp_send_message(char *message_to, char *message_body) {
102 struct CitContext *CCC = CC;
104 struct CitContext *cptr;
106 if (message_body == NULL) return;
107 if (message_to == NULL) return;
108 if (IsEmptyStr(message_to)) return;
109 if (!CCC->logged_in) return;
111 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
112 if ( (cptr->logged_in)
113 && (cptr->can_receive_im)
114 && (!strcasecmp(cptr->cs_inet_email, message_to))
116 recp = cptr->user.fullname;
121 PerformXmsgHooks(CCC->user.fullname, CCC->cs_inet_email, recp, message_body);
124 free(XMPP->message_body);
125 XMPP->message_body = NULL;
126 XMPP->message_to[0] = 0;
127 time(&CCC->lastidle);
129 void xmpp_end_message(void *data, const char *supplied_el, const char **attr)
131 xmpp_send_message(XMPP->message_to, XMPP->message_body);
132 XMPP->html_tag_level = 0;
137 CTDL_MODULE_INIT(xmpp_message)
140 AddXMPPEndHandler(HKEY("message"), xmpp_end_message, 0);
142 return "xmpp_message";