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