diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-07-16 17:45:55 +0100 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-07-18 11:43:12 +0100 |
commit | 5752b2a7b92f91fb80874272137a89151c630f21 (patch) | |
tree | 4241f8afd4612ac8ee180223da96a549557311cc | |
parent | 1158ce4649fe88dc410769665def19e5e702c9ec (diff) |
presence-cache: ignore caps nodes when we see google 'ext' features
Google keeps changing the node for its voice-v1, video-v1, share-v1,
etc. features. Let's just ignore it from now on and if there's no hash
treat it as if it might be Google.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r-- | src/presence-cache.c | 112 | ||||
-rw-r--r-- | tests/twisted/jingle-share/jingleshareutils.py | 7 |
2 files changed, 73 insertions, 46 deletions
diff --git a/src/presence-cache.c b/src/presence-cache.c index 9497dd0ad..23d1e8ade 100644 --- a/src/presence-cache.c +++ b/src/presence-cache.c @@ -497,48 +497,9 @@ static void gabble_presence_cache_add_bundle_caps (GabblePresenceCache *cache, static void gabble_presence_cache_add_bundles (GabblePresenceCache *cache) { -#define GOOGLE_BUNDLE(cap, features) \ - gabble_presence_cache_add_bundle_caps (cache, \ - "http://www.google.com/xmpp/client/caps#" cap, features); \ - gabble_presence_cache_add_bundle_caps (cache, \ - "http://talk.google.com/xmpp/client/caps#" cap, features); \ - gabble_presence_cache_add_bundle_caps (cache, \ - "http://www.android.com/gtalk/client/caps#" cap, features); \ - gabble_presence_cache_add_bundle_caps (cache, \ - "http://www.android.com/gtalk/client/caps2#" cap, features); \ - gabble_presence_cache_add_bundle_caps (cache, \ - "http://talk.google.com/xmpp/bot/caps#" cap, features); - - /* Cache various bundle from the Google Talk clients as trusted. Some old - * versions of Google Talk do not reply correctly to discovery requests. - * Plus, we know what Google's bundles mean, so it's a waste of time to disco - * them, particularly the ones for features we don't support. The desktop - * client doesn't currently have all of these, but it doesn't hurt to cache - * them anyway. - */ - GOOGLE_BUNDLE ("voice-v1", NS_GOOGLE_FEAT_VOICE); - GOOGLE_BUNDLE ("video-v1", NS_GOOGLE_FEAT_VIDEO); - - /* File transfer support */ - GOOGLE_BUNDLE ("share-v1", NS_GOOGLE_FEAT_SHARE); - - /* Not really sure what this ones is. */ - GOOGLE_BUNDLE ("sms-v1", NULL); - - /* TODO: remove this when we fix fd.o#22768. */ - GOOGLE_BUNDLE ("pmuc-v1", NULL); - - /* The camera-v1 bundle seems to mean "I have a camera plugged in". Not - * having it doesn't seem to affect anything, and we have no way of exposing - * that information anyway. - */ - GOOGLE_BUNDLE ("camera-v1", NULL); - -#undef GOOGLE_BUNDLE - - /* We should also cache the ext='' bundles Gabble advertises: older Gabbles - * advertise these and don't support hashed caps, and we shouldn't need to - * disco them. + /* We cache the ext='' bundles Gabble advertises: older Gabbles + * advertise these and don't support hashed caps, and we shouldn't + * need to disco them. */ gabble_presence_cache_add_bundle_caps (cache, NS_GABBLE_CAPS "#" BUNDLE_VOICE_V1, NS_GOOGLE_FEAT_VOICE); @@ -1503,6 +1464,44 @@ _caps_disco_cb (GabbleDisco *disco, g_ptr_array_unref (data_forms); } +static gboolean +get_google_cap (const gchar *fragment, + const gchar **ns) +{ + if (!tp_strdiff (fragment, "voice-v1")) + { + *ns = NS_GOOGLE_FEAT_VOICE; + return TRUE; + } + else if (!tp_strdiff (fragment, "video-v1")) + { + *ns = NS_GOOGLE_FEAT_VIDEO; + return TRUE; + } + else if (!tp_strdiff (fragment, "share-v1")) + { + *ns = NS_GOOGLE_FEAT_SHARE; + return TRUE; + } + else if (!tp_strdiff (fragment, "sms-v1")) + { + *ns = NULL; + return TRUE; + } + else if (!tp_strdiff (fragment, "pmuc-v1")) + { + *ns = NULL; + return TRUE; + } + else if (!tp_strdiff (fragment, "camera-v1")) + { + *ns = NULL; + return TRUE; + } + + return FALSE; +} + static void _process_caps_uri (GabblePresenceCache *cache, const gchar *from, @@ -1521,6 +1520,7 @@ _process_caps_uri (GabblePresenceCache *cache, TpHandleRepoIface *contact_repo; WockyCapsCache *caps_cache; gchar *uri = g_strdup_printf ("%s#%s", node, fragment); + const gchar *ns = NULL; priv = cache->priv; contact_repo = tp_base_connection_get_handles ( @@ -1588,6 +1588,34 @@ _process_caps_uri (GabblePresenceCache *cache, if (cached_caps != NULL) gabble_capability_set_free (cached_caps); } + else if (hash == NULL && get_google_cap (fragment, &ns)) + { + /* if the hash is NULL then are looking at the ext='...' values, + * so this is starting to smell like Google */ + GabblePresence *presence = gabble_presence_cache_get (cache, handle); + + /* we already know about this fragment; apply the known value to + * the (handle, resource) */ + DEBUG ("we know about fragment %s, setting caps for %u (%s)", fragment, handle, + from); + + if (presence != NULL) + { + GabbleCapabilitySet *cap_set = gabble_capability_set_new (); + + if (ns != NULL) + gabble_capability_set_add (cap_set, ns); + + gabble_presence_set_capabilities ( + presence, resource, cap_set, NULL, serial); + + gabble_capability_set_free (cap_set); + } + else + { + DEBUG ("presence not found"); + } + } else { GSList *waiters; diff --git a/tests/twisted/jingle-share/jingleshareutils.py b/tests/twisted/jingle-share/jingleshareutils.py index 16c75fbda..6ade4f50d 100644 --- a/tests/twisted/jingle-share/jingleshareutils.py +++ b/tests/twisted/jingle-share/jingleshareutils.py @@ -64,19 +64,18 @@ def test_ft_caps_from_contact(q, bus, conn, stream, contact, contact_handle, cli c = presence.addElement((ns.CAPS, 'c')) c['node'] = client c['ext'] = "share-v1" - c['ver'] = compute_caps_hash([], [], {}) + c['ver'] = '1.1' stream.send(presence) # Gabble looks up our capabilities event = q.expect('stream-iq', to=contact, query_ns=ns.DISCO_INFO) query_node = xpath.queryForNodes('/iq/query', event.stanza)[0] - assert query_node.attributes['node'] == \ - client + '#' + c['ext'] + assertEquals(client + '#' + c['ver'], query_node.attributes['node']) # send good reply result = make_result_iq(stream, event.stanza) query = result.firstChildElement() - query['node'] = client + '#' + c['ext'] + query['node'] = client + '#' + c['ver'] feature = query.addElement('feature') feature['var'] = ns.GOOGLE_FEAT_SHARE stream.send(result) |