From a37712e0fe87464b870d0b3df9755353b1b8fccc Mon Sep 17 00:00:00 2001 From: Meutel Date: Thu, 29 Dec 2016 18:48:26 +0100 Subject: [PATCH] Param query id --- main.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 087daeb..35c5b97 100644 --- a/main.c +++ b/main.c @@ -41,6 +41,11 @@ enum page { PAGE__MAX }; +enum key { + KEY_ID, + KEY__MAX +}; + static const char *const pages[PAGE__MAX] = { "index", /* PAGE_INDEX */ "books", /* PAGE_BOOKS */ @@ -48,6 +53,10 @@ static const char *const pages[PAGE__MAX] = { "series", /* PAGE_SERIES */ }; +static const struct kvalid keys[KEY__MAX] = { + { kvalid_int, "id" }, /* KEY_ID */ +}; + /* * Fill out all HTTP secure headers. * Use the existing document's MIME type. @@ -86,6 +95,9 @@ sendbooks(struct kreq *r) kjson_open(&req, r); kjson_obj_open(&req); kjson_putstringp(&req, "data", "books"); + if (NULL != r->fieldmap[KEY_ID]) { + kjson_putintp(&req, "id", r->fieldmap[KEY_ID]->parsed.i); + } kjson_obj_close(&req); kjson_close(&req); } @@ -138,7 +150,7 @@ main(void) /* Actually parse HTTP document. */ er = khttp_parsex(&r, ksuffixmap, - kmimetypes, KMIME__MAX, NULL, 0, + kmimetypes, KMIME__MAX, keys, KEY__MAX, pages, PAGE__MAX, KMIME_APP_JSON, PAGE_INDEX, NULL, NULL, 0, NULL);