[telepathy-gabble/master] Treat <item-not-found/> as the empty vCard
Will Thompson
will.thompson at collabora.co.uk
Mon Jan 11 05:42:39 PST 2010
When we want to update our vCard, we first retrieve our vCard from the
server. XEP-0054 says that the server MUST return <item-not-found/> if
you have no vCard set, but we previously assumed that the server would
return success, with an empty <vCard/> node. Prosody respects the XEP.
So, let's treat the former case identically to the latter.
Fixes: fd.o#25987
Reviewed-by: Simon McVittie <simon.mcvittie at collabora.co.uk>
---
src/vcard-manager.c | 13 +++++++++-
tests/twisted/Makefile.am | 1 +
tests/twisted/vcard/item-not-found.py | 42 +++++++++++++++++++++++++++++++++
3 files changed, 55 insertions(+), 1 deletions(-)
create mode 100644 tests/twisted/vcard/item-not-found.py
diff --git a/src/vcard-manager.c b/src/vcard-manager.c
index 9ccd633..4353609 100644
--- a/src/vcard-manager.c
+++ b/src/vcard-manager.c
@@ -1109,6 +1109,13 @@ suspended_request_timeout_cb (gpointer data)
return FALSE;
}
+static gboolean
+is_item_not_found (const GError *error)
+{
+ return (error->domain == GABBLE_XMPP_ERROR &&
+ error->code == XMPP_ERROR_ITEM_NOT_FOUND);
+}
+
/* Called when a GET request in the pipeline has either succeeded or failed. */
static void
pipeline_reply_cb (GabbleConnection *conn,
@@ -1134,7 +1141,11 @@ pipeline_reply_cb (GabbleConnection *conn,
entry->pipeline_item = NULL;
- if (error)
+ /* XEP-0054 says that the server MUST return <item-not-found/> if you have no
+ * vCard set, so we should treat that case identically to the server
+ * returning success but with no <vCard/> node.
+ */
+ if (error != NULL && !is_item_not_found (error))
{
/* First, handle the error "wait": suspend the request and replay it
* later */
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 0d0a33c..34d7079 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -82,6 +82,7 @@ TWISTED_TESTS = \
tubes/request-invalid-dbus-tube.py \
tubes/test-get-available-tubes.py \
tubes/test-socks5-muc.py \
+ vcard/item-not-found.py \
vcard/overlapping-sets.py \
vcard/redundant-set.py \
vcard/set-set-disconnect.py \
diff --git a/tests/twisted/vcard/item-not-found.py b/tests/twisted/vcard/item-not-found.py
new file mode 100644
index 0000000..77a3fab
--- /dev/null
+++ b/tests/twisted/vcard/item-not-found.py
@@ -0,0 +1,42 @@
+"""
+Regression test for <http://bugs.freedesktop.org/show_bug.cgi?id=25987> where
+Gabble didn't understand that <item-not-found/> just means the user doesn't
+have a vCard yet, and so it can go right ahead and set one.
+"""
+
+from twisted.words.xish import domish
+from servicetest import call_async
+from gabbletest import (
+ exec_test, sync_stream, send_error_reply, expect_and_handle_set_vcard,
+ )
+import ns
+
+def expect_get_and_send_item_not_found(q, stream):
+ get_vcard_event = q.expect('stream-iq', query_ns=ns.VCARD_TEMP,
+ query_name='vCard', iq_type='get')
+
+ error = domish.Element((None, 'error'))
+ error['type'] = 'cancel'
+ error.addElement((ns.STANZA, 'item-not-found'))
+ send_error_reply(stream, get_vcard_event.stanza, error)
+
+def test(q, bus, conn, stream):
+ conn.Connect()
+
+ expect_get_and_send_item_not_found(q, stream)
+
+ sync_stream(q, stream)
+
+ call_async(
+ q, conn.Avatars, 'SetAvatar', 'Guy.brush', 'image/x-mighty-pirate')
+
+ # Gabble checks again, but we still don't have a vCard
+ expect_get_and_send_item_not_found(q, stream)
+
+ # Never mind! It creates a new one.
+ expect_and_handle_set_vcard(q, stream)
+
+ q.expect('dbus-return', method='SetAvatar')
+
+if __name__ == '__main__':
+ exec_test(test)
--
1.5.6.5
More information about the telepathy-commits
mailing list