diff options
author | Valentin Bartenev <vbart@nginx.com> | 2017-05-18 20:40:19 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2017-05-18 20:40:19 +0300 |
commit | c7be5bd6ae38bdc7d29ee0b3170e5eb828e92d2d (patch) | |
tree | 97cbf3d6a4ced6b0ab14e5336292d97178bf78b4 /src/nxt_conf_json.c | |
parent | dc95b2f3de76df03b64bab9bbc5e6a9dc7015550 (diff) | |
download | unit-c7be5bd6ae38bdc7d29ee0b3170e5eb828e92d2d.tar.gz unit-c7be5bd6ae38bdc7d29ee0b3170e5eb828e92d2d.tar.bz2 |
Controller: partial retrieving of configuration.
Diffstat (limited to '')
-rw-r--r-- | src/nxt_conf_json.c | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/src/nxt_conf_json.c b/src/nxt_conf_json.c index 063fa988..0a9db0b3 100644 --- a/src/nxt_conf_json.c +++ b/src/nxt_conf_json.c @@ -50,10 +50,8 @@ static nxt_int_t nxt_conf_json_object_hash_test(nxt_lvlhsh_query_t *lhq, void *data); static nxt_int_t nxt_conf_json_object_member_add(nxt_lvlhsh_t *lvlhsh, nxt_conf_json_obj_member_t *member, nxt_mem_pool_t *pool); -#if 0 static nxt_conf_json_value_t *nxt_conf_json_object_member_get( nxt_lvlhsh_t *lvlhsh, u_char *name, size_t length); -#endif static u_char *nxt_conf_json_skip_space(u_char *pos, u_char *end); @@ -159,7 +157,6 @@ nxt_conf_json_object_member_add(nxt_lvlhsh_t *lvlhsh, } -#if 0 static nxt_conf_json_value_t * nxt_conf_json_object_member_get(nxt_lvlhsh_t *lvlhsh, u_char *name, size_t length) @@ -179,7 +176,42 @@ nxt_conf_json_object_member_get(nxt_lvlhsh_t *lvlhsh, u_char *name, return NULL; } -#endif + + +nxt_conf_json_value_t * +nxt_conf_json_value_get(nxt_conf_json_value_t *value, nxt_str_t *path) +{ + u_char *p, *start, *end; + + p = path->start; + end = p + path->length; + + if (p != end && end[-1] == '/') { + end--; + } + + while (p != end) { + start = p + 1; + p = start; + + while (p != end && *p != '/') { + p++; + } + + if (value->type != NXT_CONF_JSON_OBJECT) { + return NULL; + } + + value = nxt_conf_json_object_member_get(value->u.object, start, + p - start); + + if (value == NULL) { + return NULL; + } + } + + return value; +} nxt_conf_json_value_t * |