Use priority values instead of “forced” parameters
This makes parameter handling a bit easier and lets the user override parameters as he sees fit.
This commit is contained in:
parent
a0ef4ba41d
commit
a8bf206827
2 changed files with 49 additions and 46 deletions
|
@ -8,8 +8,13 @@ static char *cachedir = "~/.surf/cache/";
|
||||||
static char *cookiefile = "~/.surf/cookies.txt";
|
static char *cookiefile = "~/.surf/cookies.txt";
|
||||||
|
|
||||||
/* Webkit default features */
|
/* Webkit default features */
|
||||||
|
/* Highest priority value will be used.
|
||||||
|
* Default parameters are priority 0
|
||||||
|
* Per-uri parameters are priority 1
|
||||||
|
* Command parameters are priority 2
|
||||||
|
*/
|
||||||
static Parameter defconfig[ParameterLast] = {
|
static Parameter defconfig[ParameterLast] = {
|
||||||
/* parameter Arg value force? */
|
/* parameter Arg value priority */
|
||||||
[AcceleratedCanvas] = { { .i = 1 }, },
|
[AcceleratedCanvas] = { { .i = 1 }, },
|
||||||
[AccessMicrophone] = { { .i = 0 }, },
|
[AccessMicrophone] = { { .i = 0 }, },
|
||||||
[AccessWebcam] = { { .i = 0 }, },
|
[AccessWebcam] = { { .i = 0 }, },
|
||||||
|
|
86
surf.c
86
surf.c
|
@ -91,7 +91,7 @@ typedef union {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Arg val;
|
Arg val;
|
||||||
int force;
|
int prio;
|
||||||
} Parameter;
|
} Parameter;
|
||||||
|
|
||||||
typedef struct Client {
|
typedef struct Client {
|
||||||
|
@ -372,19 +372,18 @@ setup(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < LENGTH(uriparams); ++i) {
|
for (i = 0; i < LENGTH(uriparams); ++i) {
|
||||||
if (!regcomp(&(uriparams[i].re), uriparams[i].uri,
|
if (regcomp(&(uriparams[i].re), uriparams[i].uri,
|
||||||
REG_EXTENDED)) {
|
REG_EXTENDED)) {
|
||||||
/* copy default parameters if they are not already set
|
|
||||||
* or if they are forced */
|
|
||||||
for (j = 0; j < ParameterLast; ++j) {
|
|
||||||
if (!uriparams[i].config[j].force ||
|
|
||||||
defconfig[j].force)
|
|
||||||
uriparams[i].config[j] = defconfig[j];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Could not compile regex: %s\n",
|
fprintf(stderr, "Could not compile regex: %s\n",
|
||||||
uriparams[i].uri);
|
uriparams[i].uri);
|
||||||
uriparams[i].uri = NULL;
|
uriparams[i].uri = NULL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* copy default parameters with higher priority */
|
||||||
|
for (j = 0; j < ParameterLast; ++j) {
|
||||||
|
if (defconfig[j].prio >= uriparams[i].config[j].prio)
|
||||||
|
uriparams[i].config[j] = defconfig[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -693,19 +692,18 @@ seturiparameters(Client *c, const char *uri, ParamName *params)
|
||||||
case Certificate:
|
case Certificate:
|
||||||
case CookiePolicies:
|
case CookiePolicies:
|
||||||
case Style:
|
case Style:
|
||||||
config = defconfig[p].force ? defconfig :
|
config = (newconfig[p].prio > defconfig[p].prio) ?
|
||||||
newconfig[p].force ? newconfig :
|
newconfig : defconfig;
|
||||||
defconfig;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (defconfig[p].force)
|
if (newconfig[p].prio > defconfig[p].prio)
|
||||||
|
config = newconfig;
|
||||||
|
else if (curconfig[p].prio > defconfig[p].prio)
|
||||||
|
config = defconfig;
|
||||||
|
else
|
||||||
continue;
|
continue;
|
||||||
config = newconfig[p].force ? newconfig :
|
|
||||||
curconfig[p].force ? defconfig :
|
|
||||||
NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config)
|
|
||||||
setparameter(c, 0, p, &config[p].val);
|
setparameter(c, 0, p, &config[p].val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1914,15 +1912,15 @@ main(int argc, char *argv[])
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'a':
|
case 'a':
|
||||||
defconfig[CookiePolicies].val.v = EARGF(usage());
|
defconfig[CookiePolicies].val.v = EARGF(usage());
|
||||||
defconfig[CookiePolicies].force = 1;
|
defconfig[CookiePolicies].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
defconfig[ScrollBars].val.i = 0;
|
defconfig[ScrollBars].val.i = 0;
|
||||||
defconfig[ScrollBars].force = 1;
|
defconfig[ScrollBars].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B':
|
||||||
defconfig[ScrollBars].val.i = 1;
|
defconfig[ScrollBars].val.i = 1;
|
||||||
defconfig[ScrollBars].force = 1;
|
defconfig[ScrollBars].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
cookiefile = EARGF(usage());
|
cookiefile = EARGF(usage());
|
||||||
|
@ -1932,89 +1930,89 @@ main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
defconfig[DiskCache].val.i = 0;
|
defconfig[DiskCache].val.i = 0;
|
||||||
defconfig[DiskCache].force = 1;
|
defconfig[DiskCache].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
defconfig[DiskCache].val.i = 1;
|
defconfig[DiskCache].val.i = 1;
|
||||||
defconfig[DiskCache].force = 1;
|
defconfig[DiskCache].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
embed = strtol(EARGF(usage()), NULL, 0);
|
embed = strtol(EARGF(usage()), NULL, 0);
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
defconfig[RunInFullscreen].val.i = 0;
|
defconfig[RunInFullscreen].val.i = 0;
|
||||||
defconfig[RunInFullscreen].force = 1;
|
defconfig[RunInFullscreen].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
defconfig[RunInFullscreen].val.i = 1;
|
defconfig[RunInFullscreen].val.i = 1;
|
||||||
defconfig[RunInFullscreen].force = 1;
|
defconfig[RunInFullscreen].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
defconfig[Geolocation].val.i = 0;
|
defconfig[Geolocation].val.i = 0;
|
||||||
defconfig[Geolocation].force = 1;
|
defconfig[Geolocation].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'G':
|
case 'G':
|
||||||
defconfig[Geolocation].val.i = 1;
|
defconfig[Geolocation].val.i = 1;
|
||||||
defconfig[Geolocation].force = 1;
|
defconfig[Geolocation].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
defconfig[LoadImages].val.i = 0;
|
defconfig[LoadImages].val.i = 0;
|
||||||
defconfig[LoadImages].force = 1;
|
defconfig[LoadImages].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'I':
|
case 'I':
|
||||||
defconfig[LoadImages].val.i = 1;
|
defconfig[LoadImages].val.i = 1;
|
||||||
defconfig[LoadImages].force = 1;
|
defconfig[LoadImages].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
defconfig[KioskMode].val.i = 0;
|
defconfig[KioskMode].val.i = 0;
|
||||||
defconfig[KioskMode].force = 1;
|
defconfig[KioskMode].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'K':
|
case 'K':
|
||||||
defconfig[KioskMode].val.i = 1;
|
defconfig[KioskMode].val.i = 1;
|
||||||
defconfig[KioskMode].force = 1;
|
defconfig[KioskMode].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
defconfig[Style].val.i = 0;
|
defconfig[Style].val.i = 0;
|
||||||
defconfig[Style].force = 1;
|
defconfig[Style].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
defconfig[Style].val.i = 1;
|
defconfig[Style].val.i = 1;
|
||||||
defconfig[Style].force = 1;
|
defconfig[Style].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
defconfig[Inspector].val.i = 0;
|
defconfig[Inspector].val.i = 0;
|
||||||
defconfig[Inspector].force = 1;
|
defconfig[Inspector].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'N':
|
case 'N':
|
||||||
defconfig[Inspector].val.i = 1;
|
defconfig[Inspector].val.i = 1;
|
||||||
defconfig[Inspector].force = 1;
|
defconfig[Inspector].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
defconfig[Plugins].val.i = 0;
|
defconfig[Plugins].val.i = 0;
|
||||||
defconfig[Plugins].force = 1;
|
defconfig[Plugins].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
defconfig[Plugins].val.i = 1;
|
defconfig[Plugins].val.i = 1;
|
||||||
defconfig[Plugins].force = 1;
|
defconfig[Plugins].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
scriptfile = EARGF(usage());
|
scriptfile = EARGF(usage());
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
defconfig[JavaScript].val.i = 0;
|
defconfig[JavaScript].val.i = 0;
|
||||||
defconfig[JavaScript].force = 1;
|
defconfig[JavaScript].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
defconfig[JavaScript].val.i = 1;
|
defconfig[JavaScript].val.i = 1;
|
||||||
defconfig[JavaScript].force = 1;
|
defconfig[JavaScript].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
defconfig[StrictTLS].val.i = 0;
|
defconfig[StrictTLS].val.i = 0;
|
||||||
defconfig[StrictTLS].force = 1;
|
defconfig[StrictTLS].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
defconfig[StrictTLS].val.i = 1;
|
defconfig[StrictTLS].val.i = 1;
|
||||||
defconfig[StrictTLS].force = 1;
|
defconfig[StrictTLS].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
fulluseragent = EARGF(usage());
|
fulluseragent = EARGF(usage());
|
||||||
|
@ -2026,15 +2024,15 @@ main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
defconfig[Certificate].val.i = 0;
|
defconfig[Certificate].val.i = 0;
|
||||||
defconfig[Certificate].force = 1;
|
defconfig[Certificate].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'X':
|
case 'X':
|
||||||
defconfig[Certificate].val.i = 1;
|
defconfig[Certificate].val.i = 1;
|
||||||
defconfig[Certificate].force = 1;
|
defconfig[Certificate].prio = 2;
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
defconfig[ZoomLevel].val.f = strtof(EARGF(usage()), NULL);
|
defconfig[ZoomLevel].val.f = strtof(EARGF(usage()), NULL);
|
||||||
defconfig[ZoomLevel].force = 1;
|
defconfig[ZoomLevel].prio = 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
|
|
Loading…
Reference in a new issue