~sircmpwn/gmnisrv

32913c35cd5f36b00056d3e239c0e85f1f0ed000 — René Wagner 2 years ago ea360fa
implement handling of ROUTE_EXACT definitions

This patchset implements the handling of exact routes
as described in gmnisrvini(5).
3 files changed, 14 insertions(+), 1 deletions(-)

M include/config.h
M src/config.c
M src/serve.c
M include/config.h => include/config.h +1 -0
@@ 12,6 12,7 @@ struct gmnisrv_tls {
};

enum gmnisrv_routing {
	ROUTE_EXACT,
	ROUTE_PATH,
	ROUTE_REGEX,
};

M src/config.c => src/config.c +7 -1
@@ 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:

M src/serve.c => src/serve.c +6 -0
@@ 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) {