X-Git-Url: https://git.distorted.org.uk/~mdw/userv-utils/blobdiff_plain/92fc834ef77fe48782f2fb1b0f5c52a22127374c..0cd9d59dfadf1a9abbef4428ff4f90bf32c01bd4:/www-cgi/ucgicommon.c diff --git a/www-cgi/ucgicommon.c b/www-cgi/ucgicommon.c index 4bba186..2fa6260 100644 --- a/www-cgi/ucgicommon.c +++ b/www-cgi/ucgicommon.c @@ -18,6 +18,7 @@ * $Id$ */ +#include #include #include #include @@ -36,18 +37,20 @@ static void outerror(void) { } void syserror(const char *m) { - if (printf("Content-Type: text/plain\n\n" + if (printf("Content-Type: text/plain\n" + "Status: 500\n\n" "ucgi: system call error:\n" "%s: %s\n", m,strerror(errno))==EOF || fflush(stdout)) outerror(); exit(0); } -void error(const char *m) { - if (printf("Content-Type: text/plain\n\n" +void error(const char *m, int st) { + if (printf("Content-Type: text/plain\n" + "Status: %d\n\n" "ucgi: error:\n" "%s\n", - m)==EOF || fflush(stdout)) outerror(); + st, m)==EOF || fflush(stdout)) outerror(); exit(0); } @@ -103,7 +106,7 @@ opened: l= strlen(buf); if (buf[l - 1] == '\n') buf[--l]= 0; if (l + 1 == sizeof(buf)) - error("line too long in environment filter file"); + error("line too long in environment filter file", 500); p= buf; q= p + l; while (isspace((unsigned char)*p)) p++; while (q > p && isspace((unsigned char)q[-1])) q--; @@ -126,16 +129,28 @@ opened: static int envvar_match(unsigned flags, const char *en, const char *const *patv, + const char *const *defaults, const char **ev) { const char *const *patp; const char *q, *pat; int acceptp; + int rc; + if (!patv) { patv= defaults; defaults= 0; } for (patp= patv; (pat= *patp); patp++) { q= en; acceptp= 1; if (*pat == '!' && (flags & FILTF_WILDCARD)) { acceptp= 0; pat++; } + else if (*pat == '?') { + if (strcmp(pat + 1, "DEFAULTS") == 0) { + assert(defaults); + rc= envvar_match(flags, en, defaults, 0, ev); + if (rc) return rc; + } else + error("unknown pattern directive", 500); + continue; + } for (;;) { if (!*pat) { @@ -174,6 +189,7 @@ match: void filter_environment(unsigned flags, const char *prefix_in, const char *const *patv, + const char *const *defaults, void (*foundone)(const char *fulln, const char *en, const char *ev, void *p), @@ -191,10 +207,10 @@ void filter_environment(unsigned flags, const char *prefix_in, D( if (debugmode) printf(";; doesn't match prefix\n"); ) continue; } - if (envvar_match(flags, en + pn, patv, &ev) > 0) { + if (envvar_match(flags, en + pn, patv, defaults, &ev) > 0) { n= strcspn(en, "="); if (n >= sizeof(enbuf)) - error("environment variable name too long"); + error("environment variable name too long", 500); memcpy(enbuf, en, n); enbuf[n]= 0; D( if (debugmode)