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