1 
2 
3 ndk_http_complex_path_value_t     ndk_empty_http_complex_path_value = {{0,NULL},0};
4 
5 
6 ngx_int_t
ndk_http_complex_path_value_compile(ngx_conf_t * cf,ngx_http_complex_value_t * cv,ngx_str_t * value,ngx_uint_t prefix)7 ndk_http_complex_path_value_compile (ngx_conf_t *cf, ngx_http_complex_value_t *cv, ngx_str_t *value, ngx_uint_t prefix)
8 {
9     ngx_http_compile_complex_value_t   ccv;
10 
11     ngx_memzero (&ccv, sizeof(ngx_http_compile_complex_value_t));
12 
13     ccv.cf = cf;
14     ccv.value = value;
15     ccv.complex_value = cv;
16 
17     switch (prefix) {
18 
19     case    1 :
20         ccv.root_prefix = 1;
21         break;
22 
23     case    2 :
24         ccv.conf_prefix = 1;
25         break;
26     }
27 
28     ndk_path_to_dir_safe (value, 1, 0);
29 
30     if (!value->len)
31         return  NGX_OK;
32 
33     return  ngx_http_compile_complex_value (&ccv);
34 }
35 
36 
37 
38 ngx_array_t *
ndk_http_complex_path_create_compile(ngx_conf_t * cf,ngx_str_t * path,ngx_uint_t prefix)39 ndk_http_complex_path_create_compile (ngx_conf_t *cf, ngx_str_t *path, ngx_uint_t prefix)
40 {
41     ndk_http_complex_path_elt_t     *cpe;
42     ngx_array_t                     *a;
43     ngx_int_t                        n;
44     u_char                          *m, *s, *e;
45     ngx_str_t                        value;
46 
47     n = ndk_strcntc (path, ':') + 1;
48 
49     a = ngx_array_create (cf->pool, n, sizeof (ndk_http_complex_path_elt_t));
50     if (a == NULL) {
51         return  NULL;
52     }
53 
54     s = path->data;
55     e = s + path->len;
56 
57 
58     while (s < e) {
59 
60         m = s;
61 
62         while (m < e && *m != ':') m++;
63 
64         if (m == s) {
65             s = m+1;
66             continue;
67         }
68 
69         cpe = ngx_array_push (a);
70         if (cpe == NULL) {
71             return  NULL;
72         }
73 
74         if (*s == '#') {
75             s++;
76             cpe->dynamic = 1;
77         } else {
78             cpe->dynamic = 0;
79         }
80 
81         value.data = s;
82         value.len = m - s;
83 
84         if (ndk_http_complex_path_value_compile (cf, &cpe->val, &value, prefix) == NGX_ERROR)
85             return  NULL;
86 
87         s = m+1;
88     }
89 
90     return  a;
91 }
92 
93 
94 
95 
96 char *
ndk_conf_set_http_complex_path_slot(ngx_conf_t * cf,ngx_command_t * cmd,void * conf)97 ndk_conf_set_http_complex_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
98 {
99     char  *p = conf;
100 
101     ngx_str_t                   *path;
102     ngx_array_t                 *a;
103     ngx_conf_post_t             *post;
104     ndk_http_complex_path_t     *cp;
105 
106     cp = (ndk_http_complex_path_t *) (p + cmd->offset);
107 
108     if (cp->a != NGX_CONF_UNSET_PTR) {
109         return  "is duplicate";
110     }
111 
112     path = cf->args->elts;
113     path++;
114 
115     cp->a = ndk_http_complex_path_create_compile (cf, path, cp->prefix);
116     if (cp->a == NULL)
117         /* TODO : log */
118         return  NGX_CONF_ERROR;
119 
120     if (cmd->post) {
121         post = cmd->post;
122         return  post->post_handler (cf, post, a);
123     }
124 
125     return  NGX_CONF_OK;
126 }
127 
128 
129 
130