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