added the new option MIO_JSON_PERMIT_WORD_KEY
This commit is contained in:
parent
72422be8b8
commit
3e0654e131
@ -119,7 +119,7 @@ int main (int argc, char* argv[])
|
|||||||
|
|
||||||
for (i = 1; i < argc; i++)
|
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);
|
mio = mio_open(MIO_NULL, 0, MIO_NULL, 512, MIO_NULL);
|
||||||
|
@ -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);
|
p = MIO_BECS_PTR(&htrd->fed.b.raw);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (htrd->option & MIO_HTRD_SKIPEMPTYLINES)
|
if (htrd->option & MIO_HTRD_SKIP_EMPTY_LINES)
|
||||||
while (is_whspace_octet(*p)) p++;
|
while (is_whspace_octet(*p)) p++;
|
||||||
else
|
else
|
||||||
#endif
|
#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');
|
MIO_ASSERT (htrd->mio, *p != '\0');
|
||||||
|
|
||||||
/* parse the initial line */
|
/* parse the initial line */
|
||||||
if (!(htrd->option & MIO_HTRD_SKIPINITIALLINE))
|
if (!(htrd->option & MIO_HTRD_SKIP_INITIAL_LINE))
|
||||||
{
|
{
|
||||||
p = parse_initial_line(htrd, p);
|
p = parse_initial_line(htrd, p);
|
||||||
if (MIO_UNLIKELY(!p)) return -1;
|
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++;
|
register mio_bch_t b = *ptr++;
|
||||||
|
|
||||||
#if 0
|
#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))
|
htrd->fed.s.plen <= 0 && is_whspace_octet(b))
|
||||||
{
|
{
|
||||||
/* let's drop leading whitespaces across multiple
|
/* 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
|
/* since there are more to handle, i mark that
|
||||||
* htrd is in need of some data. this may
|
* 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? */
|
* SHOULD I simply remove the option? */
|
||||||
htrd->clean = 0;
|
htrd->clean = 0;
|
||||||
}
|
}
|
||||||
|
@ -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));
|
cgi->peer_htrd = mio_htrd_open(mio, MIO_SIZEOF(*cgi_peer));
|
||||||
if (MIO_UNLIKELY(!cgi->peer_htrd)) goto oops;
|
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);
|
mio_htrd_setrecbs (cgi->peer_htrd, &cgi_peer_htrd_recbs);
|
||||||
|
|
||||||
cgi_peer = mio_htrd_getxtn(cgi->peer_htrd);
|
cgi_peer = mio_htrd_getxtn(cgi->peer_htrd);
|
||||||
|
@ -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));
|
thr_state->peer_htrd = mio_htrd_open(mio, MIO_SIZEOF(*thr_peer));
|
||||||
if (MIO_UNLIKELY(!thr_state->peer_htrd)) goto oops;
|
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);
|
mio_htrd_setrecbs (thr_state->peer_htrd, &thr_peer_htrd_recbs);
|
||||||
|
|
||||||
thr_peer = mio_htrd_getxtn(thr_state->peer_htrd);
|
thr_peer = mio_htrd_getxtn(thr_state->peer_htrd);
|
||||||
|
@ -403,7 +403,7 @@ static int handle_word_value_char (mio_json_t* json, mio_ooci_t c)
|
|||||||
mio_json_inst_t inst;
|
mio_json_inst_t inst;
|
||||||
int ok;
|
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) || mio_is_ooch_digit(c) || c == '_'):
|
||||||
mio_is_ooch_alpha(c);
|
mio_is_ooch_alpha(c);
|
||||||
if (ok)
|
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;
|
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, "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 (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
|
else
|
||||||
{
|
{
|
||||||
mio_seterrbfmt (json->mio, MIO_EINVAL, "invalid word value - %.*js", json->tok.len, json->tok.ptr);
|
mio_seterrbfmt (json->mio, MIO_EINVAL, "invalid word value - %.*js", json->tok.len, json->tok.ptr);
|
||||||
|
@ -52,13 +52,13 @@ typedef enum mio_htrd_errnum_t mio_htrd_errnum_t;
|
|||||||
*/
|
*/
|
||||||
enum mio_htrd_option_t
|
enum mio_htrd_option_t
|
||||||
{
|
{
|
||||||
MIO_HTRD_SKIPEMPTYLINES = ((mio_bitmask_t)1 << 0), /**< skip leading empty lines before the initial line */
|
MIO_HTRD_SKIP_EMPTY_LINES = ((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_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_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_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_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_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_STRICT = ((mio_bitmask_t)1 << 6) /**< be more picky */
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum mio_htrd_option_t mio_htrd_option_t;
|
typedef enum mio_htrd_option_t mio_htrd_option_t;
|
||||||
|
@ -123,7 +123,8 @@ struct mio_json_state_node_t
|
|||||||
enum mio_json_option_t
|
enum mio_json_option_t
|
||||||
{
|
{
|
||||||
/* allow an unquoted word as an object key */
|
/* 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;
|
typedef enum mio_json_option_t mio_json_option_t;
|
||||||
|
Loading…
Reference in New Issue
Block a user