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