1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added check whether caps cached

This commit is contained in:
James Booth 2013-01-20 00:57:44 +00:00
parent 22589e8798
commit f967395f0f
3 changed files with 33 additions and 14 deletions

View File

@ -28,17 +28,20 @@
#include "common.h" #include "common.h"
#include "capabilities.h" #include "capabilities.h"
GHashTable *capabilities; static GHashTable *capabilities;
static void _caps_destroy(Capabilities *caps);
void void
caps_init(void) caps_init(void)
{ {
capabilities = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, capabilities = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
(GDestroyNotify)caps_destroy); (GDestroyNotify)_caps_destroy);
} }
Capabilities * void
caps_create(const char * const client, const char * const version) caps_add(const char * const caps_str, const char * const client,
const char * const version)
{ {
Capabilities *new_caps = malloc(sizeof(struct capabilities_t)); 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; new_caps->version = NULL;
} }
return new_caps; g_hash_table_insert(capabilities, strdup(caps_str), new_caps);
} }
void gboolean
caps_destroy(Capabilities *caps) caps_contains(const char * const caps_str)
{ {
if (caps != NULL) { return (g_hash_table_lookup(capabilities, caps_str) != NULL);
FREE_SET_NULL(caps->client);
FREE_SET_NULL(caps->version);
FREE_SET_NULL(caps);
}
} }
void void
@ -72,3 +71,13 @@ caps_close(void)
{ {
g_hash_table_destroy(capabilities); 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);
}
}

View File

@ -23,14 +23,17 @@
#ifndef CAPABILITIES_H #ifndef CAPABILITIES_H
#define CAPABILITIES_H #define CAPABILITIES_H
#include <glib.h>
typedef struct capabilities_t { typedef struct capabilities_t {
char *client; char *client;
char *version; char *version;
} Capabilities; } Capabilities;
void caps_init(void); void caps_init(void);
Capabilities* caps_create(const char * const client, const char * const version); void caps_add(const char * const caps_str, const char * const client,
void caps_destroy(Capabilities *caps); const char * const version);
gboolean caps_contains(const char * const caps_str);
void caps_close(void); void caps_close(void);
#endif #endif

View File

@ -26,6 +26,7 @@
#include <strophe.h> #include <strophe.h>
#include "capabilities.h"
#include "chat_session.h" #include "chat_session.h"
#include "common.h" #include "common.h"
#include "contact_list.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); xmpp_stanza_t *status = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_STATUS);
if (status != NULL) if (status != NULL)
status_str = xmpp_stanza_get_text(status); status_str = xmpp_stanza_get_text(status);