about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-09-23 00:08:26 +0100
committerJames Booth <boothj5@gmail.com>2014-09-23 00:08:26 +0100
commit345a9e3f405fa7e2a71552600f67b7893db67506 (patch)
treec4f7edf1e597dc8cd11824732839032e72e93d21 /src/xmpp
parent7621a846754b36fcd22fb3b3481328da5d2f9e8d (diff)
downloadprofani-tty-345a9e3f405fa7e2a71552600f67b7893db67506.tar.gz
Create sha-1 of own capabilities once
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/capabilities.c16
-rw-r--r--src/xmpp/capabilities.h1
-rw-r--r--src/xmpp/stanza.c3
3 files changed, 18 insertions, 2 deletions
diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c
index 99e8d56c..645eed68 100644
--- a/src/xmpp/capabilities.c
+++ b/src/xmpp/capabilities.c
@@ -49,12 +49,15 @@
 #include "xmpp/xmpp.h"
 #include "xmpp/stanza.h"
 #include "xmpp/form.h"
+#include "xmpp/capabilities.h"
 
 static gchar *cache_loc;
 static GKeyFile *cache;
 
 static GHashTable *jid_lookup;
 
+static char *my_sha1;
+
 static void _caps_destroy(Capabilities *caps);
 static gchar* _get_cache_file(void);
 static void _save_cache(void);
@@ -71,6 +74,8 @@ caps_init(void)
         NULL);
 
     jid_lookup = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+
+    my_sha1 = NULL;
 }
 
 void
@@ -425,6 +430,17 @@ caps_create(xmpp_stanza_t *query)
     return new_caps;
 }
 
+char*
+caps_get_my_sha1(xmpp_ctx_t * const ctx)
+{
+    if (my_sha1 == NULL) {
+        xmpp_stanza_t *query = caps_create_query_response_stanza(ctx);
+        my_sha1 = caps_create_sha1_str(query);
+        xmpp_stanza_release(query);
+    }
+
+    return my_sha1;
+}
 
 xmpp_stanza_t *
 caps_create_query_response_stanza(xmpp_ctx_t * const ctx)
diff --git a/src/xmpp/capabilities.h b/src/xmpp/capabilities.h
index bb8b92af..a43b301d 100644
--- a/src/xmpp/capabilities.h
+++ b/src/xmpp/capabilities.h
@@ -46,5 +46,6 @@ gboolean caps_contains(const char * const caps_ver);
 char* caps_create_sha1_str(xmpp_stanza_t * const query);
 xmpp_stanza_t* caps_create_query_response_stanza(xmpp_ctx_t * const ctx);
 Capabilities* caps_create(xmpp_stanza_t *query);
+char* caps_get_my_sha1(xmpp_ctx_t * const ctx);
 
 #endif
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 1a962c53..2d99c0f0 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -1198,14 +1198,13 @@ stanza_attach_caps(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence)
     xmpp_stanza_set_ns(caps, STANZA_NS_CAPS);
     xmpp_stanza_t *query = caps_create_query_response_stanza(ctx);
 
-    char *sha1 = caps_create_sha1_str(query);
+    char *sha1 = caps_get_my_sha1(ctx);
     xmpp_stanza_set_attribute(caps, STANZA_ATTR_HASH, "sha-1");
     xmpp_stanza_set_attribute(caps, STANZA_ATTR_NODE, "http://www.profanity.im");
     xmpp_stanza_set_attribute(caps, STANZA_ATTR_VER, sha1);
     xmpp_stanza_add_child(presence, caps);
     xmpp_stanza_release(caps);
     xmpp_stanza_release(query);
-    g_free(sha1);
 }
 
 const char *