[telepathy-gabble/master] request pipeline: pass in error from result stanza as GError to callback
Dafydd Harries
dafydd.harries at collabora.co.uk
Mon Aug 17 07:01:28 PDT 2009
This allows vCard error handling to be greatly simplified.
---
src/request-pipeline.c | 16 +++++++++++++++-
src/vcard-manager.c | 45 ++++++---------------------------------------
2 files changed, 21 insertions(+), 40 deletions(-)
diff --git a/src/request-pipeline.c b/src/request-pipeline.c
index 83f490c..f80d8b8 100644
--- a/src/request-pipeline.c
+++ b/src/request-pipeline.c
@@ -279,9 +279,23 @@ response_cb (GabbleConnection *conn,
priv->items_in_flight = g_slist_remove (priv->items_in_flight, item);
if (!item->zombie)
- item->callback (priv->connection, reply, item->user_data, NULL);
+ {
+ GError *error = gabble_message_get_xmpp_error (reply);
+
+ if (error)
+ {
+ item->callback (priv->connection, reply, item->user_data, error);
+ g_error_free (error);
+ }
+ else
+ {
+ item->callback (priv->connection, reply, item->user_data, NULL);
+ }
+ }
else
+ {
DEBUG ("ignoring zombie connection reply");
+ }
delete_item (item);
diff --git a/src/vcard-manager.c b/src/vcard-manager.c
index 53c7725..123584a 100644
--- a/src/vcard-manager.c
+++ b/src/vcard-manager.c
@@ -825,28 +825,6 @@ observe_vcard (GabbleConnection *conn,
g_signal_emit (G_OBJECT (manager), signals[NICKNAME_UPDATE], 0, handle);
}
-static GError *
-get_error_from_pipeline_reply (LmMessage *reply_msg, GError *error)
-{
- GError *err = NULL;
-
- if (error)
- return g_error_copy (error);
-
- if (lm_message_get_sub_type (reply_msg) != LM_MESSAGE_SUB_TYPE_ERROR)
- return NULL;
-
- err = gabble_message_get_xmpp_error (reply_msg);
-
- if (err == NULL)
- {
- err = g_error_new (GABBLE_VCARD_MANAGER_ERROR,
- GABBLE_VCARD_MANAGER_ERROR_UNKNOWN, "An unknown error occurred");
- }
-
- return err;
-}
-
/* Called when a pre-set get request failed, or when a set request succeeded
* or failed.
*/
@@ -859,25 +837,21 @@ replace_reply_cb (GabbleConnection *conn,
GabbleVCardManager *self = GABBLE_VCARD_MANAGER (user_data);
GabbleVCardManagerPrivate *priv = self->priv;
TpBaseConnection *base = (TpBaseConnection *) conn;
-
- GError *err = get_error_from_pipeline_reply (reply_msg, error);
GList *li;
- LmMessageNode *node;
+ LmMessageNode *node = NULL;
/* If we sent a SET request, it's dead now. */
priv->edit_pipeline_item = NULL;
DEBUG ("called: %s error", (error) ? "some" : "no");
- if (err)
+ if (error)
{
/* We won't need our patched vcard after all */
if (priv->patched_vcard != NULL)
lm_message_node_unref (priv->patched_vcard);
priv->patched_vcard = NULL;
-
- node = NULL;
}
else
{
@@ -906,20 +880,17 @@ replace_reply_cb (GabbleConnection *conn,
{
GabbleVCardManagerEditRequest *req = li->data;
li = g_list_next (li);
- if (req->set_in_pipeline || err)
+ if (req->set_in_pipeline || error)
{
if (req->callback)
{
- (req->callback) (req->manager, req, node, err, req->user_data);
+ (req->callback) (req->manager, req, node, error, req->user_data);
}
gabble_vcard_manager_remove_edit_request (req);
}
}
- if (err != NULL)
- g_error_free (err);
-
/* If we've received more edit requests in the meantime, send them off. */
manager_patch_vcard (self, node);
}
@@ -1055,7 +1026,6 @@ pipeline_reply_cb (GabbleConnection *conn,
TpHandleRepoIface *contact_repo =
tp_base_connection_get_handles (base, TP_HANDLE_TYPE_CONTACT);
LmMessageNode *vcard_node = NULL;
- GError *err = NULL;
DEBUG("called for entry %p", entry);
@@ -1065,8 +1035,7 @@ pipeline_reply_cb (GabbleConnection *conn,
entry->pipeline_item = NULL;
- err = get_error_from_pipeline_reply (reply_msg, error);
- if (err)
+ if (error)
{
/* If request for our own vCard failed, and we do have
* pending edits to make, cancel those and return error
@@ -1081,9 +1050,7 @@ pipeline_reply_cb (GabbleConnection *conn,
}
/* Complete pending GET requests */
- cache_entry_complete_requests (entry, err);
-
- g_error_free (err);
+ cache_entry_complete_requests (entry, error);
return;
}
--
1.5.6.5
More information about the telepathy-commits
mailing list