Controller: partial retrieving of configuration.
This commit is contained in:
@@ -18,6 +18,8 @@ typedef struct {
|
|||||||
} nxt_conf_json_pretty_t;
|
} nxt_conf_json_pretty_t;
|
||||||
|
|
||||||
|
|
||||||
|
nxt_conf_json_value_t *nxt_conf_json_value_get(nxt_conf_json_value_t *value,
|
||||||
|
nxt_str_t *path);
|
||||||
nxt_conf_json_value_t *nxt_conf_json_parse(u_char *pos, size_t length,
|
nxt_conf_json_value_t *nxt_conf_json_parse(u_char *pos, size_t length,
|
||||||
nxt_mem_pool_t *pool);
|
nxt_mem_pool_t *pool);
|
||||||
uintptr_t nxt_conf_json_print_value(u_char *pos, nxt_conf_json_value_t *value,
|
uintptr_t nxt_conf_json_print_value(u_char *pos, nxt_conf_json_value_t *value,
|
||||||
|
|||||||
@@ -50,10 +50,8 @@ static nxt_int_t nxt_conf_json_object_hash_test(nxt_lvlhsh_query_t *lhq,
|
|||||||
void *data);
|
void *data);
|
||||||
static nxt_int_t nxt_conf_json_object_member_add(nxt_lvlhsh_t *lvlhsh,
|
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);
|
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(
|
static nxt_conf_json_value_t *nxt_conf_json_object_member_get(
|
||||||
nxt_lvlhsh_t *lvlhsh, u_char *name, size_t length);
|
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);
|
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 *
|
static nxt_conf_json_value_t *
|
||||||
nxt_conf_json_object_member_get(nxt_lvlhsh_t *lvlhsh, u_char *name,
|
nxt_conf_json_object_member_get(nxt_lvlhsh_t *lvlhsh, u_char *name,
|
||||||
size_t length)
|
size_t length)
|
||||||
@@ -179,7 +176,42 @@ nxt_conf_json_object_member_get(nxt_lvlhsh_t *lvlhsh, u_char *name,
|
|||||||
|
|
||||||
return NULL;
|
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 *
|
nxt_conf_json_value_t *
|
||||||
|
|||||||
@@ -554,13 +554,34 @@ static void
|
|||||||
nxt_controller_process_request(nxt_task_t *task, nxt_event_conn_t *c,
|
nxt_controller_process_request(nxt_task_t *task, nxt_event_conn_t *c,
|
||||||
nxt_controller_request_t *req)
|
nxt_controller_request_t *req)
|
||||||
{
|
{
|
||||||
|
nxt_str_t path;
|
||||||
|
nxt_conf_json_value_t *value;
|
||||||
nxt_controller_response_t resp;
|
nxt_controller_response_t resp;
|
||||||
|
|
||||||
nxt_memzero(&resp, sizeof(nxt_controller_response_t));
|
nxt_memzero(&resp, sizeof(nxt_controller_response_t));
|
||||||
|
|
||||||
if (nxt_str_eq(&req->parser.method, "GET", 3)) {
|
if (nxt_str_eq(&req->parser.method, "GET", 3)) {
|
||||||
|
|
||||||
|
path.start = req->parser.target_start;
|
||||||
|
|
||||||
|
if (req->parser.args_start != NULL) {
|
||||||
|
path.length = req->parser.args_start - path.start;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
path.length = req->parser.target_end - path.start;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = nxt_conf_json_value_get(nxt_controller_conf.root, &path);
|
||||||
|
|
||||||
|
if (value != NULL) {
|
||||||
nxt_str_set(&resp.status_line, "200 OK");
|
nxt_str_set(&resp.status_line, "200 OK");
|
||||||
resp.json_value = nxt_controller_conf.root;
|
resp.json_value = value;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
nxt_str_set(&resp.status_line, "404 Not Found");
|
||||||
|
nxt_str_set(&resp.json_string,
|
||||||
|
"{ \"error\": \"Requested value doesn't exist\" }");
|
||||||
|
}
|
||||||
|
|
||||||
} else if (nxt_str_eq(&req->parser.method, "PUT", 3)) {
|
} else if (nxt_str_eq(&req->parser.method, "PUT", 3)) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user