1 
2 
3 
4 ngx_int_t
ndk_http_complex_value_compile(ngx_conf_t * cf,ngx_http_complex_value_t * cv,ngx_str_t * value)5 ndk_http_complex_value_compile (ngx_conf_t *cf, ngx_http_complex_value_t *cv, ngx_str_t *value)
6 {
7     ngx_http_compile_complex_value_t   ccv;
8 
9     ngx_memzero (&ccv, sizeof(ngx_http_compile_complex_value_t));
10 
11     ccv.cf = cf;
12     ccv.value = value;
13     ccv.complex_value = cv;
14 
15     return  ngx_http_compile_complex_value (&ccv);
16 }
17 
18 
19 
20 
21 ngx_array_t *
ndk_http_complex_value_array_create(ngx_conf_t * cf,char ** s,ngx_int_t n)22 ndk_http_complex_value_array_create (ngx_conf_t *cf, char **s, ngx_int_t n)
23 {
24     ngx_int_t                    i;
25     ngx_http_complex_value_t    *cv;
26     ngx_array_t                 *a;
27     ngx_str_t                    value;
28 
29     a = ngx_array_create (cf->pool, n, sizeof (ngx_http_complex_value_t));
30     if (a == NULL)
31         return  NULL;
32 
33 
34     for (i=0; i<n; i++, s++) {
35 
36         cv = ngx_array_push (a);
37 
38         value.data = (u_char *) *s;
39         value.len = strlen (*s);
40 
41         if (ndk_http_complex_value_compile (cf, cv, &value))
42             return  NULL;
43     }
44 
45     return  a;
46 }
47 
48 
49 
50 ngx_int_t
ndk_http_complex_value_array_compile(ngx_conf_t * cf,ngx_array_t * a)51 ndk_http_complex_value_array_compile (ngx_conf_t *cf, ngx_array_t *a)
52 {
53     ngx_uint_t                  i;
54     ngx_http_complex_value_t   *cv;
55 
56     if (a == NULL || a == NGX_CONF_UNSET_PTR) {
57         return  NGX_ERROR;
58     }
59 
60     cv = a->elts;
61 
62     for (i=0; i<a->nelts; i++, cv++) {
63 
64         if (ndk_http_complex_value_compile (cf, cv, &cv->value))
65             return  NGX_ERROR;
66     }
67 
68     return  NGX_OK;
69 }
70 
71 
72 
73 char *
ndk_conf_set_http_complex_value_slot(ngx_conf_t * cf,ngx_command_t * cmd,void * conf)74 ndk_conf_set_http_complex_value_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
75 {
76     char  *p = conf;
77 
78     ngx_http_complex_value_t    *cv;
79     ngx_str_t                   *value;
80     ngx_conf_post_t             *post;
81 
82     cv = (ngx_http_complex_value_t *) (p + cmd->offset);
83 
84     if (cv->value.data) {
85         return "is duplicate";
86     }
87 
88     value = cf->args->elts;
89 
90     if (ndk_http_complex_value_compile (cf, cv, value + 1))
91         return  NGX_CONF_ERROR;
92 
93     if (cmd->post) {
94         post = cmd->post;
95         return  post->post_handler (cf, post, cv);
96     }
97 
98     return  NGX_CONF_OK;
99 }
100 
101 
102 
103 char *
ndk_conf_set_http_complex_value_array_slot(ngx_conf_t * cf,ngx_command_t * cmd,void * conf)104 ndk_conf_set_http_complex_value_array_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
105 {
106     char *p = conf;
107 
108     ngx_str_t                   *value;
109     ngx_http_complex_value_t    *cv;
110     ngx_array_t                **a;
111     ngx_conf_post_t             *post;
112     ngx_uint_t                   i, alloc;
113 
114     a = (ngx_array_t **) (p + cmd->offset);
115 
116     if (*a == NULL || *a == NGX_CONF_UNSET_PTR) {
117 
118         alloc = cf->args->nelts > 4 ? cf->args->nelts : 4;
119 
120         *a = ngx_array_create (cf->pool, alloc, sizeof (ngx_http_complex_value_t));
121         if (*a == NULL) {
122             return  NGX_CONF_ERROR;
123         }
124     }
125 
126     value = cf->args->elts;
127 
128     for (i=1; i<cf->args->nelts; i++) {
129 
130         cv = ngx_array_push (*a);
131         if (cv == NULL) {
132             return  NGX_CONF_ERROR;
133         }
134 
135         if (ndk_http_complex_value_compile (cf, cv, &value[i]) == NGX_ERROR)
136             return  NGX_CONF_ERROR;
137     }
138 
139 
140     if (cmd->post) {
141         post = cmd->post;
142         return  post->post_handler (cf, post, a);
143     }
144 
145     return  NGX_CONF_OK;
146 }
147 
148 
149 char *
ndk_conf_set_http_complex_keyval_slot(ngx_conf_t * cf,ngx_command_t * cmd,void * conf)150 ndk_conf_set_http_complex_keyval_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
151 {
152     char *p = conf;
153 
154     ngx_str_t                   *value;
155     ndk_http_complex_keyval_t   *ckv;
156     ngx_array_t                **a;
157     ngx_conf_post_t             *post;
158     ngx_int_t                    alloc;
159 
160     a = (ngx_array_t **) (p + cmd->offset);
161 
162     if (*a == NULL || *a == NGX_CONF_UNSET_PTR) {
163 
164         alloc = cf->args->nelts > 4 ? cf->args->nelts : 4;
165 
166         *a = ngx_array_create (cf->pool, alloc, sizeof (ndk_http_complex_keyval_t));
167         if (*a == NULL) {
168             return  NGX_CONF_ERROR;
169         }
170     }
171 
172     ckv = ngx_array_push (*a);
173     if (ckv == NULL) {
174         return  NGX_CONF_ERROR;
175     }
176 
177     value = cf->args->elts;
178 
179     ckv->key = value[1];
180 
181     if (ndk_http_complex_value_compile (cf, &ckv->value, &value[2]) == NGX_ERROR)
182         return  NGX_CONF_ERROR;
183 
184     if (cmd->post) {
185         post = cmd->post;
186         return  post->post_handler (cf, post, a);
187     }
188 
189     return  NGX_CONF_OK;
190 }
191 
192 /* TODO : complex keyval1 */
193