From: Michael Wallner Date: Sun, 12 Jun 2005 15:48:13 +0000 (+0000) Subject: - typos & allow passing NULL as curl handle in http_request() again' X-Git-Tag: RELEASE_0_9_0~34 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=68142ac3f4879edac62d5a43c479721ae71ea014;ds=sidebyside - typos & allow passing NULL as curl handle in http_request() again' --- diff --git a/http_request_api.c b/http_request_api.c index 4cf6834..eb4d627 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -702,10 +702,23 @@ PHP_HTTP_API void _http_request_info(CURL *ch, HashTable *info TSRMLS_DC) /* {{{ STATUS http_request_ex(CURL *, http_request_method, char *, http_request_body, HashTable, HashTable, phpstr *) */ PHP_HTTP_API STATUS _http_request_ex(CURL *ch, http_request_method meth, const char *url, http_request_body *body, HashTable *options, HashTable *info, phpstr *response TSRMLS_DC) { - if (SUCCESS != http_request_init(ch, meth, url, body, options, response)) { - return FAILURE; + STATUS status; + zend_bool clean_curl; + + if ((clean_curl = (!ch))) { + if (!(ch = curl_easy_init())) { + http_error(E_WARNING, HTTP_E_CURL, "Could not initialize curl."); + return FAILURE; + } } - return http_request_exec(ch, info); + + status = ((SUCCESS == http_request_init(ch, meth, url, body, options, response)) && + (SUCCESS == http_request_exec(ch, info))) ? SUCCESS : FAILURE; + + if (clean_curl) { + curl_easy_cleanup(ch); + } + return status; } /* }}} */ @@ -846,7 +859,6 @@ PHP_HTTP_API STATUS _http_request_pool_attach(http_request_pool *pool, zval *req zval *info = GET_PROP_EX(req, request, responseInfo); if (SUCCESS != http_request_object_requesthandler(req, request, body)) { - efree(body); http_error_ex(E_WARNING, HTTP_E_CURL, "Could not initialize HttpRequest object for attaching to the HttpRequestPool"); } else if (CURLM_OK != (code = curl_multi_add_handle(pool->ch, req->ch))) { http_error_ex(E_WARNING, HTTP_E_CURL, "Could not attach HttpRequest object to the HttpRequestPool: %s", curl_multi_strerror(code)); @@ -857,6 +869,7 @@ PHP_HTTP_API STATUS _http_request_pool_attach(http_request_pool *pool, zval *req zend_llist_add_element(&pool->bodies, &body); return SUCCESS; } + efree(body); } return FAILURE; } @@ -870,7 +883,7 @@ PHP_HTTP_API STATUS _http_request_pool_detach(http_request_pool *pool, zval *req fprintf(stderr, "Detaching request %p (pool: %p) from pool %p\n", req, req->pool, pool); #endif if (req->pool != pool) { - http_error_ex(E_WARNING, HTTP_E_CURL, "HttpRequest object is not attached to this HttpRequestPool (%p != %p)", req->pool, pool); + http_error(E_WARNING, HTTP_E_CURL, "HttpRequest object is not attached to this HttpRequestPool"); } else { CURLMcode code; diff --git a/php_http_request_api.h b/php_http_request_api.h index 194a12e..4b642e4 100644 --- a/php_http_request_api.h +++ b/php_http_request_api.h @@ -92,7 +92,7 @@ extern void _http_request_data_free_string(void *string); extern void _http_request_data_free_slist(void *list); #define http_request_pool_responsehandler _http_request_pool_responsehandler -extern void http_request_pool_responsehandler(zval **req TSRMLS_DC); +extern void _http_request_pool_responsehandler(zval **req TSRMLS_DC); #define http_request_global_init _http_request_global_init extern STATUS _http_request_global_init(void);