Exemplo n.º 1
0
JNIEXPORT void JNICALL WebKitGTK_NATIVE(_1soup_1cookie_1jar_1delete_1cookie)
	(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
{
	WebKitGTK_NATIVE_ENTER(env, that, _1soup_1cookie_1jar_1delete_1cookie_FUNC);
	soup_cookie_jar_delete_cookie((SoupCookieJar *)arg0, (SoupCookie *)arg1);
	WebKitGTK_NATIVE_EXIT(env, that, _1soup_1cookie_1jar_1delete_1cookie_FUNC);
}
Exemplo n.º 2
0
/* A cookie was changed outside a request (e.g. Javascript) */
static void _cookie_permission_manager_on_cookie_changed(CookiePermissionManager *self,
															SoupCookie *inOldCookie,
															SoupCookie *inNewCookie,
															SoupCookieJar *inCookieJar)
{
	/* Do not check changed cookies because they must have been allowed before.
	 * Also do not check removed cookies because they are removed ;)
	 */
	if(inNewCookie==NULL || inOldCookie) return;

	/* New cookie is a new cookie so check */
	switch(_cookie_permission_manager_get_policy(self, inNewCookie))
	{
		case COOKIE_PERMISSION_MANAGER_POLICY_ACCEPT:
		case COOKIE_PERMISSION_MANAGER_POLICY_ACCEPT_FOR_SESSION:
			break;

		case COOKIE_PERMISSION_MANAGER_POLICY_UNDETERMINED:
			/* Fallthrough!
			 * The problem here is that we don't know the view to ask user
			 * for policy to follow for this cookie domain. Therefore we
			 * delete the cookie from jar and assume that we will be asked
			 * again in _cookie_permission_manager_on_response_received().
			 */

		default:
			soup_cookie_jar_delete_cookie(inCookieJar, inNewCookie);
			break;
	}
}
Exemplo n.º 3
0
static void
do_cookies_accept_policy_test (void)
{
	SoupSession *session;
	SoupMessage *msg;
	SoupURI *uri;
	SoupCookieJar *jar;
	GSList *l, *p;
	int i;

	debug_printf (1, "SoupCookieJarAcceptPolicy test\n");

	session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
	soup_session_add_feature_by_type (session, SOUP_TYPE_COOKIE_JAR);
	jar = SOUP_COOKIE_JAR (soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR));

	for (i = 0; i < G_N_ELEMENTS (validResults); i++) {
		soup_cookie_jar_set_accept_policy (jar, validResults[i].policy);

		uri = soup_uri_new_with_base (first_party_uri, "/index.html");
		msg = soup_message_new_from_uri ("GET", uri);
		soup_message_set_first_party (msg, first_party_uri);
		soup_session_send_message (session, msg);
		soup_uri_free (uri);
		g_object_unref (msg);

		/* We can't use two servers due to limitations in
		 * test_server, so let's swap first and third party here
		 * to simulate a cookie coming from a third party.
		 */
		uri = soup_uri_new_with_base (first_party_uri, "/foo.jpg");
		msg = soup_message_new_from_uri ("GET", uri);
		soup_message_set_first_party (msg, third_party_uri);
		soup_session_send_message (session, msg);
		soup_uri_free (uri);
		g_object_unref (msg);

		l = soup_cookie_jar_all_cookies (jar);
		if (g_slist_length (l) < validResults[i].n_cookies) {
			debug_printf (1, " accepted less cookies than it should have\n");
			errors++;
		} else if (g_slist_length (l) > validResults[i].n_cookies) {
			debug_printf (1, " accepted more cookies than it should have\n");
			errors++;
		}

		for (p = l; p; p = p->next) {
			soup_cookie_jar_delete_cookie (jar, p->data);
			soup_cookie_free (p->data);
		}

		g_slist_free (l);
	}

	soup_test_session_abort_unref (session);
}
Exemplo n.º 4
0
void deleteAllCookies(NetworkingContext* context)
{
    SoupCookieJar* cookieJar = context ? cookieJarForContext(context) : soupCookieJar();
    GOwnPtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
        soup_cookie_jar_delete_cookie(cookieJar, cookie);
        soup_cookie_free(cookie);
    }
}
Exemplo n.º 5
0
void deleteAllCookies(const NetworkStorageSession& session)
{
    SoupCookieJar* cookieJar = cookieJarForSession(session);
    GUniquePtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
        soup_cookie_jar_delete_cookie(cookieJar, cookie);
        soup_cookie_free(cookie);
    }
}
Exemplo n.º 6
0
void deleteCookiesForHostname(const NetworkStorageSession& session, const String& hostname)
{
    CString hostNameString = hostname.utf8();
    SoupCookieJar* cookieJar = cookieJarForSession(session);
    GUniquePtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
        if (soup_cookie_domain_matches(cookie, hostNameString.data()))
            soup_cookie_jar_delete_cookie(cookieJar, cookie);
        soup_cookie_free(cookie);
    }
}
Exemplo n.º 7
0
void deleteCookiesForHostname(NetworkingContext* context, const String& hostname)
{
    CString hostNameString = hostname.utf8();
    SoupCookieJar* cookieJar = context ? cookieJarForContext(context) : soupCookieJar();
    GOwnPtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
        if (soup_cookie_domain_matches(cookie, hostNameString.data()))
            soup_cookie_jar_delete_cookie(cookieJar, cookie);
        soup_cookie_free(cookie);
    }
}
Exemplo n.º 8
0
void ewk_cookies_clear(void)
{
    GSList* list;
    GSList* p;
    SoupCookieJar* cookieJar = WebCore::soupCookieJar();

    list = soup_cookie_jar_all_cookies(cookieJar);
    for (p = list; p; p = p->next)
        soup_cookie_jar_delete_cookie(cookieJar, (SoupCookie*)p->data);

    soup_cookies_free(list);
}
Exemplo n.º 9
0
gboolean
ossifer_session_delete_cookie (const gchar *name, const gchar *domain, const gchar *path)
{
    SoupCookie *cookie = ossifer_session_get_cookie (name, domain, path);

    if (cookie != NULL) {
        soup_cookie_jar_delete_cookie (ossifer_session_get_cookie_jar (), cookie);
        soup_cookie_free (cookie);
        return TRUE;
    }

    return FALSE;
}
Exemplo n.º 10
0
/**
 * Clears all the cookies from the cookie jar.
 */
void ewk_cookies_clear(void)
{
#if USE(SOUP)
    GSList* l;
    GSList* p;
    SoupCookieJar* cookieJar = WebCore::defaultCookieJar();

    l = soup_cookie_jar_all_cookies(cookieJar);
    for (p = l; p; p = p->next)
        soup_cookie_jar_delete_cookie(cookieJar, (SoupCookie*)p->data);

    soup_cookies_free(l);
#endif
}
Exemplo n.º 11
0
void
reloadcookies() {
	SoupCookieJar *jar;
	GSList *l, *e;

	lockcookie = TRUE;
	for(l = e = soup_cookie_jar_all_cookies(cookies); e; e = e->next)
		soup_cookie_jar_delete_cookie(cookies, (SoupCookie *)e->data);
	soup_cookies_free(l);
	jar = soup_cookie_jar_text_new(cookiefile, TRUE);
	for(l = e = soup_cookie_jar_all_cookies(jar); e; e = e->next)
		soup_cookie_jar_add_cookie(cookies, (SoupCookie *)e->data);
	g_slist_free(l);
	lockcookie = FALSE;
	g_object_unref(jar);
}
Exemplo n.º 12
0
/* Hide the authentication browser */
void
auth_browser_hide (AuthBrowser *browser)
{
    AuthBrowserPrivate *priv = GET_PRIVATE (browser);
    SoupSession *session = webkit_get_default_session ();
    SoupCookieJar* jar = (SoupCookieJar*)soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR);
    GSList *l, *p;

    gtk_widget_hide (priv->window);

    /* clear cookies */
    l = soup_cookie_jar_all_cookies (jar);
    for (p = l; p; p = p->next)
        soup_cookie_jar_delete_cookie (jar, (SoupCookie*)p->data);

    soup_cookies_free (l);
}
Exemplo n.º 13
0
void
changecookie(SoupCookieJar *j, SoupCookie *oc, SoupCookie *c, gpointer p) {
	SoupDate *e;
	SoupCookieJar *jar;

	if(lockcookie)
		return;
	if(c && c->expires == NULL) {
		e = soup_date_new_from_time_t(time(NULL) + sessiontime);
		c = soup_cookie_copy(c);
		soup_cookie_set_expires(c, e);
	}
	
	jar = soup_cookie_jar_text_new(cookiefile, FALSE);
	if(c)
		soup_cookie_jar_add_cookie(jar, soup_cookie_copy(c));
	else
		soup_cookie_jar_delete_cookie(jar, oc);
	g_object_unref(jar);
}
Exemplo n.º 14
0
void deleteCookie(NetworkingContext* context, const KURL& url, const String& name)
{
    SoupCookieJar* jar = context ? cookieJarForContext(context) : soupCookieJar();
    if (!jar)
        return;

    GOwnPtr<GSList> cookies(soup_cookie_jar_all_cookies(jar));
    if (!cookies)
        return;

    CString cookieName = name.utf8();
    GOwnPtr<SoupURI> uri(soup_uri_new(url.string().utf8().data()));
    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
        GOwnPtr<SoupCookie> cookie(static_cast<SoupCookie*>(iter->data));
        if (!soup_cookie_applies_to_uri(cookie.get(), uri.get()))
            continue;
        if (cookieName == cookie->name)
            soup_cookie_jar_delete_cookie(jar, cookie.get());
    }
}
Exemplo n.º 15
0
void ewk_cookies_cookie_del(Ewk_Cookie* cookie)
{
    EINA_SAFETY_ON_NULL_RETURN(cookie);
    GSList* list;
    GSList* p;
    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
    SoupCookie* cookie1 = soup_cookie_new(
        cookie->name, cookie->value, cookie->domain, cookie->path, -1);

    list = soup_cookie_jar_all_cookies(cookieJar);
    for (p = list; p; p = p->next) {
        SoupCookie* cookie2 = static_cast<SoupCookie*>(p->data);
        if (soup_cookie_equal(cookie1, cookie2)) {
            soup_cookie_jar_delete_cookie(cookieJar, cookie2);
            break;
        }
    }

    soup_cookie_free(cookie1);
    soup_cookies_free(list);
}
Exemplo n.º 16
0
void deleteCookie(const NetworkStorageSession& session, const URL& url, const String& name)
{
    SoupCookieJar* jar = cookieJarForSession(session);
    if (!jar)
        return;

    GUniquePtr<SoupURI> uri = url.createSoupURI();
    GUniquePtr<GSList> cookies(soup_cookie_jar_get_cookie_list(jar, uri.get(), TRUE));
    if (!cookies)
        return;

    CString cookieName = name.utf8();
    bool wasDeleted = false;
    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
        SoupCookie* cookie = static_cast<SoupCookie*>(iter->data);
        if (!wasDeleted && cookieName == cookie->name) {
            soup_cookie_jar_delete_cookie(jar, cookie);
            wasDeleted = true;
        }
        soup_cookie_free(cookie);
    }
}
Exemplo n.º 17
0
/**
 * Deletes a cookie from the cookie jar.
 *
 * Note that the fields name, value, domain and path are used to match this
 * cookie in the cookie jar.
 *
 * @param cookie an @c Ewk_Cookie that has the info relative to that cookie.
 */
void ewk_cookies_cookie_del(Ewk_Cookie *cookie)
{
#if USE(SOUP)
    EINA_SAFETY_ON_NULL_RETURN(cookie);
    GSList* l;
    GSList* p;
    SoupCookieJar* cookieJar = WebCore::defaultCookieJar();
    SoupCookie* c1 = soup_cookie_new(
        cookie->name, cookie->value, cookie->domain, cookie->path, -1);

    l = soup_cookie_jar_all_cookies(cookieJar);
    for (p = l; p; p = p->next) {
        SoupCookie* c2 = static_cast<SoupCookie*>(p->data);
        if (soup_cookie_equal(c1, c2)) {
            soup_cookie_jar_delete_cookie(cookieJar, c2);
            break;
        }
    }

    soup_cookie_free(c1);
    soup_cookies_free(l);
#endif
}
Exemplo n.º 18
0
/* Open database containing policies for cookie domains.
 * Create database and setup table structure if it does not exist yet.
 */
static void _cookie_permission_manager_open_database(CookiePermissionManager *self)
{
	CookiePermissionManagerPrivate	*priv=self->priv;
	const gchar						*configDir;
	gchar							*error=NULL;
	gint							success;
	sqlite3_stmt					*statement=NULL;

	/* Close any open database */
	if(priv->database)
	{
		g_free(priv->databaseFilename);
		priv->databaseFilename=NULL;

		sqlite3_close(priv->database);
		priv->database=NULL;

		g_object_notify_by_pspec(G_OBJECT(self), CookiePermissionManagerProperties[PROP_DATABASE]);
		g_object_notify_by_pspec(G_OBJECT(self), CookiePermissionManagerProperties[PROP_DATABASE_FILENAME]);
	}

	/* Build path to database file */
	configDir=midori_extension_get_config_dir(priv->extension);
	if(!configDir)
		return;
	
	if(katze_mkdir_with_parents(configDir, 0700))
	{
		g_warning(_("Could not create configuration folder for extension: %s"), g_strerror(errno));

		_cookie_permission_manager_error(self, _("Could not create configuration folder for extension."));
		return;
	}

	/* Open database */
	priv->databaseFilename=g_build_filename(configDir, COOKIE_PERMISSION_DATABASE, NULL);
	success=sqlite3_open(priv->databaseFilename, &priv->database);
	if(success!=SQLITE_OK)
	{
		g_warning(_("Could not open database of extenstion: %s"), sqlite3_errmsg(priv->database));

		g_free(priv->databaseFilename);
		priv->databaseFilename=NULL;

		if(priv->database) sqlite3_close(priv->database);
		priv->database=NULL;

		_cookie_permission_manager_error(self, _("Could not open database of extension."));
		return;
	}

	/* Create table structure if it does not exist */
	success=sqlite3_exec(priv->database,
							"CREATE TABLE IF NOT EXISTS "
							"policies(domain text, value integer);",
							NULL,
							NULL,
							&error);

	if(success==SQLITE_OK)
	{
		success=sqlite3_exec(priv->database,
								"CREATE UNIQUE INDEX IF NOT EXISTS "
								"domain ON policies (domain);",
								NULL,
								NULL,
								&error);
	}

	if(success==SQLITE_OK)
	{
		success=sqlite3_exec(priv->database,
								"PRAGMA journal_mode=TRUNCATE;",
								NULL,
								NULL,
								&error);
	}

	if(success!=SQLITE_OK || error)
	{
		_cookie_permission_manager_error(self, _("Could not set up database structure of extension."));

		if(error)
		{
			g_critical(_("Failed to execute database statement: %s"), error);
			sqlite3_free(error);
		}

		g_free(priv->databaseFilename);
		priv->databaseFilename=NULL;

		sqlite3_close(priv->database);
		priv->database=NULL;
		return;
	}

	// Delete all cookies allowed only in one session
	success=sqlite3_prepare_v2(priv->database,
								"SELECT domain FROM policies WHERE value=? ORDER BY domain DESC;",
								-1,
								&statement,
								NULL);
	if(statement && success==SQLITE_OK) success=sqlite3_bind_int(statement, 1, COOKIE_PERMISSION_MANAGER_POLICY_ACCEPT_FOR_SESSION);
	if(statement && success==SQLITE_OK)
	{
		while(sqlite3_step(statement)==SQLITE_ROW)
		{
			gchar		*domain=(gchar*)sqlite3_column_text(statement, 0);
			GSList		*cookies, *cookie;

#ifdef HAVE_LIBSOUP_2_40_0
			SoupURI		*uri;

			uri=soup_uri_new(NULL);
			soup_uri_set_host(uri, domain);
			soup_uri_set_path(uri, "/");
			cookies=soup_cookie_jar_get_cookie_list(priv->cookieJar, uri, TRUE);
			for(cookie=cookies; cookie; cookie=cookie->next)
			{
				soup_cookie_jar_delete_cookie(priv->cookieJar, (SoupCookie*)cookie->data);
			}
			soup_cookies_free(cookies);
			soup_uri_free(uri);
#else
			cookies=soup_cookie_jar_all_cookies(priv->cookieJar);
			for(cookie=cookies; cookie; cookie=cookie->next)
			{
				if(soup_cookie_domain_matches((SoupCookie*)cookie->data, domain))
				{
					soup_cookie_jar_delete_cookie(priv->cookieJar, (SoupCookie*)cookie->data);
				}
			}
			soup_cookies_free(cookies);
#endif
		}
	}
		else g_warning(_("SQL fails: %s"), sqlite3_errmsg(priv->database));

	sqlite3_finalize(statement);

	g_object_notify_by_pspec(G_OBJECT(self), CookiePermissionManagerProperties[PROP_DATABASE]);
	g_object_notify_by_pspec(G_OBJECT(self), CookiePermissionManagerProperties[PROP_DATABASE_FILENAME]);
}