| 1 |
commit 19b26084e6cd742ee76faa9f4969f39afaadd485 |
| 2 |
Author: Ailin Nemui <[email protected]> |
| 3 |
Date: Sun Dec 29 23:52:49 2019 +0100 |
| 4 |
|
| 5 |
add initial support for sending a capability hash |
| 6 |
|
| 7 |
[plus include caps.h, caps_deinit() as per my comment] |
| 8 |
|
| 9 |
--- a/src/core/Makefile |
| 10 |
+++ b/src/core/Makefile |
| 11 |
@@ -12,6 +12,7 @@ |
| 12 |
stanzas.c \ |
| 13 |
tools.c \ |
| 14 |
popenRWE.c \ |
| 15 |
+ xep/caps.c \ |
| 16 |
xep/carbons.c \ |
| 17 |
xep/chatstates.c \ |
| 18 |
xep/composing.c \ |
| 19 |
--- /dev/null |
| 20 |
+++ b/src/core/xep/caps.c |
| 21 |
@@ -0,0 +1,79 @@ |
| 22 |
+/* |
| 23 |
+ * Copyright (C) 2007,2008,2009 Colin DIDIER |
| 24 |
+ * |
| 25 |
+ * This program is free software; you can redistribute it and/or modify |
| 26 |
+ * it under the terms of the GNU General Public License version 2 as |
| 27 |
+ * published by the Free Software Foundation. |
| 28 |
+ * |
| 29 |
+ * This program is distributed in the hope that it will be useful, |
| 30 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 31 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 32 |
+ * GNU General Public License for more details. |
| 33 |
+ * |
| 34 |
+ * You should have received a copy of the GNU General Public License along |
| 35 |
+ * with this program; if not, write to the Free Software Foundation, Inc., |
| 36 |
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 37 |
+ */ |
| 38 |
+ |
| 39 |
+ /* XEP-0115: Entity Capabilities */ |
| 40 |
+ |
| 41 |
+#define XMLNS_CAPS "http://jabber.org/protocol/caps" |
| 42 |
+ |
| 43 |
+#include "module.h" |
| 44 |
+#include "caps.h" |
| 45 |
+#include "disco.h" |
| 46 |
+#include "loudmouth/loudmouth.h" |
| 47 |
+ |
| 48 |
+#include <irssi/src/core/signals.h> |
| 49 |
+ |
| 50 |
+static gchar * |
| 51 |
+ver_hash(void) |
| 52 |
+{ |
| 53 |
+ GSList *tmp; |
| 54 |
+ GChecksum *sum; |
| 55 |
+ GString *str = g_string_new(NULL); |
| 56 |
+ guint8 *out; |
| 57 |
+ gsize len; |
| 58 |
+ gchar *hash; |
| 59 |
+ g_string_append(str, "client/console//" IRSSI_XMPP_PACKAGE "<"); |
| 60 |
+ for (tmp = disco_my_features(); tmp != NULL; tmp = tmp->next) { |
| 61 |
+ g_string_append(str, tmp->data); |
| 62 |
+ g_string_append_c(str, '<'); |
| 63 |
+ } |
| 64 |
+ sum = g_checksum_new(G_CHECKSUM_SHA1); |
| 65 |
+ g_checksum_update(sum, str->str, str->len); |
| 66 |
+ len = g_checksum_type_get_length(G_CHECKSUM_SHA1); |
| 67 |
+ out = g_new0(guint8, len); |
| 68 |
+ g_checksum_get_digest(sum, out, &len); |
| 69 |
+ hash = g_base64_encode(out, len); |
| 70 |
+ g_free(out); |
| 71 |
+ g_checksum_free(sum); |
| 72 |
+ return hash; |
| 73 |
+} |
| 74 |
+ |
| 75 |
+static void |
| 76 |
+sig_add_caps(XMPP_SERVER_REC *server, LmMessage *lmsg) |
| 77 |
+{ |
| 78 |
+ gchar *ver; |
| 79 |
+ LmMessageNode *c; |
| 80 |
+ ver = ver_hash(); |
| 81 |
+ c = lm_message_node_add_child(lmsg->node, "c", NULL); |
| 82 |
+ lm_message_node_set_attribute(c, "xmlns", XMLNS_CAPS); |
| 83 |
+ lm_message_node_set_attribute(c, "hash", "sha-1"); |
| 84 |
+ lm_message_node_set_attribute(c, "node", "https://github.com/cdidier/irssi-xmpp"); |
| 85 |
+ lm_message_node_set_attribute(c, "ver", ver); |
| 86 |
+ g_free(ver); |
| 87 |
+} |
| 88 |
+ |
| 89 |
+void |
| 90 |
+caps_init(void) |
| 91 |
+{ |
| 92 |
+ disco_add_feature(XMLNS_CAPS); |
| 93 |
+ signal_add("xmpp send presence", sig_add_caps); |
| 94 |
+} |
| 95 |
+ |
| 96 |
+void |
| 97 |
+caps_deinit(void) |
| 98 |
+{ |
| 99 |
+ signal_remove("xmpp send presence", sig_add_caps); |
| 100 |
+} |
| 101 |
--- /dev/null |
| 102 |
+++ b/src/core/xep/caps.h |
| 103 |
@@ -0,0 +1,9 @@ |
| 104 |
+#ifndef __CAPS_H |
| 105 |
+#define __CAPS_H |
| 106 |
+ |
| 107 |
+__BEGIN_DECLS |
| 108 |
+void caps_init(void); |
| 109 |
+void caps_deinit(void); |
| 110 |
+__END_DECLS |
| 111 |
+ |
| 112 |
+#endif |
| 113 |
--- a/src/core/xep/disco.c |
| 114 |
+++ b/src/core/xep/disco.c |
| 115 |
@@ -38,6 +38,12 @@ |
| 116 |
(GCompareFunc)strcmp); |
| 117 |
} |
| 118 |
|
| 119 |
+GSList * |
| 120 |
+disco_my_features(void) |
| 121 |
+{ |
| 122 |
+ return my_features; |
| 123 |
+} |
| 124 |
+ |
| 125 |
gboolean |
| 126 |
disco_have_feature(GSList *list, const char *feature) |
| 127 |
{ |
| 128 |
--- a/src/core/xep/disco.h |
| 129 |
+++ b/src/core/xep/disco.h |
| 130 |
@@ -3,6 +3,7 @@ |
| 131 |
|
| 132 |
__BEGIN_DECLS |
| 133 |
void disco_add_feature(char *); |
| 134 |
+GSList * disco_my_features(void); |
| 135 |
gboolean disco_have_feature(GSList *, const char *); |
| 136 |
void disco_request(XMPP_SERVER_REC *, const char *); |
| 137 |
|
| 138 |
--- a/src/core/xep/xep.c |
| 139 |
+++ b/src/core/xep/xep.c |
| 140 |
@@ -17,6 +17,7 @@ |
| 141 |
|
| 142 |
#include "module.h" |
| 143 |
|
| 144 |
+#include "caps.h" |
| 145 |
#include "carbons.h" |
| 146 |
#include "chatstates.h" |
| 147 |
#include "composing.h" |
| 148 |
@@ -33,6 +34,7 @@ |
| 149 |
xep_init(void) |
| 150 |
{ |
| 151 |
disco_init(); /* init sevice discovery first */ |
| 152 |
+ caps_init(); |
| 153 |
carbons_init(); |
| 154 |
chatstates_init(); |
| 155 |
composing_init(); |
| 156 |
@@ -49,6 +51,7 @@ |
| 157 |
xep_deinit(void) |
| 158 |
{ |
| 159 |
disco_deinit(); |
| 160 |
+ caps_deinit(); |
| 161 |
carbons_deinit(); |
| 162 |
chatstates_deinit(); |
| 163 |
composing_deinit(); |