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
1=== modified file 'service/dispatcher.c'
2--- service/dispatcher.c 2014-12-11 19:00:04 +0000
3+++ service/dispatcher.c 2015-01-23 14:34:12 +0000
4@@ -31,6 +31,7 @@
5 static GRegex * applicationre = NULL;
6 static GRegex * appidre = NULL;
7 static GRegex * genericre = NULL;
8+static GRegex * intentre = NULL;
9 static sqlite3 * urldb = NULL;
10
11 /* Errors */
12@@ -326,6 +327,22 @@
13 return TRUE;
14 }
15
16+/* Determine the domain for an intent using the package variable */
17+static gchar *
18+intent_domain (const gchar * url)
19+{
20+ gchar * domain = NULL;
21+ GMatchInfo * intentmatch = NULL;
22+
23+ if (g_regex_match(intentre, url, 0, &intentmatch)) {
24+ domain = g_match_info_fetch(intentmatch, 1);
25+
26+ g_match_info_free(intentmatch);
27+ }
28+
29+ return domain;
30+}
31+
32 /* The core of the URL handling */
33 gboolean
34 dispatcher_url_to_appid (const gchar * url, gchar ** out_appid, const gchar ** out_url)
35@@ -367,7 +384,14 @@
36 if (g_regex_match(genericre, url, 0, &genericmatch)) {
37 gboolean found = FALSE;
38 gchar * protocol = g_match_info_fetch(genericmatch, 1);
39- gchar * domain = g_match_info_fetch(genericmatch, 2);
40+ gchar * domain = NULL;
41+
42+ /* We special case the intent domain (further comment there) */
43+ if (g_strcmp0(protocol, "intent") == 0) {
44+ domain = intent_domain(url);
45+ } else {
46+ domain = g_match_info_fetch(genericmatch, 2);
47+ }
48
49 *out_appid = url_db_find_url(urldb, protocol, domain);
50 g_debug("Protocol '%s' for domain '%s' resulting in app id '%s'", protocol, domain, *out_appid);
51@@ -450,6 +474,7 @@
52 applicationre = g_regex_new("^application:///([a-zA-Z0-9_\\.-]*)\\.desktop$", 0, 0, NULL);
53 appidre = g_regex_new("^appid://([a-z0-9\\.-]*)/([a-zA-Z0-9-]*)/([a-zA-Z0-9\\.-]*)$", 0, 0, NULL);
54 genericre = g_regex_new("^([a-z][a-z0-9]*):(?://(?:.*@)?([a-zA-Z0-9\\.-]*)(?::[0-9]*)?/?)?(.*)?$", 0, 0, NULL);
55+ intentre = g_regex_new("^intent://.*package=([a-zA-Z0-9\\.]*);.*$", 0, 0, NULL);
56
57 g_bus_get(G_BUS_TYPE_SESSION, cancellable, bus_got, mainloop);
58
59@@ -471,6 +496,7 @@
60 g_regex_unref(applicationre);
61 g_regex_unref(appidre);
62 g_regex_unref(genericre);
63+ g_regex_unref(intentre);
64 sqlite3_close(urldb);
65
66 return TRUE;
67
68=== modified file 'service/update-directory.c'
69--- service/update-directory.c 2014-05-27 17:06:58 +0000
70+++ service/update-directory.c 2015-01-23 14:34:12 +0000
71@@ -55,6 +55,16 @@
72 return;
73 }
74
75+ if (g_strcmp0(protocol, "intent") == 0) {
76+ /* Special handling for intent, we have to have a domain suffix
77+ there because otherwise things will get crazy as we're handling
78+ it by package lookup in the service. */
79+ if (suffix == NULL) {
80+ g_warning("File %s: Array entry %d is an 'intent' protocol but doesn't have a package name", urldata->filename, index);
81+ return;
82+ }
83+ }
84+
85 if (!url_db_insert_url(urldata->db, urldata->filename, protocol, suffix)) {
86 const gchar * additional[7] = {
87 "Filename",
88
89=== modified file 'tests/CMakeLists.txt'
90--- tests/CMakeLists.txt 2014-09-22 15:20:40 +0000
91+++ tests/CMakeLists.txt 2015-01-23 14:34:12 +0000
92@@ -117,6 +117,7 @@
93 add_definitions ( -DUPDATE_DIRECTORY_TOOL="${CMAKE_BINARY_DIR}/service/update-directory" )
94 add_definitions ( -DUPDATE_DIRECTORY_URLS="${CMAKE_CURRENT_SOURCE_DIR}/test-urls-simple" )
95 add_definitions ( -DUPDATE_DIRECTORY_VARIED="${CMAKE_CURRENT_SOURCE_DIR}/test-urls-varied" )
96+add_definitions ( -DUPDATE_DIRECTORY_INTENT="${CMAKE_CURRENT_SOURCE_DIR}/test-urls-intent" )
97
98 add_executable (directory-update-test directory-update-test.cc)
99 target_link_libraries (directory-update-test
100
101=== modified file 'tests/directory-update-test.cc'
102--- tests/directory-update-test.cc 2014-01-13 20:46:10 +0000
103+++ tests/directory-update-test.cc 2015-01-23 14:34:12 +0000
104@@ -351,3 +351,25 @@
105 /* Cleanup */
106 sqlite3_close(db);
107 }
108+
109+TEST_F(DirectoryUpdateTest, IntentTest)
110+{
111+ sqlite3 * db = url_db_create_database();
112+
113+ gchar * cmdline = g_strdup_printf("%s \"%s\"", UPDATE_DIRECTORY_TOOL, UPDATE_DIRECTORY_INTENT);
114+ g_spawn_command_line_sync(cmdline, NULL, NULL, NULL, NULL);
115+ g_free(cmdline);
116+
117+ EXPECT_EQ(3, get_file_count(db));
118+ EXPECT_EQ(3, get_url_count(db));
119+
120+ EXPECT_TRUE(has_file(db, UPDATE_DIRECTORY_INTENT "/intent-single.url-dispatcher"));
121+ EXPECT_TRUE(has_file(db, UPDATE_DIRECTORY_INTENT "/intent-mixed.url-dispatcher"));
122+ EXPECT_TRUE(has_file(db, UPDATE_DIRECTORY_INTENT "/intent-no-good.url-dispatcher"));
123+
124+ EXPECT_TRUE(has_url(db, "intent", "intent.single"));
125+ EXPECT_TRUE(has_url(db, "intent", "intent.mixed"));
126+ EXPECT_TRUE(has_url(db, "intent", "intent.mixed.again"));
127+
128+ sqlite3_close(db);
129+}
130
131=== modified file 'tests/dispatcher-test.cc'
132--- tests/dispatcher-test.cc 2014-12-11 18:33:34 +0000
133+++ tests/dispatcher-test.cc 2015-01-23 14:34:12 +0000
134@@ -55,6 +55,9 @@
135 url_db_set_file_motification_time(db, "/testdir/webapp.url-dispatcher", &timestamp);
136 url_db_insert_url(db, "/testdir/webapp.url-dispatcher", "http", "foo.com");
137
138+ url_db_set_file_motification_time(db, "/testdir/intenter.url-dispatcher", &timestamp);
139+ url_db_insert_url(db, "/testdir/intenter.url-dispatcher", "intent", "my.android.package");
140+
141 sqlite3_close(db);
142
143 testbus = g_test_dbus_new(G_TEST_DBUS_NONE);
144@@ -222,3 +225,25 @@
145 return;
146 }
147
148+TEST_F(DispatcherTest, IntentTest)
149+{
150+ gchar * out_appid = NULL;
151+ const gchar * out_url = NULL;
152+
153+ /* Intent basic test */
154+ EXPECT_TRUE(dispatcher_url_to_appid("intent://foo.google.com/maps#Intent;scheme=http;package=my.android.package;end", &out_appid, &out_url));
155+ EXPECT_STREQ("intenter", out_appid);
156+ g_free(out_appid);
157+
158+ /* Not our intent test */
159+ out_appid = NULL;
160+ EXPECT_FALSE(dispatcher_url_to_appid("intent://foo.google.com/maps#Intent;scheme=http;package=not.android.package;end", &out_appid, &out_url));
161+ EXPECT_EQ(NULL, out_appid);
162+
163+ /* Ensure domain is ignored */
164+ out_appid = NULL;
165+ EXPECT_FALSE(dispatcher_url_to_appid("intent://my.android.package/maps#Intent;scheme=http;package=not.android.package;end", &out_appid, &out_url));
166+ EXPECT_EQ(NULL, out_appid);
167+
168+ return;
169+}
170
171=== added directory 'tests/test-urls-intent'
172=== added file 'tests/test-urls-intent/intent-mixed.url-dispatcher'
173--- tests/test-urls-intent/intent-mixed.url-dispatcher 1970-01-01 00:00:00 +0000
174+++ tests/test-urls-intent/intent-mixed.url-dispatcher 2015-01-23 14:34:12 +0000
175@@ -0,0 +1,13 @@
176+[
177+ {
178+ "protocol": "intent",
179+ "domain-suffix": "intent.mixed"
180+ },
181+ {
182+ "protocol": "intent"
183+ },
184+ {
185+ "protocol": "intent",
186+ "domain-suffix": "intent.mixed.again"
187+ }
188+]
189
190=== added file 'tests/test-urls-intent/intent-no-good.url-dispatcher'
191--- tests/test-urls-intent/intent-no-good.url-dispatcher 1970-01-01 00:00:00 +0000
192+++ tests/test-urls-intent/intent-no-good.url-dispatcher 2015-01-23 14:34:12 +0000
193@@ -0,0 +1,8 @@
194+[
195+ {
196+ "protocol": "intent"
197+ },
198+ {
199+ "protocol": "intent"
200+ }
201+]
202
203=== added file 'tests/test-urls-intent/intent-single.url-dispatcher'
204--- tests/test-urls-intent/intent-single.url-dispatcher 1970-01-01 00:00:00 +0000
205+++ tests/test-urls-intent/intent-single.url-dispatcher 2015-01-23 14:34:12 +0000
206@@ -0,0 +1,6 @@
207+[
208+ {
209+ "protocol": "intent",
210+ "domain-suffix": "intent.single"
211+ }
212+]

Subscribers

People subscribed via source and target branches