Mercurial > hg > nginx
annotate src/core/ngx_string.c @ 4104:84f34973684c
Version bump.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 14 Sep 2011 15:20:01 +0000 |
parents | 7224d008faaf |
children | 59b99f217c6d |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
5 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
8 #include <ngx_core.h> |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
2293 | 11 static u_char *ngx_sprintf_num(u_char *buf, u_char *last, uint64_t ui64, |
12 u_char zero, ngx_uint_t hexadecimal, ngx_uint_t width); | |
3756
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
13 static ngx_int_t ngx_decode_base64_internal(ngx_str_t *dst, ngx_str_t *src, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
14 const u_char *basis); |
2293 | 15 |
16 | |
2135 | 17 void |
18 ngx_strlow(u_char *dst, u_char *src, size_t n) | |
19 { | |
3275 | 20 while (n) { |
2135 | 21 *dst = ngx_tolower(*src); |
22 dst++; | |
23 src++; | |
3275 | 24 n--; |
2135 | 25 } |
26 } | |
27 | |
28 | |
493 | 29 u_char * |
30 ngx_cpystrn(u_char *dst, u_char *src, size_t n) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
31 { |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
32 if (n == 0) { |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
33 return dst; |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
34 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 |
2919
41e7d9153967
change surplus for() to while()
Igor Sysoev <igor@sysoev.ru>
parents:
2763
diff
changeset
|
36 while (--n) { |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 *dst = *src; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
39 if (*dst == '\0') { |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
40 return dst; |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
41 } |
2919
41e7d9153967
change surplus for() to while()
Igor Sysoev <igor@sysoev.ru>
parents:
2763
diff
changeset
|
42 |
41e7d9153967
change surplus for() to while()
Igor Sysoev <igor@sysoev.ru>
parents:
2763
diff
changeset
|
43 dst++; |
41e7d9153967
change surplus for() to while()
Igor Sysoev <igor@sysoev.ru>
parents:
2763
diff
changeset
|
44 src++; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
47 *dst = '\0'; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
49 return dst; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
50 } |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
51 |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
52 |
493 | 53 u_char * |
54 ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src) | |
485 | 55 { |
56 u_char *dst; | |
57 | |
2049 | 58 dst = ngx_pnalloc(pool, src->len); |
501 | 59 if (dst == NULL) { |
485 | 60 return NULL; |
61 } | |
62 | |
63 ngx_memcpy(dst, src->data, src->len); | |
64 | |
65 return dst; | |
66 } | |
67 | |
68 | |
455 | 69 /* |
70 * supported formats: | |
473 | 71 * %[0][width][x][X]O off_t |
461 | 72 * %[0][width]T time_t |
73 * %[0][width][u][x|X]z ssize_t/size_t | |
74 * %[0][width][u][x|X]d int/u_int | |
75 * %[0][width][u][x|X]l long | |
76 * %[0][width|m][u][x|X]i ngx_int_t/ngx_uint_t | |
77 * %[0][width][u][x|X]D int32_t/uint32_t | |
78 * %[0][width][u][x|X]L int64_t/uint64_t | |
495 | 79 * %[0][width|m][u][x|X]A ngx_atomic_int_t/ngx_atomic_uint_t |
3506
c3fa65192119
use double in %f format to allow %.15f precision
Igor Sysoev <igor@sysoev.ru>
parents:
3486
diff
changeset
|
80 * %[0][width][.width]f double, max valid number fits to %18.15f |
461 | 81 * %P ngx_pid_t |
557 | 82 * %M ngx_msec_t |
461 | 83 * %r rlim_t |
1406
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1405
diff
changeset
|
84 * %p void * |
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1405
diff
changeset
|
85 * %V ngx_str_t * |
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1405
diff
changeset
|
86 * %v ngx_variable_value_t * |
461 | 87 * %s null-terminated string |
1773 | 88 * %*s length and string |
461 | 89 * %Z '\0' |
525 | 90 * %N '\n' |
461 | 91 * %c char |
92 * %% % | |
455 | 93 * |
461 | 94 * reserved: |
95 * %t ptrdiff_t | |
3046 | 96 * %S null-terminated wchar string |
461 | 97 * %C wchar |
455 | 98 */ |
99 | |
461 | 100 |
503 | 101 u_char * ngx_cdecl |
493 | 102 ngx_sprintf(u_char *buf, const char *fmt, ...) |
461 | 103 { |
104 u_char *p; | |
105 va_list args; | |
106 | |
107 va_start(args, fmt); | |
2763
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
108 p = ngx_vslprintf(buf, (void *) -1, fmt, args); |
461 | 109 va_end(args); |
110 | |
111 return p; | |
112 } | |
113 | |
114 | |
503 | 115 u_char * ngx_cdecl |
493 | 116 ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...) |
455 | 117 { |
461 | 118 u_char *p; |
119 va_list args; | |
120 | |
121 va_start(args, fmt); | |
2763
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
122 p = ngx_vslprintf(buf, buf + max, fmt, args); |
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
123 va_end(args); |
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
124 |
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
125 return p; |
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
126 } |
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
127 |
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
128 |
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
129 u_char * ngx_cdecl |
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
130 ngx_slprintf(u_char *buf, u_char *last, const char *fmt, ...) |
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
131 { |
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
132 u_char *p; |
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
133 va_list args; |
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
134 |
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
135 va_start(args, fmt); |
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
136 p = ngx_vslprintf(buf, last, fmt, args); |
461 | 137 va_end(args); |
138 | |
139 return p; | |
140 } | |
141 | |
455 | 142 |
493 | 143 u_char * |
2763
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
144 ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args) |
461 | 145 { |
2763
819bea4e964e
ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2680
diff
changeset
|
146 u_char *p, zero; |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1298
diff
changeset
|
147 int d; |
3506
c3fa65192119
use double in %f format to allow %.15f precision
Igor Sysoev <igor@sysoev.ru>
parents:
3486
diff
changeset
|
148 double f, scale; |
1773 | 149 size_t len, slen; |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1298
diff
changeset
|
150 int64_t i64; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1298
diff
changeset
|
151 uint64_t ui64; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1298
diff
changeset
|
152 ngx_msec_t ms; |
3275 | 153 ngx_uint_t width, sign, hex, max_width, frac_width, n; |
1406
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1405
diff
changeset
|
154 ngx_str_t *v; |
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1405
diff
changeset
|
155 ngx_variable_value_t *vv; |
455 | 156 |
461 | 157 while (*fmt && buf < last) { |
158 | |
159 /* | |
160 * "buf < last" means that we could copy at least one character: | |
161 * the plain character, "%%", "%c", and minus without the checking | |
162 */ | |
163 | |
455 | 164 if (*fmt == '%') { |
165 | |
461 | 166 i64 = 0; |
167 ui64 = 0; | |
168 | |
169 zero = (u_char) ((*++fmt == '0') ? '0' : ' '); | |
455 | 170 width = 0; |
171 sign = 1; | |
2293 | 172 hex = 0; |
493 | 173 max_width = 0; |
2293 | 174 frac_width = 0; |
1863 | 175 slen = (size_t) -1; |
455 | 176 |
177 while (*fmt >= '0' && *fmt <= '9') { | |
178 width = width * 10 + *fmt++ - '0'; | |
179 } | |
180 | |
181 | |
182 for ( ;; ) { | |
183 switch (*fmt) { | |
184 | |
185 case 'u': | |
186 sign = 0; | |
187 fmt++; | |
188 continue; | |
189 | |
467 | 190 case 'm': |
493 | 191 max_width = 1; |
467 | 192 fmt++; |
193 continue; | |
194 | |
461 | 195 case 'X': |
2293 | 196 hex = 2; |
461 | 197 sign = 0; |
198 fmt++; | |
199 continue; | |
200 | |
455 | 201 case 'x': |
2293 | 202 hex = 1; |
461 | 203 sign = 0; |
455 | 204 fmt++; |
205 continue; | |
206 | |
2293 | 207 case '.': |
208 fmt++; | |
209 | |
210 while (*fmt >= '0' && *fmt <= '9') { | |
211 frac_width = frac_width * 10 + *fmt++ - '0'; | |
212 } | |
213 | |
214 break; | |
215 | |
1773 | 216 case '*': |
1866 | 217 slen = va_arg(args, size_t); |
1773 | 218 fmt++; |
219 continue; | |
220 | |
455 | 221 default: |
222 break; | |
223 } | |
224 | |
225 break; | |
226 } | |
227 | |
228 | |
229 switch (*fmt) { | |
230 | |
461 | 231 case 'V': |
1406
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1405
diff
changeset
|
232 v = va_arg(args, ngx_str_t *); |
455 | 233 |
3515 | 234 len = ngx_min(((size_t) (last - buf)), v->len); |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1298
diff
changeset
|
235 buf = ngx_cpymem(buf, v->data, len); |
461 | 236 fmt++; |
455 | 237 |
461 | 238 continue; |
455 | 239 |
1406
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1405
diff
changeset
|
240 case 'v': |
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1405
diff
changeset
|
241 vv = va_arg(args, ngx_variable_value_t *); |
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1405
diff
changeset
|
242 |
3515 | 243 len = ngx_min(((size_t) (last - buf)), vv->len); |
1406
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1405
diff
changeset
|
244 buf = ngx_cpymem(buf, vv->data, len); |
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1405
diff
changeset
|
245 fmt++; |
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1405
diff
changeset
|
246 |
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1405
diff
changeset
|
247 continue; |
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1405
diff
changeset
|
248 |
455 | 249 case 's': |
461 | 250 p = va_arg(args, u_char *); |
455 | 251 |
1863 | 252 if (slen == (size_t) -1) { |
1773 | 253 while (*p && buf < last) { |
254 *buf++ = *p++; | |
255 } | |
256 | |
257 } else { | |
3515 | 258 len = ngx_min(((size_t) (last - buf)), slen); |
1867 | 259 buf = ngx_cpymem(buf, p, len); |
455 | 260 } |
1773 | 261 |
455 | 262 fmt++; |
263 | |
264 continue; | |
265 | |
461 | 266 case 'O': |
267 i64 = (int64_t) va_arg(args, off_t); | |
268 sign = 1; | |
269 break; | |
270 | |
271 case 'P': | |
272 i64 = (int64_t) va_arg(args, ngx_pid_t); | |
273 sign = 1; | |
274 break; | |
275 | |
276 case 'T': | |
277 i64 = (int64_t) va_arg(args, time_t); | |
278 sign = 1; | |
279 break; | |
280 | |
557 | 281 case 'M': |
561 | 282 ms = (ngx_msec_t) va_arg(args, ngx_msec_t); |
283 if ((ngx_msec_int_t) ms == -1) { | |
284 sign = 1; | |
285 i64 = -1; | |
286 } else { | |
287 sign = 0; | |
288 ui64 = (uint64_t) ms; | |
289 } | |
557 | 290 break; |
291 | |
461 | 292 case 'z': |
293 if (sign) { | |
294 i64 = (int64_t) va_arg(args, ssize_t); | |
295 } else { | |
296 ui64 = (uint64_t) va_arg(args, size_t); | |
297 } | |
298 break; | |
299 | |
300 case 'i': | |
301 if (sign) { | |
302 i64 = (int64_t) va_arg(args, ngx_int_t); | |
303 } else { | |
304 ui64 = (uint64_t) va_arg(args, ngx_uint_t); | |
305 } | |
493 | 306 |
307 if (max_width) { | |
308 width = NGX_INT_T_LEN; | |
309 } | |
310 | |
461 | 311 break; |
312 | |
313 case 'd': | |
314 if (sign) { | |
315 i64 = (int64_t) va_arg(args, int); | |
316 } else { | |
317 ui64 = (uint64_t) va_arg(args, u_int); | |
318 } | |
319 break; | |
320 | |
321 case 'l': | |
322 if (sign) { | |
323 i64 = (int64_t) va_arg(args, long); | |
324 } else { | |
325 ui64 = (uint64_t) va_arg(args, u_long); | |
326 } | |
327 break; | |
328 | |
329 case 'D': | |
330 if (sign) { | |
331 i64 = (int64_t) va_arg(args, int32_t); | |
332 } else { | |
333 ui64 = (uint64_t) va_arg(args, uint32_t); | |
334 } | |
335 break; | |
336 | |
337 case 'L': | |
338 if (sign) { | |
339 i64 = va_arg(args, int64_t); | |
340 } else { | |
341 ui64 = va_arg(args, uint64_t); | |
342 } | |
343 break; | |
344 | |
493 | 345 case 'A': |
346 if (sign) { | |
347 i64 = (int64_t) va_arg(args, ngx_atomic_int_t); | |
348 } else { | |
495 | 349 ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t); |
493 | 350 } |
351 | |
352 if (max_width) { | |
353 width = NGX_ATOMIC_T_LEN; | |
354 } | |
355 | |
356 break; | |
357 | |
2293 | 358 case 'f': |
3506
c3fa65192119
use double in %f format to allow %.15f precision
Igor Sysoev <igor@sysoev.ru>
parents:
3486
diff
changeset
|
359 f = va_arg(args, double); |
2293 | 360 |
361 if (f < 0) { | |
362 *buf++ = '-'; | |
363 f = -f; | |
364 } | |
365 | |
366 ui64 = (int64_t) f; | |
367 | |
368 buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width); | |
369 | |
370 if (frac_width) { | |
371 | |
372 if (buf < last) { | |
373 *buf++ = '.'; | |
374 } | |
375 | |
376 scale = 1.0; | |
377 | |
3275 | 378 for (n = frac_width; n; n--) { |
2293 | 379 scale *= 10.0; |
380 } | |
381 | |
382 /* | |
383 * (int64_t) cast is required for msvc6: | |
384 * it can not convert uint64_t to double | |
385 */ | |
3507
76fc7ad463cb
fix rounding issues in %f format
Igor Sysoev <igor@sysoev.ru>
parents:
3506
diff
changeset
|
386 ui64 = (uint64_t) ((f - (int64_t) ui64) * scale + 0.5); |
2293 | 387 |
388 buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width); | |
389 } | |
390 | |
391 fmt++; | |
392 | |
393 continue; | |
394 | |
461 | 395 #if !(NGX_WIN32) |
396 case 'r': | |
397 i64 = (int64_t) va_arg(args, rlim_t); | |
398 sign = 1; | |
399 break; | |
400 #endif | |
401 | |
402 case 'p': | |
403 ui64 = (uintptr_t) va_arg(args, void *); | |
2293 | 404 hex = 2; |
461 | 405 sign = 0; |
406 zero = '0'; | |
613 | 407 width = NGX_PTR_SIZE * 2; |
461 | 408 break; |
409 | |
457 | 410 case 'c': |
461 | 411 d = va_arg(args, int); |
457 | 412 *buf++ = (u_char) (d & 0xff); |
413 fmt++; | |
414 | |
415 continue; | |
416 | |
461 | 417 case 'Z': |
418 *buf++ = '\0'; | |
419 fmt++; | |
420 | |
421 continue; | |
422 | |
525 | 423 case 'N': |
424 #if (NGX_WIN32) | |
425 *buf++ = CR; | |
426 #endif | |
427 *buf++ = LF; | |
428 fmt++; | |
429 | |
430 continue; | |
431 | |
455 | 432 case '%': |
433 *buf++ = '%'; | |
434 fmt++; | |
435 | |
436 continue; | |
437 | |
438 default: | |
439 *buf++ = *fmt++; | |
440 | |
441 continue; | |
442 } | |
443 | |
461 | 444 if (sign) { |
445 if (i64 < 0) { | |
446 *buf++ = '-'; | |
447 ui64 = (uint64_t) -i64; | |
448 | |
449 } else { | |
450 ui64 = (uint64_t) i64; | |
451 } | |
452 } | |
453 | |
2293 | 454 buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width); |
455 | 455 |
456 fmt++; | |
457 | |
458 } else { | |
459 *buf++ = *fmt++; | |
460 } | |
461 } | |
462 | |
463 return buf; | |
464 } | |
465 | |
466 | |
2293 | 467 static u_char * |
468 ngx_sprintf_num(u_char *buf, u_char *last, uint64_t ui64, u_char zero, | |
469 ngx_uint_t hexadecimal, ngx_uint_t width) | |
470 { | |
471 u_char *p, temp[NGX_INT64_LEN + 1]; | |
472 /* | |
473 * we need temp[NGX_INT64_LEN] only, | |
474 * but icc issues the warning | |
475 */ | |
476 size_t len; | |
477 uint32_t ui32; | |
478 static u_char hex[] = "0123456789abcdef"; | |
479 static u_char HEX[] = "0123456789ABCDEF"; | |
480 | |
481 p = temp + NGX_INT64_LEN; | |
482 | |
483 if (hexadecimal == 0) { | |
484 | |
485 if (ui64 <= NGX_MAX_UINT32_VALUE) { | |
486 | |
487 /* | |
488 * To divide 64-bit numbers and to find remainders | |
489 * on the x86 platform gcc and icc call the libc functions | |
490 * [u]divdi3() and [u]moddi3(), they call another function | |
491 * in its turn. On FreeBSD it is the qdivrem() function, | |
492 * its source code is about 170 lines of the code. | |
493 * The glibc counterpart is about 150 lines of the code. | |
494 * | |
495 * For 32-bit numbers and some divisors gcc and icc use | |
496 * a inlined multiplication and shifts. For example, | |
497 * unsigned "i32 / 10" is compiled to | |
498 * | |
499 * (i32 * 0xCCCCCCCD) >> 35 | |
500 */ | |
501 | |
502 ui32 = (uint32_t) ui64; | |
503 | |
504 do { | |
505 *--p = (u_char) (ui32 % 10 + '0'); | |
506 } while (ui32 /= 10); | |
507 | |
508 } else { | |
509 do { | |
510 *--p = (u_char) (ui64 % 10 + '0'); | |
511 } while (ui64 /= 10); | |
512 } | |
513 | |
514 } else if (hexadecimal == 1) { | |
515 | |
516 do { | |
517 | |
518 /* the "(uint32_t)" cast disables the BCC's warning */ | |
519 *--p = hex[(uint32_t) (ui64 & 0xf)]; | |
520 | |
521 } while (ui64 >>= 4); | |
522 | |
523 } else { /* hexadecimal == 2 */ | |
524 | |
525 do { | |
526 | |
527 /* the "(uint32_t)" cast disables the BCC's warning */ | |
528 *--p = HEX[(uint32_t) (ui64 & 0xf)]; | |
529 | |
530 } while (ui64 >>= 4); | |
531 } | |
532 | |
533 /* zero or space padding */ | |
534 | |
535 len = (temp + NGX_INT64_LEN) - p; | |
536 | |
537 while (len++ < width && buf < last) { | |
538 *buf++ = zero; | |
539 } | |
540 | |
541 /* number safe copy */ | |
542 | |
543 len = (temp + NGX_INT64_LEN) - p; | |
544 | |
545 if (buf + len > last) { | |
546 len = last - buf; | |
547 } | |
548 | |
549 return ngx_cpymem(buf, p, len); | |
550 } | |
551 | |
552 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
553 /* |
1541 | 554 * We use ngx_strcasecmp()/ngx_strncasecmp() for 7-bit ASCII strings only, |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
555 * and implement our own ngx_strcasecmp()/ngx_strncasecmp() |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
556 * to avoid libc locale overhead. Besides, we use the ngx_uint_t's |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
557 * instead of the u_char's, because they are slightly faster. |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
558 */ |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
559 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
560 ngx_int_t |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
561 ngx_strcasecmp(u_char *s1, u_char *s2) |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
562 { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
563 ngx_uint_t c1, c2; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
564 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
565 for ( ;; ) { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
566 c1 = (ngx_uint_t) *s1++; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
567 c2 = (ngx_uint_t) *s2++; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
568 |
3115 | 569 c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1; |
570 c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2; | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
571 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
572 if (c1 == c2) { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
573 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
574 if (c1) { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
575 continue; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
576 } |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
577 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
578 return 0; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
579 } |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
580 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
581 return c1 - c2; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
582 } |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
583 } |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
584 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
585 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
586 ngx_int_t |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
587 ngx_strncasecmp(u_char *s1, u_char *s2, size_t n) |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
588 { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
589 ngx_uint_t c1, c2; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
590 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
591 while (n) { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
592 c1 = (ngx_uint_t) *s1++; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
593 c2 = (ngx_uint_t) *s2++; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
594 |
3115 | 595 c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1; |
596 c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2; | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
597 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
598 if (c1 == c2) { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
599 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
600 if (c1) { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
601 n--; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
602 continue; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
603 } |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
604 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
605 return 0; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
606 } |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
607 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
608 return c1 - c2; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
609 } |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
610 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
611 return 0; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
612 } |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
613 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
614 |
1552 | 615 u_char * |
616 ngx_strnstr(u_char *s1, char *s2, size_t len) | |
617 { | |
618 u_char c1, c2; | |
619 size_t n; | |
620 | |
621 c2 = *(u_char *) s2++; | |
622 | |
623 n = ngx_strlen(s2); | |
624 | |
625 do { | |
626 do { | |
627 if (len-- == 0) { | |
628 return NULL; | |
629 } | |
630 | |
631 c1 = *s1++; | |
632 | |
633 if (c1 == 0) { | |
634 return NULL; | |
635 } | |
636 | |
637 } while (c1 != c2); | |
638 | |
639 if (n > len) { | |
640 return NULL; | |
641 } | |
642 | |
643 } while (ngx_strncmp(s1, (u_char *) s2, n) != 0); | |
644 | |
645 return --s1; | |
646 } | |
647 | |
648 | |
1550 | 649 /* |
650 * ngx_strstrn() and ngx_strcasestrn() are intended to search for static | |
651 * substring with known length in null-terminated string. The argument n | |
652 * must be length of the second substring - 1. | |
653 */ | |
654 | |
1542
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
655 u_char * |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
656 ngx_strstrn(u_char *s1, char *s2, size_t n) |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
657 { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
658 u_char c1, c2; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
659 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
660 c2 = *(u_char *) s2++; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
661 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
662 do { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
663 do { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
664 c1 = *s1++; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
665 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
666 if (c1 == 0) { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
667 return NULL; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
668 } |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
669 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
670 } while (c1 != c2); |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
671 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
672 } while (ngx_strncmp(s1, (u_char *) s2, n) != 0); |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
673 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
674 return --s1; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
675 } |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
676 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
677 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
678 u_char * |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
679 ngx_strcasestrn(u_char *s1, char *s2, size_t n) |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
680 { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
681 ngx_uint_t c1, c2; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
682 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
683 c2 = (ngx_uint_t) *s2++; |
3115 | 684 c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2; |
1542
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
685 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
686 do { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
687 do { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
688 c1 = (ngx_uint_t) *s1++; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
689 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
690 if (c1 == 0) { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
691 return NULL; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
692 } |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
693 |
3115 | 694 c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1; |
1542
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
695 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
696 } while (c1 != c2); |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
697 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
698 } while (ngx_strncasecmp(s1, (u_char *) s2, n) != 0); |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
699 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
700 return --s1; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
701 } |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
702 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
703 |
2668 | 704 /* |
705 * ngx_strlcasestrn() is intended to search for static substring | |
706 * with known length in string until the argument last. The argument n | |
707 * must be length of the second substring - 1. | |
708 */ | |
709 | |
710 u_char * | |
711 ngx_strlcasestrn(u_char *s1, u_char *last, u_char *s2, size_t n) | |
712 { | |
713 ngx_uint_t c1, c2; | |
714 | |
715 c2 = (ngx_uint_t) *s2++; | |
3115 | 716 c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2; |
2668 | 717 last -= n; |
718 | |
719 do { | |
720 do { | |
2680
82e3946062be
backout r2677 and fix ngx_strlcasestrn() again
Igor Sysoev <igor@sysoev.ru>
parents:
2676
diff
changeset
|
721 if (s1 >= last) { |
2668 | 722 return NULL; |
723 } | |
724 | |
725 c1 = (ngx_uint_t) *s1++; | |
726 | |
3115 | 727 c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1; |
2668 | 728 |
729 } while (c1 != c2); | |
730 | |
731 } while (ngx_strncasecmp(s1, s2, n) != 0); | |
732 | |
733 return --s1; | |
734 } | |
735 | |
736 | |
493 | 737 ngx_int_t |
738 ngx_rstrncmp(u_char *s1, u_char *s2, size_t n) | |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
739 { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
740 if (n == 0) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
741 return 0; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
742 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
743 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
744 n--; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
745 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
746 for ( ;; ) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
747 if (s1[n] != s2[n]) { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
748 return s1[n] - s2[n]; |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
749 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
750 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
751 if (n == 0) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
752 return 0; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
753 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
754 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
755 n--; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
756 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
757 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
758 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
759 |
493 | 760 ngx_int_t |
761 ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n) | |
455 | 762 { |
763 u_char c1, c2; | |
764 | |
765 if (n == 0) { | |
766 return 0; | |
767 } | |
768 | |
769 n--; | |
770 | |
771 for ( ;; ) { | |
772 c1 = s1[n]; | |
773 if (c1 >= 'a' && c1 <= 'z') { | |
774 c1 -= 'a' - 'A'; | |
775 } | |
776 | |
777 c2 = s2[n]; | |
778 if (c2 >= 'a' && c2 <= 'z') { | |
779 c2 -= 'a' - 'A'; | |
780 } | |
781 | |
782 if (c1 != c2) { | |
783 return c1 - c2; | |
784 } | |
785 | |
786 if (n == 0) { | |
787 return 0; | |
788 } | |
789 | |
790 n--; | |
791 } | |
792 } | |
793 | |
794 | |
493 | 795 ngx_int_t |
1029
ce08bc4cb97b
ngx_strn2cmp() > ngx_memn2cmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1024
diff
changeset
|
796 ngx_memn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2) |
1024 | 797 { |
798 size_t n; | |
799 ngx_int_t m, z; | |
800 | |
801 if (n1 <= n2) { | |
802 n = n1; | |
803 z = -1; | |
804 | |
805 } else { | |
806 n = n2; | |
807 z = 1; | |
808 } | |
809 | |
1029
ce08bc4cb97b
ngx_strn2cmp() > ngx_memn2cmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1024
diff
changeset
|
810 m = ngx_memcmp(s1, s2, n); |
1024 | 811 |
812 if (m || n1 == n2) { | |
813 return m; | |
814 } | |
815 | |
816 return z; | |
817 } | |
818 | |
819 | |
820 ngx_int_t | |
3116
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
821 ngx_dns_strcmp(u_char *s1, u_char *s2) |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
822 { |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
823 ngx_uint_t c1, c2; |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
824 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
825 for ( ;; ) { |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
826 c1 = (ngx_uint_t) *s1++; |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
827 c2 = (ngx_uint_t) *s2++; |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
828 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
829 c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1; |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
830 c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2; |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
831 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
832 if (c1 == c2) { |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
833 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
834 if (c1) { |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
835 continue; |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
836 } |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
837 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
838 return 0; |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
839 } |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
840 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
841 /* in ASCII '.' > '-', but we need '.' to be the lowest character */ |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
842 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
843 c1 = (c1 == '.') ? ' ' : c1; |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
844 c2 = (c2 == '.') ? ' ' : c2; |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
845 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
846 return c1 - c2; |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
847 } |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
848 } |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
849 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
850 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
851 ngx_int_t |
493 | 852 ngx_atoi(u_char *line, size_t n) |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
853 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
854 ngx_int_t value; |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
855 |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
856 if (n == 0) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
857 return NGX_ERROR; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
858 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
859 |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
860 for (value = 0; n--; line++) { |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
861 if (*line < '0' || *line > '9') { |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
862 return NGX_ERROR; |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
863 } |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
864 |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
865 value = value * 10 + (*line - '0'); |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
866 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
867 |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
868 if (value < 0) { |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
869 return NGX_ERROR; |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
870 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
871 } else { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
872 return value; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
873 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
874 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
875 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
876 |
3512 | 877 /* parse a fixed point number, e.g., ngx_atofp("10.5", 4, 2) returns 1050 */ |
878 | |
879 ngx_int_t | |
880 ngx_atofp(u_char *line, size_t n, size_t point) | |
881 { | |
882 ngx_int_t value; | |
883 ngx_uint_t dot; | |
884 | |
885 if (n == 0) { | |
886 return NGX_ERROR; | |
887 } | |
888 | |
889 dot = 0; | |
890 | |
891 for (value = 0; n--; line++) { | |
892 | |
893 if (point == 0) { | |
894 return NGX_ERROR; | |
895 } | |
896 | |
897 if (*line == '.') { | |
898 if (dot) { | |
899 return NGX_ERROR; | |
900 } | |
901 | |
902 dot = 1; | |
903 continue; | |
904 } | |
905 | |
906 if (*line < '0' || *line > '9') { | |
907 return NGX_ERROR; | |
908 } | |
909 | |
910 value = value * 10 + (*line - '0'); | |
911 point -= dot; | |
912 } | |
913 | |
914 while (point--) { | |
915 value = value * 10; | |
916 } | |
917 | |
918 if (value < 0) { | |
919 return NGX_ERROR; | |
920 | |
921 } else { | |
922 return value; | |
923 } | |
924 } | |
925 | |
926 | |
501 | 927 ssize_t |
928 ngx_atosz(u_char *line, size_t n) | |
929 { | |
930 ssize_t value; | |
931 | |
932 if (n == 0) { | |
933 return NGX_ERROR; | |
934 } | |
935 | |
936 for (value = 0; n--; line++) { | |
937 if (*line < '0' || *line > '9') { | |
938 return NGX_ERROR; | |
939 } | |
940 | |
941 value = value * 10 + (*line - '0'); | |
942 } | |
943 | |
944 if (value < 0) { | |
945 return NGX_ERROR; | |
946 | |
947 } else { | |
948 return value; | |
949 } | |
950 } | |
951 | |
952 | |
953 off_t | |
954 ngx_atoof(u_char *line, size_t n) | |
955 { | |
956 off_t value; | |
957 | |
958 if (n == 0) { | |
959 return NGX_ERROR; | |
960 } | |
961 | |
962 for (value = 0; n--; line++) { | |
963 if (*line < '0' || *line > '9') { | |
964 return NGX_ERROR; | |
965 } | |
966 | |
967 value = value * 10 + (*line - '0'); | |
968 } | |
969 | |
970 if (value < 0) { | |
971 return NGX_ERROR; | |
972 | |
973 } else { | |
974 return value; | |
975 } | |
976 } | |
977 | |
978 | |
979 time_t | |
980 ngx_atotm(u_char *line, size_t n) | |
981 { | |
982 time_t value; | |
983 | |
984 if (n == 0) { | |
985 return NGX_ERROR; | |
986 } | |
987 | |
988 for (value = 0; n--; line++) { | |
989 if (*line < '0' || *line > '9') { | |
990 return NGX_ERROR; | |
991 } | |
992 | |
993 value = value * 10 + (*line - '0'); | |
994 } | |
995 | |
996 if (value < 0) { | |
997 return NGX_ERROR; | |
998 | |
999 } else { | |
1000 return value; | |
1001 } | |
1002 } | |
1003 | |
1004 | |
493 | 1005 ngx_int_t |
1006 ngx_hextoi(u_char *line, size_t n) | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1007 { |
783 | 1008 u_char c, ch; |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1009 ngx_int_t value; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1010 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1011 if (n == 0) { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1012 return NGX_ERROR; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1013 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1014 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1015 for (value = 0; n--; line++) { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1016 ch = *line; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1017 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1018 if (ch >= '0' && ch <= '9') { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1019 value = value * 16 + (ch - '0'); |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1020 continue; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1021 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1022 |
783 | 1023 c = (u_char) (ch | 0x20); |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1024 |
783 | 1025 if (c >= 'a' && c <= 'f') { |
1026 value = value * 16 + (c - 'a' + 10); | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1027 continue; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1028 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1029 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1030 return NGX_ERROR; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1031 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1032 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1033 if (value < 0) { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1034 return NGX_ERROR; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1035 |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1036 } else { |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1037 return value; |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1038 } |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1039 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1040 |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1041 |
1745
ec63069aeb78
replace ngx_md5_text() with ngx_hex_dump()
Igor Sysoev <igor@sysoev.ru>
parents:
1629
diff
changeset
|
1042 u_char * |
ec63069aeb78
replace ngx_md5_text() with ngx_hex_dump()
Igor Sysoev <igor@sysoev.ru>
parents:
1629
diff
changeset
|
1043 ngx_hex_dump(u_char *dst, u_char *src, size_t len) |
174
ea464a6c0581
nginx-0.0.1-2003-11-05-01:12:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
1044 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
1045 static u_char hex[] = "0123456789abcdef"; |
175
e92c2c647c57
nginx-0.0.1-2003-11-05-20:03:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
174
diff
changeset
|
1046 |
1745
ec63069aeb78
replace ngx_md5_text() with ngx_hex_dump()
Igor Sysoev <igor@sysoev.ru>
parents:
1629
diff
changeset
|
1047 while (len--) { |
ec63069aeb78
replace ngx_md5_text() with ngx_hex_dump()
Igor Sysoev <igor@sysoev.ru>
parents:
1629
diff
changeset
|
1048 *dst++ = hex[*src >> 4]; |
ec63069aeb78
replace ngx_md5_text() with ngx_hex_dump()
Igor Sysoev <igor@sysoev.ru>
parents:
1629
diff
changeset
|
1049 *dst++ = hex[*src++ & 0xf]; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
1050 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
1051 |
1745
ec63069aeb78
replace ngx_md5_text() with ngx_hex_dump()
Igor Sysoev <igor@sysoev.ru>
parents:
1629
diff
changeset
|
1052 return dst; |
174
ea464a6c0581
nginx-0.0.1-2003-11-05-01:12:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
1053 } |
ea464a6c0581
nginx-0.0.1-2003-11-05-01:12:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
1054 |
ea464a6c0581
nginx-0.0.1-2003-11-05-01:12:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
1055 |
493 | 1056 void |
1057 ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src) | |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1058 { |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1059 u_char *d, *s; |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1060 size_t len; |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1061 static u_char basis64[] = |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1062 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1063 |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
1064 len = src->len; |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1065 s = src->data; |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
1066 d = dst->data; |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1067 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1068 while (len > 2) { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1069 *d++ = basis64[(s[0] >> 2) & 0x3f]; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1070 *d++ = basis64[((s[0] & 3) << 4) | (s[1] >> 4)]; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1071 *d++ = basis64[((s[1] & 0x0f) << 2) | (s[2] >> 6)]; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1072 *d++ = basis64[s[2] & 0x3f]; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1073 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1074 s += 3; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1075 len -= 3; |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1076 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1077 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1078 if (len) { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1079 *d++ = basis64[(s[0] >> 2) & 0x3f]; |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1080 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1081 if (len == 1) { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1082 *d++ = basis64[(s[0] & 3) << 4]; |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1083 *d++ = '='; |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1084 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1085 } else { |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1086 *d++ = basis64[((s[0] & 3) << 4) | (s[1] >> 4)]; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1087 *d++ = basis64[(s[1] & 0x0f) << 2]; |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1088 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1089 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1090 *d++ = '='; |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1091 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1092 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1093 dst->len = d - dst->data; |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1094 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1095 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1096 |
493 | 1097 ngx_int_t |
1098 ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src) | |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1099 { |
827 | 1100 static u_char basis64[] = { |
1101 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1102 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1103 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 62, 77, 77, 77, 63, | |
1104 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 77, 77, 77, 77, 77, 77, | |
1105 77, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, | |
1106 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 77, 77, 77, 77, 77, | |
1107 77, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, | |
1108 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 77, 77, 77, 77, 77, | |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1109 |
827 | 1110 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
1111 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1112 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1113 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1114 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1115 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1116 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1117 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77 | |
1118 }; | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1119 |
3756
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1120 return ngx_decode_base64_internal(dst, src, basis64); |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1121 } |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1122 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1123 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1124 ngx_int_t |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1125 ngx_decode_base64url(ngx_str_t *dst, ngx_str_t *src) |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1126 { |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1127 static u_char basis64[] = { |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1128 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1129 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1130 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 62, 77, 77, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1131 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 77, 77, 77, 77, 77, 77, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1132 77, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1133 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 77, 77, 77, 77, 63, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1134 77, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1135 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 77, 77, 77, 77, 77, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1136 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1137 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1138 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1139 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1140 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1141 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1142 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1143 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1144 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1145 }; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1146 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1147 return ngx_decode_base64_internal(dst, src, basis64); |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1148 } |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1149 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1150 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1151 static ngx_int_t |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1152 ngx_decode_base64_internal(ngx_str_t *dst, ngx_str_t *src, const u_char *basis) |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1153 { |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1154 size_t len; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1155 u_char *d, *s; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1156 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1157 for (len = 0; len < src->len; len++) { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1158 if (src->data[len] == '=') { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1159 break; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1160 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1161 |
3756
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1162 if (basis[src->data[len]] == 77) { |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1163 return NGX_ERROR; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1164 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1165 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1166 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1167 if (len % 4 == 1) { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1168 return NGX_ERROR; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1169 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1170 |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1171 s = src->data; |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
1172 d = dst->data; |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1173 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1174 while (len > 3) { |
3756
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1175 *d++ = (u_char) (basis[s[0]] << 2 | basis[s[1]] >> 4); |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1176 *d++ = (u_char) (basis[s[1]] << 4 | basis[s[2]] >> 2); |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1177 *d++ = (u_char) (basis[s[2]] << 6 | basis[s[3]]); |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1178 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1179 s += 4; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1180 len -= 4; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1181 } |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1182 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1183 if (len > 1) { |
3756
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1184 *d++ = (u_char) (basis[s[0]] << 2 | basis[s[1]] >> 4); |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1185 } |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1186 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1187 if (len > 2) { |
3756
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1188 *d++ = (u_char) (basis[s[1]] << 4 | basis[s[2]] >> 2); |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1189 } |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1190 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1191 dst->len = d - dst->data; |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1192 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1193 return NGX_OK; |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1194 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1195 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1196 |
657 | 1197 /* |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1198 * ngx_utf8_decode() decodes two and more bytes UTF sequences only |
657 | 1199 * the return values: |
1200 * 0x80 - 0x10ffff valid character | |
2120 | 1201 * 0x110000 - 0xfffffffd invalid sequence |
657 | 1202 * 0xfffffffe incomplete sequence |
1203 * 0xffffffff error | |
1204 */ | |
1205 | |
1206 uint32_t | |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1207 ngx_utf8_decode(u_char **p, size_t n) |
657 | 1208 { |
1209 size_t len; | |
1210 uint32_t u, i, valid; | |
1211 | |
1212 u = **p; | |
1213 | |
1214 if (u > 0xf0) { | |
1215 | |
1216 u &= 0x07; | |
1217 valid = 0xffff; | |
1218 len = 3; | |
1219 | |
1220 } else if (u > 0xe0) { | |
1221 | |
1222 u &= 0x0f; | |
1223 valid = 0x7ff; | |
1224 len = 2; | |
1225 | |
1226 } else if (u > 0xc0) { | |
1227 | |
1228 u &= 0x1f; | |
1229 valid = 0x7f; | |
1230 len = 1; | |
1231 | |
1232 } else { | |
1233 (*p)++; | |
1234 return 0xffffffff; | |
1235 } | |
1236 | |
1237 if (n - 1 < len) { | |
1238 return 0xfffffffe; | |
1239 } | |
1240 | |
1241 (*p)++; | |
1242 | |
1243 while (len) { | |
1244 i = *(*p)++; | |
1245 | |
1246 if (i < 0x80) { | |
1247 return 0xffffffff; | |
1248 } | |
1249 | |
1250 u = (u << 6) | (i & 0x3f); | |
1251 | |
1252 len--; | |
1253 } | |
1254 | |
1255 if (u > valid) { | |
1256 return u; | |
1257 } | |
1258 | |
1259 return 0xffffffff; | |
1260 } | |
1261 | |
1262 | |
523 | 1263 size_t |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1264 ngx_utf8_length(u_char *p, size_t n) |
523 | 1265 { |
2120 | 1266 u_char c, *last; |
1267 size_t len; | |
523 | 1268 |
2120 | 1269 last = p + n; |
523 | 1270 |
2120 | 1271 for (len = 0; p < last; len++) { |
1272 | |
1273 c = *p; | |
523 | 1274 |
1275 if (c < 0x80) { | |
2120 | 1276 p++; |
523 | 1277 continue; |
1278 } | |
1279 | |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1280 if (ngx_utf8_decode(&p, n) > 0x10ffff) { |
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1281 /* invalid UTF-8 */ |
2120 | 1282 return n; |
523 | 1283 } |
1284 } | |
1285 | |
1286 return len; | |
1287 } | |
1288 | |
1289 | |
527 | 1290 u_char * |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1291 ngx_utf8_cpystrn(u_char *dst, u_char *src, size_t n, size_t len) |
527 | 1292 { |
2120 | 1293 u_char c, *next; |
527 | 1294 |
1295 if (n == 0) { | |
1296 return dst; | |
1297 } | |
1298 | |
2120 | 1299 while (--n) { |
527 | 1300 |
1301 c = *src; | |
1302 *dst = c; | |
1303 | |
1304 if (c < 0x80) { | |
2120 | 1305 |
1306 if (c != '\0') { | |
1307 dst++; | |
1308 src++; | |
1309 len--; | |
1310 | |
527 | 1311 continue; |
1312 } | |
1313 | |
1314 return dst; | |
1315 } | |
1316 | |
2120 | 1317 next = src; |
527 | 1318 |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1319 if (ngx_utf8_decode(&next, len) > 0x10ffff) { |
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1320 /* invalid UTF-8 */ |
2120 | 1321 break; |
527 | 1322 } |
1323 | |
2120 | 1324 while (src < next) { |
3410
bfcc9be4f1c9
fix ngx_utf8_cpystrn(): it did not fully copy utf-8 string
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
1325 *dst++ = *src++; |
2120 | 1326 len--; |
1327 } | |
527 | 1328 } |
1329 | |
1330 *dst = '\0'; | |
1331 | |
1332 return dst; | |
1333 } | |
1334 | |
1335 | |
493 | 1336 uintptr_t |
1337 ngx_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type) | |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1338 { |
3275 | 1339 ngx_uint_t n; |
827 | 1340 uint32_t *escape; |
1341 static u_char hex[] = "0123456789abcdef"; | |
461 | 1342 |
827 | 1343 /* " ", "#", "%", "?", %00-%1F, %7F-%FF */ |
485 | 1344 |
827 | 1345 static uint32_t uri[] = { |
1346 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1347 |
827 | 1348 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
1349 0x80000029, /* 1000 0000 0000 0000 0000 0000 0010 1001 */ | |
1350 | |
1351 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ | |
1352 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ | |
452 | 1353 |
827 | 1354 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ |
1355 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */ | |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1356 |
827 | 1357 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
1358 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1359 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1360 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1361 }; | |
452 | 1362 |
3486
5d28d30ba1b1
escape ampersand in argument while rewrite
Igor Sysoev <igor@sysoev.ru>
parents:
3410
diff
changeset
|
1363 /* " ", "#", "%", "&", "+", "?", %00-%1F, %7F-%FF */ |
485 | 1364 |
827 | 1365 static uint32_t args[] = { |
1366 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1367 | |
1368 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ | |
3725 | 1369 0x88000869, /* 1000 1000 0000 0000 0000 1000 0110 1001 */ |
485 | 1370 |
827 | 1371 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ |
1372 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ | |
485 | 1373 |
827 | 1374 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ |
1375 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */ | |
485 | 1376 |
827 | 1377 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
1378 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1379 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1380 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1381 }; | |
485 | 1382 |
1405
fdd064faf26a
escape " ", "%", and %00-%1F in login and password
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
1383 /* " ", "#", """, "%", "'", %00-%1F, %7F-%FF */ |
485 | 1384 |
827 | 1385 static uint32_t html[] = { |
1386 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
461 | 1387 |
827 | 1388 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
1297 | 1389 0x000000ad, /* 0000 0000 0000 0000 0000 0000 1010 1101 */ |
827 | 1390 |
1391 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ | |
1392 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ | |
461 | 1393 |
827 | 1394 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ |
1395 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */ | |
461 | 1396 |
827 | 1397 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
1398 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1399 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1400 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1401 }; | |
461 | 1402 |
1405
fdd064faf26a
escape " ", "%", and %00-%1F in login and password
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
1403 /* " ", """, "%", "'", %00-%1F, %7F-%FF */ |
461 | 1404 |
1298
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1405 static uint32_t refresh[] = { |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1406 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1407 |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1408 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
1629
12a656452ad1
do not encode already encoded characters in msie_refresh
Igor Sysoev <igor@sysoev.ru>
parents:
1593
diff
changeset
|
1409 0x00000085, /* 0000 0000 0000 0000 0000 0000 1000 0101 */ |
1298
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1410 |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1411 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1412 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1413 |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1414 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1415 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */ |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1416 |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1417 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1418 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1419 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1420 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1421 }; |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1422 |
1405
fdd064faf26a
escape " ", "%", and %00-%1F in login and password
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
1423 /* " ", "%", %00-%1F */ |
1333
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1424 |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1425 static uint32_t memcached[] = { |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1426 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1427 |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1428 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
1405
fdd064faf26a
escape " ", "%", and %00-%1F in login and password
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
1429 0x00000021, /* 0000 0000 0000 0000 0000 0000 0010 0001 */ |
1333
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1430 |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1431 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1432 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1433 |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1434 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1435 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1436 |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1437 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1438 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1439 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1440 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1441 }; |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1442 |
1405
fdd064faf26a
escape " ", "%", and %00-%1F in login and password
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
1443 /* mail_auth is the same as memcached */ |
fdd064faf26a
escape " ", "%", and %00-%1F in login and password
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
1444 |
fdd064faf26a
escape " ", "%", and %00-%1F in login and password
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
1445 static uint32_t *map[] = |
fdd064faf26a
escape " ", "%", and %00-%1F in login and password
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
1446 { uri, args, html, refresh, memcached, memcached }; |
1298
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1447 |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1448 |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1449 escape = map[type]; |
461 | 1450 |
452 | 1451 if (dst == NULL) { |
1452 | |
1453 /* find the number of the characters to be escaped */ | |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1454 |
3115 | 1455 n = 0; |
452 | 1456 |
3275 | 1457 while (size) { |
452 | 1458 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { |
1459 n++; | |
1460 } | |
1461 src++; | |
3275 | 1462 size--; |
452 | 1463 } |
1464 | |
485 | 1465 return (uintptr_t) n; |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1466 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1467 |
3275 | 1468 while (size) { |
452 | 1469 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { |
1470 *dst++ = '%'; | |
1471 *dst++ = hex[*src >> 4]; | |
1472 *dst++ = hex[*src & 0xf]; | |
1473 src++; | |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1474 |
452 | 1475 } else { |
1476 *dst++ = *src++; | |
1477 } | |
3275 | 1478 size--; |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1479 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1480 |
485 | 1481 return (uintptr_t) dst; |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1482 } |
577 | 1483 |
1484 | |
1485 void | |
601 | 1486 ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type) |
577 | 1487 { |
1488 u_char *d, *s, ch, c, decoded; | |
1489 enum { | |
1490 sw_usual = 0, | |
1491 sw_quoted, | |
1492 sw_quoted_second | |
1493 } state; | |
1494 | |
1495 d = *dst; | |
1496 s = *src; | |
1497 | |
1498 state = 0; | |
1499 decoded = 0; | |
1500 | |
1501 while (size--) { | |
1502 | |
1503 ch = *s++; | |
1504 | |
1505 switch (state) { | |
1506 case sw_usual: | |
1593 | 1507 if (ch == '?' |
1508 && (type & (NGX_UNESCAPE_URI|NGX_UNESCAPE_REDIRECT))) | |
1509 { | |
577 | 1510 *d++ = ch; |
1511 goto done; | |
1512 } | |
1513 | |
1514 if (ch == '%') { | |
1515 state = sw_quoted; | |
1516 break; | |
1517 } | |
1518 | |
1519 *d++ = ch; | |
1520 break; | |
1521 | |
1522 case sw_quoted: | |
1523 | |
1524 if (ch >= '0' && ch <= '9') { | |
1525 decoded = (u_char) (ch - '0'); | |
1526 state = sw_quoted_second; | |
1527 break; | |
1528 } | |
1529 | |
1530 c = (u_char) (ch | 0x20); | |
1531 if (c >= 'a' && c <= 'f') { | |
1532 decoded = (u_char) (c - 'a' + 10); | |
1533 state = sw_quoted_second; | |
1534 break; | |
1535 } | |
1536 | |
589 | 1537 /* the invalid quoted character */ |
577 | 1538 |
589 | 1539 state = sw_usual; |
1540 | |
1541 *d++ = ch; | |
577 | 1542 |
1543 break; | |
1544 | |
1545 case sw_quoted_second: | |
1546 | |
589 | 1547 state = sw_usual; |
1548 | |
577 | 1549 if (ch >= '0' && ch <= '9') { |
1550 ch = (u_char) ((decoded << 4) + ch - '0'); | |
1551 | |
1593 | 1552 if (type & NGX_UNESCAPE_REDIRECT) { |
601 | 1553 if (ch > '%' && ch < 0x7f) { |
1554 *d++ = ch; | |
1555 break; | |
1556 } | |
1557 | |
1558 *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1); | |
1559 | |
577 | 1560 break; |
1561 } | |
1562 | |
601 | 1563 *d++ = ch; |
577 | 1564 |
1565 break; | |
1566 } | |
1567 | |
1568 c = (u_char) (ch | 0x20); | |
1569 if (c >= 'a' && c <= 'f') { | |
1570 ch = (u_char) ((decoded << 4) + c - 'a' + 10); | |
1571 | |
1593 | 1572 if (type & NGX_UNESCAPE_URI) { |
1573 if (ch == '?') { | |
1574 *d++ = ch; | |
1575 goto done; | |
1576 } | |
1577 | |
1578 *d++ = ch; | |
1579 break; | |
1580 } | |
1581 | |
1582 if (type & NGX_UNESCAPE_REDIRECT) { | |
601 | 1583 if (ch == '?') { |
1584 *d++ = ch; | |
1585 goto done; | |
1586 } | |
577 | 1587 |
601 | 1588 if (ch > '%' && ch < 0x7f) { |
1589 *d++ = ch; | |
1590 break; | |
1591 } | |
1592 | |
1593 *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1); | |
577 | 1594 break; |
1595 } | |
1596 | |
601 | 1597 *d++ = ch; |
577 | 1598 |
1599 break; | |
1600 } | |
1601 | |
589 | 1602 /* the invalid quoted character */ |
577 | 1603 |
1604 break; | |
1605 } | |
1606 } | |
1607 | |
1608 done: | |
1609 | |
1610 *dst = d; | |
1611 *src = s; | |
1612 } | |
583 | 1613 |
1614 | |
1544 | 1615 uintptr_t |
1616 ngx_escape_html(u_char *dst, u_char *src, size_t size) | |
1617 { | |
1618 u_char ch; | |
3275 | 1619 ngx_uint_t len; |
1544 | 1620 |
1621 if (dst == NULL) { | |
1622 | |
1623 len = 0; | |
1624 | |
3275 | 1625 while (size) { |
1544 | 1626 switch (*src++) { |
1627 | |
1628 case '<': | |
1629 len += sizeof("<") - 2; | |
1560
25ee6eee7573
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1552
diff
changeset
|
1630 break; |
1544 | 1631 |
1632 case '>': | |
1633 len += sizeof(">") - 2; | |
1560
25ee6eee7573
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1552
diff
changeset
|
1634 break; |
1544 | 1635 |
1636 case '&': | |
1637 len += sizeof("&") - 2; | |
1560
25ee6eee7573
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1552
diff
changeset
|
1638 break; |
1544 | 1639 |
1640 default: | |
1641 break; | |
1642 } | |
3275 | 1643 size--; |
1544 | 1644 } |
1645 | |
1646 return (uintptr_t) len; | |
1647 } | |
1648 | |
3275 | 1649 while (size) { |
1544 | 1650 ch = *src++; |
1651 | |
1652 switch (ch) { | |
1653 | |
1654 case '<': | |
1655 *dst++ = '&'; *dst++ = 'l'; *dst++ = 't'; *dst++ = ';'; | |
1656 break; | |
1657 | |
1658 case '>': | |
1659 *dst++ = '&'; *dst++ = 'g'; *dst++ = 't'; *dst++ = ';'; | |
1660 break; | |
1661 | |
1662 case '&': | |
1663 *dst++ = '&'; *dst++ = 'a'; *dst++ = 'm'; *dst++ = 'p'; | |
1664 *dst++ = ';'; | |
1665 break; | |
1666 | |
1667 default: | |
1668 *dst++ = ch; | |
1669 break; | |
1670 } | |
3275 | 1671 size--; |
1544 | 1672 } |
1673 | |
1674 return (uintptr_t) dst; | |
1675 } | |
1676 | |
1677 | |
3641
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1678 void |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1679 ngx_str_rbtree_insert_value(ngx_rbtree_node_t *temp, |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1680 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel) |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1681 { |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1682 ngx_str_node_t *n, *t; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1683 ngx_rbtree_node_t **p; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1684 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1685 for ( ;; ) { |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1686 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1687 n = (ngx_str_node_t *) node; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1688 t = (ngx_str_node_t *) temp; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1689 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1690 if (node->key != temp->key) { |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1691 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1692 p = (node->key < temp->key) ? &temp->left : &temp->right; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1693 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1694 } else if (n->str.len != t->str.len) { |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1695 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1696 p = (n->str.len < t->str.len) ? &temp->left : &temp->right; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1697 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1698 } else { |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1699 p = (ngx_memcmp(n->str.data, t->str.data, n->str.len) < 0) |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1700 ? &temp->left : &temp->right; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1701 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1702 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1703 if (*p == sentinel) { |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1704 break; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1705 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1706 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1707 temp = *p; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1708 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1709 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1710 *p = node; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1711 node->parent = temp; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1712 node->left = sentinel; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1713 node->right = sentinel; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1714 ngx_rbt_red(node); |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1715 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1716 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1717 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1718 ngx_str_node_t * |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1719 ngx_str_rbtree_lookup(ngx_rbtree_t *rbtree, ngx_str_t *val, uint32_t hash) |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1720 { |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1721 ngx_int_t rc; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1722 ngx_str_node_t *n; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1723 ngx_rbtree_node_t *node, *sentinel; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1724 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1725 node = rbtree->root; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1726 sentinel = rbtree->sentinel; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1727 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1728 while (node != sentinel) { |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1729 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1730 n = (ngx_str_node_t *) node; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1731 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1732 if (hash != node->key) { |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1733 node = (hash < node->key) ? node->left : node->right; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1734 continue; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1735 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1736 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1737 if (val->len != n->str.len) { |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1738 node = (val->len < n->str.len) ? node->left : node->right; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1739 continue; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1740 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1741 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1742 rc = ngx_memcmp(val->data, n->str.data, val->len); |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1743 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1744 if (rc < 0) { |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1745 node = node->left; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1746 continue; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1747 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1748 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1749 if (rc > 0) { |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1750 node = node->right; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1751 continue; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1752 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1753 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1754 return n; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1755 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1756 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1757 return NULL; |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1758 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1759 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1760 |
1208 | 1761 /* ngx_sort() is implemented as insertion sort because we need stable sort */ |
1762 | |
1763 void | |
1764 ngx_sort(void *base, size_t n, size_t size, | |
1956
cb8c0c8e0c27
use ngx_int_t in ngx_sort() callback
Igor Sysoev <igor@sysoev.ru>
parents:
1955
diff
changeset
|
1765 ngx_int_t (*cmp)(const void *, const void *)) |
1208 | 1766 { |
1955
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1767 u_char *p1, *p2, *p; |
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1768 |
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1769 p = ngx_alloc(size, ngx_cycle->log); |
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1770 if (p == NULL) { |
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1771 return; |
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1772 } |
1208 | 1773 |
1774 for (p1 = (u_char *) base + size; | |
1775 p1 < (u_char *) base + n * size; | |
1776 p1 += size) | |
1777 { | |
1955
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1778 ngx_memcpy(p, p1, size); |
1208 | 1779 |
1780 for (p2 = p1; | |
1955
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1781 p2 > (u_char *) base && cmp(p2 - size, p) > 0; |
1208 | 1782 p2 -= size) |
1783 { | |
1784 ngx_memcpy(p2, p2 - size, size); | |
1785 } | |
1786 | |
1955
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1787 ngx_memcpy(p2, p, size); |
1208 | 1788 } |
1955
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1789 |
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1790 ngx_free(p); |
1208 | 1791 } |
1792 | |
1793 | |
583 | 1794 #if (NGX_MEMCPY_LIMIT) |
1795 | |
1796 void * | |
1797 ngx_memcpy(void *dst, void *src, size_t n) | |
1798 { | |
1799 if (n > NGX_MEMCPY_LIMIT) { | |
1800 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "memcpy %uz bytes", n); | |
1801 ngx_debug_point(); | |
1802 } | |
1803 | |
1804 return memcpy(dst, src, n); | |
1805 } | |
1806 | |
1807 #endif |