annotate src/core/ngx_string.c @ 4555:555ca31dea18

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