- 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 fac8a3cf98c27fca67b7348c522ddccd6e98e674..c6565b23402306b054364d18706e1a2263ab973e 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 a2a7f6ce71cfb0601392e46574e85dfdb74cc334..78745ee9d0083082bf1e6095b735b081a3bb4abb 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 ba6ef45ef13321838d508af622bf55a342aba464..10f3463a437c8efd2ab5cee7636f8c22ba2815f9 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 ce5f0518be22112252b5d91ae2da8ee92ceef8ac..5e984e4a2ba52e5f320633ccc94c8fa12b84e124 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 0f22902bb2e020fcc8744280dc16c7f9cee1a55d..7cf9cc6eb0a6844b14d3c7b0dddd439db6db8286 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 b98db1709e2de2cc0c53df175a3b9b65dfc28ea3..99bc01b30bc0b0a90ddd99989681672afb6e0f49 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 713fc5a1e8a0d00eadd1a1a8e5b9dcc588ffdf9f..d9d3370c41c79f49fc14d54055f48293bced853d 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 b40ef8992457e8a9833cf8e23c6324676aa4682c..59dd915434694eb3ba32df5bf2d3f8348f10d9e8 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 5de996a677c051bc5fe6e323558fc11e7b0f7ef9..c25e576d1e29d67fdcec814797d7d60a77d1d9b0 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