Debian Codegraph @

src/core/protocol.c

raw symbols ◀ ▶
Source reconstructed at patch state 3 of 7 — not the installed (fully patched) source.
7 Debian patches touch this file
1 /*
2 * Copyright (C) 2007,2008,2009 Colin DIDIER
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #include "module.h"
19 #include "signals.h"
20 #include "settings.h"
21
22 #include "xmpp-servers.h"
23 #include "rosters-tools.h"
24 #include "tools.h"
25
26 char *pgp_passwd = NULL;
27
28 static void
29 sig_set_presence(XMPP_SERVER_REC *server, const int show, const char *status,
30 const int priority)
31 {
32 LmMessage *lmsg;
33 char *str;
34 const char *pgp_keyid;
35
36 g_return_if_fail(IS_XMPP_SERVER(server));
37 if (!xmpp_presence_changed(show, server->show, status,
38 server->away_reason, priority, server->priority)) {
39 signal_stop();
40 return;
41 }
42
43 lmsg = lm_message_new(NULL, LM_MESSAGE_TYPE_PRESENCE);
44 server->show = show;
45
46 if (!xmpp_priority_out_of_bound(priority))
47 server->priority = priority;
48
49 if (show != XMPP_PRESENCE_AVAILABLE)
50 lm_message_node_add_child(lmsg->node, "show",
51 xmpp_presence_show[server->show]);
52
53 if(server->away_reason) g_free(server->away_reason);
54 server->away_reason = NULL;
55
56 if(!status) status = "";
57 server->away_reason = g_strdup(status);
58 str = xmpp_recode_out(server->away_reason);
59 lm_message_node_add_child(lmsg->node, "status", str);
60 if(!str) str = g_strdup("");
61
62 if((pgp_keyid = settings_get_str("xmpp_pgp"))) {
63 LmMessageNode *x;
64 char *signature = call_gpg("-ab", str, NULL, 0, 1);
65
66 x = lm_message_node_add_child(lmsg->node, "x", signature);
67 lm_message_node_set_attribute(x, "xmlns", "jabber:x:signed");
68
69 free(signature);
70 }
71
72 g_free(str);
73
74 str = g_strdup_printf("%d", server->priority);
75 lm_message_node_add_child(lmsg->node, "priority", str);
76 g_free(str);
77
78 signal_emit("xmpp send presence", 2, server, lmsg);
79 lm_message_unref(lmsg);
80 if (show != XMPP_PRESENCE_AVAILABLE) /* away */
81 signal_emit("event 306", 2, server, server->jid);
82 else if (server->usermode_away) /* unaway */
83 signal_emit("event 305", 2, server, server->jid);
84 }
85
86 static void
87 sig_recv_message(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type,
88 const char *id, const char *from, const char *to)
89 {
90 LmMessageNode *node;
91 char *str, *subject;
92
93 if ((type != LM_MESSAGE_SUB_TYPE_NOT_SET
94 && type != LM_MESSAGE_SUB_TYPE_HEADLINE
95 && type != LM_MESSAGE_SUB_TYPE_NORMAL
96 && type != LM_MESSAGE_SUB_TYPE_CHAT)
97 || server->ischannel(SERVER(server), from))
98 return;
99 node = lm_message_node_get_child(lmsg->node, "subject");
100 if (node != NULL && node->value != NULL && *node->value != '\0') {
101 str = xmpp_recode_in(node->value);
102 subject = g_strconcat("Subject: ", str, (void *)NULL);
103 g_free(str);
104 signal_emit("message private", 4, server, subject, from, from);
105 g_free(subject);
106 }
107 node = lm_message_node_get_child(lmsg->node, "body");
108 if (node != NULL && node->value != NULL && *node->value != '\0') {
109 str = xmpp_recode_in(node->value);
110 if (g_ascii_strncasecmp(str, "/me ", 4) == 0)
111 signal_emit("message xmpp action", 5,
112 server, str+4, from, from,
113 GINT_TO_POINTER(SEND_TARGET_NICK));
114 else
115 signal_emit("message private", 4, server,
116 str, from, from);
117 g_free(str);
118 }
119 }
120
121 void
122 protocol_init(void)
123 {
124 signal_add_first("xmpp set presence", sig_set_presence);
125 signal_add("xmpp recv message", sig_recv_message);
126 }
127
128 void
129 protocol_deinit(void)
130 {
131 signal_remove("xmpp set presence", sig_set_presence);
132 signal_remove("xmpp recv message", sig_recv_message);
133 }