Example #1
0
static void cookiejar_changed(SoupCookieJar *self, SoupCookie *old_cookie, SoupCookie *new_cookie)
{
    FLOCK(COOKIEJAR(self)->lock, F_WRLCK);
    SoupDate *expire;
    if (new_cookie) {
    /* session-expire-time handling */
    if (vb.config.cookie_expire_time == 0) {
        soup_cookie_set_expires(new_cookie, NULL);

    } else if (vb.config.cookie_expire_time > 0 && new_cookie->expires) {
        expire = soup_date_new_from_now(vb.config.cookie_expire_time);
        if (soup_date_to_time_t(expire) < soup_date_to_time_t(new_cookie->expires)) {
        soup_cookie_set_expires(new_cookie, expire);
        }
        soup_date_free(expire);
    }

    /* session-cookie handling */
    if (!new_cookie->expires && vb.config.cookie_timeout) {
        expire = soup_date_new_from_now(vb.config.cookie_timeout);
        soup_cookie_set_expires(new_cookie, expire);
        soup_date_free(expire);
    }
    }
    SOUP_COOKIE_JAR_CLASS(cookiejar_parent_class)->changed(self, old_cookie, new_cookie);
    FLOCK(COOKIEJAR(self)->lock, F_UNLCK);
}
Example #2
0
static void
katze_http_cookies_jar_changed_cb (SoupCookieJar*    jar,
                                   SoupCookie*       old_cookie,
                                   SoupCookie*       new_cookie,
                                   KatzeHttpCookies* http_cookies)
{
    GObject* settings;
    guint accept_cookies;

    if (old_cookie)
        soup_cookie_set_max_age (old_cookie, 0);

    if (new_cookie)
    {
        settings = g_object_get_data (G_OBJECT (jar), "midori-settings");
        accept_cookies = katze_object_get_enum (settings, "accept-cookies");
        if (accept_cookies == 2 /* MIDORI_ACCEPT_COOKIES_NONE */)
        {
            soup_cookie_set_max_age (new_cookie, 0);
        }
        else if (accept_cookies == 1 /* MIDORI_ACCEPT_COOKIES_SESSION */
            && new_cookie->expires)
        {
            soup_cookie_set_max_age (new_cookie, -1);
        }
        else if (new_cookie->expires)
        {
            gint age = katze_object_get_int (settings, "maximum-cookie-age");
            if (age > 0)
            {
                SoupDate* max_date = soup_date_new_from_now (
                    age * SOUP_COOKIE_MAX_AGE_ONE_DAY);
                if (soup_date_to_time_t (new_cookie->expires)
                  > soup_date_to_time_t (max_date))
                    soup_cookie_set_expires (new_cookie, max_date);
            }
            else
            {
                /* An age of 0 to SoupCookie means already-expired
                   A user choosing 0 days probably expects 1 hour. */
                soup_cookie_set_max_age (new_cookie, SOUP_COOKIE_MAX_AGE_ONE_HOUR);
            }
        }
    }

    if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL)
        http_cookies->counter++;

    if (!http_cookies->timeout && (old_cookie || new_cookie->expires))
        http_cookies->timeout = g_timeout_add_seconds (5,
            (GSourceFunc)katze_http_cookies_update_jar, http_cookies);
}
Example #3
0
static SoupCookie* toSoupCookie(const Cookie& cookie)
{
    SoupCookie* soupCookie = soup_cookie_new(cookie.name.utf8().data(), cookie.value.utf8().data(),
        cookie.domain.utf8().data(), cookie.path.utf8().data(), -1);
    soup_cookie_set_http_only(soupCookie, cookie.httpOnly);
    soup_cookie_set_secure(soupCookie, cookie.secure);
    if (!cookie.session) {
        SoupDate* date = msToSoupDate(cookie.expires);
        soup_cookie_set_expires(soupCookie, date);
        soup_date_free(date);
    }
    return soupCookie;
}
Example #4
0
void
setcookie(SoupCookie *c) {
	int lock;

	lock = open(cookiefile, 0);
	flock(lock, LOCK_EX);
	SoupDate *e;
	SoupCookieJar *j = soup_cookie_jar_text_new(cookiefile, FALSE);
	c = soup_cookie_copy(c);
	if(c->expires == NULL && sessiontime) {
		e = soup_date_new_from_time_t(time(NULL) + sessiontime);
		soup_cookie_set_expires(c, e);
	}
	soup_cookie_jar_add_cookie(j, c);
	g_object_unref(j);
	flock(lock, LOCK_UN);
	close(lock);
}
Example #5
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);
}
Example #6
0
void
soup_cookie_jar_add_cookie(SoupCookieJar *jar, SoupCookie *cookie)
{
	struct wl_entry		*w = NULL;
	SoupCookie		*c;
	FILE			*r_cookie_f;
	char			*public_suffix;

	DNPRINTF(XT_D_COOKIE, "soup_cookie_jar_add_cookie: %p %p %p\n",
	    jar, p_cookiejar, s_cookiejar);

	if (cookies_enabled == 0)
		return;

	/* see if we are up and running */
	if (p_cookiejar == NULL) {
		_soup_cookie_jar_add_cookie(jar, cookie);
		return;
	}
	/* disallow p_cookiejar adds, shouldn't happen */
	if (jar == p_cookiejar)
		return;

	/* sanity */
	if (jar == NULL || cookie == NULL)
		return;

	/* check if domain is valid */
	public_suffix = tld_get_suffix(cookie->domain[0] == '.' ?
			cookie->domain + 1 : cookie->domain);

	if (public_suffix == NULL ||
	    (enable_cookie_whitelist &&
	    (w = wl_find(cookie->domain, &c_wl)) == NULL)) {
		blocked_cookies++;
		DNPRINTF(XT_D_COOKIE,
		    "soup_cookie_jar_add_cookie: reject %s\n",
		    cookie->domain);
		if (save_rejected_cookies) {
			if ((r_cookie_f = fopen(rc_fname, "a+")) == NULL) {
				show_oops(NULL, "can't open reject cookie file");
				return;
			}
			fseek(r_cookie_f, 0, SEEK_END);
			fprintf(r_cookie_f, "%s%s\t%s\t%s\t%s\t%lu\t%s\t%s\n",
			    cookie->http_only ? "#HttpOnly_" : "",
			    cookie->domain,
			    *cookie->domain == '.' ? "TRUE" : "FALSE",
			    cookie->path,
			    cookie->secure ? "TRUE" : "FALSE",
			    cookie->expires ?
			        (gulong)soup_date_to_time_t(cookie->expires) :
			        0,
			    cookie->name,
			    cookie->value);
			fflush(r_cookie_f);
			fclose(r_cookie_f);
		}
		if (!allow_volatile_cookies)
			return;
	}

	if (cookie->expires == NULL && session_timeout) {
		soup_cookie_set_expires(cookie,
		    soup_date_new_from_now(session_timeout));
		print_cookie("modified add cookie", cookie);
	}

	/* see if we are white listed for persistence */
	if ((w && w->handy) || (enable_cookie_whitelist == 0)) {
		/* add to persistent jar */
		c = soup_cookie_copy(cookie);
		print_cookie("soup_cookie_jar_add_cookie p_cookiejar", c);
		_soup_cookie_jar_add_cookie(p_cookiejar, c);
	}

	/* add to session jar */
	print_cookie("soup_cookie_jar_add_cookie s_cookiejar", cookie);
	_soup_cookie_jar_add_cookie(s_cookiejar, cookie);
}
Example #7
0
static SoupCookie*
cookie_new_from_table(lua_State *L, gint idx, gchar **error)
{
    SoupCookie *cookie = NULL;
    SoupDate *date;
    const gchar *name, *value, *domain, *path;
    name = value = domain = path = NULL;
    gboolean secure, http_only;
    gint expires;

    /* correct relative index */
    if (idx < 0)
        idx = lua_gettop(L) + idx + 1;

    /* check for cookie table */
    if (!lua_istable(L, idx)) {
        *error = g_strdup_printf("invalid cookie table, got %s",
            lua_typename(L, lua_type(L, idx)));
        return NULL;
    }

#define IS_STRING  (lua_isstring(L, -1)  || lua_isnumber(L, -1))
#define IS_BOOLEAN (lua_isboolean(L, -1) || lua_isnil(L, -1))
#define IS_NUMBER  (lua_isnumber(L, -1))

#define GET_PROP(prop, typname, typexpr, typfunc)                           \
    lua_pushliteral(L, #prop);                                              \
    lua_rawget(L, idx);                                                     \
    if ((typexpr)) {                                                        \
        prop = typfunc(L, -1);                                              \
        lua_pop(L, 1);                                                      \
    } else {                                                                \
        *error = g_strdup_printf("invalid cookie." #prop " type, expected " \
            #typname ", got %s",  lua_typename(L, lua_type(L, -1)));        \
        return NULL;                                                        \
    }

    /* get cookie properties */
    GET_PROP(name,      string,  IS_STRING,  lua_tostring)
    GET_PROP(value,     string,  IS_STRING,  lua_tostring)
    GET_PROP(domain,    string,  IS_STRING,  lua_tostring)
    GET_PROP(path,      string,  IS_STRING,  lua_tostring)
    GET_PROP(secure,    boolean, IS_BOOLEAN, lua_toboolean)
    GET_PROP(http_only, boolean, IS_BOOLEAN, lua_toboolean)
    GET_PROP(expires,   number,  IS_NUMBER,  lua_tonumber)

#undef IS_STRING
#undef IS_BOOLEAN
#undef IS_NUMBER
#undef GET_PROP

    /* create soup cookie */
    if ((cookie = soup_cookie_new(name, value, domain, path, expires))) {
        soup_cookie_set_secure(cookie, secure);
        soup_cookie_set_http_only(cookie, http_only);

        /* set real expiry date from unixtime */
        if (expires > 0) {
            date = soup_date_new_from_time_t((time_t) expires);
            soup_cookie_set_expires(cookie, date);
            soup_date_free(date);
        }

        return cookie;
    }

    /* soup cookie creation failed */
    *error = g_strdup_printf("soup cookie creation failed");
    return NULL;
}