Param query id

This commit is contained in:
Meutel 2016-12-29 18:48:26 +01:00
parent d7d041ac54
commit a37712e0fe

14
main.c
View File

@ -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);