From 2290d09d3bb2ca7f50f57512a45c3bd7a2163713 Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Wed, 29 May 2013 13:33:32 +0200 Subject: [PATCH] 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. --- 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 index ae20602..a750df7 100644 --- 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 index d3eb983..09311ab 100644 --- 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);