comparison src/core/ngx_string.c @ 390:0b6053502c55 NGINX_0_7_7

nginx 0.7.7 *) Change: now the EAGAIN error returned by connect() is not considered as temporary error. *) Change: now the $ssl_client_cert variable value is a certificate with TAB character intended before each line except first one; an unchanged certificate is available in the $ssl_client_raw_cert variable. *) Feature: the "ask" parameter in the "ssl_verify_client" directive. *) Feature: byte-range processing improvements. Thanks to Maxim Dounin. *) Feature: the "directio" directive. *) Feature: MacOSX 1.5 sendfile() support. *) Bugfix: now in MacOSX and Cygwin locations are tested in case insensitive mode; however, the compare is provided by single-byte locales only. *) Bugfix: mail proxy SSL connections hanged, if select, poll, or /dev/poll methods were used. *) Bugfix: UTF-8 encoding usage in the ngx_http_autoindex_module.
author Igor Sysoev <http://sysoev.ru>
date Wed, 30 Jul 2008 00:00:00 +0400
parents 984bb0b1399b
children 34fb3a573548
comparison
equal deleted inserted replaced
389:930e48a26dde 390:0b6053502c55
950 return NGX_OK; 950 return NGX_OK;
951 } 951 }
952 952
953 953
954 /* 954 /*
955 * ngx_utf_decode() decodes two and more bytes UTF sequences only 955 * ngx_utf8_decode() decodes two and more bytes UTF sequences only
956 * the return values: 956 * the return values:
957 * 0x80 - 0x10ffff valid character 957 * 0x80 - 0x10ffff valid character
958 * 0x10ffff - 0xfffffffd invalid sequence 958 * 0x110000 - 0xfffffffd invalid sequence
959 * 0xfffffffe incomplete sequence 959 * 0xfffffffe incomplete sequence
960 * 0xffffffff error 960 * 0xffffffff error
961 */ 961 */
962 962
963 uint32_t 963 uint32_t
964 ngx_utf_decode(u_char **p, size_t n) 964 ngx_utf8_decode(u_char **p, size_t n)
965 { 965 {
966 size_t len; 966 size_t len;
967 uint32_t u, i, valid; 967 uint32_t u, i, valid;
968 968
969 u = **p; 969 u = **p;
1016 return 0xffffffff; 1016 return 0xffffffff;
1017 } 1017 }
1018 1018
1019 1019
1020 size_t 1020 size_t
1021 ngx_utf_length(u_char *p, size_t n) 1021 ngx_utf8_length(u_char *p, size_t n)
1022 { 1022 {
1023 u_char c; 1023 u_char c, *last;
1024 size_t len; 1024 size_t len;
1025 ngx_uint_t i; 1025
1026 1026 last = p + n;
1027 for (len = 0, i = 0; i < n; len++, i++) { 1027
1028 1028 for (len = 0; p < last; len++) {
1029 c = p[i]; 1029
1030 c = *p;
1030 1031
1031 if (c < 0x80) { 1032 if (c < 0x80) {
1033 p++;
1032 continue; 1034 continue;
1033 } 1035 }
1034 1036
1035 if (c >= 0xc0) { 1037 if (ngx_utf8_decode(&p, n) > 0x10ffff) {
1036 for (c <<= 1; c & 0x80; c <<= 1) { 1038 /* invalid UTF-8 */
1037 i++; 1039 return n;
1038 } 1040 }
1039
1040 continue;
1041 }
1042
1043 /* invalid utf */
1044
1045 return n;
1046 } 1041 }
1047 1042
1048 return len; 1043 return len;
1049 } 1044 }
1050 1045
1051 1046
1052 u_char * 1047 u_char *
1053 ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n) 1048 ngx_utf8_cpystrn(u_char *dst, u_char *src, size_t n, size_t len)
1054 { 1049 {
1055 u_char c; 1050 u_char c, *next;
1056 1051
1057 if (n == 0) { 1052 if (n == 0) {
1058 return dst; 1053 return dst;
1059 } 1054 }
1060 1055
1061 for ( /* void */ ; --n; dst++, src++) { 1056 while (--n) {
1062 1057
1063 c = *src; 1058 c = *src;
1064 *dst = c; 1059 *dst = c;
1065 1060
1066 if (c < 0x80) { 1061 if (c < 0x80) {
1067 if (*dst != '\0') { 1062
1063 if (c != '\0') {
1064 dst++;
1065 src++;
1066 len--;
1067
1068 continue; 1068 continue;
1069 } 1069 }
1070 1070
1071 return dst; 1071 return dst;
1072 } 1072 }
1073 1073
1074 if (c >= 0xc0) { 1074 next = src;
1075 for (c <<= 1; c & 0x80; c <<= 1) { 1075
1076 *++dst = *++src; 1076 if (ngx_utf8_decode(&next, len) > 0x10ffff) {
1077 } 1077 /* invalid UTF-8 */
1078 1078 break;
1079 continue; 1079 }
1080 } 1080
1081 1081 len--;
1082 /* invalid utf */ 1082
1083 while (src < next) {
1084 *++dst = *++src;
1085 len--;
1086 }
1083 } 1087 }
1084 1088
1085 *dst = '\0'; 1089 *dst = '\0';
1086 1090
1087 return dst; 1091 return dst;