Dolda2000 GitWeb
/
ashd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bumped version numbers.
[ashd.git]
/
src
/
patplex.c
diff --git
a/src/patplex.c
b/src/patplex.c
index
3f22d73
..
b03b626
100644
(file)
--- a/
src/patplex.c
+++ b/
src/patplex.c
@@
-24,6
+24,7
@@
#include <errno.h>
#include <ctype.h>
#include <regex.h>
#include <errno.h>
#include <ctype.h>
#include <regex.h>
+#include <sys/wait.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
@@
-56,8
+57,14
@@
struct rule {
regex_t *pattern;
};
regex_t *pattern;
};
+struct headmod {
+ struct headmod *next;
+ char *name, *value;
+};
+
struct pattern {
struct pattern *next;
struct pattern {
struct pattern *next;
+ struct headmod *headers;
char *childnm;
struct rule **rules;
char *restpat;
char *childnm;
struct rule **rules;
char *restpat;
@@
-69,6
+76,7
@@
static volatile int reload = 0;
static void freepattern(struct pattern *pat)
{
struct rule **rule;
static void freepattern(struct pattern *pat)
{
struct rule **rule;
+ struct headmod *head;
for(rule = pat->rules; *rule; rule++) {
if((*rule)->header != NULL)
for(rule = pat->rules; *rule; rule++) {
if((*rule)->header != NULL)
@@
-79,6
+87,12
@@
static void freepattern(struct pattern *pat)
}
free(*rule);
}
}
free(*rule);
}
+ while((head = pat->headers) != NULL) {
+ pat->headers = head->next;
+ free(head->name);
+ free(head->value);
+ free(head);
+ }
if(pat->childnm != NULL)
free(pat->childnm);
free(pat);
if(pat->childnm != NULL)
free(pat->childnm);
free(pat);
@@
-153,6
+167,7
@@
static struct pattern *parsepattern(struct cfstate *s)
struct pattern *pat;
int sl;
struct rule *rule;
struct pattern *pat;
int sl;
struct rule *rule;
+ struct headmod *head;
regex_t *regex;
int rxfl;
regex_t *regex;
int rxfl;
@@
-234,6
+249,16
@@
static struct pattern *parsepattern(struct cfstate *s)
if(pat->restpat != NULL)
free(pat->restpat);
pat->restpat = sstrdup(s->argv[1]);
if(pat->restpat != NULL)
free(pat->restpat);
pat->restpat = sstrdup(s->argv[1]);
+ } else if(!strcmp(s->argv[0], "set")) {
+ if(s->argc < 3) {
+ flog(LOG_WARNING, "%s:%i: missing header name or pattern for `set' directive", s->file, s->lno);
+ continue;
+ }
+ omalloc(head);
+ head->name = sstrdup(s->argv[1]);
+ head->value = sstrdup(s->argv[2]);
+ head->next = pat->headers;
+ pat->headers = head;
} else if(!strcmp(s->argv[0], "end") || !strcmp(s->argv[0], "eof")) {
break;
} else {
} else if(!strcmp(s->argv[0], "end") || !strcmp(s->argv[0], "eof")) {
break;
} else {
@@
-332,7
+357,7
@@
static void exprestpat(struct hthead *req, struct pattern *pat, char **mstr)
buffree(buf);
}
buffree(buf);
}
-static
char
*findmatch(struct config *cf, struct hthead *req, int trydefault)
+static
struct pattern
*findmatch(struct config *cf, struct hthead *req, int trydefault)
{
int i, o;
struct pattern *pat;
{
int i, o;
struct pattern *pat;
@@
-395,7
+420,7
@@
static char *findmatch(struct config *cf, struct hthead *req, int trydefault)
}
if(mstr)
freeca(mstr);
}
if(mstr)
freeca(mstr);
- return(pat
->childnm
);
+ return(pat);
}
if(mstr) {
freeca(mstr);
}
if(mstr) {
freeca(mstr);
@@
-407,63
+432,68
@@
static char *findmatch(struct config *cf, struct hthead *req, int trydefault)
static void serve(struct hthead *req, int fd)
{
static void serve(struct hthead *req, int fd)
{
- char *chnm;
+ struct pattern *pat;
+ struct headmod *head;
struct child *ch;
struct child *ch;
-
chnm
= NULL;
- if(
chnm
== NULL)
-
chnm
= findmatch(lconfig, req, 0);
- if(
chnm
== NULL)
-
chnm
= findmatch(lconfig, req, 1);
+
pat
= NULL;
+ if(
pat
== NULL)
+
pat
= findmatch(lconfig, req, 0);
+ if(
pat
== NULL)
+
pat
= findmatch(lconfig, req, 1);
if(gconfig != NULL) {
if(gconfig != NULL) {
- if(
chnm
== NULL)
-
chnm
= findmatch(gconfig, req, 0);
- if(
chnm
== NULL)
-
chnm
= findmatch(gconfig, req, 1);
+ if(
pat
== NULL)
+
pat
= findmatch(gconfig, req, 0);
+ if(
pat
== NULL)
+
pat
= findmatch(gconfig, req, 1);
}
}
- if(
chnm
== NULL) {
+ if(
pat
== NULL) {
simpleerror(fd, 404, "Not Found", "The requested resource could not be found on this server.");
return;
}
ch = NULL;
if(ch == NULL)
simpleerror(fd, 404, "Not Found", "The requested resource could not be found on this server.");
return;
}
ch = NULL;
if(ch == NULL)
- ch = getchild(lconfig,
ch
nm);
+ ch = getchild(lconfig,
pat->child
nm);
if(gconfig != NULL) {
if(ch == NULL)
if(gconfig != NULL) {
if(ch == NULL)
- ch = getchild(gconfig,
ch
nm);
+ ch = getchild(gconfig,
pat->child
nm);
}
if(ch == NULL) {
}
if(ch == NULL) {
- flog(LOG_ERR, "child %s requested, but was not declared",
ch
nm);
- simpleerror(fd, 500, "Configuration Error", "The server is erroneously configured. Handler %s was requested, but not declared.",
ch
nm);
+ flog(LOG_ERR, "child %s requested, but was not declared",
pat->child
nm);
+ simpleerror(fd, 500, "Configuration Error", "The server is erroneously configured. Handler %s was requested, but not declared.",
pat->child
nm);
return;
}
return;
}
- if(childhandle(ch, req, fd))
+ for(head = pat->headers; head != NULL; head = head->next) {
+ headrmheader(req, head->name);
+ headappheader(req, head->name, head->value);
+ }
+ if(childhandle(ch, req, fd, NULL, NULL))
simpleerror(fd, 500, "Server Error", "The request handler crashed.");
}
static void reloadconf(char *nm)
{
struct config *cf;
simpleerror(fd, 500, "Server Error", "The request handler crashed.");
}
static void reloadconf(char *nm)
{
struct config *cf;
- struct child *ch1, *ch2;
if((cf = readconfig(nm)) == NULL) {
flog(LOG_WARNING, "could not reload configuration file `%s'", nm);
return;
}
if((cf = readconfig(nm)) == NULL) {
flog(LOG_WARNING, "could not reload configuration file `%s'", nm);
return;
}
- for(ch1 = cf->children; ch1 != NULL; ch1 = ch1->next) {
- for(ch2 = lconfig->children; ch2 != NULL; ch2 = ch2->next) {
- if(!strcmp(ch1->name, ch2->name)) {
- ch1->fd = ch2->fd;
- ch2->fd = -1;
- break;
- }
- }
- }
+ mergechildren(cf->children, lconfig->children);
freeconfig(lconfig);
lconfig = cf;
}
freeconfig(lconfig);
lconfig = cf;
}
+static void chldhandler(int sig)
+{
+ pid_t pid;
+
+ do {
+ pid = waitpid(-1, NULL, WNOHANG);
+ } while(pid > 0);
+}
+
static void sighandler(int sig)
{
if(sig == SIGHUP)
static void sighandler(int sig)
{
if(sig == SIGHUP)
@@
-511,14
+541,17
@@
int main(int argc, char **argv)
flog(LOG_ERR, "could not read `%s'", argv[optind]);
exit(1);
}
flog(LOG_ERR, "could not read `%s'", argv[optind]);
exit(1);
}
- signal(SIGCHLD,
SIG_IGN
);
+ signal(SIGCHLD,
chldhandler
);
signal(SIGHUP, sighandler);
signal(SIGHUP, sighandler);
+ signal(SIGPIPE, sighandler);
while(1) {
if(reload) {
reloadconf(argv[optind]);
reload = 0;
}
if((fd = recvreq(0, &req)) < 0) {
while(1) {
if(reload) {
reloadconf(argv[optind]);
reload = 0;
}
if((fd = recvreq(0, &req)) < 0) {
+ if(errno == EINTR)
+ continue;
if(errno != 0)
flog(LOG_ERR, "recvreq: %s", strerror(errno));
break;
if(errno != 0)
flog(LOG_ERR, "recvreq: %s", strerror(errno));
break;