Debian Codegraph @

src/core/protocol.c

raw symbols ◀ ▶
Source reconstructed at patch state 4 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 if(signature) {
67 x = lm_message_node_add_child(lmsg->node, "x", signature);
68 lm_message_node_set_attribute(x, "xmlns", "jabber:x:signed");
69
70 free(signature);
71 }
72 }
73
74 g_free(str);
75
76 str = g_strdup_printf("%d", server->priority);
77 lm_message_node_add_child(lmsg->node, "priority", str);
78 g_free(str);
79
80 signal_emit("xmpp send presence", 2, server, lmsg);
81 lm_message_unref(lmsg);
82 if (show != XMPP_PRESENCE_AVAILABLE) /* away */
83 signal_emit("event 306", 2, server, server->jid);
84 else if (server->usermode_away) /* unaway */
85 signal_emit("event 305", 2, server, server->jid);
86 }
87
88 static void
89 sig_recv_message(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type,
90 const char *id, const char *from, const char *to)
91 {
92 LmMessageNode *node;
93 char *str, *subject;
94
95 if ((type != LM_MESSAGE_SUB_TYPE_NOT_SET
96 && type != LM_MESSAGE_SUB_TYPE_HEADLINE
97 && type != LM_MESSAGE_SUB_TYPE_NORMAL
98 && type != LM_MESSAGE_SUB_TYPE_CHAT)
99 || server->ischannel(SERVER(server), from))
100 return;
101 node = lm_message_node_get_child(lmsg->node, "subject");
102 if (node != NULL && node->value != NULL && *node->value != '\0') {
103 str = xmpp_recode_in(node->value);
104 subject = g_strconcat("Subject: ", str, (void *)NULL);
105 g_free(str);
106 signal_emit("message private", 4, server, subject, from, from);
107 g_free(subject);
108 }
109 node = lm_message_node_get_child(lmsg->node, "body");
110 if (node != NULL && node->value != NULL && *node->value != '\0') {
111 str = xmpp_recode_in(node->value);
112 if (g_ascii_strncasecmp(str, "/me ", 4) == 0)
113 signal_emit("message xmpp action", 5,
114 server, str+4, from, from,
115 GINT_TO_POINTER(SEND_TARGET_NICK));
116 else
117 signal_emit("message private", 4, server,
118 str, from, from);
119 g_free(str);
120 }
121 }
122
123 void
124 protocol_init(void)
125 {
126 signal_add_first("xmpp set presence", sig_set_presence);
127 signal_add("xmpp recv message", sig_recv_message);
128 }
129
130 void
131 protocol_deinit(void)
132 {
133 signal_remove("xmpp set presence", sig_set_presence);
134 signal_remove("xmpp recv message", sig_recv_message);
135 }