From 8c9f91624646d22121166446f3c16edbcd7026b6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 10 Feb 2013 18:16:06 +0000 Subject: [PATCH] Added p_contact_add_resource --- src/contact.c | 20 +++++++++++--------- src/contact.h | 7 ++++--- src/contact_list.c | 3 +-- src/muc.c | 5 ++++- src/resource.h | 2 ++ 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/contact.c b/src/contact.c index 9455929c..45ace58f 100644 --- a/src/contact.c +++ b/src/contact.c @@ -20,6 +20,7 @@ * */ +#include #include #include @@ -40,9 +41,7 @@ struct p_contact_t { 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) + const char * const subscription, gboolean pending_out) { PContact contact = malloc(sizeof(struct p_contact_t)); contact->barejid = strdup(barejid); @@ -63,16 +62,19 @@ p_contact_new(const char * const barejid, const char * const name, contact->available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)resource_destroy); - // TODO, priority, last activity - if (g_strcmp0(presence, "offline") != 0) { - 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); - } return contact; } +void +p_contact_add_resource(PContact contact, Resource *resource) +{ + assert(contact != NULL); + assert(resource != NULL); + + g_hash_table_insert(contact->available_resources, strdup(resource->name), resource); +} + PContact p_contact_new_subscription(const char * const barejid, const char * const subscription, gboolean pending_out) diff --git a/src/contact.h b/src/contact.h index f0119081..c32f3800 100644 --- a/src/contact.h +++ b/src/contact.h @@ -23,14 +23,15 @@ #ifndef CONTACT_H #define CONTACT_H +#include "resource.h" + typedef struct p_contact_t *PContact; 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); + const char * const subscription, gboolean pending_out); PContact p_contact_new_subscription(const char * const barejid, const char * const subscription, gboolean pending_out); +void p_contact_add_resource(PContact contact, Resource *resource); 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 73333156..13c71f0a 100644 --- a/src/contact_list.c +++ b/src/contact_list.c @@ -70,8 +70,7 @@ contact_list_add(const char * const barejid, const char * const name, PContact contact = g_hash_table_lookup(contacts, barejid); if (contact == NULL) { - contact = p_contact_new(barejid, name, "offline", NULL, subscription, - pending_out, NULL); + contact = p_contact_new(barejid, name, subscription, pending_out); g_hash_table_insert(contacts, strdup(barejid), contact); autocomplete_add(ac, strdup(barejid)); added = TRUE; diff --git a/src/muc.c b/src/muc.c index b061e4ba..a59ac96b 100644 --- a/src/muc.c +++ b/src/muc.c @@ -220,7 +220,10 @@ muc_add_to_roster(const char * const room, const char * const nick, (g_strcmp0(p_contact_status(old), status) != 0)) { updated = TRUE; } - PContact contact = p_contact_new(nick, NULL, show, status, NULL, FALSE, caps_str); + PContact contact = p_contact_new(nick, NULL, NULL, FALSE); + resource_presence_t resource_presence = resource_presence_from_string(show); + Resource *resource = resource_new("default", resource_presence, status, 0, caps_str); + p_contact_add_resource(contact, resource); g_hash_table_replace(chat_room->roster, strdup(nick), contact); } diff --git a/src/resource.h b/src/resource.h index d69101f7..534153e4 100644 --- a/src/resource.h +++ b/src/resource.h @@ -23,6 +23,8 @@ #ifndef RESOURCE_H #define RESOURCE_H +#include "common.h" + typedef struct resource_t { char *name; resource_presence_t presence;