X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_request_api.c;h=00f4b9d48d6fb7e1d28dc05b1a820efa72191605;hb=08bec19979c75a45978c7c7a7c6d7926a9d5322e;hp=f7d308997f653d71275938f494cbb57bbd758d23;hpb=960586b99568624a207faa24fe56233582b6d0dc;p=m6w6%2Fext-http diff --git a/http_request_api.c b/http_request_api.c index f7d3089..00f4b9d 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2005, Michael Wallner | + | Copyright (c) 2004-2006, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -239,10 +239,10 @@ PHP_HTTP_API void _http_request_dtor(http_request *request) if (request->ch) { /* avoid nasty segfaults with already cleaned up callbacks */ - curl_easy_setopt(request->ch, CURLOPT_NOPROGRESS, 1); - curl_easy_setopt(request->ch, CURLOPT_PROGRESSFUNCTION, NULL); - curl_easy_setopt(request->ch, CURLOPT_VERBOSE, 0); - curl_easy_setopt(request->ch, CURLOPT_DEBUGFUNCTION, NULL); + HTTP_CURL_OPT(NOPROGRESS, 1); + HTTP_CURL_OPT(PROGRESSFUNCTION, NULL); + HTTP_CURL_OPT(VERBOSE, 0); + HTTP_CURL_OPT(DEBUGFUNCTION, NULL); curl_easy_cleanup(request->ch); request->ch = NULL; } @@ -326,6 +326,9 @@ PHP_HTTP_API void _http_request_defaults(http_request *request) HTTP_CURL_OPT(USERAGENT, "PECL::HTTP/" PHP_EXT_HTTP_VERSION " (PHP/" PHP_VERSION ")"); HTTP_CURL_OPT(HTTPHEADER, NULL); HTTP_CURL_OPT(COOKIE, NULL); +#if LIBCURL_VERSION_NUM >= 0x070e01 + HTTP_CURL_OPT(COOKIELIST, NULL); +#endif HTTP_CURL_OPT(COOKIEFILE, NULL); HTTP_CURL_OPT(COOKIEJAR, NULL); HTTP_CURL_OPT(RESUME_FROM, 0); @@ -355,6 +358,7 @@ PHP_HTTP_API void _http_request_defaults(http_request *request) HTTP_CURL_OPT(IOCTLDATA, NULL); HTTP_CURL_OPT(READDATA, NULL); HTTP_CURL_OPT(INFILESIZE, 0); + HTTP_CURL_OPT(HTTP_VERSION, CURL_HTTP_VERSION_NONE); } } /* }}} */ @@ -366,10 +370,16 @@ PHP_HTTP_API void _http_request_set_progress_callback(http_request *request, zva if (request->_progress_callback) { zval_ptr_dtor(&request->_progress_callback); } - if (cb) { + if ((request->_progress_callback = cb)) { ZVAL_ADDREF(cb); + HTTP_CURL_OPT(NOPROGRESS, 0); + HTTP_CURL_OPT(PROGRESSDATA, request); + HTTP_CURL_OPT(PROGRESSFUNCTION, http_curl_progress_callback); + } else { + HTTP_CURL_OPT(NOPROGRESS, 1); + HTTP_CURL_OPT(PROGRESSDATA, NULL); + HTTP_CURL_OPT(PROGRESSFUNCTION, NULL); } - request->_progress_callback = cb; } /* {{{ STATUS http_request_prepare(http_request *, HashTable *) */ @@ -389,10 +399,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti HTTP_CURL_OPT(URL, request->url); /* progress callback */ - if ((zoption = http_request_option(request, options, "onprogress", 0))) { - HTTP_CURL_OPT(NOPROGRESS, 0); - HTTP_CURL_OPT(PROGRESSDATA, request); - HTTP_CURL_OPT(PROGRESSFUNCTION, http_curl_progress_callback); + if ((zoption = http_request_option(request, options, "onprogress", -1))) { http_request_set_progress_callback(request, zoption); } @@ -479,7 +486,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti } } if ((zoption = http_request_option(request, options, "compress", IS_BOOL)) && Z_LVAL_P(zoption)) { - request->_cache.headers = curl_slist_append(request->_cache.headers, "Accept-Encoding: gzip;q=1.0,deflate;q=0.5,*;q=0.1"); + request->_cache.headers = curl_slist_append(request->_cache.headers, "Accept-Encoding: gzip;q=1.0,deflate;q=0.5"); } HTTP_CURL_OPT(HTTPHEADER, request->_cache.headers); @@ -492,7 +499,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti } } -#if LIBCURL_VERSION_NUM >= 0x070f01 +#if LIBCURL_VERSION_NUM >= 0x070e01 /* reset cookies */ if ((zoption = http_request_option(request, options, "resetcookies", IS_BOOL)) && Z_LVAL_P(zoption)) { HTTP_CURL_OPT(COOKIELIST, "ALL"); @@ -528,6 +535,11 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti HTTP_CURL_OPT(MAXFILESIZE, Z_LVAL_P(zoption)); } + /* http protocol */ + if ((zoption = http_request_option(request, options, "protocol", IS_LONG))) { + HTTP_CURL_OPT(HTTP_VERSION, Z_LVAL_P(zoption)); + } + /* lastmodified */ if ((zoption = http_request_option(request, options, "lastmodified", IS_LONG))) { if (Z_LVAL_P(zoption)) { @@ -591,24 +603,24 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti switch (request->meth) { case HTTP_GET: - curl_easy_setopt(request->ch, CURLOPT_HTTPGET, 1); + HTTP_CURL_OPT(HTTPGET, 1); break; case HTTP_HEAD: - curl_easy_setopt(request->ch, CURLOPT_NOBODY, 1); + HTTP_CURL_OPT(NOBODY, 1); break; case HTTP_POST: - curl_easy_setopt(request->ch, CURLOPT_POST, 1); + HTTP_CURL_OPT(POST, 1); break; case HTTP_PUT: - curl_easy_setopt(request->ch, CURLOPT_UPLOAD, 1); + HTTP_CURL_OPT(UPLOAD, 1); break; default: if (http_request_method_exists(0, request->meth, NULL)) { - curl_easy_setopt(request->ch, CURLOPT_CUSTOMREQUEST, http_request_method_name(request->meth)); + HTTP_CURL_OPT(CUSTOMREQUEST, http_request_method_name(request->meth)); } else { http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Unsupported request method: %d (%s)", request->meth, request->url); return FAILURE; @@ -617,22 +629,22 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti } /* attach request body */ - if (request->body && (request->meth != HTTP_GET) && (request->meth != HTTP_HEAD)) { + if (request->body && (request->meth != HTTP_GET) && (request->meth != HTTP_HEAD) && (request->meth != HTTP_OPTIONS)) { switch (request->body->type) { case HTTP_REQUEST_BODY_CSTRING: - curl_easy_setopt(request->ch, CURLOPT_POSTFIELDS, request->body->data); - curl_easy_setopt(request->ch, CURLOPT_POSTFIELDSIZE, request->body->size); + HTTP_CURL_OPT(POSTFIELDS, request->body->data); + HTTP_CURL_OPT(POSTFIELDSIZE, request->body->size); break; case HTTP_REQUEST_BODY_CURLPOST: - curl_easy_setopt(request->ch, CURLOPT_HTTPPOST, (struct curl_httppost *) request->body->data); + HTTP_CURL_OPT(HTTPPOST, (struct curl_httppost *) request->body->data); break; case HTTP_REQUEST_BODY_UPLOADFILE: - curl_easy_setopt(request->ch, CURLOPT_IOCTLDATA, request); - curl_easy_setopt(request->ch, CURLOPT_READDATA, request); - curl_easy_setopt(request->ch, CURLOPT_INFILESIZE, request->body->size); + HTTP_CURL_OPT(IOCTLDATA, request); + HTTP_CURL_OPT(READDATA, request); + HTTP_CURL_OPT(INFILESIZE, request->body->size); break; default: @@ -713,30 +725,26 @@ static size_t http_curl_read_callback(void *data, size_t len, size_t n, void *ct /* {{{ static int http_curl_progress_callback(void *, double, double, double, double) */ static int http_curl_progress_callback(void *ctx, double dltotal, double dlnow, double ultotal, double ulnow) { - int rc; - zval *params_pass[4], params_local[4], retval; + zval *param, retval; http_request *request = (http_request *) ctx; TSRMLS_FETCH_FROM_CTX(request->tsrm_ls); - params_pass[0] = ¶ms_local[0]; - params_pass[1] = ¶ms_local[1]; - params_pass[2] = ¶ms_local[2]; - params_pass[3] = ¶ms_local[3]; - - INIT_PZVAL(params_pass[0]); - INIT_PZVAL(params_pass[1]); - INIT_PZVAL(params_pass[2]); - INIT_PZVAL(params_pass[3]); - ZVAL_DOUBLE(params_pass[0], dltotal); - ZVAL_DOUBLE(params_pass[1], dlnow); - ZVAL_DOUBLE(params_pass[2], ultotal); - ZVAL_DOUBLE(params_pass[3], ulnow); - INIT_PZVAL(&retval); ZVAL_NULL(&retval); - rc = call_user_function(EG(function_table), NULL, request->_progress_callback, &retval, 4, params_pass TSRMLS_CC); + + MAKE_STD_ZVAL(param); + array_init(param); + add_assoc_double(param, "dltotal", dltotal); + add_assoc_double(param, "dlnow", dlnow); + add_assoc_double(param, "ultotal", ultotal); + add_assoc_double(param, "ulnow", ulnow); + + call_user_function(EG(function_table), NULL, request->_progress_callback, &retval, 1, ¶m TSRMLS_CC); + + zval_ptr_dtor(¶m); zval_dtor(&retval); - return rc; + + return 0; } /* }}} */ @@ -935,7 +943,7 @@ static int http_ssl_mutex_unlock(void **m) } static struct gcry_thread_cbs http_gnutls_tsl = { - GCRY_THREAD_OPTIONS_USER, + GCRY_THREAD_OPTION_USER, NULL, http_ssl_mutex_create, http_ssl_mutex_destroy,