forked from mirrors/kore
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.
This commit is contained in:
parent
697ff6d980
commit
2290d09d3b
|
@ -49,6 +49,7 @@ static struct {
|
|||
{ "bind", configure_bind },
|
||||
{ "load", configure_load },
|
||||
{ "static", configure_handler },
|
||||
{ "dynamic", configure_handler },
|
||||
{ "domain", configure_domain },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
|
20
src/module.c
20
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);
|
||||
|
|
Loading…
Reference in New Issue