- no HttpMessage property access by reference
authorMichael Wallner <mike@php.net>
Fri, 28 Oct 2005 21:01:36 +0000 (21:01 +0000)
committerMichael Wallner <mike@php.net>
Fri, 28 Oct 2005 21:01:36 +0000 (21:01 +0000)
- use ulong/uint instead of unsigned long/int

http_encoding_api.c
http_functions.c
http_message_api.c
http_message_object.c
http_request_api.c
http_request_method_api.c
http_send_api.c
php_http_cache_api.h
php_http_encoding_api.h
php_http_request_method_api.h

index b4244f01131e610d2f3b9c0a97c387e1932f5b67..c16bc1a8722ecb1c0f7c3783c91c75a0406c79e6 100644 (file)
@@ -54,7 +54,7 @@ PHP_HTTP_API const char *_http_encoding_dechunk(const char *encoded, size_t enco
        *decoded = ecalloc(1, encoded_len);
 
        while ((encoded + encoded_len - e_ptr) > 0) {
-               unsigned long chunk_len = 0, rest;
+               ulong chunk_len = 0, rest;
 
                chunk_len = strtoul(e_ptr, &n_ptr, 16);
 
@@ -72,7 +72,7 @@ PHP_HTTP_API const char *_http_encoding_dechunk(const char *encoded, size_t enco
                                return encoded + encoded_len;
                        } else {
                                efree(*decoded);
-                               http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected chunk size at pos %lu of %lu but got trash", (unsigned long) (n_ptr - encoded), (unsigned long) encoded_len);
+                               http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected chunk size at pos %lu of %lu but got trash", (ulong) (n_ptr - encoded), (ulong) encoded_len);
                                return NULL;
                        }
                }
@@ -85,16 +85,16 @@ PHP_HTTP_API const char *_http_encoding_dechunk(const char *encoded, size_t enco
                /* there should be CRLF after the chunk size, but we'll ignore SP+ too */
                if (*n_ptr && !eol_match(&n_ptr, &eol_len)) {
                        if (eol_len == 2) {
-                               http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected CRLF at pos %lu of %lu but got 0x%02X 0x%02X", (unsigned long) (n_ptr - encoded), (unsigned long) encoded_len, *n_ptr, *(n_ptr + 1));
+                               http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected CRLF at pos %lu of %lu but got 0x%02X 0x%02X", (ulong) (n_ptr - encoded), (ulong) encoded_len, *n_ptr, *(n_ptr + 1));
                        } else {
-                               http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected LF at pos %lu of %lu but got 0x%02X", (unsigned long) (n_ptr - encoded), (unsigned long) encoded_len, *n_ptr);
+                               http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected LF at pos %lu of %lu but got 0x%02X", (ulong) (n_ptr - encoded), (ulong) encoded_len, *n_ptr);
                        }
                }
                n_ptr += eol_len;
                
                /* chunk size pretends more data than we actually got, so it's probably a truncated message */
                if (chunk_len > (rest = encoded + encoded_len - n_ptr)) {
-                       http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Truncated message: chunk size %lu exceeds remaining data size %lu at pos %lu of %lu", chunk_len, rest, (unsigned long) (n_ptr - encoded), (unsigned long) encoded_len);
+                       http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Truncated message: chunk size %lu exceeds remaining data size %lu at pos %lu of %lu", chunk_len, rest, (ulong) (n_ptr - encoded), (ulong) encoded_len);
                        chunk_len = rest;
                }
 
@@ -200,7 +200,7 @@ inline size_t http_finish_buffer(size_t buf_len, char **buf_ptr)
 
 inline size_t http_finish_gzencode_buffer(z_stream *Z, const char *data, size_t data_len, char **buf_ptr)
 {
-       unsigned long crc;
+       ulong crc;
        char *trailer;
        
        crc = crc32(0L, Z_NULL, 0);
@@ -268,7 +268,7 @@ inline STATUS http_verify_gzencode_buffer(const char *data, size_t data_len, con
                if (data_len <= offset) {
                        goto really_bad_gzip_header;
                } else {
-                       unsigned long crc, cmp;
+                       ulong crc, cmp;
                        
                        cmp =  (unsigned) ((data[offset-2] & 0xFF));
                        cmp += (unsigned) ((data[offset-1] & 0xFF) << 8);
@@ -305,7 +305,7 @@ really_bad_gzip_header:
 inline STATUS http_verify_gzdecode_buffer(const char *data, size_t data_len, const char *decoded, size_t decoded_len, int error_level TSRMLS_DC)
 {
        STATUS status = SUCCESS;
-       unsigned long len, cmp, crc;
+       ulong len, cmp, crc;
        
        crc = crc32(0L, Z_NULL, 0);
        crc = crc32(crc, (const Bytef *) decoded, decoded_len);
@@ -604,7 +604,7 @@ PHP_HTTP_API zend_bool _http_encoding_response_start(size_t content_length TSRML
                        if (content_length) {
                                char cl_header_str[128];
                                size_t cl_header_len;
-                               cl_header_len = snprintf(cl_header_str, lenof(cl_header_str), "Content-Length: %lu", (unsigned long) content_length);
+                               cl_header_len = snprintf(cl_header_str, lenof(cl_header_str), "Content-Length: %lu", (ulong) content_length);
                                http_send_header_string_ex(cl_header_str, cl_header_len, 1);
                        }
                } else {
index 34a8e7181f23f0e799f5c2c9cb5c0a1694badadf..5ff5e33a7eff753d79771b9ade894f1a98c3dde0 100644 (file)
@@ -1259,7 +1259,7 @@ PHP_FUNCTION(http_request_method_register)
 {
        char *method;
        int method_len;
-       unsigned long existing;
+       ulong existing;
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) {
                RETURN_FALSE;
@@ -1296,7 +1296,7 @@ PHP_FUNCTION(http_request_method_unregister)
                        if (is_numeric_string(Z_STRVAL_P(method), Z_STRLEN_P(method), NULL, NULL, 1)) {
                                convert_to_long(method);
                        } else {
-                               unsigned long mn;
+                               ulong mn;
                                if (!(mn = http_request_method_exists(1, 0, Z_STRVAL_P(method)))) {
                                        RETURN_FALSE;
                                }
@@ -1364,7 +1364,7 @@ PHP_FUNCTION(http_request_method_name)
                        RETURN_FALSE;
                }
 
-               RETURN_STRING(estrdup(http_request_method_name((unsigned long) method)), 0);
+               RETURN_STRING(estrdup(http_request_method_name((ulong) method)), 0);
        }
 }
 /* }}} */
index 0cd1e8bdac76f3bca7304af833fce2ea645b487d..6dd20673b081addab2c92fa72902d6cfa93b7ce1 100644 (file)
@@ -175,7 +175,7 @@ PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char
 
                /* message has content-length header */
                if (c = http_message_header(msg, "Content-Length")) {
-                       unsigned long len = strtoul(Z_STRVAL_P(c), NULL, 10);
+                       ulong len = strtoul(Z_STRVAL_P(c), NULL, 10);
                        if (len > remaining) {
                                http_error_ex(HE_NOTICE, HTTP_E_MALFORMED_HEADERS, "The Content-Length header pretends a larger body than actually received (expected %lu bytes; got %lu bytes)", len, remaining);
                                len = remaining;
@@ -204,7 +204,7 @@ PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char
                                        }
                                        if (end >= start && (!total || end < total)) {
                                                phpstr_from_string_ex(PHPSTR(msg), body, len);
-                                               continue_at = body + (end + 1 - start);
+                                               continue_at = body + len;
                                        }
                                }
                        }
index 29ea53a040c039b973aff8749bae51e2bf179c6a..0510829f74d791b02345ba51798a9fdd2adf25ad 100644 (file)
@@ -237,14 +237,13 @@ static zval *_http_message_object_read_prop(zval *object, zval *member, int type
 #endif
 
        if (type == BP_VAR_W) {
-               return_value = &EG(uninitialized_zval);
-               return_value->refcount = 1;
-               return_value->is_ref = 1;
-       } else {
-               ALLOC_ZVAL(return_value);
-               return_value->refcount = 0;
-               return_value->is_ref = 0;
+               zend_error(E_ERROR, "Cannot access HttpMessage properties by reference or array key/index");
+               return NULL;
        }
+       
+       ALLOC_ZVAL(return_value);
+       return_value->refcount = 0;
+       return_value->is_ref = 0;
 
 #ifdef WONKY
        switch (h)
@@ -265,18 +264,13 @@ static zval *_http_message_object_read_prop(zval *object, zval *member, int type
                case HTTP_MSG_PROPHASH_BODY:
                case HTTP_MSG_CHILD_PROPHASH_BODY:
                        phpstr_fix(PHPSTR(msg));
-                       RETVAL_PHPSTR(PHPSTR(msg), 0, !return_value->is_ref);
+                       RETVAL_PHPSTR(PHPSTR(msg), 0, 1);
                break;
 
                case HTTP_MSG_PROPHASH_HEADERS:
                case HTTP_MSG_CHILD_PROPHASH_HEADERS:
-                       if (return_value->is_ref) {
-                               Z_TYPE_P(return_value) = IS_ARRAY;
-                               Z_ARRVAL_P(return_value) = &msg->hdrs;
-                       } else {
-                               array_init(return_value);
-                               zend_hash_copy(Z_ARRVAL_P(return_value), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
-                       }
+                       array_init(return_value);
+                       zend_hash_copy(Z_ARRVAL_P(return_value), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
                break;
 
                case HTTP_MSG_PROPHASH_PARENT_MESSAGE:
@@ -291,7 +285,7 @@ static zval *_http_message_object_read_prop(zval *object, zval *member, int type
                case HTTP_MSG_PROPHASH_REQUEST_METHOD:
                case HTTP_MSG_CHILD_PROPHASH_REQUEST_METHOD:
                        if (HTTP_MSG_TYPE(REQUEST, msg) && msg->http.info.request.method) {
-                               RETVAL_STRING(msg->http.info.request.method, !return_value->is_ref);
+                               RETVAL_STRING(msg->http.info.request.method, 1);
                        } else {
                                RETVAL_NULL();
                        }
@@ -300,7 +294,7 @@ static zval *_http_message_object_read_prop(zval *object, zval *member, int type
                case HTTP_MSG_PROPHASH_REQUEST_URI:
                case HTTP_MSG_CHILD_PROPHASH_REQUEST_URI:
                        if (HTTP_MSG_TYPE(REQUEST, msg) && msg->http.info.request.URI) {
-                               RETVAL_STRING(msg->http.info.request.URI, !return_value->is_ref);
+                               RETVAL_STRING(msg->http.info.request.URI, 1);
                        } else {
                                RETVAL_NULL();
                        }
@@ -318,7 +312,7 @@ static zval *_http_message_object_read_prop(zval *object, zval *member, int type
                case HTTP_MSG_PROPHASH_RESPONSE_STATUS:
                case HTTP_MSG_CHILD_PROPHASH_RESPONSE_STATUS:
                        if (HTTP_MSG_TYPE(RESPONSE, msg) && msg->http.info.response.status) {
-                               RETVAL_STRING(msg->http.info.response.status, !return_value->is_ref);
+                               RETVAL_STRING(msg->http.info.response.status, 1);
                        } else {
                                RETVAL_NULL();
                        }
index ace6b4eb7e4347bcd522e150f95aa70b816187d6..5214a77c401f025e4bad8bc3a893f2915b082dfb 100644 (file)
@@ -834,10 +834,6 @@ static int http_curl_raw_callback(CURL *ch, curl_infotype type, char *data, size
 {
        HTTP_REQUEST_CALLBACK_DATA(ctx, http_request_conv *, conv);
 
-#if 0
-       fprintf(stderr, "DEBUG: %s\n", data);
-#endif
-
        switch (type)
        {
                case CURLINFO_DATA_IN:
@@ -858,6 +854,26 @@ static int http_curl_raw_callback(CURL *ch, curl_infotype type, char *data, size
                                phpstr_append(conv->request, data, length);
                        }
                break;
+#if 0
+               default:
+                       fprintf(stderr, "## ", type);
+                       if (!type) {
+                               fprintf(stderr, "%s", data);
+                       } else {
+                               ulong i;
+                               for (i = 1; i <= length; ++i) {
+                                       fprintf(stderr, "%02X ", data[i-1] & 0xFF);
+                                       if (!(i % 20)) {
+                                               fprintf(stderr, "\n## ");
+                                       }
+                               }
+                               fprintf(stderr, "\n");
+                       }
+                       if (data[length-1] != 0xa) {
+                               fprintf(stderr, "\n");
+                       }
+               break;
+#endif
        }
 
        if (type) {
@@ -907,9 +923,9 @@ static void http_ssl_lock(int mode, int n, const char * file, int line)
        }
 }
 
-static unsigned long http_ssl_id(void)
+static ulong http_ssl_id(void)
 {
-       return (unsigned long) tsrm_thread_id();
+       return (ulong) tsrm_thread_id();
 }
 
 static inline void http_ssl_init(void)
index c17106d2708cdc9d81fe4beb381c139d508f96a0..be19f492ce9832609e4028e9c83a8724d2283862 100644 (file)
@@ -133,8 +133,8 @@ PHP_HTTP_API const char *_http_request_method_name(http_request_method m TSRMLS_
 }
 /* }}} */
 
-/* {{{ unsigned long http_request_method_exists(zend_bool, unsigned long, char *) */
-PHP_HTTP_API unsigned long _http_request_method_exists(zend_bool by_name, unsigned long id, const char *name TSRMLS_DC)
+/* {{{ ulong http_request_method_exists(zend_bool, ulong, char *) */
+PHP_HTTP_API ulong _http_request_method_exists(zend_bool by_name, ulong id, const char *name TSRMLS_DC)
 {
        if (by_name) {
                unsigned i;
@@ -162,12 +162,12 @@ PHP_HTTP_API unsigned long _http_request_method_exists(zend_bool by_name, unsign
 }
 /* }}} */
 
-/* {{{ unsigned long http_request_method_register(char *) */
-PHP_HTTP_API unsigned long _http_request_method_register(const char *method_name, size_t method_name_len TSRMLS_DC)
+/* {{{ ulong http_request_method_register(char *) */
+PHP_HTTP_API ulong _http_request_method_register(const char *method_name, size_t method_name_len TSRMLS_DC)
 {
        zval array;
        char *http_method, *method;
-       unsigned long i, meth_num = HTTP_G(request).methods.custom.nNextFreeElement + HTTP_MAX_REQUEST_METHOD;
+       ulong i, meth_num = HTTP_G(request).methods.custom.nNextFreeElement + HTTP_MAX_REQUEST_METHOD;
 
        method = emalloc(method_name_len + 1);
        for (i = 0; i < method_name_len; ++i) {
@@ -193,7 +193,7 @@ PHP_HTTP_API unsigned long _http_request_method_register(const char *method_name
 /* }}} */
 
 /* {{{ STATUS http_request_method_unregister(usngigned long) */
-PHP_HTTP_API STATUS _http_request_method_unregister(unsigned long method TSRMLS_DC)
+PHP_HTTP_API STATUS _http_request_method_unregister(ulong method TSRMLS_DC)
 {
        zval **zmethod;
        char *http_method;
index 2a531078a4b12653b0d6bcbdf5d00a99365531c5..6ab4a2f2f3e1010267d6df019c830188b72d2a2e 100644 (file)
@@ -338,7 +338,7 @@ PHP_HTTP_API STATUS _http_send_ex(const void *data_ptr, size_t data_size, http_s
                                                char range_header_str[256];
                                                size_t range_header_len;
                                                
-                                               range_header_len = snprintf(range_header_str, lenof(range_header_str), "Content-Range: bytes %ld-%ld/%lu", Z_LVAL_PP(begin), Z_LVAL_PP(end), (unsigned long) data_size);
+                                               range_header_len = snprintf(range_header_str, lenof(range_header_str), "Content-Range: bytes %ld-%ld/%lu", Z_LVAL_PP(begin), Z_LVAL_PP(end), (ulong) data_size);
                                                http_send_status_header_ex(206, range_header_str, range_header_len, 1);
                                                http_send_response_start(&s, Z_LVAL_PP(end)-Z_LVAL_PP(begin)+1);
                                                http_send_response_data_fetch(&s, data_ptr, data_size, data_mode, Z_LVAL_PP(begin), Z_LVAL_PP(end) + 1);
@@ -353,7 +353,7 @@ PHP_HTTP_API STATUS _http_send_ex(const void *data_ptr, size_t data_size, http_s
                                        char boundary_str[32], range_header_str[256];
                                        size_t boundary_len, range_header_len;
                                        
-                                       boundary_len = snprintf(boundary_str, lenof(boundary_str), "%lu%0.9f", (unsigned long) time(NULL), (float) php_combined_lcg(TSRMLS_C));
+                                       boundary_len = snprintf(boundary_str, lenof(boundary_str), "%lu%0.9f", (ulong) time(NULL), (float) php_combined_lcg(TSRMLS_C));
                                        range_header_len = snprintf(range_header_str, lenof(range_header_str), "Content-Type: multipart/byteranges; boundary=%s", boundary_str);
                                        
                                        http_send_status_header_ex(206, range_header_str, range_header_len, 1);
index d75d432125a1ef4c98b433e7e9f012ad5ea590d9..e6c0838c8cec6a62c2715b842588f1acf7194e50 100644 (file)
@@ -74,8 +74,8 @@ static inline void *_http_etag_init(TSRMLS_D)
        switch (mode)
        {
                case HTTP_ETAG_CRC32:
-                       ctx = emalloc(sizeof(unsigned int));
-                       *((unsigned int *) ctx) = ~0;
+                       ctx = emalloc(sizeof(uint));
+                       *((uint *) ctx) = ~0;
                break;
                
                case HTTP_ETAG_SHA1:
@@ -109,9 +109,9 @@ static inline void _http_etag_free(void **ctx_ptr TSRMLS_DC)
        switch (mode)
        {
                case HTTP_ETAG_CRC32:
-                       if (*((unsigned int **) ctx_ptr)) {
-                               efree(*((unsigned int **) ctx_ptr));
-                               *((unsigned int **) ctx_ptr) = NULL;
+                       if (*((uint **) ctx_ptr)) {
+                               efree(*((uint **) ctx_ptr));
+                               *((uint **) ctx_ptr) = NULL;
                        }
                break;
                
@@ -154,8 +154,8 @@ static inline char *_http_etag_finish(void **ctx_ptr TSRMLS_DC)
        switch (mode)
        {
                case HTTP_ETAG_CRC32:
-                       **((unsigned int **) ctx_ptr) = ~**((unsigned int **) ctx_ptr);
-                       etag = http_etag_digest(*((const unsigned char **) ctx_ptr), sizeof(unsigned int));
+                       **((uint **) ctx_ptr) = ~**((uint **) ctx_ptr);
+                       etag = http_etag_digest(*((const unsigned char **) ctx_ptr), sizeof(uint));
                break;
                
                case HTTP_ETAG_SHA1:
@@ -196,12 +196,12 @@ static inline void _http_etag_update(void *ctx, const char *data_ptr, size_t dat
        {
                case HTTP_ETAG_CRC32:
                {
-                       unsigned int i, c = *((unsigned int *) ctx);
+                       uint i, c = *((uint *) ctx);
                        
                        for (i = 0; i < data_len; ++i) {
                                c = CRC32(c, data_ptr[i]);
                        }
-                       *((unsigned int *)ctx) = c;
+                       *((uint *)ctx) = c;
                }
                break;
                
index c26f2f4720f704c9dce08e8a7d4fe026e55c775c..a87a8c6dfde985ae445e54408042970f1885b879 100644 (file)
@@ -53,7 +53,7 @@ PHP_HTTP_API STATUS _http_decode(http_encoding_type type, const char *data, size
 typedef struct {
        z_stream Z;
        int gzip;
-       unsigned long crc;
+       ulong crc;
        phpstr *storage;
 } http_encoding_stream;
 
index 7a2f0b1c456f5de4c78d446584b838f951f91b1a..67b3665b773ad7e541741b765d222426fc7e5bf1 100644 (file)
@@ -64,13 +64,13 @@ extern PHP_RSHUTDOWN_FUNCTION(http_request_method);
 PHP_HTTP_API const char *_http_request_method_name(http_request_method m TSRMLS_DC);
 
 #define http_request_method_exists(u, l, c) _http_request_method_exists((u), (l), (c) TSRMLS_CC)
-PHP_HTTP_API unsigned long _http_request_method_exists(zend_bool by_name, unsigned long id, const char *name TSRMLS_DC);
+PHP_HTTP_API ulong _http_request_method_exists(zend_bool by_name, ulong id, const char *name TSRMLS_DC);
 
 #define http_request_method_register(m, l) _http_request_method_register((m), (l) TSRMLS_CC)
-PHP_HTTP_API unsigned long _http_request_method_register(const char *method, size_t method_name_len TSRMLS_DC);
+PHP_HTTP_API ulong _http_request_method_register(const char *method, size_t method_name_len TSRMLS_DC);
 
 #define http_request_method_unregister(mn) _http_request_method_unregister((mn) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_request_method_unregister(unsigned long method TSRMLS_DC);
+PHP_HTTP_API STATUS _http_request_method_unregister(ulong method TSRMLS_DC);
 
 #endif