kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit f6cd16c567cca9ce22169f44d500f58677d4d1a0
parent 73757a29d596f116a08792d0eb2d3d2afffcb195
Author: Joris Vink <joris@coders.se>
Date:   Fri, 15 Nov 2019 08:11:02 +0100

Replace static/dynamic with a single option: route

Kore will automatically detect if a route is a dynamic or static one
so there is no need for the configuration options to differ anymore.

Diffstat:
examples/async-curl/conf/async-curl.conf | 4++--
examples/cookies/conf/cookies.conf | 6+++---
examples/cpp/conf/cpp.conf | 2+-
examples/generic/conf/generic.conf | 20++++++++++----------
examples/headers/conf/headers.conf | 2+-
examples/integers/conf/integers.conf | 2+-
examples/json/conf/json.conf | 2+-
examples/json_yajl/conf/json_yajl.conf | 2+-
examples/jsonrpc/conf/jsonrpc.conf | 4++--
examples/memtag/conf/memtag.conf | 2+-
examples/messaging/conf/messaging.conf | 4++--
examples/parameters/conf/parameters.conf | 2+-
examples/pgsql-sync/conf/pgsql-sync.conf | 2+-
examples/pgsql/conf/pgsql.conf | 4++--
examples/pipe_task/conf/pipe_task.conf | 4++--
examples/python-async/conf/python-async.conf | 12++++++------
examples/python-pgsql/kore.conf | 6+++---
examples/sse/conf/sse.conf | 4++--
examples/tasks/conf/tasks.conf | 4++--
examples/upload/conf/upload.conf | 2+-
examples/video_stream/conf/video_stream.conf | 4++--
examples/websocket/conf/websocket.conf | 4++--
src/config.c | 25+++++++++++++++++--------
23 files changed, 66 insertions(+), 57 deletions(-)

diff --git a/examples/async-curl/conf/async-curl.conf b/examples/async-curl/conf/async-curl.conf @@ -15,6 +15,6 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / http - static /ftp ftp + route / http + route /ftp ftp } diff --git a/examples/cookies/conf/cookies.conf b/examples/cookies/conf/cookies.conf @@ -14,7 +14,7 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / serve_cookies - static /secure serve_cookies - static /vault serve_cookies + route / serve_cookies + route /secure serve_cookies + route /vault serve_cookies } diff --git a/examples/cpp/conf/cpp.conf b/examples/cpp/conf/cpp.conf @@ -12,5 +12,5 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / page + route / page } diff --git a/examples/generic/conf/generic.conf b/examples/generic/conf/generic.conf @@ -30,16 +30,16 @@ domain * { certkey cert/key.pem accesslog kore_access.log - static /css/style.css asset_serve_style_css - static / asset_serve_index_html - static /intro.jpg asset_serve_intro_jpg - static /b64test serve_b64test - static /upload serve_file_upload - static /validator serve_validator - static /params-test serve_params_test - static /private serve_private - - static /private/test asset_serve_private_test_html auth_example + route /css/style.css asset_serve_style_css + route / asset_serve_index_html + route /intro.jpg asset_serve_intro_jpg + route /b64test serve_b64test + route /upload serve_file_upload + route /validator serve_validator + route /params-test serve_params_test + route /private serve_private + + route /private/test asset_serve_private_test_html auth_example params post /params-test { validate test1 v_example diff --git a/examples/headers/conf/headers.conf b/examples/headers/conf/headers.conf @@ -13,5 +13,5 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / page + route / page } diff --git a/examples/integers/conf/integers.conf b/examples/integers/conf/integers.conf @@ -18,7 +18,7 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / page + route / page # allowed parameters in the query string for GETs params qs:get / { diff --git a/examples/json/conf/json.conf b/examples/json/conf/json.conf @@ -14,6 +14,6 @@ domain 127.0.0.1 { certfile cert/server.pem certkey cert/key.pem - static / page + route / page restrict / post } diff --git a/examples/json_yajl/conf/json_yajl.conf b/examples/json_yajl/conf/json_yajl.conf @@ -14,5 +14,5 @@ domain 127.0.0.1 { certfile cert/server.pem certkey cert/key.pem - static / page + route / page } diff --git a/examples/jsonrpc/conf/jsonrpc.conf b/examples/jsonrpc/conf/jsonrpc.conf @@ -14,6 +14,6 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / homepage - static /v1 v1 + route / homepage + route /v1 v1 } diff --git a/examples/memtag/conf/memtag.conf b/examples/memtag/conf/memtag.conf @@ -14,5 +14,5 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / page + route / page } diff --git a/examples/messaging/conf/messaging.conf b/examples/messaging/conf/messaging.conf @@ -13,6 +13,6 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / page - static /shutdown page_shutdown + route / page + route /shutdown page_shutdown } diff --git a/examples/parameters/conf/parameters.conf b/examples/parameters/conf/parameters.conf @@ -19,7 +19,7 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / page + route / page # The parameters allowed for "/" (GET method). # diff --git a/examples/pgsql-sync/conf/pgsql-sync.conf b/examples/pgsql-sync/conf/pgsql-sync.conf @@ -12,5 +12,5 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / page + route / page } diff --git a/examples/pgsql/conf/pgsql.conf b/examples/pgsql/conf/pgsql.conf @@ -20,6 +20,6 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / page - static /hello hello + route / page + route /hello hello } diff --git a/examples/pipe_task/conf/pipe_task.conf b/examples/pipe_task/conf/pipe_task.conf @@ -17,6 +17,6 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / page - static /connect page_ws_connect + route / page + route /connect page_ws_connect } diff --git a/examples/python-async/conf/python-async.conf b/examples/python-async/conf/python-async.conf @@ -17,12 +17,12 @@ python_import ./src/async_http.py domain * { attach notls - static /queue async_queue - static /lock async_lock - static /proc async_proc + route /queue async_queue + route /lock async_lock + route /proc async_proc - static /socket async_socket - static /socket-test socket_test + route /socket async_socket + route /socket-test socket_test - static /httpclient httpclient + route /httpclient httpclient } diff --git a/examples/python-pgsql/kore.conf b/examples/python-pgsql/kore.conf @@ -12,7 +12,7 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / koreapp.query - static /hello koreapp.hello - static /slow koreapp.slow + route / koreapp.query + route /hello koreapp.hello + route /slow koreapp.slow } diff --git a/examples/sse/conf/sse.conf b/examples/sse/conf/sse.conf @@ -15,6 +15,6 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / page - static /subscribe subscribe + route / page + route /subscribe subscribe } diff --git a/examples/tasks/conf/tasks.conf b/examples/tasks/conf/tasks.conf @@ -21,8 +21,8 @@ domain * { certkey cert/key.pem accesslog kore_access.log - static / page_handler - static /post_back post_back + route / page_handler + route /post_back post_back params qs:get / { validate user v_user diff --git a/examples/upload/conf/upload.conf b/examples/upload/conf/upload.conf @@ -17,5 +17,5 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / page + route / page } diff --git a/examples/video_stream/conf/video_stream.conf b/examples/video_stream/conf/video_stream.conf @@ -17,6 +17,6 @@ domain * { certkey cert/key.pem accesslog access.log - static / asset_serve_video_html - dynamic ^/[a-z]*.[a-z0-9]{3}$ video_stream + route / asset_serve_video_html + route ^/[a-z]*.[a-z0-9]{3}$ video_stream } diff --git a/examples/websocket/conf/websocket.conf b/examples/websocket/conf/websocket.conf @@ -21,6 +21,6 @@ domain * { certfile cert/server.pem certkey cert/key.pem - static / page - static /connect page_ws_connect + route / page + route /connect page_ws_connect } diff --git a/src/config.c b/src/config.c @@ -107,11 +107,11 @@ static int configure_client_verify(char *); static int configure_client_verify_depth(char *); #if !defined(KORE_NO_HTTP) +static int configure_route(char *); static int configure_filemap(char *); -static int configure_restrict(char *); -static int configure_handler(int, char *); static int configure_static_handler(char *); static int configure_dynamic_handler(char *); +static int configure_restrict(char *); static int configure_accesslog(char *); static int configure_http_header_max(char *); static int configure_http_header_timeout(char *); @@ -186,6 +186,7 @@ static struct { { "python_import", configure_python_import }, #endif #if !defined(KORE_NO_HTTP) + { "route", configure_route}, { "filemap", configure_filemap }, { "static", configure_static_handler }, { "dynamic", configure_dynamic_handler }, @@ -971,35 +972,43 @@ configure_attach(char *name) static int configure_static_handler(char *options) { - return (configure_handler(HANDLER_TYPE_STATIC, options)); + kore_log(LOG_NOTICE, "static keyword removed, use route instead"); + return (KORE_RESULT_ERROR); } static int configure_dynamic_handler(char *options) { - return (configure_handler(HANDLER_TYPE_DYNAMIC, options)); + kore_log(LOG_NOTICE, "dynamic keyword removed, use route instead"); + return (KORE_RESULT_ERROR); } static int -configure_handler(int type, char *options) +configure_route(char *options) { + int type; char *argv[4]; if (current_domain == NULL) { - printf("page handler not specified in domain context\n"); + printf("route not specified in domain context\n"); return (KORE_RESULT_ERROR); } kore_split_string(options, " ", argv, 4); if (argv[0] == NULL || argv[1] == NULL) { - printf("missing parameters for page handler\n"); + printf("missing parameters for route \n"); return (KORE_RESULT_ERROR); } + if (*argv[0] == '/') + type = HANDLER_TYPE_STATIC; + else + type = HANDLER_TYPE_DYNAMIC; + if (!kore_module_handler_new(current_domain, argv[0], argv[1], argv[2], type)) { - printf("cannot create handler for %s\n", argv[0]); + printf("cannot create route for %s\n", argv[0]); return (KORE_RESULT_ERROR); }