commit 19b26084e6cd742ee76faa9f4969f39afaadd485 Author: Ailin Nemui Date: Sun Dec 29 23:52:49 2019 +0100 add initial support for sending a capability hash [plus include caps.h, caps_deinit() as per my comment] --- a/src/core/Makefile +++ b/src/core/Makefile @@ -12,6 +12,7 @@ stanzas.c \ tools.c \ popenRWE.c \ + xep/caps.c \ xep/carbons.c \ xep/chatstates.c \ xep/composing.c \ --- /dev/null +++ b/src/core/xep/caps.c @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2007,2008,2009 Colin DIDIER + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + + /* XEP-0115: Entity Capabilities */ + +#define XMLNS_CAPS "http://jabber.org/protocol/caps" + +#include "module.h" +#include "caps.h" +#include "disco.h" +#include "loudmouth/loudmouth.h" + +#include + +static gchar * +ver_hash(void) +{ + GSList *tmp; + GChecksum *sum; + GString *str = g_string_new(NULL); + guint8 *out; + gsize len; + gchar *hash; + g_string_append(str, "client/console//" IRSSI_XMPP_PACKAGE "<"); + for (tmp = disco_my_features(); tmp != NULL; tmp = tmp->next) { + g_string_append(str, tmp->data); + g_string_append_c(str, '<'); + } + sum = g_checksum_new(G_CHECKSUM_SHA1); + g_checksum_update(sum, str->str, str->len); + len = g_checksum_type_get_length(G_CHECKSUM_SHA1); + out = g_new0(guint8, len); + g_checksum_get_digest(sum, out, &len); + hash = g_base64_encode(out, len); + g_free(out); + g_checksum_free(sum); + return hash; +} + +static void +sig_add_caps(XMPP_SERVER_REC *server, LmMessage *lmsg) +{ + gchar *ver; + LmMessageNode *c; + ver = ver_hash(); + c = lm_message_node_add_child(lmsg->node, "c", NULL); + lm_message_node_set_attribute(c, "xmlns", XMLNS_CAPS); + lm_message_node_set_attribute(c, "hash", "sha-1"); + lm_message_node_set_attribute(c, "node", "https://github.com/cdidier/irssi-xmpp"); + lm_message_node_set_attribute(c, "ver", ver); + g_free(ver); +} + +void +caps_init(void) +{ + disco_add_feature(XMLNS_CAPS); + signal_add("xmpp send presence", sig_add_caps); +} + +void +caps_deinit(void) +{ + signal_remove("xmpp send presence", sig_add_caps); +} --- /dev/null +++ b/src/core/xep/caps.h @@ -0,0 +1,9 @@ +#ifndef __CAPS_H +#define __CAPS_H + +__BEGIN_DECLS +void caps_init(void); +void caps_deinit(void); +__END_DECLS + +#endif --- a/src/core/xep/disco.c +++ b/src/core/xep/disco.c @@ -38,6 +38,12 @@ (GCompareFunc)strcmp); } +GSList * +disco_my_features(void) +{ + return my_features; +} + gboolean disco_have_feature(GSList *list, const char *feature) { --- a/src/core/xep/disco.h +++ b/src/core/xep/disco.h @@ -3,6 +3,7 @@ __BEGIN_DECLS void disco_add_feature(char *); +GSList * disco_my_features(void); gboolean disco_have_feature(GSList *, const char *); void disco_request(XMPP_SERVER_REC *, const char *); --- a/src/core/xep/xep.c +++ b/src/core/xep/xep.c @@ -17,6 +17,7 @@ #include "module.h" +#include "caps.h" #include "carbons.h" #include "chatstates.h" #include "composing.h" @@ -33,6 +34,7 @@ xep_init(void) { disco_init(); /* init sevice discovery first */ + caps_init(); carbons_init(); chatstates_init(); composing_init(); @@ -49,6 +51,7 @@ xep_deinit(void) { disco_deinit(); + caps_deinit(); carbons_deinit(); chatstates_deinit(); composing_deinit();