X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_request_object.c;h=444516f53c450becab9bbdd728ca3c15c0b8697e;hp=f43d3ad3033381ffa207ae11ad4bf1a1c6d440b2;hb=902d195a198f4976c8ff081a95cdd3e315c14f5f;hpb=76a1064dde808801f4988df89521a323661742aa diff --git a/http_request_object.c b/http_request_object.c index f43d3ad..444516f 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -19,26 +19,23 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif - -#ifdef HTTP_HAVE_CURL -# ifdef PHP_WIN32 -# include -# endif -# include -#endif - #include "php.h" +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) + #include "php_http_std_defs.h" #include "php_http_request_object.h" #include "php_http_request_api.h" +#include "php_http_request_pool_api.h" #include "php_http_api.h" #include "php_http_url_api.h" #include "php_http_message_api.h" #include "php_http_message_object.h" -#ifdef ZEND_ENGINE_2 -#ifdef HTTP_HAVE_CURL +#ifdef PHP_WIN32 +# include +#endif +#include #define http_request_object_declare_default_properties() _http_request_object_declare_default_properties(TSRMLS_C) static inline void _http_request_object_declare_default_properties(TSRMLS_D); @@ -156,7 +153,7 @@ zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC) o = ecalloc(1, sizeof(http_request_object)); o->zo.ce = ce; o->ch = curl_easy_init(); - o->attached = 0; + o->pool = NULL; phpstr_init_ex(&o->response, HTTP_CURLBUF_SIZE, 0); @@ -208,7 +205,7 @@ void _http_request_object_free(zend_object *object TSRMLS_DC) STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ptr, http_request_body *body TSRMLS_DC) { zval *meth, *URL, *qdata, *opts; - char *request_uri, *uri; + char *request_uri; STATUS status; if (!body) { @@ -237,16 +234,13 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ } strncat(request_uri, Z_STRVAL_P(qdata), HTTP_URI_MAXLEN - strlen(request_uri)); } - - uri = http_request_copystr(request_uri); - efree(request_uri); switch (Z_LVAL_P(meth)) { case HTTP_GET: case HTTP_HEAD: body->type = -1; - status = http_request_init(obj->ch, Z_LVAL_P(meth), uri, NULL, Z_ARRVAL_P(opts), &obj->response); + status = http_request_init(obj->ch, Z_LVAL_P(meth), request_uri, NULL, Z_ARRVAL_P(opts), &obj->response); break; case HTTP_PUT: @@ -261,7 +255,7 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ body->data = stream; body->size = ssb.sb.st_size; - status = http_request_init(obj->ch, HTTP_PUT, uri, body, Z_ARRVAL_P(opts), &obj->response); + status = http_request_init(obj->ch, HTTP_PUT, request_uri, body, Z_ARRVAL_P(opts), &obj->response); } else { status = FAILURE; } @@ -273,7 +267,7 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ zval *fields = GET_PROP(obj, postFields), *files = GET_PROP(obj, postFiles); if (SUCCESS == (status = http_request_body_fill(body, Z_ARRVAL_P(fields), Z_ARRVAL_P(files)))) { - status = http_request_init(obj->ch, HTTP_POST, uri, body, Z_ARRVAL_P(opts), &obj->response); + status = http_request_init(obj->ch, HTTP_POST, request_uri, body, Z_ARRVAL_P(opts), &obj->response); } } break; @@ -286,24 +280,25 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ body->data = Z_STRVAL_P(post); body->size = Z_STRLEN_P(post); - status = http_request_init(obj->ch, Z_LVAL_P(meth), uri, body, Z_ARRVAL_P(opts), &obj->response); + status = http_request_init(obj->ch, Z_LVAL_P(meth), request_uri, body, Z_ARRVAL_P(opts), &obj->response); } break; } + efree(request_uri); return status; } -STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this_ptr, HashTable *info TSRMLS_DC) +STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this_ptr TSRMLS_DC) { http_message *msg; - + phpstr_fix(&obj->response); if (msg = http_message_parse(PHPSTR_VAL(&obj->response), PHPSTR_LEN(&obj->response))) { char *body; size_t body_len; - zval *headers, *message = GET_PROP(obj, responseMessage), *resp = GET_PROP(obj, responseData); + zval *headers, *message, *resp = GET_PROP(obj, responseData), *info = GET_PROP(obj, responseInfo); UPD_PROP(obj, long, responseCode, msg->info.response.code); @@ -316,22 +311,22 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this add_assoc_zval(resp, "headers", headers); add_assoc_stringl(resp, "body", body, body_len, 0); - //zval_dtor(&message); - Z_TYPE_P(message) = IS_OBJECT; + MAKE_STD_ZVAL(message); + message->type = IS_OBJECT; + message->is_ref = 1; message->value.obj = http_message_object_from_msg(msg); SET_PROP(obj, responseMessage, message); + zval_ptr_dtor(&message); - if (info) { - http_request_info(obj->ch, info); - } + http_request_info(obj->ch, Z_ARRVAL_P(info)); + SET_PROP(obj, responseInfo, info); return SUCCESS; } return FAILURE; } -#endif /* HTTP_HAVE_CURL */ -#endif /* ZEND_ENGINE_2 */ +#endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */ /* * Local variables: