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 3e84502235ba30c889948ecb40690d78101220fc
parent 7f11e37161d9feab56ed518d5364346ce8d564ff
Author: Joris Vink <joris@coders.se>
Date:   Sat, 25 Feb 2017 17:02:39 -0800

Adjust examples after recent changes.

- New kodev tool generates config with server.pem/key.pem.
- Use proper formats for kore_log().
- Update to new websocket api.

Diffstat:
examples/cookies/conf/cookies.conf | 4++--
examples/cpp/conf/cpp.conf | 4++--
examples/generic/conf/generic.conf | 4++--
examples/headers/conf/headers.conf | 4++--
examples/integers/conf/integers.conf | 4++--
examples/json_yajl/conf/json_yajl.conf | 4++--
examples/jsonrpc/conf/jsonrpc.conf | 4++--
examples/ktunnel/conf/ktunnel.conf | 4++--
examples/messaging/conf/messaging.conf | 4++--
examples/nohttp/conf/nohttp.conf | 4++--
examples/nohttp/src/nohttp.c | 2+-
examples/parameters/conf/parameters.conf | 4++--
examples/pgsql-sync/conf/pgsql-sync.conf | 4++--
examples/pgsql/conf/pgsql.conf | 4++--
examples/pipe_task/conf/pipe_task.conf | 4++--
examples/pipe_task/src/pipe_task.c | 19++++++++-----------
examples/python-pgsql/conf/python-pgsql.conf | 4++--
examples/python/conf/python.conf | 4++--
examples/sse/conf/sse.conf | 4++--
examples/tasks/conf/tasks.conf | 4++--
examples/tls-proxy/conf/tls-proxy.conf | 4++--
examples/upload/conf/upload.conf | 4++--
examples/video_stream/conf/video_stream.conf | 4++--
examples/video_stream/src/stream.c | 12++++++------
examples/websocket/conf/websocket.conf | 4++--
25 files changed, 59 insertions(+), 62 deletions(-)

diff --git a/examples/cookies/conf/cookies.conf b/examples/cookies/conf/cookies.conf @@ -6,8 +6,8 @@ load ./cookies.so tls_dhparam dh2048.pem domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / serve_cookies static /secure serve_cookies diff --git a/examples/cpp/conf/cpp.conf b/examples/cpp/conf/cpp.conf @@ -5,7 +5,7 @@ load ./cpp.so tls_dhparam dh2048.pem domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / page } diff --git a/examples/generic/conf/generic.conf b/examples/generic/conf/generic.conf @@ -21,8 +21,8 @@ authentication auth_example { } domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem accesslog kore_access.log static /css/style.css serve_style_css diff --git a/examples/headers/conf/headers.conf b/examples/headers/conf/headers.conf @@ -6,7 +6,7 @@ load ./headers.so tls_dhparam dh2048.pem domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / page } diff --git a/examples/integers/conf/integers.conf b/examples/integers/conf/integers.conf @@ -11,8 +11,8 @@ tls_dhparam dh2048.pem validator v_id regex ^-?[0-9]*$ domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / page params get / { diff --git a/examples/json_yajl/conf/json_yajl.conf b/examples/json_yajl/conf/json_yajl.conf @@ -6,8 +6,8 @@ load ./json_yajl.so tls_dhparam dh2048.pem domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / page } diff --git a/examples/jsonrpc/conf/jsonrpc.conf b/examples/jsonrpc/conf/jsonrpc.conf @@ -6,8 +6,8 @@ load ./jsonrpc.so tls_dhparam dh2048.pem domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / homepage static /v1 v1 diff --git a/examples/ktunnel/conf/ktunnel.conf b/examples/ktunnel/conf/ktunnel.conf @@ -13,8 +13,8 @@ validator v_port regex ^[0-9]*$ http_keepalive_time 0 domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static /connect open_connection diff --git a/examples/messaging/conf/messaging.conf b/examples/messaging/conf/messaging.conf @@ -6,8 +6,8 @@ tls_dhparam dh2048.pem workers 4 domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / page static /shutdown page_shutdown } diff --git a/examples/nohttp/conf/nohttp.conf b/examples/nohttp/conf/nohttp.conf @@ -17,6 +17,6 @@ tls_dhparam dh2048.pem # We must still define a domain to use TLS. This might go away # in the future for NOHTTP=1 domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem } diff --git a/examples/nohttp/src/nohttp.c b/examples/nohttp/src/nohttp.c @@ -78,7 +78,7 @@ connection_recv_data(struct netbuf *nb) { struct connection *c = (struct connection *)nb->owner; - kore_log(LOG_NOTICE, "%p: received %u bytes", c, nb->s_off); + kore_log(LOG_NOTICE, "%p: received %zu bytes", (void *)c, nb->s_off); /* We will just dump these back to the client. */ net_send_queue(c, nb->buf, nb->s_off); diff --git a/examples/parameters/conf/parameters.conf b/examples/parameters/conf/parameters.conf @@ -11,8 +11,8 @@ tls_dhparam dh2048.pem validator v_id regex ^[0-9]*$ domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / page diff --git a/examples/pgsql-sync/conf/pgsql-sync.conf b/examples/pgsql-sync/conf/pgsql-sync.conf @@ -5,7 +5,7 @@ load ./pgsql-sync.so init tls_dhparam dh2048.pem domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / page } diff --git a/examples/pgsql/conf/pgsql.conf b/examples/pgsql/conf/pgsql.conf @@ -8,7 +8,7 @@ tls_dhparam dh2048.pem http_keepalive_time 0 domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / page } diff --git a/examples/pipe_task/conf/pipe_task.conf b/examples/pipe_task/conf/pipe_task.conf @@ -9,8 +9,8 @@ websocket_maxframe 65536 websocket_timeout 10000 domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / page static /connect page_ws_connect diff --git a/examples/pipe_task/src/pipe_task.c b/examples/pipe_task/src/pipe_task.c @@ -46,13 +46,6 @@ void websocket_message(struct connection *, int pipe_reader(struct kore_task *); void pipe_data_available(struct kore_task *); -/* Websocket callbacks. */ -struct kore_wscbs wscbs = { - websocket_connect, - websocket_message, - websocket_disconnect -}; - /* Our pipe reader. */ struct kore_task pipe_task; @@ -65,7 +58,7 @@ init(int state) return (KORE_RESULT_ERROR); /* Only do this on a dedicated worker. */ - if (worker->id != 0) + if (worker->id != 1) return (KORE_RESULT_OK); /* Create our task. */ @@ -115,7 +108,8 @@ page(struct http_request *req) int page_ws_connect(struct http_request *req) { - kore_websocket_handshake(req, &wscbs); + kore_websocket_handshake(req, "websocket_connect", + "websocket_message", "websocket_disconnect"); return (KORE_RESULT_OK); } @@ -134,6 +128,8 @@ pipe_reader(struct kore_task *t) fd = -1; + kore_log(LOG_INFO, "pipe_reader starting"); + /* Just run forever. */ for (;;) { /* Attempt to open the pipe if needed. */ @@ -142,7 +138,7 @@ pipe_reader(struct kore_task *t) if ((fd = open("/tmp/pipe", O_RDONLY)) == -1) { kore_log(LOG_NOTICE, "failed to open pipe"); - sleep(10); + sleep(1); continue; } @@ -196,7 +192,8 @@ pipe_data_available(struct kore_task *t) kore_log(LOG_WARNING, "truncated data from task"); /* Broadcast it to all connected websocket clients. */ - kore_log(LOG_NOTICE, "got %d bytes from task", len); + kore_log(LOG_NOTICE, "got %zu bytes from task", len); + kore_websocket_broadcast(NULL, WEBSOCKET_OP_TEXT, buf, len, WEBSOCKET_BROADCAST_GLOBAL); } diff --git a/examples/python-pgsql/conf/python-pgsql.conf b/examples/python-pgsql/conf/python-pgsql.conf @@ -7,8 +7,8 @@ python_import src/query.py tls_dhparam dh2048.pem domain * { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / query static /hello hello diff --git a/examples/python/conf/python.conf b/examples/python/conf/python.conf @@ -24,8 +24,8 @@ authentication auth { } domain * { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem # Mix page handlers between native and python. static / page diff --git a/examples/sse/conf/sse.conf b/examples/sse/conf/sse.conf @@ -7,8 +7,8 @@ tls_dhparam dh2048.pem http_keepalive_time 600 domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / page static /subscribe subscribe diff --git a/examples/tasks/conf/tasks.conf b/examples/tasks/conf/tasks.conf @@ -12,8 +12,8 @@ http_keepalive_time 0 validator v_user regex ^[a-z]*$ domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem accesslog kore_access.log static / page_handler diff --git a/examples/tls-proxy/conf/tls-proxy.conf b/examples/tls-proxy/conf/tls-proxy.conf @@ -12,6 +12,6 @@ bind 127.0.0.1 8888 client_setup # Setup domain for TLS usage. domain localhost { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem } diff --git a/examples/upload/conf/upload.conf b/examples/upload/conf/upload.conf @@ -9,8 +9,8 @@ http_body_max 1024000000 http_body_disk_offload 4096 domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / page } diff --git a/examples/video_stream/conf/video_stream.conf b/examples/video_stream/conf/video_stream.conf @@ -8,8 +8,8 @@ tls_dhparam dh2048.pem http_keepalive_time 600 domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem accesslog access.log static / serve_page diff --git a/examples/video_stream/src/stream.c b/examples/video_stream/src/stream.c @@ -93,8 +93,8 @@ video_stream(struct http_request *req) return (KORE_RESULT_OK); } - kore_log(LOG_NOTICE, "%p: opened %s (%s) for streaming (%ld ref:%d)", - req->owner, v->path, ctype, v->size, v->ref); + kore_log(LOG_NOTICE, "%p: opened %s (%s) for streaming (%lld ref:%d)", + (void *)req->owner, v->path, ctype, v->size, v->ref); if (http_request_header(req, "range", &header)) { if ((bytes = strchr(header, '=')) == NULL) { @@ -148,8 +148,8 @@ video_stream(struct http_request *req) return (KORE_RESULT_OK); } - kore_log(LOG_NOTICE, "%p: %s sending: %ld-%ld/%ld", - req->owner, v->path, start, end - 1, v->size); + kore_log(LOG_NOTICE, "%p: %s sending: %lld-%lld/%lld", + (void *)req->owner, v->path, start, end - 1, v->size); http_response_header(req, "content-range", rb); } else { start = 0; @@ -261,8 +261,8 @@ video_stream_finish(struct netbuf *nb) struct video *v = nb->extra; v->ref--; - kore_log(LOG_NOTICE, "%p: video stream %s done (%d/%d ref:%d)", - nb->owner, v->path, nb->s_off, nb->b_len, v->ref); + kore_log(LOG_NOTICE, "%p: video stream %s done (%zu/%zu ref:%d)", + (void *)nb->owner, v->path, nb->s_off, nb->b_len, v->ref); if (v->ref == 0) video_unmap(v); diff --git a/examples/websocket/conf/websocket.conf b/examples/websocket/conf/websocket.conf @@ -13,8 +13,8 @@ websocket_maxframe 65536 websocket_timeout 20 domain 127.0.0.1 { - certfile cert/server.crt - certkey cert/server.key + certfile cert/server.pem + certkey cert/key.pem static / page static /connect page_ws_connect