| •1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 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 |
} |