Mercurial > hg > nginx-vendor-0-6
comparison src/http/ngx_http_config.c @ 140:55a211e5eeb7 NGINX_0_3_17
nginx 0.3.17
*) Change: now on Linux configure checks the presence of epoll and
sendfile64() in kernel.
*) Feature: the "map" directive supports domain names in the
".domain.tld" form.
*) Bugfix: the timeouts were not used in SSL handshake; bug appeared in
0.2.4.
*) Bugfix: in the HTTPS protocol in the "proxy_pass" directive.
*) Bugfix: when the HTTPS protocol was used in the "proxy_pass"
directive the port 80 was used by default.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Sun, 18 Dec 2005 00:00:00 +0300 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
139:9cee8bc94578 | 140:55a211e5eeb7 |
---|---|
1 | |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_event.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
13 ngx_int_t | |
14 ngx_http_config_add_hash(ngx_http_hash_conf_t *h, ngx_str_t *key, void *value, | |
15 ngx_uint_t flags) | |
16 { | |
17 size_t len; | |
18 ngx_str_t *name; | |
19 ngx_uint_t i, k, n, skip; | |
20 ngx_hash_key_t *hk; | |
21 u_char buf[2048]; | |
22 | |
23 if (!(flags & NGX_HTTP_WILDCARD_HASH)) { | |
24 | |
25 /* exact hash */ | |
26 | |
27 k = 0; | |
28 | |
29 for (i = 0; i < key->len; i++) { | |
30 key->data[i] = ngx_tolower(key->data[i]); | |
31 k = ngx_hash(k, key->data[i]); | |
32 } | |
33 | |
34 k %= NGX_HTTP_CONFIG_HASH; | |
35 | |
36 /* check conflicts in exact hash */ | |
37 | |
38 name = h->keys_hash[k].elts; | |
39 | |
40 if (name) { | |
41 for (i = 0; i < h->keys_hash[k].nelts; i++) { | |
42 if (key->len != name[i].len) { | |
43 continue; | |
44 } | |
45 | |
46 if (ngx_strncmp(key->data, name[i].data, key->len) == 0) { | |
47 return NGX_BUSY; | |
48 } | |
49 } | |
50 | |
51 } else { | |
52 if (ngx_array_init(&h->keys_hash[k], h->temp_pool, 4, | |
53 sizeof(ngx_str_t)) | |
54 != NGX_OK) | |
55 { | |
56 return NGX_ERROR; | |
57 } | |
58 } | |
59 | |
60 name = ngx_array_push(&h->keys_hash[k]); | |
61 if (name == NULL) { | |
62 return NGX_ERROR; | |
63 } | |
64 | |
65 *name = *key; | |
66 | |
67 hk = ngx_array_push(&h->keys); | |
68 if (hk == NULL) { | |
69 return NGX_ERROR; | |
70 } | |
71 | |
72 hk->key = *key; | |
73 hk->key_hash = ngx_hash_key(key->data, key->len); | |
74 hk->value = value; | |
75 | |
76 } else { | |
77 | |
78 /* wildcard hash */ | |
79 | |
80 skip = (key->data[0] == '*') ? 2 : 1; | |
81 k = 0; | |
82 | |
83 for (i = skip; i < key->len; i++) { | |
84 key->data[i] = ngx_tolower(key->data[i]); | |
85 k = ngx_hash(k, key->data[i]); | |
86 } | |
87 | |
88 k %= NGX_HTTP_CONFIG_HASH; | |
89 | |
90 if (skip == 1) { | |
91 | |
92 /* check conflicts in exact hash for ".example.com" */ | |
93 | |
94 name = h->keys_hash[k].elts; | |
95 | |
96 if (name) { | |
97 len = key->len - skip; | |
98 | |
99 for (i = 0; i < h->keys_hash[k].nelts; i++) { | |
100 if (len != name[i].len) { | |
101 continue; | |
102 } | |
103 | |
104 if (ngx_strncmp(&key->data[1], name[i].data, len) == 0) { | |
105 return NGX_BUSY; | |
106 } | |
107 } | |
108 | |
109 } else { | |
110 if (ngx_array_init(&h->keys_hash[k], h->temp_pool, 4, | |
111 sizeof(ngx_str_t)) | |
112 != NGX_OK) | |
113 { | |
114 return NGX_ERROR; | |
115 } | |
116 } | |
117 | |
118 name = ngx_array_push(&h->keys_hash[k]); | |
119 if (name == NULL) { | |
120 return NGX_ERROR; | |
121 } | |
122 | |
123 name->len = key->len - 1; | |
124 name->data = ngx_palloc(h->temp_pool, name->len); | |
125 if (name->data == NULL) { | |
126 return NGX_ERROR; | |
127 } | |
128 | |
129 ngx_memcpy(name->data, &key->data[1], name->len); | |
130 } | |
131 | |
132 | |
133 /* | |
134 * convert "*.example.com" to "com.example.\0" | |
135 * and ".example.com" to "com.example\0" | |
136 */ | |
137 | |
138 len = 0; | |
139 n = 0; | |
140 | |
141 for (i = key->len - 1; i; i--) { | |
142 if (key->data[i] == '.') { | |
143 ngx_memcpy(&buf[n], &key->data[i + 1], len); | |
144 n += len; | |
145 buf[n++] = '.'; | |
146 len = 0; | |
147 continue; | |
148 } | |
149 | |
150 len++; | |
151 } | |
152 | |
153 if (len) { | |
154 ngx_memcpy(&buf[n], &key->data[1], len); | |
155 n += len; | |
156 } | |
157 | |
158 buf[n] = '\0'; | |
159 | |
160 | |
161 /* check conflicts in wildcard hash */ | |
162 | |
163 name = h->dns_hash[k].elts; | |
164 | |
165 if (name) { | |
166 len = key->len - skip; | |
167 | |
168 for (i = 0; i < h->dns_hash[k].nelts; i++) { | |
169 if (len != name[i].len) { | |
170 continue; | |
171 } | |
172 | |
173 if (ngx_strncmp(key->data + skip, name[i].data, len) == 0) { | |
174 return NGX_BUSY; | |
175 } | |
176 } | |
177 | |
178 } else { | |
179 if (ngx_array_init(&h->dns_hash[k], h->temp_pool, 4, | |
180 sizeof(ngx_str_t)) | |
181 != NGX_OK) | |
182 { | |
183 return NGX_ERROR; | |
184 } | |
185 } | |
186 | |
187 name = ngx_array_push(&h->dns_hash[k]); | |
188 if (name == NULL) { | |
189 return NGX_ERROR; | |
190 } | |
191 | |
192 name->len = key->len - skip; | |
193 name->data = ngx_palloc(h->temp_pool, name->len); | |
194 if (name->data == NULL) { | |
195 return NGX_ERROR; | |
196 } | |
197 ngx_memcpy(name->data, key->data + skip, name->len); | |
198 | |
199 | |
200 ngx_memcpy(key->data, buf, key->len); | |
201 key->len--; | |
202 | |
203 hk = ngx_array_push(&h->dns_wildcards); | |
204 if (hk == NULL) { | |
205 return NGX_ERROR; | |
206 } | |
207 | |
208 hk->key = *key; | |
209 hk->key_hash = 0; | |
210 hk->value = value; | |
211 } | |
212 | |
213 return NGX_OK; | |
214 } |