Object mapping interface extended with more string types.
This commit is contained in:
parent
2dd8048bf9
commit
95907e2912
4 changed files with 52 additions and 15 deletions
|
@ -420,9 +420,10 @@ nxt_conf_get_object_member(nxt_conf_value_t *value, nxt_str_t *name,
|
|||
|
||||
|
||||
nxt_int_t
|
||||
nxt_conf_map_object(nxt_conf_value_t *value, nxt_conf_map_t *map, nxt_uint_t n,
|
||||
void *data)
|
||||
nxt_conf_map_object(nxt_mp_t *mp, nxt_conf_value_t *value, nxt_conf_map_t *map,
|
||||
nxt_uint_t n, void *data)
|
||||
{
|
||||
nxt_str_t str, *s;
|
||||
nxt_uint_t i;
|
||||
nxt_conf_value_t *v;
|
||||
|
||||
|
@ -436,6 +437,7 @@ nxt_conf_map_object(nxt_conf_value_t *value, nxt_conf_map_t *map, nxt_uint_t n,
|
|||
nxt_msec_t msec;
|
||||
double dbl;
|
||||
nxt_str_t str;
|
||||
char *cstrz;
|
||||
void *v;
|
||||
} *ptr;
|
||||
|
||||
|
@ -515,15 +517,48 @@ nxt_conf_map_object(nxt_conf_value_t *value, nxt_conf_map_t *map, nxt_uint_t n,
|
|||
break;
|
||||
|
||||
case NXT_CONF_MAP_STR:
|
||||
case NXT_CONF_MAP_STR_COPY:
|
||||
case NXT_CONF_MAP_CSTRZ:
|
||||
|
||||
if (v->type == NXT_CONF_VALUE_SHORT_STRING
|
||||
|| v->type == NXT_CONF_VALUE_STRING)
|
||||
if (v->type != NXT_CONF_VALUE_SHORT_STRING
|
||||
&& v->type != NXT_CONF_VALUE_STRING)
|
||||
{
|
||||
nxt_conf_get_string(v, &ptr->str);
|
||||
break;
|
||||
}
|
||||
|
||||
nxt_conf_get_string(v, &str);
|
||||
|
||||
switch (map[i].type) {
|
||||
|
||||
case NXT_CONF_MAP_STR:
|
||||
ptr->str = str;
|
||||
break;
|
||||
|
||||
case NXT_CONF_MAP_STR_COPY:
|
||||
|
||||
s = nxt_str_dup(mp, &ptr->str, &str);
|
||||
|
||||
if (nxt_slow_path(s == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case NXT_CONF_MAP_CSTRZ:
|
||||
|
||||
ptr->cstrz = nxt_str_cstrz(mp, &str);
|
||||
|
||||
if (nxt_slow_path(ptr->cstrz == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
nxt_unreachable();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case NXT_CONF_MAP_PTR:
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@ typedef enum {
|
|||
NXT_CONF_MAP_MSEC,
|
||||
NXT_CONF_MAP_DOUBLE,
|
||||
NXT_CONF_MAP_STR,
|
||||
NXT_CONF_MAP_STR_COPY,
|
||||
NXT_CONF_MAP_CSTRZ,
|
||||
NXT_CONF_MAP_PTR,
|
||||
} nxt_conf_map_type_t;
|
||||
|
||||
|
@ -63,8 +65,8 @@ nxt_conf_value_t *nxt_conf_get_object_member(nxt_conf_value_t *value,
|
|||
nxt_conf_value_t *nxt_conf_next_object_member(nxt_conf_value_t *value,
|
||||
nxt_str_t *name, uint32_t *next);
|
||||
|
||||
nxt_int_t nxt_conf_map_object(nxt_conf_value_t *value, nxt_conf_map_t *map,
|
||||
nxt_uint_t n, void *data);
|
||||
nxt_int_t nxt_conf_map_object(nxt_mp_t *mp, nxt_conf_value_t *value,
|
||||
nxt_conf_map_t *map, nxt_uint_t n, void *data);
|
||||
|
||||
nxt_int_t nxt_conf_op_compile(nxt_mp_t *mp, nxt_conf_op_t **ops,
|
||||
nxt_conf_value_t *root, nxt_str_t *path, nxt_conf_value_t *value);
|
||||
|
|
|
@ -190,7 +190,7 @@ nxt_port_master_start_worker_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
|
|||
|
||||
app_conf.user = nobody;
|
||||
|
||||
ret = nxt_conf_map_object(conf, nxt_common_app_conf,
|
||||
ret = nxt_conf_map_object(mp, conf, nxt_common_app_conf,
|
||||
nxt_nitems(nxt_common_app_conf), &app_conf);
|
||||
if (ret != NXT_OK) {
|
||||
nxt_log(task, NXT_LOG_CRIT, "root map error");
|
||||
|
|
|
@ -667,7 +667,9 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||
return NXT_ERROR;
|
||||
}
|
||||
|
||||
ret = nxt_conf_map_object(conf, nxt_router_conf,
|
||||
mp = tmcf->conf->mem_pool;
|
||||
|
||||
ret = nxt_conf_map_object(mp, conf, nxt_router_conf,
|
||||
nxt_nitems(nxt_router_conf), tmcf->conf);
|
||||
if (ret != NXT_OK) {
|
||||
nxt_log(task, NXT_LOG_CRIT, "root map error");
|
||||
|
@ -723,7 +725,7 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||
continue;
|
||||
}
|
||||
|
||||
ret = nxt_conf_map_object(application, nxt_router_app_conf,
|
||||
ret = nxt_conf_map_object(mp, application, nxt_router_app_conf,
|
||||
nxt_nitems(nxt_router_app_conf), &apcf);
|
||||
if (ret != NXT_OK) {
|
||||
nxt_log(task, NXT_LOG_CRIT, "application map error");
|
||||
|
@ -782,8 +784,6 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||
|
||||
next = 0;
|
||||
|
||||
mp = tmcf->conf->mem_pool;
|
||||
|
||||
for ( ;; ) {
|
||||
listener = nxt_conf_next_object_member(listeners, &name, &next);
|
||||
if (listener == NULL) {
|
||||
|
@ -806,7 +806,7 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||
goto fail;
|
||||
}
|
||||
|
||||
ret = nxt_conf_map_object(listener, nxt_router_listener_conf,
|
||||
ret = nxt_conf_map_object(mp, listener, nxt_router_listener_conf,
|
||||
nxt_nitems(nxt_router_listener_conf), &lscf);
|
||||
if (ret != NXT_OK) {
|
||||
nxt_log(task, NXT_LOG_CRIT, "listener map error");
|
||||
|
@ -825,7 +825,7 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||
skcf->body_read_timeout = 5000;
|
||||
|
||||
if (http != NULL) {
|
||||
ret = nxt_conf_map_object(http, nxt_router_http_conf,
|
||||
ret = nxt_conf_map_object(mp, http, nxt_router_http_conf,
|
||||
nxt_nitems(nxt_router_http_conf), skcf);
|
||||
if (ret != NXT_OK) {
|
||||
nxt_log(task, NXT_LOG_CRIT, "http map error");
|
||||
|
|
Loading…
Reference in a new issue