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

Move available resources to connection struct

This commit is contained in:
James Booth 2016-05-07 23:04:50 +01:00
parent 7f1beadea9
commit 9596591610
7 changed files with 35 additions and 28 deletions

View File

@ -963,7 +963,7 @@ cons_show_account(ProfAccount *account)
if ((connection_get_status() == JABBER_CONNECTED) && if ((connection_get_status() == JABBER_CONNECTED) &&
(g_strcmp0(session_get_account_name(), account->name) == 0)) { (g_strcmp0(session_get_account_name(), account->name) == 0)) {
GList *resources = session_get_available_resources(); GList *resources = connection_get_available_resources();
GList *ordered_resources = NULL; GList *ordered_resources = NULL;
GList *curr = resources; GList *curr = resources;

View File

@ -59,6 +59,7 @@ typedef struct prof_conn_t {
char *presence_message; char *presence_message;
int priority; int priority;
char *domain; char *domain;
GHashTable *available_resources;
} ProfConnection; } ProfConnection;
static ProfConnection conn; static ProfConnection conn;
@ -81,6 +82,7 @@ void connection_init(void)
conn.xmpp_conn = NULL; conn.xmpp_conn = NULL;
conn.xmpp_ctx = NULL; conn.xmpp_ctx = NULL;
conn.domain = NULL; conn.domain = NULL;
conn.available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)resource_destroy);
} }
jabber_conn_status_t jabber_conn_status_t
@ -197,6 +199,30 @@ connection_get_fulljid(void)
return xmpp_conn_get_jid(conn.xmpp_conn); return xmpp_conn_get_jid(conn.xmpp_conn);
} }
GList*
connection_get_available_resources(void)
{
return g_hash_table_get_values(conn.available_resources);
}
void
connection_add_available_resource(Resource *resource)
{
g_hash_table_replace(conn.available_resources, strdup(resource->name), resource);
}
void
connection_remove_available_resource(const char *const resource)
{
g_hash_table_remove(conn.available_resources, resource);
}
void
connection_remove_all_available_resources(void)
{
g_hash_table_remove_all(conn.available_resources);
}
char* char*
connection_create_uuid(void) connection_create_uuid(void)
{ {

View File

@ -48,6 +48,7 @@ void connection_set_status(jabber_conn_status_t status);
void connection_set_presence_msg(const char *const message); void connection_set_presence_msg(const char *const message);
void connection_set_priority(const int priority); void connection_set_priority(const int priority);
void connection_set_domain(char *domain); void connection_set_domain(char *domain);
void connection_set_priority(int priority);
void connection_free_conn(void); void connection_free_conn(void);
void connection_free_ctx(void); void connection_free_ctx(void);
@ -57,6 +58,8 @@ void connection_free_log(void);
xmpp_conn_t* connection_get_conn(void); xmpp_conn_t* connection_get_conn(void);
xmpp_ctx_t* connection_get_ctx(void); xmpp_ctx_t* connection_get_ctx(void);
void connection_set_priority(int priority); void connection_add_available_resource(Resource *resource);
void connection_remove_available_resource(const char *const resource);
void connection_remove_all_available_resources(void);
#endif #endif

View File

@ -538,7 +538,7 @@ _unavailable_handler(xmpp_stanza_t *const stanza)
} }
} else { } else {
if (from_jid->resourcepart) { if (from_jid->resourcepart) {
session_remove_available_resource(from_jid->resourcepart); connection_remove_available_resource(from_jid->resourcepart);
} }
} }
@ -644,7 +644,7 @@ _available_handler(xmpp_stanza_t *const stanza)
Resource *resource = stanza_resource_from_presence(xmpp_presence); Resource *resource = stanza_resource_from_presence(xmpp_presence);
if (g_strcmp0(xmpp_presence->jid->barejid, my_jid->barejid) == 0) { if (g_strcmp0(xmpp_presence->jid->barejid, my_jid->barejid) == 0) {
session_add_available_resource(resource); connection_add_available_resource(resource);
} else { } else {
char *pgpsig = NULL; char *pgpsig = NULL;
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_SIGNED); xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_SIGNED);

View File

@ -66,7 +66,6 @@
#include "xmpp/stanza.h" #include "xmpp/stanza.h"
#include "xmpp/xmpp.h" #include "xmpp/xmpp.h"
static GHashTable *available_resources;
static GSList *disco_items; static GSList *disco_items;
// for auto reconnect // for auto reconnect
@ -101,7 +100,6 @@ session_init(void)
connection_init(); connection_init();
presence_sub_requests_init(); presence_sub_requests_init();
caps_init(); caps_init();
available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)resource_destroy);
disco_items = NULL; disco_items = NULL;
xmpp_initialize(); xmpp_initialize();
} }
@ -275,12 +273,6 @@ session_process_events(int millis)
} }
} }
GList*
session_get_available_resources(void)
{
return g_hash_table_get_values(available_resources);
}
GSList* GSList*
session_get_disco_items(void) session_get_disco_items(void)
{ {
@ -314,18 +306,6 @@ session_get_account_name(void)
return saved_account.name; return saved_account.name;
} }
void
session_add_available_resource(Resource *resource)
{
g_hash_table_replace(available_resources, strdup(resource->name), resource);
}
void
session_remove_available_resource(const char *const resource)
{
g_hash_table_remove(available_resources, resource);
}
void void
session_login_success(gboolean secured) session_login_success(gboolean secured)
{ {
@ -463,7 +443,7 @@ _session_free_session_data(void)
{ {
g_slist_free_full(disco_items, (GDestroyNotify)_session_info_destroy); g_slist_free_full(disco_items, (GDestroyNotify)_session_info_destroy);
disco_items = NULL; disco_items = NULL;
g_hash_table_remove_all(available_resources); connection_remove_all_available_resources();
chat_sessions_clear(); chat_sessions_clear();
presence_clear_sub_requests(); presence_clear_sub_requests();
} }

View File

@ -52,7 +52,5 @@ void session_lost_connection(void);
GSList* session_get_disco_items(void); GSList* session_get_disco_items(void);
void session_set_disco_items(GSList *_disco_items); void session_set_disco_items(GSList *_disco_items);
void session_autoping_fail(void); void session_autoping_fail(void);
void session_remove_available_resource(const char *const resource);
void session_add_available_resource(Resource *resource);
#endif #endif

View File

@ -118,7 +118,6 @@ void session_disconnect(void);
void session_shutdown(void); void session_shutdown(void);
void session_process_events(int millis); void session_process_events(int millis);
char* session_get_account_name(void); char* session_get_account_name(void);
GList* session_get_available_resources(void);
gboolean session_service_supports(const char *const feature); gboolean session_service_supports(const char *const feature);
@ -132,6 +131,7 @@ TLSCertificate* connection_get_tls_peer_cert(void);
#endif #endif
gboolean connection_is_secured(void); gboolean connection_is_secured(void);
gboolean connection_send_stanza(const char *const stanza); gboolean connection_send_stanza(const char *const stanza);
GList* connection_get_available_resources(void);
char* message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url); char* message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url);
char* message_send_chat_otr(const char *const barejid, const char *const msg); char* message_send_chat_otr(const char *const barejid, const char *const msg);