sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

surf-proxyconfig-20210503-7dcce9e.diff (2786B)


      1 From d0ba61a0e75cfc7b8e6d70d6f323d53295e628ad Mon Sep 17 00:00:00 2001
      2 From: weirdling <maddy@clappe.rs>
      3 Date: Mon, 3 May 2021 14:46:24 +0100
      4 Subject: [PATCH] Implement proxy settings
      5 
      6 ---
      7  config.def.h |  3 +++
      8  surf.c       | 32 ++++++++++++++++++++++++++++++++
      9  2 files changed, 35 insertions(+)
     10 
     11 diff --git a/config.def.h b/config.def.h
     12 index be168ab..46d164e 100644
     13 --- a/config.def.h
     14 +++ b/config.def.h
     15 @@ -43,6 +43,9 @@ static Parameter defconfig[ParameterLast] = {
     16  	[MediaManualPlay]     =       { { .i = 1 },     },
     17  	[Plugins]             =       { { .i = 1 },     },
     18  	[PreferredLanguages]  =       { { .v = (char *[]){ NULL } }, },
     19 +	[ProxyIgnoreHosts]    =       { { .v = (char *[]){ NULL } }, },
     20 +	[ProxyMode]           =       { { .i = SystemProxy }, },
     21 +	[ProxyUrl]            =       { { .v = (char *) NULL }, },
     22  	[RunInFullscreen]     =       { { .i = 0 },     },
     23  	[ScrollBars]          =       { { .i = 1 },     },
     24  	[ShowIndicators]      =       { { .i = 1 },     },
     25 diff --git a/surf.c b/surf.c
     26 index ac832ff..5c74560 100644
     27 --- a/surf.c
     28 +++ b/surf.c
     29 @@ -50,6 +50,12 @@ enum {
     30  	OnAny   = OnDoc | OnLink | OnImg | OnMedia | OnEdit | OnBar | OnSel,
     31  };
     32  
     33 +enum {
     34 +	CustomProxy = WEBKIT_NETWORK_PROXY_MODE_CUSTOM,
     35 +	SystemProxy = WEBKIT_NETWORK_PROXY_MODE_DEFAULT,
     36 +	NoProxy		= WEBKIT_NETWORK_PROXY_MODE_NO_PROXY,
     37 +};
     38 +
     39  typedef enum {
     40  	AcceleratedCanvas,
     41  	AccessMicrophone,
     42 @@ -73,6 +79,9 @@ typedef enum {
     43  	LoadImages,
     44  	MediaManualPlay,
     45  	Plugins,
     46 +	ProxyIgnoreHosts,
     47 +	ProxyMode,
     48 +	ProxyUrl,
     49  	PreferredLanguages,
     50  	RunInFullscreen,
     51  	ScrollBars,
     52 @@ -1111,6 +1120,7 @@ newview(Client *c, WebKitWebView *rv)
     53  	WebKitWebContext *context;
     54  	WebKitCookieManager *cookiemanager;
     55  	WebKitUserContentManager *contentmanager;
     56 +	WebKitNetworkProxySettings *proxysettings;
     57  
     58  	/* Webview */
     59  	if (rv) {
     60 @@ -1171,6 +1181,28 @@ newview(Client *c, WebKitWebView *rv)
     61  		webkit_web_context_set_tls_errors_policy(context,
     62  		    curconfig[StrictTLS].val.i ? WEBKIT_TLS_ERRORS_POLICY_FAIL :
     63  		    WEBKIT_TLS_ERRORS_POLICY_IGNORE);
     64 +		/* proxy */
     65 +		switch (curconfig[ProxyMode].val.i) {
     66 +			case CustomProxy:
     67 +				proxysettings = webkit_network_proxy_settings_new(
     68 +					curconfig[ProxyUrl].val.v,
     69 +					curconfig[ProxyIgnoreHosts].val.v);
     70 +				webkit_web_context_set_network_proxy_settings(context,
     71 +					CustomProxy,
     72 +					proxysettings);
     73 +				break;
     74 +			case NoProxy:
     75 +				webkit_web_context_set_network_proxy_settings(context,
     76 +					NoProxy,
     77 +					NULL);
     78 +				break;
     79 +			case SystemProxy:
     80 +			default:
     81 +				webkit_web_context_set_network_proxy_settings(context,
     82 +					SystemProxy,
     83 +					proxysettings);
     84 +				break;
     85 +		}
     86  		/* disk cache */
     87  		webkit_web_context_set_cache_model(context,
     88  		    curconfig[DiskCache].val.i ? WEBKIT_CACHE_MODEL_WEB_BROWSER :
     89 -- 
     90 2.31.1
     91