citadel
About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).
  Fossies Dox: citadel.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

xmpp_messages.c
Go to the documentation of this file.
1/*
2 * Handle messages sent and received using XMPP (Jabber) protocol
3 *
4 * Copyright (c) 2007-2010 by Art Cancro
5 *
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.
8 *
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.
13 */
14
15#include "sysdep.h"
16#include <stdlib.h>
17#include <unistd.h>
18#include <stdio.h>
19#include <fcntl.h>
20#include <signal.h>
21#include <pwd.h>
22#include <errno.h>
23#include <sys/types.h>
24#include <time.h>
25#include <sys/wait.h>
26#include <string.h>
27#include <limits.h>
28#include <ctype.h>
29#include <expat.h>
30#include <libcitadel.h>
31#include "citadel.h"
32#include "server.h"
33#include "citserver.h"
34#include "support.h"
35#include "config.h"
36#include "internet_addressing.h"
37#include "ctdl_module.h"
38#include "serv_xmpp.h"
39
40
41/*
42 * This function is called by the XMPP service's async loop.
43 * If the client session has instant messages waiting, it outputs
44 * unsolicited XML stanzas containing them.
45 */
47
48 struct ExpressMessage *ptr;
49 char xmlbuf1[4096];
50 char xmlbuf2[4096];
51
52 while (CC->FirstExpressMessage != NULL) {
53
55 ptr = CC->FirstExpressMessage;
56 CC->FirstExpressMessage = CC->FirstExpressMessage->next;
58
59 cprintf("<message to=\"%s\" from=\"%s\" type=\"chat\">",
60 xmlesc(xmlbuf1, XMPP->client_jid, sizeof xmlbuf1),
61 xmlesc(xmlbuf2, ptr->sender_email, sizeof xmlbuf2)
62 );
63 if (ptr->text != NULL) {
64 striplt(ptr->text);
65 cprintf("<body>%s</body>", xmlesc(xmlbuf1, ptr->text, sizeof xmlbuf1));
66 free(ptr->text);
67 }
68 cprintf("</message>");
69 free(ptr);
70 }
71}
72
73
74/*
75 * Client is sending a message.
76 */
77void xmpp_send_message(char *message_to, char *message_body) {
78 char *recp = NULL;
79 struct CitContext *cptr;
80
81 if (message_body == NULL) return;
82 if (message_to == NULL) return;
83 if (IsEmptyStr(message_to)) return;
84 if (!CC->logged_in) return;
85
86 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
87 if ( (cptr->logged_in)
88 && (cptr->can_receive_im)
89 && (!strcasecmp(cptr->cs_principal_id, message_to))
90 ) {
91 recp = cptr->user.fullname;
92 }
93 }
94
95 if (recp) {
96 PerformXmsgHooks(CC->user.fullname, CC->cs_principal_id, recp, message_body);
97 }
98
99 free(XMPP->message_body);
100 XMPP->message_body = NULL;
101 XMPP->message_to[0] = 0;
102 time(&CC->lastidle);
103}
104
CitContext * ContextList
Definition: context.c:22
#define CC
Definition: context.h:140
void free(void *)
int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg)
char * xmlesc(char *buf, char *str, int bufsiz)
Definition: serv_xmpp.c:100
#define XMPP
Definition: serv_xmpp.h:43
@ S_SESSION_TABLE
Definition: server.h:137
int logged_in
Definition: context.h:70
struct ctdluser user
Definition: context.h:109
CitContext * next
Definition: context.h:42
int can_receive_im
Definition: context.h:81
char cs_principal_id[256]
Definition: context.h:94
char sender_email[256]
Definition: server.h:123
char * text
Definition: server.h:124
char fullname[64]
Definition: citadel.h:90
void cprintf(const char *format,...)
Definition: sysdep.c:381
void begin_critical_section(int which_one)
Definition: threads.c:67
void end_critical_section(int which_one)
Definition: threads.c:85
void xmpp_output_incoming_messages(void)
Definition: xmpp_messages.c:46
void xmpp_send_message(char *message_to, char *message_body)
Definition: xmpp_messages.c:77