Hi all,

Please find attached a small patch which implements a private mode
for vimprobable2 which will disable writing to the
history/cookies/closed files when active.

Toggle (or set in RC) with:
        
        set private=true|on|1

And turn off with:

        set private=false|off|0

By default, it remains off.

Thanks,
-Matt

-- 
Matthew Carter
[email protected]
diff --git a/config.h b/config.h
index ec84f60..dec0544 100644
--- a/config.h
+++ b/config.h
@@ -23,6 +23,7 @@ static const gboolean enablePlugins     = TRUE; /* TRUE keeps plugins enabled */
 static const gboolean enableJava        = TRUE; /* FALSE disables Java applets */
 static const gboolean enablePagecache   = FALSE; /* TRUE turns on the page cache. */
 static gboolean escape_input_on_load    = TRUE; /* TRUE will disable automatic focusing of input fields via Javascript*/
+static gboolean private_mode            = FALSE; /* TRUE will disable writing to the history file, cookie file and closed file */
 char temp_dir[MAX_SETTING_SIZE]         = "/tmp"; /* location of temporary files, default will be overridden if TEMPDIR is set */
 
 char downloads_path[MAX_SETTING_SIZE]   = "";
@@ -232,6 +233,7 @@ static Setting browsersettings[] = {
     { "inputbox",        NULL,               "",                            FALSE,          TRUE,            FALSE,          FALSE  },
     { "completioncase",  NULL,               "",                            FALSE,          TRUE,            FALSE,          FALSE  },
     { "escapeinput",     NULL,               "",                           FALSE,          TRUE,            FALSE,          FALSE  },
+    { "private",         NULL,               "",                           FALSE,          TRUE,            FALSE,          FALSE  },
     { "strictssl",       NULL,               "",                            FALSE,          TRUE,            FALSE,          FALSE  },
     { "cabundle",        ca_bundle,          "",                            FALSE,          FALSE,           FALSE,          FALSE  },
     { "tempdir",         temp_dir,           "",                            FALSE,          FALSE,           FALSE,          FALSE  },
diff --git a/main.c b/main.c
index b1704d7..b36cd6b 100644
--- a/main.c
+++ b/main.c
@@ -136,6 +136,7 @@ static void load_all_cookies(void);
 static void new_generic_request(SoupSession *soup_ses, SoupMessage *soup_msg, gpointer unused);
 static void update_cookie_jar(SoupCookieJar *jar, SoupCookie *old, SoupCookie *new);
 static void handle_cookie_request(SoupMessage *soup_msg, gpointer unused);
+SoupCookieJarAcceptPolicy CookiePolicyLastOn = SOUP_COOKIE_JAR_ACCEPT_ALWAYS; /* by default, accept all cookies */
 #endif
 
 Client client;
@@ -1382,7 +1383,7 @@ quit(const Arg *arg) {
     if (uri != NULL) {
         /* write last URL into status file for recreation with "u" */
         filename = g_strdup_printf("%s", client.config.config_base);
-        filename = g_strdup_printf(CLOSED_URL_FILENAME);
+        filename = g_strdup_printf(private_mode ? "/dev/null" : CLOSED_URL_FILENAME);
         f = fopen(filename, "w");
         g_free((gpointer *)filename);
         if (f != NULL) {
@@ -1795,7 +1796,7 @@ history() {
                 strncat(entry, title, strlen(title));
             }
             n = strlen(entry);
-            filename = g_strdup_printf(HISTORY_STORAGE_FILENAME);
+            filename = g_strdup_printf(private_mode ? "/dev/null" : HISTORY_STORAGE_FILENAME);
             f = fopen(filename, "r");
             if (f != NULL) {
                 new = (char *)malloc(HISTORY_MAX_ENTRIES * 512 * sizeof(char) + 1);
@@ -2339,6 +2340,20 @@ process_set_line(char *line) {
                 gtk_widget_set_visible(client.gui.inputbox, boolval);
             } else if (strlen(my_pair.what) == 11 && strncmp("escapeinput", my_pair.what, 11) == 0) {
                 escape_input_on_load = boolval;
+            } else if (strlen(my_pair.what) == 7 && strncmp("private", my_pair.what, 7) == 0) {
+              /* Store the state of the last 'on' cookie state before toggling it off */
+              if(boolval) {
+                /* Only update this LastOn state if private mode was false before */
+                if(!private_mode) {
+                  CookiePolicyLastOn = CookiePolicy;
+                }
+                CookiePolicy = SOUP_COOKIE_JAR_ACCEPT_NEVER;
+              } else {
+                /* If here, we are not in private_mode, so restore the cookie policy */
+                CookiePolicy = CookiePolicyLastOn;
+              }
+              soup_cookie_jar_set_accept_policy(client.net.session_cookie_jar, CookiePolicy);
+              private_mode = boolval; /* Lastly, set the private_mode for use in other areas */
             } else if (strlen(my_pair.what) == 7 && strncmp("cookies", my_pair.what, 7) == 0) {
                 /* cookie policy */
                 if (strncmp(my_pair.value, "on", 2) == 0 || strncmp(my_pair.value, "true", 4) == 0 ||
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Vimprobable-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vimprobable-users

Reply via email to