Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add initial support for sending a capability hash #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SRCS= xmpp-commands.c \
rosters-tools.c \
stanzas.c \
tools.c \
xep/caps.c \
xep/chatstates.c \
xep/composing.c \
xep/datetime.c \
Expand Down
4 changes: 2 additions & 2 deletions src/core/module.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define MODULE_NAME "xmpp/core"

#include "irssi-config.h"
#include "common.h"
#include <irssi/irssi-config.h>
#include <irssi/src/common.h>
#include "xmpp.h"
2 changes: 1 addition & 1 deletion src/core/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "rosters-tools.h"
Expand Down
2 changes: 1 addition & 1 deletion src/core/rosters.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <string.h>

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "rosters-tools.h"
Expand Down
4 changes: 2 additions & 2 deletions src/core/stanzas.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/

#include "module.h"
#include "settings.h"
#include "signals.h"
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "tools.h"
Expand Down
6 changes: 3 additions & 3 deletions src/core/tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include <string.h>

#include "module.h"
#include "recode.h"
#include "settings.h"
#include "signals.h"
#include <irssi/src/core/recode.h>
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>

#define XMPP_PRIORITY_MIN -128
#define XMPP_PRIORITY_MAX 127
Expand Down
79 changes: 79 additions & 0 deletions src/core/xep/caps.c
Original file line number Diff line number Diff line change
@@ -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 <irssi/src/core/signals.h>

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);
}
9 changes: 9 additions & 0 deletions src/core/xep/caps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef __CAPS_H
#define __CAPS_H

__BEGIN_DECLS
void caps_init(void);
void caps_deinit(void);
__END_DECLS

#endif
2 changes: 1 addition & 1 deletion src/core/xep/chatstates.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "disco.h"
Expand Down
2 changes: 1 addition & 1 deletion src/core/xep/composing.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <string.h>

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "xmpp-queries.h"
Expand Down
2 changes: 1 addition & 1 deletion src/core/xep/delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "tools.h"
Expand Down
8 changes: 7 additions & 1 deletion src/core/xep/disco.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <string.h>

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "tools.h"
Expand All @@ -38,6 +38,12 @@ disco_add_feature(char *feature)
(GCompareFunc)strcmp);
}

GSList *
disco_my_features(void)
{
return my_features;
}

gboolean
disco_have_feature(GSList *list, const char *feature)
{
Expand Down
1 change: 1 addition & 0 deletions src/core/xep/disco.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

Expand Down
6 changes: 3 additions & 3 deletions src/core/xep/muc-commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include <stdlib.h>

#include "module.h"
#include "settings.h"
#include "signals.h"
#include "window-item-def.h"
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>
#include <irssi/src/core/window-item-def.h>

#include "xmpp-servers.h"
#include "xmpp-commands.h"
Expand Down
8 changes: 4 additions & 4 deletions src/core/xep/muc-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#include <string.h>

#include "module.h"
#include "commands.h"
#include "misc.h"
#include "settings.h"
#include "signals.h"
#include <irssi/src/core/commands.h>
#include <irssi/src/core/misc.h>
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>

#include "rosters-tools.h"
#include "tools.h"
Expand Down
2 changes: 1 addition & 1 deletion src/core/xep/muc-nicklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <string.h>

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "rosters.h"
#include "muc-affiliation.h"
Expand Down
4 changes: 2 additions & 2 deletions src/core/xep/muc-nicklist.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __MUC_NICKLIST_H
#define __MUC_NICKLIST_H

#include "nicklist.h"
#include <irssi/src/core/nicklist.h>
#include "muc.h"

/* Returns XMPP_NICK_REC if it's XMPP channel, NULL if it isn't. */
Expand All @@ -16,7 +16,7 @@


struct _XMPP_NICK_REC {
#include "nick-rec.h"
#include <irssi/src/core/nick-rec.h>

int show;
char *status;
Expand Down
4 changes: 2 additions & 2 deletions src/core/xep/muc-reconnect.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/

#include "module.h"
#include "servers-reconnect.h"
#include "signals.h"
#include <irssi/src/core/servers-reconnect.h>
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "muc.h"
Expand Down
6 changes: 3 additions & 3 deletions src/core/xep/muc.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#include <string.h>

#include "module.h"
#include "commands.h"
#include "settings.h"
#include "signals.h"
#include <irssi/src/core/commands.h>
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>

#include "rosters-tools.h"
#include "tools.h"
Expand Down
6 changes: 3 additions & 3 deletions src/core/xep/muc.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef __MUC_H
#define __MUC_H

#include "channels.h"
#include "channels-setup.h"
#include <irssi/src/core/channels.h>
#include <irssi/src/core/channels-setup.h>
#include "xmpp-servers.h"
#include "tools.h"

Expand Down Expand Up @@ -34,7 +34,7 @@

#define STRUCT_SERVER_REC XMPP_SERVER_REC
struct _MUC_REC {
#include "channel-rec.h"
#include <irssi/src/core/channel-rec.h>

char *nick;
};
Expand Down
2 changes: 1 addition & 1 deletion src/core/xep/oob.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "tools.h"
Expand Down
6 changes: 3 additions & 3 deletions src/core/xep/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
#include <time.h>

#include "module.h"
#include "misc.h"
#include "settings.h"
#include "signals.h"
#include <irssi/src/core/misc.h>
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "xmpp-commands.h"
Expand Down
4 changes: 2 additions & 2 deletions src/core/xep/registration.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <string.h>

#include "module.h"
#include "settings.h"
#include "signals.h"
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>
#include "tools.h"

#include "xmpp-servers.h"
Expand Down
4 changes: 2 additions & 2 deletions src/core/xep/vcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/

#include "module.h"
#include "queries.h"
#include "signals.h"
#include <irssi/src/core/queries.h>
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "xmpp-commands.h"
Expand Down
6 changes: 3 additions & 3 deletions src/core/xep/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#include <string.h>

#include "module.h"
#include "queries.h"
#include "settings.h"
#include "signals.h"
#include <irssi/src/core/queries.h>
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "xmpp-commands.h"
Expand Down
1 change: 1 addition & 0 deletions src/core/xep/xep.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void
xep_init(void)
{
disco_init(); /* init sevice discovery first */
caps_init();
chatstates_init();
composing_init();
delay_init();
Expand Down
12 changes: 6 additions & 6 deletions src/core/xmpp-commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
#include <stdlib.h>

#include "module.h"
#include "channels.h"
#include "nicklist.h"
#include "recode.h"
#include "settings.h"
#include "signals.h"
#include "window-item-def.h"
#include <irssi/src/core/channels.h>
#include <irssi/src/core/nicklist.h>
#include <irssi/src/core/recode.h>
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>
#include <irssi/src/core/window-item-def.h>

#include "xmpp-commands.h"
#include "xmpp-queries.h"
Expand Down
2 changes: 1 addition & 1 deletion src/core/xmpp-commands.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __XMPP_COMMANDS_H
#define __XMPP_COMMANDS_H

#include "commands.h"
#include <irssi/src/core/commands.h>

enum {
XMPP_COMMAND_AWAY,
Expand Down
Loading