comparison src/core/ngx_string.c @ 596:6c96fdd2dfc3 NGINX_0_8_50

nginx 0.8.50 *) Feature: the "secure_link", "secure_link_md5", and "secure_link_expires" directives of the ngx_http_secure_link_module. *) Feature: the -q switch. Thanks to Gena Makhomed. *) Bugfix: worker processes may got caught in an endless loop during reconfiguration, if a caching was used; the bug had appeared in 0.8.48. *) Bugfix: in the "gzip_disable" directive. Thanks to Derrick Petzold. *) Bugfix: nginx/Windows could not send stop, quit, reopen, and reload signals to a process run in other session.
author Igor Sysoev <http://sysoev.ru>
date Thu, 02 Sep 2010 00:00:00 +0400
parents 09d5f308901f
children
comparison
equal deleted inserted replaced
595:57dcc025db4f 596:6c96fdd2dfc3
8 #include <ngx_core.h> 8 #include <ngx_core.h>
9 9
10 10
11 static u_char *ngx_sprintf_num(u_char *buf, u_char *last, uint64_t ui64, 11 static u_char *ngx_sprintf_num(u_char *buf, u_char *last, uint64_t ui64,
12 u_char zero, ngx_uint_t hexadecimal, ngx_uint_t width); 12 u_char zero, ngx_uint_t hexadecimal, ngx_uint_t width);
13 static ngx_int_t ngx_decode_base64_internal(ngx_str_t *dst, ngx_str_t *src,
14 const u_char *basis);
13 15
14 16
15 void 17 void
16 ngx_strlow(u_char *dst, u_char *src, size_t n) 18 ngx_strlow(u_char *dst, u_char *src, size_t n)
17 { 19 {
1093 1095
1094 1096
1095 ngx_int_t 1097 ngx_int_t
1096 ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src) 1098 ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src)
1097 { 1099 {
1098 size_t len;
1099 u_char *d, *s;
1100 static u_char basis64[] = { 1100 static u_char basis64[] = {
1101 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 1101 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1102 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 1102 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1103 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 62, 77, 77, 77, 63, 1103 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 62, 77, 77, 77, 63,
1104 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 77, 77, 77, 77, 77, 77, 1104 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 77, 77, 77, 77, 77, 77,
1115 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 1115 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1116 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 1116 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1117 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77 1117 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77
1118 }; 1118 };
1119 1119
1120 return ngx_decode_base64_internal(dst, src, basis64);
1121 }
1122
1123
1124 ngx_int_t
1125 ngx_decode_base64url(ngx_str_t *dst, ngx_str_t *src)
1126 {
1127 static u_char basis64[] = {
1128 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1129 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1130 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 62, 77, 77,
1131 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 77, 77, 77, 77, 77, 77,
1132 77, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
1133 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 77, 77, 77, 77, 63,
1134 77, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1135 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 77, 77, 77, 77, 77,
1136
1137 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1138 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1139 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1140 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1141 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1142 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1143 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1144 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77
1145 };
1146
1147 return ngx_decode_base64_internal(dst, src, basis64);
1148 }
1149
1150
1151 static ngx_int_t
1152 ngx_decode_base64_internal(ngx_str_t *dst, ngx_str_t *src, const u_char *basis)
1153 {
1154 size_t len;
1155 u_char *d, *s;
1156
1120 for (len = 0; len < src->len; len++) { 1157 for (len = 0; len < src->len; len++) {
1121 if (src->data[len] == '=') { 1158 if (src->data[len] == '=') {
1122 break; 1159 break;
1123 } 1160 }
1124 1161
1125 if (basis64[src->data[len]] == 77) { 1162 if (basis[src->data[len]] == 77) {
1126 return NGX_ERROR; 1163 return NGX_ERROR;
1127 } 1164 }
1128 } 1165 }
1129 1166
1130 if (len % 4 == 1) { 1167 if (len % 4 == 1) {
1133 1170
1134 s = src->data; 1171 s = src->data;
1135 d = dst->data; 1172 d = dst->data;
1136 1173
1137 while (len > 3) { 1174 while (len > 3) {
1138 *d++ = (u_char) (basis64[s[0]] << 2 | basis64[s[1]] >> 4); 1175 *d++ = (u_char) (basis[s[0]] << 2 | basis[s[1]] >> 4);
1139 *d++ = (u_char) (basis64[s[1]] << 4 | basis64[s[2]] >> 2); 1176 *d++ = (u_char) (basis[s[1]] << 4 | basis[s[2]] >> 2);
1140 *d++ = (u_char) (basis64[s[2]] << 6 | basis64[s[3]]); 1177 *d++ = (u_char) (basis[s[2]] << 6 | basis[s[3]]);
1141 1178
1142 s += 4; 1179 s += 4;
1143 len -= 4; 1180 len -= 4;
1144 } 1181 }
1145 1182
1146 if (len > 1) { 1183 if (len > 1) {
1147 *d++ = (u_char) (basis64[s[0]] << 2 | basis64[s[1]] >> 4); 1184 *d++ = (u_char) (basis[s[0]] << 2 | basis[s[1]] >> 4);
1148 } 1185 }
1149 1186
1150 if (len > 2) { 1187 if (len > 2) {
1151 *d++ = (u_char) (basis64[s[1]] << 4 | basis64[s[2]] >> 2); 1188 *d++ = (u_char) (basis[s[1]] << 4 | basis[s[2]] >> 2);
1152 } 1189 }
1153 1190
1154 dst->len = d - dst->data; 1191 dst->len = d - dst->data;
1155 1192
1156 return NGX_OK; 1193 return NGX_OK;