diff --git a/config.def.h b/config.def.h index b81e6b0..a7571ac 100644 --- a/config.def.h +++ b/config.def.h @@ -12,6 +12,7 @@ static Bool kioskmode = FALSE; /* Ignore shortcuts */ static Bool showindicators = TRUE; /* Show indicators in window title */ static Bool zoomto96dpi = TRUE; /* Zoom pages to always emulate 96dpi */ static Bool runinfullscreen = FALSE; /* Run in fullscreen mode by default */ +static char cookiepolicy[] = "A"; /* A:always, a:never, @:no third party */ static guint defaultfontsize = 12; /* Default font size */ static gfloat zoomlevel = 1.0; /* Default zoom level */ diff --git a/surf.1 b/surf.1 index 325e817..c64ad9e 100644 --- a/surf.1 +++ b/surf.1 @@ -18,13 +18,18 @@ which makes it possible to embed it in another application. Furthermore, one can point surf to another URI by setting its XProperties. .SH OPTIONS .TP +.B \-a policy +Specify the cookie +.I policy +to use +.TP .B \-b Disable Scrollbars .TP .B \-B Enable Scrollbars .TP -.B \-c cookiefile +.B \-c cookiefile Specify the .I cookiefile to use. @@ -69,7 +74,7 @@ Disable Plugins .B \-P Enable Plugins .TP -.B \-r scriptfile +.B \-r scriptfile Specify the user .I scriptfile. .TP @@ -83,7 +88,7 @@ Enable Javascript Specify the user .I stylefile. .TP -.B \-u useragent +.B \-u useragent Specify the .I useragent which surf should use. @@ -94,7 +99,7 @@ Prints version information to standard output, then exits. .B \-x Prints xid to standard output. This can be used to script the browser by using .TP -.B \-z zoomlevel +.B \-z zoomlevel Specify the .I zoomlevel which surf should use. @@ -177,7 +182,7 @@ Toggle auto-loading of images. .TP .B Ctrl\-Shift\-m Toggle if the -.I stylefile +.I stylefile file should be loaded. .TP .B Ctrl\-Shift\-o diff --git a/surf.c b/surf.c index f0be24b..79ef37d 100644 --- a/surf.c +++ b/surf.c @@ -79,7 +79,7 @@ static gboolean showxid = FALSE; static char winid[64]; static gboolean usingproxy = 0; static char togglestat[7]; -static char pagestat[3]; +static char pagestat[4]; static void addaccelgroup(Client *c); static void beforerequest(WebKitWebView *w, WebKitWebFrame *f, @@ -94,9 +94,12 @@ static void clipboard(Client *c, const Arg *arg); static void cookiejar_changed(SoupCookieJar *self, SoupCookie *old_cookie, SoupCookie *new_cookie); static void cookiejar_finalize(GObject *self); -static SoupCookieJar *cookiejar_new(const char *filename, gboolean read_only); +static SoupCookieJar *cookiejar_new(const char *filename, gboolean read_only, + SoupCookieJarAcceptPolicy policy); static void cookiejar_set_property(GObject *self, guint prop_id, const GValue *value, GParamSpec *pspec); +static SoupCookieJarAcceptPolicy cookiepolicy_get(const char *p); +static char cookiepolicy_set(const SoupCookieJarAcceptPolicy p); static char *copystr(char **str, const char *src); static WebKitWebView *createwindow(WebKitWebView *v, WebKitWebFrame *f, @@ -295,10 +298,12 @@ cookiejar_init(CookieJar *self) { } static SoupCookieJar * -cookiejar_new(const char *filename, gboolean read_only) { +cookiejar_new(const char *filename, gboolean read_only, + SoupCookieJarAcceptPolicy policy) { return g_object_new(COOKIEJAR_TYPE, SOUP_COOKIE_JAR_TEXT_FILENAME, filename, - SOUP_COOKIE_JAR_READ_ONLY, read_only, NULL); + SOUP_COOKIE_JAR_READ_ONLY, read_only, + SOUP_COOKIE_JAR_ACCEPT_POLICY, policy, NULL); } static void @@ -310,6 +315,47 @@ cookiejar_set_property(GObject *self, guint prop_id, const GValue *value, flock(COOKIEJAR(self)->lock, LOCK_UN); } +static SoupCookieJarAcceptPolicy +cookiepolicy_get(const char *p) { + SoupCookieJarAcceptPolicy ep; + + switch (*p) { + case 'A': + ep = SOUP_COOKIE_JAR_ACCEPT_ALWAYS; + break; + case 'a': + ep = SOUP_COOKIE_JAR_ACCEPT_NEVER; + break; + case '@': + ep = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY; + break; + default: + ep = SOUP_COOKIE_JAR_ACCEPT_ALWAYS; + } + return ep; +} + +static char +cookiepolicy_set(const SoupCookieJarAcceptPolicy ep) { + char p; + + switch (ep) { + case SOUP_COOKIE_JAR_ACCEPT_ALWAYS: + p = 'A'; + break; + case SOUP_COOKIE_JAR_ACCEPT_NEVER: + p = 'a'; + break; + case SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY: + p = '@'; + break; + default: + p = 'A'; + break; + } + return p; +} + static void evalscript(JSContextRef js, char *script, char* scriptname) { JSStringRef jsscript, jsscriptname; @@ -1066,8 +1112,8 @@ setup(void) { /* cookie jar */ soup_session_add_feature(s, - SOUP_SESSION_FEATURE(cookiejar_new(cookiefile, - FALSE))); + SOUP_SESSION_FEATURE(cookiejar_new(cookiefile, FALSE, + cookiepolicy_get(cookiepolicy)))); /* ssl */ g_object_set(G_OBJECT(s), "ssl-ca-file", cafile, NULL); @@ -1238,14 +1284,14 @@ static void getpagestat(Client *c) { const char *uri = geturi(c); + pagestat[0] = cookiepolicy_set(cookiepolicy_get(cookiepolicy)); if(strstr(uri, "https://") == uri) { - pagestat[0] = c->sslfailed ? 'U' : 'T'; + pagestat[1] = c->sslfailed ? 'U' : 'T'; } else { - pagestat[0] = '-'; + pagestat[1] = '-'; } - - pagestat[1] = usingproxy ? 'P' : '-'; - pagestat[2] = '\0'; + pagestat[2] = usingproxy ? 'P' : '-'; + pagestat[3] = '\0'; } @@ -1284,9 +1330,9 @@ updatewinid(Client *c) { static void usage(void) { die("usage: %s [-bBfFgGiIkKnNpPsSvx]" - " [-c cookiefile] [-e xid] [-r scriptfile]" - " [-t stylefile] [-u useragent] [-z zoomlevel]" - " [uri]\n", basename(argv0)); + " [-a cookiepolicy] [-c cookiefile] [-e xid]" + " [-r scriptfile] [-t stylefile] [-u useragent]" + " [-z zoomlevel] [uri]\n", basename(argv0)); } static void @@ -1319,6 +1365,9 @@ main(int argc, char *argv[]) { /* command line args */ ARGBEGIN { + case 'a': + g_strlcpy(cookiepolicy, EARGF(usage()), sizeof(cookiepolicy)); + break; case 'b': enablescrollbars = 0; break;