1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -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 "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);
}
}

View File

@ -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

View File

@ -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);