- portable ctype (http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=34632)
authorMichael Wallner <mike@php.net>
Wed, 27 Sep 2006 09:29:56 +0000 (09:29 +0000)
committerMichael Wallner <mike@php.net>
Wed, 27 Sep 2006 09:29:56 +0000 (09:29 +0000)
- update KnownIssues

KnownIssues.txt
http_api.c
http_date_api.c
http_headers_api.c
http_info_api.c
http_message_api.c
http_request_method_api.c
http_request_object.c
php_http.h

index fac8a3c..c6565b2 100644 (file)
@@ -2,23 +2,17 @@ Known Issues
 ============
 $Id$
 
-HttpResponse (only in PHP-5.1+):
-       HttpResponse::getHeader() does not work in Apache2 with a 
-PHP version lower than 5.1.3 (as mod_php).
+PHP < 5.1.3:
+       HttpResponse::getHeader() does not work with Apache2 SAPIs.
+       Using an encoding stream filter on a stream you read from doesn't work.
 
 Windows:
        If you keep getting "SSL connect error" when trying to issue 
-requests, try another (newer) libeay32.dll/ssleay32.dll pair.
-
-Deflate/Inflate:
-       Inflating raw deflated data causes a re-initialization of the inflate
-stream where the corresponding window bits are modified to tell libz to 
-not check for zlib header bytes.  This is not preventable AFAICS.
-       Using an encoding stream filter on a stream you read from, will
-not work as expected in a PHP version lower than 5.1.3.
+               requests, try another (newer) libeay32.dll/ssleay32.dll pair.
 
 Internals:
-       -       our http_urlencode_hash() does not differentiate between prefixes
+       Our http_urlencode_hash() does not differentiate between prefixes
                for numeric or string keys.
-       -       detaching a request from a pool in its progress callback causes
-               all sorts of memory errors
+       Inflating raw deflated data causes a re-initialization of the inflate
+               stream where the corresponding window bits are modified to tell libz
+               to not check for zlib header bytes.  This is not preventable AFAICS.
index a2a7f6c..78745ee 100644 (file)
@@ -67,15 +67,16 @@ PHP_HTTP_API long _http_support(long feature)
 /* char *pretty_key(char *, size_t, zend_bool, zend_bool) */
 char *_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen)
 {
+       size_t i;
+       int wasalpha;
+       
        if (key && key_len) {
-               size_t i;
-               int wasalpha;
-               if ((wasalpha = isalpha((int) key[0]))) {
-                       key[0] = (char) (uctitle ? toupper((int) key[0]) : tolower((int) key[0]));
+               if ((wasalpha = HTTP_IS_CTYPE(alpha, key[0]))) {
+                       key[0] = (char) (uctitle ? HTTP_TO_CTYPE(upper, key[0]) : HTTP_TO_CTYPE(lower, key[0]));
                }
                for (i = 1; i < key_len; i++) {
-                       if (isalpha((int) key[i])) {
-                               key[i] = (char) (((!wasalpha) && uctitle) ? toupper((int) key[i]) : tolower((int) key[i]));
+                       if (HTTP_IS_CTYPE(alpha, key[i])) {
+                               key[i] = (char) (((!wasalpha) && uctitle) ? HTTP_TO_CTYPE(upper, key[i]) : HTTP_TO_CTYPE(lower, key[i]));
                                wasalpha = 1;
                        } else {
                                if (xhyphen && (key[i] == '_')) {
@@ -255,8 +256,8 @@ STATUS _http_check_method_ex(const char *method, const char *methods)
        const char *found;
 
        if (    (found = strstr(methods, method)) &&
-                       (found == method || !isalpha(found[-1])) &&
-                       (strlen(found) >= strlen(method) && !isalpha(found[strlen(method)]))) {
+                       (found == method || !HTTP_IS_CTYPE(alpha, found[-1])) &&
+                       (strlen(found) >= strlen(method) && !HTTP_IS_CTYPE(alpha, found[strlen(method)]))) {
                return SUCCESS;
        }
        return FAILURE;
index ba6ef45..10f3463 100644 (file)
@@ -204,11 +204,11 @@ static inline time_t parse_date(const char *date)
        while (*date && (part < 6)) {
                int found = 0;
 
-               while (*date && !isalnum(*date)) {
+               while (*date && !HTTP_IS_CTYPE(alnum, *date)) {
                        date++;
                }
 
-               if (isalpha(*date)) {
+               if (HTTP_IS_CTYPE(alpha, *date)) {
                        /* a name coming up */
                        char buf[32] = "";
                        size_t len;
@@ -242,7 +242,7 @@ static inline time_t parse_date(const char *date)
                        }
                        date += len;
                }
-               else if (isdigit(*date)) {
+               else if (HTTP_IS_CTYPE(digit, *date)) {
                        /* a digit */
                        int val;
                        char *end;
index ce5f051..5e984e4 100644 (file)
@@ -143,7 +143,7 @@ PHP_HTTP_API HashTable *_http_negotiate_q(const char *header, HashTable *support
                                if ((separator = strchr(Z_STRVAL_PP(entry), ';'))) {
                                        const char *ptr = separator;
                                        
-                                       while (*++ptr && !isdigit(*ptr) && '.' != *ptr);
+                                       while (*++ptr && !HTTP_IS_CTYPE(digit, *ptr) && '.' != *ptr);
                                        
                                        quality = atof(ptr);
                                        identifier = estrndup(Z_STRVAL_PP(entry), ident_len = separator - Z_STRVAL_PP(entry));
@@ -153,11 +153,11 @@ PHP_HTTP_API HashTable *_http_negotiate_q(const char *header, HashTable *support
                                }
                                freeme = identifier;
                                
-                               while (isspace(*identifier)) {
+                               while (HTTP_IS_CTYPE(space, *identifier)) {
                                        ++identifier;
                                        --ident_len;
                                }
-                               while (ident_len && isspace(identifier[ident_len - 1])) {
+                               while (ident_len && HTTP_IS_CTYPE(space, identifier[ident_len - 1])) {
                                        identifier[--ident_len] = '\0';
                                }
                                
@@ -326,7 +326,7 @@ PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *header
        INIT_ZARR(array, headers);
        
        /* skip leading ws */
-       while (isspace(*header)) ++header;
+       while (HTTP_IS_CTYPE(space, *header)) ++header;
        line = header;
        
 #define MORE_HEADERS (*(line-1) && !(*(line-1) == '\n' && (*line == '\n' || *line == '\r')))
@@ -358,9 +358,9 @@ PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *header
                                                        const char *key = header;
                                                        
                                                        /* skip leading ws */
-                                                       while (keylen && isspace(*key)) --keylen && ++key;
+                                                       while (keylen && HTTP_IS_CTYPE(space, *key)) --keylen && ++key;
                                                        /* skip trailing ws */
-                                                       while (keylen && isspace(key[keylen - 1])) --keylen;
+                                                       while (keylen && HTTP_IS_CTYPE(space, key[keylen - 1])) --keylen;
                                                        
                                                        if (keylen > 0) {
                                                                zval **previous = NULL;
@@ -374,9 +374,9 @@ PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *header
                                                                value_len += line - colon - 1;
                                                                
                                                                /* skip leading ws */
-                                                               while (isspace(*(++colon))) --value_len;
+                                                               while (HTTP_IS_CTYPE(space, *(++colon))) --value_len;
                                                                /* skip trailing ws */
-                                                               while (isspace(colon[value_len - 1])) --value_len;
+                                                               while (HTTP_IS_CTYPE(space, colon[value_len - 1])) --value_len;
                                                                
                                                                if (value_len > 0) {
                                                                        value = estrndup(colon, value_len);
index 0f22902..7cf9cc6 100644 (file)
@@ -97,8 +97,8 @@ PHP_HTTP_API STATUS _http_info_parse_ex(const char *pre_header, http_info *info,
         */
        if (    (!(http = php_memnstr((char *) pre_header, "HTTP/1.", lenof("HTTP/1."), (char *)end))) || 
                        (!(http < end)) ||
-                       (!isdigit(http[lenof("HTTP/1.")])) ||
-                       (http[lenof("HTTP/1.1")] && (!isspace(http[lenof("HTTP/1.1")])))) {
+                       (!HTTP_IS_CTYPE(digit, http[lenof("HTTP/1.")])) ||
+                       (http[lenof("HTTP/1.1")] && (!HTTP_IS_CTYPE(space, http[lenof("HTTP/1.1")])))) {
                if (!silent) {
                        http_error(HE_WARNING, HTTP_E_MALFORMED_HEADERS, "Invalid or missing HTTP/1.x protocol identification");
                }
index b98db17..99bc01b 100644 (file)
@@ -265,7 +265,7 @@ PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char
 
                /* check for following messages */
                if (continue_at && (continue_at < (message + message_length))) {
-                       while (isspace(*continue_at)) ++continue_at;
+                       while (HTTP_IS_CTYPE(space, *continue_at)) ++continue_at;
                        if (continue_at < (message + message_length)) {
                                http_message *next = NULL, *most = NULL;
 
index 713fc5a..d9d3370 100644 (file)
@@ -191,7 +191,7 @@ PHP_HTTP_API int _http_request_method_register(const char *method_name, int meth
        char *http_method, *method, *mconst;
        http_request_method_entry **ptr = HTTP_G->request.methods.custom.entries;
        
-       if (!isalpha(*method_name)) {
+       if (!HTTP_IS_CTYPE(alpha, *method_name)) {
                http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Request method does not start with a character (%s)", method_name);
                return 0;
        }
@@ -211,13 +211,13 @@ PHP_HTTP_API int _http_request_method_register(const char *method_name, int meth
                                break;
                        
                        default:
-                               if (!isalnum(method_name[i])) {
+                               if (!HTTP_IS_CTYPE(alnum, method_name[i])) {
                                        efree(method);
                                        efree(mconst);
                                        http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Request method contains illegal characters (%s)", method_name);
                                        return 0;
                                }
-                               mconst[i] = method[i] = toupper(method_name[i]);
+                               mconst[i] = method[i] = HTTP_TO_CTYPE(upper, method_name[i]);
                                break;
                }
        }
index b40ef89..59dd915 100644 (file)
@@ -498,7 +498,7 @@ static inline void _http_request_object_check_request_content_type(zval *this_pt
                                
                                /* check for spaces only */
                                for (i = 0; i < Z_STRLEN_PP(ct_header); ++i) {
-                                       if (!isspace(Z_STRVAL_PP(ct_header)[i])) {
+                                       if (!HTTP_IS_CTYPE(space, Z_STRVAL_PP(ct_header)[i])) {
                                                only_space = 0;
                                                break;
                                        }
index 5de996a..c25e576 100644 (file)
@@ -71,6 +71,8 @@
 #endif
 
 #include <ctype.h>
+#define HTTP_IS_CTYPE(type, c) is##type((int) (unsigned char) (c))
+#define HTTP_TO_CTYPE(type, c) to##type((int) (unsigned char) (c))
 
 extern zend_module_entry http_module_entry;
 #define phpext_http_ptr &http_module_entry