From 266dd631dcb4e0652522ad4884ee8a40b88532ec Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 28 Oct 2005 21:01:36 +0000 Subject: [PATCH] - no HttpMessage property access by reference - use ulong/uint instead of unsigned long/int --- http_encoding_api.c | 18 +++++++++--------- http_functions.c | 6 +++--- http_message_api.c | 4 ++-- http_message_object.c | 30 ++++++++++++------------------ http_request_api.c | 28 ++++++++++++++++++++++------ http_request_method_api.c | 12 ++++++------ http_send_api.c | 4 ++-- php_http_cache_api.h | 18 +++++++++--------- php_http_encoding_api.h | 2 +- php_http_request_method_api.h | 6 +++--- 10 files changed, 69 insertions(+), 59 deletions(-) diff --git a/http_encoding_api.c b/http_encoding_api.c index b4244f0..c16bc1a 100644 --- a/http_encoding_api.c +++ b/http_encoding_api.c @@ -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 { diff --git a/http_functions.c b/http_functions.c index 34a8e71..5ff5e33 100644 --- a/http_functions.c +++ b/http_functions.c @@ -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); } } /* }}} */ diff --git a/http_message_api.c b/http_message_api.c index 0cd1e8b..6dd2067 100644 --- a/http_message_api.c +++ b/http_message_api.c @@ -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; } } } diff --git a/http_message_object.c b/http_message_object.c index 29ea53a..0510829 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -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(); } diff --git a/http_request_api.c b/http_request_api.c index ace6b4e..5214a77 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -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) diff --git a/http_request_method_api.c b/http_request_method_api.c index c17106d..be19f49 100644 --- a/http_request_method_api.c +++ b/http_request_method_api.c @@ -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; diff --git a/http_send_api.c b/http_send_api.c index 2a53107..6ab4a2f 100644 --- a/http_send_api.c +++ b/http_send_api.c @@ -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); diff --git a/php_http_cache_api.h b/php_http_cache_api.h index d75d432..e6c0838 100644 --- a/php_http_cache_api.h +++ b/php_http_cache_api.h @@ -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; diff --git a/php_http_encoding_api.h b/php_http_encoding_api.h index c26f2f4..a87a8c6 100644 --- a/php_http_encoding_api.h +++ b/php_http_encoding_api.h @@ -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; diff --git a/php_http_request_method_api.h b/php_http_request_method_api.h index 7a2f0b1..67b3665 100644 --- a/php_http_request_method_api.h +++ b/php_http_request_method_api.h @@ -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 -- 2.30.2