summaryrefslogtreecommitdiff
path: root/src/domain.c
diff options
context:
space:
mode:
authorportix <none@none>2012-12-06 01:15:48 +0100
committerportix <none@none>2012-12-06 01:15:48 +0100
commit2d2a9936443d1ade647adce3fef90a8c9f1d8ffa (patch)
tree1aec68c271916ff73e1cacda4acfa392f480e526 /src/domain.c
parentb2c1a51d6a0f4f0accad2db4a3d73ab45806000f (diff)
downloaddwb-2d2a9936443d1ade647adce3fef90a8c9f1d8ffa.zip
Indentation in soup.c, domain.c, download.c, completion.c
Diffstat (limited to 'src/domain.c')
-rw-r--r--src/domain.c294
1 files changed, 159 insertions, 135 deletions
diff --git a/src/domain.c b/src/domain.c
index 1bc0024e..437466f1 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -24,156 +24,180 @@
static GHashTable *m_tld_table;
GSList *
-domain_get_cookie_domains(WebKitWebView *wv) {
- GSList *ret = NULL;
- WebKitWebFrame *frame = webkit_web_view_get_main_frame(wv);
- WebKitWebDataSource *data = webkit_web_frame_get_data_source(frame);
- if (data == NULL)
- return NULL;
- WebKitNetworkRequest *request = webkit_web_data_source_get_request(data);
- if (request == NULL)
- return NULL;
- SoupMessage *msg = webkit_network_request_get_message(request);
- if (msg == NULL)
- return NULL;
- SoupURI *uri = soup_message_get_uri(msg);
- if (uri == NULL)
- return NULL;
- const char *host = soup_uri_get_host(uri);
- char *base_host = g_strconcat(".", host, NULL);
- const char *base_domain = domain_get_base_for_host(base_host);
- char *cur = base_host;
- char *nextdot;
- while (cur != base_domain) {
- nextdot = strchr(cur, '.');
- ret = g_slist_append(ret, nextdot);
- cur = nextdot+1;
- ret = g_slist_append(ret, cur);
- }
- return ret;
+domain_get_cookie_domains(WebKitWebView *wv)
+{
+ GSList *ret = NULL;
+ WebKitWebFrame *frame = webkit_web_view_get_main_frame(wv);
+ WebKitWebDataSource *data = webkit_web_frame_get_data_source(frame);
+ if (data == NULL)
+ return NULL;
+
+ WebKitNetworkRequest *request = webkit_web_data_source_get_request(data);
+ if (request == NULL)
+ return NULL;
+
+ SoupMessage *msg = webkit_network_request_get_message(request);
+ if (msg == NULL)
+ return NULL;
+
+ SoupURI *uri = soup_message_get_uri(msg);
+ if (uri == NULL)
+ return NULL;
+
+ const char *host = soup_uri_get_host(uri);
+ char *base_host = g_strconcat(".", host, NULL);
+ const char *base_domain = domain_get_base_for_host(base_host);
+
+ char *cur = base_host;
+ char *nextdot;
+
+ while (cur != base_domain)
+ {
+ nextdot = strchr(cur, '.');
+ ret = g_slist_append(ret, nextdot);
+ cur = nextdot+1;
+ ret = g_slist_append(ret, cur);
+ }
+ return ret;
}
gboolean
-domain_match(char **domains, const char *host, const char *base_domain) {
- g_return_val_if_fail(domains != NULL, false);
- g_return_val_if_fail(host != NULL, false);
- g_return_val_if_fail(base_domain != NULL, false);
- g_return_val_if_fail(g_str_has_suffix(host, base_domain), false);
-
- const char *subdomains[SUBDOMAIN_MAX];
- int sdc = 0;
-
- gboolean domain_exc = false;
- gboolean has_positive = false;
- gboolean has_exception = false;
- gboolean found_positive = false;
- gboolean found_exception = false;
-
- char *real_domain;
- char *nextdot;
- /* extract subdomains */
- subdomains[sdc++] = host;
- while (g_strcmp0(host, base_domain)) {
- nextdot = strchr(host, '.');
- host = nextdot + 1;
+domain_match(char **domains, const char *host, const char *base_domain)
+{
+ g_return_val_if_fail(domains != NULL, false);
+ g_return_val_if_fail(host != NULL, false);
+ g_return_val_if_fail(base_domain != NULL, false);
+ g_return_val_if_fail(g_str_has_suffix(host, base_domain), false);
+
+ const char *subdomains[SUBDOMAIN_MAX];
+ int sdc = 0;
+
+ gboolean domain_exc = false;
+ gboolean has_positive = false;
+ gboolean has_exception = false;
+ gboolean found_positive = false;
+ gboolean found_exception = false;
+
+ char *real_domain;
+ char *nextdot;
+ /* extract subdomains */
subdomains[sdc++] = host;
- if (sdc == SUBDOMAIN_MAX-1)
- break;
- }
- subdomains[sdc++] = NULL;
-
- /* TODO Maybe replace this with a hashtable
- * in most cases the loop runs at most 9 times, 3 times each
- * */
- for (int k=0; domains[k]; k++) {
- for (int j=0; subdomains[j]; j++) {
- real_domain = domains[k];
- if (*real_domain == '~') {
- domain_exc = true;
- real_domain++;
- has_exception = true;
- }
- else {
- domain_exc = false;
- has_positive = true;
- }
-
- if (!g_strcmp0(subdomains[j], real_domain)) {
- if (domain_exc) {
- found_exception = true;
- }
- else {
- found_positive = true;
+ while (g_strcmp0(host, base_domain))
+ {
+ nextdot = strchr(host, '.');
+ host = nextdot + 1;
+ subdomains[sdc++] = host;
+ if (sdc == SUBDOMAIN_MAX-1)
+ break;
+ }
+ subdomains[sdc++] = NULL;
+
+ for (int k=0; domains[k]; k++)
+ {
+ for (int j=0; subdomains[j]; j++)
+ {
+ real_domain = domains[k];
+ if (*real_domain == '~')
+ {
+ domain_exc = true;
+ real_domain++;
+ has_exception = true;
+ }
+ else
+ {
+ domain_exc = false;
+ has_positive = true;
+ }
+
+ if (!g_strcmp0(subdomains[j], real_domain))
+ {
+ if (domain_exc)
+ found_exception = true;
+ else
+ found_positive = true;
+ }
}
- }
}
- }
- if ((has_positive && found_positive && !found_exception) || (has_exception && !has_positive && !found_exception))
- return true;
+ if ((has_positive && found_positive && !found_exception) || (has_exception && !has_positive && !found_exception))
+ return true;
- return false;
+ return false;
}/*}}}*/
const char *
-domain_get_base_for_host(const char *host) {
- if (host == NULL)
- return NULL;
- g_return_val_if_fail(m_tld_table != NULL, NULL);
-
- const char *cur_domain = host;
- const char *prev_domain = host;
- const char *pprev_domain = host;
- const char *ret = NULL;
- char *nextdot = strchr(cur_domain, '.');
- char *entry = NULL;
- while (1) {
- entry = g_hash_table_lookup(m_tld_table, cur_domain);
- if (entry != NULL) {
- if (*entry == '*') {
- ret = pprev_domain;
- break;
- }
- else if (*entry == '!' && nextdot) {
- ret = nextdot + 1;
- break;
- }
- else {
- ret = prev_domain;
- break;
- }
+domain_get_base_for_host(const char *host)
+{
+ if (host == NULL)
+ return NULL;
+ g_return_val_if_fail(m_tld_table != NULL, NULL);
+
+ const char *cur_domain = host;
+ const char *prev_domain = host;
+ const char *pprev_domain = host;
+ const char *ret = NULL;
+ char *nextdot = strchr(cur_domain, '.');
+ char *entry = NULL;
+
+ while (1)
+ {
+ entry = g_hash_table_lookup(m_tld_table, cur_domain);
+ if (entry != NULL)
+ {
+ if (*entry == '*')
+ {
+ ret = pprev_domain;
+ break;
+ }
+ else if (*entry == '!' && nextdot)
+ {
+ ret = nextdot + 1;
+ break;
+ }
+ else
+ {
+ ret = prev_domain;
+ break;
+ }
+ }
+ if (nextdot == NULL)
+ break;
+
+ pprev_domain = prev_domain;
+ prev_domain = cur_domain;
+ cur_domain = nextdot + 1;
+
+ PRINT_DEBUG(nextdot);
+
+ nextdot = strchr(cur_domain, '.');
}
- if (nextdot == NULL)
- break;
- pprev_domain = prev_domain;
- prev_domain = cur_domain;
- cur_domain = nextdot + 1;
-
- PRINT_DEBUG(nextdot);
-
- nextdot = strchr(cur_domain, '.');
- }
- if (ret == NULL)
- ret = host;
- return ret;
+ if (ret == NULL)
+ ret = host;
+ return ret;
}
void
-domain_end() {
- if (m_tld_table) {
- g_hash_table_unref(m_tld_table);
- m_tld_table = NULL;
- }
+domain_end()
+{
+ if (m_tld_table)
+ {
+ g_hash_table_unref(m_tld_table);
+ m_tld_table = NULL;
+ }
}
void
-domain_init() {
- m_tld_table = g_hash_table_new((GHashFunc)g_str_hash, (GEqualFunc)g_str_equal);
- char *eff_tld;
- for (int i=0; (eff_tld = TLDS_EFFECTIVE[i]); i++) {
- if (*eff_tld == '*' || *eff_tld == '!')
- eff_tld++;
- if (*eff_tld == '.')
- eff_tld++;
- g_hash_table_insert(m_tld_table, eff_tld, TLDS_EFFECTIVE[i]);
- }
+domain_init()
+{
+ m_tld_table = g_hash_table_new((GHashFunc)g_str_hash, (GEqualFunc)g_str_equal);
+ char *eff_tld;
+ for (int i=0; (eff_tld = TLDS_EFFECTIVE[i]); i++)
+ {
+ if (*eff_tld == '*' || *eff_tld == '!')
+ eff_tld++;
+
+ if (*eff_tld == '.')
+ eff_tld++;
+
+ g_hash_table_insert(m_tld_table, eff_tld, TLDS_EFFECTIVE[i]);
+ }
}