From: Michael Wallner Date: Sat, 7 Jan 2006 18:46:38 +0000 (+0000) Subject: - clarify http_curl_init(), it cannot be used with anything else than http_request X-Git-Tag: RELEASE_1_0_4~9 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=1db2ac7587e2c201b2b0534c385fbb833788a335;p=m6w6%2Fext-http - clarify http_curl_init(), it cannot be used with anything else than http_request - move http_request_defaults() to http_curl_init() --- diff --git a/http_request_api.c b/http_request_api.c index 440eacd..8c11249 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -211,7 +211,7 @@ static curlioerr http_curl_ioctl_callback(CURL *, curliocmd, void *); /* }}} */ /* {{{ CURL *http_curl_init(http_request *) */ -PHP_HTTP_API CURL * _http_curl_init_ex(CURL *ch, void *context, char *error_buffer) +PHP_HTTP_API CURL * _http_curl_init_ex(CURL *ch, http_request *request) { if (ch || (ch = curl_easy_init())) { #if defined(ZTS) @@ -226,9 +226,18 @@ PHP_HTTP_API CURL * _http_curl_init_ex(CURL *ch, void *context, char *error_buff HTTP_CURL_OPT_EX(ch, READFUNCTION, http_curl_read_callback); HTTP_CURL_OPT_EX(ch, IOCTLFUNCTION, http_curl_ioctl_callback); HTTP_CURL_OPT_EX(ch, WRITEFUNCTION, http_curl_dummy_callback); - HTTP_CURL_OPT_EX(ch, DEBUGDATA, context); - HTTP_CURL_OPT_EX(ch, PRIVATE, context); - HTTP_CURL_OPT_EX(ch, ERRORBUFFER, error_buffer); + + /* set context */ + if (request) { + HTTP_CURL_OPT_EX(ch, PRIVATE, request); + HTTP_CURL_OPT_EX(ch, DEBUGDATA, request); + HTTP_CURL_OPT_EX(ch, ERRORBUFFER, request->_error); + + /* attach curl handle */ + request->ch = ch; + /* set defaults (also in http_request_reset()) */ + http_request_defaults(request); + } } return ch; @@ -414,7 +423,6 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti TSRMLS_FETCH_FROM_CTX(request->tsrm_ls); HTTP_CHECK_CURL_INIT(request->ch, http_curl_init(request), return FAILURE); - http_request_defaults(request); /* set options */ HTTP_CURL_OPT(URL, request->url); @@ -478,6 +486,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti /* useragent, default "PECL::HTTP/version (PHP/version)" */ if ((zoption = http_request_option(request, options, "useragent", IS_STRING))) { + /* allow to send no user agent, not even default one */ if (Z_STRLEN_P(zoption)) { HTTP_CURL_OPT(USERAGENT, Z_STRVAL_P(zoption)); } else { diff --git a/http_request_object.c b/http_request_object.c index 74dbe4f..60c79dd 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -339,7 +339,7 @@ zend_object_value _http_request_object_clone_obj(zval *this_ptr TSRMLS_DC) old_zo = zend_objects_get_address(this_ptr TSRMLS_CC); new_ov = http_request_object_new_ex(old_zo->ce, NULL, &new_obj); if (old_obj->request->ch) { - new_obj->request->ch = http_curl_init_ex(curl_easy_duphandle(old_obj->request->ch), new_obj->request, new_obj->request->_error); + http_curl_init_ex(curl_easy_duphandle(old_obj->request->ch), new_obj->request); } zend_objects_clone_members(&new_obj->zo, new_ov, old_zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC); diff --git a/php_http_request_api.h b/php_http_request_api.h index 28e3a85..16523f6 100644 --- a/php_http_request_api.h +++ b/php_http_request_api.h @@ -50,9 +50,9 @@ typedef struct { } http_request; -#define http_curl_init(r) http_curl_init_ex(NULL, (r), (r)->_error) -#define http_curl_init_ex(c, r, e) _http_curl_init_ex((c), (r), (e)) -PHP_HTTP_API CURL *_http_curl_init_ex(CURL *ch, void *context, char *error_buffer); +#define http_curl_init(r) http_curl_init_ex(NULL, (r)) +#define http_curl_init_ex(c, r) _http_curl_init_ex((c), (r)) +PHP_HTTP_API CURL *_http_curl_init_ex(CURL *ch, http_request *request); #define http_curl_free(c) _http_curl_free(c) PHP_HTTP_API void _http_curl_free(CURL **ch);