1
0
forked from aniani/gmnisrv

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 { enum gmnisrv_routing {
ROUTE_EXACT,
ROUTE_PATH, ROUTE_PATH,
ROUTE_REGEX, ROUTE_REGEX,
}; };

View File

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

View File

@ -337,6 +337,12 @@ route_match(struct gmnisrv_route *route, const char *path, char **revised)
free(*revised); free(*revised);
*revised = NULL; *revised = NULL;
switch (route->routing) { 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:; case ROUTE_PATH:;
size_t l = strlen(route->path); size_t l = strlen(route->path);
if (strncmp(path, route->path, l) != 0) { if (strncmp(path, route->path, l) != 0) {