X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_request_api.c;h=d6a370481dbe2da6cb0c90cbb9e276f7f8f50d6d;hb=dd199f9961262ed43fa544240df15a9d6d7d0f08;hp=1addfd96d0b418cd0a8d33a0e3ccc4a85aea57e4;hpb=2f39230d83bdf816dcae52c7e5a1b019347f0e7b;p=m6w6%2Fext-http diff --git a/http_request_api.c b/http_request_api.c index 1addfd9..d6a3704 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -420,6 +420,32 @@ PHP_HTTP_API void _http_request_reset(http_request *request) } /* }}} */ +/* {{{ STATUS http_request_enable_cookies(http_request *) */ +PHP_HTTP_API STATUS _http_request_enable_cookies(http_request *request) +{ + TSRMLS_FETCH_FROM_CTX(request->tsrm_ls); + if (CURLE_OK == curl_easy_setopt(request->ch, CURLOPT_COOKIEFILE, "")) { + return SUCCESS; + } + http_error(HE_WARNING, HTTP_E_REQUEST, "Could not enable cookies for this session"); + return FAILURE; +} +/* }}} */ + +/* {{{ STATUS http_request_reset_cookies(http_request *) */ +PHP_HTTP_API STATUS _http_request_reset_cookies(http_request *request) +{ + TSRMLS_FETCH_FROM_CTX(request->tsrm_ls); +#if HTTP_CURL_VERSION(7,14,1) + if (CURLE_OK == curl_easy_setopt(request->ch, CURLOPT_COOKIELIST, "ALL")) { + return SUCCESS; + } +#endif + http_error(HE_WARNING, HTTP_E_REQUEST, "Could not reset cookies"); + return FAILURE; +} +/* }}} */ + /* {{{ void http_request_defaults(http_request *) */ PHP_HTTP_API void _http_request_defaults(http_request *request) { @@ -450,8 +476,6 @@ PHP_HTTP_API void _http_request_defaults(http_request *request) #if HTTP_CURL_VERSION(7,14,1) HTTP_CURL_OPT(CURLOPT_COOKIELIST, NULL); #endif - HTTP_CURL_OPT(CURLOPT_COOKIEFILE, NULL); - HTTP_CURL_OPT(CURLOPT_COOKIEJAR, NULL); HTTP_CURL_OPT(CURLOPT_RANGE, NULL); HTTP_CURL_OPT(CURLOPT_RESUME_FROM, 0); HTTP_CURL_OPT(CURLOPT_MAXFILESIZE, 0); @@ -757,27 +781,16 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti } } -#if HTTP_CURL_VERSION(7,14,1) - /* reset cookies */ - if ((zoption = http_request_option(request, options, "resetcookies", IS_BOOL)) && Z_LVAL_P(zoption)) { - HTTP_CURL_OPT(CURLOPT_COOKIELIST, "ALL"); - } -#endif - - /* session cookies */ - if ((zoption = http_request_option(request, options, "cookiesession", IS_BOOL))) { - if (Z_LVAL_P(zoption)) { - /* accept cookies for this session */ - HTTP_CURL_OPT(CURLOPT_COOKIEFILE, ""); - } else { - /* reset session cookies */ - HTTP_CURL_OPT(CURLOPT_COOKIESESSION, 1); - } + /* don't load session cookies from cookiestore */ + if ((zoption = http_request_option(request, options, "cookiesession", IS_BOOL)) && Z_BVAL_P(zoption)) { + HTTP_CURL_OPT(CURLOPT_COOKIESESSION, 1); } /* cookiestore, read initial cookies from that file and store cookies back into that file */ - if ((zoption = http_request_option(request, options, "cookiestore", IS_STRING)) && Z_STRLEN_P(zoption)) { - HTTP_CHECK_OPEN_BASEDIR(Z_STRVAL_P(zoption), return FAILURE); + if ((zoption = http_request_option(request, options, "cookiestore", IS_STRING))) { + if (Z_STRLEN_P(zoption)) { + HTTP_CHECK_OPEN_BASEDIR(Z_STRVAL_P(zoption), return FAILURE); + } HTTP_CURL_OPT(CURLOPT_COOKIEFILE, Z_STRVAL_P(zoption)); HTTP_CURL_OPT(CURLOPT_COOKIEJAR, Z_STRVAL_P(zoption)); }