summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-02-14 17:18:39 +0200
committerSergey Poznyakoff <gray@gnu.org>2018-02-14 17:18:39 +0200
commit353e3210fefe141bbde7d117dbf07752261e37a8 (patch)
tree46711b2918b9ee2744691a6884fad07d4e10ef8c /src
parent5c691054bb7e8623b203fcbae31e468781597607 (diff)
downloadfileserv-353e3210fefe141bbde7d117dbf07752261e37a8.tar.gz
fileserv-353e3210fefe141bbde7d117dbf07752261e37a8.tar.bz2
Fix the sorting order of the mapping list
* src/config.c: New global keyword "index-css" * src/fileserv.c (urimap_add): Make sure the list is sorted by uri_len in descending order. (main): Fix the check for empty mapping list. * src/fileserv.h (index_css): New extern.
Diffstat (limited to 'src')
-rw-r--r--src/config.c19
-rw-r--r--src/fileserv.c17
-rw-r--r--src/fileserv.h1
3 files changed, 29 insertions, 8 deletions
diff --git a/src/config.c b/src/config.c
index 874bd29..1cb591d 100644
--- a/src/config.c
+++ b/src/config.c
@@ -322,6 +322,18 @@ set_index_template(size_t argc, char **argv, CONFIG *conf,
}
static int
+set_index_css(size_t argc, char **argv, CONFIG *conf,
+ char const *file, int line)
+{
+ if (argc != 2) {
+ error("%s:%d: expected exactly one argument", file, line);
+ return 1;
+ }
+ index_css = xstrdup(argv[1]);
+ return 0;
+}
+
+static int
set_dotfile(size_t argc, char **argv, CONFIG *conf,
char const *file, int line)
{
@@ -428,18 +440,19 @@ set_mapping(size_t argc, char **argv, CONFIG *conf,
-struct configkeyword {
+struct config_keyword {
int context;
char const *ident;
int (*setter)(size_t argc, char **argv, CONFIG *conf,
char const *file, int line);
};
-static struct configkeyword keywords[] = {
+static struct config_keyword keywords[] = {
{ CTXGLOB, "user", set_user },
{ CTXGLOB, "group", set_group },
{ CTXGLOB, "listen", set_listen },
{ CTXGLOB, "index-template", set_index_template },
+ { CTXGLOB, "index-css", set_index_css },
{ CTXGLOB, "access-file-name", set_dotfile },
{ CTXGLOB, "forwarded-header", set_forwarded_header },
{ CTXGLOB, "trusted-proxy", set_trusted_proxy },
@@ -460,7 +473,7 @@ static int
line_interpret(struct wordsplit const *ws,
CONFIG *conf, int ctx, char const *file, int line)
{
- struct configkeyword *kw;
+ struct config_keyword *kw;
for (kw = keywords; kw->ident; kw++) {
if ((kw->context & ctx)
&& strcmp(kw->ident, ws->ws_wordv[0]) == 0)
diff --git a/src/fileserv.c b/src/fileserv.c
index b81c9e7..b17bce5 100644
--- a/src/fileserv.c
+++ b/src/fileserv.c
@@ -192,7 +192,7 @@ urimap_find_dir(char const *host, char const *filename)
void
urimap_add(char *arg)
{
- struct urimap *map;
+ struct urimap *map, *cur;
char *copy, *p;
map = xmalloc(sizeof(*map) + strlen(arg) + 1);
@@ -225,6 +225,13 @@ urimap_add(char *arg)
map->dir[--map->dir_len] = 0;
}
+ /* Make sure the list is sorted by uri_len in descending order */
+ TAILQ_FOREACH(cur, &map_head, next) {
+ if (cur->uri_len < map->uri_len) {
+ TAILQ_INSERT_BEFORE(cur, map, next);
+ return;
+ }
+ }
TAILQ_INSERT_TAIL(&map_head, map, next);
}
@@ -641,14 +648,14 @@ main(int argc, char **argv)
runas(user, group);
- if (optind == argc) {
+ for (i = optind; i < argc; i++)
+ urimap_add(argv[i]);
+
+ if (TAILQ_EMPTY(&map_head)) {
error("no mappings");
exit(1);
}
- for (i = optind; i < argc; i++)
- urimap_add(argv[i]);
-
if (!foreground) {
int i;
diff --git a/src/fileserv.h b/src/fileserv.h
index 6c2ea4c..1eda56b 100644
--- a/src/fileserv.h
+++ b/src/fileserv.h
@@ -33,6 +33,7 @@ extern char *mime_types_file;
extern char *user;
extern char *group;
extern char *address;
+extern char *index_css;
extern int verbose;
void error(char const *fmt, ...);

Return to:

Send suggestions and report system problems to the System administrator.