From 84a4ab95459107d50625b3487ad0ffbee78ffe31 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 10 Feb 2013 02:17:22 +0000 Subject: Fixed error clearing contact list --- src/contact.c | 26 ++++++++++++++++++++++++++ src/contact.h | 2 ++ src/contact_list.c | 7 ++++--- src/resource.c | 1 - 4 files changed, 32 insertions(+), 4 deletions(-) (limited to 'src') 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)) -- cgit 1.4.1-2-gfad0