X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=http_message_object.c;h=3853231249f5a4be047f3d4dcaafa9a63b516b4b;hb=6da3520587f9f79c7429501289512d2a2415b517;hp=c5a219f49a303144e1c8f9b333d8a07271f6615b;hpb=8e6cf53b544342e1eaf0ec4f530e32852120294a;p=m6w6%2Fext-http diff --git a/http_message_object.c b/http_message_object.c index c5a219f..3853231 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -21,6 +21,7 @@ #include "zend_interfaces.h" #include "ext/standard/url.h" +#include "php_variables.h" #include "php_http_api.h" #include "php_http_send_api.h" @@ -118,6 +119,7 @@ HTTP_END_ARGS; HTTP_EMPTY_ARGS(getParentMessage); HTTP_EMPTY_ARGS(send); +HTTP_EMPTY_ARGS(__toString); HTTP_BEGIN_ARGS(toString, 0) HTTP_ARG_VAL(include_parent, 0) HTTP_END_ARGS; @@ -194,7 +196,7 @@ zend_function_entry http_message_object_fe[] = { HTTP_MESSAGE_ME(key, ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(next, ZEND_ACC_PUBLIC) - ZEND_MALIAS(HttpMessage, __toString, toString, HTTP_ARGS(HttpMessage, toString), ZEND_ACC_PUBLIC) + ZEND_MALIAS(HttpMessage, __toString, toString, HTTP_ARGS(HttpMessage, __toString), ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(factory, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_MALIAS(HttpMessage, fromString, factory, HTTP_ARGS(HttpMessage, factory), ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) @@ -427,8 +429,13 @@ static zval *_http_message_object_read_prop(zval *object, zval *member, int type } ALLOC_ZVAL(return_value); +#ifdef Z_SET_REFCOUNT + Z_SET_REFCOUNT_P(return_value, 0); + Z_UNSET_ISREF_P(return_value); +#else return_value->refcount = 0; return_value->is_ref = 0; +#endif #ifdef WONKY switch (h) @@ -1235,21 +1242,24 @@ PHP_METHOD(HttpMessage, toMessageTypeObject) #ifdef HTTP_HAVE_CURL int method; char *url; - zval body, *array, *headers, *host = http_message_header(obj->message, "Host"); - php_url hurl, *purl = php_url_parse(obj->message->http.info.request.url); + zval post, body, *array, *headers, *host = http_message_header(obj->message, "Host"); + php_url hurl, *purl = php_url_parse(STR_PTR(obj->message->http.info.request.url)); MAKE_STD_ZVAL(array); array_init(array); memset(&hurl, 0, sizeof(php_url)); - hurl.host = host ? Z_STRVAL_P(host) : NULL; - zval_ptr_dtor(&host); + if (host) { + hurl.host = Z_STRVAL_P(host); + zval_ptr_dtor(&host); + } http_build_url(HTTP_URL_REPLACE, purl, &hurl, NULL, &url, NULL); php_url_free(purl); add_assoc_string(array, "url", url, 0); - if ( (method = http_request_method_exists(1, 0, obj->message->http.info.request.method)) || - (method = http_request_method_register(obj->message->http.info.request.method, strlen(obj->message->http.info.request.method)))) { + if ( obj->message->http.info.request.method && + ((method = http_request_method_exists(1, 0, obj->message->http.info.request.method)) || + (method = http_request_method_register(obj->message->http.info.request.method, strlen(obj->message->http.info.request.method))))) { add_assoc_long(array, "method", method); } @@ -1266,9 +1276,20 @@ PHP_METHOD(HttpMessage, toMessageTypeObject) zend_call_method_with_1_params(&return_value, http_request_object_ce, NULL, "setoptions", NULL, array); zval_ptr_dtor(&array); - INIT_PZVAL(&body); - ZVAL_STRINGL(&body, PHPSTR_VAL(obj->message), PHPSTR_LEN(obj->message), 0); - zend_call_method_with_1_params(&return_value, http_request_object_ce, NULL, "setrawpostdata", NULL, &body); + if (PHPSTR_VAL(obj->message) && PHPSTR_LEN(obj->message)) { + INIT_PZVAL(&body); + ZVAL_STRINGL(&body, PHPSTR_VAL(obj->message), PHPSTR_LEN(obj->message), 0); + if (method != HTTP_POST) { + zend_call_method_with_1_params(&return_value, http_request_object_ce, NULL, "setbody", NULL, &body); + } else { + INIT_PZVAL(&post); + array_init(&post); + + zval_copy_ctor(&body); + sapi_module.treat_data(PARSE_STRING, Z_STRVAL(body), &post TSRMLS_CC); + zend_call_method_with_1_params(&return_value, http_request_object_ce, NULL, "setpostfields", NULL, &post); + } + } #else http_error(HE_WARNING, HTTP_E_RUNTIME, "Cannot transform HttpMessage to HttpRequest (missing curl support)"); #endif @@ -1479,16 +1500,18 @@ PHP_METHOD(HttpMessage, next) { NO_ARGS { getObject(http_message_object, obj); - getObjectEx(http_message_object, itr, obj->iterator); - - if (itr && itr->parent.handle) { - zval *old = obj->iterator; - MAKE_STD_ZVAL(obj->iterator); - ZVAL_OBJVAL(obj->iterator, itr->parent, 1); - zval_ptr_dtor(&old); - } else { - zval_ptr_dtor(&obj->iterator); - obj->iterator = NULL; + if (obj->iterator) { + getObjectEx(http_message_object, itr, obj->iterator); + + if (itr && itr->parent.handle) { + zval *old = obj->iterator; + MAKE_STD_ZVAL(obj->iterator); + ZVAL_OBJVAL(obj->iterator, itr->parent, 1); + zval_ptr_dtor(&old); + } else { + zval_ptr_dtor(&obj->iterator); + obj->iterator = NULL; + } } } }