From 95907e29128c51be79aec0b5149e2639c3fd9042 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Wed, 16 Aug 2017 15:45:12 +0300 Subject: Object mapping interface extended with more string types. --- src/nxt_conf.c | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'src/nxt_conf.c') diff --git a/src/nxt_conf.c b/src/nxt_conf.c index d205ca71..12e35ebc 100644 --- a/src/nxt_conf.c +++ b/src/nxt_conf.c @@ -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; } - 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: -- cgit