* Restored the '(none)' and '(nothing)' displays in the summary screen when the Tasks...
[citadel.git] / citadel / modules / jabber / xmpp_messages.c
blob6ae5e83b0df1b1d46d2e7801901983cf8b72c5e7
1 /*
2 * $Id$
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.
9 */
11 #include "sysdep.h"
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <stdio.h>
15 #include <fcntl.h>
16 #include <signal.h>
17 #include <pwd.h>
18 #include <errno.h>
19 #include <sys/types.h>
21 #if TIME_WITH_SYS_TIME
22 # include <sys/time.h>
23 # include <time.h>
24 #else
25 # if HAVE_SYS_TIME_H
26 # include <sys/time.h>
27 # else
28 # include <time.h>
29 # endif
30 #endif
32 #include <sys/wait.h>
33 #include <string.h>
34 #include <limits.h>
35 #include <ctype.h>
36 #include <expat.h>
37 #include <libcitadel.h>
38 #include "citadel.h"
39 #include "server.h"
40 #include "citserver.h"
41 #include "support.h"
42 #include "config.h"
43 #include "internet_addressing.h"
44 #include "md5.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\">",
66 XMPP->client_jid,
67 ptr->sender_email);
68 if (ptr->text != NULL) {
69 striplt(ptr->text);
70 cprintf("<body>%s</body>", ptr->text);
71 free(ptr->text);
73 cprintf("</message>");
74 free(ptr);
79 * Client is sending a message.
81 void jabber_send_message(char *message_to, char *message_body) {
82 char *recp = NULL;
83 int message_sent = 0;
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;
99 if (recp) {
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;
106 time(&CC->lastidle);