about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/connection.c23
-rw-r--r--src/xmpp/connection.h2
-rw-r--r--src/xmpp/presence.c8
-rw-r--r--src/xmpp/xmpp.h1
4 files changed, 34 insertions, 0 deletions
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 5d509d87..2c0c5186 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -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)
 {
@@ -253,6 +263,18 @@ connection_set_priority(const int 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)
 {
     FREE_SET_NULL(saved_details.name);
@@ -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);
diff --git a/src/xmpp/connection.h b/src/xmpp/connection.h
index abe989cd..c242f65f 100644
--- a/src/xmpp/connection.h
+++ b/src/xmpp/connection.h
@@ -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
diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c
index 4d152a20..28e2039e 100644
--- a/src/xmpp/presence.c
+++ b/src/xmpp/presence.c
@@ -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);
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 44f89407..3fc9c633 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -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);