4 * Handle messages sent and received using XMPP (Jabber) protocol
6 * Copyright (c) 2007 by Art Cancro
7 * This code is released under the terms of the GNU General Public License.
19 #include <sys/types.h>
21 #if TIME_WITH_SYS_TIME
22 # include <sys/time.h>
26 # include <sys/time.h>
37 #include <libcitadel.h>
40 #include "citserver.h"
43 #include "internet_addressing.h"
45 #include "ctdl_module.h"
46 #include "serv_xmpp.h"
50 * This function is called by the XMPP service's async loop.
51 * If the client session has instant messages waiting, it outputs
52 * unsolicited XML stanzas containing them.
54 void jabber_output_incoming_messages(void) {
56 struct ExpressMessage
*ptr
;
58 while (CC
->FirstExpressMessage
!= NULL
) {
60 begin_critical_section(S_SESSION_TABLE
);
61 ptr
= CC
->FirstExpressMessage
;
62 CC
->FirstExpressMessage
= CC
->FirstExpressMessage
->next
;
63 end_critical_section(S_SESSION_TABLE
);
65 cprintf("<message to=\"%s\" from=\"%s\" type=\"chat\">",
68 if (ptr
->text
!= NULL
) {
70 cprintf("<body>%s</body>", ptr
->text
);
73 cprintf("</message>");
79 * Client is sending a message.
81 void jabber_send_message(char *message_to
, char *message_body
) {
84 struct CitContext
*cptr
;
86 if (message_body
== NULL
) return;
87 if (message_to
== NULL
) return;
88 if (IsEmptyStr(message_to
)) return;
89 if (!CC
->logged_in
) return;
91 for (cptr
= ContextList
; cptr
!= NULL
; cptr
= cptr
->next
) {
92 if (cptr
->logged_in
) {
93 if (!strcasecmp(cptr
->cs_inet_email
, message_to
)) {
94 recp
= cptr
->user
.fullname
;
100 message_sent
= PerformXmsgHooks(CC
->user
.fullname
, CC
->cs_inet_email
, recp
, message_body
);
103 free(XMPP
->message_body
);
104 XMPP
->message_body
= NULL
;
105 XMPP
->message_to
[0] = 0;