comparison src/core/ngx_string.c @ 552:c04fa65fe604 NGINX_0_8_22

nginx 0.8.22 *) Feature: the "proxy_bind", "fastcgi_bind", and "memcached_bind" directives. *) Feature: the "access" and the "deny" directives support IPv6. *) Feature: the "set_real_ip_from" directive supports IPv6 addresses in request headers. *) Feature: the "unix:" parameter of the "set_real_ip_from" directive. *) Bugfix: nginx did not delete unix domain socket after configuration testing. *) Bugfix: nginx deleted unix domain socket while online upgrade. *) Bugfix: the "!-x" operator did not work. Thanks to Maxim Dounin. *) Bugfix: a segmentation fault might occur in a worker process, if limit_rate was used in HTTPS server. Thanks to Maxim Dounin. *) Bugfix: a segmentation fault might occur in a worker process while $limit_rate logging. Thanks to Maxim Dounin. *) Bugfix: a segmentation fault might occur in a worker process, if there was no "listen" directive in "server" block; the bug had appeared in 0.8.21.
author Igor Sysoev <http://sysoev.ru>
date Tue, 03 Nov 2009 00:00:00 +0300
parents 0161f3197817
children daf4847b43ff
comparison
equal deleted inserted replaced
551:c88014f74832 552:c04fa65fe604
13 13
14 14
15 void 15 void
16 ngx_strlow(u_char *dst, u_char *src, size_t n) 16 ngx_strlow(u_char *dst, u_char *src, size_t n)
17 { 17 {
18 while (n--) { 18 while (n) {
19 *dst = ngx_tolower(*src); 19 *dst = ngx_tolower(*src);
20 dst++; 20 dst++;
21 src++; 21 src++;
22 n--;
22 } 23 }
23 } 24 }
24 25
25 26
26 u_char * 27 u_char *
145 float f, scale; 146 float f, scale;
146 size_t len, slen; 147 size_t len, slen;
147 int64_t i64; 148 int64_t i64;
148 uint64_t ui64; 149 uint64_t ui64;
149 ngx_msec_t ms; 150 ngx_msec_t ms;
150 ngx_uint_t width, sign, hex, max_width, frac_width, i; 151 ngx_uint_t width, sign, hex, max_width, frac_width, n;
151 ngx_str_t *v; 152 ngx_str_t *v;
152 ngx_variable_value_t *vv; 153 ngx_variable_value_t *vv;
153 154
154 while (*fmt && buf < last) { 155 while (*fmt && buf < last) {
155 156
375 *buf++ = '.'; 376 *buf++ = '.';
376 } 377 }
377 378
378 scale = 1.0; 379 scale = 1.0;
379 380
380 for (i = 0; i < frac_width; i++) { 381 for (n = frac_width; n; n--) {
381 scale *= 10.0; 382 scale *= 10.0;
382 } 383 }
383 384
384 /* 385 /*
385 * (int64_t) cast is required for msvc6: 386 * (int64_t) cast is required for msvc6:
1253 1254
1254 1255
1255 uintptr_t 1256 uintptr_t
1256 ngx_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type) 1257 ngx_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type)
1257 { 1258 {
1258 ngx_uint_t i, n; 1259 ngx_uint_t n;
1259 uint32_t *escape; 1260 uint32_t *escape;
1260 static u_char hex[] = "0123456789abcdef"; 1261 static u_char hex[] = "0123456789abcdef";
1261 1262
1262 /* " ", "#", "%", "?", %00-%1F, %7F-%FF */ 1263 /* " ", "#", "%", "?", %00-%1F, %7F-%FF */
1263 1264
1371 1372
1372 /* find the number of the characters to be escaped */ 1373 /* find the number of the characters to be escaped */
1373 1374
1374 n = 0; 1375 n = 0;
1375 1376
1376 for (i = 0; i < size; i++) { 1377 while (size) {
1377 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { 1378 if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
1378 n++; 1379 n++;
1379 } 1380 }
1380 src++; 1381 src++;
1382 size--;
1381 } 1383 }
1382 1384
1383 return (uintptr_t) n; 1385 return (uintptr_t) n;
1384 } 1386 }
1385 1387
1386 for (i = 0; i < size; i++) { 1388 while (size) {
1387 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { 1389 if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
1388 *dst++ = '%'; 1390 *dst++ = '%';
1389 *dst++ = hex[*src >> 4]; 1391 *dst++ = hex[*src >> 4];
1390 *dst++ = hex[*src & 0xf]; 1392 *dst++ = hex[*src & 0xf];
1391 src++; 1393 src++;
1392 1394
1393 } else { 1395 } else {
1394 *dst++ = *src++; 1396 *dst++ = *src++;
1395 } 1397 }
1398 size--;
1396 } 1399 }
1397 1400
1398 return (uintptr_t) dst; 1401 return (uintptr_t) dst;
1399 } 1402 }
1400 1403
1531 1534
1532 uintptr_t 1535 uintptr_t
1533 ngx_escape_html(u_char *dst, u_char *src, size_t size) 1536 ngx_escape_html(u_char *dst, u_char *src, size_t size)
1534 { 1537 {
1535 u_char ch; 1538 u_char ch;
1536 ngx_uint_t i, len; 1539 ngx_uint_t len;
1537 1540
1538 if (dst == NULL) { 1541 if (dst == NULL) {
1539 1542
1540 len = 0; 1543 len = 0;
1541 1544
1542 for (i = 0; i < size; i++) { 1545 while (size) {
1543 switch (*src++) { 1546 switch (*src++) {
1544 1547
1545 case '<': 1548 case '<':
1546 len += sizeof("&lt;") - 2; 1549 len += sizeof("&lt;") - 2;
1547 break; 1550 break;
1555 break; 1558 break;
1556 1559
1557 default: 1560 default:
1558 break; 1561 break;
1559 } 1562 }
1563 size--;
1560 } 1564 }
1561 1565
1562 return (uintptr_t) len; 1566 return (uintptr_t) len;
1563 } 1567 }
1564 1568
1565 for (i = 0; i < size; i++) { 1569 while (size) {
1566 ch = *src++; 1570 ch = *src++;
1567 1571
1568 switch (ch) { 1572 switch (ch) {
1569 1573
1570 case '<': 1574 case '<':
1582 1586
1583 default: 1587 default:
1584 *dst++ = ch; 1588 *dst++ = ch;
1585 break; 1589 break;
1586 } 1590 }
1591 size--;
1587 } 1592 }
1588 1593
1589 return (uintptr_t) dst; 1594 return (uintptr_t) dst;
1590 } 1595 }
1591 1596