diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2012-01-30 15:26:01 +0000 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2012-01-31 17:40:44 +0000 |
commit | 8601d29953e44416e5413c8e8053f980397f04b3 (patch) | |
tree | a19c741b061815e5d847d0f8c10a48588fd212cc | |
parent | 3403ab38582559b2293feb17f69f2df90e6ed229 (diff) | |
download | telepathy-gabble-8601d29953e44416e5413c8e8053f980397f04b3.tar.gz |
location: stop using lm_message_node_get_child_with_namespace()
The test change illustrates the problem with using
lm_message_node_get_child_with_namespace(): the test suite was sending
a broken stanza, and we still accepted it. It should have sent:
<iq type=result>
<pubsub>
<items>
<item>
<geoloc>
But instead it sent:
<iq type=result>
<pubsub>
<items>
<item>
<geoloc>
This patch would be smaller if
<https://bugs.freedesktop.org/show_bug.cgi?id=45400> were fixed.
-rw-r--r-- | src/conn-location.c | 42 | ||||
-rw-r--r-- | tests/twisted/test-location.py | 4 |
2 files changed, 35 insertions, 11 deletions
diff --git a/src/conn-location.c b/src/conn-location.c index 3131d736f..b409abe39 100644 --- a/src/conn-location.c +++ b/src/conn-location.c @@ -10,6 +10,7 @@ #include <telepathy-glib/gtypes.h> #include <telepathy-glib/interfaces.h> +#include <wocky/wocky-namespaces.h> #include <gabble/gabble.h> @@ -75,8 +76,10 @@ build_mapping_tables (void) } } -static gboolean update_location_from_msg (GabbleConnection *conn, - TpHandle contact, WockyStanza *msg); +static gboolean update_location_from_item ( + GabbleConnection *conn, + TpHandle contact, + WockyNode *item_node); /* * get_cached_location: @@ -181,9 +184,17 @@ request_location_reply_cb (GObject *source, } else { + WockyNode *pubsub_node, *items_node = NULL, *item_node = NULL; GHashTable *location; - if (update_location_from_msg (ctx->self, ctx->handle, reply)) + pubsub_node = wocky_node_get_child_ns ( + wocky_stanza_get_top_node (reply), "pubsub", NS_PUBSUB); + if (pubsub_node != NULL) + items_node = wocky_node_get_child (pubsub_node, "items"); + if (items_node != NULL) + item_node = wocky_node_get_child (items_node, "item"); + + if (update_location_from_item (ctx->self, ctx->handle, item_node)) { location = get_cached_location (ctx->self, ctx->handle); /* We just cached a location for this contact, so it should be @@ -516,9 +527,10 @@ conn_location_properties_setter (GObject *object, } static gboolean -update_location_from_msg (GabbleConnection *conn, - TpHandle contact, - WockyStanza *msg) +update_location_from_item ( + GabbleConnection *conn, + TpHandle contact, + WockyNode *item_node) { WockyNode *node; GHashTable *location = g_hash_table_new_full (g_direct_hash, g_direct_equal, @@ -530,8 +542,10 @@ update_location_from_msg (GabbleConnection *conn, WockyNode *subloc_node; const gchar *lang; - node = lm_message_node_get_child_with_namespace (wocky_stanza_get_top_node (msg), - "geoloc", NULL); + if (item_node == NULL) + return FALSE; + + node = wocky_node_get_child_ns (item_node, "geoloc", NS_GEOLOC); if (node == NULL) return FALSE; @@ -625,6 +639,7 @@ location_pep_node_changed (WockyPepService *pep, TpBaseConnection *base = (TpBaseConnection *) conn; TpHandle handle; const gchar *jid; + WockyNode *event_node, *items_node = NULL, *item_node = NULL; jid = wocky_bare_contact_get_jid (contact); handle = tp_handle_ensure (contact_repo, jid, NULL, NULL); @@ -638,7 +653,16 @@ location_pep_node_changed (WockyPepService *pep, /* Ignore echoed pubsub notifications */ goto out; - update_location_from_msg (conn, handle, stanza); + /* TODO: WockyPepService should do this for us. + * https://bugs.freedesktop.org/show_bug.cgi?id=45400 */ + event_node = wocky_node_get_child_ns ( + wocky_stanza_get_top_node (stanza), "event", WOCKY_XMPP_NS_PUBSUB_EVENT); + if (event_node != NULL) + items_node = wocky_node_get_child (event_node, "items"); + if (items_node != NULL) + item_node = wocky_node_get_child (items_node, "item"); + + update_location_from_item (conn, handle, item_node); out: tp_handle_unref (contact_repo, handle); diff --git a/tests/twisted/test-location.py b/tests/twisted/test-location.py index 71433ec04..cb1817321 100644 --- a/tests/twisted/test-location.py +++ b/tests/twisted/test-location.py @@ -275,8 +275,8 @@ def test(q, bus, conn, stream): # Hey, while we weren't looking Bob moved abroad! result = make_result_iq(stream, e.stanza) result['from'] = 'bob@foo.com' - query = result.firstChildElement() - result.addChild( + pubsub_node = result.firstChildElement() + pubsub_node.addChild( elem('items', node=ns.GEOLOC)( elem('item', id='12345')( elem(ns.GEOLOC, 'geoloc')( |