diff options
author | James Booth <boothj5@gmail.com> | 2013-02-10 02:17:22 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2013-02-10 02:17:22 +0000 |
commit | 84a4ab95459107d50625b3487ad0ffbee78ffe31 (patch) | |
tree | 5b3a0aee76f31d2987fd00be7b10f3b8bad5614d | |
parent | 84a6ac194972b25c014ecf8d238a13cf153a57fa (diff) | |
download | profani-tty-84a4ab95459107d50625b3487ad0ffbee78ffe31.tar.gz |
Fixed error clearing contact list
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | src/contact.c | 26 | ||||
-rw-r--r-- | src/contact.h | 2 | ||||
-rw-r--r-- | src/contact_list.c | 7 | ||||
-rw-r--r-- | src/resource.c | 1 |
5 files changed, 34 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am index f80376ad..697d2e6a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,7 +25,8 @@ check_PROGRAMS = tests/testsuite tests_testsuite_SOURCES = tests/test_contact_list.c src/contact_list.c src/contact.c \ tests/test_common.c tests/test_history.c src/tools/history.c src/common.c \ tests/test_autocomplete.c src/tools/autocomplete.c tests/testsuite.c \ - tests/test_parser.c src/command/parser.c tests/test_jid.c src/jid.c + tests/test_parser.c src/command/parser.c tests/test_jid.c src/jid.c \ + src/resource.c src/resource.h tests_testsuite_LDADD = -lheadunit -lstdc++ man_MANS = docs/profanity.1 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)) |