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 <[email protected]> --- 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 ------------------------------------------------------------------------------ Go from Idea to Many App Stores Faster with Intel(R) XDK Give your users amazing mobile app experiences with Intel(R) XDK. Use one codebase in this all-in-one HTML5 development environment. Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs. http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140 _______________________________________________ Vimprobable-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/vimprobable-users
