From: Fredrik Tolf Date: Thu, 27 Feb 2014 08:50:35 +0000 (+0100) Subject: lib: Removed nested functions from all required parts of the code. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=091936b4cde21cdfd2d0f8650f9536e7ede19c50;hp=2a619a21d4af6cbc5033f987b2aa25ef2b749600;p=ashd.git lib: Removed nested functions from all required parts of the code. --- diff --git a/lib/cf.c b/lib/cf.c index bd4aba3..aae8485 100644 --- a/lib/cf.c +++ b/lib/cf.c @@ -355,26 +355,35 @@ static char **expandargs(struct stdchild *sd) return(ret); } -static int stdhandle(struct child *ch, struct hthead *req, int fd, void (*chinit)(void *), void *idata) +struct sidata { + struct stdchild *sd; + void (*sinit)(void *); + void *sdata; +}; + +static void stdinit(void *data) +{ + struct sidata *d = data; + int i; + + for(i = 0; d->sd->envp[i]; i += 2) + putenv(sprintf2("%s=%s", d->sd->envp[i], d->sd->envp[i + 1])); + if(d->sinit != NULL) + d->sinit(d->sdata); +} + +static int stdhandle(struct child *ch, struct hthead *req, int fd, void (*chinit)(void *), void *sdata) { struct stdchild *sd = ch->pdata; int serr; char **args; - - void stdinit(void *data) - { - int i; - - for(i = 0; sd->envp[i]; i += 2) - putenv(sprintf2("%s=%s", sd->envp[i], sd->envp[i + 1])); - if(chinit != NULL) - chinit(data); - } + struct sidata idat; if(sd->type == CH_SOCKET) { + idat = (struct sidata) {.sd = sd, .sinit = chinit, sdata = sdata}; if(sd->fd < 0) { args = expandargs(sd); - sd->fd = stdmkchild(args, stdinit, idata); + sd->fd = stdmkchild(args, stdinit, &idat); freeca(args); } if(sendreq2(sd->fd, req, fd, MSG_NOSIGNAL | MSG_DONTWAIT)) { @@ -383,7 +392,7 @@ static int stdhandle(struct child *ch, struct hthead *req, int fd, void (*chinit /* Assume that the child has crashed and restart it. */ close(sd->fd); args = expandargs(sd); - sd->fd = stdmkchild(args, stdinit, idata); + sd->fd = stdmkchild(args, stdinit, &idat); freeca(args); if(!sendreq2(sd->fd, req, fd, MSG_NOSIGNAL | MSG_DONTWAIT)) goto ok; @@ -406,7 +415,7 @@ static int stdhandle(struct child *ch, struct hthead *req, int fd, void (*chinit } } else if(sd->type == CH_FORK) { args = expandargs(sd); - if(stdforkserve(args, req, fd, chinit, idata) < 0) { + if(stdforkserve(args, req, fd, chinit, sdata) < 0) { freeca(args); return(-1); } diff --git a/lib/resp.c b/lib/resp.c index 25fb2cb..bae24bf 100644 --- a/lib/resp.c +++ b/lib/resp.c @@ -190,6 +190,22 @@ char *fmthttpdate(time_t time) return(sprintf3("%s, %i %s %i %02i:%02i:%02i GMT", days[(tm->tm_wday + 6) % 7], tm->tm_mday, months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour, tm->tm_min, tm->tm_sec)); } +static int gtoi(char *bstr, regmatch_t g) +{ + int i, n; + + for(i = g.rm_so, n = 0; i < g.rm_eo; i++) + n = (n * 10) + (bstr[i] - '0'); + return(n); +} + +static int gstrcmp(char *bstr, regmatch_t g, char *str) +{ + if(g.rm_eo - g.rm_so != strlen(str)) + return(1); + return(strncasecmp(bstr + g.rm_so, str, g.rm_eo - g.rm_so)); +} + time_t parsehttpdate(char *date) { static regex_t *spec = NULL; @@ -200,21 +216,6 @@ time_t parsehttpdate(char *date) struct tm tm; int tz; - int gtoi(regmatch_t g) - { - int i, n; - - for(i = g.rm_so, n = 0; i < g.rm_eo; i++) - n = (n * 10) + (date[i] - '0'); - return(n); - } - - int gstrcmp(regmatch_t g, char *str) { - if(g.rm_eo - g.rm_so != strlen(str)) - return(1); - return(strncasecmp(date + g.rm_so, str, g.rm_eo - g.rm_so)); - } - if(spec == NULL) { omalloc(spec); if(regcomp(spec, "^[A-Z]{3}, +([0-9]+) +([A-Z]{3}) +([0-9]+) +([0-9]{2}):([0-9]{2}):([0-9]{2}) +(([A-Z]+)|[+-]([0-9]{2})([0-9]{2}))$", REG_EXTENDED | REG_ICASE)) { @@ -225,15 +226,15 @@ time_t parsehttpdate(char *date) } if(regexec(spec, date, 11, g, 0)) return(0); - tm.tm_mday = gtoi(g[1]); - tm.tm_year = gtoi(g[3]) - 1900; - tm.tm_hour = gtoi(g[4]); - tm.tm_min = gtoi(g[5]); - tm.tm_sec = gtoi(g[6]); + tm.tm_mday = gtoi(date, g[1]); + tm.tm_year = gtoi(date, g[3]) - 1900; + tm.tm_hour = gtoi(date, g[4]); + tm.tm_min = gtoi(date, g[5]); + tm.tm_sec = gtoi(date, g[6]); tm.tm_mon = -1; for(i = 0; i < 12; i++) { - if(!gstrcmp(g[2], months[i])) { + if(!gstrcmp(date, g[2], months[i])) { tm.tm_mon = i; break; } @@ -242,12 +243,12 @@ time_t parsehttpdate(char *date) return(0); if(g[8].rm_so > 0) { - if(!gstrcmp(g[8], "GMT")) + if(!gstrcmp(date, g[8], "GMT")) tz = 0; else return(0); } else if((g[9].rm_so > 0) && (g[10].rm_so > 0)) { - tz = gtoi(g[9]) * 3600 + gtoi(g[10]) * 60; + tz = gtoi(date, g[9]) * 3600 + gtoi(date, g[10]) * 60; if(date[g[7].rm_so] == '-') tz = -tz; } else {