static gboolean katze_http_cookies_update_jar (KatzeHttpCookies* http_cookies) { gint fn = 0; FILE* f = NULL; gchar* temporary_filename = NULL; GSList* cookies; http_cookies->timeout = 0; temporary_filename = g_strconcat (http_cookies->filename, ".XXXXXX", NULL); if ((fn = g_mkstemp (temporary_filename)) == -1) goto failed; if (!((f = fdopen (fn, "wb")))) goto failed; cookies = soup_cookie_jar_all_cookies (http_cookies->jar); for (; cookies != NULL; cookies = g_slist_next (cookies)) { SoupCookie* cookie = cookies->data; if (cookie->expires && !soup_date_is_past (cookie->expires)) write_cookie (f, cookie); soup_cookie_free (cookie); } g_slist_free (cookies); if (fclose (f) != 0) { f = NULL; goto failed; } f = NULL; if (g_rename (temporary_filename, http_cookies->filename) == -1) goto failed; g_free (temporary_filename); if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL) { g_print ("KatzeHttpCookies: %d cookies changed\n", http_cookies->counter); http_cookies->counter = 0; } return FALSE; failed: if (f) fclose (f); g_unlink (temporary_filename); g_free (temporary_filename); if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL) g_print ("KatzeHttpCookies: Failed to write '%s'\n", http_cookies->filename); return FALSE; }
/** * Checks if given host is a known https host according to RFC 6797 8.2f */ static inline gboolean should_secure_host(HSTSProvider *provider, const char *host) { HSTSProviderPrivate *priv = HSTS_PROVIDER_GET_PRIVATE(provider); HSTSEntry *entry; char *canonical, *p; gboolean result = false, is_subdomain = false; /* ip is not allowed for hsts */ if (g_hostname_is_ip_address(host)) { return false; } canonical = g_hostname_to_ascii(host); /* don't match empty host */ if (*canonical) { p = canonical; /* Try to find the whole congruent matching host in hash table - if * not found strip of the first label and try to find a superdomain * match. Specified is a from right to left comparison 8.3, but in the * end this should be lead to the same result. */ while (p != NULL) { entry = g_hash_table_lookup(priv->whitelist, p); if (entry != NULL) { /* remove expired entries RFC 6797 8.1.1 */ if (soup_date_is_past(entry->expires_at)) { remove_host_entry(provider, p); } else if(!is_subdomain || entry->include_sub_domains) { result = true; break; } } is_subdomain = true; /* test without the first domain part */ if ((p = strchr(p, '.'))) { p++; } } } g_free(canonical); return result; }