kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 2290d09d3bb2ca7f50f57512a45c3bd7a2163713
parent 697ff6d9809ce9778a5f727eb2fe24ddefc9863d
Author: Joris Vink <joris@coders.se>
Date:   Wed, 29 May 2013 13:33:32 +0200

Add dynamic handles, which can be used to partially match a URI and still call a cb handler. This is especially usefull when considering the handlers as a ruleset:

static /	serve_index
static /foo	serve_foo
dynamic /	serve_other

/ will be matched to serve_index, while /foo will be matched to serve_foo and /bar will be matched to serve_other for example.

Diffstat:
src/config.c | 1+
src/module.c | 20++++++++++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/config.c b/src/config.c @@ -49,6 +49,7 @@ static struct { { "bind", configure_bind }, { "load", configure_load }, { "static", configure_handler }, + { "dynamic", configure_handler }, { "domain", configure_domain }, { NULL, NULL }, }; diff --git a/src/module.c b/src/module.c @@ -125,6 +125,7 @@ kore_module_handler_new(char *path, char *domain, char *func, int type) void * kore_module_handler_find(char *domain, char *path) { + size_t len; struct kore_module_handle *hdlr; char uri[512], *p; @@ -132,10 +133,21 @@ kore_module_handler_find(char *domain, char *path) p = strchr(uri, '.'); TAILQ_FOREACH(hdlr, &handlers, list) { - if (hdlr->uri[0] != '.' && !strcmp(hdlr->uri, uri)) - return (hdlr->addr); - if (p != NULL && hdlr->uri[0] == '.' && !strcmp(hdlr->uri, p)) - return (hdlr->addr); + if (hdlr->type == HANDLER_TYPE_STATIC) { + if (hdlr->uri[0] != '.' && !strcmp(hdlr->uri, uri)) + return (hdlr->addr); + if (p != NULL && hdlr->uri[0] == '.' && + !strcmp(hdlr->uri, p)) + return (hdlr->addr); + } else { + len = strlen(hdlr->uri); + if (hdlr->uri[0] != '.' && + !strncmp(hdlr->uri, uri, len)) + return (hdlr->addr); + if (p != NULL && hdlr->uri[0] == '.' && + !strncmp(hdlr->uri, p, len)) + return (hdlr->addr); + } } return (NULL);