Show available resources for current account with "/account"
This commit is contained in:
@@ -52,6 +52,8 @@ static struct _jabber_conn_t {
|
||||
int tls_disabled;
|
||||
} jabber_conn;
|
||||
|
||||
static GHashTable *available_resources;
|
||||
|
||||
// for auto reconnect
|
||||
static struct {
|
||||
char *name;
|
||||
@@ -92,6 +94,8 @@ jabber_init(const int disable_tls)
|
||||
jabber_conn.tls_disabled = disable_tls;
|
||||
presence_init();
|
||||
caps_init();
|
||||
available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free,
|
||||
(GDestroyNotify)resource_destroy);
|
||||
}
|
||||
|
||||
jabber_conn_status_t
|
||||
@@ -201,6 +205,12 @@ jabber_set_autoping(const int seconds)
|
||||
}
|
||||
}
|
||||
|
||||
GList *
|
||||
jabber_get_available_resources(void)
|
||||
{
|
||||
return g_hash_table_get_values(available_resources);
|
||||
}
|
||||
|
||||
jabber_conn_status_t
|
||||
jabber_get_connection_status(void)
|
||||
{
|
||||
@@ -252,6 +262,18 @@ connection_set_priority(const int priority)
|
||||
jabber_conn.priority = priority;
|
||||
}
|
||||
|
||||
void
|
||||
connection_add_available_resource(Resource *resource)
|
||||
{
|
||||
g_hash_table_replace(available_resources, strdup(resource->name), resource);
|
||||
}
|
||||
|
||||
void
|
||||
connection_remove_available_resource(const char * const resource)
|
||||
{
|
||||
g_hash_table_remove(available_resources, resource);
|
||||
}
|
||||
|
||||
void
|
||||
connection_free_resources(void)
|
||||
{
|
||||
@@ -261,6 +283,7 @@ connection_free_resources(void)
|
||||
FREE_SET_NULL(saved_details.altdomain);
|
||||
FREE_SET_NULL(saved_account.name);
|
||||
FREE_SET_NULL(saved_account.passwd);
|
||||
g_hash_table_destroy(available_resources);
|
||||
chat_sessions_clear();
|
||||
presence_free_sub_requests();
|
||||
xmpp_conn_release(jabber_conn.conn);
|
||||
|
||||
@@ -32,5 +32,7 @@ int connection_error_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
void connection_set_priority(int priority);
|
||||
void connection_set_presence_message(const char * const message);
|
||||
void connection_add_available_resource(Resource *resource);
|
||||
void connection_remove_available_resource(const char * const resource);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -343,6 +343,8 @@ _unavailable_handler(xmpp_conn_t * const conn,
|
||||
|
||||
if (strcmp(my_jid->barejid, from_jid->barejid) !=0) {
|
||||
prof_handle_contact_offline(from_jid->barejid, from_jid->resourcepart, status_str);
|
||||
} else {
|
||||
connection_remove_available_resource(from_jid->resourcepart);
|
||||
}
|
||||
|
||||
jid_destroy(my_jid);
|
||||
@@ -425,6 +427,12 @@ _available_handler(xmpp_conn_t * const conn,
|
||||
Resource *resource = resource_new(from_jid->resourcepart, presence,
|
||||
status_str, priority, caps_key);
|
||||
prof_handle_contact_online(from_jid->barejid, resource, last_activity);
|
||||
} else {
|
||||
// handle self presence
|
||||
resource_presence_t presence = resource_presence_from_string(show_str);
|
||||
Resource *resource = resource_new(from_jid->resourcepart, presence,
|
||||
status_str, priority, caps_key);
|
||||
connection_add_available_resource(resource);
|
||||
}
|
||||
|
||||
jid_destroy(my_jid);
|
||||
|
||||
@@ -70,6 +70,7 @@ jabber_conn_status_t jabber_get_connection_status(void);
|
||||
char * jabber_get_presence_message(void);
|
||||
void jabber_set_autoping(int seconds);
|
||||
char* jabber_get_account_name(void);
|
||||
GList * jabber_get_available_resources(void);
|
||||
|
||||
// message functions
|
||||
void message_send(const char * const msg, const char * const recipient);
|
||||
|
||||
Reference in New Issue
Block a user