Configuration: reduced names of structures, functions, and macros.

This commit is contained in:
Valentin Bartenev
2017-06-28 18:56:33 +03:00
parent ec5e540fd7
commit 53074c3b29
4 changed files with 361 additions and 375 deletions

View File

@@ -138,7 +138,7 @@ NXT_LIB_SRCS=" \
src/nxt_http_parse.c \ src/nxt_http_parse.c \
src/nxt_app_log.c \ src/nxt_app_log.c \
src/nxt_runtime.c \ src/nxt_runtime.c \
src/nxt_conf_json.c \ src/nxt_conf.c \
src/nxt_stream_module.c \ src/nxt_stream_module.c \
src/nxt_master_process.c \ src/nxt_master_process.c \
src/nxt_worker_process.c \ src/nxt_worker_process.c \

File diff suppressed because it is too large Load Diff

View File

@@ -9,28 +9,28 @@
#define _NXT_CONF_INCLUDED_ #define _NXT_CONF_INCLUDED_
typedef struct nxt_conf_json_value_s nxt_conf_json_value_t; typedef struct nxt_conf_value_s nxt_conf_value_t;
typedef struct nxt_conf_json_op_s nxt_conf_json_op_t; typedef struct nxt_conf_op_s nxt_conf_op_t;
typedef enum { typedef enum {
NXT_CONF_JSON_MAP_INT8, NXT_CONF_MAP_INT8,
NXT_CONF_JSON_MAP_INT32, NXT_CONF_MAP_INT32,
NXT_CONF_JSON_MAP_INT64, NXT_CONF_MAP_INT64,
NXT_CONF_JSON_MAP_INT, NXT_CONF_MAP_INT,
NXT_CONF_JSON_MAP_SIZE, NXT_CONF_MAP_SIZE,
NXT_CONF_JSON_MAP_OFF, NXT_CONF_MAP_OFF,
NXT_CONF_JSON_MAP_DOUBLE, NXT_CONF_MAP_DOUBLE,
NXT_CONF_JSON_MAP_STR, NXT_CONF_MAP_STR,
NXT_CONF_JSON_MAP_PTR, NXT_CONF_MAP_PTR,
} nxt_conf_json_map_type_t; } nxt_conf_map_type_t;
typedef struct { typedef struct {
nxt_str_t name; nxt_str_t name;
nxt_conf_json_map_type_t type; nxt_conf_map_type_t type;
size_t offset; size_t offset;
} nxt_conf_json_object_map_t; } nxt_conf_map_t;
typedef struct { typedef struct {
@@ -39,31 +39,28 @@ typedef struct {
} nxt_conf_json_pretty_t; } nxt_conf_json_pretty_t;
nxt_conf_json_value_t *nxt_conf_json_get_value(nxt_conf_json_value_t *value, nxt_conf_value_t *nxt_conf_get_path(nxt_conf_value_t *value, nxt_str_t *path);
nxt_str_t *path); nxt_conf_value_t *nxt_conf_get_object_member(nxt_conf_value_t *value,
nxt_conf_json_value_t *nxt_conf_json_object_get_member( nxt_str_t *name, uint32_t *index);
nxt_conf_json_value_t *value, nxt_str_t *name, uint32_t *index); nxt_conf_value_t *nxt_conf_next_object_member(nxt_conf_value_t *value,
nxt_conf_json_value_t *nxt_conf_json_object_next_member( nxt_str_t *name, uint32_t *next);
nxt_conf_json_value_t *value, nxt_str_t *name, uint32_t *next);
nxt_int_t nxt_conf_json_object_map(nxt_conf_json_value_t *value, nxt_int_t nxt_conf_map_object(nxt_conf_value_t *value, nxt_conf_map_t *map,
nxt_conf_json_object_map_t *map, void *data); void *data);
nxt_int_t nxt_conf_json_op_compile(nxt_mp_t *mp, nxt_conf_json_op_t **ops, nxt_int_t nxt_conf_op_compile(nxt_mp_t *mp, nxt_conf_op_t **ops,
nxt_conf_json_value_t *root, nxt_str_t *path, nxt_conf_value_t *root, nxt_str_t *path, nxt_conf_value_t *value);
nxt_conf_json_value_t *value); nxt_conf_value_t *nxt_conf_clone(nxt_mp_t *mp, nxt_conf_op_t *op,
nxt_conf_json_value_t *nxt_conf_json_clone_value(nxt_mp_t *mp, nxt_conf_value_t *value);
nxt_conf_json_op_t *op, nxt_conf_json_value_t *value);
nxt_conf_json_value_t *nxt_conf_json_parse(nxt_mp_t *mp, u_char *start, nxt_conf_value_t *nxt_conf_json_parse(nxt_mp_t *mp, u_char *start, u_char *end);
u_char *end);
#define nxt_conf_json_str_parse(mp, str) \ #define nxt_conf_json_parse_str(mp, str) \
nxt_conf_json_parse(mp, (str)->start, (str)->start + (str)->length) nxt_conf_json_parse(mp, (str)->start, (str)->start + (str)->length)
size_t nxt_conf_json_value_length(nxt_conf_json_value_t *value, size_t nxt_conf_json_length(nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty); nxt_conf_json_pretty_t *pretty);
u_char *nxt_conf_json_value_print(u_char *p, nxt_conf_json_value_t *value, u_char *nxt_conf_json_print(u_char *p, nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty); nxt_conf_json_pretty_t *pretty);

View File

@@ -12,7 +12,7 @@
typedef struct { typedef struct {
nxt_conf_json_value_t *root; nxt_conf_value_t *root;
nxt_mp_t *pool; nxt_mp_t *pool;
} nxt_controller_conf_t; } nxt_controller_conf_t;
@@ -27,8 +27,8 @@ typedef struct {
typedef struct { typedef struct {
nxt_str_t status_line; nxt_str_t status_line;
nxt_conf_json_value_t *json_value; nxt_conf_value_t *conf;
nxt_str_t json_string; nxt_str_t json;
} nxt_controller_response_t; } nxt_controller_response_t;
@@ -84,7 +84,7 @@ nxt_int_t
nxt_controller_start(nxt_task_t *task, nxt_runtime_t *rt) nxt_controller_start(nxt_task_t *task, nxt_runtime_t *rt)
{ {
nxt_mp_t *mp; nxt_mp_t *mp;
nxt_conf_json_value_t *conf; nxt_conf_value_t *conf;
nxt_http_fields_hash_t *hash; nxt_http_fields_hash_t *hash;
static const nxt_str_t json static const nxt_str_t json
@@ -108,7 +108,7 @@ nxt_controller_start(nxt_task_t *task, nxt_runtime_t *rt)
return NXT_ERROR; return NXT_ERROR;
} }
conf = nxt_conf_json_str_parse(mp, &json); conf = nxt_conf_json_parse_str(mp, &json);
if (conf == NULL) { if (conf == NULL) {
return NXT_ERROR; return NXT_ERROR;
@@ -546,8 +546,8 @@ nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
nxt_str_t path; nxt_str_t path;
nxt_uint_t status; nxt_uint_t status;
nxt_buf_mem_t *mbuf; nxt_buf_mem_t *mbuf;
nxt_conf_json_op_t *ops; nxt_conf_op_t *ops;
nxt_conf_json_value_t *value; nxt_conf_value_t *value;
nxt_controller_response_t resp; nxt_controller_response_t resp;
static const nxt_str_t empty_obj = nxt_string("{}"); static const nxt_str_t empty_obj = nxt_string("{}");
@@ -569,14 +569,14 @@ nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
if (nxt_str_eq(&req->parser.method, "GET", 3)) { if (nxt_str_eq(&req->parser.method, "GET", 3)) {
value = nxt_conf_json_get_value(nxt_controller_conf.root, &path); value = nxt_conf_get_path(nxt_controller_conf.root, &path);
if (value == NULL) { if (value == NULL) {
status = 404; status = 404;
goto done; goto done;
} }
resp.json_value = value; resp.conf = value;
status = 200; status = 200;
goto done; goto done;
@@ -602,7 +602,7 @@ nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
} }
if (path.length != 1) { if (path.length != 1) {
rc = nxt_conf_json_op_compile(c->mem_pool, &ops, rc = nxt_conf_op_compile(c->mem_pool, &ops,
nxt_controller_conf.root, nxt_controller_conf.root,
&path, value); &path, value);
@@ -616,8 +616,7 @@ nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
goto done; goto done;
} }
value = nxt_conf_json_clone_value(mp, ops, value = nxt_conf_clone(mp, ops, nxt_controller_conf.root);
nxt_controller_conf.root);
if (nxt_slow_path(value == NULL)) { if (nxt_slow_path(value == NULL)) {
nxt_mp_destroy(mp); nxt_mp_destroy(mp);
@@ -631,7 +630,7 @@ nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
nxt_controller_conf.root = value; nxt_controller_conf.root = value;
nxt_controller_conf.pool = mp; nxt_controller_conf.pool = mp;
nxt_str_set(&resp.json_string, "{ \"success\": \"Updated.\" }"); nxt_str_set(&resp.json, "{ \"success\": \"Updated.\" }");
status = 200; status = 200;
goto done; goto done;
@@ -647,10 +646,10 @@ nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
goto done; goto done;
} }
value = nxt_conf_json_str_parse(mp, &empty_obj); value = nxt_conf_json_parse_str(mp, &empty_obj);
} else { } else {
rc = nxt_conf_json_op_compile(c->mem_pool, &ops, rc = nxt_conf_op_compile(c->mem_pool, &ops,
nxt_controller_conf.root, nxt_controller_conf.root,
&path, NULL); &path, NULL);
@@ -671,8 +670,7 @@ nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
goto done; goto done;
} }
value = nxt_conf_json_clone_value(mp, ops, value = nxt_conf_clone(mp, ops, nxt_controller_conf.root);
nxt_controller_conf.root);
} }
if (nxt_slow_path(value == NULL)) { if (nxt_slow_path(value == NULL)) {
@@ -686,7 +684,7 @@ nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
nxt_controller_conf.root = value; nxt_controller_conf.root = value;
nxt_controller_conf.pool = mp; nxt_controller_conf.pool = mp;
nxt_str_set(&resp.json_string, "{ \"success\": \"Deleted.\" }"); nxt_str_set(&resp.json, "{ \"success\": \"Deleted.\" }");
status = 200; status = 200;
goto done; goto done;
@@ -704,25 +702,22 @@ done:
case 400: case 400:
nxt_str_set(&resp.status_line, "400 Bad Request"); nxt_str_set(&resp.status_line, "400 Bad Request");
nxt_str_set(&resp.json_string, nxt_str_set(&resp.json, "{ \"error\": \"Invalid JSON.\" }");
"{ \"error\": \"Invalid JSON.\" }");
break; break;
case 404: case 404:
nxt_str_set(&resp.status_line, "404 Not Found"); nxt_str_set(&resp.status_line, "404 Not Found");
nxt_str_set(&resp.json_string, nxt_str_set(&resp.json, "{ \"error\": \"Value doesn't exist.\" }");
"{ \"error\": \"Value doesn't exist.\" }");
break; break;
case 405: case 405:
nxt_str_set(&resp.status_line, "405 Method Not Allowed"); nxt_str_set(&resp.status_line, "405 Method Not Allowed");
nxt_str_set(&resp.json_string, "{ \"error\": \"Invalid method.\" }"); nxt_str_set(&resp.json, "{ \"error\": \"Invalid method.\" }");
break; break;
case 500: case 500:
nxt_str_set(&resp.status_line, "500 Internal Server Error"); nxt_str_set(&resp.status_line, "500 Internal Server Error");
nxt_str_set(&resp.json_string, nxt_str_set(&resp.json, "{ \"error\": \"Memory allocation failed.\" }");
"{ \"error\": \"Memory allocation failed.\" }");
break; break;
} }
@@ -772,14 +767,14 @@ nxt_controller_response_body(nxt_controller_response_t *resp, nxt_mp_t *pool)
{ {
size_t size; size_t size;
nxt_buf_t *b; nxt_buf_t *b;
nxt_conf_json_value_t *value; nxt_conf_value_t *value;
nxt_conf_json_pretty_t pretty; nxt_conf_json_pretty_t pretty;
if (resp->json_value) { if (resp->conf) {
value = resp->json_value; value = resp->conf;
} else { } else {
value = nxt_conf_json_str_parse(pool, &resp->json_string); value = nxt_conf_json_parse_str(pool, &resp->json);
if (nxt_slow_path(value == NULL)) { if (nxt_slow_path(value == NULL)) {
return NULL; return NULL;
@@ -788,7 +783,7 @@ nxt_controller_response_body(nxt_controller_response_t *resp, nxt_mp_t *pool)
nxt_memzero(&pretty, sizeof(nxt_conf_json_pretty_t)); nxt_memzero(&pretty, sizeof(nxt_conf_json_pretty_t));
size = nxt_conf_json_value_length(value, &pretty) + 2; size = nxt_conf_json_length(value, &pretty) + 2;
b = nxt_buf_mem_alloc(pool, size, 0); b = nxt_buf_mem_alloc(pool, size, 0);
if (nxt_slow_path(b == NULL)) { if (nxt_slow_path(b == NULL)) {
@@ -797,7 +792,7 @@ nxt_controller_response_body(nxt_controller_response_t *resp, nxt_mp_t *pool)
nxt_memzero(&pretty, sizeof(nxt_conf_json_pretty_t)); nxt_memzero(&pretty, sizeof(nxt_conf_json_pretty_t));
b->mem.free = nxt_conf_json_value_print(b->mem.free, value, &pretty); b->mem.free = nxt_conf_json_print(b->mem.free, value, &pretty);
*b->mem.free++ = '\r'; *b->mem.free++ = '\r';
*b->mem.free++ = '\n'; *b->mem.free++ = '\n';