diff options
Diffstat (limited to '')
-rw-r--r-- | src/nxt_conf.c | 26 | ||||
-rw-r--r-- | src/nxt_conf.h | 4 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/nxt_conf.c b/src/nxt_conf.c index 8546e2b7..79e776a0 100644 --- a/src/nxt_conf.c +++ b/src/nxt_conf.c @@ -393,6 +393,13 @@ nxt_conf_array_elements_count(nxt_conf_value_t *value) nxt_uint_t +nxt_conf_array_elements_count_or_1(nxt_conf_value_t *value) +{ + return (value->type == NXT_CONF_VALUE_ARRAY) ? value->u.array->count : 1; +} + + +nxt_uint_t nxt_conf_type(nxt_conf_value_t *value) { switch (value->type) { @@ -750,6 +757,25 @@ nxt_conf_get_array_element(nxt_conf_value_t *value, uint32_t index) } +nxt_conf_value_t * +nxt_conf_get_array_element_or_itself(nxt_conf_value_t *value, uint32_t index) +{ + nxt_conf_array_t *array; + + if (value->type != NXT_CONF_VALUE_ARRAY) { + return (index == 0) ? value : NULL; + } + + array = value->u.array; + + if (index >= array->count) { + return NULL; + } + + return &array->elements[index]; +} + + void nxt_conf_array_qsort(nxt_conf_value_t *value, int (*compare)(const void *, const void *)) diff --git a/src/nxt_conf.h b/src/nxt_conf.h index 09f21756..cfbc5991 100644 --- a/src/nxt_conf.h +++ b/src/nxt_conf.h @@ -87,6 +87,8 @@ NXT_EXPORT nxt_conf_value_t *nxt_conf_next_object_member( nxt_conf_value_t *value, nxt_str_t *name, uint32_t *next); NXT_EXPORT nxt_conf_value_t *nxt_conf_get_array_element(nxt_conf_value_t *value, uint32_t index); +NXT_EXPORT nxt_conf_value_t *nxt_conf_get_array_element_or_itself( + nxt_conf_value_t *value, uint32_t index); NXT_EXPORT 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); @@ -139,6 +141,8 @@ void nxt_conf_set_element(nxt_conf_value_t *array, nxt_uint_t index, nxt_int_t nxt_conf_set_element_string_dup(nxt_conf_value_t *array, nxt_mp_t *mp, nxt_uint_t index, nxt_str_t *value); NXT_EXPORT nxt_uint_t nxt_conf_array_elements_count(nxt_conf_value_t *value); +NXT_EXPORT nxt_uint_t nxt_conf_array_elements_count_or_1( + nxt_conf_value_t *value); void nxt_conf_array_qsort(nxt_conf_value_t *value, int (*compare)(const void *, const void *)); |