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 634bb482d6be3c7559484ddf7545c30b5916afe6
parent ccd9e1046a8a4d757ac298559355905bee138d24
Author: Joris Vink <joris@coders.se>
Date:   Sat,  1 Feb 2014 17:47:58 +0100

Pass the http_request responsible for calling the validator.

Diffstat:
includes/kore.h | 15++++++++-------
modules/example/src/example.c | 14+++++++-------
src/auth.c | 4++--
src/http.c | 2+-
src/validator.c | 9+++++----
5 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/includes/kore.h b/includes/kore.h @@ -244,11 +244,11 @@ TAILQ_HEAD(kore_domain_h, kore_domain); #define KORE_VALIDATOR_TYPE_FUNCTION 2 struct kore_validator { - u_int8_t type; - char *name; - char *arg; - regex_t rctx; - int (*func)(char *); + u_int8_t type; + char *name; + char *arg; + regex_t rctx; + int (*func)(struct http_request *, char *); TAILQ_ENTRY(kore_validator) list; }; @@ -407,8 +407,9 @@ struct kore_module_handle *kore_module_handler_find(char *, char *); void kore_validator_init(void); void kore_validator_reload(void); int kore_validator_add(char *, u_int8_t, char *); -int kore_validator_run(char *, char *); -int kore_validator_check(struct kore_validator *, char *); +int kore_validator_run(struct http_request *, char *, char *); +int kore_validator_check(struct http_request *, + struct kore_validator *, char *); struct kore_validator *kore_validator_lookup(char *); void fatal(const char *, ...); diff --git a/modules/example/src/example.c b/modules/example/src/example.c @@ -34,8 +34,8 @@ int serve_private(struct http_request *); int serve_private_test(struct http_request *); void my_callback(void); -int v_example_func(char *); -int v_session_validate(char *); +int v_example_func(struct http_request *, char *); +int v_session_validate(struct http_request *, char *); void test_base64(u_int8_t *, u_int32_t, struct kore_buf *); char *b64tests[] = { @@ -222,17 +222,17 @@ test_base64(u_int8_t *src, u_int32_t slen, struct kore_buf *res) int serve_validator(struct http_request *req) { - if (kore_validator_run("v_example", "test")) + if (kore_validator_run(NULL, "v_example", "test")) kore_log(LOG_NOTICE, "v_example ok (expected)"); else kore_log(LOG_NOTICE, "v_example failed"); - if (kore_validator_run("v_regex", "/test/123")) + if (kore_validator_run(NULL, "v_regex", "/test/123")) kore_log(LOG_NOTICE, "regex #1 ok"); else kore_log(LOG_NOTICE, "regex #1 failed (expected)"); - if (kore_validator_run("v_regex", "/test/joris")) + if (kore_validator_run(NULL, "v_regex", "/test/joris")) kore_log(LOG_NOTICE, "regex #2 ok (expected)"); else kore_log(LOG_NOTICE, "regex #2 failed"); @@ -339,7 +339,7 @@ my_callback(void) } int -v_example_func(char *data) +v_example_func(struct http_request *req, char *data) { kore_log(LOG_NOTICE, "v_example_func called"); @@ -350,7 +350,7 @@ v_example_func(char *data) } int -v_session_validate(char *data) +v_session_validate(struct http_request *req, char *data) { kore_log(LOG_NOTICE, "v_session_validate: %s", data); diff --git a/src/auth.c b/src/auth.c @@ -121,7 +121,7 @@ kore_auth_cookie(struct http_request *req, struct kore_auth *auth) return (KORE_RESULT_ERROR); } - i = kore_validator_check(auth->validator, ++value); + i = kore_validator_check(req, auth->validator, ++value); kore_mem_free(cookie); return (i); @@ -136,7 +136,7 @@ kore_auth_header(struct http_request *req, struct kore_auth *auth) if (!http_request_header_get(req, auth->value, &header)) return (KORE_RESULT_ERROR); - r = kore_validator_check(auth->validator, header); + r = kore_validator_check(req, auth->validator, header); kore_mem_free(header); return (r); diff --git a/src/http.c b/src/http.c @@ -801,7 +801,7 @@ http_argument_add(struct http_request *req, char *name, len = strlen(value); } - if (!kore_validator_check(p->validator, value)) { + if (!kore_validator_check(req, p->validator, value)) { kore_log(LOG_NOTICE, "validator %s (%s) for %s failed", p->validator->name, p->name, req->path); diff --git a/src/validator.c b/src/validator.c @@ -63,7 +63,7 @@ kore_validator_add(char *name, u_int8_t type, char *arg) } int -kore_validator_run(char *name, char *data) +kore_validator_run(struct http_request *req, char *name, char *data) { struct kore_validator *val; @@ -71,14 +71,15 @@ kore_validator_run(char *name, char *data) if (strcmp(val->name, name)) continue; - return (kore_validator_check(val, data)); + return (kore_validator_check(req, val, data)); } return (KORE_RESULT_ERROR); } int -kore_validator_check(struct kore_validator *val, char *data) +kore_validator_check(struct http_request *req, struct kore_validator *val, + char *data) { int r; @@ -90,7 +91,7 @@ kore_validator_check(struct kore_validator *val, char *data) r = KORE_RESULT_ERROR; break; case KORE_VALIDATOR_TYPE_FUNCTION: - r = val->func(data); + r = val->func(req, data); break; default: r = KORE_RESULT_ERROR;