Trivial fix to silence compilation errors on gcc 9.3.0:
src/config.c: In function ‘conf_ini_handler’:
src/config.c:154:23: error: ‘routing’ may be used uninitialized in this
function [-Werror=maybe-uninitialized]
154 | enum gmnisrv_routing routing;
| ^~~~~~~
src/config.c:197:18: error: ‘spec’ may be used uninitialized in this
function [-Werror=maybe-uninitialized]
197 | route->path = strdup(spec);
| ^~~~~~~~~~~~
Signed-off-by: William Casarin <jb55@jb55.com>
This takes the nginx approach to the "root" directive, which is simpler
to implement and more consistent with more complex routing behaviors
like regexp.
The path component of the URL is now simply appended to the root to form
the path to the file which should be served to the client.
All this does is parse the regexes out of the config file.
I've vendored libregexp from Bellard's quickjs project, because it's
reasonably small and self-contained, and POSIX regexes don't support
captures. We're eventually going to want captures for URL rewrites, so
this'll do for now.
With the following directory structure:
/srv/gmni:
baz/ foo/
/srv/gmni/baz:
a
/srv/gmni/foo:
bar/
/srv/gmni/foo/bar:
b
trying to access gemini://somesite/ with autoindex=on works,
but accessing /foo fails because it tries to stat /srv/gmni/foobar
instead of /srv/gmni/foo/bar. This commit fixes that by adding a trailing slash.
gcc 9.3.0 catches an off-by-one error with strncat in serve_autoindex
where it might not write a 0 byte:
In function ‘strncat’,
inlined from ‘serve_autoindex’ at src/serve.c:60:3:
/nix/store/...glibc-2.31-dev/include/bits/string_fortified.h:136:10:
error: ‘__builtin___strncat_chk’ specified bound 4097 equals destination size
[-Werror=stringop-overflow=]
Signed-off-by: William Casarin <jb55@jb55.com>