aboutsummaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-02-10 16:37:08 +0000
committerOmar Polo <op@omarpolo.com>2021-02-10 16:37:08 +0000
commit49b73ba1ab4be9993532bdecaf14e74f45eca676 (patch)
treec79c26c3127f6de5edf1289ea7f838c25207c76c /server.c
parent2898780aeac7ff0a456b6f380af2bc3a25a49d3b (diff)
fix "first location" bug
reported by devel at datenbrei dot de. The first location would overwrite the default value for a server, triggering the "`foo' rule specified more than once" error. This also needed a small tweak on how we match locations to avoid breaking other tests.
Diffstat (limited to 'server.c')
-rw-r--r--server.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/server.c b/server.c
index 1dc0d91..8520739 100644
--- a/server.c
+++ b/server.c
@@ -43,6 +43,8 @@ struct server_events {
int connected_clients;
+static inline int matches(const char*, const char*);
+
static inline void reschedule_read(int, struct client*, statefn);
static inline void reschedule_write(int, struct client*, statefn);
@@ -72,6 +74,14 @@ static void close_conn(int, short, void*);
static void do_accept(int, short, void*);
static void handle_sighup(int, short, void*);
+static inline int
+matches(const char *pattern, const char *path)
+{
+ if (*path == '/')
+ path++;
+ return !fnmatch(pattern, path, 0);
+}
+
static inline void
reschedule_read(int fd, struct client *c, statefn fn)
{
@@ -94,7 +104,7 @@ vhost_lang(struct vhost *v, const char *path)
for (loc = &v->locations[1]; loc->match != NULL; ++loc) {
if (loc->lang != NULL) {
- if (!fnmatch(loc->match, path, 0))
+ if (matches(loc->match, path))
return loc->lang;
}
}
@@ -113,7 +123,7 @@ vhost_default_mime(struct vhost *v, const char *path)
for (loc = &v->locations[1]; loc->match != NULL; ++loc) {
if (loc->default_mime != NULL) {
- if (!fnmatch(loc->match, path, 0))
+ if (matches(loc->match, path))
return loc->default_mime;
}
}
@@ -134,7 +144,7 @@ vhost_index(struct vhost *v, const char *path)
for (loc = &v->locations[1]; loc->match != NULL; ++loc) {
if (loc->index != NULL) {
- if (!fnmatch(loc->match, path, 0))
+ if (matches(loc->match, path))
return loc->index;
}
}
@@ -154,7 +164,7 @@ vhost_auto_index(struct vhost *v, const char *path)
for (loc = &v->locations[1]; loc->match != NULL; ++loc) {
if (loc->auto_index != 0) {
- if (!fnmatch(loc->match, path, 0))
+ if (matches(loc->match, path))
return loc->auto_index == 1;
}
}
@@ -172,7 +182,7 @@ vhost_block_return(struct vhost *v, const char *path, int *code, const char **fm
for (loc = &v->locations[1]; loc->match != NULL; ++loc) {
if (loc->block_code != 0) {
- if (!fnmatch(loc->match, path, 0)) {
+ if (matches(loc->match, path)) {
*code = loc->block_code;
*fmt = loc->block_fmt;
return 1;
@@ -195,7 +205,7 @@ vhost_strip(struct vhost *v, const char *path)
for (loc = &v->locations[1]; loc->match != NULL; ++loc) {
if (loc->strip != 0) {
- if (!fnmatch(loc->match, path, 0))
+ if (matches(loc->match, path))
return loc->strip;
}
}
@@ -213,7 +223,7 @@ vhost_require_ca(struct vhost *v, const char *path)
for (loc = &v->locations[1]; loc->match != NULL; ++loc) {
if (loc->reqca != NULL) {
- if (!fnmatch(loc->match, path, 0))
+ if (matches(loc->match, path))
return loc->reqca;
}
}