Mercurial > hg > nginx-quic
annotate src/core/ngx_string.c @ 588:0a2c30f516e6
release-0.3.15 tag
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 07 Dec 2005 14:51:31 +0000 |
parents | 4e296b7d25bf |
children | d4e858a5751a |
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 |
493 | 11 u_char * |
12 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
|
13 { |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
14 if (n == 0) { |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 return dst; |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
16 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
17 |
517 | 18 for ( /* void */ ; --n; dst++, src++) { |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
19 *dst = *src; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
21 if (*dst == '\0') { |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
22 return dst; |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
23 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
24 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
26 *dst = '\0'; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
27 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 return dst; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 } |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
30 |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
31 |
493 | 32 u_char * |
33 ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src) | |
485 | 34 { |
35 u_char *dst; | |
36 | |
501 | 37 dst = ngx_palloc(pool, src->len); |
38 if (dst == NULL) { | |
485 | 39 return NULL; |
40 } | |
41 | |
42 ngx_memcpy(dst, src->data, src->len); | |
43 | |
44 return dst; | |
45 } | |
46 | |
47 | |
455 | 48 /* |
49 * supported formats: | |
473 | 50 * %[0][width][x][X]O off_t |
461 | 51 * %[0][width]T time_t |
52 * %[0][width][u][x|X]z ssize_t/size_t | |
53 * %[0][width][u][x|X]d int/u_int | |
54 * %[0][width][u][x|X]l long | |
55 * %[0][width|m][u][x|X]i ngx_int_t/ngx_uint_t | |
56 * %[0][width][u][x|X]D int32_t/uint32_t | |
57 * %[0][width][u][x|X]L int64_t/uint64_t | |
495 | 58 * %[0][width|m][u][x|X]A ngx_atomic_int_t/ngx_atomic_uint_t |
461 | 59 * %P ngx_pid_t |
557 | 60 * %M ngx_msec_t |
461 | 61 * %r rlim_t |
62 * %p pointer | |
63 * %V pointer to ngx_str_t | |
64 * %s null-terminated string | |
65 * %Z '\0' | |
525 | 66 * %N '\n' |
461 | 67 * %c char |
68 * %% % | |
455 | 69 * |
461 | 70 * reserved: |
71 * %t ptrdiff_t | |
72 * %S null-teminated wchar string | |
73 * %C wchar | |
455 | 74 */ |
75 | |
461 | 76 |
503 | 77 u_char * ngx_cdecl |
493 | 78 ngx_sprintf(u_char *buf, const char *fmt, ...) |
461 | 79 { |
80 u_char *p; | |
81 va_list args; | |
82 | |
83 va_start(args, fmt); | |
84 p = ngx_vsnprintf(buf, /* STUB */ 65536, fmt, args); | |
85 va_end(args); | |
86 | |
87 return p; | |
88 } | |
89 | |
90 | |
503 | 91 u_char * ngx_cdecl |
493 | 92 ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...) |
455 | 93 { |
461 | 94 u_char *p; |
95 va_list args; | |
96 | |
97 va_start(args, fmt); | |
98 p = ngx_vsnprintf(buf, max, fmt, args); | |
99 va_end(args); | |
100 | |
101 return p; | |
102 } | |
103 | |
455 | 104 |
493 | 105 u_char * |
106 ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args) | |
461 | 107 { |
479 | 108 u_char *p, zero, *last, temp[NGX_INT64_LEN + 1]; |
109 /* | |
110 * really we need temp[NGX_INT64_LEN] only, | |
493 | 111 * but icc issues the warning |
479 | 112 */ |
461 | 113 int d; |
114 size_t len; | |
115 uint32_t ui32; | |
116 int64_t i64; | |
117 uint64_t ui64; | |
561 | 118 ngx_msec_t ms; |
461 | 119 ngx_str_t *s; |
493 | 120 ngx_uint_t width, sign, hexadecimal, max_width; |
461 | 121 static u_char hex[] = "0123456789abcdef"; |
122 static u_char HEX[] = "0123456789ABCDEF"; | |
455 | 123 |
461 | 124 if (max == 0) { |
125 return buf; | |
126 } | |
127 | |
128 last = buf + max; | |
129 | |
130 while (*fmt && buf < last) { | |
131 | |
132 /* | |
133 * "buf < last" means that we could copy at least one character: | |
134 * the plain character, "%%", "%c", and minus without the checking | |
135 */ | |
136 | |
455 | 137 if (*fmt == '%') { |
138 | |
461 | 139 i64 = 0; |
140 ui64 = 0; | |
141 | |
142 zero = (u_char) ((*++fmt == '0') ? '0' : ' '); | |
455 | 143 width = 0; |
144 sign = 1; | |
145 hexadecimal = 0; | |
493 | 146 max_width = 0; |
455 | 147 |
477 | 148 p = temp + NGX_INT64_LEN; |
455 | 149 |
150 while (*fmt >= '0' && *fmt <= '9') { | |
151 width = width * 10 + *fmt++ - '0'; | |
152 } | |
153 | |
154 | |
155 for ( ;; ) { | |
156 switch (*fmt) { | |
157 | |
158 case 'u': | |
159 sign = 0; | |
160 fmt++; | |
161 continue; | |
162 | |
467 | 163 case 'm': |
493 | 164 max_width = 1; |
467 | 165 fmt++; |
166 continue; | |
167 | |
461 | 168 case 'X': |
169 hexadecimal = 2; | |
170 sign = 0; | |
171 fmt++; | |
172 continue; | |
173 | |
455 | 174 case 'x': |
175 hexadecimal = 1; | |
461 | 176 sign = 0; |
455 | 177 fmt++; |
178 continue; | |
179 | |
180 default: | |
181 break; | |
182 } | |
183 | |
184 break; | |
185 } | |
186 | |
187 | |
188 switch (*fmt) { | |
189 | |
461 | 190 case 'V': |
191 s = va_arg(args, ngx_str_t *); | |
455 | 192 |
573 | 193 len = s->len & 0xffff; |
194 len = (buf + len < last) ? len : (size_t) (last - buf); | |
195 | |
461 | 196 buf = ngx_cpymem(buf, s->data, len); |
197 fmt++; | |
455 | 198 |
461 | 199 continue; |
455 | 200 |
201 case 's': | |
461 | 202 p = va_arg(args, u_char *); |
455 | 203 |
461 | 204 while (*p && buf < last) { |
455 | 205 *buf++ = *p++; |
206 } | |
207 fmt++; | |
208 | |
209 continue; | |
210 | |
461 | 211 case 'O': |
212 i64 = (int64_t) va_arg(args, off_t); | |
213 sign = 1; | |
214 break; | |
215 | |
216 case 'P': | |
217 i64 = (int64_t) va_arg(args, ngx_pid_t); | |
218 sign = 1; | |
219 break; | |
220 | |
221 case 'T': | |
222 i64 = (int64_t) va_arg(args, time_t); | |
223 sign = 1; | |
224 break; | |
225 | |
557 | 226 case 'M': |
561 | 227 ms = (ngx_msec_t) va_arg(args, ngx_msec_t); |
228 if ((ngx_msec_int_t) ms == -1) { | |
229 sign = 1; | |
230 i64 = -1; | |
231 } else { | |
232 sign = 0; | |
233 ui64 = (uint64_t) ms; | |
234 } | |
557 | 235 break; |
236 | |
461 | 237 case 'z': |
238 if (sign) { | |
239 i64 = (int64_t) va_arg(args, ssize_t); | |
240 } else { | |
241 ui64 = (uint64_t) va_arg(args, size_t); | |
242 } | |
243 break; | |
244 | |
245 case 'i': | |
246 if (sign) { | |
247 i64 = (int64_t) va_arg(args, ngx_int_t); | |
248 } else { | |
249 ui64 = (uint64_t) va_arg(args, ngx_uint_t); | |
250 } | |
493 | 251 |
252 if (max_width) { | |
253 width = NGX_INT_T_LEN; | |
254 } | |
255 | |
461 | 256 break; |
257 | |
258 case 'd': | |
259 if (sign) { | |
260 i64 = (int64_t) va_arg(args, int); | |
261 } else { | |
262 ui64 = (uint64_t) va_arg(args, u_int); | |
263 } | |
264 break; | |
265 | |
266 case 'l': | |
267 if (sign) { | |
268 i64 = (int64_t) va_arg(args, long); | |
269 } else { | |
270 ui64 = (uint64_t) va_arg(args, u_long); | |
271 } | |
272 break; | |
273 | |
274 case 'D': | |
275 if (sign) { | |
276 i64 = (int64_t) va_arg(args, int32_t); | |
277 } else { | |
278 ui64 = (uint64_t) va_arg(args, uint32_t); | |
279 } | |
280 break; | |
281 | |
282 case 'L': | |
283 if (sign) { | |
284 i64 = va_arg(args, int64_t); | |
285 } else { | |
286 ui64 = va_arg(args, uint64_t); | |
287 } | |
288 break; | |
289 | |
493 | 290 case 'A': |
291 if (sign) { | |
292 i64 = (int64_t) va_arg(args, ngx_atomic_int_t); | |
293 } else { | |
495 | 294 ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t); |
493 | 295 } |
296 | |
297 if (max_width) { | |
298 width = NGX_ATOMIC_T_LEN; | |
299 } | |
300 | |
301 break; | |
302 | |
461 | 303 #if !(NGX_WIN32) |
304 case 'r': | |
305 i64 = (int64_t) va_arg(args, rlim_t); | |
306 sign = 1; | |
307 break; | |
308 #endif | |
309 | |
310 case 'p': | |
311 ui64 = (uintptr_t) va_arg(args, void *); | |
312 hexadecimal = 2; | |
313 sign = 0; | |
314 zero = '0'; | |
315 width = 8; | |
316 break; | |
317 | |
457 | 318 case 'c': |
461 | 319 d = va_arg(args, int); |
457 | 320 *buf++ = (u_char) (d & 0xff); |
321 fmt++; | |
322 | |
323 continue; | |
324 | |
461 | 325 case 'Z': |
326 *buf++ = '\0'; | |
327 fmt++; | |
328 | |
329 continue; | |
330 | |
525 | 331 case 'N': |
332 #if (NGX_WIN32) | |
333 *buf++ = CR; | |
334 #endif | |
335 *buf++ = LF; | |
336 fmt++; | |
337 | |
338 continue; | |
339 | |
455 | 340 case '%': |
341 *buf++ = '%'; | |
342 fmt++; | |
343 | |
344 continue; | |
345 | |
346 default: | |
347 *buf++ = *fmt++; | |
348 | |
349 continue; | |
350 } | |
351 | |
461 | 352 if (sign) { |
353 if (i64 < 0) { | |
354 *buf++ = '-'; | |
355 ui64 = (uint64_t) -i64; | |
356 | |
357 } else { | |
358 ui64 = (uint64_t) i64; | |
359 } | |
360 } | |
361 | |
362 if (hexadecimal == 1) { | |
363 do { | |
364 | |
365 /* the "(uint32_t)" cast disables the BCC's warning */ | |
366 *--p = hex[(uint32_t) (ui64 & 0xf)]; | |
367 | |
368 } while (ui64 >>= 4); | |
369 | |
370 } else if (hexadecimal == 2) { | |
371 do { | |
372 | |
373 /* the "(uint32_t)" cast disables the BCC's warning */ | |
374 *--p = HEX[(uint32_t) (ui64 & 0xf)]; | |
375 | |
376 } while (ui64 >>= 4); | |
377 | |
378 } else if (ui64 <= NGX_MAX_UINT32_VALUE) { | |
379 | |
380 /* | |
381 * To divide 64-bit number and to find the remainder | |
382 * on the x86 platform gcc and icc call the libc functions | |
383 * [u]divdi3() and [u]moddi3(), they call another function | |
493 | 384 * in its turn. On FreeBSD it is the qdivrem() function, |
461 | 385 * its source code is about 170 lines of the code. |
386 * The glibc counterpart is about 150 lines of the code. | |
387 * | |
493 | 388 * For 32-bit numbers and some divisors gcc and icc use |
389 * the inlined multiplication and shifts. For example, | |
390 * unsigned "i32 / 10" is compiled to | |
391 * | |
392 * (i32 * 0xCCCCCCCD) >> 35 | |
461 | 393 */ |
394 | |
395 ui32 = (uint32_t) ui64; | |
396 | |
397 do { | |
398 *--p = (u_char) (ui32 % 10 + '0'); | |
399 } while (ui32 /= 10); | |
400 | |
401 } else { | |
402 do { | |
403 *--p = (u_char) (ui64 % 10 + '0'); | |
404 } while (ui64 /= 10); | |
405 } | |
406 | |
477 | 407 len = (temp + NGX_INT64_LEN) - p; |
455 | 408 |
461 | 409 while (len++ < width && buf < last) { |
410 *buf++ = zero; | |
455 | 411 } |
412 | |
477 | 413 len = (temp + NGX_INT64_LEN) - p; |
461 | 414 if (buf + len > last) { |
415 len = last - buf; | |
416 } | |
417 | |
418 buf = ngx_cpymem(buf, p, len); | |
455 | 419 |
420 fmt++; | |
421 | |
422 } else { | |
423 *buf++ = *fmt++; | |
424 } | |
425 } | |
426 | |
427 return buf; | |
428 } | |
429 | |
430 | |
493 | 431 ngx_int_t |
432 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
|
433 { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
434 if (n == 0) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
435 return 0; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
436 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
437 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
438 n--; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
439 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
440 for ( ;; ) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
441 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
|
442 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
|
443 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
444 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
445 if (n == 0) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
446 return 0; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
447 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
448 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
449 n--; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
450 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
451 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
452 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
453 |
493 | 454 ngx_int_t |
455 ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n) | |
455 | 456 { |
457 u_char c1, c2; | |
458 | |
459 if (n == 0) { | |
460 return 0; | |
461 } | |
462 | |
463 n--; | |
464 | |
465 for ( ;; ) { | |
466 c1 = s1[n]; | |
467 if (c1 >= 'a' && c1 <= 'z') { | |
468 c1 -= 'a' - 'A'; | |
469 } | |
470 | |
471 c2 = s2[n]; | |
472 if (c2 >= 'a' && c2 <= 'z') { | |
473 c2 -= 'a' - 'A'; | |
474 } | |
475 | |
476 if (c1 != c2) { | |
477 return c1 - c2; | |
478 } | |
479 | |
480 if (n == 0) { | |
481 return 0; | |
482 } | |
483 | |
484 n--; | |
485 } | |
486 } | |
487 | |
488 | |
493 | 489 ngx_int_t |
490 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
|
491 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
492 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
|
493 |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
494 if (n == 0) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
495 return NGX_ERROR; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
496 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
497 |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
498 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
|
499 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
|
500 return NGX_ERROR; |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
501 } |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
502 |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
503 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
|
504 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
505 |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
506 if (value < 0) { |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
507 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
|
508 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
509 } else { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
510 return value; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
511 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
512 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
513 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
514 |
501 | 515 ssize_t |
516 ngx_atosz(u_char *line, size_t n) | |
517 { | |
518 ssize_t value; | |
519 | |
520 if (n == 0) { | |
521 return NGX_ERROR; | |
522 } | |
523 | |
524 for (value = 0; n--; line++) { | |
525 if (*line < '0' || *line > '9') { | |
526 return NGX_ERROR; | |
527 } | |
528 | |
529 value = value * 10 + (*line - '0'); | |
530 } | |
531 | |
532 if (value < 0) { | |
533 return NGX_ERROR; | |
534 | |
535 } else { | |
536 return value; | |
537 } | |
538 } | |
539 | |
540 | |
541 off_t | |
542 ngx_atoof(u_char *line, size_t n) | |
543 { | |
544 off_t value; | |
545 | |
546 if (n == 0) { | |
547 return NGX_ERROR; | |
548 } | |
549 | |
550 for (value = 0; n--; line++) { | |
551 if (*line < '0' || *line > '9') { | |
552 return NGX_ERROR; | |
553 } | |
554 | |
555 value = value * 10 + (*line - '0'); | |
556 } | |
557 | |
558 if (value < 0) { | |
559 return NGX_ERROR; | |
560 | |
561 } else { | |
562 return value; | |
563 } | |
564 } | |
565 | |
566 | |
567 time_t | |
568 ngx_atotm(u_char *line, size_t n) | |
569 { | |
570 time_t value; | |
571 | |
572 if (n == 0) { | |
573 return NGX_ERROR; | |
574 } | |
575 | |
576 for (value = 0; n--; line++) { | |
577 if (*line < '0' || *line > '9') { | |
578 return NGX_ERROR; | |
579 } | |
580 | |
581 value = value * 10 + (*line - '0'); | |
582 } | |
583 | |
584 if (value < 0) { | |
585 return NGX_ERROR; | |
586 | |
587 } else { | |
588 return value; | |
589 } | |
590 } | |
591 | |
592 | |
493 | 593 ngx_int_t |
594 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
|
595 { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
596 u_char ch; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
597 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
|
598 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
599 if (n == 0) { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
600 return NGX_ERROR; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
601 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
602 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
603 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
|
604 ch = *line; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
605 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
606 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
|
607 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
|
608 continue; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
609 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
610 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
611 if (ch >= 'A' && ch <= 'F') { |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
612 value = value * 16 + (ch - 'A' + 10); |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
613 continue; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
614 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
615 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
616 if (ch >= 'a' && ch <= 'f') { |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
617 value = value * 16 + (ch - 'a' + 10); |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
618 continue; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
619 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
620 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
621 return NGX_ERROR; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
622 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
623 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
624 if (value < 0) { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
625 return NGX_ERROR; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
626 |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
627 } else { |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
628 return value; |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
629 } |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
630 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
631 |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
632 |
493 | 633 void |
634 ngx_md5_text(u_char *text, u_char *md5) | |
174
ea464a6c0581
nginx-0.0.1-2003-11-05-01:12:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
635 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
636 int i; |
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
637 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
|
638 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
639 for (i = 0; i < 16; i++) { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
640 *text++ = hex[md5[i] >> 4]; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
641 *text++ = hex[md5[i] & 0xf]; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
642 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
643 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
644 *text = '\0'; |
174
ea464a6c0581
nginx-0.0.1-2003-11-05-01:12:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
645 } |
ea464a6c0581
nginx-0.0.1-2003-11-05-01:12:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
646 |
ea464a6c0581
nginx-0.0.1-2003-11-05-01:12:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
647 |
493 | 648 void |
649 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
|
650 { |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
651 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
|
652 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
|
653 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
|
654 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
655 |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
656 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
|
657 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
|
658 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
|
659 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
660 while (len > 2) { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
661 *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
|
662 *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
|
663 *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
|
664 *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
|
665 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
666 s += 3; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
667 len -= 3; |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
668 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
669 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
670 if (len) { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
671 *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
|
672 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
673 if (len == 1) { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
674 *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
|
675 *d++ = '='; |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
676 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
677 } else { |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
678 *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
|
679 *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
|
680 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
681 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
682 *d++ = '='; |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
683 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
684 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
685 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
|
686 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
687 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
688 |
493 | 689 ngx_int_t |
690 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
|
691 { |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
692 size_t len; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
693 u_char *d, *s; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
694 static u_char basis64[] = |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
695 { 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
696 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
697 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 62, 77, 77, 77, 63, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
698 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 77, 77, 77, 77, 77, 77, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
699 77, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
700 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 77, 77, 77, 77, 77, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
701 77, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
702 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
|
703 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
704 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
705 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
706 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
707 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
708 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
709 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
710 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
711 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77 }; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
712 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
713 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
|
714 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
|
715 break; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
716 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
717 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
718 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
|
719 return NGX_ERROR; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
720 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
721 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
722 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
723 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
|
724 return NGX_ERROR; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
725 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
726 |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
727 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
|
728 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
|
729 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
730 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
|
731 *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
|
732 *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
|
733 *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
|
734 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
735 s += 4; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
736 len -= 4; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
737 } |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
738 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
739 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
|
740 *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
|
741 } |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
742 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
743 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
|
744 *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
|
745 } |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
746 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
747 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
|
748 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
749 return NGX_OK; |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
750 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
751 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
752 |
523 | 753 size_t |
754 ngx_utf_length(ngx_str_t *utf) | |
755 { | |
756 u_char c; | |
757 size_t len; | |
758 ngx_uint_t i; | |
759 | |
760 for (len = 0, i = 0; i < utf->len; len++, i++) { | |
761 | |
762 c = utf->data[i]; | |
763 | |
764 if (c < 0x80) { | |
765 continue; | |
766 } | |
767 | |
527 | 768 if (c >= 0xc0) { |
769 for (c <<= 1; c & 0x80; c <<= 1) { | |
770 i++; | |
771 } | |
772 | |
773 continue; | |
523 | 774 } |
775 | |
527 | 776 /* invalid utf */ |
777 | |
778 return utf->len; | |
523 | 779 } |
780 | |
781 return len; | |
782 } | |
783 | |
784 | |
527 | 785 u_char * |
786 ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n) | |
787 { | |
788 u_char c; | |
789 | |
790 if (n == 0) { | |
791 return dst; | |
792 } | |
793 | |
794 for ( /* void */ ; --n; dst++, src++) { | |
795 | |
796 c = *src; | |
797 *dst = c; | |
798 | |
799 if (c < 0x80) { | |
800 if (*dst != '\0') { | |
801 continue; | |
802 } | |
803 | |
804 return dst; | |
805 } | |
806 | |
807 if (c >= 0xc0) { | |
808 for (c <<= 1; c & 0x80; c <<= 1) { | |
809 *++dst = *++src; | |
810 } | |
811 | |
812 continue; | |
813 } | |
814 | |
815 /* invalid utf */ | |
816 } | |
817 | |
818 *dst = '\0'; | |
819 | |
820 return dst; | |
821 } | |
822 | |
823 | |
493 | 824 uintptr_t |
825 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
|
826 { |
461 | 827 ngx_uint_t i, n; |
828 uint32_t *escape; | |
452 | 829 static u_char hex[] = "0123456789abcdef"; |
461 | 830 |
493 | 831 /* " ", "#", "%", "?", %00-%1F, %7F-%FF */ |
485 | 832 |
461 | 833 static uint32_t uri[] = |
452 | 834 { 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
|
835 |
452 | 836 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
493 | 837 0x80000029, /* 1000 0000 0000 0000 0000 0000 0010 1001 */ |
452 | 838 |
839 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ | |
840 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ | |
841 | |
842 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ | |
843 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
|
844 |
452 | 845 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
846 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
847 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
848 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ }; | |
849 | |
493 | 850 /* " ", "#", "%", "+", "?", %00-%1F, %7F-%FF */ |
485 | 851 |
852 static uint32_t args[] = | |
853 { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
854 | |
855 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ | |
493 | 856 0x80000829, /* 1000 0000 0000 0000 0000 1000 0010 1001 */ |
485 | 857 |
858 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ | |
859 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ | |
860 | |
861 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ | |
862 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */ | |
863 | |
864 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
865 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
866 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
867 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ }; | |
868 | |
869 /* " ", """, "%", "'", %00-%1F, %7F-%FF */ | |
870 | |
461 | 871 static uint32_t html[] = |
872 { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
873 | |
874 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ | |
493 | 875 0x800000ad, /* 0000 0000 0000 0000 0000 0000 1010 1101 */ |
461 | 876 |
877 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ | |
878 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ | |
879 | |
880 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ | |
881 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */ | |
882 | |
883 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
884 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
885 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
886 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ }; | |
887 | |
888 | |
485 | 889 switch (type) { |
890 case NGX_ESCAPE_HTML: | |
461 | 891 escape = html; |
485 | 892 break; |
893 case NGX_ESCAPE_ARGS: | |
894 escape = args; | |
895 break; | |
896 default: | |
461 | 897 escape = uri; |
485 | 898 break; |
461 | 899 } |
900 | |
452 | 901 if (dst == NULL) { |
902 | |
903 /* 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
|
904 |
452 | 905 n = 0; |
906 | |
907 for (i = 0; i < size; i++) { | |
908 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { | |
909 n++; | |
910 } | |
911 src++; | |
912 } | |
913 | |
485 | 914 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
|
915 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
916 |
452 | 917 for (i = 0; i < size; i++) { |
918 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { | |
919 *dst++ = '%'; | |
920 *dst++ = hex[*src >> 4]; | |
921 *dst++ = hex[*src & 0xf]; | |
922 src++; | |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
923 |
452 | 924 } else { |
925 *dst++ = *src++; | |
926 } | |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
927 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
928 |
485 | 929 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
|
930 } |
577 | 931 |
932 | |
933 void | |
934 ngx_unescape_uri(u_char **dst, u_char **src, size_t size) | |
935 { | |
936 u_char *d, *s, ch, c, decoded; | |
937 enum { | |
938 sw_usual = 0, | |
939 sw_quoted, | |
940 sw_quoted_second | |
941 } state; | |
942 | |
943 d = *dst; | |
944 s = *src; | |
945 | |
946 state = 0; | |
947 decoded = 0; | |
948 | |
949 while (size--) { | |
950 | |
951 ch = *s++; | |
952 | |
953 switch (state) { | |
954 case sw_usual: | |
955 if (ch == '?') { | |
956 *d++ = ch; | |
957 goto done; | |
958 } | |
959 | |
960 if (ch == '%') { | |
961 state = sw_quoted; | |
962 break; | |
963 } | |
964 | |
965 *d++ = ch; | |
966 break; | |
967 | |
968 case sw_quoted: | |
969 | |
970 if (ch >= '0' && ch <= '9') { | |
971 decoded = (u_char) (ch - '0'); | |
972 state = sw_quoted_second; | |
973 break; | |
974 } | |
975 | |
976 c = (u_char) (ch | 0x20); | |
977 if (c >= 'a' && c <= 'f') { | |
978 decoded = (u_char) (c - 'a' + 10); | |
979 state = sw_quoted_second; | |
980 break; | |
981 } | |
982 | |
983 /* skip the invalid quoted character */ | |
984 | |
985 s++; | |
986 size--; | |
987 | |
988 break; | |
989 | |
990 case sw_quoted_second: | |
991 | |
992 if (ch >= '0' && ch <= '9') { | |
993 ch = (u_char) ((decoded << 4) + ch - '0'); | |
994 | |
995 state = sw_usual; | |
996 | |
997 if (ch > '%' && ch < 0x7f) { | |
998 *d++ = ch; | |
999 break; | |
1000 } | |
1001 | |
1002 *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1); | |
1003 | |
1004 break; | |
1005 } | |
1006 | |
1007 c = (u_char) (ch | 0x20); | |
1008 if (c >= 'a' && c <= 'f') { | |
1009 ch = (u_char) ((decoded << 4) + c - 'a' + 10); | |
1010 | |
1011 if (ch == '?') { | |
1012 *d++ = ch; | |
1013 goto done; | |
1014 } | |
1015 | |
1016 state = sw_usual; | |
1017 | |
1018 if (ch > '%' && ch < 0x7f) { | |
1019 *d++ = ch; | |
1020 break; | |
1021 } | |
1022 | |
1023 *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1); | |
1024 | |
1025 break; | |
1026 } | |
1027 | |
1028 /* skip the invalid quoted character */ | |
1029 | |
1030 break; | |
1031 } | |
1032 } | |
1033 | |
1034 done: | |
1035 | |
1036 *dst = d; | |
1037 *src = s; | |
1038 } | |
583 | 1039 |
1040 | |
1041 #if (NGX_MEMCPY_LIMIT) | |
1042 | |
1043 void * | |
1044 ngx_memcpy(void *dst, void *src, size_t n) | |
1045 { | |
1046 if (n > NGX_MEMCPY_LIMIT) { | |
1047 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "memcpy %uz bytes", n); | |
1048 ngx_debug_point(); | |
1049 } | |
1050 | |
1051 return memcpy(dst, src, n); | |
1052 } | |
1053 | |
1054 #endif |