forked from aniani/gmnisrv
1
0
Fork 0

implement handling of ROUTE_EXACT definitions

This patchset implements the handling of exact routes
as described in gmnisrvini(5).
This commit is contained in:
René Wagner 2021-01-27 20:57:18 +01:00 committed by Drew DeVault
parent ea360fa4c1
commit 32913c35cd
3 changed files with 14 additions and 1 deletions

View File

@ -12,6 +12,7 @@ struct gmnisrv_tls {
};
enum gmnisrv_routing {
ROUTE_EXACT,
ROUTE_PATH,
ROUTE_REGEX,
};

View File

@ -152,12 +152,16 @@ conf_ini_handler(void *user, const char *section,
const char *spec;
char hostname[1024 + 1];
enum gmnisrv_routing routing;
size_t hostln = strcspn(section, ":~");
size_t hostln = strcspn(section, "=:~");
switch (section[hostln]) {
case '\0':
routing = ROUTE_PATH;
spec = "/";
break;
case '=':
routing = ROUTE_EXACT;
spec = &section[hostln + 1];
break;
case ':':
routing = ROUTE_PATH;
spec = &section[hostln + 1];
@ -196,6 +200,7 @@ conf_ini_handler(void *user, const char *section,
switch (route->routing) {
case ROUTE_PATH:
case ROUTE_EXACT:
route->path = strdup(spec);
break;
case ROUTE_REGEX:
@ -315,6 +320,7 @@ config_finish(struct gmnisrv_config *conf)
while (route) {
switch (route->routing) {
case ROUTE_PATH:
case ROUTE_EXACT:
free(route->path);
break;
case ROUTE_REGEX:

View File

@ -337,6 +337,12 @@ route_match(struct gmnisrv_route *route, const char *path, char **revised)
free(*revised);
*revised = NULL;
switch (route->routing) {
case ROUTE_EXACT:;
if (strlen(route->path)==strlen(path) && strncmp(path, route->path, strlen(route->path)) == 0 ) {
*revised = strdup(path);
return true;
}
return false;
case ROUTE_PATH:;
size_t l = strlen(route->path);
if (strncmp(path, route->path, l) != 0) {