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:
parent
ea360fa4c1
commit
32913c35cd
@ -12,6 +12,7 @@ struct gmnisrv_tls {
|
||||
};
|
||||
|
||||
enum gmnisrv_routing {
|
||||
ROUTE_EXACT,
|
||||
ROUTE_PATH,
|
||||
ROUTE_REGEX,
|
||||
};
|
||||
|
@ -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 = §ion[hostln + 1];
|
||||
break;
|
||||
case ':':
|
||||
routing = ROUTE_PATH;
|
||||
spec = §ion[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:
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user