CRYPTO_set_id_callback(http_openssl_thread_id);
CRYPTO_set_locking_callback(http_openssl_thread_lock);
#endif
-#ifdef HTTP_NED_GNUTLS_TSL
+#ifdef HTTP_NEED_GNUTLS_TSL
gcry_control(GCRYCTL_SET_THREAD_CBS, &http_gnutls_tsl);
#endif
}
#define HTTP_CURL_OPT_LONG_EX(keyname, optname) \
if (!strcasecmp(key, keyname)) { \
- zval *copy = http_request_option_cache_ex(request, keyname, strlen(keyname)+1, 0, zval_copy(IS_LONG, *param)); \
+ zval *copy = zval_copy(IS_LONG, *param); \
HTTP_CURL_OPT(optname, Z_LVAL_P(copy)); \
key = NULL; \
+ zval_free(©); \
continue; \
}
/* }}} */
/* {{{ void http_request_dtor(http_request *) */
PHP_HTTP_API void _http_request_dtor(http_request *request)
{
- TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
-
http_curl_free(&request->ch);
http_request_reset(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)
{
#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);
PHP_HTTP_API void _http_request_set_progress_callback(http_request *request, zval *cb)
{
- TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
-
if (request->_progress_callback) {
zval_ptr_dtor(&request->_progress_callback);
}
}
}
-#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));
}
}
/* request method */
- switch (request->meth)
- {
+ switch (request->meth) {
case HTTP_GET:
HTTP_CURL_OPT(CURLOPT_HTTPGET, 1);
- break;
+ break;
case HTTP_HEAD:
HTTP_CURL_OPT(CURLOPT_NOBODY, 1);
- break;
+ break;
case HTTP_POST:
HTTP_CURL_OPT(CURLOPT_POST, 1);
- break;
+ break;
case HTTP_PUT:
HTTP_CURL_OPT(CURLOPT_UPLOAD, 1);
- break;
+ break;
default:
if (http_request_method_exists(0, request->meth, NULL)) {
http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Unsupported request method: %d (%s)", request->meth, request->url);
return FAILURE;
}
- break;
+ break;
}
/* attach request body */
if (request->body && (request->meth != HTTP_GET) && (request->meth != HTTP_HEAD) && (request->meth != HTTP_OPTIONS)) {
- switch (request->body->type)
- {
+ switch (request->body->type) {
case HTTP_REQUEST_BODY_EMPTY:
/* nothing */
- break;
+ break;
case HTTP_REQUEST_BODY_CURLPOST:
HTTP_CURL_OPT(CURLOPT_HTTPPOST, (struct curl_httppost *) request->body->data);
- break;
+ break;
case HTTP_REQUEST_BODY_CSTRING:
if (request->meth != HTTP_PUT) {
HTTP_CURL_OPT(CURLOPT_IOCTLDATA, request);
HTTP_CURL_OPT(CURLOPT_READDATA, request);
HTTP_CURL_OPT(CURLOPT_INFILESIZE, request->body->size);
- break;
+ break;
default:
/* shouldn't ever happen */
http_error_ex(HE_ERROR, 0, "Unknown request body type: %d (%s)", request->body->type, request->url);
return FAILURE;
- break;
}
}
TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
if (request->body) {
- switch (request->body->type)
- {
+ switch (request->body->type) {
case HTTP_REQUEST_BODY_CSTRING:
{
size_t out = MIN(len * n, request->body->size - request->body->priv);
request->body->priv += out;
return out;
}
+ break;
}
- break;
case HTTP_REQUEST_BODY_UPLOADFILE:
return php_stream_read((php_stream *) request->body->data, data, len * n);
- break;
}
}
return 0;
}
if (request->body) {
- switch (request->body->type)
- {
+ switch (request->body->type) {
case HTTP_REQUEST_BODY_CSTRING:
request->body->priv = 0;
return CURLIOE_OK;
- break;
+ break;
case HTTP_REQUEST_BODY_UPLOADFILE:
if (SUCCESS == php_stream_rewind((php_stream *) request->body->data)) {
return CURLIOE_OK;
}
- break;
+ break;
}
}
{
http_request *request = (http_request *) ctx;
- switch (type)
- {
+ switch (type) {
case CURLINFO_DATA_IN:
if (request->conv.last_type == CURLINFO_HEADER_IN) {
phpstr_appends(&request->conv.response, HTTP_CRLF);
}
case CURLINFO_HEADER_IN:
phpstr_append(&request->conv.response, data, length);
- break;
+ break;
case CURLINFO_DATA_OUT:
if (request->conv.last_type == CURLINFO_HEADER_OUT) {
phpstr_appends(&request->conv.request, HTTP_CRLF);
}
case CURLINFO_HEADER_OUT:
phpstr_append(&request->conv.request, data, length);
- break;
+ break;
default:
#if 0
fprintf(stderr, "## ", type);
fprintf(stderr, "\n");
}
#endif
- break;
+ break;
}
if (type) {