1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Fixed error clearing contact list

This commit is contained in:
James Booth 2013-02-10 02:17:22 +00:00
parent 84a6ac1949
commit 84a4ab9545
5 changed files with 34 additions and 5 deletions

View File

@ -25,7 +25,8 @@ check_PROGRAMS = tests/testsuite
tests_testsuite_SOURCES = tests/test_contact_list.c src/contact_list.c src/contact.c \ 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_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_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++ tests_testsuite_LDADD = -lheadunit -lstdc++
man_MANS = docs/profanity.1 man_MANS = docs/profanity.1

View File

@ -65,6 +65,32 @@ p_contact_new(const char * const barejid, const char * const name,
(GDestroyNotify)resource_destroy); (GDestroyNotify)resource_destroy);
// TODO, priority, last activity // TODO, priority, last activity
Resource *resource = resource_new("default", presence, status, 0, caps_str); 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); g_hash_table_insert(contact->resources, resource->name, resource);
return contact; return contact;

View File

@ -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 presence, const char * const status,
const char * const subscription, gboolean pending_out, const char * const subscription, gboolean pending_out,
const char * const caps_str); 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); void p_contact_free(PContact contact);
const char* p_contact_barejid(PContact contact); const char* p_contact_barejid(PContact contact);
const char* p_contact_name(PContact contact); const char* p_contact_name(PContact contact);

View File

@ -45,7 +45,9 @@ void
contact_list_clear(void) contact_list_clear(void)
{ {
autocomplete_clear(ac); 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 void
@ -125,8 +127,7 @@ contact_list_update_subscription(const char * const barejid,
PContact contact = g_hash_table_lookup(contacts, barejid); PContact contact = g_hash_table_lookup(contacts, barejid);
if (contact == NULL) { if (contact == NULL) {
contact = p_contact_new(barejid, NULL, "offline", NULL, subscription, contact = p_contact_new_subscription(barejid, subscription, pending_out);
pending_out, NULL);
g_hash_table_insert(contacts, strdup(barejid), contact); g_hash_table_insert(contacts, strdup(barejid), contact);
} else { } else {
p_contact_set_subscription(contact, subscription); p_contact_set_subscription(contact, subscription);

View File

@ -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) const char * const status, const int priority, const char * const caps_str)
{ {
assert(name != NULL); assert(name != NULL);
assert(show != NULL);
Resource *new_resource = malloc(sizeof(struct resource_t)); Resource *new_resource = malloc(sizeof(struct resource_t));
new_resource->name = strdup(name); new_resource->name = strdup(name);
if (show == NULL || (strcmp(show, "") == 0)) if (show == NULL || (strcmp(show, "") == 0))