diff options
| author | Drew DeVault <sir@cmpwn.com> | 2020-10-29 22:47:56 -0400 |
|---|---|---|
| committer | Drew DeVault <sir@cmpwn.com> | 2020-10-29 22:47:56 -0400 |
| commit | 7e8a9537949f298eef026f6b97b8c349a9b56ea0 (patch) | |
| tree | 8eec16fd2ac48918f515cf069788eaec4202eadb /src/config.c | |
| parent | a26573251bf84d43dc32a6253c7ca7f6dcd36053 (diff) | |
| download | gmnisrv-7e8a9537949f298eef026f6b97b8c349a9b56ea0.tar.gz gmnisrv-7e8a9537949f298eef026f6b97b8c349a9b56ea0.tar.xz gmnisrv-7e8a9537949f298eef026f6b97b8c349a9b56ea0.zip | |
Initial pass on regex routing support
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.
Diffstat (limited to 'src/config.c')
| -rw-r--r-- | src/config.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/config.c b/src/config.c index ad2a8ac..ec767da 100644 --- a/src/config.c +++ b/src/config.c @@ -7,6 +7,7 @@ #include <strings.h> #include "config.h" #include "ini.h" +#include "regex.h" struct gmnisrv_host * gmnisrv_config_get_host(struct gmnisrv_config *conf, const char *hostname) @@ -179,6 +180,8 @@ conf_ini_handler(void *user, const char *section, conf->hosts = host; } + int bytecode_len; + char error_msg[64]; struct gmnisrv_route *route = gmnisrv_host_get_route(host, routing, spec); if (!route) { @@ -194,7 +197,15 @@ conf_ini_handler(void *user, const char *section, route->path = strdup(spec); break; case ROUTE_REGEX: - assert(0); // TODO + route->regex = lre_compile(&bytecode_len, + error_msg, sizeof(error_msg), + spec, strlen(spec), 0, NULL); + if (!route->regex) { + fprintf(stderr, "Error compiling regex '%s': %s\n", + spec, error_msg); + return 0; + } + break; } } @@ -299,7 +310,8 @@ config_finish(struct gmnisrv_config *conf) free(route->path); break; case ROUTE_REGEX: - assert(0); // TODO + free(route->regex); + break; } struct gmnisrv_route *rnext = route->next; |
