From fb1bf0fc38dfb3e7e03e96890598daf3fab27420 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sun, 25 Aug 2013 17:25:42 +0300 Subject: [PATCH] ucs: add transaction to request function Add transaction parameter to some of the operations so that the correct transaction can be passed around. --- src/core/sipe-buddy.c | 10 +++++++++- src/core/sipe-group.c | 2 ++ src/core/sipe-group.h | 2 ++ src/core/sipe-notify.c | 5 ++++- src/core/sipe-ucs.c | 42 +++++++++++++++++++++++++++--------------- src/core/sipe-ucs.h | 7 +++++++ 6 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/core/sipe-buddy.c b/src/core/sipe-buddy.c index 463f17f7..aaca11ae 100644 --- a/src/core/sipe-buddy.c +++ b/src/core/sipe-buddy.c @@ -594,11 +594,13 @@ void sipe_core_buddy_group(struct sipe_core_public *sipe_public, * 2. existing buddy moved from old to existing group */ sipe_ucs_group_add_buddy(SIPE_CORE_PRIVATE, + NULL, new_group, buddy, buddy->name); if (old_group) sipe_ucs_group_remove_buddy(SIPE_CORE_PRIVATE, + NULL, old_group, buddy); @@ -608,6 +610,7 @@ void sipe_core_buddy_group(struct sipe_core_public *sipe_public, * 4. existing buddy removed from last group */ sipe_ucs_group_remove_buddy(SIPE_CORE_PRIVATE, + NULL, old_group, buddy); if (g_slist_length(buddy->groups) < 1) @@ -622,7 +625,10 @@ void sipe_core_buddy_group(struct sipe_core_public *sipe_public, /* 5. buddy added to new group */ if (!new_group) - sipe_group_create(SIPE_CORE_PRIVATE, new_group_name, who); + sipe_group_create(SIPE_CORE_PRIVATE, + NULL, + new_group_name, + who); } void sipe_core_buddy_add(struct sipe_core_public *sipe_public, @@ -707,6 +713,7 @@ void sipe_core_buddy_remove(struct sipe_core_public *sipe_public, if (sipe_ucs_is_migrated(sipe_private)) { sipe_ucs_group_remove_buddy(sipe_private, + NULL, group, buddy); } else { @@ -722,6 +729,7 @@ void sipe_core_buddy_remove(struct sipe_core_public *sipe_public, } else { if (sipe_ucs_is_migrated(sipe_private)) { sipe_ucs_group_remove_buddy(sipe_private, + NULL, group, buddy); } else diff --git a/src/core/sipe-group.c b/src/core/sipe-group.c index 4eaf0d56..809a5199 100755 --- a/src/core/sipe-group.c +++ b/src/core/sipe-group.c @@ -152,11 +152,13 @@ sipe_group_find_by_name(struct sipe_core_private *sipe_private, void sipe_group_create(struct sipe_core_private *sipe_private, + struct sipe_ucs_transaction *trans, const gchar *name, const gchar *who) { if (sipe_ucs_is_migrated(sipe_private)) { sipe_ucs_group_create(sipe_private, + trans, name, who); } else { diff --git a/src/core/sipe-group.h b/src/core/sipe-group.h index ad253068..2f6454c1 100644 --- a/src/core/sipe-group.h +++ b/src/core/sipe-group.h @@ -23,6 +23,7 @@ /* Forward declarations */ struct sipe_buddy; struct sipe_core_private; +struct sipe_ucs_transaction; struct sipe_group { gchar *name; @@ -39,6 +40,7 @@ struct sipe_group *sipe_group_find_by_name(struct sipe_core_private *sipe_privat const gchar * name); void sipe_group_create(struct sipe_core_private *sipe_private, + struct sipe_ucs_transaction *trans, const gchar *name, const gchar *who); diff --git a/src/core/sipe-notify.c b/src/core/sipe-notify.c index 4205b4e7..8c949621 100644 --- a/src/core/sipe-notify.c +++ b/src/core/sipe-notify.c @@ -1208,7 +1208,10 @@ static gboolean sipe_process_roaming_contacts(struct sipe_core_private *sipe_pri /* Make sure we have at least one group */ if (sipe_group_count(sipe_private) == 0) { - sipe_group_create(sipe_private, _("Other Contacts"), NULL); + sipe_group_create(sipe_private, + NULL, + _("Other Contacts"), + NULL); } /* Parse contacts */ diff --git a/src/core/sipe-ucs.c b/src/core/sipe-ucs.c index f7b43739..02f9b23f 100644 --- a/src/core/sipe-ucs.c +++ b/src/core/sipe-ucs.c @@ -44,12 +44,12 @@ #include "sipe-utils.h" #include "sipe-xml.h" -struct ucs_transaction { +struct sipe_ucs_transaction { GSList *pending_requests; }; typedef void (ucs_callback)(struct sipe_core_private *sipe_private, - struct ucs_transaction *trans, + struct sipe_ucs_transaction *trans, const sipe_xml *body, gpointer callback_data); @@ -57,12 +57,12 @@ struct ucs_request { gchar *body; ucs_callback *cb; gpointer cb_data; - struct ucs_transaction *transaction; + struct sipe_ucs_transaction *transaction; struct sipe_http_request *request; }; struct sipe_ucs { - struct ucs_transaction default_transaction; + struct sipe_ucs_transaction default_transaction; struct ucs_request *active_request; gchar *ews_url; time_t last_response; @@ -74,7 +74,7 @@ struct sipe_ucs { static void sipe_ucs_request_free(struct sipe_core_private *sipe_private, struct ucs_request *data) { - struct ucs_transaction *trans = data->transaction; + struct sipe_ucs_transaction *trans = data->transaction; trans->pending_requests = g_slist_remove(trans->pending_requests, data); @@ -125,7 +125,7 @@ static void sipe_ucs_http_response(struct sipe_core_private *sipe_private, static void sipe_ucs_next_request(struct sipe_core_private *sipe_private) { struct sipe_ucs *ucs = sipe_private->ucs; - struct ucs_transaction *trans; + struct sipe_ucs_transaction *trans; if (ucs->active_request || ucs->shutting_down || !ucs->ews_url) return; @@ -178,6 +178,7 @@ static void sipe_ucs_next_request(struct sipe_core_private *sipe_private) } static gboolean sipe_ucs_http_request(struct sipe_core_private *sipe_private, + struct sipe_ucs_transaction *trans, gchar *body, /* takes ownership */ ucs_callback *callback, gpointer callback_data) @@ -192,15 +193,14 @@ static gboolean sipe_ucs_http_request(struct sipe_core_private *sipe_private, return(FALSE); } else { - struct ucs_transaction *trans; struct ucs_request *data = g_new0(struct ucs_request, 1); data->cb = callback; data->cb_data = callback_data; data->body = body; - /* @TODO */ - trans = &ucs->default_transaction; + if (!trans) + trans = &ucs->default_transaction; data->transaction = trans; trans->pending_requests = g_slist_append(trans->pending_requests, data); @@ -211,7 +211,7 @@ static gboolean sipe_ucs_http_request(struct sipe_core_private *sipe_private, } static void sipe_ucs_get_user_photo_response(struct sipe_core_private *sipe_private, - SIPE_UNUSED_PARAMETER struct ucs_transaction *trans, + SIPE_UNUSED_PARAMETER struct sipe_ucs_transaction *trans, const sipe_xml *body, gpointer callback_data) { @@ -259,6 +259,7 @@ void sipe_ucs_get_photo(struct sipe_core_private *sipe_private, sipe_get_no_sip_uri(uri)); if (!sipe_ucs_http_request(sipe_private, + NULL, body, sipe_ucs_get_user_photo_response, payload)) @@ -266,7 +267,7 @@ void sipe_ucs_get_photo(struct sipe_core_private *sipe_private, } static void sipe_ucs_ignore_response(struct sipe_core_private *sipe_private, - SIPE_UNUSED_PARAMETER struct ucs_transaction *trans, + SIPE_UNUSED_PARAMETER struct sipe_ucs_transaction *trans, SIPE_UNUSED_PARAMETER const sipe_xml *body, SIPE_UNUSED_PARAMETER gpointer callback_data) { @@ -301,7 +302,7 @@ static void ucs_extract_keys(const sipe_xml *persona_node, } static void sipe_ucs_add_new_im_contact_to_group_response(struct sipe_core_private *sipe_private, - SIPE_UNUSED_PARAMETER struct ucs_transaction *trans, + SIPE_UNUSED_PARAMETER struct sipe_ucs_transaction *trans, const sipe_xml *body, gpointer callback_data) { @@ -337,6 +338,7 @@ static void sipe_ucs_add_new_im_contact_to_group_response(struct sipe_core_priva } void sipe_ucs_group_add_buddy(struct sipe_core_private *sipe_private, + struct sipe_ucs_transaction *trans, struct sipe_group *group, struct sipe_buddy *buddy, const gchar *who) @@ -353,6 +355,7 @@ void sipe_ucs_group_add_buddy(struct sipe_core_private *sipe_private, group->change_key); sipe_ucs_http_request(sipe_private, + trans, body, sipe_ucs_ignore_response, NULL); @@ -367,6 +370,7 @@ void sipe_ucs_group_add_buddy(struct sipe_core_private *sipe_private, group->change_key); if (!sipe_ucs_http_request(sipe_private, + trans, body, sipe_ucs_add_new_im_contact_to_group_response, payload)) @@ -375,6 +379,7 @@ void sipe_ucs_group_add_buddy(struct sipe_core_private *sipe_private, } void sipe_ucs_group_remove_buddy(struct sipe_core_private *sipe_private, + struct sipe_ucs_transaction *trans, struct sipe_group *group, struct sipe_buddy *buddy) { @@ -395,6 +400,7 @@ void sipe_ucs_group_remove_buddy(struct sipe_core_private *sipe_private, group->change_key); sipe_ucs_http_request(sipe_private, + trans, body, sipe_ucs_ignore_response, NULL); @@ -426,7 +432,7 @@ static struct sipe_group *ucs_create_group(struct sipe_core_private *sipe_privat } static void sipe_ucs_add_im_group_response(struct sipe_core_private *sipe_private, - SIPE_UNUSED_PARAMETER struct ucs_transaction *trans, + struct sipe_ucs_transaction *trans, const sipe_xml *body, gpointer callback_data) { @@ -445,6 +451,7 @@ static void sipe_ucs_add_im_group_response(struct sipe_core_private *sipe_privat sipe_buddy_insert_group(buddy, group); sipe_ucs_group_add_buddy(sipe_private, + trans, group, buddy, who); @@ -454,6 +461,7 @@ static void sipe_ucs_add_im_group_response(struct sipe_core_private *sipe_privat } void sipe_ucs_group_create(struct sipe_core_private *sipe_private, + struct sipe_ucs_transaction *trans, const gchar *name, const gchar *who) { @@ -465,6 +473,7 @@ void sipe_ucs_group_create(struct sipe_core_private *sipe_private, name); if (!sipe_ucs_http_request(sipe_private, + trans, body, sipe_ucs_add_im_group_response, payload)) @@ -485,6 +494,7 @@ void sipe_ucs_group_rename(struct sipe_core_private *sipe_private, new_name); sipe_ucs_http_request(sipe_private, + NULL, body, sipe_ucs_ignore_response, NULL); @@ -500,13 +510,14 @@ void sipe_ucs_group_remove(struct sipe_core_private *sipe_private, group->change_key); sipe_ucs_http_request(sipe_private, + NULL, body, sipe_ucs_ignore_response, NULL); } static void sipe_ucs_get_im_item_list_response(struct sipe_core_private *sipe_private, - SIPE_UNUSED_PARAMETER struct ucs_transaction *trans, + SIPE_UNUSED_PARAMETER struct sipe_ucs_transaction *trans, const sipe_xml *body, SIPE_UNUSED_PARAMETER gpointer callback_data) { @@ -603,6 +614,7 @@ static void ucs_get_im_item_list(struct sipe_core_private *sipe_private) { if (sipe_private->ucs->migrated) sipe_ucs_http_request(sipe_private, + NULL, g_strdup(""), sipe_ucs_get_im_item_list_response, NULL); @@ -673,7 +685,7 @@ void sipe_ucs_init(struct sipe_core_private *sipe_private, void sipe_ucs_free(struct sipe_core_private *sipe_private) { struct sipe_ucs *ucs = sipe_private->ucs; - struct ucs_transaction *trans; + struct sipe_ucs_transaction *trans; if (!ucs) return; diff --git a/src/core/sipe-ucs.h b/src/core/sipe-ucs.h index 05a12a0a..6f99151e 100644 --- a/src/core/sipe-ucs.h +++ b/src/core/sipe-ucs.h @@ -25,6 +25,7 @@ struct sipe_buddy; struct sipe_core_private; struct sipe_group; +struct sipe_ucs_transaction; /** * Get buddy photo @@ -50,11 +51,13 @@ gboolean sipe_ucs_is_migrated(struct sipe_core_private *sipe_private); * Add existing/new buddy to group * * @param sipe_private SIPE core private data + * @param trans UCS transaction (may be @c NULL) * @param group sipe_group structure * @param buddy sipe_buddy structure (may be @c NULL) * @param who SIP URI of the new buddy */ void sipe_ucs_group_add_buddy(struct sipe_core_private *sipe_private, + struct sipe_ucs_transaction *trans, struct sipe_group *group, struct sipe_buddy *buddy, const gchar *who); @@ -63,10 +66,12 @@ void sipe_ucs_group_add_buddy(struct sipe_core_private *sipe_private, * Remove buddy from group * * @param sipe_private SIPE core private data + * @param trans UCS transaction (may be @c NULL) * @param group sipe_group structure (may be @c NULL) * @param buddy sipe_buddy structure */ void sipe_ucs_group_remove_buddy(struct sipe_core_private *sipe_private, + struct sipe_ucs_transaction *trans, struct sipe_group *group, struct sipe_buddy *buddy); @@ -74,10 +79,12 @@ void sipe_ucs_group_remove_buddy(struct sipe_core_private *sipe_private, * Create group * * @param sipe_private SIPE core private data + * @param trans UCS transaction (may be @c NULL) * @param name name for group * @param who SIP URI of the buddy to add to the new group */ void sipe_ucs_group_create(struct sipe_core_private *sipe_private, + struct sipe_ucs_transaction *trans, const gchar *name, const gchar *who); -- 2.11.4.GIT