comparison src/core/ngx_string.c @ 34:aab2ea7c0458 NGINX_0_1_17

nginx 0.1.17 *) Change: the ngx_http_rewrite_module was rewritten from the scratch. Now it is possible to redirect, to return the error codes, to check the variables and referrers. The directives can be used inside locations. The redirect directive was canceled. *) Feature: the ngx_http_geo_module. *) Feature: the proxy_set_x_var and fastcgi_set_var directives. *) Bugfix: the location configuration with "=" modifier may be used in another location. *) Bugfix: the correct content type was set only for requests that use small caps letters in extension. *) Bugfix: if the proxy_pass or fastcgi_pass directives were set in the location, and access was denied, and the error was redirected to a static page, then the segmentation fault occurred. *) Bugfix: if in a proxied "Location" header was a relative URL, then a host name and a slash were added to them; bug appeared in 0.1.14. *) Bugfix: the system error message was not logged on Linux.
author Igor Sysoev <http://sysoev.ru>
date Thu, 03 Feb 2005 00:00:00 +0300
parents 7ca9bdc82b3f
children 41ccba1aba45
comparison
equal deleted inserted replaced
33:27f09a550803 34:aab2ea7c0458
21 return dst; 21 return dst;
22 } 22 }
23 } 23 }
24 24
25 *dst = '\0'; 25 *dst = '\0';
26
27 return dst;
28 }
29
30
31 u_char *ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src)
32 {
33 u_char *dst;
34
35 if (!(dst = ngx_palloc(pool, src->len))) {
36 return NULL;
37 }
38
39 ngx_memcpy(dst, src->data, src->len);
26 40
27 return dst; 41 return dst;
28 } 42 }
29 43
30 44
600 614
601 return NGX_OK; 615 return NGX_OK;
602 } 616 }
603 617
604 618
605 ngx_uint_t ngx_escape_uri(u_char *dst, u_char *src, size_t size, 619 uintptr_t ngx_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type)
606 ngx_uint_t type)
607 { 620 {
608 ngx_uint_t i, n; 621 ngx_uint_t i, n;
609 uint32_t *escape; 622 uint32_t *escape;
610 static u_char hex[] = "0123456789abcdef"; 623 static u_char hex[] = "0123456789abcdef";
611 624
625 /* " ", "%", "?", %00-%1F, %7F-%FF */
626
612 static uint32_t uri[] = 627 static uint32_t uri[] =
613 { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ 628 { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
614 629
615 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ 630 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
616 0x80000021, /* 1000 0000 0000 0000 0000 0000 0010 0001 */ 631 0x80000021, /* 1000 0000 0000 0000 0000 0000 0010 0001 */
624 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ 639 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
625 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ 640 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
626 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ 641 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
627 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ }; 642 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ };
628 643
644 /* " ", "%", "+", "?", %00-%1F, %7F-%FF */
645
646 static uint32_t args[] =
647 { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
648
649 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
650 0x80000821, /* 1000 0000 0000 0000 0000 1000 0010 0001 */
651
652 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
653 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
654
655 /* ~}| {zyx wvut srqp onml kjih gfed cba` */
656 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
657
658 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
659 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
660 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
661 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ };
662
663 /* " ", """, "%", "'", %00-%1F, %7F-%FF */
664
629 static uint32_t html[] = 665 static uint32_t html[] =
630 { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ 666 { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
631 667
632 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ 668 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
633 0x80000021, /* 0000 0000 0000 0000 0000 0000 1010 0101 */ 669 0x80000021, /* 0000 0000 0000 0000 0000 0000 1010 0101 */
642 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ 678 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
643 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ 679 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
644 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ }; 680 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ };
645 681
646 682
647 if (type == NGX_ESCAPE_HTML) { 683 switch (type) {
684 case NGX_ESCAPE_HTML:
648 escape = html; 685 escape = html;
649 686 break;
650 } else { 687 case NGX_ESCAPE_ARGS:
688 escape = args;
689 break;
690 default:
651 escape = uri; 691 escape = uri;
692 break;
652 } 693 }
653 694
654 if (dst == NULL) { 695 if (dst == NULL) {
655 696
656 /* find the number of the characters to be escaped */ 697 /* find the number of the characters to be escaped */
662 n++; 703 n++;
663 } 704 }
664 src++; 705 src++;
665 } 706 }
666 707
667 return n; 708 return (uintptr_t) n;
668 } 709 }
669 710
670 for (i = 0; i < size; i++) { 711 for (i = 0; i < size; i++) {
671 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { 712 if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
672 *dst++ = '%'; 713 *dst++ = '%';
677 } else { 718 } else {
678 *dst++ = *src++; 719 *dst++ = *src++;
679 } 720 }
680 } 721 }
681 722
682 return 0; 723 return (uintptr_t) dst;
683 } 724 }