diff options
author | portix <portix@gmx.net> | 2012-03-22 17:20:28 +0100 |
---|---|---|
committer | portix <portix@gmx.net> | 2012-03-22 17:20:28 +0100 |
commit | 4194579591edd3d21b3508d11a90f05cfbccdbe1 (patch) | |
tree | 6983b8a8289c29099e51594472e1c86c1531a398 /src | |
parent | e6594743e1afeb3436427389b082f80dadc0a165 (diff) | |
download | dwb-4194579591edd3d21b3508d11a90f05cfbccdbe1.zip |
Branch experimental: reduce disk access with new 'sync-files' property
--HG--
branch : experimental
Diffstat (limited to 'src')
-rw-r--r-- | src/commands.c | 8 | ||||
-rw-r--r-- | src/config.h | 2 | ||||
-rw-r--r-- | src/dwb.c | 88 | ||||
-rw-r--r-- | src/dwb.h | 5 | ||||
-rw-r--r-- | src/soup.c | 30 | ||||
-rw-r--r-- | src/soup.h | 1 | ||||
-rw-r--r-- | src/view.c | 4 |
7 files changed, 90 insertions, 48 deletions
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", }, @@ -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<g_strv_length(lines); i++) { - if (!g_strcmp0(lines[i], data)) { - ret = true; - break; - } - } - g_strfreev(lines); - g_free(content); - } - return ret; -}/*}}}*/ - /* dwb_toggle_allowed(const char *filename, const char *data) {{{*/ gboolean -dwb_toggle_allowed(const char *filename, const char *data) { - char *content = NULL; +dwb_toggle_allowed(const char *filename, const char *data, GList **pers) { if (!data) return false; - gboolean allowed = dwb_get_allowed(filename, data); - g_file_get_contents(filename, &content, NULL, NULL); + char *content = util_get_file_content(filename); + char **lines = NULL; + gboolean allowed = false; + if (content != NULL) { + lines = util_get_lines(filename); + if (lines != NULL) { + for (int i=0; lines[i] != NULL; i++) { + if (!g_strcmp0(lines[i], data)) { + allowed = true; + break; + } + } + } + } GString *buffer = g_string_new(NULL); if (!allowed) { if (content) { g_string_append(buffer, content); } g_string_append_printf(buffer, "%s\n", data); + *pers = g_list_prepend(*pers, g_strdup(data)); + g_strfreev(lines); } else if (content) { - char **lines = g_strsplit(content, "\n", -1); - for (int i=0; i<g_strv_length(lines); i++) { - if (strlen(lines[i]) && g_strcmp0(lines[i], data)) { - g_string_append_printf(buffer, "%s\n", lines[i]); + if (pers != NULL) { + dwb_free_list(*pers, (void_func)g_free); + *pers = NULL; + } + if (lines != NULL) { + for (int i=0; lines[i] != NULL; i++) { + if (strlen(lines[i]) && g_strcmp0(lines[i], data)) { + g_string_append_printf(buffer, "%s\n", lines[i]); + *pers = g_list_prepend(*pers, lines[i]); + } } } } @@ -2669,6 +2669,8 @@ dwb_clean_up() { dwb_free_list(dwb.fc.navigations, (void_func)g_free); dwb_free_list(dwb.fc.commands, (void_func)g_free); dwb_free_list(dwb.misc.userscripts, (void_func)dwb_navigation_free); + dwb_free_list(dwb.fc.pers_plugins, (void_func)g_free); + dwb_free_list(dwb.fc.pers_scripts, (void_func)g_free); dwb_free_custom_keys(); dwb_soup_end(); @@ -2787,9 +2789,7 @@ dwb_save_list(GList *list, const char *filename, int limit) { /* dwb_save_files() {{{*/ gboolean dwb_save_files(gboolean end_session) { - if (dwb.misc.synctimer > 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; @@ -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); @@ -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); }/*}}}*/ @@ -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 *); @@ -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); |