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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2013-09-08 22:22:34 +0000
+++ CMakeLists.txt 2013-09-16 23:23:07 +0000
@@ -106,6 +106,7 @@
106endif ()106endif ()
107if (${DEPS_libsoup-gnome-2.4_VERSION} VERSION_GREATER "2.40.0")107if (${DEPS_libsoup-gnome-2.4_VERSION} VERSION_GREATER "2.40.0")
108 add_definitions("-DHAVE_LIBSOUP_2_40_0")108 add_definitions("-DHAVE_LIBSOUP_2_40_0")
109 set(VALAFLAGS ${VALAFLAGS} -D HAVE_LIBSOUP_2_40_0)
109endif ()110endif ()
110111
111if (WIN32)112if (WIN32)
112113
=== modified file 'extensions/nojs/nojs.c'
--- extensions/nojs/nojs.c 2013-09-09 09:53:44 +0000
+++ extensions/nojs/nojs.c 2013-09-16 23:23:07 +0000
@@ -873,38 +873,15 @@
873873
874 NoJSPrivate *priv=self->priv;874 NoJSPrivate *priv=self->priv;
875 const gchar *realDomain;875 const gchar *realDomain;
876 gchar *asciiDomain, *domain;
877 gchar *finalDomain;876 gchar *finalDomain;
878877
879 /* Get domain of site to lookup */878 /* Get domain of site to lookup */
880 realDomain=soup_uri_get_host(inURI);879 realDomain=soup_uri_get_host(inURI);
881880
882 domain=asciiDomain=g_hostname_to_ascii(realDomain);
883
884 if(priv->checkOnlySecondLevel)881 if(priv->checkOnlySecondLevel)
885 {882 finalDomain=midori_uri_get_base_domain(realDomain);
886 /* Only get second level domain if host is not an IP address */883 else
887 if(!g_hostname_is_ip_address(asciiDomain))884 finalDomain=midori_uri_to_ascii(realDomain);
888 {
889 gint numberDots=0;
890
891 domain=asciiDomain+strlen(asciiDomain)-1;
892 while(domain>=asciiDomain && numberDots<2)
893 {
894 if(*domain=='.') numberDots++;
895 domain--;
896 }
897 domain++;
898 if(*domain=='.') domain++;
899 }
900 }
901
902 /* Create copy for return value */
903 if(strlen(domain)>0) finalDomain=g_strdup(domain);
904 else finalDomain=NULL;
905
906 /* Free allocated resources */
907 g_free(asciiDomain);
908885
909 /* Return domain */886 /* Return domain */
910 return(finalDomain);887 return(finalDomain);
911888
=== modified file 'katze/midori-uri.vala'
--- katze/midori-uri.vala 2013-08-06 21:52:12 +0000
+++ katze/midori-uri.vala 2013-09-16 23:23:07 +0000
@@ -52,6 +52,17 @@
52 }52 }
53 return uri;53 return uri;
54 }54 }
55 public static string get_base_domain (string uri) {
56 string ascii = to_ascii (uri);
57#if HAVE_LIBSOUP_2_40_0
58 try {
59 return Soup.tld_get_base_domain (ascii);
60 } catch (Error error) {
61 /* This is fine, we fallback to hostname */
62 }
63#endif
64 return parse_hostname (uri, null);
65 }
55 public static string unescape (string uri) {66 public static string unescape (string uri) {
56 /* Unescape, pass through + and %20 */67 /* Unescape, pass through + and %20 */
57 if (uri.chr (-1, '%') != null || uri.chr (-1, ' ') != null) {68 if (uri.chr (-1, '%') != null || uri.chr (-1, ' ') != null) {
5869
=== modified file 'tests/magic-uri.c'
--- tests/magic-uri.c 2013-05-27 00:32:12 +0000
+++ tests/magic-uri.c 2013-09-16 23:23:07 +0000
@@ -420,6 +420,16 @@
420 g_assert (sokoke_external_uri ("httparty:woo") == uri_has_default ("httparty:woo"));420 g_assert (sokoke_external_uri ("httparty:woo") == uri_has_default ("httparty:woo"));
421}421}
422422
423static void
424magic_uri_base_domain (void)
425{
426 #ifdef HAVE_LIBSOUP_2_40_0
427 g_assert_cmpstr ("bbc.co.uk", ==, midori_uri_get_base_domain ("http://www.bbc.co.uk"));
428 g_assert_cmpstr ("zeit.de", ==, midori_uri_get_base_domain ("http://www.zeit.de"));
429 #endif
430 g_assert_cmpstr ("123.456.789.100", ==, midori_uri_get_base_domain ("http://123.456.789.100"));
431}
432
423int433int
424main (int argc,434main (int argc,
425 char** argv)435 char** argv)
@@ -439,6 +449,7 @@
439 g_test_add_func ("/magic-uri/prefetch", magic_uri_prefetch);449 g_test_add_func ("/magic-uri/prefetch", magic_uri_prefetch);
440 g_test_add_func ("/magic-uri/commands", magic_uri_commands);450 g_test_add_func ("/magic-uri/commands", magic_uri_commands);
441 g_test_add_func ("/magic-uri/protocols", magic_uri_protocols);451 g_test_add_func ("/magic-uri/protocols", magic_uri_protocols);
452 g_test_add_func ("/magic-uri/base-domain", magic_uri_base_domain);
442453
443 return g_test_run ();454 return g_test_run ();
444}455}

Subscribers

People subscribed via source and target branches

to all changes: