diff options
author | James Booth <boothj5@gmail.com> | 2013-01-20 00:57:44 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2013-01-20 00:57:44 +0000 |
commit | f967395f0f99a7eba7aa6ea1c006b39b142f56d5 (patch) | |
tree | c0f1c36ea2665b27d228009754543fa62fac0f5e | |
parent | 22589e879822a89212c49030dabee3db0c10f8e8 (diff) | |
download | profani-tty-f967395f0f99a7eba7aa6ea1c006b39b142f56d5.tar.gz |
Added check whether caps cached
-rw-r--r-- | src/capabilities.c | 33 | ||||
-rw-r--r-- | src/capabilities.h | 7 | ||||
-rw-r--r-- | src/jabber.c | 7 |
3 files changed, 33 insertions, 14 deletions
diff --git a/src/capabilities.c b/src/capabilities.c index 7ed5c810..e28112e7 100644 --- a/src/capabilities.c +++ b/src/capabilities.c @@ -28,17 +28,20 @@ #include "common.h" #include "capabilities.h" -GHashTable *capabilities; +static GHashTable *capabilities; + +static void _caps_destroy(Capabilities *caps); void caps_init(void) { capabilities = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, - (GDestroyNotify)caps_destroy); + (GDestroyNotify)_caps_destroy); } -Capabilities * -caps_create(const char * const client, const char * const version) +void +caps_add(const char * const caps_str, const char * const client, + const char * const version) { Capabilities *new_caps = malloc(sizeof(struct capabilities_t)); @@ -54,17 +57,13 @@ caps_create(const char * const client, const char * const version) new_caps->version = NULL; } - return new_caps; + g_hash_table_insert(capabilities, strdup(caps_str), new_caps); } -void -caps_destroy(Capabilities *caps) +gboolean +caps_contains(const char * const caps_str) { - if (caps != NULL) { - FREE_SET_NULL(caps->client); - FREE_SET_NULL(caps->version); - FREE_SET_NULL(caps); - } + return (g_hash_table_lookup(capabilities, caps_str) != NULL); } void @@ -72,3 +71,13 @@ caps_close(void) { g_hash_table_destroy(capabilities); } + +static void +_caps_destroy(Capabilities *caps) +{ + if (caps != NULL) { + FREE_SET_NULL(caps->client); + FREE_SET_NULL(caps->version); + FREE_SET_NULL(caps); + } +} diff --git a/src/capabilities.h b/src/capabilities.h index 430348a6..128fb2e1 100644 --- a/src/capabilities.h +++ b/src/capabilities.h @@ -23,14 +23,17 @@ #ifndef CAPABILITIES_H #define CAPABILITIES_H +#include <glib.h> + typedef struct capabilities_t { char *client; char *version; } Capabilities; void caps_init(void); -Capabilities* caps_create(const char * const client, const char * const version); -void caps_destroy(Capabilities *caps); +void caps_add(const char * const caps_str, const char * const client, + const char * const version); +gboolean caps_contains(const char * const caps_str); void caps_close(void); #endif diff --git a/src/jabber.c b/src/jabber.c index a85ecbed..d5fb23ce 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -26,6 +26,7 @@ #include <strophe.h> +#include "capabilities.h" #include "chat_session.h" #include "common.h" #include "contact_list.h" @@ -1069,6 +1070,12 @@ _presence_handler(xmpp_conn_t * const conn, } } + if (caps_str != NULL) { + if (!caps_contains(caps_str)) { + // send iq request for caps info + } + } + xmpp_stanza_t *status = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_STATUS); if (status != NULL) status_str = xmpp_stanza_get_text(status); |