From 7e8a9537949f298eef026f6b97b8c349a9b56ea0 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 29 Oct 2020 22:47:56 -0400 Subject: 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. --- src/config.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/config.c') 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 #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; -- cgit v1.2.3