xref: /unit/src/nxt_conf.h (revision 2139:99d792169ffb)
129Svbart@nginx.com 
229Svbart@nginx.com /*
329Svbart@nginx.com  * Copyright (C) Igor Sysoev
429Svbart@nginx.com  * Copyright (C) Valentin V. Bartenev
529Svbart@nginx.com  * Copyright (C) NGINX, Inc.
629Svbart@nginx.com  */
729Svbart@nginx.com 
829Svbart@nginx.com #ifndef _NXT_CONF_INCLUDED_
929Svbart@nginx.com #define _NXT_CONF_INCLUDED_
1029Svbart@nginx.com 
1129Svbart@nginx.com 
12357Svbart@nginx.com typedef enum {
13357Svbart@nginx.com     NXT_CONF_NULL = 0,
14357Svbart@nginx.com     NXT_CONF_BOOLEAN,
15357Svbart@nginx.com     NXT_CONF_INTEGER,
16357Svbart@nginx.com     NXT_CONF_NUMBER,
17357Svbart@nginx.com     NXT_CONF_STRING,
18357Svbart@nginx.com     NXT_CONF_ARRAY,
19357Svbart@nginx.com     NXT_CONF_OBJECT,
20357Svbart@nginx.com } nxt_conf_type_t;
21116Svbart@nginx.com 
22116Svbart@nginx.com 
231049Svbart@nginx.com typedef enum {
241049Svbart@nginx.com     NXT_CONF_OP_OK = 0,
251049Svbart@nginx.com     NXT_CONF_OP_NOT_FOUND,
261049Svbart@nginx.com     NXT_CONF_OP_NOT_ALLOWED,
271049Svbart@nginx.com     NXT_CONF_OP_ERROR,
281049Svbart@nginx.com } nxt_conf_op_ret_t;
291049Svbart@nginx.com 
301049Svbart@nginx.com 
31106Svbart@nginx.com typedef struct nxt_conf_value_s  nxt_conf_value_t;
32106Svbart@nginx.com typedef struct nxt_conf_op_s     nxt_conf_op_t;
3329Svbart@nginx.com 
3429Svbart@nginx.com 
35208Svbart@nginx.com typedef struct {
36208Svbart@nginx.com     u_char               *pos;
37208Svbart@nginx.com     u_char               *detail;
38208Svbart@nginx.com } nxt_conf_json_error_t;
39208Svbart@nginx.com 
40208Svbart@nginx.com 
4197Svbart@nginx.com typedef enum {
42106Svbart@nginx.com     NXT_CONF_MAP_INT8,
43106Svbart@nginx.com     NXT_CONF_MAP_INT32,
44106Svbart@nginx.com     NXT_CONF_MAP_INT64,
45106Svbart@nginx.com     NXT_CONF_MAP_INT,
46106Svbart@nginx.com     NXT_CONF_MAP_SIZE,
47106Svbart@nginx.com     NXT_CONF_MAP_OFF,
48111Sigor@sysoev.ru     NXT_CONF_MAP_MSEC,
49106Svbart@nginx.com     NXT_CONF_MAP_DOUBLE,
50106Svbart@nginx.com     NXT_CONF_MAP_STR,
51213Svbart@nginx.com     NXT_CONF_MAP_STR_COPY,
52213Svbart@nginx.com     NXT_CONF_MAP_CSTRZ,
53106Svbart@nginx.com     NXT_CONF_MAP_PTR,
54106Svbart@nginx.com } nxt_conf_map_type_t;
5597Svbart@nginx.com 
5697Svbart@nginx.com 
5745Svbart@nginx.com typedef struct {
58106Svbart@nginx.com     nxt_str_t            name;
59106Svbart@nginx.com     nxt_conf_map_type_t  type;
60106Svbart@nginx.com     size_t               offset;
61106Svbart@nginx.com } nxt_conf_map_t;
6297Svbart@nginx.com 
6397Svbart@nginx.com 
6497Svbart@nginx.com typedef struct {
65106Svbart@nginx.com     uint32_t             level;
66106Svbart@nginx.com     uint8_t              more_space;  /* 1 bit. */
6745Svbart@nginx.com } nxt_conf_json_pretty_t;
6845Svbart@nginx.com 
6945Svbart@nginx.com 
70357Svbart@nginx.com typedef struct {
71357Svbart@nginx.com     nxt_conf_value_t     *conf;
72357Svbart@nginx.com     nxt_mp_t             *pool;
73357Svbart@nginx.com     nxt_str_t            error;
741183Svbart@nginx.com     void                 *ctx;
751969Sz.hong@f5.com     nxt_mp_t             *conf_pool;
761969Sz.hong@f5.com     nxt_uint_t           ver;
77357Svbart@nginx.com } nxt_conf_validation_t;
78357Svbart@nginx.com 
79357Svbart@nginx.com 
80686Svbart@nginx.com NXT_EXPORT nxt_uint_t nxt_conf_type(nxt_conf_value_t *value);
81116Svbart@nginx.com 
82686Svbart@nginx.com NXT_EXPORT nxt_conf_value_t *nxt_conf_get_path(nxt_conf_value_t *value,
83686Svbart@nginx.com     nxt_str_t *path);
84686Svbart@nginx.com NXT_EXPORT nxt_conf_value_t *nxt_conf_get_object_member(nxt_conf_value_t *value,
85106Svbart@nginx.com     nxt_str_t *name, uint32_t *index);
86686Svbart@nginx.com NXT_EXPORT nxt_conf_value_t *nxt_conf_next_object_member(
87686Svbart@nginx.com     nxt_conf_value_t *value, nxt_str_t *name, uint32_t *next);
88686Svbart@nginx.com NXT_EXPORT nxt_conf_value_t *nxt_conf_get_array_element(nxt_conf_value_t *value,
89214Svbart@nginx.com     uint32_t index);
902076Salx.manpages@gmail.com NXT_EXPORT nxt_conf_value_t *nxt_conf_get_array_element_or_itself(
912076Salx.manpages@gmail.com     nxt_conf_value_t *value, uint32_t index);
9251Svbart@nginx.com 
93686Svbart@nginx.com NXT_EXPORT nxt_int_t nxt_conf_map_object(nxt_mp_t *mp, nxt_conf_value_t *value,
94213Svbart@nginx.com     nxt_conf_map_t *map, nxt_uint_t n, void *data);
9597Svbart@nginx.com 
961049Svbart@nginx.com nxt_conf_op_ret_t nxt_conf_op_compile(nxt_mp_t *mp, nxt_conf_op_t **ops,
971049Svbart@nginx.com     nxt_conf_value_t *root, nxt_str_t *path, nxt_conf_value_t *value,
981049Svbart@nginx.com     nxt_bool_t add);
99106Svbart@nginx.com nxt_conf_value_t *nxt_conf_clone(nxt_mp_t *mp, nxt_conf_op_t *op,
100106Svbart@nginx.com     nxt_conf_value_t *value);
10151Svbart@nginx.com 
102208Svbart@nginx.com nxt_conf_value_t *nxt_conf_json_parse(nxt_mp_t *mp, u_char *start, u_char *end,
103208Svbart@nginx.com     nxt_conf_json_error_t *error);
10451Svbart@nginx.com 
105106Svbart@nginx.com #define nxt_conf_json_parse_str(mp, str)                                      \
106208Svbart@nginx.com     nxt_conf_json_parse(mp, (str)->start, (str)->start + (str)->length, NULL)
10791Svbart@nginx.com 
108106Svbart@nginx.com size_t nxt_conf_json_length(nxt_conf_value_t *value,
10992Svbart@nginx.com     nxt_conf_json_pretty_t *pretty);
110106Svbart@nginx.com u_char *nxt_conf_json_print(u_char *p, nxt_conf_value_t *value,
11145Svbart@nginx.com     nxt_conf_json_pretty_t *pretty);
112*2139Sandrew@digital-domain.net void nxt_conf_json_position(u_char *start, const u_char *pos, nxt_uint_t *line,
113208Svbart@nginx.com     nxt_uint_t *column);
11429Svbart@nginx.com 
115357Svbart@nginx.com nxt_int_t nxt_conf_validate(nxt_conf_validation_t *vldt);
116116Svbart@nginx.com 
117686Svbart@nginx.com NXT_EXPORT void nxt_conf_get_string(nxt_conf_value_t *value, nxt_str_t *str);
118773Svbart@nginx.com NXT_EXPORT void nxt_conf_set_string(nxt_conf_value_t *value, nxt_str_t *str);
119774Svbart@nginx.com NXT_EXPORT nxt_int_t nxt_conf_set_string_dup(nxt_conf_value_t *value,
1202075Salx.manpages@gmail.com     nxt_mp_t *mp, const nxt_str_t *str);
1211439Svbart@nginx.com NXT_EXPORT double nxt_conf_get_number(nxt_conf_value_t *value);
1221236St.nateldemoura@f5.com NXT_EXPORT uint8_t nxt_conf_get_boolean(nxt_conf_value_t *value);
123121Svbart@nginx.com 
124121Svbart@nginx.com // FIXME reimplement and reorder functions below
1251473Svbart@nginx.com NXT_EXPORT nxt_uint_t nxt_conf_object_members_count(nxt_conf_value_t *value);
126121Svbart@nginx.com nxt_conf_value_t *nxt_conf_create_object(nxt_mp_t *mp, nxt_uint_t count);
127208Svbart@nginx.com void nxt_conf_set_member(nxt_conf_value_t *object, nxt_str_t *name,
128*2139Sandrew@digital-domain.net     const nxt_conf_value_t *value, uint32_t index);
129208Svbart@nginx.com void nxt_conf_set_member_string(nxt_conf_value_t *object, nxt_str_t *name,
130208Svbart@nginx.com     nxt_str_t *value, uint32_t index);
131774Svbart@nginx.com nxt_int_t nxt_conf_set_member_string_dup(nxt_conf_value_t *object, nxt_mp_t *mp,
132774Svbart@nginx.com     nxt_str_t *name, nxt_str_t *value, uint32_t index);
133208Svbart@nginx.com void nxt_conf_set_member_integer(nxt_conf_value_t *object, nxt_str_t *name,
134208Svbart@nginx.com     int64_t value, uint32_t index);
135774Svbart@nginx.com void nxt_conf_set_member_null(nxt_conf_value_t *object, nxt_str_t *name,
136774Svbart@nginx.com     uint32_t index);
137774Svbart@nginx.com 
138774Svbart@nginx.com nxt_conf_value_t *nxt_conf_create_array(nxt_mp_t *mp, nxt_uint_t count);
139774Svbart@nginx.com void nxt_conf_set_element(nxt_conf_value_t *array, nxt_uint_t index,
140*2139Sandrew@digital-domain.net     const nxt_conf_value_t *value);
141774Svbart@nginx.com nxt_int_t nxt_conf_set_element_string_dup(nxt_conf_value_t *array, nxt_mp_t *mp,
142774Svbart@nginx.com     nxt_uint_t index, nxt_str_t *value);
143977Smax.romanov@gmail.com NXT_EXPORT nxt_uint_t nxt_conf_array_elements_count(nxt_conf_value_t *value);
1442076Salx.manpages@gmail.com NXT_EXPORT nxt_uint_t nxt_conf_array_elements_count_or_1(
1452076Salx.manpages@gmail.com     nxt_conf_value_t *value);
146962Sigor@sysoev.ru void nxt_conf_array_qsort(nxt_conf_value_t *value,
147962Sigor@sysoev.ru     int (*compare)(const void *, const void *));
148121Svbart@nginx.com 
14929Svbart@nginx.com 
15029Svbart@nginx.com #endif /* _NXT_CONF_INCLUDED_ */
151