void gotheaders(SoupMessage *msg, gpointer v) { SoupURI *uri; GSList *l, *p; uri = soup_message_get_uri(msg); for(p = l = soup_cookies_from_response(msg); p; p = g_slist_next(p)) { setcookie((SoupCookie *)p->data); } soup_cookies_free(l); }
/* We received the HTTP headers of the request and it contains cookie-managing headers */ static void _cookie_permission_manager_on_response_received(WebKitWebView *inView, WebKitWebFrame *inFrame, WebKitWebResource *inResource, WebKitNetworkResponse *inResponse, gpointer inUserData) { g_return_if_fail(IS_COOKIE_PERMISSION_MANAGER(inUserData)); CookiePermissionManager *self=COOKIE_PERMISSION_MANAGER(inUserData); CookiePermissionManagerPrivate *priv=self->priv; GSList *newCookies, *cookie; GSList *unknownCookies=NULL, *acceptedCookies=NULL; SoupURI *firstParty; SoupCookieJarAcceptPolicy cookiePolicy; gint unknownCookiesPolicy; SoupMessage *message; /* If policy is to deny all cookies return immediately */ cookiePolicy=soup_cookie_jar_get_accept_policy(priv->cookieJar); if(cookiePolicy==SOUP_COOKIE_JAR_ACCEPT_NEVER) return; /* Get SoupMessage */ message=webkit_network_response_get_message(inResponse); if(!message || !SOUP_IS_MESSAGE(message)) return; /* Iterate through cookies in response and check if they should be * blocked (remove from cookies list) or accepted (added to cookie jar). * If we could not determine what to do collect these cookies and * ask user */ newCookies=soup_cookies_from_response(message); firstParty=soup_message_get_first_party(message); for(cookie=newCookies; cookie; cookie=cookie->next) { switch(_cookie_permission_manager_get_policy(self, cookie->data)) { case COOKIE_PERMISSION_MANAGER_POLICY_BLOCK: soup_cookie_free(cookie->data); break; case COOKIE_PERMISSION_MANAGER_POLICY_ACCEPT: case COOKIE_PERMISSION_MANAGER_POLICY_ACCEPT_FOR_SESSION: if((cookiePolicy==SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY && firstParty!=NULL && firstParty->host && soup_cookie_domain_matches(cookie->data, firstParty->host)) || cookiePolicy==SOUP_COOKIE_JAR_ACCEPT_ALWAYS) { acceptedCookies=g_slist_prepend(acceptedCookies, cookie->data); } else soup_cookie_free(cookie->data); break; case COOKIE_PERMISSION_MANAGER_POLICY_UNDETERMINED: default: if((cookiePolicy==SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY && firstParty!=NULL && firstParty->host && soup_cookie_domain_matches(cookie->data, firstParty->host)) || cookiePolicy==SOUP_COOKIE_JAR_ACCEPT_ALWAYS) { unknownCookies=g_slist_prepend(unknownCookies, cookie->data); } else soup_cookie_free(cookie->data); break; } } /* Prepending an item to list is the fastest method but the order of cookies * is reversed now and may be added to cookie jar in the wrong order. So we * need to reverse list now of both - undetermined and accepted cookies */ unknownCookies=g_slist_reverse(unknownCookies); acceptedCookies=g_slist_reverse(acceptedCookies); /* Ask user for his decision what to do with cookies whose policy is undetermined * But only ask if there is any undetermined one */ if(g_slist_length(unknownCookies)>0) { /* Get view */ MidoriView *view; view=MIDORI_VIEW(g_object_get_data(G_OBJECT(inView), "midori-view")); /* Ask for user's decision */ unknownCookiesPolicy=_cookie_permission_manager_ask_for_policy(self, view, message, unknownCookies); if(unknownCookiesPolicy==COOKIE_PERMISSION_MANAGER_POLICY_ACCEPT || unknownCookiesPolicy==COOKIE_PERMISSION_MANAGER_POLICY_ACCEPT_FOR_SESSION) { /* Add accepted undetermined cookies to cookie jar */ for(cookie=unknownCookies; cookie; cookie=cookie->next) { soup_cookie_jar_add_cookie(priv->cookieJar, (SoupCookie*)cookie->data); } } else { /* Free cookies because they should be blocked */ for(cookie=unknownCookies; cookie; cookie=cookie->next) { soup_cookie_free((SoupCookie*)cookie->data); } } } /* Add accepted cookies to cookie jar */ for(cookie=acceptedCookies; cookie; cookie=cookie->next) { soup_cookie_jar_add_cookie(priv->cookieJar, (SoupCookie*)cookie->data); } /* Free list of cookies */ g_slist_free(unknownCookies); g_slist_free(acceptedCookies); g_slist_free(newCookies); }