Merge lp:~ted/url-dispatcher/intent-pkg-domain into lp:url-dispatcher/rtm-14.09

Proposed by Ted Gould
Status: Merged
Approved by: Ted Gould
Approved revision: 91
Merged at revision: 79
Proposed branch: lp:~ted/url-dispatcher/intent-pkg-domain
Merge into: lp:url-dispatcher/rtm-14.09
Diff against target: 212 lines (+112/-1)
8 files modified
service/dispatcher.c (+27/-1)
service/update-directory.c (+10/-0)
tests/CMakeLists.txt (+1/-0)
tests/directory-update-test.cc (+22/-0)
tests/dispatcher-test.cc (+25/-0)
tests/test-urls-intent/intent-mixed.url-dispatcher (+13/-0)
tests/test-urls-intent/intent-no-good.url-dispatcher (+8/-0)
tests/test-urls-intent/intent-single.url-dispatcher (+6/-0)
To merge this branch: bzr merge lp:~ted/url-dispatcher/intent-pkg-domain
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Review via email: mp+245880@code.launchpad.net

Commit message

Special handling for intent URLs

Description of the change

Makes it so that intent URLs are handled differently in that we use our current domain suffix for the package name instead of the domain. We don't want to choose packages based on domain there, as it isn't as important as the package that is supposed to be used. Many webapps think we're Android, so they send us intent URLs.

To post a comment you must log in.
Revision history for this message
Charles Kerr (charlesk) wrote :

I found a few optional nitpicks, but LGTM

review: Approve
Revision history for this message
Ted Gould (ted) wrote :

Marked as Approved to get the new small changes in Charles' comments. And he's out sick so he can't do it himself.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'service/dispatcher.c'
--- service/dispatcher.c 2014-12-11 19:00:04 +0000
+++ service/dispatcher.c 2015-01-23 14:34:12 +0000
@@ -31,6 +31,7 @@
31static GRegex * applicationre = NULL;31static GRegex * applicationre = NULL;
32static GRegex * appidre = NULL;32static GRegex * appidre = NULL;
33static GRegex * genericre = NULL;33static GRegex * genericre = NULL;
34static GRegex * intentre = NULL;
34static sqlite3 * urldb = NULL;35static sqlite3 * urldb = NULL;
3536
36/* Errors */37/* Errors */
@@ -326,6 +327,22 @@
326 return TRUE;327 return TRUE;
327}328}
328329
330/* Determine the domain for an intent using the package variable */
331static gchar *
332intent_domain (const gchar * url)
333{
334 gchar * domain = NULL;
335 GMatchInfo * intentmatch = NULL;
336
337 if (g_regex_match(intentre, url, 0, &intentmatch)) {
338 domain = g_match_info_fetch(intentmatch, 1);
339
340 g_match_info_free(intentmatch);
341 }
342
343 return domain;
344}
345
329/* The core of the URL handling */346/* The core of the URL handling */
330gboolean347gboolean
331dispatcher_url_to_appid (const gchar * url, gchar ** out_appid, const gchar ** out_url)348dispatcher_url_to_appid (const gchar * url, gchar ** out_appid, const gchar ** out_url)
@@ -367,7 +384,14 @@
367 if (g_regex_match(genericre, url, 0, &genericmatch)) {384 if (g_regex_match(genericre, url, 0, &genericmatch)) {
368 gboolean found = FALSE;385 gboolean found = FALSE;
369 gchar * protocol = g_match_info_fetch(genericmatch, 1);386 gchar * protocol = g_match_info_fetch(genericmatch, 1);
370 gchar * domain = g_match_info_fetch(genericmatch, 2);387 gchar * domain = NULL;
388
389 /* We special case the intent domain (further comment there) */
390 if (g_strcmp0(protocol, "intent") == 0) {
391 domain = intent_domain(url);
392 } else {
393 domain = g_match_info_fetch(genericmatch, 2);
394 }
371395
372 *out_appid = url_db_find_url(urldb, protocol, domain);396 *out_appid = url_db_find_url(urldb, protocol, domain);
373 g_debug("Protocol '%s' for domain '%s' resulting in app id '%s'", protocol, domain, *out_appid);397 g_debug("Protocol '%s' for domain '%s' resulting in app id '%s'", protocol, domain, *out_appid);
@@ -450,6 +474,7 @@
450 applicationre = g_regex_new("^application:///([a-zA-Z0-9_\\.-]*)\\.desktop$", 0, 0, NULL);474 applicationre = g_regex_new("^application:///([a-zA-Z0-9_\\.-]*)\\.desktop$", 0, 0, NULL);
451 appidre = g_regex_new("^appid://([a-z0-9\\.-]*)/([a-zA-Z0-9-]*)/([a-zA-Z0-9\\.-]*)$", 0, 0, NULL);475 appidre = g_regex_new("^appid://([a-z0-9\\.-]*)/([a-zA-Z0-9-]*)/([a-zA-Z0-9\\.-]*)$", 0, 0, NULL);
452 genericre = g_regex_new("^([a-z][a-z0-9]*):(?://(?:.*@)?([a-zA-Z0-9\\.-]*)(?::[0-9]*)?/?)?(.*)?$", 0, 0, NULL);476 genericre = g_regex_new("^([a-z][a-z0-9]*):(?://(?:.*@)?([a-zA-Z0-9\\.-]*)(?::[0-9]*)?/?)?(.*)?$", 0, 0, NULL);
477 intentre = g_regex_new("^intent://.*package=([a-zA-Z0-9\\.]*);.*$", 0, 0, NULL);
453478
454 g_bus_get(G_BUS_TYPE_SESSION, cancellable, bus_got, mainloop);479 g_bus_get(G_BUS_TYPE_SESSION, cancellable, bus_got, mainloop);
455480
@@ -471,6 +496,7 @@
471 g_regex_unref(applicationre);496 g_regex_unref(applicationre);
472 g_regex_unref(appidre);497 g_regex_unref(appidre);
473 g_regex_unref(genericre);498 g_regex_unref(genericre);
499 g_regex_unref(intentre);
474 sqlite3_close(urldb);500 sqlite3_close(urldb);
475501
476 return TRUE;502 return TRUE;
477503
=== modified file 'service/update-directory.c'
--- service/update-directory.c 2014-05-27 17:06:58 +0000
+++ service/update-directory.c 2015-01-23 14:34:12 +0000
@@ -55,6 +55,16 @@
55 return;55 return;
56 }56 }
5757
58 if (g_strcmp0(protocol, "intent") == 0) {
59 /* Special handling for intent, we have to have a domain suffix
60 there because otherwise things will get crazy as we're handling
61 it by package lookup in the service. */
62 if (suffix == NULL) {
63 g_warning("File %s: Array entry %d is an 'intent' protocol but doesn't have a package name", urldata->filename, index);
64 return;
65 }
66 }
67
58 if (!url_db_insert_url(urldata->db, urldata->filename, protocol, suffix)) {68 if (!url_db_insert_url(urldata->db, urldata->filename, protocol, suffix)) {
59 const gchar * additional[7] = {69 const gchar * additional[7] = {
60 "Filename",70 "Filename",
6171
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2014-09-22 15:20:40 +0000
+++ tests/CMakeLists.txt 2015-01-23 14:34:12 +0000
@@ -117,6 +117,7 @@
117add_definitions ( -DUPDATE_DIRECTORY_TOOL="${CMAKE_BINARY_DIR}/service/update-directory" )117add_definitions ( -DUPDATE_DIRECTORY_TOOL="${CMAKE_BINARY_DIR}/service/update-directory" )
118add_definitions ( -DUPDATE_DIRECTORY_URLS="${CMAKE_CURRENT_SOURCE_DIR}/test-urls-simple" )118add_definitions ( -DUPDATE_DIRECTORY_URLS="${CMAKE_CURRENT_SOURCE_DIR}/test-urls-simple" )
119add_definitions ( -DUPDATE_DIRECTORY_VARIED="${CMAKE_CURRENT_SOURCE_DIR}/test-urls-varied" )119add_definitions ( -DUPDATE_DIRECTORY_VARIED="${CMAKE_CURRENT_SOURCE_DIR}/test-urls-varied" )
120add_definitions ( -DUPDATE_DIRECTORY_INTENT="${CMAKE_CURRENT_SOURCE_DIR}/test-urls-intent" )
120121
121add_executable (directory-update-test directory-update-test.cc)122add_executable (directory-update-test directory-update-test.cc)
122target_link_libraries (directory-update-test123target_link_libraries (directory-update-test
123124
=== modified file 'tests/directory-update-test.cc'
--- tests/directory-update-test.cc 2014-01-13 20:46:10 +0000
+++ tests/directory-update-test.cc 2015-01-23 14:34:12 +0000
@@ -351,3 +351,25 @@
351 /* Cleanup */351 /* Cleanup */
352 sqlite3_close(db);352 sqlite3_close(db);
353}353}
354
355TEST_F(DirectoryUpdateTest, IntentTest)
356{
357 sqlite3 * db = url_db_create_database();
358
359 gchar * cmdline = g_strdup_printf("%s \"%s\"", UPDATE_DIRECTORY_TOOL, UPDATE_DIRECTORY_INTENT);
360 g_spawn_command_line_sync(cmdline, NULL, NULL, NULL, NULL);
361 g_free(cmdline);
362
363 EXPECT_EQ(3, get_file_count(db));
364 EXPECT_EQ(3, get_url_count(db));
365
366 EXPECT_TRUE(has_file(db, UPDATE_DIRECTORY_INTENT "/intent-single.url-dispatcher"));
367 EXPECT_TRUE(has_file(db, UPDATE_DIRECTORY_INTENT "/intent-mixed.url-dispatcher"));
368 EXPECT_TRUE(has_file(db, UPDATE_DIRECTORY_INTENT "/intent-no-good.url-dispatcher"));
369
370 EXPECT_TRUE(has_url(db, "intent", "intent.single"));
371 EXPECT_TRUE(has_url(db, "intent", "intent.mixed"));
372 EXPECT_TRUE(has_url(db, "intent", "intent.mixed.again"));
373
374 sqlite3_close(db);
375}
354376
=== modified file 'tests/dispatcher-test.cc'
--- tests/dispatcher-test.cc 2014-12-11 18:33:34 +0000
+++ tests/dispatcher-test.cc 2015-01-23 14:34:12 +0000
@@ -55,6 +55,9 @@
55 url_db_set_file_motification_time(db, "/testdir/webapp.url-dispatcher", &timestamp);55 url_db_set_file_motification_time(db, "/testdir/webapp.url-dispatcher", &timestamp);
56 url_db_insert_url(db, "/testdir/webapp.url-dispatcher", "http", "foo.com");56 url_db_insert_url(db, "/testdir/webapp.url-dispatcher", "http", "foo.com");
5757
58 url_db_set_file_motification_time(db, "/testdir/intenter.url-dispatcher", &timestamp);
59 url_db_insert_url(db, "/testdir/intenter.url-dispatcher", "intent", "my.android.package");
60
58 sqlite3_close(db);61 sqlite3_close(db);
5962
60 testbus = g_test_dbus_new(G_TEST_DBUS_NONE);63 testbus = g_test_dbus_new(G_TEST_DBUS_NONE);
@@ -222,3 +225,25 @@
222 return;225 return;
223}226}
224227
228TEST_F(DispatcherTest, IntentTest)
229{
230 gchar * out_appid = NULL;
231 const gchar * out_url = NULL;
232
233 /* Intent basic test */
234 EXPECT_TRUE(dispatcher_url_to_appid("intent://foo.google.com/maps#Intent;scheme=http;package=my.android.package;end", &out_appid, &out_url));
235 EXPECT_STREQ("intenter", out_appid);
236 g_free(out_appid);
237
238 /* Not our intent test */
239 out_appid = NULL;
240 EXPECT_FALSE(dispatcher_url_to_appid("intent://foo.google.com/maps#Intent;scheme=http;package=not.android.package;end", &out_appid, &out_url));
241 EXPECT_EQ(NULL, out_appid);
242
243 /* Ensure domain is ignored */
244 out_appid = NULL;
245 EXPECT_FALSE(dispatcher_url_to_appid("intent://my.android.package/maps#Intent;scheme=http;package=not.android.package;end", &out_appid, &out_url));
246 EXPECT_EQ(NULL, out_appid);
247
248 return;
249}
225250
=== added directory 'tests/test-urls-intent'
=== added file 'tests/test-urls-intent/intent-mixed.url-dispatcher'
--- tests/test-urls-intent/intent-mixed.url-dispatcher 1970-01-01 00:00:00 +0000
+++ tests/test-urls-intent/intent-mixed.url-dispatcher 2015-01-23 14:34:12 +0000
@@ -0,0 +1,13 @@
1[
2 {
3 "protocol": "intent",
4 "domain-suffix": "intent.mixed"
5 },
6 {
7 "protocol": "intent"
8 },
9 {
10 "protocol": "intent",
11 "domain-suffix": "intent.mixed.again"
12 }
13]
014
=== added file 'tests/test-urls-intent/intent-no-good.url-dispatcher'
--- tests/test-urls-intent/intent-no-good.url-dispatcher 1970-01-01 00:00:00 +0000
+++ tests/test-urls-intent/intent-no-good.url-dispatcher 2015-01-23 14:34:12 +0000
@@ -0,0 +1,8 @@
1[
2 {
3 "protocol": "intent"
4 },
5 {
6 "protocol": "intent"
7 }
8]
09
=== added file 'tests/test-urls-intent/intent-single.url-dispatcher'
--- tests/test-urls-intent/intent-single.url-dispatcher 1970-01-01 00:00:00 +0000
+++ tests/test-urls-intent/intent-single.url-dispatcher 2015-01-23 14:34:12 +0000
@@ -0,0 +1,6 @@
1[
2 {
3 "protocol": "intent",
4 "domain-suffix": "intent.single"
5 }
6]

Subscribers

People subscribed via source and target branches