Merge lp:~kalikiana/midori/subdomains into lp:midori

Proposed by Cris Dywan
Status: Merged
Approved by: André Stösel
Approved revision: 6400
Merged at revision: 6401
Proposed branch: lp:~kalikiana/midori/subdomains
Merge into: lp:midori
Diff against target: 108 lines (+26/-26)
4 files modified
CMakeLists.txt (+1/-0)
extensions/nojs/nojs.c (+3/-26)
katze/midori-uri.vala (+11/-0)
tests/magic-uri.c (+11/-0)
To merge this branch: bzr merge lp:~kalikiana/midori/subdomains
Reviewer Review Type Date Requested Status
André Stösel Approve
Review via email: mp+185950@code.launchpad.net

Commit message

Add Midori.URI.get_base_domain and use it in NoJS

To post a comment you must log in.
Revision history for this message
André Stösel (ivaldi) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2013-09-08 22:22:34 +0000
3+++ CMakeLists.txt 2013-09-16 23:23:07 +0000
4@@ -106,6 +106,7 @@
5 endif ()
6 if (${DEPS_libsoup-gnome-2.4_VERSION} VERSION_GREATER "2.40.0")
7 add_definitions("-DHAVE_LIBSOUP_2_40_0")
8+ set(VALAFLAGS ${VALAFLAGS} -D HAVE_LIBSOUP_2_40_0)
9 endif ()
10
11 if (WIN32)
12
13=== modified file 'extensions/nojs/nojs.c'
14--- extensions/nojs/nojs.c 2013-09-09 09:53:44 +0000
15+++ extensions/nojs/nojs.c 2013-09-16 23:23:07 +0000
16@@ -873,38 +873,15 @@
17
18 NoJSPrivate *priv=self->priv;
19 const gchar *realDomain;
20- gchar *asciiDomain, *domain;
21 gchar *finalDomain;
22
23 /* Get domain of site to lookup */
24 realDomain=soup_uri_get_host(inURI);
25
26- domain=asciiDomain=g_hostname_to_ascii(realDomain);
27-
28 if(priv->checkOnlySecondLevel)
29- {
30- /* Only get second level domain if host is not an IP address */
31- if(!g_hostname_is_ip_address(asciiDomain))
32- {
33- gint numberDots=0;
34-
35- domain=asciiDomain+strlen(asciiDomain)-1;
36- while(domain>=asciiDomain && numberDots<2)
37- {
38- if(*domain=='.') numberDots++;
39- domain--;
40- }
41- domain++;
42- if(*domain=='.') domain++;
43- }
44- }
45-
46- /* Create copy for return value */
47- if(strlen(domain)>0) finalDomain=g_strdup(domain);
48- else finalDomain=NULL;
49-
50- /* Free allocated resources */
51- g_free(asciiDomain);
52+ finalDomain=midori_uri_get_base_domain(realDomain);
53+ else
54+ finalDomain=midori_uri_to_ascii(realDomain);
55
56 /* Return domain */
57 return(finalDomain);
58
59=== modified file 'katze/midori-uri.vala'
60--- katze/midori-uri.vala 2013-08-06 21:52:12 +0000
61+++ katze/midori-uri.vala 2013-09-16 23:23:07 +0000
62@@ -52,6 +52,17 @@
63 }
64 return uri;
65 }
66+ public static string get_base_domain (string uri) {
67+ string ascii = to_ascii (uri);
68+#if HAVE_LIBSOUP_2_40_0
69+ try {
70+ return Soup.tld_get_base_domain (ascii);
71+ } catch (Error error) {
72+ /* This is fine, we fallback to hostname */
73+ }
74+#endif
75+ return parse_hostname (uri, null);
76+ }
77 public static string unescape (string uri) {
78 /* Unescape, pass through + and %20 */
79 if (uri.chr (-1, '%') != null || uri.chr (-1, ' ') != null) {
80
81=== modified file 'tests/magic-uri.c'
82--- tests/magic-uri.c 2013-05-27 00:32:12 +0000
83+++ tests/magic-uri.c 2013-09-16 23:23:07 +0000
84@@ -420,6 +420,16 @@
85 g_assert (sokoke_external_uri ("httparty:woo") == uri_has_default ("httparty:woo"));
86 }
87
88+static void
89+magic_uri_base_domain (void)
90+{
91+ #ifdef HAVE_LIBSOUP_2_40_0
92+ g_assert_cmpstr ("bbc.co.uk", ==, midori_uri_get_base_domain ("http://www.bbc.co.uk"));
93+ g_assert_cmpstr ("zeit.de", ==, midori_uri_get_base_domain ("http://www.zeit.de"));
94+ #endif
95+ g_assert_cmpstr ("123.456.789.100", ==, midori_uri_get_base_domain ("http://123.456.789.100"));
96+}
97+
98 int
99 main (int argc,
100 char** argv)
101@@ -439,6 +449,7 @@
102 g_test_add_func ("/magic-uri/prefetch", magic_uri_prefetch);
103 g_test_add_func ("/magic-uri/commands", magic_uri_commands);
104 g_test_add_func ("/magic-uri/protocols", magic_uri_protocols);
105+ g_test_add_func ("/magic-uri/base-domain", magic_uri_base_domain);
106
107 return g_test_run ();
108 }

Subscribers

People subscribed via source and target branches

to all changes: