Mercurial > hg > nginx-quic
annotate src/core/ngx_string.c @ 6819:4395758d08e6
Fixed spelling of logical AND operator, no functional changes.
Found by PVS-Studio.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 07 Dec 2016 13:54:30 +0300 |
parents | b3682580c1bd |
children | 289403abc84e 5c25f01bbd52 |
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'; | |
6314
fcbac620ae83
Style: NGX_PTR_SIZE replaced with sizeof(void *).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6009
diff
changeset
|
413 width = 2 * sizeof(void *); |
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; | |
5965
78271500b8de
A bounds check of %N format on Windows.
Igor Sysoev <igor@sysoev.ru>
parents:
5944
diff
changeset
|
432 if (buf < last) { |
78271500b8de
A bounds check of %N format on Windows.
Igor Sysoev <igor@sysoev.ru>
parents:
5944
diff
changeset
|
433 *buf++ = LF; |
78271500b8de
A bounds check of %N format on Windows.
Igor Sysoev <igor@sysoev.ru>
parents:
5944
diff
changeset
|
434 } |
78271500b8de
A bounds check of %N format on Windows.
Igor Sysoev <igor@sysoev.ru>
parents:
5944
diff
changeset
|
435 #else |
78271500b8de
A bounds check of %N format on Windows.
Igor Sysoev <igor@sysoev.ru>
parents:
5944
diff
changeset
|
436 *buf++ = LF; |
525 | 437 #endif |
438 fmt++; | |
439 | |
440 continue; | |
441 | |
455 | 442 case '%': |
443 *buf++ = '%'; | |
444 fmt++; | |
445 | |
446 continue; | |
447 | |
448 default: | |
449 *buf++ = *fmt++; | |
450 | |
451 continue; | |
452 } | |
453 | |
461 | 454 if (sign) { |
455 if (i64 < 0) { | |
456 *buf++ = '-'; | |
457 ui64 = (uint64_t) -i64; | |
458 | |
459 } else { | |
460 ui64 = (uint64_t) i64; | |
461 } | |
462 } | |
463 | |
2293 | 464 buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width); |
455 | 465 |
466 fmt++; | |
467 | |
468 } else { | |
469 *buf++ = *fmt++; | |
470 } | |
471 } | |
472 | |
473 return buf; | |
474 } | |
475 | |
476 | |
2293 | 477 static u_char * |
478 ngx_sprintf_num(u_char *buf, u_char *last, uint64_t ui64, u_char zero, | |
479 ngx_uint_t hexadecimal, ngx_uint_t width) | |
480 { | |
481 u_char *p, temp[NGX_INT64_LEN + 1]; | |
482 /* | |
483 * we need temp[NGX_INT64_LEN] only, | |
484 * but icc issues the warning | |
485 */ | |
486 size_t len; | |
487 uint32_t ui32; | |
488 static u_char hex[] = "0123456789abcdef"; | |
489 static u_char HEX[] = "0123456789ABCDEF"; | |
490 | |
491 p = temp + NGX_INT64_LEN; | |
492 | |
493 if (hexadecimal == 0) { | |
494 | |
5358
670ceaba03d8
Win32: Open Watcom C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4781
diff
changeset
|
495 if (ui64 <= (uint64_t) NGX_MAX_UINT32_VALUE) { |
2293 | 496 |
497 /* | |
498 * To divide 64-bit numbers and to find remainders | |
499 * on the x86 platform gcc and icc call the libc functions | |
500 * [u]divdi3() and [u]moddi3(), they call another function | |
501 * in its turn. On FreeBSD it is the qdivrem() function, | |
502 * its source code is about 170 lines of the code. | |
503 * The glibc counterpart is about 150 lines of the code. | |
504 * | |
505 * For 32-bit numbers and some divisors gcc and icc use | |
506 * a inlined multiplication and shifts. For example, | |
507 * unsigned "i32 / 10" is compiled to | |
508 * | |
509 * (i32 * 0xCCCCCCCD) >> 35 | |
510 */ | |
511 | |
512 ui32 = (uint32_t) ui64; | |
513 | |
514 do { | |
515 *--p = (u_char) (ui32 % 10 + '0'); | |
516 } while (ui32 /= 10); | |
517 | |
518 } else { | |
519 do { | |
520 *--p = (u_char) (ui64 % 10 + '0'); | |
521 } while (ui64 /= 10); | |
522 } | |
523 | |
524 } else if (hexadecimal == 1) { | |
525 | |
526 do { | |
527 | |
528 /* the "(uint32_t)" cast disables the BCC's warning */ | |
529 *--p = hex[(uint32_t) (ui64 & 0xf)]; | |
530 | |
531 } while (ui64 >>= 4); | |
532 | |
533 } else { /* hexadecimal == 2 */ | |
534 | |
535 do { | |
536 | |
537 /* the "(uint32_t)" cast disables the BCC's warning */ | |
538 *--p = HEX[(uint32_t) (ui64 & 0xf)]; | |
539 | |
540 } while (ui64 >>= 4); | |
541 } | |
542 | |
543 /* zero or space padding */ | |
544 | |
545 len = (temp + NGX_INT64_LEN) - p; | |
546 | |
547 while (len++ < width && buf < last) { | |
548 *buf++ = zero; | |
549 } | |
550 | |
551 /* number safe copy */ | |
552 | |
553 len = (temp + NGX_INT64_LEN) - p; | |
554 | |
555 if (buf + len > last) { | |
556 len = last - buf; | |
557 } | |
558 | |
559 return ngx_cpymem(buf, p, len); | |
560 } | |
561 | |
562 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
563 /* |
1541 | 564 * 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
|
565 * and implement our own ngx_strcasecmp()/ngx_strncasecmp() |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
566 * 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
|
567 * 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
|
568 */ |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
569 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
570 ngx_int_t |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
571 ngx_strcasecmp(u_char *s1, u_char *s2) |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
572 { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
573 ngx_uint_t c1, c2; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
574 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
575 for ( ;; ) { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
576 c1 = (ngx_uint_t) *s1++; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
577 c2 = (ngx_uint_t) *s2++; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
578 |
3115 | 579 c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1; |
580 c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2; | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
581 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
582 if (c1 == c2) { |
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 if (c1) { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
585 continue; |
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 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
588 return 0; |
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 return c1 - c2; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
592 } |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
593 } |
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 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
596 ngx_int_t |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
597 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
|
598 { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
599 ngx_uint_t c1, c2; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
600 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
601 while (n) { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
602 c1 = (ngx_uint_t) *s1++; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
603 c2 = (ngx_uint_t) *s2++; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
604 |
3115 | 605 c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1; |
606 c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2; | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
607 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
608 if (c1 == c2) { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
609 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
610 if (c1) { |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
611 n--; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
612 continue; |
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 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
615 return 0; |
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 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
618 return c1 - c2; |
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 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
621 return 0; |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
622 } |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
623 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1029
diff
changeset
|
624 |
1552 | 625 u_char * |
626 ngx_strnstr(u_char *s1, char *s2, size_t len) | |
627 { | |
628 u_char c1, c2; | |
629 size_t n; | |
630 | |
631 c2 = *(u_char *) s2++; | |
632 | |
633 n = ngx_strlen(s2); | |
634 | |
635 do { | |
636 do { | |
637 if (len-- == 0) { | |
638 return NULL; | |
639 } | |
640 | |
641 c1 = *s1++; | |
642 | |
643 if (c1 == 0) { | |
644 return NULL; | |
645 } | |
646 | |
647 } while (c1 != c2); | |
648 | |
649 if (n > len) { | |
650 return NULL; | |
651 } | |
652 | |
653 } while (ngx_strncmp(s1, (u_char *) s2, n) != 0); | |
654 | |
655 return --s1; | |
656 } | |
657 | |
658 | |
1550 | 659 /* |
660 * ngx_strstrn() and ngx_strcasestrn() are intended to search for static | |
661 * substring with known length in null-terminated string. The argument n | |
662 * must be length of the second substring - 1. | |
663 */ | |
664 | |
1542
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
665 u_char * |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
666 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
|
667 { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
668 u_char c1, c2; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
669 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
670 c2 = *(u_char *) s2++; |
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 do { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
673 do { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
674 c1 = *s1++; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
675 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
676 if (c1 == 0) { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
677 return NULL; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
678 } |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
679 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
680 } while (c1 != c2); |
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 } while (ngx_strncmp(s1, (u_char *) s2, n) != 0); |
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 return --s1; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
685 } |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
686 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
687 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
688 u_char * |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
689 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
|
690 { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
691 ngx_uint_t c1, c2; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
692 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
693 c2 = (ngx_uint_t) *s2++; |
3115 | 694 c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2; |
1542
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
695 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
696 do { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
697 do { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
698 c1 = (ngx_uint_t) *s1++; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
699 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
700 if (c1 == 0) { |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
701 return NULL; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
702 } |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
703 |
3115 | 704 c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1; |
1542
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 } while (c1 != c2); |
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 } while (ngx_strncasecmp(s1, (u_char *) s2, n) != 0); |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
709 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
710 return --s1; |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
711 } |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
712 |
f5bd1a7ed2cd
ngx_strstrn() and ngx_strcasestrn()
Igor Sysoev <igor@sysoev.ru>
parents:
1541
diff
changeset
|
713 |
2668 | 714 /* |
715 * ngx_strlcasestrn() is intended to search for static substring | |
716 * with known length in string until the argument last. The argument n | |
717 * must be length of the second substring - 1. | |
718 */ | |
719 | |
720 u_char * | |
721 ngx_strlcasestrn(u_char *s1, u_char *last, u_char *s2, size_t n) | |
722 { | |
723 ngx_uint_t c1, c2; | |
724 | |
725 c2 = (ngx_uint_t) *s2++; | |
3115 | 726 c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2; |
2668 | 727 last -= n; |
728 | |
729 do { | |
730 do { | |
2680
82e3946062be
backout r2677 and fix ngx_strlcasestrn() again
Igor Sysoev <igor@sysoev.ru>
parents:
2676
diff
changeset
|
731 if (s1 >= last) { |
2668 | 732 return NULL; |
733 } | |
734 | |
735 c1 = (ngx_uint_t) *s1++; | |
736 | |
3115 | 737 c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1; |
2668 | 738 |
739 } while (c1 != c2); | |
740 | |
741 } while (ngx_strncasecmp(s1, s2, n) != 0); | |
742 | |
743 return --s1; | |
744 } | |
745 | |
746 | |
493 | 747 ngx_int_t |
748 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
|
749 { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
750 if (n == 0) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
751 return 0; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
752 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
753 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
754 n--; |
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 for ( ;; ) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
757 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
|
758 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
|
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 if (n == 0) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
762 return 0; |
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 n--; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
766 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
767 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
768 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
769 |
493 | 770 ngx_int_t |
771 ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n) | |
455 | 772 { |
773 u_char c1, c2; | |
774 | |
775 if (n == 0) { | |
776 return 0; | |
777 } | |
778 | |
779 n--; | |
780 | |
781 for ( ;; ) { | |
782 c1 = s1[n]; | |
783 if (c1 >= 'a' && c1 <= 'z') { | |
784 c1 -= 'a' - 'A'; | |
785 } | |
786 | |
787 c2 = s2[n]; | |
788 if (c2 >= 'a' && c2 <= 'z') { | |
789 c2 -= 'a' - 'A'; | |
790 } | |
791 | |
792 if (c1 != c2) { | |
793 return c1 - c2; | |
794 } | |
795 | |
796 if (n == 0) { | |
797 return 0; | |
798 } | |
799 | |
800 n--; | |
801 } | |
802 } | |
803 | |
804 | |
493 | 805 ngx_int_t |
1029
ce08bc4cb97b
ngx_strn2cmp() > ngx_memn2cmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1024
diff
changeset
|
806 ngx_memn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2) |
1024 | 807 { |
808 size_t n; | |
809 ngx_int_t m, z; | |
810 | |
811 if (n1 <= n2) { | |
812 n = n1; | |
813 z = -1; | |
814 | |
815 } else { | |
816 n = n2; | |
817 z = 1; | |
818 } | |
819 | |
1029
ce08bc4cb97b
ngx_strn2cmp() > ngx_memn2cmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1024
diff
changeset
|
820 m = ngx_memcmp(s1, s2, n); |
1024 | 821 |
822 if (m || n1 == n2) { | |
823 return m; | |
824 } | |
825 | |
826 return z; | |
827 } | |
828 | |
829 | |
830 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
|
831 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
|
832 { |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
833 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
|
834 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
835 for ( ;; ) { |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
836 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
|
837 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
|
838 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
839 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
|
840 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
|
841 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
842 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
|
843 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
844 if (c1) { |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
845 continue; |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
846 } |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
847 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
848 return 0; |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
849 } |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
850 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
851 /* 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
|
852 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
853 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
|
854 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
|
855 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
856 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
|
857 } |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
858 } |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
859 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
860 |
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
861 ngx_int_t |
5389
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
862 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
|
863 { |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
864 ngx_uint_t c1, c2; |
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 while (n) { |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
867 c1 = (ngx_uint_t) *s1++; |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
868 c2 = (ngx_uint_t) *s2++; |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
869 |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
870 #if (NGX_HAVE_CASELESS_FILESYSTEM) |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
871 c1 = tolower(c1); |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
872 c2 = tolower(c2); |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
873 #endif |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
874 |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
875 if (c1 == c2) { |
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 if (c1) { |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
878 n--; |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
879 continue; |
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 |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
882 return 0; |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
883 } |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
884 |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
885 /* 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
|
886 |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
887 if (c1 == 0 || c2 == 0) { |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
888 return c1 - 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 |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
891 c1 = (c1 == '/') ? 0 : c1; |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
892 c2 = (c2 == '/') ? 0 : c2; |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
893 |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
894 return c1 - c2; |
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 return 0; |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
898 } |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
899 |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
900 |
72e31d88defa
Added ngx_filename_cmp() with "/" sorted to the left.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5358
diff
changeset
|
901 ngx_int_t |
493 | 902 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
|
903 { |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
904 ngx_int_t value, cutoff, cutlim; |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
905 |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
906 if (n == 0) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
907 return NGX_ERROR; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
908 } |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
909 |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
910 cutoff = NGX_MAX_INT_T_VALUE / 10; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
911 cutlim = NGX_MAX_INT_T_VALUE % 10; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
912 |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
913 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
|
914 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
|
915 return NGX_ERROR; |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
916 } |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
917 |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
918 if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) { |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
919 return NGX_ERROR; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
920 } |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
921 |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
922 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
|
923 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
924 |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
925 return value; |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
926 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
927 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
928 |
3512 | 929 /* parse a fixed point number, e.g., ngx_atofp("10.5", 4, 2) returns 1050 */ |
930 | |
931 ngx_int_t | |
932 ngx_atofp(u_char *line, size_t n, size_t point) | |
933 { | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
934 ngx_int_t value, cutoff, cutlim; |
3512 | 935 ngx_uint_t dot; |
936 | |
937 if (n == 0) { | |
938 return NGX_ERROR; | |
939 } | |
940 | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
941 cutoff = NGX_MAX_INT_T_VALUE / 10; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
942 cutlim = NGX_MAX_INT_T_VALUE % 10; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
943 |
3512 | 944 dot = 0; |
945 | |
946 for (value = 0; n--; line++) { | |
947 | |
948 if (point == 0) { | |
949 return NGX_ERROR; | |
950 } | |
951 | |
952 if (*line == '.') { | |
953 if (dot) { | |
954 return NGX_ERROR; | |
955 } | |
956 | |
957 dot = 1; | |
958 continue; | |
959 } | |
960 | |
961 if (*line < '0' || *line > '9') { | |
962 return NGX_ERROR; | |
963 } | |
964 | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
965 if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) { |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
966 return NGX_ERROR; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
967 } |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
968 |
3512 | 969 value = value * 10 + (*line - '0'); |
970 point -= dot; | |
971 } | |
972 | |
973 while (point--) { | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
974 if (value > cutoff) { |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
975 return NGX_ERROR; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
976 } |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
977 |
3512 | 978 value = value * 10; |
979 } | |
980 | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
981 return value; |
3512 | 982 } |
983 | |
984 | |
501 | 985 ssize_t |
986 ngx_atosz(u_char *line, size_t n) | |
987 { | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
988 ssize_t value, cutoff, cutlim; |
501 | 989 |
990 if (n == 0) { | |
991 return NGX_ERROR; | |
992 } | |
993 | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
994 cutoff = NGX_MAX_SIZE_T_VALUE / 10; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
995 cutlim = NGX_MAX_SIZE_T_VALUE % 10; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
996 |
501 | 997 for (value = 0; n--; line++) { |
998 if (*line < '0' || *line > '9') { | |
999 return NGX_ERROR; | |
1000 } | |
1001 | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1002 if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) { |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1003 return NGX_ERROR; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1004 } |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1005 |
501 | 1006 value = value * 10 + (*line - '0'); |
1007 } | |
1008 | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1009 return value; |
501 | 1010 } |
1011 | |
1012 | |
1013 off_t | |
1014 ngx_atoof(u_char *line, size_t n) | |
1015 { | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1016 off_t value, cutoff, cutlim; |
501 | 1017 |
1018 if (n == 0) { | |
1019 return NGX_ERROR; | |
1020 } | |
1021 | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1022 cutoff = NGX_MAX_OFF_T_VALUE / 10; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1023 cutlim = NGX_MAX_OFF_T_VALUE % 10; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1024 |
501 | 1025 for (value = 0; n--; line++) { |
1026 if (*line < '0' || *line > '9') { | |
1027 return NGX_ERROR; | |
1028 } | |
1029 | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1030 if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) { |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1031 return NGX_ERROR; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1032 } |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1033 |
501 | 1034 value = value * 10 + (*line - '0'); |
1035 } | |
1036 | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1037 return value; |
501 | 1038 } |
1039 | |
1040 | |
1041 time_t | |
1042 ngx_atotm(u_char *line, size_t n) | |
1043 { | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1044 time_t value, cutoff, cutlim; |
501 | 1045 |
1046 if (n == 0) { | |
1047 return NGX_ERROR; | |
1048 } | |
1049 | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1050 cutoff = NGX_MAX_TIME_T_VALUE / 10; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1051 cutlim = NGX_MAX_TIME_T_VALUE % 10; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1052 |
501 | 1053 for (value = 0; n--; line++) { |
1054 if (*line < '0' || *line > '9') { | |
1055 return NGX_ERROR; | |
1056 } | |
1057 | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1058 if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) { |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1059 return NGX_ERROR; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1060 } |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1061 |
501 | 1062 value = value * 10 + (*line - '0'); |
1063 } | |
1064 | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1065 return value; |
501 | 1066 } |
1067 | |
1068 | |
493 | 1069 ngx_int_t |
1070 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
|
1071 { |
783 | 1072 u_char c, ch; |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1073 ngx_int_t value, cutoff; |
338
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 if (n == 0) { |
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 |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1079 cutoff = NGX_MAX_INT_T_VALUE / 16; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1080 |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1081 for (value = 0; n--; line++) { |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1082 if (value > cutoff) { |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1083 return NGX_ERROR; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1084 } |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1085 |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1086 ch = *line; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1087 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1088 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
|
1089 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
|
1090 continue; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1091 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1092 |
783 | 1093 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
|
1094 |
783 | 1095 if (c >= 'a' && c <= 'f') { |
1096 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
|
1097 continue; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1098 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1099 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1100 return NGX_ERROR; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1101 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1102 |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
5965
diff
changeset
|
1103 return value; |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1104 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1105 |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1106 |
1745
ec63069aeb78
replace ngx_md5_text() with ngx_hex_dump()
Igor Sysoev <igor@sysoev.ru>
parents:
1629
diff
changeset
|
1107 u_char * |
ec63069aeb78
replace ngx_md5_text() with ngx_hex_dump()
Igor Sysoev <igor@sysoev.ru>
parents:
1629
diff
changeset
|
1108 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
|
1109 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
1110 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
|
1111 |
1745
ec63069aeb78
replace ngx_md5_text() with ngx_hex_dump()
Igor Sysoev <igor@sysoev.ru>
parents:
1629
diff
changeset
|
1112 while (len--) { |
ec63069aeb78
replace ngx_md5_text() with ngx_hex_dump()
Igor Sysoev <igor@sysoev.ru>
parents:
1629
diff
changeset
|
1113 *dst++ = hex[*src >> 4]; |
ec63069aeb78
replace ngx_md5_text() with ngx_hex_dump()
Igor Sysoev <igor@sysoev.ru>
parents:
1629
diff
changeset
|
1114 *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
|
1115 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
1116 |
1745
ec63069aeb78
replace ngx_md5_text() with ngx_hex_dump()
Igor Sysoev <igor@sysoev.ru>
parents:
1629
diff
changeset
|
1117 return dst; |
174
ea464a6c0581
nginx-0.0.1-2003-11-05-01:12:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
1118 } |
ea464a6c0581
nginx-0.0.1-2003-11-05-01:12:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
1119 |
ea464a6c0581
nginx-0.0.1-2003-11-05-01:12:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
1120 |
493 | 1121 void |
1122 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
|
1123 { |
5551
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1124 static u_char basis64[] = |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1125 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1126 |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1127 ngx_encode_base64_internal(dst, src, basis64, 1); |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1128 } |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1129 |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1130 |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1131 void |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1132 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
|
1133 { |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1134 static u_char basis64[] = |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1135 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1136 |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1137 ngx_encode_base64_internal(dst, src, basis64, 0); |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1138 } |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1139 |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1140 |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1141 static void |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1142 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
|
1143 ngx_uint_t padding) |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1144 { |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1145 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
|
1146 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
|
1147 |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
1148 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
|
1149 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
|
1150 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
|
1151 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1152 while (len > 2) { |
5551
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1153 *d++ = basis[(s[0] >> 2) & 0x3f]; |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1154 *d++ = basis[((s[0] & 3) << 4) | (s[1] >> 4)]; |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1155 *d++ = basis[((s[1] & 0x0f) << 2) | (s[2] >> 6)]; |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1156 *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
|
1157 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1158 s += 3; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1159 len -= 3; |
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 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1162 if (len) { |
5551
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1163 *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
|
1164 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1165 if (len == 1) { |
5551
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1166 *d++ = basis[(s[0] & 3) << 4]; |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1167 if (padding) { |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1168 *d++ = '='; |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1169 } |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1170 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1171 } else { |
5551
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1172 *d++ = basis[((s[0] & 3) << 4) | (s[1] >> 4)]; |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1173 *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
|
1174 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1175 |
5551
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1176 if (padding) { |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1177 *d++ = '='; |
a602e1006579
Core: added ngx_encode_base64url().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5389
diff
changeset
|
1178 } |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1179 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1180 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1181 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
|
1182 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1183 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1184 |
493 | 1185 ngx_int_t |
1186 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
|
1187 { |
827 | 1188 static u_char basis64[] = { |
1189 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1190 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1191 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 62, 77, 77, 77, 63, | |
1192 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 77, 77, 77, 77, 77, 77, | |
1193 77, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, | |
1194 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 77, 77, 77, 77, 77, | |
1195 77, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, | |
1196 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
|
1197 |
827 | 1198 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, |
1199 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1200 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1201 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1202 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1203 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1204 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | |
1205 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77 | |
1206 }; | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1207 |
3756
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1208 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
|
1209 } |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1210 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1211 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1212 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
|
1213 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
|
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 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
|
1216 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
|
1217 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
|
1218 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
|
1219 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
|
1220 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
|
1221 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
|
1222 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
|
1223 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
|
1224 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1225 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
|
1226 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
|
1227 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
|
1228 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
|
1229 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
|
1230 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
|
1231 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
|
1232 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
|
1233 }; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1234 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1235 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
|
1236 } |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1237 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1238 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1239 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
|
1240 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
|
1241 { |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1242 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
|
1243 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
|
1244 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1245 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
|
1246 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
|
1247 break; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1248 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1249 |
3756
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3725
diff
changeset
|
1250 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
|
1251 return NGX_ERROR; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1252 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1253 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1254 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1255 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
|
1256 return NGX_ERROR; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1257 } |
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 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
|
1260 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 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1262 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
|
1263 *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
|
1264 *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
|
1265 *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
|
1266 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1267 s += 4; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1268 len -= 4; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1269 } |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1270 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1271 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
|
1272 *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
|
1273 } |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1274 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1275 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
|
1276 *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
|
1277 } |
404
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1278 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
1279 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
|
1280 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1281 return NGX_OK; |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1282 } |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1283 |
37b5381fb6d8
nginx-0.0.9-2004-07-30-21:05:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1284 |
657 | 1285 /* |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1286 * ngx_utf8_decode() decodes two and more bytes UTF sequences only |
657 | 1287 * the return values: |
1288 * 0x80 - 0x10ffff valid character | |
2120 | 1289 * 0x110000 - 0xfffffffd invalid sequence |
657 | 1290 * 0xfffffffe incomplete sequence |
1291 * 0xffffffff error | |
1292 */ | |
1293 | |
1294 uint32_t | |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1295 ngx_utf8_decode(u_char **p, size_t n) |
657 | 1296 { |
1297 size_t len; | |
1298 uint32_t u, i, valid; | |
1299 | |
1300 u = **p; | |
1301 | |
4209
9679fc14c063
Fixed utf8 decode (ticket #25).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4192
diff
changeset
|
1302 if (u >= 0xf0) { |
657 | 1303 |
1304 u &= 0x07; | |
1305 valid = 0xffff; | |
1306 len = 3; | |
1307 | |
4209
9679fc14c063
Fixed utf8 decode (ticket #25).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4192
diff
changeset
|
1308 } else if (u >= 0xe0) { |
657 | 1309 |
1310 u &= 0x0f; | |
1311 valid = 0x7ff; | |
1312 len = 2; | |
1313 | |
4209
9679fc14c063
Fixed utf8 decode (ticket #25).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4192
diff
changeset
|
1314 } else if (u >= 0xc2) { |
657 | 1315 |
1316 u &= 0x1f; | |
1317 valid = 0x7f; | |
1318 len = 1; | |
1319 | |
1320 } else { | |
1321 (*p)++; | |
1322 return 0xffffffff; | |
1323 } | |
1324 | |
1325 if (n - 1 < len) { | |
1326 return 0xfffffffe; | |
1327 } | |
1328 | |
1329 (*p)++; | |
1330 | |
1331 while (len) { | |
1332 i = *(*p)++; | |
1333 | |
1334 if (i < 0x80) { | |
1335 return 0xffffffff; | |
1336 } | |
1337 | |
1338 u = (u << 6) | (i & 0x3f); | |
1339 | |
1340 len--; | |
1341 } | |
1342 | |
1343 if (u > valid) { | |
1344 return u; | |
1345 } | |
1346 | |
1347 return 0xffffffff; | |
1348 } | |
1349 | |
1350 | |
523 | 1351 size_t |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1352 ngx_utf8_length(u_char *p, size_t n) |
523 | 1353 { |
2120 | 1354 u_char c, *last; |
1355 size_t len; | |
523 | 1356 |
2120 | 1357 last = p + n; |
523 | 1358 |
2120 | 1359 for (len = 0; p < last; len++) { |
1360 | |
1361 c = *p; | |
523 | 1362 |
1363 if (c < 0x80) { | |
2120 | 1364 p++; |
523 | 1365 continue; |
1366 } | |
1367 | |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1368 if (ngx_utf8_decode(&p, n) > 0x10ffff) { |
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1369 /* invalid UTF-8 */ |
2120 | 1370 return n; |
523 | 1371 } |
1372 } | |
1373 | |
1374 return len; | |
1375 } | |
1376 | |
1377 | |
527 | 1378 u_char * |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1379 ngx_utf8_cpystrn(u_char *dst, u_char *src, size_t n, size_t len) |
527 | 1380 { |
2120 | 1381 u_char c, *next; |
527 | 1382 |
1383 if (n == 0) { | |
1384 return dst; | |
1385 } | |
1386 | |
2120 | 1387 while (--n) { |
527 | 1388 |
1389 c = *src; | |
1390 *dst = c; | |
1391 | |
1392 if (c < 0x80) { | |
2120 | 1393 |
1394 if (c != '\0') { | |
1395 dst++; | |
1396 src++; | |
1397 len--; | |
1398 | |
527 | 1399 continue; |
1400 } | |
1401 | |
1402 return dst; | |
1403 } | |
1404 | |
2120 | 1405 next = src; |
527 | 1406 |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1407 if (ngx_utf8_decode(&next, len) > 0x10ffff) { |
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2120
diff
changeset
|
1408 /* invalid UTF-8 */ |
2120 | 1409 break; |
527 | 1410 } |
1411 | |
2120 | 1412 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
|
1413 *dst++ = *src++; |
2120 | 1414 len--; |
1415 } | |
527 | 1416 } |
1417 | |
1418 *dst = '\0'; | |
1419 | |
1420 return dst; | |
1421 } | |
1422 | |
1423 | |
493 | 1424 uintptr_t |
1425 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
|
1426 { |
3275 | 1427 ngx_uint_t n; |
827 | 1428 uint32_t *escape; |
5772
d421be0d842a
Core: use uppercase hexadecimal digits for percent-encoding.
Piotr Sikora <piotr@cloudflare.com>
parents:
5551
diff
changeset
|
1429 static u_char hex[] = "0123456789ABCDEF"; |
461 | 1430 |
827 | 1431 /* " ", "#", "%", "?", %00-%1F, %7F-%FF */ |
485 | 1432 |
827 | 1433 static uint32_t uri[] = { |
1434 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
|
1435 |
827 | 1436 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
1437 0x80000029, /* 1000 0000 0000 0000 0000 0000 0010 1001 */ | |
1438 | |
1439 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ | |
1440 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ | |
452 | 1441 |
827 | 1442 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ |
1443 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
|
1444 |
827 | 1445 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
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 }; | |
452 | 1450 |
3486
5d28d30ba1b1
escape ampersand in argument while rewrite
Igor Sysoev <igor@sysoev.ru>
parents:
3410
diff
changeset
|
1451 /* " ", "#", "%", "&", "+", "?", %00-%1F, %7F-%FF */ |
485 | 1452 |
827 | 1453 static uint32_t args[] = { |
1454 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1455 | |
1456 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ | |
3725 | 1457 0x88000869, /* 1000 1000 0000 0000 0000 1000 0110 1001 */ |
485 | 1458 |
827 | 1459 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ |
1460 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ | |
485 | 1461 |
827 | 1462 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ |
1463 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */ | |
485 | 1464 |
827 | 1465 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
1466 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1467 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1468 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1469 }; | |
485 | 1470 |
4192
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1471 /* not ALPHA, DIGIT, "-", ".", "_", "~" */ |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1472 |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1473 static uint32_t uri_component[] = { |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1474 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1475 |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1476 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1477 0xfc009fff, /* 1111 1100 0000 0000 1001 1111 1111 1111 */ |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1478 |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1479 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1480 0x78000001, /* 0111 1000 0000 0000 0000 0000 0000 0001 */ |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1481 |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1482 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1483 0xb8000001, /* 1011 1000 0000 0000 0000 0000 0000 0001 */ |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1484 |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1485 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1486 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1487 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1488 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1489 }; |
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1490 |
1405
fdd064faf26a
escape " ", "%", and %00-%1F in login and password
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
1491 /* " ", "#", """, "%", "'", %00-%1F, %7F-%FF */ |
485 | 1492 |
827 | 1493 static uint32_t html[] = { |
1494 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
461 | 1495 |
827 | 1496 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
1297 | 1497 0x000000ad, /* 0000 0000 0000 0000 0000 0000 1010 1101 */ |
827 | 1498 |
1499 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ | |
1500 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ | |
461 | 1501 |
827 | 1502 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ |
1503 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */ | |
461 | 1504 |
827 | 1505 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
1506 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1507 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1508 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |
1509 }; | |
461 | 1510 |
1405
fdd064faf26a
escape " ", "%", and %00-%1F in login and password
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
1511 /* " ", """, "%", "'", %00-%1F, %7F-%FF */ |
461 | 1512 |
1298
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1513 static uint32_t refresh[] = { |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1514 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
|
1515 |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1516 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
1629
12a656452ad1
do not encode already encoded characters in msie_refresh
Igor Sysoev <igor@sysoev.ru>
parents:
1593
diff
changeset
|
1517 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
|
1518 |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1519 /* _^]\ [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
|
1520 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
|
1521 |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1522 /* ~}| {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
|
1523 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
|
1524 |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1525 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
|
1526 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
|
1527 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
|
1528 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
|
1529 }; |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1530 |
1405
fdd064faf26a
escape " ", "%", and %00-%1F in login and password
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
1531 /* " ", "%", %00-%1F */ |
1333
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1532 |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1533 static uint32_t memcached[] = { |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1534 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
|
1535 |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1536 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
1405
fdd064faf26a
escape " ", "%", and %00-%1F in login and password
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
1537 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
|
1538 |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1539 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1540 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
|
1541 |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1542 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1543 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
|
1544 |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1545 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
|
1546 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
|
1547 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
|
1548 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
|
1549 }; |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1310
diff
changeset
|
1550 |
1405
fdd064faf26a
escape " ", "%", and %00-%1F in login and password
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
1551 /* 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
|
1552 |
fdd064faf26a
escape " ", "%", and %00-%1F in login and password
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
1553 static uint32_t *map[] = |
4192
61e4af19df9f
Autoindex: escape '?' in file names.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
1554 { 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
|
1555 |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1556 |
458e041fc902
msie_refresh should escape at least '"' to prevent XSS
Igor Sysoev <igor@sysoev.ru>
parents:
1297
diff
changeset
|
1557 escape = map[type]; |
461 | 1558 |
452 | 1559 if (dst == NULL) { |
1560 | |
1561 /* 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
|
1562 |
3115 | 1563 n = 0; |
452 | 1564 |
3275 | 1565 while (size) { |
6626
b3682580c1bd
Avoid left-shifting integers into the sign bit, which is undefined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6314
diff
changeset
|
1566 if (escape[*src >> 5] & (1U << (*src & 0x1f))) { |
452 | 1567 n++; |
1568 } | |
1569 src++; | |
3275 | 1570 size--; |
452 | 1571 } |
1572 | |
485 | 1573 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
|
1574 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1575 |
3275 | 1576 while (size) { |
6626
b3682580c1bd
Avoid left-shifting integers into the sign bit, which is undefined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6314
diff
changeset
|
1577 if (escape[*src >> 5] & (1U << (*src & 0x1f))) { |
452 | 1578 *dst++ = '%'; |
1579 *dst++ = hex[*src >> 4]; | |
1580 *dst++ = hex[*src & 0xf]; | |
1581 src++; | |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1582 |
452 | 1583 } else { |
1584 *dst++ = *src++; | |
1585 } | |
3275 | 1586 size--; |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1587 } |
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
1588 |
485 | 1589 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
|
1590 } |
577 | 1591 |
1592 | |
1593 void | |
601 | 1594 ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type) |
577 | 1595 { |
1596 u_char *d, *s, ch, c, decoded; | |
1597 enum { | |
1598 sw_usual = 0, | |
1599 sw_quoted, | |
1600 sw_quoted_second | |
1601 } state; | |
1602 | |
1603 d = *dst; | |
1604 s = *src; | |
1605 | |
1606 state = 0; | |
1607 decoded = 0; | |
1608 | |
1609 while (size--) { | |
1610 | |
1611 ch = *s++; | |
1612 | |
1613 switch (state) { | |
1614 case sw_usual: | |
1593 | 1615 if (ch == '?' |
1616 && (type & (NGX_UNESCAPE_URI|NGX_UNESCAPE_REDIRECT))) | |
1617 { | |
577 | 1618 *d++ = ch; |
1619 goto done; | |
1620 } | |
1621 | |
1622 if (ch == '%') { | |
1623 state = sw_quoted; | |
1624 break; | |
1625 } | |
1626 | |
1627 *d++ = ch; | |
1628 break; | |
1629 | |
1630 case sw_quoted: | |
1631 | |
1632 if (ch >= '0' && ch <= '9') { | |
1633 decoded = (u_char) (ch - '0'); | |
1634 state = sw_quoted_second; | |
1635 break; | |
1636 } | |
1637 | |
1638 c = (u_char) (ch | 0x20); | |
1639 if (c >= 'a' && c <= 'f') { | |
1640 decoded = (u_char) (c - 'a' + 10); | |
1641 state = sw_quoted_second; | |
1642 break; | |
1643 } | |
1644 | |
589 | 1645 /* the invalid quoted character */ |
577 | 1646 |
589 | 1647 state = sw_usual; |
1648 | |
1649 *d++ = ch; | |
577 | 1650 |
1651 break; | |
1652 | |
1653 case sw_quoted_second: | |
1654 | |
589 | 1655 state = sw_usual; |
1656 | |
577 | 1657 if (ch >= '0' && ch <= '9') { |
1658 ch = (u_char) ((decoded << 4) + ch - '0'); | |
1659 | |
1593 | 1660 if (type & NGX_UNESCAPE_REDIRECT) { |
601 | 1661 if (ch > '%' && ch < 0x7f) { |
1662 *d++ = ch; | |
1663 break; | |
1664 } | |
1665 | |
1666 *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1); | |
1667 | |
577 | 1668 break; |
1669 } | |
1670 | |
601 | 1671 *d++ = ch; |
577 | 1672 |
1673 break; | |
1674 } | |
1675 | |
1676 c = (u_char) (ch | 0x20); | |
1677 if (c >= 'a' && c <= 'f') { | |
1678 ch = (u_char) ((decoded << 4) + c - 'a' + 10); | |
1679 | |
1593 | 1680 if (type & NGX_UNESCAPE_URI) { |
1681 if (ch == '?') { | |
1682 *d++ = ch; | |
1683 goto done; | |
1684 } | |
1685 | |
1686 *d++ = ch; | |
1687 break; | |
1688 } | |
1689 | |
1690 if (type & NGX_UNESCAPE_REDIRECT) { | |
601 | 1691 if (ch == '?') { |
1692 *d++ = ch; | |
1693 goto done; | |
1694 } | |
577 | 1695 |
601 | 1696 if (ch > '%' && ch < 0x7f) { |
1697 *d++ = ch; | |
1698 break; | |
1699 } | |
1700 | |
1701 *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1); | |
577 | 1702 break; |
1703 } | |
1704 | |
601 | 1705 *d++ = ch; |
577 | 1706 |
1707 break; | |
1708 } | |
1709 | |
589 | 1710 /* the invalid quoted character */ |
577 | 1711 |
1712 break; | |
1713 } | |
1714 } | |
1715 | |
1716 done: | |
1717 | |
1718 *dst = d; | |
1719 *src = s; | |
1720 } | |
583 | 1721 |
1722 | |
1544 | 1723 uintptr_t |
1724 ngx_escape_html(u_char *dst, u_char *src, size_t size) | |
1725 { | |
1726 u_char ch; | |
3275 | 1727 ngx_uint_t len; |
1544 | 1728 |
1729 if (dst == NULL) { | |
1730 | |
1731 len = 0; | |
1732 | |
3275 | 1733 while (size) { |
1544 | 1734 switch (*src++) { |
1735 | |
1736 case '<': | |
1737 len += sizeof("<") - 2; | |
1560
25ee6eee7573
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1552
diff
changeset
|
1738 break; |
1544 | 1739 |
1740 case '>': | |
1741 len += sizeof(">") - 2; | |
1560
25ee6eee7573
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1552
diff
changeset
|
1742 break; |
1544 | 1743 |
1744 case '&': | |
1745 len += sizeof("&") - 2; | |
1560
25ee6eee7573
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1552
diff
changeset
|
1746 break; |
1544 | 1747 |
4312
0a8e51a16484
Added escaping of double quotes in ngx_escape_html().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4209
diff
changeset
|
1748 case '"': |
0a8e51a16484
Added escaping of double quotes in ngx_escape_html().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4209
diff
changeset
|
1749 len += sizeof(""") - 2; |
0a8e51a16484
Added escaping of double quotes in ngx_escape_html().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4209
diff
changeset
|
1750 break; |
0a8e51a16484
Added escaping of double quotes in ngx_escape_html().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4209
diff
changeset
|
1751 |
1544 | 1752 default: |
1753 break; | |
1754 } | |
3275 | 1755 size--; |
1544 | 1756 } |
1757 | |
1758 return (uintptr_t) len; | |
1759 } | |
1760 | |
3275 | 1761 while (size) { |
1544 | 1762 ch = *src++; |
1763 | |
1764 switch (ch) { | |
1765 | |
1766 case '<': | |
1767 *dst++ = '&'; *dst++ = 'l'; *dst++ = 't'; *dst++ = ';'; | |
1768 break; | |
1769 | |
1770 case '>': | |
1771 *dst++ = '&'; *dst++ = 'g'; *dst++ = 't'; *dst++ = ';'; | |
1772 break; | |
1773 | |
1774 case '&': | |
1775 *dst++ = '&'; *dst++ = 'a'; *dst++ = 'm'; *dst++ = 'p'; | |
1776 *dst++ = ';'; | |
1777 break; | |
1778 | |
4312
0a8e51a16484
Added escaping of double quotes in ngx_escape_html().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4209
diff
changeset
|
1779 case '"': |
0a8e51a16484
Added escaping of double quotes in ngx_escape_html().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4209
diff
changeset
|
1780 *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
|
1781 *dst++ = 't'; *dst++ = ';'; |
0a8e51a16484
Added escaping of double quotes in ngx_escape_html().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4209
diff
changeset
|
1782 break; |
0a8e51a16484
Added escaping of double quotes in ngx_escape_html().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4209
diff
changeset
|
1783 |
1544 | 1784 default: |
1785 *dst++ = ch; | |
1786 break; | |
1787 } | |
3275 | 1788 size--; |
1544 | 1789 } |
1790 | |
1791 return (uintptr_t) dst; | |
1792 } | |
1793 | |
1794 | |
5944
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1795 uintptr_t |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1796 ngx_escape_json(u_char *dst, u_char *src, size_t size) |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1797 { |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1798 u_char ch; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1799 ngx_uint_t len; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1800 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1801 if (dst == NULL) { |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1802 len = 0; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1803 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1804 while (size) { |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1805 ch = *src++; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1806 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1807 if (ch == '\\' || ch == '"') { |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1808 len++; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1809 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1810 } else if (ch <= 0x1f) { |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1811 len += sizeof("\\u001F") - 2; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1812 } |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1813 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1814 size--; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1815 } |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1816 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1817 return (uintptr_t) len; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1818 } |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1819 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1820 while (size) { |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1821 ch = *src++; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1822 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1823 if (ch > 0x1f) { |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1824 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1825 if (ch == '\\' || ch == '"') { |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1826 *dst++ = '\\'; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1827 } |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1828 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1829 *dst++ = ch; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1830 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1831 } else { |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1832 *dst++ = '\\'; *dst++ = 'u'; *dst++ = '0'; *dst++ = '0'; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1833 *dst++ = '0' + (ch >> 4); |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1834 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1835 ch &= 0xf; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1836 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1837 *dst++ = (ch < 10) ? ('0' + ch) : ('A' + ch - 10); |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1838 } |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1839 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1840 size--; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1841 } |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1842 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1843 return (uintptr_t) dst; |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1844 } |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1845 |
33c08d7e2915
Autoindex: implemented JSON output format.
Valentin Bartenev <vbart@nginx.com>
parents:
5772
diff
changeset
|
1846 |
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
|
1847 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
|
1848 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
|
1849 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
|
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 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
|
1852 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
|
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 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
|
1855 |
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 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
|
1857 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
|
1858 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1859 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
|
1860 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1861 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
|
1862 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1863 } 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
|
1864 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1865 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
|
1866 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1867 } 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
|
1868 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
|
1869 ? &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
|
1870 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1871 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1872 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
|
1873 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
|
1874 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1875 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1876 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
|
1877 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1878 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1879 *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
|
1880 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
|
1881 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
|
1882 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
|
1883 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
|
1884 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1885 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1886 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1887 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
|
1888 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
|
1889 { |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1890 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
|
1891 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
|
1892 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
|
1893 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1894 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
|
1895 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
|
1896 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1897 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
|
1898 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1899 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
|
1900 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1901 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
|
1902 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
|
1903 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
|
1904 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1905 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1906 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
|
1907 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
|
1908 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
|
1909 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1910 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1911 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
|
1912 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1913 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
|
1914 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
|
1915 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
|
1916 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1917 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1918 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
|
1919 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
|
1920 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
|
1921 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1922 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1923 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
|
1924 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1925 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1926 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
|
1927 } |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1928 |
6802ba529ec4
change ngx_http_variable_value_node_t to more generic ngx_str_node_t
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1929 |
1208 | 1930 /* ngx_sort() is implemented as insertion sort because we need stable sort */ |
1931 | |
1932 void | |
1933 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
|
1934 ngx_int_t (*cmp)(const void *, const void *)) |
1208 | 1935 { |
1955
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1936 u_char *p1, *p2, *p; |
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1937 |
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1938 p = ngx_alloc(size, ngx_cycle->log); |
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1939 if (p == NULL) { |
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1940 return; |
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1941 } |
1208 | 1942 |
1943 for (p1 = (u_char *) base + size; | |
1944 p1 < (u_char *) base + n * size; | |
1945 p1 += size) | |
1946 { | |
1955
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1947 ngx_memcpy(p, p1, size); |
1208 | 1948 |
1949 for (p2 = p1; | |
1955
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1950 p2 > (u_char *) base && cmp(p2 - size, p) > 0; |
1208 | 1951 p2 -= size) |
1952 { | |
1953 ngx_memcpy(p2, p2 - size, size); | |
1954 } | |
1955 | |
1955
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1956 ngx_memcpy(p2, p, size); |
1208 | 1957 } |
1955
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1958 |
466fdc84c82d
use dynamically allocated buffer in ngx_sort()
Igor Sysoev <igor@sysoev.ru>
parents:
1867
diff
changeset
|
1959 ngx_free(p); |
1208 | 1960 } |
1961 | |
1962 | |
583 | 1963 #if (NGX_MEMCPY_LIMIT) |
1964 | |
1965 void * | |
4781
814541b2ec23
Added "const" to ngx_memcpy() with NGX_MEMCPY_LIMIT defined.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4604
diff
changeset
|
1966 ngx_memcpy(void *dst, const void *src, size_t n) |
583 | 1967 { |
1968 if (n > NGX_MEMCPY_LIMIT) { | |
1969 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "memcpy %uz bytes", n); | |
1970 ngx_debug_point(); | |
1971 } | |
1972 | |
1973 return memcpy(dst, src, n); | |
1974 } | |
1975 | |
1976 #endif |