# include "php_http_request_object.h"
#endif
-/* {{{ cruft for thread safe SSL crypto locks */
-#if defined(ZTS) && defined(HTTP_HAVE_SSL)
-# ifdef PHP_WIN32
-# define HTTP_NEED_OPENSSL_TSL
-# include <openssl/crypto.h>
-# else /* !PHP_WIN32 */
-# if defined(HTTP_HAVE_OPENSSL)
-# if defined(HAVE_OPENSSL_CRYPTO_H)
-# define HTTP_NEED_OPENSSL_TSL
-# include <openssl/crypto.h>
-# else
-# warning \
- "libcurl was compiled with OpenSSL support, but configure could not find " \
- "openssl/crypto.h; thus no SSL crypto locking callbacks will be set, which may " \
- "cause random crashes on SSL requests"
-# endif
-# elif defined(HTTP_HAVE_GNUTLS)
-# if defined(HAVE_GCRYPT_H)
-# define HTTP_NEED_GNUTLS_TSL
-# include <gcrypt.h>
-# else
-# warning \
- "libcurl was compiled with GnuTLS support, but configure could not find " \
- "gcrypt.h; thus no SSL crypto locking callbacks will be set, which may " \
- "cause random crashes on SSL requests"
-# endif
-# else
-# warning \
- "libcurl was compiled with SSL support, but configure could not determine which" \
- "library was used; thus no SSL crypto locking callbacks will be set, which may " \
- "cause random crashes on SSL requests"
-# endif /* HTTP_HAVE_OPENSSL || HTTP_HAVE_GNUTLS */
-# endif /* PHP_WIN32 */
-#endif /* ZTS && HTTP_HAVE_SSL */
+#include "php_http_request_int.h"
+/* {{{ cruft for thread safe SSL crypto locks */
#ifdef HTTP_NEED_OPENSSL_TSL
static MUTEX_T *http_openssl_tsl = NULL;
}
/* }}} */
-/* {{{ MACROS */
-#ifndef HAVE_CURL_EASY_STRERROR
-# define curl_easy_strerror(dummy) "unknown error"
-#endif
-
-#define HTTP_CURL_INFO(I) \
- { \
- char *N = #I; \
- HTTP_CURL_INFO_EX(I, N+lenof("CURLINFO_")); \
- }
-#define HTTP_CURL_INFO_EX(I, X) \
- switch (I & ~CURLINFO_MASK) \
- { \
- case CURLINFO_STRING: \
- { \
- char *c; \
- if (CURLE_OK == curl_easy_getinfo(request->ch, I, &c)) { \
- char *key = estrndup(X, strlen(X)); \
- add_assoc_string(&array, pretty_key(key, strlen(X), 0, 0), c ? c : "", 1); \
- efree(key); \
- } \
- } \
- break; \
-\
- case CURLINFO_DOUBLE: \
- { \
- double d; \
- if (CURLE_OK == curl_easy_getinfo(request->ch, I, &d)) { \
- char *key = estrndup(X, strlen(X)); \
- add_assoc_double(&array, pretty_key(key, strlen(X), 0, 0), d); \
- efree(key); \
- } \
- } \
- break; \
-\
- case CURLINFO_LONG: \
- { \
- long l; \
- if (CURLE_OK == curl_easy_getinfo(request->ch, I, &l)) { \
- char *key = estrndup(X, strlen(X)); \
- add_assoc_long(&array, pretty_key(key, strlen(X), 0, 0), l); \
- efree(key); \
- } \
- } \
- break; \
-\
- case CURLINFO_SLIST: \
- { \
- struct curl_slist *l, *p; \
- if (CURLE_OK == curl_easy_getinfo(request->ch, I, &l)) { \
- zval *subarray; \
- char *key = estrndup(X, strlen(X)); \
- MAKE_STD_ZVAL(subarray); \
- array_init(subarray); \
- for (p = l; p; p = p->next) { \
- add_next_index_string(subarray, p->data, 1); \
- } \
- add_assoc_zval(&array, pretty_key(key, strlen(X), 0, 0), subarray); \
- curl_slist_free_all(l); \
- efree(key); \
- } \
- } \
- }
-
-#define HTTP_CURL_OPT(OPTION, p) HTTP_CURL_OPT_EX(request->ch, OPTION, (p))
-#define HTTP_CURL_OPT_EX(ch, OPTION, p) curl_easy_setopt((ch), OPTION, (p))
-
-#define HTTP_CURL_OPT_STRING(OPTION, ldiff, obdc) \
- { \
- char *K = #OPTION; \
- HTTP_CURL_OPT_STRING_EX(K+lenof("CURLOPT_KEY")+ldiff, OPTION, obdc); \
- }
-#define HTTP_CURL_OPT_STRING_EX(keyname, optname, obdc) \
- if (!strcasecmp(key, keyname)) { \
- zval *copy = http_request_option_cache_ex(request, keyname, strlen(keyname)+1, 0, zval_copy(IS_STRING, *param)); \
- if (obdc) { \
- HTTP_CHECK_OPEN_BASEDIR(Z_STRVAL_P(copy), return FAILURE); \
- } \
- HTTP_CURL_OPT(optname, Z_STRVAL_P(copy)); \
- key = NULL; \
- continue; \
- }
-#define HTTP_CURL_OPT_LONG(OPTION, ldiff) \
- { \
- char *K = #OPTION; \
- HTTP_CURL_OPT_LONG_EX(K+lenof("CURLOPT_KEY")+ldiff, OPTION); \
- }
-#define HTTP_CURL_OPT_LONG_EX(keyname, optname) \
- if (!strcasecmp(key, keyname)) { \
- zval *copy = zval_copy(IS_LONG, *param); \
- HTTP_CURL_OPT(optname, Z_LVAL_P(copy)); \
- key = NULL; \
- zval_free(©); \
- continue; \
- }
-/* }}} */
-
/* {{{ forward declarations */
#define http_request_option(r, o, k, t) _http_request_option_ex((r), (o), (k), sizeof(k), (t) TSRMLS_CC)
#define http_request_option_ex(r, o, k, l, t) _http_request_option_ex((r), (o), (k), (l), (t) TSRMLS_CC)
/* {{{ STATUS http_request_enable_cookies(http_request *) */
PHP_HTTP_API STATUS _http_request_enable_cookies(http_request *request)
{
+ int initialized = 1;
TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
- if (CURLE_OK == curl_easy_setopt(request->ch, CURLOPT_COOKIEFILE, "")) {
+
+ HTTP_CHECK_CURL_INIT(request->ch, http_curl_init_ex(request->ch, request), initialized = 0);
+ if (initialized) {
+ curl_easy_setopt(request->ch, CURLOPT_COOKIEFILE, "");
return SUCCESS;
}
http_error(HE_WARNING, HTTP_E_REQUEST, "Could not enable cookies for this session");
/* {{{ STATUS http_request_reset_cookies(http_request *, int) */
PHP_HTTP_API STATUS _http_request_reset_cookies(http_request *request, int session_only)
{
+ int initialized = 1;
TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
+ HTTP_CHECK_CURL_INIT(request->ch, http_curl_init_ex(request->ch, request), initialized = 0);
if (session_only) {
#if HTTP_CURL_VERSION(7,15,4)
- curl_easy_setopt(request->ch, CURLOPT_COOKIELIST, "SESS");
- return SUCCESS;
-#else
- http_error(HE_WARNING, HTTP_E_REQUEST, "Could not reset session cookies (need libcurl >= v7.15.4)");
+ if (initialized) {
+ curl_easy_setopt(request->ch, CURLOPT_COOKIELIST, "SESS");
+ return SUCCESS;
+ }
#endif
+ http_error(HE_WARNING, HTTP_E_REQUEST, "Could not reset session cookies (need libcurl >= v7.15.4)");
} else {
#if HTTP_CURL_VERSION(7,14,1)
- curl_easy_setopt(request->ch, CURLOPT_COOKIELIST, "ALL");
- return SUCCESS;
-#else
- http_error(HE_WARNING, HTTP_E_REQUEST, "Could not reset cookies (need libcurl >= v7.14.1)");
+ if (initialized) {
+ curl_easy_setopt(request->ch, CURLOPT_COOKIELIST, "ALL");
+ return SUCCESS;
+ }
#endif
+ http_error(HE_WARNING, HTTP_E_REQUEST, "Could not reset cookies (need libcurl >= v7.14.1)");
}
return FAILURE;
}
HTTP_CURL_OPT(CURLOPT_PROXYTYPE, 0L);
HTTP_CURL_OPT(CURLOPT_PROXYUSERPWD, NULL);
HTTP_CURL_OPT(CURLOPT_PROXYAUTH, 0L);
+ HTTP_CURL_OPT(CURLOPT_DNS_CACHE_TIMEOUT, 60L);
+ HTTP_CURL_OPT(CURLOPT_LOW_SPEED_LIMIT, 0L);
+ HTTP_CURL_OPT(CURLOPT_LOW_SPEED_TIME, 0L);
+#if HTTP_CURL_VERSION(7,15,5)
+ HTTP_CURL_OPT(CURLOPT_MAX_SEND_SPEED_LARGE, (curl_off_t) 0);
+ HTTP_CURL_OPT(CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) 0);
+#endif
+ /* crashes
+ HTTP_CURL_OPT(CURLOPT_MAXCONNECTS, 5L); */
+ HTTP_CURL_OPT(CURLOPT_FRESH_CONNECT, 0L);
+ HTTP_CURL_OPT(CURLOPT_FORBID_REUSE, 0L);
HTTP_CURL_OPT(CURLOPT_INTERFACE, NULL);
HTTP_CURL_OPT(CURLOPT_PORT, 0L);
#if HTTP_CURL_VERSION(7,15,2)
}
}
+ /* dns */
+ if ((zoption = http_request_option(request, options, "dns_cache_timeout", IS_LONG))) {
+ HTTP_CURL_OPT(CURLOPT_DNS_CACHE_TIMEOUT, Z_LVAL_P(zoption));
+ }
+
+ /* limits */
+ if ((zoption = http_request_option(request, options, "low_speed_limit", IS_LONG))) {
+ HTTP_CURL_OPT(CURLOPT_LOW_SPEED_LIMIT, Z_LVAL_P(zoption));
+ }
+ if ((zoption = http_request_option(request, options, "low_speed_time", IS_LONG))) {
+ HTTP_CURL_OPT(CURLOPT_LOW_SPEED_TIME, Z_LVAL_P(zoption));
+ }
+#if HTTP_CURL_VERSION(7,15,5)
+ if ((zoption = http_request_option(request, options, "max_send_speed", IS_LONG))) {
+ HTTP_CURL_OPT(CURLOPT_MAX_SEND_SPEED_LARGE, (curl_off_t) Z_LVAL_P(zoption));
+ }
+ if ((zoption = http_request_option(request, options, "max_recv_speed", IS_LONG))) {
+ HTTP_CURL_OPT(CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) Z_LVAL_P(zoption));
+ }
+#endif
+ /* crashes
+ if ((zoption = http_request_option(request, options, "maxconnects", IS_LONG))) {
+ HTTP_CURL_OPT(CURLOPT_MAXCONNECTS, Z_LVAL_P(zoption));
+ } */
+ if ((zoption = http_request_option(request, options, "fresh_connect", IS_BOOL)) && Z_BVAL_P(zoption)) {
+ HTTP_CURL_OPT(CURLOPT_FRESH_CONNECT, 1L);
+ }
+ if ((zoption = http_request_option(request, options, "forbid_reuse", IS_BOOL)) && Z_BVAL_P(zoption)) {
+ HTTP_CURL_OPT(CURLOPT_FORBID_REUSE, 1L);
+ }
+
/* outgoing interface */
if ((zoption = http_request_option(request, options, "interface", IS_STRING))) {
HTTP_CURL_OPT(CURLOPT_INTERFACE, Z_STRVAL_P(zoption));
add_assoc_double(param, "ulnow", ulnow);
with_error_handling(EH_NORMAL, NULL) {
+ request->_in_progress_cb = 1;
call_user_function(EG(function_table), NULL, request->_progress_callback, &retval, 1, ¶m TSRMLS_CC);
+ request->_in_progress_cb = 0;
} end_error_handling();
zval_ptr_dtor(¶m);
if (data[length-1] != 0xa) {
fprintf(stderr, "\n");
}
+#endif
+#if 0
+ fprintf(stderr, "%.*s%s", length, data, data[length-1]=='\n'?"":"\n");
#endif
break;
}