Mercurial > hg > nginx-quic
annotate src/core/ngx_string.c @ 504:4cfdcb10967c
release-0.1.26 tag
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 22 Mar 2005 16:02:46 +0000 |
parents | b1648294f693 |
children | dadfa78d2270 |
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 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
18 for (/* void */; --n; dst++, src++) { |
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 |
60 * %r rlim_t | |
61 * %p pointer | |
62 * %V pointer to ngx_str_t | |
63 * %s null-terminated string | |
64 * %Z '\0' | |
65 * %c char | |
66 * %% % | |
455 | 67 * |
461 | 68 * TODO: |
69 * %M ngx_msec_t | |
70 * | |
71 * reserved: | |
72 * %t ptrdiff_t | |
73 * %S null-teminated wchar string | |
74 * %C wchar | |
455 | 75 */ |
76 | |
461 | 77 |
503 | 78 u_char * ngx_cdecl |
493 | 79 ngx_sprintf(u_char *buf, const char *fmt, ...) |
461 | 80 { |
81 u_char *p; | |
82 va_list args; | |
83 | |
84 va_start(args, fmt); | |
85 p = ngx_vsnprintf(buf, /* STUB */ 65536, fmt, args); | |
86 va_end(args); | |
87 | |
88 return p; | |
89 } | |
90 | |
91 | |
503 | 92 u_char * ngx_cdecl |
493 | 93 ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...) |
455 | 94 { |
461 | 95 u_char *p; |
96 va_list args; | |
97 | |
98 va_start(args, fmt); | |
99 p = ngx_vsnprintf(buf, max, fmt, args); | |
100 va_end(args); | |
101 | |
102 return p; | |
103 } | |
104 | |
455 | 105 |
493 | 106 u_char * |
107 ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args) | |
461 | 108 { |
479 | 109 u_char *p, zero, *last, temp[NGX_INT64_LEN + 1]; |
110 /* | |
111 * really we need temp[NGX_INT64_LEN] only, | |
493 | 112 * but icc issues the warning |
479 | 113 */ |
461 | 114 int d; |
115 size_t len; | |
116 uint32_t ui32; | |
117 int64_t i64; | |
118 uint64_t ui64; | |
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 |
461 | 193 len = (buf + s->len < last) ? s->len : (size_t) (last - buf); |
194 buf = ngx_cpymem(buf, s->data, len); | |
195 fmt++; | |
455 | 196 |
461 | 197 continue; |
455 | 198 |
199 case 's': | |
461 | 200 p = va_arg(args, u_char *); |
455 | 201 |
461 | 202 while (*p && buf < last) { |
455 | 203 *buf++ = *p++; |
204 } | |
205 fmt++; | |
206 | |
207 continue; | |
208 | |
461 | 209 case 'O': |
210 i64 = (int64_t) va_arg(args, off_t); | |
211 sign = 1; | |
212 break; | |
213 | |
214 case 'P': | |
215 i64 = (int64_t) va_arg(args, ngx_pid_t); | |
216 sign = 1; | |
217 break; | |
218 | |
219 case 'T': | |
220 i64 = (int64_t) va_arg(args, time_t); | |
221 sign = 1; | |
222 break; | |
223 | |
224 case 'z': | |
225 if (sign) { | |
226 i64 = (int64_t) va_arg(args, ssize_t); | |
227 } else { | |
228 ui64 = (uint64_t) va_arg(args, size_t); | |
229 } | |
230 break; | |
231 | |
232 case 'i': | |
233 if (sign) { | |
234 i64 = (int64_t) va_arg(args, ngx_int_t); | |
235 } else { | |
236 ui64 = (uint64_t) va_arg(args, ngx_uint_t); | |
237 } | |
493 | 238 |
239 if (max_width) { | |
240 width = NGX_INT_T_LEN; | |
241 } | |
242 | |
461 | 243 break; |
244 | |
245 case 'd': | |
246 if (sign) { | |
247 i64 = (int64_t) va_arg(args, int); | |
248 } else { | |
249 ui64 = (uint64_t) va_arg(args, u_int); | |
250 } | |
251 break; | |
252 | |
253 case 'l': | |
254 if (sign) { | |
255 i64 = (int64_t) va_arg(args, long); | |
256 } else { | |
257 ui64 = (uint64_t) va_arg(args, u_long); | |
258 } | |
259 break; | |
260 | |
261 case 'D': | |
262 if (sign) { | |
263 i64 = (int64_t) va_arg(args, int32_t); | |
264 } else { | |
265 ui64 = (uint64_t) va_arg(args, uint32_t); | |
266 } | |
267 break; | |
268 | |
269 case 'L': | |
270 if (sign) { | |
271 i64 = va_arg(args, int64_t); | |
272 } else { | |
273 ui64 = va_arg(args, uint64_t); | |
274 } | |
275 break; | |
276 | |
493 | 277 case 'A': |
278 if (sign) { | |
279 i64 = (int64_t) va_arg(args, ngx_atomic_int_t); | |
280 } else { | |
495 | 281 ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t); |
493 | 282 } |
283 | |
284 if (max_width) { | |
285 width = NGX_ATOMIC_T_LEN; | |
286 } | |
287 | |
288 break; | |
289 | |
461 | 290 #if !(NGX_WIN32) |
291 case 'r': | |
292 i64 = (int64_t) va_arg(args, rlim_t); | |
293 sign = 1; | |
294 break; | |
295 #endif | |
296 | |
297 case 'p': | |
298 ui64 = (uintptr_t) va_arg(args, void *); | |
299 hexadecimal = 2; | |
300 sign = 0; | |
301 zero = '0'; | |
302 width = 8; | |
303 break; | |
304 | |
457 | 305 case 'c': |
461 | 306 d = va_arg(args, int); |
457 | 307 *buf++ = (u_char) (d & 0xff); |
308 fmt++; | |
309 | |
310 continue; | |
311 | |
461 | 312 case 'Z': |
313 *buf++ = '\0'; | |
314 fmt++; | |
315 | |
316 continue; | |
317 | |
455 | 318 case '%': |
319 *buf++ = '%'; | |
320 fmt++; | |
321 | |
322 continue; | |
323 | |
324 default: | |
325 *buf++ = *fmt++; | |
326 | |
327 continue; | |
328 } | |
329 | |
461 | 330 if (sign) { |
331 if (i64 < 0) { | |
332 *buf++ = '-'; | |
333 ui64 = (uint64_t) -i64; | |
334 | |
335 } else { | |
336 ui64 = (uint64_t) i64; | |
337 } | |
338 } | |
339 | |
340 if (hexadecimal == 1) { | |
341 do { | |
342 | |
343 /* the "(uint32_t)" cast disables the BCC's warning */ | |
344 *--p = hex[(uint32_t) (ui64 & 0xf)]; | |
345 | |
346 } while (ui64 >>= 4); | |
347 | |
348 } else if (hexadecimal == 2) { | |
349 do { | |
350 | |
351 /* the "(uint32_t)" cast disables the BCC's warning */ | |
352 *--p = HEX[(uint32_t) (ui64 & 0xf)]; | |
353 | |
354 } while (ui64 >>= 4); | |
355 | |
356 } else if (ui64 <= NGX_MAX_UINT32_VALUE) { | |
357 | |
358 /* | |
359 * To divide 64-bit number and to find the remainder | |
360 * on the x86 platform gcc and icc call the libc functions | |
361 * [u]divdi3() and [u]moddi3(), they call another function | |
493 | 362 * in its turn. On FreeBSD it is the qdivrem() function, |
461 | 363 * its source code is about 170 lines of the code. |
364 * The glibc counterpart is about 150 lines of the code. | |
365 * | |
493 | 366 * For 32-bit numbers and some divisors gcc and icc use |
367 * the inlined multiplication and shifts. For example, | |
368 * unsigned "i32 / 10" is compiled to | |
369 * | |
370 * (i32 * 0xCCCCCCCD) >> 35 | |
461 | 371 */ |
372 | |
373 ui32 = (uint32_t) ui64; | |
374 | |
375 do { | |
376 *--p = (u_char) (ui32 % 10 + '0'); | |
377 } while (ui32 /= 10); | |
378 | |
379 } else { | |
380 do { | |
381 *--p = (u_char) (ui64 % 10 + '0'); | |
382 } while (ui64 /= 10); | |
383 } | |
384 | |
477 | 385 len = (temp + NGX_INT64_LEN) - p; |
455 | 386 |
461 | 387 while (len++ < width && buf < last) { |
388 *buf++ = zero; | |
455 | 389 } |
390 | |
477 | 391 len = (temp + NGX_INT64_LEN) - p; |
461 | 392 if (buf + len > last) { |
393 len = last - buf; | |
394 } | |
395 | |
396 buf = ngx_cpymem(buf, p, len); | |
455 | 397 |
398 fmt++; | |
399 | |
400 } else { | |
401 *buf++ = *fmt++; | |
402 } | |
403 } | |
404 | |
405 return buf; | |
406 } | |
407 | |
408 | |
493 | 409 ngx_int_t |
410 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
|
411 { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
412 if (n == 0) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
413 return 0; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
414 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
415 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
416 n--; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
417 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
418 for ( ;; ) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
419 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
|
420 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
|
421 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
422 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
423 if (n == 0) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
424 return 0; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
425 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
426 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
427 n--; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
428 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
429 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
430 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
431 |
493 | 432 ngx_int_t |
433 ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n) | |
455 | 434 { |
435 u_char c1, c2; | |
436 | |
437 if (n == 0) { | |
438 return 0; | |
439 } | |
440 | |
441 n--; | |
442 | |
443 for ( ;; ) { | |
444 c1 = s1[n]; | |
445 if (c1 >= 'a' && c1 <= 'z') { | |
446 c1 -= 'a' - 'A'; | |
447 } | |
448 | |
449 c2 = s2[n]; | |
450 if (c2 >= 'a' && c2 <= 'z') { | |
451 c2 -= 'a' - 'A'; | |
452 } | |
453 | |
454 if (c1 != c2) { | |
455 return c1 - c2; | |
456 } | |
457 | |
458 if (n == 0) { | |
459 return 0; | |
460 } | |
461 | |
462 n--; | |
463 } | |
464 } | |
465 | |
466 | |
493 | 467 ngx_int_t |
468 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
|
469 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
470 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
|
471 |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
472 if (n == 0) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
473 return NGX_ERROR; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
474 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
475 |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
476 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
|
477 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
|
478 return NGX_ERROR; |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
479 } |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
480 |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
481 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
|
482 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
483 |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
484 if (value < 0) { |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
485 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
|
486 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
487 } else { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
488 return value; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
489 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
490 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
491 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
492 |
501 | 493 ssize_t |
494 ngx_atosz(u_char *line, size_t n) | |
495 { | |
496 ssize_t value; | |
497 | |
498 if (n == 0) { | |
499 return NGX_ERROR; | |
500 } | |
501 | |
502 for (value = 0; n--; line++) { | |
503 if (*line < '0' || *line > '9') { | |
504 return NGX_ERROR; | |
505 } | |
506 | |
507 value = value * 10 + (*line - '0'); | |
508 } | |
509 | |
510 if (value < 0) { | |
511 return NGX_ERROR; | |
512 | |
513 } else { | |
514 return value; | |
515 } | |
516 } | |
517 | |
518 | |
519 off_t | |
520 ngx_atoof(u_char *line, size_t n) | |
521 { | |
522 off_t value; | |
523 | |
524 if (n == 0) { | |
525 return NGX_ERROR; | |
526 } | |
527 | |
528 for (value = 0; n--; line++) { | |
529 if (*line < '0' || *line > '9') { | |
530 return NGX_ERROR; | |
531 } | |
532 | |
533 value = value * 10 + (*line - '0'); | |
534 } | |
535 | |
536 if (value < 0) { | |
537 return NGX_ERROR; | |
538 | |
539 } else { | |
540 return value; | |
541 } | |
542 } | |
543 | |
544 | |
545 time_t | |
546 ngx_atotm(u_char *line, size_t n) | |
547 { | |
548 time_t value; | |
549 | |
550 if (n == 0) { | |
551 return NGX_ERROR; | |
552 } | |
553 | |
554 for (value = 0; n--; line++) { | |
555 if (*line < '0' || *line > '9') { | |
556 return NGX_ERROR; | |
557 } | |
558 | |
559 value = value * 10 + (*line - '0'); | |
560 } | |
561 | |
562 if (value < 0) { | |
563 return NGX_ERROR; | |
564 | |
565 } else { | |
566 return value; | |
567 } | |
568 } | |
569 | |
570 | |
493 | 571 ngx_int_t |
572 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
|
573 { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
574 u_char ch; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
575 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
|
576 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
577 if (n == 0) { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
578 return NGX_ERROR; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
579 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
580 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
581 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
|
582 ch = *line; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
583 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
584 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
|
585 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
|
586 continue; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
587 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
588 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
589 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
|
590 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
|
591 continue; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
592 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
593 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
594 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
|
595 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
|
596 continue; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
597 } |
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 return NGX_ERROR; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
600 } |
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 if (value < 0) { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
603 return NGX_ERROR; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
604 |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
605 } else { |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
606 return value; |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
607 } |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
608 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
609 |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
610 |
493 | 611 void |
612 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
|
613 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
614 int i; |
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
615 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
|
616 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
617 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
|
618 *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
|
619 *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
|
620 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
621 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
622 *text = '\0'; |
174
ea464a6c0581
nginx-0.0.1-2003-11-05-01:12:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
623 } |
ea464a6c0581
nginx-0.0.1-2003-11-05-01:12:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
624 |
ea464a6c0581
nginx-0.0.1-2003-11-05-01:12:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
625 |
493 | 626 void |
627 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
|
628 { |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
629 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
|
630 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
|
631 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
|
632 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
633 |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
634 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
|
635 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
|
636 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
|
637 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
638 while (len > 2) { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
639 *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
|
640 *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
|
641 *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
|
642 *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
|
643 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
644 s += 3; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
645 len -= 3; |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
646 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
647 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
648 if (len) { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
649 *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
|
650 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
651 if (len == 1) { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
652 *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
|
653 *d++ = '='; |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
654 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
655 } else { |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
656 *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
|
657 *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
|
658 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
659 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
660 *d++ = '='; |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
661 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
662 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
663 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
|
664 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
665 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
666 |
493 | 667 ngx_int_t |
668 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
|
669 { |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
670 size_t len; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
671 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
|
672 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
|
673 { 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
|
674 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
|
675 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
|
676 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
|
677 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
|
678 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
|
679 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
|
680 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
|
681 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
682 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
|
683 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
|
684 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
|
685 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
|
686 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
|
687 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
|
688 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
|
689 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
|
690 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
691 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
|
692 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
|
693 break; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
694 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
695 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
696 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
|
697 return NGX_ERROR; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
698 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
699 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
700 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
701 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
|
702 return NGX_ERROR; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
703 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
704 |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
705 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
|
706 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
|
707 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
708 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
|
709 *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
|
710 *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
|
711 *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
|
712 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
713 s += 4; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
714 len -= 4; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
715 } |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
716 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
717 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
|
718 *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
|
719 } |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
720 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
721 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
|
722 *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
|
723 } |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
724 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
725 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
|
726 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
727 return NGX_OK; |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
728 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
729 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
730 |
493 | 731 uintptr_t |
732 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
|
733 { |
461 | 734 ngx_uint_t i, n; |
735 uint32_t *escape; | |
452 | 736 static u_char hex[] = "0123456789abcdef"; |
461 | 737 |
493 | 738 /* " ", "#", "%", "?", %00-%1F, %7F-%FF */ |
485 | 739 |
461 | 740 static uint32_t uri[] = |
452 | 741 { 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
|
742 |
452 | 743 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
493 | 744 0x80000029, /* 1000 0000 0000 0000 0000 0000 0010 1001 */ |
452 | 745 |
746 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ | |
747 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ | |
748 | |
749 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ | |
750 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
|
751 |
452 | 752 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
753 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
754 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
755 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ }; | |
756 | |
493 | 757 /* " ", "#", "%", "+", "?", %00-%1F, %7F-%FF */ |
485 | 758 |
759 static uint32_t args[] = | |
760 { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
761 | |
762 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ | |
493 | 763 0x80000829, /* 1000 0000 0000 0000 0000 1000 0010 1001 */ |
485 | 764 |
765 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ | |
766 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ | |
767 | |
768 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ | |
769 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */ | |
770 | |
771 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
772 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
773 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
774 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ }; | |
775 | |
776 /* " ", """, "%", "'", %00-%1F, %7F-%FF */ | |
777 | |
461 | 778 static uint32_t html[] = |
779 { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
780 | |
781 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ | |
493 | 782 0x800000ad, /* 0000 0000 0000 0000 0000 0000 1010 1101 */ |
461 | 783 |
784 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ | |
785 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ | |
786 | |
787 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ | |
788 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */ | |
789 | |
790 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
791 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
792 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
793 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ }; | |
794 | |
795 | |
485 | 796 switch (type) { |
797 case NGX_ESCAPE_HTML: | |
461 | 798 escape = html; |
485 | 799 break; |
800 case NGX_ESCAPE_ARGS: | |
801 escape = args; | |
802 break; | |
803 default: | |
461 | 804 escape = uri; |
485 | 805 break; |
461 | 806 } |
807 | |
452 | 808 if (dst == NULL) { |
809 | |
810 /* 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
|
811 |
452 | 812 n = 0; |
813 | |
814 for (i = 0; i < size; i++) { | |
815 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { | |
816 n++; | |
817 } | |
818 src++; | |
819 } | |
820 | |
485 | 821 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
|
822 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
823 |
452 | 824 for (i = 0; i < size; i++) { |
825 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { | |
826 *dst++ = '%'; | |
827 *dst++ = hex[*src >> 4]; | |
828 *dst++ = hex[*src & 0xf]; | |
829 src++; | |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
830 |
452 | 831 } else { |
832 *dst++ = *src++; | |
833 } | |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
834 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
835 |
485 | 836 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
|
837 } |