void transfer_cookies(void) { GSList *cf; SoupCookie *sc, *pc; cf = soup_cookie_jar_all_cookies(p_cookiejar); for (;cf; cf = cf->next) { pc = cf->data; sc = soup_cookie_copy(pc); _soup_cookie_jar_add_cookie(s_cookiejar, sc); } soup_cookies_free(cf); }
void soup_cookie_jar_add_cookie(SoupCookieJar *jar, SoupCookie *cookie) { struct wl_entry *w = NULL; SoupCookie *c; FILE *r_cookie_f; char *public_suffix; DNPRINTF(XT_D_COOKIE, "soup_cookie_jar_add_cookie: %p %p %p\n", jar, p_cookiejar, s_cookiejar); if (cookies_enabled == 0) return; /* see if we are up and running */ if (p_cookiejar == NULL) { _soup_cookie_jar_add_cookie(jar, cookie); return; } /* disallow p_cookiejar adds, shouldn't happen */ if (jar == p_cookiejar) return; /* sanity */ if (jar == NULL || cookie == NULL) return; /* check if domain is valid */ public_suffix = tld_get_suffix(cookie->domain[0] == '.' ? cookie->domain + 1 : cookie->domain); if (public_suffix == NULL || (enable_cookie_whitelist && (w = wl_find(cookie->domain, &c_wl)) == NULL)) { blocked_cookies++; DNPRINTF(XT_D_COOKIE, "soup_cookie_jar_add_cookie: reject %s\n", cookie->domain); if (save_rejected_cookies) { if ((r_cookie_f = fopen(rc_fname, "a+")) == NULL) { show_oops(NULL, "can't open reject cookie file"); return; } fseek(r_cookie_f, 0, SEEK_END); fprintf(r_cookie_f, "%s%s\t%s\t%s\t%s\t%lu\t%s\t%s\n", cookie->http_only ? "#HttpOnly_" : "", cookie->domain, *cookie->domain == '.' ? "TRUE" : "FALSE", cookie->path, cookie->secure ? "TRUE" : "FALSE", cookie->expires ? (gulong)soup_date_to_time_t(cookie->expires) : 0, cookie->name, cookie->value); fflush(r_cookie_f); fclose(r_cookie_f); } if (!allow_volatile_cookies) return; } if (cookie->expires == NULL && session_timeout) { soup_cookie_set_expires(cookie, soup_date_new_from_now(session_timeout)); print_cookie("modified add cookie", cookie); } /* see if we are white listed for persistence */ if ((w && w->handy) || (enable_cookie_whitelist == 0)) { /* add to persistent jar */ c = soup_cookie_copy(cookie); print_cookie("soup_cookie_jar_add_cookie p_cookiejar", c); _soup_cookie_jar_add_cookie(p_cookiejar, c); } /* add to session jar */ print_cookie("soup_cookie_jar_add_cookie s_cookiejar", cookie); _soup_cookie_jar_add_cookie(s_cookiejar, cookie); }
int wl_save(struct tab *t, struct karg *args, int list) { char file[PATH_MAX], *lst_str = NULL; FILE *f = NULL; char *line = NULL, *lt = NULL, *dom; size_t linelen; const gchar *uri; struct karg a; struct domain *d; GSList *cf; SoupCookie *ci, *c; if (t == NULL || args == NULL) return (1); if (runtime_settings[0] == '\0') return (1); switch (list) { case XT_WL_JAVASCRIPT: lst_str = "JavaScript"; break; case XT_WL_COOKIE: lst_str = "Cookie"; break; case XT_WL_PLUGIN: lst_str = "Plugin"; break; default: show_oops(t, "Invalid list id: %d", list); return (1); } uri = get_uri(t); dom = find_domain(uri, args->i & XT_WL_TOPLEVEL); if (uri == NULL || dom == NULL || webkit_web_view_get_load_status(t->wv) == WEBKIT_LOAD_FAILED) { show_oops(t, "Can't add domain to %s white list", lst_str); goto done; } switch (list) { case XT_WL_JAVASCRIPT: lt = g_strdup_printf("js_wl=%s", dom); break; case XT_WL_COOKIE: lt = g_strdup_printf("cookie_wl=%s", dom); break; case XT_WL_PLUGIN: lt = g_strdup_printf("pl_wl=%s", dom); break; default: /* can't happen */ show_oops(t, "Invalid list id: %d", list); goto done; } snprintf(file, sizeof file, "%s" PS "%s", work_dir, runtime_settings); if ((f = fopen(file, "r+")) == NULL) { show_oops(t, "can't open file %s"); goto done; } while (!feof(f)) { line = fparseln(f, &linelen, NULL, NULL, 0); if (line == NULL) continue; if (!strcmp(line, lt)) goto done; free(line); line = NULL; } fprintf(f, "%s\n", lt); a.i = XT_WL_ENABLE; a.i |= args->i; switch (list) { case XT_WL_JAVASCRIPT: d = wl_find(dom, &js_wl); if (!d) { settings_add("js_wl", dom); d = wl_find(dom, &js_wl); } toggle_js(t, &a); break; case XT_WL_COOKIE: d = wl_find(dom, &c_wl); if (!d) { settings_add("cookie_wl", dom); d = wl_find(dom, &c_wl); } toggle_cwl(t, &a); /* find and add to persistent jar */ cf = soup_cookie_jar_all_cookies(s_cookiejar); for (;cf; cf = cf->next) { ci = cf->data; if (!strcmp(dom, ci->domain) || !strcmp(&dom[1], ci->domain)) /* deal with leading . */ { c = soup_cookie_copy(ci); _soup_cookie_jar_add_cookie(p_cookiejar, c); } } soup_cookies_free(cf); break; case XT_WL_PLUGIN: d = wl_find(dom, &pl_wl); if (!d) { settings_add("pl_wl", dom); d = wl_find(dom, &pl_wl); } toggle_pl(t, &a); break; default: abort(); /* can't happen */ } if (d) d->handy = 1; done: if (line) free(line); if (dom) g_free(dom); if (lt) g_free(lt); if (f) fclose(f); return (0); }