about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-02-10 02:17:22 +0000
committerJames Booth <boothj5@gmail.com>2013-02-10 02:17:22 +0000
commit84a4ab95459107d50625b3487ad0ffbee78ffe31 (patch)
tree5b3a0aee76f31d2987fd00be7b10f3b8bad5614d /src
parent84a6ac194972b25c014ecf8d238a13cf153a57fa (diff)
downloadprofani-tty-84a4ab95459107d50625b3487ad0ffbee78ffe31.tar.gz
Fixed error clearing contact list
Diffstat (limited to 'src')
-rw-r--r--src/contact.c26
-rw-r--r--src/contact.h2
-rw-r--r--src/contact_list.c7
-rw-r--r--src/resource.c1
4 files changed, 32 insertions, 4 deletions
diff --git a/src/contact.c b/src/contact.c
index d1929e60..dd0205ee 100644
--- a/src/contact.c
+++ b/src/contact.c
@@ -65,6 +65,32 @@ p_contact_new(const char * const barejid, const char * const name,
         (GDestroyNotify)resource_destroy);
     // TODO, priority, last activity
     Resource *resource = resource_new("default", presence, status, 0, caps_str);
+    g_hash_table_insert(contact->resources, strdup(resource->name), resource);
+
+    return contact;
+}
+
+PContact
+p_contact_new_subscription(const char * const barejid,
+    const char * const subscription, gboolean pending_out)
+{
+    PContact contact = malloc(sizeof(struct p_contact_t));
+    contact->barejid = strdup(barejid);
+
+    contact->name = NULL;
+
+    if (subscription != NULL)
+        contact->subscription = strdup(subscription);
+    else
+        contact->subscription = strdup("none");
+
+    contact->pending_out = pending_out;
+    contact->last_activity = NULL;
+
+    contact->resources = g_hash_table_new_full(g_str_hash, g_str_equal, free,
+        (GDestroyNotify)resource_destroy);
+    // TODO, priority, last activity
+    Resource *resource = resource_new("default", "offline", NULL, 0, NULL);
     g_hash_table_insert(contact->resources, resource->name, resource);
 
     return contact;
diff --git a/src/contact.h b/src/contact.h
index 2b5456d7..f0119081 100644
--- a/src/contact.h
+++ b/src/contact.h
@@ -29,6 +29,8 @@ PContact p_contact_new(const char * const barejid, const char * const name,
     const char * const presence, const char * const status,
     const char * const subscription, gboolean pending_out,
     const char * const caps_str);
+PContact p_contact_new_subscription(const char * const barejid,
+    const char * const subscription, gboolean pending_out);
 void p_contact_free(PContact contact);
 const char* p_contact_barejid(PContact contact);
 const char* p_contact_name(PContact contact);
diff --git a/src/contact_list.c b/src/contact_list.c
index 43868b71..cac593ee 100644
--- a/src/contact_list.c
+++ b/src/contact_list.c
@@ -45,7 +45,9 @@ void
 contact_list_clear(void)
 {
     autocomplete_clear(ac);
-    g_hash_table_remove_all(contacts);
+    g_hash_table_destroy(contacts);
+    contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free,
+        (GDestroyNotify)p_contact_free);
 }
 
 void
@@ -125,8 +127,7 @@ contact_list_update_subscription(const char * const barejid,
     PContact contact = g_hash_table_lookup(contacts, barejid);
 
     if (contact == NULL) {
-        contact = p_contact_new(barejid, NULL, "offline", NULL, subscription,
-            pending_out, NULL);
+        contact = p_contact_new_subscription(barejid, subscription, pending_out);
         g_hash_table_insert(contacts, strdup(barejid), contact);
     } else {
         p_contact_set_subscription(contact, subscription);
diff --git a/src/resource.c b/src/resource.c
index cd992592..e8443d58 100644
--- a/src/resource.c
+++ b/src/resource.c
@@ -31,7 +31,6 @@ Resource * resource_new(const char * const name, const char * const show,
     const char * const status, const int priority, const char * const caps_str)
 {
     assert(name != NULL);
-    assert(show != NULL);
     Resource *new_resource = malloc(sizeof(struct resource_t));
     new_resource->name = strdup(name);
     if (show == NULL || (strcmp(show, "") == 0))