From cc8acf603d067ea4ad52e676e43f03701728eb9d Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 4 Dec 2015 14:00:34 +0100 Subject: [PATCH] add http\Env\Url remove http\Url::FROM_ENV from default flags add class_entry accessors --- src/php_http_client.c | 27 ++++++++------- src/php_http_client.h | 2 +- src/php_http_client_request.c | 12 ++++--- src/php_http_client_request.h | 2 +- src/php_http_client_response.c | 14 +++++--- src/php_http_client_response.h | 2 +- src/php_http_cookie.c | 9 +++-- src/php_http_cookie.h | 2 +- src/php_http_encoding.c | 26 ++++++++++++--- src/php_http_encoding.h | 8 ++--- src/php_http_env.c | 10 ++++-- src/php_http_env.h | 2 +- src/php_http_env_request.c | 15 +++++---- src/php_http_env_request.h | 2 +- src/php_http_env_response.c | 24 ++++++++------ src/php_http_env_response.h | 2 +- src/php_http_exception.c | 60 ++++++++++++++++++++++++++++------ src/php_http_exception.h | 24 +++++++------- src/php_http_header.c | 10 ++++-- src/php_http_header.h | 2 +- src/php_http_header_parser.c | 8 +++-- src/php_http_header_parser.h | 2 +- src/php_http_message.c | 28 +++++++++------- src/php_http_message.h | 2 +- src/php_http_message_body.c | 12 ++++--- src/php_http_message_body.h | 2 +- src/php_http_message_parser.c | 12 ++++--- src/php_http_message_parser.h | 2 +- src/php_http_params.c | 10 ++++-- src/php_http_params.h | 2 +- src/php_http_querystring.c | 12 ++++--- src/php_http_querystring.h | 2 +- src/php_http_url.c | 29 +++++++++++++--- src/php_http_url.h | 3 +- tests/url001.phpt | 14 ++++---- 35 files changed, 264 insertions(+), 131 deletions(-) diff --git a/src/php_http_client.c b/src/php_http_client.c index 5d78803..5de1eac 100644 --- a/src/php_http_client.c +++ b/src/php_http_client.c @@ -61,6 +61,12 @@ void php_http_client_driver_list(HashTable *ht) zend_hash_apply_with_argument(&php_http_client_drivers, apply_driver_list, ht); } +static zend_class_entry *php_http_client_class_entry; +zend_class_entry *php_http_client_get_class_entry(void) +{ + return php_http_client_class_entry; +} + void php_http_client_options_set_subr(zval *instance, char *key, size_t len, zval *opts, int overwrite) { if (overwrite || (opts && zend_hash_num_elements(Z_ARRVAL_P(opts)))) { @@ -318,7 +324,6 @@ ZEND_RESULT_CODE php_http_client_getopt(php_http_client_t *h, php_http_client_ge return FAILURE; } -zend_class_entry *php_http_client_class_entry; static zend_object_handlers php_http_client_object_handlers; void php_http_client_object_free(zend_object *object) @@ -357,7 +362,7 @@ static void handle_history(zval *zclient, php_http_message_t *request, php_http_ php_http_message_t *req_copy = php_http_message_copy(request, NULL); php_http_message_t *res_copy = php_http_message_copy(response, NULL); php_http_message_t *zipped = php_http_message_zip(res_copy, req_copy); - php_http_message_object_t *obj = php_http_message_object_new_ex(php_http_message_class_entry, zipped); + php_http_message_object_t *obj = php_http_message_object_new_ex(php_http_message_get_class_entry(), zipped); ZVAL_OBJ(&new_hist, &obj->zo); @@ -394,7 +399,7 @@ static ZEND_RESULT_CODE handle_response(void *arg, php_http_client_t *client, ph php_http_message_free(&msg->parent); *response = NULL; - msg_obj = php_http_message_object_new_ex(php_http_client_response_class_entry, msg); + msg_obj = php_http_message_object_new_ex(php_http_get_client_response_class_entry(), msg); ZVAL_OBJ(&zresponse, &msg_obj->zo); ZVAL_OBJECT(&zrequest, &((php_http_message_object_t *) e->opaque)->zo, 1); @@ -403,7 +408,7 @@ static ZEND_RESULT_CODE handle_response(void *arg, php_http_client_t *client, ph object_init(&info); info_ht = HASH_OF(&info); php_http_client_getopt(client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, e->request, &info_ht); - zend_update_property(php_http_client_response_class_entry, &zresponse, ZEND_STRL("transferInfo"), &info); + zend_update_property(php_http_get_client_response_class_entry(), &zresponse, ZEND_STRL("transferInfo"), &info); zval_ptr_dtor(&info); Z_ADDREF(zresponse); @@ -599,7 +604,7 @@ static PHP_METHOD(HttpClient, enqueue) php_http_message_object_t *msg_obj; php_http_client_enqueue_t q; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O|f", &request, php_http_client_request_class_entry, &fci, &fcc), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O|f", &request, php_http_get_client_request_class_entry(), &fci, &fcc), invalid_arg, return); obj = PHP_HTTP_OBJ(NULL, getThis()); msg_obj = PHP_HTTP_OBJ(NULL, request); @@ -642,7 +647,7 @@ static PHP_METHOD(HttpClient, dequeue) php_http_client_object_t *obj; php_http_message_object_t *msg_obj; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &request, php_http_client_request_class_entry), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &request, php_http_get_client_request_class_entry()), invalid_arg, return); obj = PHP_HTTP_OBJ(NULL, getThis()); msg_obj = PHP_HTTP_OBJ(NULL, request); @@ -670,7 +675,7 @@ static PHP_METHOD(HttpClient, requeue) php_http_message_object_t *msg_obj; php_http_client_enqueue_t q; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O|f", &request, php_http_client_request_class_entry, &fci, &fcc), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O|f", &request, php_http_get_client_request_class_entry(), &fci, &fcc), invalid_arg, return); obj = PHP_HTTP_OBJ(NULL, getThis()); msg_obj = PHP_HTTP_OBJ(NULL, request); @@ -724,7 +729,7 @@ static PHP_METHOD(HttpClient, getResponse) zval *zrequest = NULL; php_http_client_object_t *obj; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|O", &zrequest, php_http_client_request_class_entry), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|O", &zrequest, php_http_get_client_request_class_entry()), invalid_arg, return); obj = PHP_HTTP_OBJ(NULL, getThis()); @@ -892,7 +897,7 @@ static PHP_METHOD(HttpClient, notify) php_http_client_object_t *client_obj; struct notify_arg arg = {NULL}; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|O!o!", &request, php_http_client_request_class_entry, &zprogress), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|O!o!", &request, php_http_get_client_request_class_entry(), &zprogress), invalid_arg, return); client_obj = PHP_HTTP_OBJ(NULL, getThis()); observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0, &observers_tmp); @@ -1010,7 +1015,7 @@ static PHP_METHOD(HttpClient, getProgressInfo) php_http_message_object_t *req_obj; php_http_client_progress_state_t *progress; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &request, php_http_client_request_class_entry), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &request, php_http_get_client_request_class_entry()), invalid_arg, return); obj = PHP_HTTP_OBJ(NULL, getThis()); req_obj = PHP_HTTP_OBJ(NULL, request); @@ -1037,7 +1042,7 @@ static PHP_METHOD(HttpClient, getTransferInfo) php_http_client_object_t *obj; php_http_message_object_t *req_obj; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &request, php_http_client_request_class_entry), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &request, php_http_get_client_request_class_entry()), invalid_arg, return); obj = PHP_HTTP_OBJ(NULL, getThis()); req_obj = PHP_HTTP_OBJ(NULL, request); diff --git a/src/php_http_client.h b/src/php_http_client.h index 792581a..6aa8abf 100644 --- a/src/php_http_client.h +++ b/src/php_http_client.h @@ -111,7 +111,7 @@ typedef struct php_http_client { zend_llist responses; } php_http_client_t; -PHP_HTTP_API zend_class_entry *php_http_client_class_entry; +PHP_HTTP_API zend_class_entry *php_http_client_get_class_entry(); typedef struct php_http_client_object { php_http_client_t *client; diff --git a/src/php_http_client_request.c b/src/php_http_client_request.c index 05d4a81..f64c357 100644 --- a/src/php_http_client_request.c +++ b/src/php_http_client_request.c @@ -12,6 +12,12 @@ #include "php_http_api.h" +static zend_class_entry *php_http_client_request_class_entry; +zend_class_entry *php_http_get_client_request_class_entry(void) +{ + return php_http_client_request_class_entry; +} + void php_http_client_options_set_subr(zval *this_ptr, char *key, size_t len, zval *opts, int overwrite); void php_http_client_options_set(zval *this_ptr, zval *opts); void php_http_client_options_get_subr(zval *this_ptr, char *key, size_t len, zval *return_value); @@ -36,7 +42,7 @@ static PHP_METHOD(HttpClientRequest, __construct) zval *zheaders = NULL, *zbody = NULL, *zurl = NULL; php_http_message_object_t *obj; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!z!a!O!", &meth_str, &meth_len, &zurl, &zheaders, &zbody, php_http_message_body_class_entry), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!z!a!O!", &meth_str, &meth_len, &zurl, &zheaders, &zbody, php_http_get_message_body_class_entry()), invalid_arg, return); obj = PHP_HTTP_OBJ(NULL, getThis()); @@ -276,14 +282,12 @@ static zend_function_entry php_http_client_request_methods[] = { EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_client_request_class_entry; - PHP_MINIT_FUNCTION(http_client_request) { zend_class_entry ce = {0}; INIT_NS_CLASS_ENTRY(ce, "http\\Client", "Request", php_http_client_request_methods); - php_http_client_request_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry); + php_http_client_request_class_entry = zend_register_internal_class_ex(&ce, php_http_message_get_class_entry()); zend_declare_property_null(php_http_client_request_class_entry, ZEND_STRL("options"), ZEND_ACC_PROTECTED); diff --git a/src/php_http_client_request.h b/src/php_http_client_request.h index 474114b..aee4da5 100644 --- a/src/php_http_client_request.h +++ b/src/php_http_client_request.h @@ -13,7 +13,7 @@ #ifndef PHP_HTTP_CLIENT_REQUEST_H #define PHP_HTTP_CLIENT_REQUEST_H -PHP_HTTP_API zend_class_entry *php_http_client_request_class_entry; +PHP_HTTP_API zend_class_entry *php_http_get_client_request_class_entry(void); PHP_MINIT_FUNCTION(http_client_request); #endif /* PHP_HTTP_CLIENT_REQUEST_H */ diff --git a/src/php_http_client_response.c b/src/php_http_client_response.c index b1377fe..5acddae 100644 --- a/src/php_http_client_response.c +++ b/src/php_http_client_response.c @@ -12,6 +12,12 @@ #include "php_http_api.h" +static zend_class_entry *php_http_client_response_class_entry; +zend_class_entry *php_http_get_client_response_class_entry(void) +{ + return php_http_client_response_class_entry; +} + ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientResponse_getCookies, 0, 0, 0) ZEND_ARG_INFO(0, flags) ZEND_ARG_INFO(0, allowed_extras) @@ -57,7 +63,7 @@ static PHP_METHOD(HttpClientResponse, getCookies) if ((list = php_http_cookie_list_parse(NULL, zs->val, zs->len, flags, allowed_extras))) { zval cookie; - ZVAL_OBJ(&cookie, &php_http_cookie_object_new_ex(php_http_cookie_class_entry, list)->zo); + ZVAL_OBJ(&cookie, &php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list)->zo); add_next_index_zval(return_value, &cookie); } zend_string_release(zs); @@ -69,7 +75,7 @@ static PHP_METHOD(HttpClientResponse, getCookies) if ((list = php_http_cookie_list_parse(NULL, zs->val, zs->len, flags, allowed_extras))) { zval cookie; - ZVAL_OBJ(&cookie, &php_http_cookie_object_new_ex(php_http_cookie_class_entry, list)->zo); + ZVAL_OBJ(&cookie, &php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list)->zo); add_next_index_zval(return_value, &cookie); } zend_string_release(zs); @@ -121,14 +127,12 @@ static zend_function_entry php_http_client_response_methods[] = { EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_client_response_class_entry; - PHP_MINIT_FUNCTION(http_client_response) { zend_class_entry ce = {0}; INIT_NS_CLASS_ENTRY(ce, "http\\Client", "Response", php_http_client_response_methods); - php_http_client_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry); + php_http_client_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_get_class_entry()); zend_declare_property_null(php_http_client_response_class_entry, ZEND_STRL("transferInfo"), ZEND_ACC_PROTECTED); diff --git a/src/php_http_client_response.h b/src/php_http_client_response.h index 15d004e..7a47cbe 100644 --- a/src/php_http_client_response.h +++ b/src/php_http_client_response.h @@ -13,7 +13,7 @@ #ifndef PHP_HTTP_CLIENT_RESPONSE_H #define PHP_HTTP_CLIENT_RESPONSE_H -PHP_HTTP_API zend_class_entry *php_http_client_response_class_entry; +PHP_HTTP_API zend_class_entry *php_http_get_client_response_class_entry(void); PHP_MINIT_FUNCTION(http_client_response); #endif /* PHP_HTTP_CLIENT_RESPONSE_H */ diff --git a/src/php_http_cookie.c b/src/php_http_cookie.c index 9625401..67b4494 100644 --- a/src/php_http_cookie.c +++ b/src/php_http_cookie.c @@ -366,6 +366,11 @@ void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, si } +static zend_class_entry *php_http_cookie_class_entry; +zend_class_entry *php_http_cookie_get_class_entry(void) +{ + return php_http_cookie_class_entry; +} static zend_object_handlers php_http_cookie_object_handlers; @@ -439,7 +444,7 @@ static PHP_METHOD(HttpCookie, __construct) obj = PHP_HTTP_OBJ(NULL, getThis()); - zend_replace_error_handling(EH_THROW, php_http_exception_runtime_class_entry, &zeh); + zend_replace_error_handling(EH_THROW, php_http_get_exception_runtime_class_entry(), &zeh); if (zcookie) { if (allowed_extras && zend_hash_num_elements(allowed_extras)) { @@ -1010,8 +1015,6 @@ static zend_function_entry php_http_cookie_methods[] = { EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_cookie_class_entry; - PHP_MINIT_FUNCTION(http_cookie) { zend_class_entry ce = {0}; diff --git a/src/php_http_cookie.h b/src/php_http_cookie.h index f7dbf8d..e7b924e 100644 --- a/src/php_http_cookie.h +++ b/src/php_http_cookie.h @@ -53,7 +53,7 @@ PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, c PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_from_struct(php_http_cookie_list_t *list, zval *strct); PHP_HTTP_API void php_http_cookie_list_to_struct(php_http_cookie_list_t *list, zval *strct); -PHP_HTTP_API zend_class_entry *php_http_cookie_class_entry; +PHP_HTTP_API zend_class_entry *php_http_cookie_get_class_entry(void); typedef struct php_http_cookie_object { php_http_cookie_list_t *list; diff --git a/src/php_http_encoding.c b/src/php_http_encoding.c index e7557a0..7fbe7c7 100644 --- a/src/php_http_encoding.c +++ b/src/php_http_encoding.c @@ -943,6 +943,27 @@ void php_http_encoding_stream_object_free(zend_object *object) zend_object_std_dtor(object); } +static zend_class_entry *php_http_encoding_stream_class_entry; +zend_class_entry *php_http_get_encoding_stream_class_entry(void) +{ + return php_http_encoding_stream_class_entry; +} +static zend_class_entry *php_http_deflate_stream_class_entry; +zend_class_entry *php_http_get_deflate_stream_class_entry(void) +{ + return php_http_deflate_stream_class_entry; +} +static zend_class_entry *php_http_inflate_stream_class_entry; +zend_class_entry *php_http_get_inflate_stream_class_entry(void) +{ + return php_http_inflate_stream_class_entry; +} +static zend_class_entry *php_http_dechunk_stream_class_entry; +zend_class_entry *php_http_get_dechunk_stream_class_entry(void) +{ + return php_http_dechunk_stream_class_entry; +} + ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream___construct, 0, 0, 0) ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO(); @@ -1165,11 +1186,6 @@ static zend_function_entry php_http_dechunk_stream_methods[] = { EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_encoding_stream_class_entry; -zend_class_entry *php_http_deflate_stream_class_entry; -zend_class_entry *php_http_inflate_stream_class_entry; -zend_class_entry *php_http_dechunk_stream_class_entry; - PHP_MINIT_FUNCTION(http_encoding) { zend_class_entry ce = {0}; diff --git a/src/php_http_encoding.h b/src/php_http_encoding.h index ea767dd..a924eaf 100644 --- a/src/php_http_encoding.h +++ b/src/php_http_encoding.h @@ -170,16 +170,16 @@ typedef struct php_http_encoding_stream_object { zend_object zo; } php_http_encoding_stream_object_t; -PHP_HTTP_API zend_class_entry *php_http_encoding_stream_class_entry; +PHP_HTTP_API zend_class_entry *php_http_get_encoding_stream_class_entry(void); zend_object *php_http_encoding_stream_object_new(zend_class_entry *ce); php_http_encoding_stream_object_t *php_http_encoding_stream_object_new_ex(zend_class_entry *ce, php_http_encoding_stream_t *s); zend_object *php_http_encoding_stream_object_clone(zval *object); void php_http_encoding_stream_object_free(zend_object *object); -PHP_HTTP_API zend_class_entry *php_http_deflate_stream_class_entry; -PHP_HTTP_API zend_class_entry *php_http_inflate_stream_class_entry; -PHP_HTTP_API zend_class_entry *php_http_dechunk_stream_class_entry; +PHP_HTTP_API zend_class_entry *php_http_get_deflate_stream_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_get_inflate_stream_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_get_dechunk_stream_class_entry(void); #endif diff --git a/src/php_http_env.c b/src/php_http_env.c index df22d5a..21bd89a 100644 --- a/src/php_http_env.c +++ b/src/php_http_env.c @@ -555,12 +555,12 @@ static PHP_METHOD(HttpEnv, getRequestBody) { php_http_message_body_t *body; php_http_message_body_object_t *body_obj; - zend_class_entry *class_entry = php_http_message_body_class_entry; + zend_class_entry *class_entry = php_http_get_message_body_class_entry(); php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|C", &class_entry), invalid_arg, return); body = php_http_env_get_request_body(); - if (SUCCESS == php_http_new((void *) &body_obj, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_message_body_class_entry, body)) { + if (SUCCESS == php_http_new((void *) &body_obj, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_get_message_body_class_entry(), body)) { php_http_message_body_addref(body); RETVAL_OBJ(&body_obj->zo); } @@ -795,7 +795,11 @@ static zend_function_entry php_http_env_methods[] = { EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_env_class_entry; +static zend_class_entry *php_http_env_class_entry; +zend_class_entry *php_http_env_get_class_entry(void) +{ + return php_http_env_class_entry; +} PHP_MINIT_FUNCTION(http_env) { diff --git a/src/php_http_env.h b/src/php_http_env.h index 273ba16..8292744 100644 --- a/src/php_http_env.h +++ b/src/php_http_env.h @@ -76,7 +76,7 @@ static inline zend_bool php_http_env_got_server_var(const char *v) } -PHP_HTTP_API zend_class_entry *php_http_env_class_entry; +PHP_HTTP_API zend_class_entry *php_http_env_get_class_entry(void); PHP_MINIT_FUNCTION(http_env); PHP_RSHUTDOWN_FUNCTION(http_env); diff --git a/src/php_http_env_request.c b/src/php_http_env_request.c index 0ee68f4..b5454ed 100644 --- a/src/php_http_env_request.c +++ b/src/php_http_env_request.c @@ -117,6 +117,11 @@ static int grab_files(zval *val, int argc, va_list argv, zend_hash_key *key) } \ } while(0) +static zend_class_entry *php_http_env_request_class_entry; +zend_class_entry *php_http_get_env_request_class_entry(void) +{ + return php_http_env_request_class_entry; +} ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvRequest___construct, 0, 0, 0) ZEND_END_ARG_INFO(); @@ -133,19 +138,19 @@ static PHP_METHOD(HttpEnvRequest, __construct) php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_REQUEST), unexpected_val, return); zsg = php_http_env_get_superglobal(ZEND_STRL("_GET")); - object_init_ex(&zqs, php_http_querystring_class_entry); + object_init_ex(&zqs, php_http_querystring_get_class_entry()); php_http_expect(SUCCESS == php_http_querystring_ctor(&zqs, zsg), unexpected_val, return); zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("query"), &zqs); zval_ptr_dtor(&zqs); zsg = php_http_env_get_superglobal(ZEND_STRL("_POST")); - object_init_ex(&zqs, php_http_querystring_class_entry); + object_init_ex(&zqs, php_http_querystring_get_class_entry()); php_http_expect(SUCCESS == php_http_querystring_ctor(&zqs, zsg), unexpected_val, return); zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("form"), &zqs); zval_ptr_dtor(&zqs); zsg = php_http_env_get_superglobal(ZEND_STRL("_COOKIE")); - object_init_ex(&zqs, php_http_querystring_class_entry); + object_init_ex(&zqs, php_http_querystring_get_class_entry()); php_http_expect(SUCCESS == php_http_querystring_ctor(&zqs, zsg), unexpected_val, return); zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("cookie"), &zqs); zval_ptr_dtor(&zqs); @@ -248,14 +253,12 @@ static zend_function_entry php_http_env_request_methods[] = { EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_env_request_class_entry; - PHP_MINIT_FUNCTION(http_env_request) { zend_class_entry ce = {0}; INIT_NS_CLASS_ENTRY(ce, "http\\Env", "Request", php_http_env_request_methods); - php_http_env_request_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry); + php_http_env_request_class_entry = zend_register_internal_class_ex(&ce, php_http_message_get_class_entry()); zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("query"), ZEND_ACC_PROTECTED); zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("form"), ZEND_ACC_PROTECTED); diff --git a/src/php_http_env_request.h b/src/php_http_env_request.h index a97836b..a799134 100644 --- a/src/php_http_env_request.h +++ b/src/php_http_env_request.h @@ -13,7 +13,7 @@ #ifndef PHP_HTTP_ENV_REQUEST_H #define PHP_HTTP_ENV_REQUEST_H -PHP_HTTP_API zend_class_entry *php_http_env_request_class_entry; +PHP_HTTP_API zend_class_entry *php_http_get_env_request_class_entry(void); PHP_MINIT_FUNCTION(http_env_request); #endif diff --git a/src/php_http_env_response.c b/src/php_http_env_response.c index 9bc3f5b..6324698 100644 --- a/src/php_http_env_response.c +++ b/src/php_http_env_response.c @@ -82,7 +82,7 @@ static php_http_message_body_t *get_body(zval *options) php_http_message_body_t *body = NULL; if ((zbody = get_option(options, ZEND_STRL("body"), &zbody_tmp))) { - if ((Z_TYPE_P(zbody) == IS_OBJECT) && instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry)) { + if ((Z_TYPE_P(zbody) == IS_OBJECT) && instanceof_function(Z_OBJCE_P(zbody), php_http_get_message_body_class_entry())) { php_http_message_body_object_t *body_obj = PHP_HTTP_OBJ(NULL, zbody); body = body_obj->body; @@ -98,7 +98,7 @@ static php_http_message_t *get_request(zval *options) php_http_message_t *request = NULL; if ((zrequest = get_option(options, ZEND_STRL("request"), &zrequest_tmp))) { - if (Z_TYPE_P(zrequest) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zrequest), php_http_message_class_entry)) { + if (Z_TYPE_P(zrequest) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zrequest), php_http_message_get_class_entry())) { php_http_message_object_t *request_obj = PHP_HTTP_OBJ(NULL, zrequest); request = request_obj->message; @@ -385,7 +385,7 @@ static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zoption), zcookie) { - if (Z_TYPE_P(zcookie) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zcookie), php_http_cookie_class_entry)) { + if (Z_TYPE_P(zcookie) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zcookie), php_http_cookie_get_class_entry())) { php_http_cookie_object_t *obj = PHP_HTTP_OBJ(NULL, zcookie); char *str; size_t len; @@ -1178,7 +1178,7 @@ static PHP_METHOD(HttpEnvResponse, setEnvRequest) { zval *env_req = NULL; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|O", &env_req, php_http_message_class_entry), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|O", &env_req, php_http_message_get_class_entry()), invalid_arg, return); set_option(getThis(), ZEND_STRL("request"), IS_OBJECT, env_req, 0); RETVAL_ZVAL(getThis(), 1, 0); @@ -1328,10 +1328,10 @@ static PHP_METHOD(HttpEnvResponse, setCookie) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcookie_new), invalid_arg, return); - zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh); + zend_replace_error_handling(EH_THROW, php_http_get_exception_unexpected_val_class_entry(), &zeh); switch (Z_TYPE_P(zcookie_new)) { case IS_OBJECT: - if (instanceof_function(Z_OBJCE_P(zcookie_new), php_http_cookie_class_entry)) { + if (instanceof_function(Z_OBJCE_P(zcookie_new), php_http_cookie_get_class_entry())) { Z_ADDREF_P(zcookie_new); break; } @@ -1339,7 +1339,7 @@ static PHP_METHOD(HttpEnvResponse, setCookie) case IS_ARRAY: list = php_http_cookie_list_from_struct(NULL, zcookie_new); zcookie_new = &tmp; - ZVAL_OBJECT(zcookie_new, &php_http_cookie_object_new_ex(php_http_cookie_class_entry, list)->zo, 0); + ZVAL_OBJECT(zcookie_new, &php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list)->zo, 0); break; default: @@ -1347,7 +1347,7 @@ static PHP_METHOD(HttpEnvResponse, setCookie) list = php_http_cookie_list_parse(NULL, zs->val, zs->len, 0, NULL); zend_string_release(zs); zcookie_new = &tmp; - ZVAL_OBJECT(zcookie_new, &php_http_cookie_object_new_ex(php_http_cookie_class_entry, list)->zo, 0); + ZVAL_OBJECT(zcookie_new, &php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list)->zo, 0); } zend_restore_error_handling(&zeh); @@ -1412,14 +1412,18 @@ static zend_function_entry php_http_env_response_methods[] = { EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_env_response_class_entry; +static zend_class_entry *php_http_env_response_class_entry; +zend_class_entry *php_http_get_env_response_class_entry(void) +{ + return php_http_env_response_class_entry; +} PHP_MINIT_FUNCTION(http_env_response) { zend_class_entry ce = {0}; INIT_NS_CLASS_ENTRY(ce, "http\\Env", "Response", php_http_env_response_methods); - php_http_env_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry); + php_http_env_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_get_class_entry()); zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_NONE"), PHP_HTTP_CONTENT_ENCODING_NONE); zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_GZIP"), PHP_HTTP_CONTENT_ENCODING_GZIP); diff --git a/src/php_http_env_response.h b/src/php_http_env_response.h index ae1441d..62fb8f7 100644 --- a/src/php_http_env_response.h +++ b/src/php_http_env_response.h @@ -70,7 +70,7 @@ PHP_HTTP_API void php_http_env_response_free(php_http_env_response_t **r); PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request); PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request); -PHP_HTTP_API zend_class_entry *php_http_env_response_class_entry; +PHP_HTTP_API zend_class_entry *php_http_get_env_response_class_entry(); PHP_MINIT_FUNCTION(http_env_response); #endif diff --git a/src/php_http_exception.c b/src/php_http_exception.c index bae09f9..4c83028 100644 --- a/src/php_http_exception.c +++ b/src/php_http_exception.c @@ -30,16 +30,56 @@ static void php_http_exception_hook(zval *ex) } #endif -zend_class_entry *php_http_exception_interface_class_entry; -zend_class_entry *php_http_exception_runtime_class_entry; -zend_class_entry *php_http_exception_unexpected_val_class_entry; -zend_class_entry *php_http_exception_bad_method_call_class_entry; -zend_class_entry *php_http_exception_invalid_arg_class_entry; -zend_class_entry *php_http_exception_bad_header_class_entry; -zend_class_entry *php_http_exception_bad_url_class_entry; -zend_class_entry *php_http_exception_bad_message_class_entry; -zend_class_entry *php_http_exception_bad_conversion_class_entry; -zend_class_entry *php_http_exception_bad_querystring_class_entry; +static zend_class_entry *php_http_exception_interface_class_entry; +zend_class_entry *php_http_get_exception_interface_class_entry(void) +{ + return php_http_exception_interface_class_entry; +} +static zend_class_entry *php_http_exception_runtime_class_entry; +zend_class_entry *php_http_get_exception_runtime_class_entry(void) +{ + return php_http_exception_runtime_class_entry; +} +static zend_class_entry *php_http_exception_unexpected_val_class_entry; +zend_class_entry *php_http_get_exception_unexpected_val_class_entry(void) +{ + return php_http_exception_unexpected_val_class_entry; +} +static zend_class_entry *php_http_exception_bad_method_call_class_entry; +zend_class_entry *php_http_get_exception_bad_method_call_class_entry(void) +{ + return php_http_exception_bad_method_call_class_entry; +} +static zend_class_entry *php_http_exception_invalid_arg_class_entry; +zend_class_entry *php_http_get_exception_invalid_arg_class_entry(void) +{ + return php_http_exception_invalid_arg_class_entry; +} +static zend_class_entry *php_http_exception_bad_header_class_entry; +zend_class_entry *php_http_get_exception_bad_header_class_entry(void) +{ + return php_http_exception_bad_header_class_entry; +} +static zend_class_entry *php_http_exception_bad_url_class_entry; +zend_class_entry *php_http_get_exception_bad_url_class_entry(void) +{ + return php_http_exception_bad_url_class_entry; +} +static zend_class_entry *php_http_exception_bad_message_class_entry; +zend_class_entry *php_http_get_exception_bad_message_class_entry(void) +{ + return php_http_exception_bad_message_class_entry; +} +static zend_class_entry *php_http_exception_bad_conversion_class_entry; +zend_class_entry *php_http_get_exception_bad_conversion_class_entry(void) +{ + return php_http_exception_bad_conversion_class_entry; +} +static zend_class_entry *php_http_exception_bad_querystring_class_entry; +zend_class_entry *php_http_get_exception_bad_querystring_class_entry(void) +{ + return php_http_exception_bad_querystring_class_entry; +} PHP_MINIT_FUNCTION(http_exception) { diff --git a/src/php_http_exception.h b/src/php_http_exception.h index eaf7a13..5acf280 100644 --- a/src/php_http_exception.h +++ b/src/php_http_exception.h @@ -15,13 +15,13 @@ /* short hand for zend_throw_exception_ex */ #define php_http_throw(e, fmt, ...) \ - zend_throw_exception_ex(php_http_exception_ ##e## _class_entry, 0, fmt, __VA_ARGS__) + zend_throw_exception_ex(php_http_get_exception_ ##e## _class_entry(), 0, fmt, __VA_ARGS__) /* wrap a call with replaced zend_error_handling */ #define php_http_expect(test, e, fail) \ do { \ zend_error_handling __zeh; \ - zend_replace_error_handling(EH_THROW, php_http_exception_ ##e## _class_entry, &__zeh); \ + zend_replace_error_handling(EH_THROW, php_http_get_exception_ ##e## _class_entry(), &__zeh); \ if (!(test)) { \ zend_restore_error_handling(&__zeh); \ fail; \ @@ -29,16 +29,16 @@ zend_restore_error_handling(&__zeh); \ } while(0) -PHP_HTTP_API zend_class_entry *php_http_exception_interface_class_entry; -PHP_HTTP_API zend_class_entry *php_http_exception_runtime_class_entry; -PHP_HTTP_API zend_class_entry *php_http_exception_unexpected_val_class_entry; -PHP_HTTP_API zend_class_entry *php_http_exception_bad_method_call_class_entry; -PHP_HTTP_API zend_class_entry *php_http_exception_invalid_arg_class_entry; -PHP_HTTP_API zend_class_entry *php_http_exception_bad_header_class_entry; -PHP_HTTP_API zend_class_entry *php_http_exception_bad_url_class_entry; -PHP_HTTP_API zend_class_entry *php_http_exception_bad_message_class_entry; -PHP_HTTP_API zend_class_entry *php_http_exception_bad_conversion_class_entry; -PHP_HTTP_API zend_class_entry *php_http_exception_bad_querystring_class_entry; +PHP_HTTP_API zend_class_entry *php_http_get_exception_interface_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_get_exception_runtime_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_get_exception_unexpected_val_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_get_exception_bad_method_call_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_get_exception_invalid_arg_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_get_exception_bad_header_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_get_exception_bad_url_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_get_exception_bad_message_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_get_exception_bad_conversion_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_get_exception_bad_querystring_class_entry(void); PHP_MINIT_FUNCTION(http_exception); diff --git a/src/php_http_header.c b/src/php_http_header.c index d4f2b51..f31e084 100644 --- a/src/php_http_header.c +++ b/src/php_http_header.c @@ -116,6 +116,12 @@ zend_string *php_http_header_value_to_string(zval *header) } } +static zend_class_entry *php_http_header_class_entry; +zend_class_entry *php_http_header_get_class_entry(void) +{ + return php_http_header_class_entry; +} + ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader___construct, 0, 0, 0) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, value) @@ -276,7 +282,7 @@ PHP_METHOD(HttpHeader, getParams) ZVAL_STRINGL(&zctor, "__construct", lenof("__construct")); - object_init_ex(&zparams_obj, php_http_params_class_entry); + object_init_ex(&zparams_obj, php_http_params_get_class_entry()); zargs = (zval *) ecalloc(ZEND_NUM_ARGS()+1, sizeof(zval)); ZVAL_COPY_VALUE(&zargs[0], zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0, &value_tmp)); @@ -356,8 +362,6 @@ static zend_function_entry php_http_header_methods[] = { EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_header_class_entry; - PHP_MINIT_FUNCTION(http_header) { zend_class_entry ce = {0}; diff --git a/src/php_http_header.h b/src/php_http_header.h index 88ebd10..1ba9ef5 100644 --- a/src/php_http_header.h +++ b/src/php_http_header.h @@ -23,7 +23,7 @@ PHP_HTTP_API void php_http_header_to_string(php_http_buffer_t *str, HashTable *h PHP_HTTP_API zend_string *php_http_header_value_to_string(zval *header); PHP_HTTP_API zend_string *php_http_header_value_array_to_string(zval *header); -PHP_HTTP_API zend_class_entry *php_http_header_class_entry; +PHP_HTTP_API zend_class_entry *php_http_header_get_class_entry(void); PHP_MINIT_FUNCTION(http_header); #endif diff --git a/src/php_http_header_parser.c b/src/php_http_header_parser.c index 5dfaedd..fb84452 100644 --- a/src/php_http_header_parser.c +++ b/src/php_http_header_parser.c @@ -333,7 +333,11 @@ php_http_header_parser_state_t php_http_header_parser_parse_stream(php_http_head return PHP_HTTP_HEADER_PARSER_STATE_DONE; } -zend_class_entry *php_http_header_parser_class_entry; +static zend_class_entry *php_http_header_parser_class_entry; +zend_class_entry *php_http_get_header_parser_class_entry(void) +{ + return php_http_header_parser_class_entry; +} static zend_object_handlers php_http_header_parser_object_handlers; zend_object *php_http_header_parser_object_new(zend_class_entry *ce) @@ -425,7 +429,7 @@ static PHP_METHOD(HttpHeaderParser, stream) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &zstream, &flags, &zmsg), invalid_arg, return); - zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh); + zend_replace_error_handling(EH_THROW, php_http_get_exception_unexpected_val_class_entry(), &zeh); php_stream_from_zval(s, zstream); zend_restore_error_handling(&zeh); diff --git a/src/php_http_header_parser.h b/src/php_http_header_parser.h index 33707bd..c22c6a7 100644 --- a/src/php_http_header_parser.h +++ b/src/php_http_header_parser.h @@ -55,7 +55,7 @@ typedef struct php_http_header_parser_object { zend_object zo; } php_http_header_parser_object_t; -PHP_HTTP_API zend_class_entry *php_http_header_parser_class_entry; +PHP_HTTP_API zend_class_entry *php_http_get_header_parser_class_entry(void); PHP_MINIT_FUNCTION(http_header_parser); diff --git a/src/php_http_message.c b/src/php_http_message.c index 74036f9..45f584f 100644 --- a/src/php_http_message.c +++ b/src/php_http_message.c @@ -512,6 +512,12 @@ void php_http_message_free(php_http_message_t **message) } } +static zend_class_entry *php_http_message_class_entry; +zend_class_entry *php_http_message_get_class_entry(void) +{ + return php_http_message_class_entry; +} + static zval *php_http_message_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *rv); static void php_http_message_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot); @@ -763,14 +769,14 @@ ZEND_RESULT_CODE php_http_message_object_set_body(php_http_message_object_t *msg is_resource: body = php_http_message_body_init(NULL, s); - if (!(body_obj = php_http_message_body_object_new_ex(php_http_message_body_class_entry, body))) { + if (!(body_obj = php_http_message_body_object_new_ex(php_http_get_message_body_class_entry(), body))) { php_http_message_body_free(&body); return FAILURE; } break; case IS_OBJECT: - if (instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry)) { + if (instanceof_function(Z_OBJCE_P(zbody), php_http_get_message_body_class_entry())) { Z_ADDREF_P(zbody); body_obj = PHP_HTTP_OBJ(NULL, zbody); break; @@ -807,7 +813,7 @@ ZEND_RESULT_CODE php_http_message_object_set_body(php_http_message_object_t *msg ZEND_RESULT_CODE php_http_message_object_init_body_object(php_http_message_object_t *obj) { php_http_message_body_addref(obj->message->body); - return php_http_new((void *) &obj->body, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body); + return php_http_new((void *) &obj->body, php_http_get_message_body_class_entry(), (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body); } zend_object *php_http_message_object_new(zend_class_entry *ce) @@ -828,7 +834,7 @@ php_http_message_object_t *php_http_message_object_new_ex(zend_class_entry *ce, if (msg->parent) { o->parent = php_http_message_object_new_ex(ce, msg->parent); } - o->body = php_http_message_body_object_new_ex(php_http_message_body_class_entry, php_http_message_body_init(&msg->body, NULL)); + o->body = php_http_message_body_object_new_ex(php_http_get_message_body_class_entry(), php_http_message_body_init(&msg->body, NULL)); } o->zo.handlers = &php_http_message_object_handlers; @@ -1021,13 +1027,13 @@ static PHP_METHOD(HttpMessage, __construct) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!b", &zmessage, &greedy), invalid_arg, return); - zend_replace_error_handling(EH_THROW, php_http_exception_bad_message_class_entry, &zeh); + zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_message_class_entry(), &zeh); if (zmessage && Z_TYPE_P(zmessage) == IS_RESOURCE) { php_stream *s; php_http_message_parser_t p; zend_error_handling zeh; - zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh); + zend_replace_error_handling(EH_THROW, php_http_get_exception_unexpected_val_class_entry(), &zeh); php_stream_from_zval(s, zmessage); zend_restore_error_handling(&zeh); @@ -1097,7 +1103,7 @@ static PHP_METHOD(HttpMessage, setBody) { zval *zbody; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zbody, php_http_message_body_class_entry)) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zbody, php_http_get_message_body_class_entry())) { php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); @@ -1113,7 +1119,7 @@ static PHP_METHOD(HttpMessage, addBody) { zval *new_body; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &new_body, php_http_message_body_class_entry)) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &new_body, php_http_get_message_body_class_entry())) { php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); php_http_message_body_object_t *new_obj = PHP_HTTP_OBJ(NULL, new_body); @@ -1142,7 +1148,7 @@ static PHP_METHOD(HttpMessage, getHeader) if ((header = php_http_message_header(obj->message, header_str, header_len))) { if (!header_ce) { RETURN_ZVAL(header, 1, 0); - } else if (instanceof_function(header_ce, php_http_header_class_entry)) { + } else if (instanceof_function(header_ce, php_http_header_get_class_entry())) { php_http_object_method_t cb; zval argv[2]; @@ -1589,7 +1595,7 @@ static PHP_METHOD(HttpMessage, setRequestUrl) return; } - zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh); + zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh); url = php_http_url_from_zval(zurl, ~0); zend_restore_error_handling(&zeh); @@ -1988,8 +1994,6 @@ static zend_function_entry php_http_message_methods[] = { EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_message_class_entry; - PHP_MINIT_FUNCTION(http_message) { zend_class_entry ce = {0}; diff --git a/src/php_http_message.h b/src/php_http_message.h index 2f99507..eb5aa0d 100644 --- a/src/php_http_message.h +++ b/src/php_http_message.h @@ -92,7 +92,7 @@ typedef struct php_http_message_object { zend_object zo; } php_http_message_object_t; -PHP_HTTP_API zend_class_entry *php_http_message_class_entry; +PHP_HTTP_API zend_class_entry *php_http_message_get_class_entry(void); PHP_MINIT_FUNCTION(http_message); PHP_MSHUTDOWN_FUNCTION(http_message); diff --git a/src/php_http_message_body.c b/src/php_http_message_body.c index d629ae5..43aba7f 100644 --- a/src/php_http_message_body.c +++ b/src/php_http_message_body.c @@ -546,6 +546,12 @@ php_http_message_t *php_http_message_body_split(php_http_message_body_t *body, c return msg; } +static zend_class_entry *php_http_message_body_class_entry; +zend_class_entry *php_http_get_message_body_class_entry(void) +{ + return php_http_message_body_class_entry; +} + static zend_object_handlers php_http_message_body_object_handlers; zend_object *php_http_message_body_object_new(zend_class_entry *ce) @@ -774,14 +780,14 @@ PHP_METHOD(HttpMessageBody, addPart) php_http_message_object_t *mobj; zend_error_handling zeh; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zobj, php_http_message_class_entry), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zobj, php_http_message_get_class_entry()), invalid_arg, return); obj = PHP_HTTP_OBJ(NULL, getThis()); mobj = PHP_HTTP_OBJ(NULL, zobj); PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj); - zend_replace_error_handling(EH_THROW, php_http_exception_runtime_class_entry, &zeh); + zend_replace_error_handling(EH_THROW, php_http_get_exception_runtime_class_entry(), &zeh); php_http_message_body_add_part(obj->body, mobj->message); zend_restore_error_handling(&zeh); @@ -874,8 +880,6 @@ static zend_function_entry php_http_message_body_methods[] = { EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_message_body_class_entry; - PHP_MINIT_FUNCTION(http_message_body) { zend_class_entry ce = {0}; diff --git a/src/php_http_message_body.h b/src/php_http_message_body.h index 92353f7..4e224d0 100644 --- a/src/php_http_message_body.h +++ b/src/php_http_message_body.h @@ -60,7 +60,7 @@ typedef struct php_http_message_body_object { zend_object zo; } php_http_message_body_object_t; -PHP_HTTP_API zend_class_entry *php_http_message_body_class_entry; +PHP_HTTP_API zend_class_entry *php_http_get_message_body_class_entry(void); PHP_MINIT_FUNCTION(http_message_body); zend_object *php_http_message_body_object_new(zend_class_entry *ce); diff --git a/src/php_http_message_parser.c b/src/php_http_message_parser.c index 535a2b3..db935d9 100644 --- a/src/php_http_message_parser.c +++ b/src/php_http_message_parser.c @@ -534,7 +534,11 @@ php_http_message_parser_state_t php_http_message_parser_parse(php_http_message_p return php_http_message_parser_state_is(parser); } -zend_class_entry *php_http_message_parser_class_entry; +static zend_class_entry *php_http_message_parser_class_entry; +zend_class_entry *php_http_get_message_parser_class_entry(void) +{ + return php_http_message_parser_class_entry; +} static zend_object_handlers php_http_message_parser_object_handlers; zend_object *php_http_message_parser_object_new(zend_class_entry *ce) @@ -607,7 +611,7 @@ static PHP_METHOD(HttpMessageParser, parse) ZVAL_NULL(zmsg); if (parser_obj->parser->message) { php_http_message_t *msg_cpy = php_http_message_copy(parser_obj->parser->message, NULL); - php_http_message_object_t *msg_obj = php_http_message_object_new_ex(php_http_message_class_entry, msg_cpy); + php_http_message_object_t *msg_obj = php_http_message_object_new_ex(php_http_message_get_class_entry(), msg_cpy); ZVAL_OBJ(zmsg, &msg_obj->zo); } } @@ -627,7 +631,7 @@ static PHP_METHOD(HttpMessageParser, stream) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &zstream, &flags, &zmsg), invalid_arg, return); - zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh); + zend_replace_error_handling(EH_THROW, php_http_get_exception_unexpected_val_class_entry(), &zeh); php_stream_from_zval(s, zstream); zend_restore_error_handling(&zeh); @@ -639,7 +643,7 @@ static PHP_METHOD(HttpMessageParser, stream) ZVAL_NULL(zmsg); if (parser_obj->parser->message) { php_http_message_t *msg_cpy = php_http_message_copy(parser_obj->parser->message, NULL); - php_http_message_object_t *msg_obj = php_http_message_object_new_ex(php_http_message_class_entry, msg_cpy); + php_http_message_object_t *msg_obj = php_http_message_object_new_ex(php_http_message_get_class_entry(), msg_cpy); ZVAL_OBJ(zmsg, &msg_obj->zo); } } diff --git a/src/php_http_message_parser.h b/src/php_http_message_parser.h index fa63858..9b6174d 100644 --- a/src/php_http_message_parser.h +++ b/src/php_http_message_parser.h @@ -60,7 +60,7 @@ typedef struct php_http_message_parser_object { zend_object zo; } php_http_message_parser_object_t; -PHP_HTTP_API zend_class_entry *php_http_message_parser_class_entry; +PHP_HTTP_API zend_class_entry *php_http_get_message_parser_class_entry(void); PHP_MINIT_FUNCTION(http_message_parser); diff --git a/src/php_http_params.c b/src/php_http_params.c index b51ab71..8db5c35 100644 --- a/src/php_http_params.c +++ b/src/php_http_params.c @@ -1027,6 +1027,12 @@ void php_http_params_separator_free(php_http_params_token_t **separator) } } +static zend_class_entry *php_http_params_class_entry; +zend_class_entry *php_http_params_get_class_entry(void) +{ + return php_http_params_class_entry; +} + ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams___construct, 0, 0, 0) ZEND_ARG_INFO(0, params) ZEND_ARG_INFO(0, param_sep) @@ -1043,7 +1049,7 @@ PHP_METHOD(HttpParams, __construct) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!/z/z/z/l", &zparams, ¶m_sep, &arg_sep, &val_sep, &flags), invalid_arg, return); - zend_replace_error_handling(EH_THROW, php_http_exception_runtime_class_entry, &zeh); + zend_replace_error_handling(EH_THROW, php_http_get_exception_runtime_class_entry(), &zeh); { switch (ZEND_NUM_ARGS()) { case 5: @@ -1283,8 +1289,6 @@ static zend_function_entry php_http_params_methods[] = { EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_params_class_entry; - PHP_MINIT_FUNCTION(http_params) { zend_class_entry ce = {0}; diff --git a/src/php_http_params.h b/src/php_http_params.h index b889210..433cf76 100644 --- a/src/php_http_params.h +++ b/src/php_http_params.h @@ -45,7 +45,7 @@ PHP_HTTP_API void php_http_params_separator_free(php_http_params_token_t **separ typedef php_http_object_t php_http_params_object_t; -PHP_HTTP_API zend_class_entry *php_http_params_class_entry; +PHP_HTTP_API zend_class_entry *php_http_params_get_class_entry(void); PHP_MINIT_FUNCTION(http_params); diff --git a/src/php_http_querystring.c b/src/php_http_querystring.c index 5f4eff8..ea84d8d 100644 --- a/src/php_http_querystring.c +++ b/src/php_http_querystring.c @@ -23,6 +23,12 @@ # include #endif +static zend_class_entry *php_http_querystring_class_entry; +zend_class_entry *php_http_querystring_get_class_entry(void) +{ + return php_http_querystring_class_entry; +} + #define QS_MERGE 1 static inline void php_http_querystring_set(zval *instance, zval *params, int flags) @@ -334,7 +340,7 @@ PHP_METHOD(HttpQueryString, __construct) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z", ¶ms), invalid_arg, return); - zend_replace_error_handling(EH_THROW, php_http_exception_bad_querystring_class_entry, &zeh); + zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_querystring_class_entry(), &zeh); php_http_querystring_set(getThis(), params, 0); zend_restore_error_handling(&zeh); } @@ -477,7 +483,7 @@ PHP_METHOD(HttpQueryString, mod) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z", ¶ms), invalid_arg, return); - zend_replace_error_handling(EH_THROW, php_http_exception_bad_querystring_class_entry, &zeh); + zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_querystring_class_entry(), &zeh); ZVAL_OBJ(return_value, Z_OBJ_HT_P(instance)->clone_obj(instance)); /* make sure we do not inherit the reference to _GET */ SEPARATE_ZVAL(zend_read_property(Z_OBJCE_P(return_value), return_value, ZEND_STRL("queryArray"), 0, &qa_tmp)); @@ -655,8 +661,6 @@ PHP_METHOD(HttpQueryString, offsetUnset) zval_ptr_dtor(¶m); } -zend_class_entry *php_http_querystring_class_entry; - static zend_function_entry php_http_querystring_methods[] = { PHP_ME(HttpQueryString, __construct, ai_HttpQueryString___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) diff --git a/src/php_http_querystring.h b/src/php_http_querystring.h index d41b8e9..dc45f31 100644 --- a/src/php_http_querystring.h +++ b/src/php_http_querystring.h @@ -28,7 +28,7 @@ typedef php_http_object_t php_http_querystring_object_t; #define PHP_HTTP_QUERYSTRING_TYPE_ARRAY IS_ARRAY #define PHP_HTTP_QUERYSTRING_TYPE_OBJECT IS_OBJECT -PHP_HTTP_API zend_class_entry *php_http_querystring_class_entry; +PHP_HTTP_API zend_class_entry *php_http_querystring_get_class_entry(void); PHP_MINIT_FUNCTION(http_querystring); diff --git a/src/php_http_url.c b/src/php_http_url.c index 076171e..cce4ba7 100644 --- a/src/php_http_url.c +++ b/src/php_http_url.c @@ -1556,6 +1556,19 @@ php_http_url_t *php_http_url_parse_authority(const char *str, size_t len, unsign return (php_http_url_t *) state; } +static zend_class_entry *php_http_url_class_entry; +static zend_class_entry *php_http_env_url_class_entry; + +zend_class_entry *php_http_url_get_class_entry(void) +{ + return php_http_url_class_entry; +} + +zend_class_entry *php_http_get_env_url_class_entry(void) +{ + return php_http_env_url_class_entry; +} + ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl___construct, 0, 0, 0) ZEND_ARG_INFO(0, old_url) ZEND_ARG_INFO(0, new_url) @@ -1564,12 +1577,17 @@ ZEND_END_ARG_INFO(); PHP_METHOD(HttpUrl, __construct) { zval *new_url = NULL, *old_url = NULL; - zend_long flags = PHP_HTTP_URL_FROM_ENV; + zend_long flags = 0; zend_error_handling zeh; php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!z!l", &old_url, &new_url, &flags), invalid_arg, return); - zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh); + /* always set http\Url::FROM_ENV for instances of http\Env\Url */ + if (instanceof_function(Z_OBJCE_P(getThis()), php_http_env_url_class_entry)) { + flags |= PHP_HTTP_URL_FROM_ENV; + } + + zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh); { php_http_url_t *res_purl, *new_purl = NULL, *old_purl = NULL; @@ -1617,7 +1635,7 @@ PHP_METHOD(HttpUrl, mod) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z!|l", &new_url, &flags), invalid_arg, return); - zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh); + zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh); { php_http_url_t *new_purl = NULL, *old_purl = NULL; @@ -1691,8 +1709,6 @@ static zend_function_entry php_http_url_methods[] = { EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_url_class_entry; - PHP_MINIT_FUNCTION(http_url) { zend_class_entry ce = {0}; @@ -1732,6 +1748,9 @@ PHP_MINIT_FUNCTION(http_url) #endif zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT); + INIT_NS_CLASS_ENTRY(ce, "http\\Env", "Url", php_http_url_methods); + php_http_env_url_class_entry = zend_register_internal_class_ex(&ce, php_http_url_class_entry); + return SUCCESS; } diff --git a/src/php_http_url.h b/src/php_http_url.h index 6ae0ac3..40e98a0 100644 --- a/src/php_http_url.h +++ b/src/php_http_url.h @@ -83,7 +83,8 @@ static inline zend_bool php_http_url_is_empty(const php_http_url_t *url) { return !(url->scheme || url->pass || url->user || url->host || url->port || url->path || url->query || url->fragment); } -PHP_HTTP_API zend_class_entry *php_http_url_class_entry; +PHP_HTTP_API zend_class_entry *php_http_url_get_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_get_env_url_class_entry(void); PHP_MINIT_FUNCTION(http_url); #define php_http_url_object_new php_http_object_new diff --git a/tests/url001.phpt b/tests/url001.phpt index e1bc250..647c7a5 100644 --- a/tests/url001.phpt +++ b/tests/url001.phpt @@ -11,11 +11,12 @@ HTTP_HOST=example.com s=b&i=0&e=&a[]=1&a[]=2 --FILE-- "https", "port" => 443))); -printf("%s\n", new http\Url(array("path" => "/./up/../down/../././//index.php/.", "query" => null), null, http\Url::SANITIZE_PATH|http\Url::FROM_ENV)); -printf("%s\n", new http\Url(null, null, 0)); +printf("%s\n", new http\Env\Url); +printf("%s\n", new http\Env\Url("other", "index")); +printf("%s\n", new http\Env\Url(array("scheme" => "https", "port" => 443))); +printf("%s\n", new http\Env\Url(array("path" => "/./up/../down/../././//index.php/.", "query" => null), null, http\Url::SANITIZE_PATH|http\Url::FROM_ENV)); +printf("%s\n", new http\Env\Url(null, null, 0)); +printf("%s\n", new http\Url(null, null, http\Url::FROM_ENV)); ?> DONE --EXPECTF-- @@ -23,5 +24,6 @@ http://example.com:55555/?s=b&i=0&e=&a[]=1&a[]=2 http://example.com:55555/index?s=b&i=0&e=&a[]=1&a[]=2 https://example.com/?s=b&i=0&e=&a[]=1&a[]=2 http://example.com:55555/index.php/ - +http://example.com:55555/?s=b&i=0&e=&a[]=1&a[]=2 +http://example.com:55555/?s=b&i=0&e=&a[]=1&a[]=2 DONE -- 2.30.2