From 3e0654e131064d3b1f76c020d48344a7df4df37b Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 14 Jul 2021 05:22:03 +0000 Subject: [PATCH] added the new option MIO_JSON_PERMIT_WORD_KEY --- mio/bin/t03.c | 2 +- mio/lib/htrd.c | 8 ++++---- mio/lib/http-cgi.c | 2 +- mio/lib/http-thr.c | 2 +- mio/lib/json.c | 4 ++-- mio/lib/mio-htrd.h | 14 +++++++------- mio/lib/mio-json.h | 3 ++- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/mio/bin/t03.c b/mio/bin/t03.c index cacb24f..5b5ca5d 100644 --- a/mio/bin/t03.c +++ b/mio/bin/t03.c @@ -119,7 +119,7 @@ int main (int argc, char* argv[]) for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "--permit-word-key") == 0) o |= MIO_JSON_PERMITWORDKEY; + if (strcmp(argv[i], "--permit-word-key") == 0) o |= MIO_JSON_PERMIT_WORD_KEY; } mio = mio_open(MIO_NULL, 0, MIO_NULL, 512, MIO_NULL); diff --git a/mio/lib/htrd.c b/mio/lib/htrd.c index bc06dc8..95278c1 100644 --- a/mio/lib/htrd.c +++ b/mio/lib/htrd.c @@ -871,7 +871,7 @@ static MIO_INLINE int parse_initial_line_and_headers (mio_htrd_t* htrd, const mi p = MIO_BECS_PTR(&htrd->fed.b.raw); #if 0 - if (htrd->option & MIO_HTRD_SKIPEMPTYLINES) + if (htrd->option & MIO_HTRD_SKIP_EMPTY_LINES) while (is_whspace_octet(*p)) p++; else #endif @@ -880,7 +880,7 @@ static MIO_INLINE int parse_initial_line_and_headers (mio_htrd_t* htrd, const mi MIO_ASSERT (htrd->mio, *p != '\0'); /* parse the initial line */ - if (!(htrd->option & MIO_HTRD_SKIPINITIALLINE)) + if (!(htrd->option & MIO_HTRD_SKIP_INITIAL_LINE)) { p = parse_initial_line(htrd, p); if (MIO_UNLIKELY(!p)) return -1; @@ -1100,7 +1100,7 @@ int mio_htrd_feed (mio_htrd_t* htrd, const mio_bch_t* req, mio_oow_t len, mio_oo register mio_bch_t b = *ptr++; #if 0 - if (htrd->option & MIO_HTRD_SKIPEMPTYLINES && + if (htrd->option & MIO_HTRD_SKIP_EMPTY_LINES && htrd->fed.s.plen <= 0 && is_whspace_octet(b)) { /* let's drop leading whitespaces across multiple @@ -1445,7 +1445,7 @@ mio_printf (MIO_T("CONTENT_LENGTH %d, RAW HEADER LENGTH %d\n"), /* since there are more to handle, i mark that * htrd is in need of some data. this may - * not be really compatible with SKIPEMPTYLINES. + * not be really compatible with SKIP_EMPTY_LINES. * SHOULD I simply remove the option? */ htrd->clean = 0; } diff --git a/mio/lib/http-cgi.c b/mio/lib/http-cgi.c index 01c3cf2..6a8a7ce 100644 --- a/mio/lib/http-cgi.c +++ b/mio/lib/http-cgi.c @@ -963,7 +963,7 @@ int mio_svc_htts_docgi (mio_svc_htts_t* htts, mio_dev_sck_t* csck, mio_htre_t* r cgi->peer_htrd = mio_htrd_open(mio, MIO_SIZEOF(*cgi_peer)); if (MIO_UNLIKELY(!cgi->peer_htrd)) goto oops; - mio_htrd_setoption (cgi->peer_htrd, MIO_HTRD_SKIPINITIALLINE | MIO_HTRD_RESPONSE); + mio_htrd_setoption (cgi->peer_htrd, MIO_HTRD_SKIP_INITIAL_LINE | MIO_HTRD_RESPONSE); mio_htrd_setrecbs (cgi->peer_htrd, &cgi_peer_htrd_recbs); cgi_peer = mio_htrd_getxtn(cgi->peer_htrd); diff --git a/mio/lib/http-thr.c b/mio/lib/http-thr.c index f6cd5f6..619ef66 100644 --- a/mio/lib/http-thr.c +++ b/mio/lib/http-thr.c @@ -889,7 +889,7 @@ int mio_svc_htts_dothr (mio_svc_htts_t* htts, mio_dev_sck_t* csck, mio_htre_t* r thr_state->peer_htrd = mio_htrd_open(mio, MIO_SIZEOF(*thr_peer)); if (MIO_UNLIKELY(!thr_state->peer_htrd)) goto oops; - mio_htrd_setoption (thr_state->peer_htrd, MIO_HTRD_SKIPINITIALLINE | MIO_HTRD_RESPONSE); + mio_htrd_setoption (thr_state->peer_htrd, MIO_HTRD_SKIP_INITIAL_LINE | MIO_HTRD_RESPONSE); mio_htrd_setrecbs (thr_state->peer_htrd, &thr_peer_htrd_recbs); thr_peer = mio_htrd_getxtn(thr_state->peer_htrd); diff --git a/mio/lib/json.c b/mio/lib/json.c index 9bf09fd..b3b5dd4 100644 --- a/mio/lib/json.c +++ b/mio/lib/json.c @@ -403,7 +403,7 @@ static int handle_word_value_char (mio_json_t* json, mio_ooci_t c) mio_json_inst_t inst; int ok; - ok = (json->option & MIO_JSON_PERMITWORDKEY)? + ok = (json->option & MIO_JSON_PERMIT_WORD_KEY)? (mio_is_ooch_alpha(c) || mio_is_ooch_digit(c) || c == '_'): mio_is_ooch_alpha(c); if (ok) @@ -417,7 +417,7 @@ static int handle_word_value_char (mio_json_t* json, mio_ooci_t c) if (mio_comp_oochars_bcstr(json->tok.ptr, json->tok.len, "null", 0) == 0) inst = MIO_JSON_INST_NIL; else if (mio_comp_oochars_bcstr(json->tok.ptr, json->tok.len, "true", 0) == 0) inst = MIO_JSON_INST_TRUE; else if (mio_comp_oochars_bcstr(json->tok.ptr, json->tok.len, "false", 0) == 0) inst = MIO_JSON_INST_FALSE; - else if (json->option & MIO_JSON_PERMITWORDKEY) inst = __INST_WORD_STRING; /* internal only */ + else if (json->option & MIO_JSON_PERMIT_WORD_KEY) inst = __INST_WORD_STRING; /* internal only */ else { mio_seterrbfmt (json->mio, MIO_EINVAL, "invalid word value - %.*js", json->tok.len, json->tok.ptr); diff --git a/mio/lib/mio-htrd.h b/mio/lib/mio-htrd.h index 126c4a3..92e0cfd 100644 --- a/mio/lib/mio-htrd.h +++ b/mio/lib/mio-htrd.h @@ -52,13 +52,13 @@ typedef enum mio_htrd_errnum_t mio_htrd_errnum_t; */ enum mio_htrd_option_t { - MIO_HTRD_SKIPEMPTYLINES = ((mio_bitmask_t)1 << 0), /**< skip leading empty lines before the initial line */ - MIO_HTRD_SKIPINITIALLINE = ((mio_bitmask_t)1 << 1), /**< skip processing an initial line */ - MIO_HTRD_CANONQPATH = ((mio_bitmask_t)1 << 2), /**< canonicalize the query path */ - MIO_HTRD_REQUEST = ((mio_bitmask_t)1 << 3), /**< parse input as a request */ - MIO_HTRD_RESPONSE = ((mio_bitmask_t)1 << 4), /**< parse input as a response */ - MIO_HTRD_TRAILERS = ((mio_bitmask_t)1 << 5), /**< store trailers in a separate table */ - MIO_HTRD_STRICT = ((mio_bitmask_t)1 << 6) /**< be more picky */ + MIO_HTRD_SKIP_EMPTY_LINES = ((mio_bitmask_t)1 << 0), /**< skip leading empty lines before the initial line */ + MIO_HTRD_SKIP_INITIAL_LINE = ((mio_bitmask_t)1 << 1), /**< skip processing an initial line */ + MIO_HTRD_CANONQPATH = ((mio_bitmask_t)1 << 2), /**< canonicalize the query path */ + MIO_HTRD_REQUEST = ((mio_bitmask_t)1 << 3), /**< parse input as a request */ + MIO_HTRD_RESPONSE = ((mio_bitmask_t)1 << 4), /**< parse input as a response */ + MIO_HTRD_TRAILERS = ((mio_bitmask_t)1 << 5), /**< store trailers in a separate table */ + MIO_HTRD_STRICT = ((mio_bitmask_t)1 << 6) /**< be more picky */ }; typedef enum mio_htrd_option_t mio_htrd_option_t; diff --git a/mio/lib/mio-json.h b/mio/lib/mio-json.h index 5075de6..266af83 100644 --- a/mio/lib/mio-json.h +++ b/mio/lib/mio-json.h @@ -123,7 +123,8 @@ struct mio_json_state_node_t enum mio_json_option_t { /* allow an unquoted word as an object key */ - MIO_JSON_PERMITWORDKEY = ((mio_bitmask_t)1 << 0), + MIO_JSON_PERMIT_WORD_KEY = ((mio_bitmask_t)1 << 0), + MIO_JSON_OPTIONAL_COMMA = ((mio_bitmask_t)1 << 1) }; typedef enum mio_json_option_t mio_json_option_t;