mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 12:39:01 -04:00
from now on configuration files must specify a domain for the handlers that follow. This allows for easy subdomain configuration.
example: domain joris.local static / serve_index domain .joris.local static / serve_another_index
This commit is contained in:
parent
53cbc1a21e
commit
807764614b
@ -8,5 +8,6 @@ load example/example.module
|
||||
|
||||
# Declare page handlers below.
|
||||
# handler path module_callback
|
||||
domain 10.211.55.3
|
||||
static /css/style.css betrippin_serve_style_css
|
||||
static / betrippin_serve_index
|
||||
|
@ -89,6 +89,7 @@ struct connection {
|
||||
|
||||
struct kore_module_handle {
|
||||
char *uri;
|
||||
char *domain;
|
||||
void *func;
|
||||
int type;
|
||||
|
||||
@ -121,8 +122,8 @@ long long kore_strtonum(const char *, long long, long long, int *);
|
||||
|
||||
void kore_module_load(char *);
|
||||
int kore_module_loaded(void);
|
||||
void *kore_module_handler_find(char *);
|
||||
int kore_module_handler_new(char *, char *, int);
|
||||
void *kore_module_handler_find(char *, char *);
|
||||
int kore_module_handler_new(char *, char *, char *, int);
|
||||
|
||||
void fatal(const char *, ...);
|
||||
void kore_log_internal(char *, int, const char *, ...);
|
||||
|
25
src/config.c
25
src/config.c
@ -40,6 +40,7 @@
|
||||
static int configure_bind(char **);
|
||||
static int configure_load(char **);
|
||||
static int configure_handler(char **);
|
||||
static int configure_domain(char **);
|
||||
|
||||
static struct {
|
||||
const char *name;
|
||||
@ -48,10 +49,12 @@ static struct {
|
||||
{ "bind", configure_bind },
|
||||
{ "load", configure_load },
|
||||
{ "static", configure_handler },
|
||||
{ "dynamic", configure_handler },
|
||||
{ "domain", configure_domain },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
static char *current_domain = NULL;
|
||||
|
||||
void
|
||||
kore_parse_config(const char *config_path)
|
||||
{
|
||||
@ -126,11 +129,29 @@ configure_load(char **argv)
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
||||
|
||||
static int
|
||||
configure_domain(char **argv)
|
||||
{
|
||||
if (argv[1] == NULL)
|
||||
return (KORE_RESULT_ERROR);
|
||||
|
||||
if (current_domain != NULL)
|
||||
free(current_domain);
|
||||
current_domain = kore_strdup(argv[1]);
|
||||
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
||||
|
||||
static int
|
||||
configure_handler(char **argv)
|
||||
{
|
||||
int type;
|
||||
|
||||
if (current_domain == NULL) {
|
||||
kore_log("missing domain for page handler");
|
||||
return (KORE_RESULT_ERROR);
|
||||
}
|
||||
|
||||
if (argv[1] == NULL || argv[2] == NULL)
|
||||
return (KORE_RESULT_ERROR);
|
||||
|
||||
@ -141,7 +162,7 @@ configure_handler(char **argv)
|
||||
else
|
||||
return (KORE_RESULT_ERROR);
|
||||
|
||||
if (!kore_module_handler_new(argv[1], argv[2], type)) {
|
||||
if (!kore_module_handler_new(argv[1], current_domain, argv[2], type)) {
|
||||
kore_log("cannot create handler for %s", argv[1]);
|
||||
return (KORE_RESULT_ERROR);
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ http_process(void)
|
||||
for (req = TAILQ_FIRST(&http_requests); req != NULL; req = next) {
|
||||
next = TAILQ_NEXT(req, list);
|
||||
|
||||
handler = kore_module_handler_find(req->path);
|
||||
handler = kore_module_handler_find(req->host, req->path);
|
||||
if (handler == NULL)
|
||||
r = http_generic_404(req);
|
||||
else
|
||||
|
20
src/module.c
20
src/module.c
@ -72,12 +72,14 @@ kore_module_loaded(void)
|
||||
}
|
||||
|
||||
int
|
||||
kore_module_handler_new(char *uri, char *func, int type)
|
||||
kore_module_handler_new(char *path, char *domain, char *func, int type)
|
||||
{
|
||||
void *addr;
|
||||
struct kore_module_handle *hdlr;
|
||||
char uri[512];
|
||||
|
||||
kore_log("kore_module_handler_new(%s, %s, %d)", uri, func, type);
|
||||
kore_log("kore_module_handler_new(%s, %s, %s, %d)", path,
|
||||
domain, func, type);
|
||||
|
||||
addr = dlsym(mod_handle, func);
|
||||
if (addr == NULL) {
|
||||
@ -85,22 +87,30 @@ kore_module_handler_new(char *uri, char *func, int type)
|
||||
return (KORE_RESULT_ERROR);
|
||||
}
|
||||
|
||||
snprintf(uri, sizeof(uri), "%s%s", domain, path);
|
||||
|
||||
hdlr = (struct kore_module_handle *)kore_malloc(sizeof(*hdlr));
|
||||
hdlr->uri = kore_strdup(uri);
|
||||
hdlr->func = addr;
|
||||
hdlr->type = type;
|
||||
hdlr->uri = kore_strdup(uri);
|
||||
TAILQ_INSERT_TAIL(&(handlers), hdlr, list);
|
||||
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
||||
|
||||
void *
|
||||
kore_module_handler_find(char *uri)
|
||||
kore_module_handler_find(char *domain, char *path)
|
||||
{
|
||||
struct kore_module_handle *hdlr;
|
||||
char uri[512], *p;
|
||||
|
||||
snprintf(uri, sizeof(uri), "%s%s", domain, path);
|
||||
p = strchr(uri, '.');
|
||||
|
||||
TAILQ_FOREACH(hdlr, &handlers, list) {
|
||||
if (!strcmp(hdlr->uri, uri))
|
||||
if (hdlr->uri[0] != '.' && !strcmp(hdlr->uri, uri))
|
||||
return (hdlr->func);
|
||||
if (hdlr->uri[0] == '.' && !strcmp(hdlr->uri, p))
|
||||
return (hdlr->func);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user