From 4194579591edd3d21b3508d11a90f05cfbccdbe1 Mon Sep 17 00:00:00 2001 From: portix Date: Thu, 22 Mar 2012 17:20:28 +0100 Subject: Branch experimental: reduce disk access with new 'sync-files' property --HG-- branch : experimental --- src/commands.c | 8 +++--- src/config.h | 2 +- src/dwb.c | 88 +++++++++++++++++++++++++++++++++++----------------------- src/dwb.h | 5 +++- src/soup.c | 30 ++++++++++++++++---- src/soup.h | 1 + src/view.c | 4 +-- 7 files changed, 90 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/commands.c b/src/commands.c index c26538a7..2e6783cb 100644 --- a/src/commands.c +++ b/src/commands.c @@ -527,7 +527,7 @@ commands_complete_type(KeyMap *km, Arg *arg) { }/*}}}*/ void -commands_toggle(Arg *arg, const char *filename, GList **tmp, const char *message) { +commands_toggle(Arg *arg, const char *filename, GList **tmp, GList **pers, const char *message) { char *host = NULL; const char *block = NULL; gboolean allowed; @@ -556,7 +556,7 @@ commands_toggle(Arg *arg, const char *filename, GList **tmp, const char *message dwb_set_normal_message(dwb.state.fview, true, "%s temporarily %s for %s", message, allowed ? "allowed" : "blocked", block); } else { - allowed = dwb_toggle_allowed(filename, block); + allowed = dwb_toggle_allowed(filename, block, pers); dwb_set_normal_message(dwb.state.fview, true, "%s %s for %s", message, allowed ? "allowed" : "blocked", block); } } @@ -566,14 +566,14 @@ commands_toggle(Arg *arg, const char *filename, GList **tmp, const char *message DwbStatus commands_toggle_plugin_blocker(KeyMap *km, Arg *arg) { - commands_toggle(arg, dwb.files.plugins_allow, &dwb.fc.tmp_plugins, "Plugins"); + commands_toggle(arg, dwb.files.plugins_allow, &dwb.fc.tmp_plugins, &dwb.fc.pers_plugins, "Plugins"); return STATUS_OK; } /* commands_toggle_scripts {{{ */ DwbStatus commands_toggle_scripts(KeyMap *km, Arg *arg) { - commands_toggle(arg, dwb.files.scripts_allow, &dwb.fc.tmp_scripts, "Scripts"); + commands_toggle(arg, dwb.files.scripts_allow, &dwb.fc.tmp_scripts, &dwb.fc.pers_scripts, "Scripts"); return STATUS_OK; }/*}}}*/ diff --git a/src/config.h b/src/config.h index 548390a4..eef223f5 100644 --- a/src/config.h +++ b/src/config.h @@ -931,7 +931,7 @@ static WebSettings DWB_SETTINGS[] = { SETTING_GLOBAL, BOOLEAN, { .b = true }, NULL, }, { { "enable-favicon", "Whether to show favicons", }, SETTING_GLOBAL, BOOLEAN, { .b = true }, (S_Func)dwb_set_favicon, }, - { { "sync-history", "Interval to save history to hdd or 0 to directly write to hdd", }, + { { "sync-files", "Interval to save history and cookies to hdd or 0 to directly write to hdd", }, SETTING_GLOBAL|SETTING_ONINIT, INTEGER, { .i = 0 }, (S_Func) dwb_set_sync_interval, }, { { "active-completion-fg-color", "Foreground color of the active tabcompletion item", }, diff --git a/src/dwb.c b/src/dwb.c index 71a6f3ee..fd004260 100644 --- a/src/dwb.c +++ b/src/dwb.c @@ -70,7 +70,7 @@ static DwbStatus dwb_set_ntlm(GList *gl, WebSettings *s); static DwbStatus dwb_init_hints(GList *gl, WebSettings *s); static Navigation * dwb_get_search_completion_from_navigation(Navigation *); -static gboolean dwb_sync_history(gpointer); +static gboolean dwb_sync_files(gpointer); static void dwb_save_key_value(const char *file, const char *key, const char *value); static gboolean dwb_editable_focus_cb(WebKitDOMElement *element, WebKitDOMEvent *event, GList *gl); @@ -220,7 +220,7 @@ dwb_set_sync_interval(GList *gl, WebSettings *s) { dwb.misc.sync_interval = s->arg.i; if (s->arg.i > 0) { - dwb.misc.synctimer = g_timeout_add_seconds(s->arg.i, dwb_sync_history, NULL); + dwb.misc.synctimer = g_timeout_add_seconds(s->arg.i, dwb_sync_files, NULL); } return STATUS_OK; }/*}}}*/ @@ -947,7 +947,7 @@ dwb_remove_quickmark(const char *line) { /* dwb_sync_history {{{*/ static gboolean -dwb_sync_history(gpointer data) { +dwb_sync_files(gpointer data) { GString *buffer = g_string_new(NULL); for (GList *gl = dwb.fc.history; gl; gl=gl->next) { Navigation *n = gl->data; @@ -955,6 +955,7 @@ dwb_sync_history(gpointer data) { } g_file_set_contents(dwb.files.history, buffer->str, -1, NULL); g_string_free(buffer, true); + dwb_soup_sync_cookies(); return true; }/*}}}*/ @@ -1139,46 +1140,45 @@ dwb_focus_view(GList *gl) { } }/*}}}*/ -/* dwb_get_allowed(const char *filename, const char *data) {{{*/ -gboolean -dwb_get_allowed(const char *filename, const char *data) { - char *content; - gboolean ret = false; - g_file_get_contents(filename, &content, NULL, NULL); - if (content) { - char **lines = g_strsplit(content, "\n", -1); - for (int i=0; i 0) { - dwb_sync_history(NULL); - } + dwb_sync_files(NULL); /* Save command history */ if (! dwb.misc.private_browsing) { dwb_save_list(dwb.fc.navigations, dwb.files.navigation_history, GET_INT("navigation-history-max")); @@ -3410,6 +3410,24 @@ dwb_get_search_completion(const char *text) { return dwb_get_search_completion_from_navigation(n); } +GList * +dwb_get_simple_list(GList *gl, const char *filename) { + if (gl != NULL) { + for (GList *l = gl; l; l=l->next) { + g_free(l->data); + } + g_list_free(gl); + gl = NULL; + } + char **lines = util_get_lines(filename); + if (lines == NULL) + return NULL; + for (int i=0; lines[i]; i++) { + gl = g_list_prepend(gl, lines[i]); + } + return gl; +} + /* dwb_init_files() {{{*/ void dwb_init_files() { @@ -3465,6 +3483,8 @@ dwb_init_files() { dwb.fc.tmp_scripts = NULL; dwb.fc.tmp_plugins = NULL; dwb.fc.downloads = NULL; + dwb.fc.pers_scripts = dwb_get_simple_list(NULL, dwb.files.scripts_allow); + dwb.fc.pers_plugins = dwb_get_simple_list(NULL, dwb.files.plugins_allow); if (g_list_last(dwb.fc.searchengines)) dwb.misc.default_search = ((Navigation*)dwb.fc.searchengines->data)->second; diff --git a/src/dwb.h b/src/dwb.h index e68b2d2b..ef380685 100644 --- a/src/dwb.h +++ b/src/dwb.h @@ -747,6 +747,8 @@ struct _FileContent { GList *adblock; GList *tmp_scripts; GList *tmp_plugins; + GList *pers_scripts; + GList *pers_plugins; GList *downloads; }; @@ -834,7 +836,7 @@ void dwb_clean_load_end(GList *); void dwb_clean_load_begin(GList *); void dwb_update_uri(GList *); gboolean dwb_get_allowed(const char *, const char *); -gboolean dwb_toggle_allowed(const char *, const char *); +gboolean dwb_toggle_allowed(const char *, const char *, GList **); char * dwb_get_host(WebKitWebView *); void dwb_focus_view(GList *); void dwb_clean_key_buffer(void); @@ -881,6 +883,7 @@ DwbStatus dwb_pack(const char *layout, gboolean rebuild); void dwb_init_signals(void); void dwb_parse_commands(const char *line); DwbStatus dwb_scheme_handler(GList *gl, WebKitNetworkRequest *request); +GList *dwb_get_simple_list(GList *, const char *filename); gboolean dwb_dom_remove_from_parent(WebKitDOMNode *node, GError **error); diff --git a/src/soup.c b/src/soup.c index d116bef1..69cac757 100644 --- a/src/soup.c +++ b/src/soup.c @@ -25,6 +25,7 @@ static SoupCookieJar *_jar; static guint _changed_id; static SoupCookieJar *_tmpJar; +static SoupCookieJar *_persJar; /* dwb_soup_allow_cookie(GList *, const char, CookieStorePolicy) {{{*/ static DwbStatus @@ -220,15 +221,13 @@ dwb_soup_get_cookie_store_policy(const char *policy) { /*dwb_soup_cookie_changed_cb {{{*/ static void dwb_soup_cookie_changed_cb(SoupCookieJar *jar, SoupCookie *old, SoupCookie *new, gpointer *p) { - int fd = open(dwb.files.cookies, 0); - flock(fd, LOCK_EX); - SoupCookieJar *j = soup_cookie_jar_text_new(dwb.files.cookies, false); + //SoupCookieJar *j = soup_cookie_jar_text_new(dwb.files.cookies, false); if (old) { - soup_cookie_jar_delete_cookie(j, old); + soup_cookie_jar_delete_cookie(_persJar, old); } if (new) { if (dwb.state.cookie_store_policy == COOKIE_STORE_PERSISTENT || dwb_soup_test_cookie_allowed(dwb.fc.cookies_allow, new)) { - soup_cookie_jar_add_cookie(j, soup_cookie_copy(new)); + soup_cookie_jar_add_cookie(_persJar, soup_cookie_copy(new)); } else { soup_cookie_jar_add_cookie(_tmpJar, soup_cookie_copy(new)); @@ -239,16 +238,33 @@ dwb_soup_cookie_changed_cb(SoupCookieJar *jar, SoupCookie *old, SoupCookie *new, } } } + if (dwb.misc.sync_interval <= 0) + dwb_soup_sync_cookies(); + +}/*}}}*/ + +void +dwb_soup_sync_cookies() { + int fd = open(dwb.files.cookies, 0); + flock(fd, LOCK_EX); + GSList *all_cookies = soup_cookie_jar_all_cookies(_persJar); + SoupCookieJar *j = soup_cookie_jar_text_new(dwb.files.cookies, false); + for (GSList *l = all_cookies; l; l=l->next) { + soup_cookie_jar_add_cookie(j, l->data); + } + g_slist_free(all_cookies); g_object_unref(j); flock(fd, LOCK_UN); close(fd); -}/*}}}*/ +} /* dwb_soup_init_cookies {{{*/ void dwb_soup_init_cookies(SoupSession *s) { _jar = soup_cookie_jar_new(); _tmpJar = soup_cookie_jar_new(); + //_persJar = soup_cookie_jar_new(); + _persJar = soup_cookie_jar_new(); dwb_soup_set_cookie_accept_policy(GET_CHAR("cookies-accept-policy")); SoupCookieJar *old_cookies = soup_cookie_jar_text_new(dwb.files.cookies, true); GSList *l = soup_cookie_jar_all_cookies(old_cookies); @@ -307,6 +323,8 @@ void dwb_soup_end() { g_object_unref(_tmpJar); g_object_unref(_jar); + dwb_soup_sync_cookies(); + g_object_unref(_persJar); g_free(dwb.misc.proxyuri); }/*}}}*/ diff --git a/src/soup.h b/src/soup.h index e42b6848..6fac3160 100644 --- a/src/soup.h +++ b/src/soup.h @@ -20,6 +20,7 @@ #define COOKIES_H void dwb_soup_clean(void); +void dwb_soup_sync_cookies(void); void dwb_soup_allow_cookie_tmp(void); DwbStatus dwb_soup_allow_cookie(GList **, const char *, CookieStorePolicy); const char * dwb_soup_get_host_from_request(WebKitNetworkRequest *); diff --git a/src/view.c b/src/view.c index fb8a5649..eb36b888 100644 --- a/src/view.c +++ b/src/view.c @@ -552,7 +552,7 @@ view_load_status_cb(WebKitWebView *web, GParamSpec *pspec, GList *gl) { view_ssl_state(gl); if (VIEW(gl)->status->scripts & SCRIPTS_BLOCKED && (((host = dwb_get_host(web)) - && (dwb_get_allowed(dwb.files.scripts_allow, host) || dwb_get_allowed(dwb.files.scripts_allow, uri) + && (g_list_find_custom(dwb.fc.pers_scripts, host, (GCompareFunc)g_strcmp0) || g_list_find_custom(dwb.fc.pers_scripts, uri, (GCompareFunc)g_strcmp0) || g_list_find_custom(dwb.fc.tmp_scripts, host, (GCompareFunc)g_strcmp0) || g_list_find_custom(dwb.fc.tmp_scripts, uri, (GCompareFunc)g_strcmp0))) || g_str_has_prefix(uri, "dwb:") || !g_strcmp0(uri, "Error"))) { g_object_set(webkit_web_view_get_settings(web), "enable-scripts", true, NULL); @@ -560,7 +560,7 @@ view_load_status_cb(WebKitWebView *web, GParamSpec *pspec, GList *gl) { } if (v->plugins->status & PLUGIN_STATUS_ENABLED && ( (host != NULL || (host = dwb_get_host(web))) - && (dwb_get_allowed(dwb.files.plugins_allow, host) || dwb_get_allowed(dwb.files.plugins_allow, uri) + && (g_list_find_custom(dwb.fc.pers_plugins, host, (GCompareFunc)g_strcmp0) || g_list_find_custom(dwb.fc.pers_plugins, uri, (GCompareFunc)g_strcmp0) || g_list_find_custom(dwb.fc.tmp_plugins, host, (GCompareFunc)g_strcmp0) || g_list_find_custom(dwb.fc.tmp_plugins, uri, (GCompareFunc)g_strcmp0) ) )) { plugins_disconnect(gl); -- cgit debian/1.2.3+git2.25.1-1-2-gaceb0