Thread: [Vimprobable-users] cookies
Vimprobable is a lean web browser optimised for full keyboard control
Brought to you by:
hanness
From: Serge E. H. <se...@ha...> - 2015-11-21 21:18:02
|
Hi, has anyone written a patch to make the the cookies file and the readonly state configurable? (I.e. :set cookies=~/github.cookies) Seems like it would be nice to keep different sites balkanized, as well as more easily keep tabs on which sites are really laying on the garbage. -serge |
From: Hannes S. <ha...@yl...> - 2015-11-22 09:11:31
|
"Serge E. Hallyn" <se...@ha...>: > has anyone written a patch to make the the cookies file and the > readonly state configurable? (I.e. :set cookies=~/github.cookies) Sounds useful! Hannes |
From: Serge E. H. <ser...@ub...> - 2015-11-22 16:13:56
|
On Sun, Nov 22, 2015 at 10:11:22AM +0100, Hannes Schüller wrote: > "Serge E. Hallyn" <se...@ha...>: > > has anyone written a patch to make the the cookies file and the > > readonly state configurable? (I.e. :set cookies=~/github.cookies) > > Sounds useful! Ok, I'm playing with my wm right now, I'll try to get something along these lines in the next few weeks. |
From: Serge E. H. <se...@ha...> - 2015-12-03 03:55:22
|
The default cookie site is ~/.config/vimprobable/cookies. With this patch, you can do :cookies gh or :cookies lp to load a per-site cookiefile called ~/.config/vimprobable/cookies_gh or cookies_lp (i.e. for github and launchpad). This allows you to segregate cookies by sites, and more easily keep an eye on suspect sites. Signed-off-by: Serge Hallyn <ser...@ub...> --- config.h | 2 ++ main.c | 31 +++++++++++++++++++++++++------ vimprobable.h | 2 +- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/config.h b/config.h index e423f77..33ab743 100644 --- a/config.h +++ b/config.h @@ -83,6 +83,7 @@ static URIHandler uri_handlers[] = { /* cookies */ #define ENABLE_COOKIE_SUPPORT #define COOKIES_STORAGE_FILENAME "%s/vimprobable/cookies", client.config.config_base +#define COOKIES_STORAGE_PATH "%s/vimprobable/cookies_%s", client.config.config_base #define COOKIES_STORAGE_READONLY FALSE /* if TRUE new cookies will be lost if you quit */ SoupCookieJarAcceptPolicy CookiePolicy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY; /* by default, accept all cookies, but third party */ SoupCookieJarAcceptPolicy CookiePolicyLastOn = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY; /* tracking variable for private mode */ @@ -156,6 +157,7 @@ Command commands[COMMANDSIZE] = { { "tabopen", open_arg, {TargetNew} }, { "print", print_frame, {0} }, { "bma", bookmark, {0} }, + { "cookies", switch_cookies, {0} }, { "bookmark", bookmark, {0} }, { "source", view_source, {0} }, { "esource", edit_source, {0} }, diff --git a/main.c b/main.c index d90c4c2..d72d0a1 100644 --- a/main.c +++ b/main.c @@ -66,6 +66,7 @@ static gboolean blank_cb(void); /* functions */ static gboolean bookmark(const Arg *arg); +static gboolean switch_cookies(const Arg *arg); static gboolean browser_settings(const Arg *arg); static gboolean commandhistoryfetch(const Arg *arg); static gboolean complete(const Arg *arg); @@ -135,7 +136,7 @@ static char **args; /* Cookie support. */ #ifdef ENABLE_COOKIE_SUPPORT -static void setup_cookies(void); +static void setup_cookies(const char *); static char *get_cookies(SoupURI *soup_uri); static void load_all_cookies(void); static void new_generic_request(SoupSession *soup_ses, SoupMessage *soup_msg, gpointer unused); @@ -1765,6 +1766,24 @@ commandhistoryfetch(const Arg *arg) { } gboolean +switch_cookies(const Arg *arg) { + if (!arg->s || !strlen(arg->s)) { + echo_message(Info, "No cookie file given"); + return FALSE; + } + + Network *net = &client.net; + if (net->file_cookie_jar) + g_object_unref(net->file_cookie_jar); + char *tmp = g_strdup_printf(COOKIES_STORAGE_PATH, arg->s); + setup_cookies(tmp); + g_free(tmp); + + echo_message(Info, "Cookies loaded"); + return TRUE; +} + +gboolean bookmark(const Arg *arg) { FILE *f; const char *filename; @@ -2969,11 +2988,9 @@ scripts_run_user_file() { #ifdef ENABLE_COOKIE_SUPPORT void -setup_cookies() +setup_cookies(const char *cookiefile) { Network *net = &client.net; - if (net->file_cookie_jar) - g_object_unref(net->file_cookie_jar); if (net->session_cookie_jar) g_object_unref(net->session_cookie_jar); @@ -2981,7 +2998,7 @@ setup_cookies() net->session_cookie_jar = soup_cookie_jar_new(); soup_cookie_jar_set_accept_policy(net->session_cookie_jar, CookiePolicy); - net->cookie_store = g_strdup_printf(COOKIES_STORAGE_FILENAME); + net->cookie_store = g_strdup(cookiefile); load_all_cookies(); @@ -3181,7 +3198,9 @@ main(int argc, char *argv[]) { make_keyslist(); setup_gui(); #ifdef ENABLE_COOKIE_SUPPORT - setup_cookies(); + char *tmp = g_strdup_printf(COOKIES_STORAGE_FILENAME); + setup_cookies(tmp); + g_free(tmp); #endif make_searchengines_list(searchengines, LENGTH(searchengines)); diff --git a/vimprobable.h b/vimprobable.h index 5f6ee83..949eb14 100644 --- a/vimprobable.h +++ b/vimprobable.h @@ -193,7 +193,7 @@ enum ConfigFileError { #define CLOSED_URL_FILENAME "%s/vimprobable/closed", client.config.config_base /* Command size */ -#define COMMANDSIZE 49 +#define COMMANDSIZE 51 /* maximum size of internal string variable handled by :set * if you set this to anything lower than 8, colour values -- 2.5.0 |
From: Hannes S. <ha...@yl...> - 2015-12-07 18:12:24
|
Hi Serge, thanks for this patch! "Serge E. Hallyn" <se...@ha...>: > The default cookie site is ~/.config/vimprobable/cookies. With this > patch, you can do > > :cookies gh > or > :cookies lp > > to load a per-site cookiefile called ~/.config/vimprobable/cookies_gh > or cookies_lp (i.e. for github and launchpad). This allows you to > segregate cookies by sites, and more easily keep an eye on suspect > sites. I basically have two comments. 1. I see no way of switching back to the original file. 2. What's the rationale for defining this as a new command rather than a "setting"? From your original description, I would have expected something like :set cookiefile=... Don't you think it could be a little confusing to have both :set cookies=(on|off) *and* :cookies=... Hannes |
From: Serge E. H. <se...@ha...> - 2015-12-07 18:36:37
|
On Mon, Dec 07, 2015 at 07:12:13PM +0100, Hannes Schüller wrote: > Hi Serge, > > thanks for this patch! > > "Serge E. Hallyn" <se...@ha...>: > > The default cookie site is ~/.config/vimprobable/cookies. With this > > patch, you can do > > > > :cookies gh > > or > > :cookies lp > > > > to load a per-site cookiefile called ~/.config/vimprobable/cookies_gh > > or cookies_lp (i.e. for github and launchpad). This allows you to > > segregate cookies by sites, and more easily keep an eye on suspect > > sites. > > I basically have two comments. > > 1. I see no way of switching back to the original file. true. > 2. What's the rationale for defining this as a new command rather than > a "setting"? From your original description, I would have expected > something like > :set cookiefile=... > Don't you think it could be a little confusing to have both > :set cookies=(on|off) > *and* > :cookies=... In fact it is a little confusing :) But I did it for lazyness' sake. I'll probably have 4-5 cookie files (too many to assign ctrl-<something> to each one), and I see no way to map, say, f6 to ":set cookie_file=" leaving me to fill in the name. So ':c<tab>' works nicely. I suppose providing a way (if I'm not wrong, and such a way doesn't already exist :) to allow such mapping, and making cookiefile a setting, would make the most sense. |