From 1a6490a5b761087ad00d63dfa59d737318b0ceeb Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 10 Feb 2013 17:27:08 +0000 Subject: [PATCH] Use resource_presence_t in Resource --- src/contact.c | 15 ++++++--------- src/resource.c | 9 ++------- src/resource.h | 4 ++-- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/contact.c b/src/contact.c index 7f6dcadc..9455929c 100644 --- a/src/contact.c +++ b/src/contact.c @@ -65,7 +65,8 @@ p_contact_new(const char * const barejid, const char * const name, (GDestroyNotify)resource_destroy); // TODO, priority, last activity if (g_strcmp0(presence, "offline") != 0) { - Resource *resource = resource_new("default", presence, status, 0, caps_str); + resource_presence_t resource_presence = resource_presence_from_string(presence); + Resource *resource = resource_new("default", resource_presence, status, 0, caps_str); g_hash_table_insert(contact->available_resources, strdup(resource->name), resource); } @@ -130,7 +131,7 @@ p_contact_presence(const PContact contact) return "offline"; } else { Resource *resource = g_hash_table_lookup(contact->available_resources, "default"); - return resource->show; + return string_from_resource_presence(resource->presence); } } @@ -180,17 +181,13 @@ p_contact_set_presence(const PContact contact, const char * const presence) if (g_strcmp0(presence, "offline") == 0) { g_hash_table_remove(contact->available_resources, "default"); } else { + resource_presence_t resource_presence = resource_presence_from_string(presence); if (g_hash_table_size(contact->available_resources) == 0) { - Resource *resource = resource_new("default", presence, NULL, 0, NULL); + Resource *resource = resource_new("default", resource_presence, NULL, 0, NULL); g_hash_table_insert(contact->available_resources, strdup(resource->name), resource); } else { Resource *resource = g_hash_table_lookup(contact->available_resources, "default"); - if (presence != NULL) { - FREE_SET_NULL(resource->show); - resource->show = strdup(presence); - } else { - resource->show = NULL; - } + resource->presence = resource_presence; } } } diff --git a/src/resource.c b/src/resource.c index 74cb5755..3ec664ec 100644 --- a/src/resource.c +++ b/src/resource.c @@ -27,17 +27,13 @@ #include #include -Resource * resource_new(const char * const name, const char * const show, +Resource * resource_new(const char * const name, resource_presence_t presence, const char * const status, const int priority, const char * const caps_str) { - assert(g_strcmp0(show, "offline") != 0); assert(name != NULL); Resource *new_resource = malloc(sizeof(struct resource_t)); new_resource->name = strdup(name); - if (show == NULL || (strcmp(show, "") == 0)) - new_resource->show = strdup("online"); - else - new_resource->show = strdup(show); + new_resource->presence = presence; if (status != NULL) { new_resource->status = strdup(status); } else { @@ -57,7 +53,6 @@ void resource_destroy(Resource *resource) { assert(resource != NULL); FREE_SET_NULL(resource->name); - FREE_SET_NULL(resource->show); FREE_SET_NULL(resource->status); FREE_SET_NULL(resource->caps_str); FREE_SET_NULL(resource); diff --git a/src/resource.h b/src/resource.h index 491b33cc..d69101f7 100644 --- a/src/resource.h +++ b/src/resource.h @@ -25,13 +25,13 @@ typedef struct resource_t { char *name; - char *show; + resource_presence_t presence; char *status; int priority; char *caps_str; } Resource; -Resource * resource_new(const char * const name, const char * const show, +Resource * resource_new(const char * const name, resource_presence_t presence, const char * const status, const int priority, const char * const caps_str); void resource_destroy(Resource *resource);