Debian Codegraph @

src/core/xep/caps.c

raw symbols ◀ ▶ SCIP
1 Debian patch 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 /* XEP-0115: Entity Capabilities */
19
20 #define XMLNS_CAPS "http://jabber.org/protocol/caps"
21
22 #include "module.h"
23 #include "caps.h"
24 #include "disco.h"
25 #include "loudmouth/loudmouth.h"
26
27 #include <irssi/src/core/signals.h>
28
29 static gchar *
30 ver_hash(void)
31 {
32 GSList *tmp;
33 GChecksum *sum;
34 GString *str = g_string_new(NULL);
35 guint8 *out;
36 gsize len;
37 gchar *hash;
38 g_string_append(str, "client/console//" IRSSI_XMPP_PACKAGE "<");
39 for (tmp = disco_my_features(); tmp != NULL; tmp = tmp->next) {
40 g_string_append(str, tmp->data);
41 g_string_append_c(str, '<');
42 }
43 sum = g_checksum_new(G_CHECKSUM_SHA1);
44 g_checksum_update(sum, str->str, str->len);
45 len = g_checksum_type_get_length(G_CHECKSUM_SHA1);
46 out = g_new0(guint8, len);
47 g_checksum_get_digest(sum, out, &len);
48 hash = g_base64_encode(out, len);
49 g_free(out);
50 g_checksum_free(sum);
51 return hash;
52 }
53
54 static void
55 sig_add_caps(XMPP_SERVER_REC *server, LmMessage *lmsg)
56 {
57 gchar *ver;
58 LmMessageNode *c;
59 ver = ver_hash();
60 c = lm_message_node_add_child(lmsg->node, "c", NULL);
61 lm_message_node_set_attribute(c, "xmlns", XMLNS_CAPS);
62 lm_message_node_set_attribute(c, "hash", "sha-1");
63 lm_message_node_set_attribute(c, "node", "https://github.com/cdidier/irssi-xmpp");
64 lm_message_node_set_attribute(c, "ver", ver);
65 g_free(ver);
66 }
67
68 void
69 caps_init(void)
70 {
71 disco_add_feature(XMLNS_CAPS);
72 signal_add("xmpp send presence", sig_add_caps);
73 }
74
75 void
76 caps_deinit(void)
77 {
78 signal_remove("xmpp send presence", sig_add_caps);
79 }