mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Started work on creating sha-1 caps hash
This commit is contained in:
parent
4ecb69bfab
commit
64d81c7c4c
26
src/common.c
26
src/common.c
@ -167,3 +167,29 @@ prof_getline(FILE *stream)
|
||||
free(buf);
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
octet_compare(unsigned char *str1, unsigned char *str2)
|
||||
{
|
||||
if ((strcmp((char *)str1, "") == 0) && (strcmp((char *)str2, "") == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((strcmp((char *)str1, "") == 0) && (strcmp((char *)str2, "") != 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((strcmp((char *)str1, "") != 0) && (strcmp((char *)str2, "") == 0)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (str1[0] == str2[0]) {
|
||||
return octet_compare(&str1[1], &str2[1]);
|
||||
}
|
||||
|
||||
if (str1[0] < str2[0]) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -51,5 +51,6 @@ char * str_replace(const char *string, const char *substr,
|
||||
int str_contains(char str[], int size, char ch);
|
||||
char* encode_xml(const char * const xml);
|
||||
char * prof_getline(FILE *stream);
|
||||
int octet_compare(unsigned char *str1, unsigned char *str2);
|
||||
|
||||
#endif
|
||||
|
70
src/jabber.c
70
src/jabber.c
@ -181,7 +181,7 @@ jabber_disconnect(void)
|
||||
}
|
||||
|
||||
char *
|
||||
jabber_get_sha1_caps_str(void)
|
||||
jabber_get_local_sha1_caps_str(void)
|
||||
{
|
||||
GString *str = g_string_new("");
|
||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||
@ -202,6 +202,74 @@ jabber_get_sha1_caps_str(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
sha1_caps_str(xmpp_stanza_t *query)
|
||||
{
|
||||
GSList *identities = NULL;
|
||||
GSList *features = NULL;
|
||||
|
||||
GString *s = g_string_new("");
|
||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||
|
||||
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
|
||||
while (child != NULL) {
|
||||
if (strcmp(xmpp_stanza_get_name(child), STANZA_NAME_IDENTITY) == 0) {
|
||||
char *category = xmpp_stanza_get_attribute(child, "category");
|
||||
char *type = xmpp_stanza_get_attribute(child, "type");
|
||||
char *lang = xmpp_stanza_get_attribute(child, "xml:lang");
|
||||
char *name = xmpp_stanza_get_attribute(child, "name");
|
||||
|
||||
GString *identity_str = g_string_new(category);
|
||||
g_string_append(identity_str, "/");
|
||||
if (type != NULL) {
|
||||
g_string_append(identity_str, type);
|
||||
}
|
||||
g_string_append(identity_str, "/");
|
||||
if (lang != NULL) {
|
||||
g_string_append(identity_str, lang);
|
||||
}
|
||||
g_string_append(identity_str, "/");
|
||||
if (name != NULL) {
|
||||
g_string_append(identity_str, name);
|
||||
}
|
||||
g_string_append(identity_str, "<");
|
||||
identities = g_slist_insert_sorted(identities, identity_str, (GCompareFunc)octet_compare);
|
||||
g_string_free(identity_str, TRUE);
|
||||
} else if (strcmp(xmpp_stanza_get_name(child), STANZA_NAME_FEATURE) == 0) {
|
||||
char *feature_str = xmpp_stanza_get_attribute(child, "var");
|
||||
features = g_slist_insert_sorted(features, feature_str, (GCompareFunc)octet_compare);
|
||||
} else if (strcmp(xmpp_stanza_get_name(child), STANZA_NAME_X) == 0) {
|
||||
// check for and add form to string
|
||||
}
|
||||
child = xmpp_stanza_get_next(child);
|
||||
}
|
||||
|
||||
GSList *curr = identities;
|
||||
while (curr != NULL) {
|
||||
g_string_append(s, curr->data);
|
||||
g_string_append(s, "<");
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
curr = features;
|
||||
while (curr != NULL) {
|
||||
g_string_append(s, curr->data);
|
||||
g_string_append(s, "<");
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
SHA1((unsigned char *)s->str, strlen(s->str), hash);
|
||||
|
||||
char *result = g_base64_encode(hash, strlen((char *)hash));
|
||||
|
||||
g_string_free(s, TRUE);
|
||||
g_slist_free_full(identities, free);
|
||||
g_slist_free_full(features, free);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
jabber_process_events(void)
|
||||
{
|
||||
|
@ -23,6 +23,8 @@
|
||||
#ifndef JABBER_H
|
||||
#define JABBER_H
|
||||
|
||||
#include <strophe.h>
|
||||
|
||||
#include "accounts.h"
|
||||
#include "jid.h"
|
||||
|
||||
@ -81,6 +83,7 @@ char * jabber_get_status(void);
|
||||
void jabber_free_resources(void);
|
||||
void jabber_restart(void);
|
||||
void jabber_set_autoping(int seconds);
|
||||
char * jabber_get_sha1_caps_str(void);
|
||||
char * jabber_get_local_sha1_caps_str(void);
|
||||
char * sha1_caps_str(xmpp_stanza_t *query);
|
||||
|
||||
#endif
|
||||
|
@ -48,6 +48,8 @@
|
||||
#define STANZA_NAME_SUBJECT "subject"
|
||||
#define STANZA_NAME_ITEM "item"
|
||||
#define STANZA_NAME_C "c"
|
||||
#define STANZA_NAME_IDENTITY "identity"
|
||||
#define STANZA_NAME_FEATURE "feature"
|
||||
|
||||
#define STANZA_TYPE_CHAT "chat"
|
||||
#define STANZA_TYPE_GROUPCHAT "groupchat"
|
||||
|
Loading…
Reference in New Issue
Block a user