diff options
Diffstat (limited to 'ext/curl')
69 files changed, 2668 insertions, 1584 deletions
diff --git a/ext/curl/config.m4 b/ext/curl/config.m4 index fbb4f5b4e5..2f82c3485d 100644 --- a/ext/curl/config.m4 +++ b/ext/curl/config.m4 @@ -3,11 +3,7 @@ dnl $Id$ dnl PHP_ARG_WITH(curl, for cURL support, -[ --with-curl[=DIR] Include cURL support]) - -dnl Temporary option while we develop this aspect of the extension -PHP_ARG_WITH(curlwrappers, if we should use cURL for url streams, -[ --with-curlwrappers EXPERIMENTAL: Use cURL for url streams], no, no) +[ --with-curl[=DIR] Include cURL support]) if test "$PHP_CURL" != "no"; then if test -r $PHP_CURL/include/curl/easy.h; then @@ -131,13 +127,6 @@ int main(int argc, char *argv[]) $CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR ]) - PHP_CHECK_LIBRARY(curl,curl_version_info, - [ - AC_DEFINE(HAVE_CURL_VERSION_INFO,1,[ ]) - ],[],[ - $CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR - ]) - PHP_CHECK_LIBRARY(curl,curl_easy_strerror, [ AC_DEFINE(HAVE_CURL_EASY_STRERROR,1,[ ]) @@ -152,10 +141,6 @@ int main(int argc, char *argv[]) $CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR ]) - if test "$PHP_CURLWRAPPERS" != "no" ; then - AC_DEFINE(PHP_CURL_URL_WRAPPERS,1,[ ]) - fi - - PHP_NEW_EXTENSION(curl, interface.c multi.c streams.c, $ext_shared) + PHP_NEW_EXTENSION(curl, interface.c multi.c share.c curl_file.c, $ext_shared) PHP_SUBST(CURL_SHARED_LIBADD) fi diff --git a/ext/curl/config.w32 b/ext/curl/config.w32 index 930adcfd41..965721318e 100644 --- a/ext/curl/config.w32 +++ b/ext/curl/config.w32 @@ -13,15 +13,13 @@ if (PHP_CURL != "no") { && (((PHP_ZLIB=="no") && (CHECK_LIB("zlib_a.lib;zlib.lib", "curl", PHP_CURL))) || (PHP_ZLIB_SHARED && CHECK_LIB("zlib.lib", "curl", PHP_CURL)) || (PHP_ZLIB == "yes" && (!PHP_ZLIB_SHARED))) ) { - EXTENSION("curl", "interface.c multi.c streams.c", true); + EXTENSION("curl", "interface.c multi.c share.c curl_file.c", true); AC_DEFINE('HAVE_CURL', 1, 'Have cURL library'); AC_DEFINE('HAVE_CURL_SSL', 1, 'Have SSL suppurt in cURL'); AC_DEFINE('HAVE_CURL_EASY_STRERROR', 1, 'Have curl_easy_strerror in cURL'); AC_DEFINE('HAVE_CURL_MULTI_STRERROR', 1, 'Have curl_multi_strerror in cURL'); - AC_DEFINE('HAVE_CURL_VERSION_INFO', 1, 'Have curl_version_info in cURL'); ADD_FLAG("CFLAGS_CURL", "/D CURL_STATICLIB"); // TODO: check for curl_version_info - // AC_DEFINE('PHP_CURL_URL_WRAPPERS', 0, 'Use curl for URL wrappers [experimental]'); } else { WARNING("curl not enabled; libraries and headers not found"); } diff --git a/ext/curl/curl.dsp b/ext/curl/curl.dsp index 81d823183d..6524fceb89 100644 --- a/ext/curl/curl.dsp +++ b/ext/curl/curl.dsp @@ -166,6 +166,10 @@ SOURCE=.\multi.c # End Source File
# Begin Source File
+SOURCE=.\share.c
+# End Source File
+
+# Begin Source File
SOURCE=.\streams.c
# End Source File
diff --git a/ext/curl/curl_file.c b/ext/curl/curl_file.c new file mode 100644 index 0000000000..9f371df538 --- /dev/null +++ b/ext/curl/curl_file.c @@ -0,0 +1,177 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2014 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Stanislav Malyshev <stas@php.net> | + +----------------------------------------------------------------------+ + */ + +/* $Id$ */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "php.h" +#include "Zend/zend_exceptions.h" +#include "php_curl.h" +#if HAVE_CURL + +PHP_CURL_API zend_class_entry *curl_CURLFile_class; + +static void curlfile_ctor(INTERNAL_FUNCTION_PARAMETERS) +{ + char *fname = NULL, *mime = NULL, *postname = NULL; + int fname_len, mime_len, postname_len; + zval *cf = return_value; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ss", &fname, &fname_len, &mime, &mime_len, &postname, &postname_len) == FAILURE) { + return; + } + + if (fname) { + zend_update_property_string(curl_CURLFile_class, cf, "name", sizeof("name")-1, fname TSRMLS_CC); + } + + if (mime) { + zend_update_property_string(curl_CURLFile_class, cf, "mime", sizeof("mime")-1, mime TSRMLS_CC); + } + + if (postname) { + zend_update_property_string(curl_CURLFile_class, cf, "postname", sizeof("postname")-1, postname TSRMLS_CC); + } +} + +/* {{{ proto void CURLFile::__construct(string $name, [string $mimetype [, string $postfilename]]) + Create the CURLFile object */ +ZEND_METHOD(CURLFile, __construct) +{ + return_value = getThis(); + curlfile_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); +} +/* }}} */ + +/* {{{ proto CURLFile curl_file_create(string $name, [string $mimetype [, string $postfilename]]) + Create the CURLFile object */ +PHP_FUNCTION(curl_file_create) +{ + object_init_ex( return_value, curl_CURLFile_class ); + curlfile_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); +} +/* }}} */ + +static void curlfile_get_property(char *name, INTERNAL_FUNCTION_PARAMETERS) +{ + zval *res; + if (zend_parse_parameters_none() == FAILURE) { + return; + } + res = zend_read_property(curl_CURLFile_class, getThis(), name, strlen(name), 1 TSRMLS_CC); + *return_value = *res; + zval_copy_ctor(return_value); + INIT_PZVAL(return_value); +} + +static void curlfile_set_property(char *name, INTERNAL_FUNCTION_PARAMETERS) +{ + char *arg = NULL; + int arg_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { + return; + } + zend_update_property_string(curl_CURLFile_class, getThis(), name, strlen(name), arg TSRMLS_CC); +} + +/* {{{ proto string CURLFile::getFilename() + Get file name */ +ZEND_METHOD(CURLFile, getFilename) +{ + curlfile_get_property("name", INTERNAL_FUNCTION_PARAM_PASSTHRU); +} +/* }}} */ + +/* {{{ proto string CURLFile::getMimeType() + Get MIME type */ +ZEND_METHOD(CURLFile, getMimeType) +{ + curlfile_get_property("mime", INTERNAL_FUNCTION_PARAM_PASSTHRU); +} +/* }}} */ + +/* {{{ proto string CURLFile::getPostFilename() + Get file name for POST */ +ZEND_METHOD(CURLFile, getPostFilename) +{ + curlfile_get_property("postname", INTERNAL_FUNCTION_PARAM_PASSTHRU); +} +/* }}} */ + +/* {{{ proto void CURLFile::setMimeType(string $mime) + Set MIME type */ +ZEND_METHOD(CURLFile, setMimeType) +{ + curlfile_set_property("mime", INTERNAL_FUNCTION_PARAM_PASSTHRU); +} +/* }}} */ + +/* {{{ proto void CURLFile::setPostFilename(string $name) + Set file name for POST */ +ZEND_METHOD(CURLFile, setPostFilename) +{ + curlfile_set_property("postname", INTERNAL_FUNCTION_PARAM_PASSTHRU); +} +/* }}} */ + +/* {{{ proto void CURLFile::__wakeup() + Unserialization handler */ +ZEND_METHOD(CURLFile, __wakeup) +{ + zend_update_property_string(curl_CURLFile_class, getThis(), "name", sizeof("name")-1, "" TSRMLS_CC); + zend_throw_exception(NULL, "Unserialization of CURLFile instances is not allowed", 0 TSRMLS_CC); +} +/* }}} */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_curlfile_create, 0, 0, 1) + ZEND_ARG_INFO(0, filename) + ZEND_ARG_INFO(0, mimetype) + ZEND_ARG_INFO(0, postname) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_curlfile_name, 0) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + + +static const zend_function_entry curlfile_funcs[] = { + PHP_ME(CURLFile, __construct, arginfo_curlfile_create, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC) + PHP_ME(CURLFile, getFilename, NULL, ZEND_ACC_PUBLIC) + PHP_ME(CURLFile, getMimeType, NULL, ZEND_ACC_PUBLIC) + PHP_ME(CURLFile, setMimeType, arginfo_curlfile_name, ZEND_ACC_PUBLIC) + PHP_ME(CURLFile, getPostFilename, NULL, ZEND_ACC_PUBLIC) + PHP_ME(CURLFile, setPostFilename, arginfo_curlfile_name, ZEND_ACC_PUBLIC) + PHP_ME(CURLFile, __wakeup, NULL, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +void curlfile_register_class(TSRMLS_D) +{ + zend_class_entry ce; + INIT_CLASS_ENTRY( ce, "CURLFile", curlfile_funcs ); + curl_CURLFile_class = zend_register_internal_class(&ce TSRMLS_CC); + zend_declare_property_string(curl_CURLFile_class, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_string(curl_CURLFile_class, "mime", sizeof("mime")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_string(curl_CURLFile_class, "postname", sizeof("postname")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); +} + +#endif diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 8915625047..765918cc35 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -90,6 +90,7 @@ int le_curl; int le_curl_multi_handle; +int le_curl_share_handle; #ifdef PHP_CURL_NEED_OPENSSL_TSL /* {{{ */ static MUTEX_T *php_curl_openssl_tsl = NULL; @@ -164,50 +165,62 @@ static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC); # define php_curl_ret(__ret) RETVAL_FALSE; return; #endif -static int php_curl_option_url(php_curl *ch, const char *url, const int len TSRMLS_DC) /* {{{ */ +static int php_curl_option_str(php_curl *ch, long option, const char *str, const int len, zend_bool make_copy TSRMLS_DC) { CURLcode error = CURLE_OK; -#if LIBCURL_VERSION_NUM < 0x071100 - char *copystr = NULL; + +#if LIBCURL_VERSION_NUM >= 0x071100 + if (make_copy) { #endif + char *copystr; + + /* Strings passed to libcurl as 'char *' arguments, are copied by the library since 7.17.0 */ + copystr = estrndup(str, len); + error = curl_easy_setopt(ch->cp, option, copystr); + zend_llist_add_element(&ch->to_free->str, ©str); +#if LIBCURL_VERSION_NUM >= 0x071100 + } else { + error = curl_easy_setopt(ch->cp, option, str); + } +#endif + + SAVE_CURL_ERROR(ch, error) + + return error == CURLE_OK ? SUCCESS : FAILURE; +} + +static int php_curl_option_url(php_curl *ch, const char *url, const int len TSRMLS_DC) /* {{{ */ +{ /* Disable file:// if open_basedir are used */ if (PG(open_basedir) && *PG(open_basedir)) { #if LIBCURL_VERSION_NUM >= 0x071304 - error = curl_easy_setopt(ch->cp, CURLOPT_PROTOCOLS, CURLPROTO_ALL & ~CURLPROTO_FILE); + curl_easy_setopt(ch->cp, CURLOPT_PROTOCOLS, CURLPROTO_ALL & ~CURLPROTO_FILE); #else php_url *uri; if (!(uri = php_url_parse_ex(url, len))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid URL '%s'", url); - return 0; + return FAILURE; } if (uri->scheme && !strncasecmp("file", uri->scheme, sizeof("file"))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Protocol 'file' disabled in cURL"); php_url_free(uri); - return 0; + return FAILURE; } php_url_free(uri); #endif } - /* Strings passed to libcurl as 'char *' arguments, are copied by the library... NOTE: before 7.17.0 strings were not copied. */ -#if LIBCURL_VERSION_NUM >= 0x071100 - error = curl_easy_setopt(ch->cp, CURLOPT_URL, url); -#else - copystr = estrndup(url, len); - error = curl_easy_setopt(ch->cp, CURLOPT_URL, copystr); - zend_llist_add_element(&ch->to_free->str, ©str); -#endif - return (error == CURLE_OK ? 1 : 0); + return php_curl_option_str(ch, CURLOPT_URL, url, len, 0 TSRMLS_CC); } /* }}} */ -int _php_curl_verify_handlers(php_curl *ch, int reporterror TSRMLS_DC) /* {{{ */ +void _php_curl_verify_handlers(php_curl *ch, int reporterror TSRMLS_DC) /* {{{ */ { php_stream *stream; if (!ch || !ch->handlers) { - return 0; + return; } if (ch->handlers->std_err) { @@ -261,11 +274,10 @@ int _php_curl_verify_handlers(php_curl *ch, int reporterror TSRMLS_DC) /* {{{ */ ch->handlers->write->stream = NULL; ch->handlers->write->method = PHP_CURL_STDOUT; - ch->handlers->write->type = PHP_CURL_ASCII; curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch); } } - return 1; + return ; } /* }}} */ @@ -314,6 +326,30 @@ ZEND_BEGIN_ARG_INFO(arginfo_curl_close, 0) ZEND_ARG_INFO(0, ch) ZEND_END_ARG_INFO() +#if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */ +ZEND_BEGIN_ARG_INFO(arginfo_curl_reset, 0) + ZEND_ARG_INFO(0, ch) +ZEND_END_ARG_INFO() +#endif + +#if LIBCURL_VERSION_NUM > 0x070f03 /* 7.15.4 */ +ZEND_BEGIN_ARG_INFO(arginfo_curl_escape, 0) + ZEND_ARG_INFO(0, ch) + ZEND_ARG_INFO(0, str) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_curl_unescape, 0) + ZEND_ARG_INFO(0, ch) + ZEND_ARG_INFO(0, str) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_setopt, 0) + ZEND_ARG_INFO(0, sh) + ZEND_ARG_INFO(0, option) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() +#endif + ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_init, 0) ZEND_END_ARG_INFO() @@ -349,6 +385,42 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_close, 0) ZEND_ARG_INFO(0, mh) ZEND_END_ARG_INFO() + +#if LIBCURL_VERSION_NUM >= 0x070c00 /* Available since 7.12.0 */ +ZEND_BEGIN_ARG_INFO(arginfo_curl_strerror, 0) + ZEND_ARG_INFO(0, errornum) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_strerror, 0) + ZEND_ARG_INFO(0, errornum) +ZEND_END_ARG_INFO() +#endif + +ZEND_BEGIN_ARG_INFO(arginfo_curl_share_init, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_curl_share_close, 0) + ZEND_ARG_INFO(0, sh) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_curl_share_setopt, 0) + ZEND_ARG_INFO(0, sh) + ZEND_ARG_INFO(0, option) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +#if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */ +ZEND_BEGIN_ARG_INFO(arginfo_curl_pause, 0) + ZEND_ARG_INFO(0, ch) + ZEND_ARG_INFO(0, bitmask) +ZEND_END_ARG_INFO() +#endif + +ZEND_BEGIN_ARG_INFO_EX(arginfo_curlfile_create, 0, 0, 1) + ZEND_ARG_INFO(0, filename) + ZEND_ARG_INFO(0, mimetype) + ZEND_ARG_INFO(0, postname) +ZEND_END_ARG_INFO() /* }}} */ /* {{{ curl_functions[] @@ -364,6 +436,20 @@ const zend_function_entry curl_functions[] = { PHP_FE(curl_error, arginfo_curl_error) PHP_FE(curl_errno, arginfo_curl_errno) PHP_FE(curl_close, arginfo_curl_close) +#if LIBCURL_VERSION_NUM >= 0x070c00 /* 7.12.0 */ + PHP_FE(curl_strerror, arginfo_curl_strerror) + PHP_FE(curl_multi_strerror, arginfo_curl_multi_strerror) +#endif +#if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */ + PHP_FE(curl_reset, arginfo_curl_reset) +#endif +#if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */ + PHP_FE(curl_escape, arginfo_curl_escape) + PHP_FE(curl_unescape, arginfo_curl_unescape) +#endif +#if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */ + PHP_FE(curl_pause, arginfo_curl_pause) +#endif PHP_FE(curl_multi_init, arginfo_curl_multi_init) PHP_FE(curl_multi_add_handle, arginfo_curl_multi_add_handle) PHP_FE(curl_multi_remove_handle, arginfo_curl_multi_remove_handle) @@ -372,6 +458,13 @@ const zend_function_entry curl_functions[] = { PHP_FE(curl_multi_getcontent, arginfo_curl_multi_getcontent) PHP_FE(curl_multi_info_read, arginfo_curl_multi_info_read) PHP_FE(curl_multi_close, arginfo_curl_multi_close) +#if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */ + PHP_FE(curl_multi_setopt, arginfo_curl_multi_setopt) +#endif + PHP_FE(curl_share_init, arginfo_curl_share_init) + PHP_FE(curl_share_close, arginfo_curl_share_close) + PHP_FE(curl_share_setopt, arginfo_curl_share_setopt) + PHP_FE(curl_file_create, arginfo_curlfile_create) PHP_FE_END }; /* }}} */ @@ -428,42 +521,40 @@ PHP_MINFO_FUNCTION(curl) unsigned int i; static const struct feat feats[] = { -#if LIBCURL_VERSION_NUM > 0x070a06 /* 7.10.7 */ +#if LIBCURL_VERSION_NUM >= 0x070a07 /* 7.10.7 */ {"AsynchDNS", CURL_VERSION_ASYNCHDNS}, #endif -#if LIBCURL_VERSION_NUM > 0x070a05 /* 7.10.6 */ +#if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */ + {"CharConv", CURL_VERSION_CONV}, +#endif +#if LIBCURL_VERSION_NUM >= 0x070a06 /* 7.10.6 */ {"Debug", CURL_VERSION_DEBUG}, {"GSS-Negotiate", CURL_VERSION_GSSNEGOTIATE}, #endif -#if LIBCURL_VERSION_NUM > 0x070b02 /* 7.12.0 */ +#if LIBCURL_VERSION_NUM >= 0x070c00 /* 7.12.0 */ {"IDN", CURL_VERSION_IDN}, #endif -#ifdef CURL_VERSION_IPV6 {"IPv6", CURL_VERSION_IPV6}, -#endif -#if LIBCURL_VERSION_NUM > 0x070b00 /* 7.11.1 */ + {"krb4", CURL_VERSION_KERBEROS4}, +#if LIBCURL_VERSION_NUM >= 0x070b01 /* 7.11.1 */ {"Largefile", CURL_VERSION_LARGEFILE}, #endif -#if LIBCURL_VERSION_NUM > 0x070a05 /* 7.10.6 */ + {"libz", CURL_VERSION_LIBZ}, +#if LIBCURL_VERSION_NUM >= 0x070a06 /* 7.10.6 */ {"NTLM", CURL_VERSION_NTLM}, #endif -#if LIBCURL_VERSION_NUM > 0x070a07 /* 7.10.8 */ +#if LIBCURL_VERSION_NUM >= 0x071600 /* 7.22.0 */ + {"NTLMWB", CURL_VERSION_NTLM_WB}, +#endif +#if LIBCURL_VERSION_NUM >= 0x070a08 /* 7.10.8 */ {"SPNEGO", CURL_VERSION_SPNEGO}, #endif -#ifdef CURL_VERSION_SSL {"SSL", CURL_VERSION_SSL}, -#endif -#if LIBCURL_VERSION_NUM > 0x070d01 /* 7.13.2 */ +#if LIBCURL_VERSION_NUM >= 0x070d02 /* 7.13.2 */ {"SSPI", CURL_VERSION_SSPI}, #endif -#ifdef CURL_VERSION_KERBEROS4 - {"krb4", CURL_VERSION_KERBEROS4}, -#endif -#ifdef CURL_VERSION_LIBZ - {"libz", CURL_VERSION_LIBZ}, -#endif -#if LIBCURL_VERSION_NUM > 0x070f03 /* 7.15.4 */ - {"CharConv", CURL_VERSION_CONV}, +#if LIBCURL_VERSION_NUM >= 0x071504 /* 7.21.4 */ + {"TLS-SRP", CURL_VERSION_TLSAUTH_SRP}, #endif {NULL, 0} }; @@ -528,6 +619,7 @@ PHP_MINIT_FUNCTION(curl) { le_curl = zend_register_list_destructors_ex(_php_curl_close, NULL, "curl", module_number); le_curl_multi_handle = zend_register_list_destructors_ex(_php_curl_multi_close, NULL, "curl_multi", module_number); + le_curl_share_handle = zend_register_list_destructors_ex(_php_curl_share_close, NULL, "curl_share", module_number); REGISTER_INI_ENTRIES(); @@ -536,358 +628,586 @@ PHP_MINIT_FUNCTION(curl) of options and which version they were introduced */ /* Constants for curl_setopt() */ -#if LIBCURL_VERSION_NUM > 0x070a07 /* CURLOPT_IPRESOLVE is available since curl 7.10.8 */ - REGISTER_CURL_CONSTANT(CURLOPT_IPRESOLVE); - REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_WHATEVER); - REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V4); - REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V6); -#endif - REGISTER_CURL_CONSTANT(CURLOPT_DNS_USE_GLOBAL_CACHE); + REGISTER_CURL_CONSTANT(CURLOPT_AUTOREFERER); + REGISTER_CURL_CONSTANT(CURLOPT_BINARYTRANSFER); + REGISTER_CURL_CONSTANT(CURLOPT_BUFFERSIZE); + REGISTER_CURL_CONSTANT(CURLOPT_CAINFO); + REGISTER_CURL_CONSTANT(CURLOPT_CAPATH); + REGISTER_CURL_CONSTANT(CURLOPT_CLOSEPOLICY); + REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT); + REGISTER_CURL_CONSTANT(CURLOPT_COOKIE); + REGISTER_CURL_CONSTANT(CURLOPT_COOKIEFILE); + REGISTER_CURL_CONSTANT(CURLOPT_COOKIEJAR); + REGISTER_CURL_CONSTANT(CURLOPT_COOKIESESSION); + REGISTER_CURL_CONSTANT(CURLOPT_CRLF); + REGISTER_CURL_CONSTANT(CURLOPT_CUSTOMREQUEST); REGISTER_CURL_CONSTANT(CURLOPT_DNS_CACHE_TIMEOUT); - REGISTER_CURL_CONSTANT(CURLOPT_PORT); + REGISTER_CURL_CONSTANT(CURLOPT_DNS_USE_GLOBAL_CACHE); + REGISTER_CURL_CONSTANT(CURLOPT_EGDSOCKET); + REGISTER_CURL_CONSTANT(CURLOPT_ENCODING); + REGISTER_CURL_CONSTANT(CURLOPT_FAILONERROR); REGISTER_CURL_CONSTANT(CURLOPT_FILE); - REGISTER_CURL_CONSTANT(CURLOPT_READDATA); - REGISTER_CURL_CONSTANT(CURLOPT_INFILE); - REGISTER_CURL_CONSTANT(CURLOPT_INFILESIZE); - REGISTER_CURL_CONSTANT(CURLOPT_URL); - REGISTER_CURL_CONSTANT(CURLOPT_PROXY); - REGISTER_CURL_CONSTANT(CURLOPT_VERBOSE); + REGISTER_CURL_CONSTANT(CURLOPT_FILETIME); + REGISTER_CURL_CONSTANT(CURLOPT_FOLLOWLOCATION); + REGISTER_CURL_CONSTANT(CURLOPT_FORBID_REUSE); + REGISTER_CURL_CONSTANT(CURLOPT_FRESH_CONNECT); + REGISTER_CURL_CONSTANT(CURLOPT_FTPAPPEND); + REGISTER_CURL_CONSTANT(CURLOPT_FTPLISTONLY); + REGISTER_CURL_CONSTANT(CURLOPT_FTPPORT); + REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPRT); + REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPSV); REGISTER_CURL_CONSTANT(CURLOPT_HEADER); + REGISTER_CURL_CONSTANT(CURLOPT_HEADERFUNCTION); + REGISTER_CURL_CONSTANT(CURLOPT_HTTP200ALIASES); + REGISTER_CURL_CONSTANT(CURLOPT_HTTPGET); REGISTER_CURL_CONSTANT(CURLOPT_HTTPHEADER); - REGISTER_CURL_CONSTANT(CURLOPT_NOPROGRESS); - REGISTER_CURL_CONSTANT(CURLOPT_PROGRESSFUNCTION); + REGISTER_CURL_CONSTANT(CURLOPT_HTTPPROXYTUNNEL); + REGISTER_CURL_CONSTANT(CURLOPT_HTTP_VERSION); + REGISTER_CURL_CONSTANT(CURLOPT_INFILE); + REGISTER_CURL_CONSTANT(CURLOPT_INFILESIZE); + REGISTER_CURL_CONSTANT(CURLOPT_INTERFACE); + REGISTER_CURL_CONSTANT(CURLOPT_KRB4LEVEL); + REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_LIMIT); + REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_TIME); + REGISTER_CURL_CONSTANT(CURLOPT_MAXCONNECTS); + REGISTER_CURL_CONSTANT(CURLOPT_MAXREDIRS); + REGISTER_CURL_CONSTANT(CURLOPT_NETRC); REGISTER_CURL_CONSTANT(CURLOPT_NOBODY); - REGISTER_CURL_CONSTANT(CURLOPT_FAILONERROR); - REGISTER_CURL_CONSTANT(CURLOPT_UPLOAD); + REGISTER_CURL_CONSTANT(CURLOPT_NOPROGRESS); + REGISTER_CURL_CONSTANT(CURLOPT_NOSIGNAL); + REGISTER_CURL_CONSTANT(CURLOPT_PORT); REGISTER_CURL_CONSTANT(CURLOPT_POST); - REGISTER_CURL_CONSTANT(CURLOPT_FTPLISTONLY); - REGISTER_CURL_CONSTANT(CURLOPT_FTPAPPEND); - REGISTER_CURL_CONSTANT(CURLOPT_NETRC); - REGISTER_CURL_CONSTANT(CURLOPT_FOLLOWLOCATION); -#if CURLOPT_FTPASCII != 0 - REGISTER_CURL_CONSTANT(CURLOPT_FTPASCII); -#endif - REGISTER_CURL_CONSTANT(CURLOPT_PUT); -#if CURLOPT_MUTE != 0 - REGISTER_CURL_CONSTANT(CURLOPT_MUTE); -#endif - REGISTER_CURL_CONSTANT(CURLOPT_USERPWD); + REGISTER_CURL_CONSTANT(CURLOPT_POSTFIELDS); + REGISTER_CURL_CONSTANT(CURLOPT_POSTQUOTE); + REGISTER_CURL_CONSTANT(CURLOPT_PREQUOTE); + REGISTER_CURL_CONSTANT(CURLOPT_PRIVATE); + REGISTER_CURL_CONSTANT(CURLOPT_PROGRESSFUNCTION); + REGISTER_CURL_CONSTANT(CURLOPT_PROXY); + REGISTER_CURL_CONSTANT(CURLOPT_PROXYPORT); + REGISTER_CURL_CONSTANT(CURLOPT_PROXYTYPE); REGISTER_CURL_CONSTANT(CURLOPT_PROXYUSERPWD); + REGISTER_CURL_CONSTANT(CURLOPT_PUT); + REGISTER_CURL_CONSTANT(CURLOPT_QUOTE); + REGISTER_CURL_CONSTANT(CURLOPT_RANDOM_FILE); REGISTER_CURL_CONSTANT(CURLOPT_RANGE); - REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT); -#if LIBCURL_VERSION_NUM > 0x071002 - REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT_MS); -#endif - REGISTER_CURL_CONSTANT(CURLOPT_POSTFIELDS); + REGISTER_CURL_CONSTANT(CURLOPT_READDATA); + REGISTER_CURL_CONSTANT(CURLOPT_READFUNCTION); REGISTER_CURL_CONSTANT(CURLOPT_REFERER); - REGISTER_CURL_CONSTANT(CURLOPT_USERAGENT); - REGISTER_CURL_CONSTANT(CURLOPT_FTPPORT); - REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPSV); - REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_LIMIT); - REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_TIME); REGISTER_CURL_CONSTANT(CURLOPT_RESUME_FROM); - REGISTER_CURL_CONSTANT(CURLOPT_COOKIE); - REGISTER_CURL_CONSTANT(CURLOPT_COOKIESESSION); - REGISTER_CURL_CONSTANT(CURLOPT_AUTOREFERER); + REGISTER_CURL_CONSTANT(CURLOPT_RETURNTRANSFER); + REGISTER_CURL_CONSTANT(CURLOPT_SHARE); REGISTER_CURL_CONSTANT(CURLOPT_SSLCERT); REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTPASSWD); - REGISTER_CURL_CONSTANT(CURLOPT_WRITEHEADER); - REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYHOST); - REGISTER_CURL_CONSTANT(CURLOPT_COOKIEFILE); + REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTTYPE); + REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE); + REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE_DEFAULT); + REGISTER_CURL_CONSTANT(CURLOPT_SSLKEY); + REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYPASSWD); + REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYTYPE); REGISTER_CURL_CONSTANT(CURLOPT_SSLVERSION); + REGISTER_CURL_CONSTANT(CURLOPT_SSL_CIPHER_LIST); + REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYHOST); + REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYPEER); + REGISTER_CURL_CONSTANT(CURLOPT_STDERR); + REGISTER_CURL_CONSTANT(CURLOPT_TELNETOPTIONS); REGISTER_CURL_CONSTANT(CURLOPT_TIMECONDITION); + REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT); REGISTER_CURL_CONSTANT(CURLOPT_TIMEVALUE); - REGISTER_CURL_CONSTANT(CURLOPT_CUSTOMREQUEST); - REGISTER_CURL_CONSTANT(CURLOPT_STDERR); REGISTER_CURL_CONSTANT(CURLOPT_TRANSFERTEXT); - REGISTER_CURL_CONSTANT(CURLOPT_RETURNTRANSFER); - REGISTER_CURL_CONSTANT(CURLOPT_QUOTE); - REGISTER_CURL_CONSTANT(CURLOPT_POSTQUOTE); - REGISTER_CURL_CONSTANT(CURLOPT_INTERFACE); - REGISTER_CURL_CONSTANT(CURLOPT_KRB4LEVEL); - REGISTER_CURL_CONSTANT(CURLOPT_HTTPPROXYTUNNEL); - REGISTER_CURL_CONSTANT(CURLOPT_FILETIME); - REGISTER_CURL_CONSTANT(CURLOPT_WRITEFUNCTION); - REGISTER_CURL_CONSTANT(CURLOPT_READFUNCTION); -#if CURLOPT_PASSWDFUNCTION != 0 - REGISTER_CURL_CONSTANT(CURLOPT_PASSWDFUNCTION); -#endif - REGISTER_CURL_CONSTANT(CURLOPT_HEADERFUNCTION); - REGISTER_CURL_CONSTANT(CURLOPT_MAXREDIRS); - REGISTER_CURL_CONSTANT(CURLOPT_MAXCONNECTS); - REGISTER_CURL_CONSTANT(CURLOPT_CLOSEPOLICY); - REGISTER_CURL_CONSTANT(CURLOPT_FRESH_CONNECT); - REGISTER_CURL_CONSTANT(CURLOPT_FORBID_REUSE); - REGISTER_CURL_CONSTANT(CURLOPT_RANDOM_FILE); - REGISTER_CURL_CONSTANT(CURLOPT_EGDSOCKET); - REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT); -#if LIBCURL_VERSION_NUM > 0x071002 - REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT_MS); -#endif - REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYPEER); - REGISTER_CURL_CONSTANT(CURLOPT_CAINFO); - REGISTER_CURL_CONSTANT(CURLOPT_CAPATH); - REGISTER_CURL_CONSTANT(CURLOPT_COOKIEJAR); - REGISTER_CURL_CONSTANT(CURLOPT_SSL_CIPHER_LIST); - REGISTER_CURL_CONSTANT(CURLOPT_BINARYTRANSFER); - REGISTER_CURL_CONSTANT(CURLOPT_NOSIGNAL); - REGISTER_CURL_CONSTANT(CURLOPT_PROXYTYPE); - REGISTER_CURL_CONSTANT(CURLOPT_BUFFERSIZE); - REGISTER_CURL_CONSTANT(CURLOPT_HTTPGET); - REGISTER_CURL_CONSTANT(CURLOPT_HTTP_VERSION); - REGISTER_CURL_CONSTANT(CURLOPT_SSLKEY); - REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYTYPE); - REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYPASSWD); - REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE); - REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE_DEFAULT); - REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTTYPE); - REGISTER_CURL_CONSTANT(CURLOPT_CRLF); - REGISTER_CURL_CONSTANT(CURLOPT_ENCODING); - REGISTER_CURL_CONSTANT(CURLOPT_PROXYPORT); REGISTER_CURL_CONSTANT(CURLOPT_UNRESTRICTED_AUTH); - REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPRT); -#if LIBCURL_VERSION_NUM > 0x070b01 /* CURLOPT_TCP_NODELAY is available since curl 7.11.2 */ - REGISTER_CURL_CONSTANT(CURLOPT_TCP_NODELAY); -#endif - REGISTER_CURL_CONSTANT(CURLOPT_HTTP200ALIASES); - REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFMODSINCE); - REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFUNMODSINCE); - REGISTER_CURL_CONSTANT(CURL_TIMECOND_LASTMOD); - -#if LIBCURL_VERSION_NUM > 0x070f04 /* CURLOPT_MAX_RECV_SPEED_LARGE & CURLOPT_MAX_SEND_SPEED_LARGE are available since curl 7.15.5 */ - REGISTER_CURL_CONSTANT(CURLOPT_MAX_RECV_SPEED_LARGE); - REGISTER_CURL_CONSTANT(CURLOPT_MAX_SEND_SPEED_LARGE); -#endif - -#if LIBCURL_VERSION_NUM > 0x070a05 /* CURLOPT_HTTPAUTH is available since curl 7.10.6 */ - REGISTER_CURL_CONSTANT(CURLOPT_HTTPAUTH); - /* http authentication options */ - REGISTER_CURL_CONSTANT(CURLAUTH_BASIC); - REGISTER_CURL_CONSTANT(CURLAUTH_DIGEST); - REGISTER_CURL_CONSTANT(CURLAUTH_GSSNEGOTIATE); - REGISTER_CURL_CONSTANT(CURLAUTH_NTLM); - REGISTER_CURL_CONSTANT(CURLAUTH_ANY); - REGISTER_CURL_CONSTANT(CURLAUTH_ANYSAFE); -#endif - -#if LIBCURL_VERSION_NUM > 0x070a06 /* CURLOPT_PROXYAUTH & CURLOPT_FTP_CREATE_MISSING_DIRS are available since curl 7.10.7 */ - REGISTER_CURL_CONSTANT(CURLOPT_PROXYAUTH); - REGISTER_CURL_CONSTANT(CURLOPT_FTP_CREATE_MISSING_DIRS); -#endif - - REGISTER_CURL_CONSTANT(CURLOPT_PRIVATE); + REGISTER_CURL_CONSTANT(CURLOPT_UPLOAD); + REGISTER_CURL_CONSTANT(CURLOPT_URL); + REGISTER_CURL_CONSTANT(CURLOPT_USERAGENT); + REGISTER_CURL_CONSTANT(CURLOPT_USERPWD); + REGISTER_CURL_CONSTANT(CURLOPT_VERBOSE); + REGISTER_CURL_CONSTANT(CURLOPT_WRITEFUNCTION); + REGISTER_CURL_CONSTANT(CURLOPT_WRITEHEADER); /* Constants effecting the way CURLOPT_CLOSEPOLICY works */ + REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_CALLBACK); REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_LEAST_RECENTLY_USED); REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_LEAST_TRAFFIC); - REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_SLOWEST); - REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_CALLBACK); REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_OLDEST); + REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_SLOWEST); - /* Info constants */ - REGISTER_CURL_CONSTANT(CURLINFO_EFFECTIVE_URL); - REGISTER_CURL_CONSTANT(CURLINFO_HTTP_CODE); - REGISTER_CURL_CONSTANT(CURLINFO_HEADER_SIZE); - REGISTER_CURL_CONSTANT(CURLINFO_REQUEST_SIZE); - REGISTER_CURL_CONSTANT(CURLINFO_TOTAL_TIME); - REGISTER_CURL_CONSTANT(CURLINFO_NAMELOOKUP_TIME); - REGISTER_CURL_CONSTANT(CURLINFO_CONNECT_TIME); - REGISTER_CURL_CONSTANT(CURLINFO_PRETRANSFER_TIME); - REGISTER_CURL_CONSTANT(CURLINFO_SIZE_UPLOAD); - REGISTER_CURL_CONSTANT(CURLINFO_SIZE_DOWNLOAD); - REGISTER_CURL_CONSTANT(CURLINFO_SPEED_DOWNLOAD); - REGISTER_CURL_CONSTANT(CURLINFO_SPEED_UPLOAD); - REGISTER_CURL_CONSTANT(CURLINFO_FILETIME); - REGISTER_CURL_CONSTANT(CURLINFO_SSL_VERIFYRESULT); - REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_DOWNLOAD); - REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_UPLOAD); - REGISTER_CURL_CONSTANT(CURLINFO_STARTTRANSFER_TIME); - REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_TYPE); - REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_TIME); - REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_COUNT); - REGISTER_CURL_CONSTANT(CURLINFO_HEADER_OUT); - REGISTER_CURL_CONSTANT(CURLINFO_PRIVATE); -#if LIBCURL_VERSION_NUM > 0x071301 - REGISTER_CURL_CONSTANT(CURLINFO_CERTINFO); -#endif -#if LIBCURL_VERSION_NUM >= 0x071202 - REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_URL); -#endif -#if LIBCURL_VERSION_NUM >= 0x071300 /* 7.19.0 */ - REGISTER_CURL_CONSTANT(CURLINFO_PRIMARY_IP); -#endif -#if LIBCURL_VERSION_NUM >= 0x071500 /* 7.21.0 */ - REGISTER_CURL_CONSTANT(CURLINFO_PRIMARY_PORT); - REGISTER_CURL_CONSTANT(CURLINFO_LOCAL_IP); - REGISTER_CURL_CONSTANT(CURLINFO_LOCAL_PORT); -#endif - - - /* cURL protocol constants (curl_version) */ - REGISTER_CURL_CONSTANT(CURL_VERSION_IPV6); - REGISTER_CURL_CONSTANT(CURL_VERSION_KERBEROS4); - REGISTER_CURL_CONSTANT(CURL_VERSION_SSL); - REGISTER_CURL_CONSTANT(CURL_VERSION_LIBZ); - - /* version constants */ - REGISTER_CURL_CONSTANT(CURLVERSION_NOW); - - /* Error Constants */ - REGISTER_CURL_CONSTANT(CURLE_OK); - REGISTER_CURL_CONSTANT(CURLE_UNSUPPORTED_PROTOCOL); - REGISTER_CURL_CONSTANT(CURLE_FAILED_INIT); - REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT); - REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT_USER); - REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_PROXY); - REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_HOST); + /* */ + REGISTER_CURL_CONSTANT(CURLE_ABORTED_BY_CALLBACK); + REGISTER_CURL_CONSTANT(CURLE_BAD_CALLING_ORDER); + REGISTER_CURL_CONSTANT(CURLE_BAD_CONTENT_ENCODING); + REGISTER_CURL_CONSTANT(CURLE_BAD_DOWNLOAD_RESUME); + REGISTER_CURL_CONSTANT(CURLE_BAD_FUNCTION_ARGUMENT); + REGISTER_CURL_CONSTANT(CURLE_BAD_PASSWORD_ENTERED); REGISTER_CURL_CONSTANT(CURLE_COULDNT_CONNECT); - REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_SERVER_REPLY); + REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_HOST); + REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_PROXY); + REGISTER_CURL_CONSTANT(CURLE_FAILED_INIT); + REGISTER_CURL_CONSTANT(CURLE_FILE_COULDNT_READ_FILE); REGISTER_CURL_CONSTANT(CURLE_FTP_ACCESS_DENIED); - REGISTER_CURL_CONSTANT(CURLE_FTP_USER_PASSWORD_INCORRECT); - REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASS_REPLY); - REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_USER_REPLY); - REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASV_REPLY); - REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_227_FORMAT); + REGISTER_CURL_CONSTANT(CURLE_FTP_BAD_DOWNLOAD_RESUME); REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_GET_HOST); REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_RECONNECT); - REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_BINARY); - REGISTER_CURL_CONSTANT(CURLE_PARTIAL_FILE); + REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_GET_SIZE); REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_RETR_FILE); - REGISTER_CURL_CONSTANT(CURLE_FTP_WRITE_ERROR); - REGISTER_CURL_CONSTANT(CURLE_FTP_QUOTE_ERROR); - REGISTER_CURL_CONSTANT(CURLE_HTTP_NOT_FOUND); - REGISTER_CURL_CONSTANT(CURLE_WRITE_ERROR); - REGISTER_CURL_CONSTANT(CURLE_MALFORMAT_USER); - REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_STOR_FILE); - REGISTER_CURL_CONSTANT(CURLE_READ_ERROR); - REGISTER_CURL_CONSTANT(CURLE_OUT_OF_MEMORY); - REGISTER_CURL_CONSTANT(CURLE_OPERATION_TIMEOUTED); REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_ASCII); - REGISTER_CURL_CONSTANT(CURLE_FTP_PORT_FAILED); + REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_BINARY); + REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_STOR_FILE); REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_USE_REST); - REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_GET_SIZE); - REGISTER_CURL_CONSTANT(CURLE_HTTP_RANGE_ERROR); + REGISTER_CURL_CONSTANT(CURLE_FTP_PARTIAL_FILE); + REGISTER_CURL_CONSTANT(CURLE_FTP_PORT_FAILED); + REGISTER_CURL_CONSTANT(CURLE_FTP_QUOTE_ERROR); + REGISTER_CURL_CONSTANT(CURLE_FTP_USER_PASSWORD_INCORRECT); + REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_227_FORMAT); + REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASS_REPLY); + REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASV_REPLY); + REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_SERVER_REPLY); + REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_USER_REPLY); + REGISTER_CURL_CONSTANT(CURLE_FTP_WRITE_ERROR); + REGISTER_CURL_CONSTANT(CURLE_FUNCTION_NOT_FOUND); + REGISTER_CURL_CONSTANT(CURLE_GOT_NOTHING); + REGISTER_CURL_CONSTANT(CURLE_HTTP_NOT_FOUND); + REGISTER_CURL_CONSTANT(CURLE_HTTP_PORT_FAILED); REGISTER_CURL_CONSTANT(CURLE_HTTP_POST_ERROR); - REGISTER_CURL_CONSTANT(CURLE_SSL_CONNECT_ERROR); - REGISTER_CURL_CONSTANT(CURLE_FTP_BAD_DOWNLOAD_RESUME); - REGISTER_CURL_CONSTANT(CURLE_FILE_COULDNT_READ_FILE); + REGISTER_CURL_CONSTANT(CURLE_HTTP_RANGE_ERROR); + REGISTER_CURL_CONSTANT(CURLE_HTTP_RETURNED_ERROR); REGISTER_CURL_CONSTANT(CURLE_LDAP_CANNOT_BIND); REGISTER_CURL_CONSTANT(CURLE_LDAP_SEARCH_FAILED); REGISTER_CURL_CONSTANT(CURLE_LIBRARY_NOT_FOUND); - REGISTER_CURL_CONSTANT(CURLE_FUNCTION_NOT_FOUND); - REGISTER_CURL_CONSTANT(CURLE_ABORTED_BY_CALLBACK); - REGISTER_CURL_CONSTANT(CURLE_BAD_FUNCTION_ARGUMENT); - REGISTER_CURL_CONSTANT(CURLE_BAD_CALLING_ORDER); - REGISTER_CURL_CONSTANT(CURLE_HTTP_PORT_FAILED); - REGISTER_CURL_CONSTANT(CURLE_BAD_PASSWORD_ENTERED); - REGISTER_CURL_CONSTANT(CURLE_TOO_MANY_REDIRECTS); - REGISTER_CURL_CONSTANT(CURLE_UNKNOWN_TELNET_OPTION); - REGISTER_CURL_CONSTANT(CURLE_TELNET_OPTION_SYNTAX); + REGISTER_CURL_CONSTANT(CURLE_MALFORMAT_USER); REGISTER_CURL_CONSTANT(CURLE_OBSOLETE); - REGISTER_CURL_CONSTANT(CURLE_SSL_PEER_CERTIFICATE); - REGISTER_CURL_CONSTANT(CURLE_GOT_NOTHING); - REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_NOTFOUND); - REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_SETFAILED); - REGISTER_CURL_CONSTANT(CURLE_SEND_ERROR); + REGISTER_CURL_CONSTANT(CURLE_OK); + REGISTER_CURL_CONSTANT(CURLE_OPERATION_TIMEDOUT); + REGISTER_CURL_CONSTANT(CURLE_OPERATION_TIMEOUTED); + REGISTER_CURL_CONSTANT(CURLE_OUT_OF_MEMORY); + REGISTER_CURL_CONSTANT(CURLE_PARTIAL_FILE); + REGISTER_CURL_CONSTANT(CURLE_READ_ERROR); REGISTER_CURL_CONSTANT(CURLE_RECV_ERROR); + REGISTER_CURL_CONSTANT(CURLE_SEND_ERROR); REGISTER_CURL_CONSTANT(CURLE_SHARE_IN_USE); + REGISTER_CURL_CONSTANT(CURLE_SSL_CACERT); REGISTER_CURL_CONSTANT(CURLE_SSL_CERTPROBLEM); REGISTER_CURL_CONSTANT(CURLE_SSL_CIPHER); - REGISTER_CURL_CONSTANT(CURLE_SSL_CACERT); - REGISTER_CURL_CONSTANT(CURLE_BAD_CONTENT_ENCODING); -#if LIBCURL_VERSION_NUM >= 0x070a08 - REGISTER_CURL_CONSTANT(CURLE_LDAP_INVALID_URL); - REGISTER_CURL_CONSTANT(CURLE_FILESIZE_EXCEEDED); -#endif -#if LIBCURL_VERSION_NUM >= 0x070b00 - REGISTER_CURL_CONSTANT(CURLE_FTP_SSL_FAILED); -#endif + REGISTER_CURL_CONSTANT(CURLE_SSL_CONNECT_ERROR); + REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_NOTFOUND); + REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_SETFAILED); + REGISTER_CURL_CONSTANT(CURLE_SSL_PEER_CERTIFICATE); + REGISTER_CURL_CONSTANT(CURLE_TELNET_OPTION_SYNTAX); + REGISTER_CURL_CONSTANT(CURLE_TOO_MANY_REDIRECTS); + REGISTER_CURL_CONSTANT(CURLE_UNKNOWN_TELNET_OPTION); + REGISTER_CURL_CONSTANT(CURLE_UNSUPPORTED_PROTOCOL); + REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT); + REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT_USER); + REGISTER_CURL_CONSTANT(CURLE_WRITE_ERROR); + + /* cURL info constants */ + REGISTER_CURL_CONSTANT(CURLINFO_CONNECT_TIME); + REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_DOWNLOAD); + REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_UPLOAD); + REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_TYPE); + REGISTER_CURL_CONSTANT(CURLINFO_EFFECTIVE_URL); + REGISTER_CURL_CONSTANT(CURLINFO_FILETIME); + REGISTER_CURL_CONSTANT(CURLINFO_HEADER_OUT); + REGISTER_CURL_CONSTANT(CURLINFO_HEADER_SIZE); + REGISTER_CURL_CONSTANT(CURLINFO_HTTP_CODE); + REGISTER_CURL_CONSTANT(CURLINFO_LASTONE); + REGISTER_CURL_CONSTANT(CURLINFO_NAMELOOKUP_TIME); + REGISTER_CURL_CONSTANT(CURLINFO_PRETRANSFER_TIME); + REGISTER_CURL_CONSTANT(CURLINFO_PRIVATE); + REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_COUNT); + REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_TIME); + REGISTER_CURL_CONSTANT(CURLINFO_REQUEST_SIZE); + REGISTER_CURL_CONSTANT(CURLINFO_SIZE_DOWNLOAD); + REGISTER_CURL_CONSTANT(CURLINFO_SIZE_UPLOAD); + REGISTER_CURL_CONSTANT(CURLINFO_SPEED_DOWNLOAD); + REGISTER_CURL_CONSTANT(CURLINFO_SPEED_UPLOAD); + REGISTER_CURL_CONSTANT(CURLINFO_SSL_VERIFYRESULT); + REGISTER_CURL_CONSTANT(CURLINFO_STARTTRANSFER_TIME); + REGISTER_CURL_CONSTANT(CURLINFO_TOTAL_TIME); + + /* Other */ + REGISTER_CURL_CONSTANT(CURLMSG_DONE); + REGISTER_CURL_CONSTANT(CURLVERSION_NOW); + + /* Curl Multi Constants */ + REGISTER_CURL_CONSTANT(CURLM_BAD_EASY_HANDLE); + REGISTER_CURL_CONSTANT(CURLM_BAD_HANDLE); + REGISTER_CURL_CONSTANT(CURLM_CALL_MULTI_PERFORM); + REGISTER_CURL_CONSTANT(CURLM_INTERNAL_ERROR); + REGISTER_CURL_CONSTANT(CURLM_OK); + REGISTER_CURL_CONSTANT(CURLM_OUT_OF_MEMORY); + + /* Curl proxy constants */ REGISTER_CURL_CONSTANT(CURLPROXY_HTTP); REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS4); REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS5); - REGISTER_CURL_CONSTANT(CURL_NETRC_OPTIONAL); - REGISTER_CURL_CONSTANT(CURL_NETRC_IGNORED); - REGISTER_CURL_CONSTANT(CURL_NETRC_REQUIRED); + /* Curl Share constants */ + REGISTER_CURL_CONSTANT(CURLSHOPT_NONE); + REGISTER_CURL_CONSTANT(CURLSHOPT_SHARE); + REGISTER_CURL_CONSTANT(CURLSHOPT_UNSHARE); - REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_NONE); + /* Curl Http Version constants (CURLOPT_HTTP_VERSION) */ REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_0); REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_1); + REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_NONE); - REGISTER_CURL_CONSTANT(CURLM_CALL_MULTI_PERFORM); - REGISTER_CURL_CONSTANT(CURLM_OK); - REGISTER_CURL_CONSTANT(CURLM_BAD_HANDLE); - REGISTER_CURL_CONSTANT(CURLM_BAD_EASY_HANDLE); - REGISTER_CURL_CONSTANT(CURLM_OUT_OF_MEMORY); - REGISTER_CURL_CONSTANT(CURLM_INTERNAL_ERROR); + /* Curl Lock constants */ + REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_COOKIE); + REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_DNS); + REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_SSL_SESSION); - REGISTER_CURL_CONSTANT(CURLMSG_DONE); + /* Curl NETRC constants (CURLOPT_NETRC) */ + REGISTER_CURL_CONSTANT(CURL_NETRC_IGNORED); + REGISTER_CURL_CONSTANT(CURL_NETRC_OPTIONAL); + REGISTER_CURL_CONSTANT(CURL_NETRC_REQUIRED); -#if LIBCURL_VERSION_NUM >= 0x070c02 - REGISTER_CURL_CONSTANT(CURLOPT_FTPSSLAUTH); + /* Curl SSL Version constants (CURLOPT_SSLVERSION) */ + REGISTER_CURL_CONSTANT(CURL_SSLVERSION_DEFAULT); + REGISTER_CURL_CONSTANT(CURL_SSLVERSION_SSLv2); + REGISTER_CURL_CONSTANT(CURL_SSLVERSION_SSLv3); + REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1); + + /* Curl TIMECOND constants (CURLOPT_TIMECONDITION) */ + REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFMODSINCE); + REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFUNMODSINCE); + REGISTER_CURL_CONSTANT(CURL_TIMECOND_LASTMOD); + REGISTER_CURL_CONSTANT(CURL_TIMECOND_NONE); + + /* Curl version constants */ + REGISTER_CURL_CONSTANT(CURL_VERSION_IPV6); + REGISTER_CURL_CONSTANT(CURL_VERSION_KERBEROS4); + REGISTER_CURL_CONSTANT(CURL_VERSION_LIBZ); + REGISTER_CURL_CONSTANT(CURL_VERSION_SSL); + +#if LIBCURL_VERSION_NUM >= 0x070a06 /* Available since 7.10.6 */ + REGISTER_CURL_CONSTANT(CURLOPT_HTTPAUTH); + /* http authentication options */ + REGISTER_CURL_CONSTANT(CURLAUTH_ANY); + REGISTER_CURL_CONSTANT(CURLAUTH_ANYSAFE); + REGISTER_CURL_CONSTANT(CURLAUTH_BASIC); + REGISTER_CURL_CONSTANT(CURLAUTH_DIGEST); + REGISTER_CURL_CONSTANT(CURLAUTH_GSSNEGOTIATE); + REGISTER_CURL_CONSTANT(CURLAUTH_NONE); + REGISTER_CURL_CONSTANT(CURLAUTH_NTLM); +#endif + +#if LIBCURL_VERSION_NUM >= 0x070a07 /* Available since 7.10.7 */ + REGISTER_CURL_CONSTANT(CURLINFO_HTTP_CONNECTCODE); + REGISTER_CURL_CONSTANT(CURLOPT_FTP_CREATE_MISSING_DIRS); + REGISTER_CURL_CONSTANT(CURLOPT_PROXYAUTH); +#endif + +#if LIBCURL_VERSION_NUM >= 0x070a08 /* Available since 7.10.8 */ + REGISTER_CURL_CONSTANT(CURLE_FILESIZE_EXCEEDED); + REGISTER_CURL_CONSTANT(CURLE_LDAP_INVALID_URL); + REGISTER_CURL_CONSTANT(CURLINFO_HTTPAUTH_AVAIL); + REGISTER_CURL_CONSTANT(CURLINFO_RESPONSE_CODE); + REGISTER_CURL_CONSTANT(CURLINFO_PROXYAUTH_AVAIL); + REGISTER_CURL_CONSTANT(CURLOPT_FTP_RESPONSE_TIMEOUT); + REGISTER_CURL_CONSTANT(CURLOPT_IPRESOLVE); + REGISTER_CURL_CONSTANT(CURLOPT_MAXFILESIZE); + REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V4); + REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V6); + REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_WHATEVER); +#endif + +#if LIBCURL_VERSION_NUM >= 0x070b00 /* Available since 7.11.0 */ + REGISTER_CURL_CONSTANT(CURLE_FTP_SSL_FAILED); + REGISTER_CURL_CONSTANT(CURLFTPSSL_ALL); + REGISTER_CURL_CONSTANT(CURLFTPSSL_CONTROL); + REGISTER_CURL_CONSTANT(CURLFTPSSL_NONE); + REGISTER_CURL_CONSTANT(CURLFTPSSL_TRY); + REGISTER_CURL_CONSTANT(CURLOPT_FTP_SSL); + REGISTER_CURL_CONSTANT(CURLOPT_NETRC_FILE); +#endif + +#if LIBCURL_VERSION_NUM >= 0x070c02 /* Available since 7.12.2 */ REGISTER_CURL_CONSTANT(CURLFTPAUTH_DEFAULT); REGISTER_CURL_CONSTANT(CURLFTPAUTH_SSL); REGISTER_CURL_CONSTANT(CURLFTPAUTH_TLS); + REGISTER_CURL_CONSTANT(CURLOPT_FTPSSLAUTH); #endif -#if LIBCURL_VERSION_NUM > 0x070b00 - REGISTER_CURL_CONSTANT(CURLOPT_FTP_SSL); - REGISTER_CURL_CONSTANT(CURLFTPSSL_NONE); - REGISTER_CURL_CONSTANT(CURLFTPSSL_TRY); - REGISTER_CURL_CONSTANT(CURLFTPSSL_CONTROL); - REGISTER_CURL_CONSTANT(CURLFTPSSL_ALL); +#if LIBCURL_VERSION_NUM >= 0x070d00 /* Available since 7.13.0 */ + REGISTER_CURL_CONSTANT(CURLOPT_FTP_ACCOUNT); #endif -#if LIBCURL_VERSION_NUM > 0x071301 - REGISTER_CURL_CONSTANT(CURLOPT_CERTINFO); - REGISTER_CURL_CONSTANT(CURLOPT_POSTREDIR); +#if LIBCURL_VERSION_NUM >= 0x070b02 /* Available since 7.11.2 */ + REGISTER_CURL_CONSTANT(CURLOPT_TCP_NODELAY); #endif -/* SSH support works in 7.19.0+ using libssh2 */ -#if LIBCURL_VERSION_NUM >= 0x071300 - REGISTER_CURL_CONSTANT(CURLSSH_AUTH_NONE); - REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PUBLICKEY); - REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PASSWORD); - REGISTER_CURL_CONSTANT(CURLSSH_AUTH_HOST); - REGISTER_CURL_CONSTANT(CURLSSH_AUTH_KEYBOARD); - REGISTER_CURL_CONSTANT(CURLSSH_AUTH_DEFAULT); +#if LIBCURL_VERSION_NUM >= 0x070c02 /* Available since 7.12.2 */ + REGISTER_CURL_CONSTANT(CURLINFO_OS_ERRNO); +#endif + +#if LIBCURL_VERSION_NUM >= 0x070c03 /* Available since 7.12.3 */ + REGISTER_CURL_CONSTANT(CURLINFO_NUM_CONNECTS); + REGISTER_CURL_CONSTANT(CURLINFO_SSL_ENGINES); +#endif + +#if LIBCURL_VERSION_NUM >= 0x070e01 /* Available since 7.14.1 */ + REGISTER_CURL_CONSTANT(CURLINFO_COOKIELIST); + REGISTER_CURL_CONSTANT(CURLOPT_COOKIELIST); + REGISTER_CURL_CONSTANT(CURLOPT_IGNORE_CONTENT_LENGTH); +#endif + +#if LIBCURL_VERSION_NUM >= 0x070f00 /* Available since 7.15.0 */ + REGISTER_CURL_CONSTANT(CURLOPT_FTP_SKIP_PASV_IP); +#endif + +#if LIBCURL_VERSION_NUM >= 0x070f01 /* Available since 7.15.1 */ + REGISTER_CURL_CONSTANT(CURLOPT_FTP_FILEMETHOD); +#endif + +#if LIBCURL_VERSION_NUM >= 0x070f02 /* Available since 7.15.2 */ + REGISTER_CURL_CONSTANT(CURLOPT_CONNECT_ONLY); + REGISTER_CURL_CONSTANT(CURLOPT_LOCALPORT); + REGISTER_CURL_CONSTANT(CURLOPT_LOCALPORTRANGE); +#endif + +#if LIBCURL_VERSION_NUM >= 0x070f03 /* Available since 7.15.3 */ + REGISTER_CURL_CONSTANT(CURLFTPMETHOD_MULTICWD); + REGISTER_CURL_CONSTANT(CURLFTPMETHOD_NOCWD); + REGISTER_CURL_CONSTANT(CURLFTPMETHOD_SINGLECWD); +#endif + +#if LIBCURL_VERSION_NUM >= 0x070f04 /* Available since 7.15.4 */ + REGISTER_CURL_CONSTANT(CURLINFO_FTP_ENTRY_PATH); +#endif + +#if LIBCURL_VERSION_NUM >= 0x070f05 /* Available since 7.15.5 */ + REGISTER_CURL_CONSTANT(CURLOPT_FTP_ALTERNATIVE_TO_USER); + REGISTER_CURL_CONSTANT(CURLOPT_MAX_RECV_SPEED_LARGE); + REGISTER_CURL_CONSTANT(CURLOPT_MAX_SEND_SPEED_LARGE); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071000 /* Available since 7.16.0 */ + REGISTER_CURL_CONSTANT(CURLOPT_SSL_SESSIONID_CACHE); + REGISTER_CURL_CONSTANT(CURLMOPT_PIPELINING); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */ + REGISTER_CURL_CONSTANT(CURLE_SSH); + REGISTER_CURL_CONSTANT(CURLOPT_FTP_SSL_CCC); REGISTER_CURL_CONSTANT(CURLOPT_SSH_AUTH_TYPES); - REGISTER_CURL_CONSTANT(CURLOPT_KEYPASSWD); - REGISTER_CURL_CONSTANT(CURLOPT_SSH_PUBLIC_KEYFILE); REGISTER_CURL_CONSTANT(CURLOPT_SSH_PRIVATE_KEYFILE); + REGISTER_CURL_CONSTANT(CURLOPT_SSH_PUBLIC_KEYFILE); + REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_ACTIVE); + REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_NONE); + REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_PASSIVE); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071002 /* Available since 7.16.2 */ + REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT_MS); + REGISTER_CURL_CONSTANT(CURLOPT_HTTP_CONTENT_DECODING); + REGISTER_CURL_CONSTANT(CURLOPT_HTTP_TRANSFER_DECODING); + REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT_MS); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071003 /* Available since 7.16.3 */ + REGISTER_CURL_CONSTANT(CURLMOPT_MAXCONNECTS); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */ + REGISTER_CURL_CONSTANT(CURLOPT_KRBLEVEL); + REGISTER_CURL_CONSTANT(CURLOPT_NEW_DIRECTORY_PERMS); + REGISTER_CURL_CONSTANT(CURLOPT_NEW_FILE_PERMS); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071100 /* Available since 7.17.0 */ + REGISTER_CURL_CONSTANT(CURLOPT_APPEND); + REGISTER_CURL_CONSTANT(CURLOPT_DIRLISTONLY); + REGISTER_CURL_CONSTANT(CURLOPT_USE_SSL); + /* Curl SSL Constants */ + REGISTER_CURL_CONSTANT(CURLUSESSL_ALL); + REGISTER_CURL_CONSTANT(CURLUSESSL_CONTROL); + REGISTER_CURL_CONSTANT(CURLUSESSL_NONE); + REGISTER_CURL_CONSTANT(CURLUSESSL_TRY); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071101 /* Available since 7.17.1 */ REGISTER_CURL_CONSTANT(CURLOPT_SSH_HOST_PUBLIC_KEY_MD5); - REGISTER_CURL_CONSTANT(CURLE_SSH); #endif -#if LIBCURL_VERSION_NUM >= 0x071304 - REGISTER_CURL_CONSTANT(CURLOPT_REDIR_PROTOCOLS); +#if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */ + REGISTER_CURL_CONSTANT(CURLOPT_PROXY_TRANSFER_MODE); + REGISTER_CURL_CONSTANT(CURLPAUSE_ALL); + REGISTER_CURL_CONSTANT(CURLPAUSE_CONT); + REGISTER_CURL_CONSTANT(CURLPAUSE_RECV); + REGISTER_CURL_CONSTANT(CURLPAUSE_RECV_CONT); + REGISTER_CURL_CONSTANT(CURLPAUSE_SEND); + REGISTER_CURL_CONSTANT(CURLPAUSE_SEND_CONT); + REGISTER_CURL_CONSTANT(CURL_READFUNC_PAUSE); + REGISTER_CURL_CONSTANT(CURL_WRITEFUNC_PAUSE); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071202 /* Available since 7.18.2 */ + REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_URL); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */ + REGISTER_CURL_CONSTANT(CURLINFO_APPCONNECT_TIME); + REGISTER_CURL_CONSTANT(CURLINFO_PRIMARY_IP); + + REGISTER_CURL_CONSTANT(CURLOPT_ADDRESS_SCOPE); + REGISTER_CURL_CONSTANT(CURLOPT_CRLFILE); + REGISTER_CURL_CONSTANT(CURLOPT_ISSUERCERT); + REGISTER_CURL_CONSTANT(CURLOPT_KEYPASSWD); + + REGISTER_CURL_CONSTANT(CURLSSH_AUTH_ANY); + REGISTER_CURL_CONSTANT(CURLSSH_AUTH_DEFAULT); + REGISTER_CURL_CONSTANT(CURLSSH_AUTH_HOST); + REGISTER_CURL_CONSTANT(CURLSSH_AUTH_KEYBOARD); + REGISTER_CURL_CONSTANT(CURLSSH_AUTH_NONE); + REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PASSWORD); + REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PUBLICKEY); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */ + REGISTER_CURL_CONSTANT(CURLINFO_CERTINFO); + REGISTER_CURL_CONSTANT(CURLOPT_CERTINFO); + REGISTER_CURL_CONSTANT(CURLOPT_PASSWORD); + REGISTER_CURL_CONSTANT(CURLOPT_POSTREDIR); + REGISTER_CURL_CONSTANT(CURLOPT_PROXYPASSWORD); + REGISTER_CURL_CONSTANT(CURLOPT_PROXYUSERNAME); + REGISTER_CURL_CONSTANT(CURLOPT_USERNAME); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071303 /* Available since 7.19.3 */ + REGISTER_CURL_CONSTANT(CURLAUTH_DIGEST_IE); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */ + REGISTER_CURL_CONSTANT(CURLINFO_CONDITION_UNMET); + + REGISTER_CURL_CONSTANT(CURLOPT_NOPROXY); REGISTER_CURL_CONSTANT(CURLOPT_PROTOCOLS); - REGISTER_CURL_CONSTANT(CURLPROTO_HTTP); - REGISTER_CURL_CONSTANT(CURLPROTO_HTTPS); + REGISTER_CURL_CONSTANT(CURLOPT_REDIR_PROTOCOLS); + REGISTER_CURL_CONSTANT(CURLOPT_SOCKS5_GSSAPI_NEC); + REGISTER_CURL_CONSTANT(CURLOPT_SOCKS5_GSSAPI_SERVICE); + REGISTER_CURL_CONSTANT(CURLOPT_TFTP_BLKSIZE); + + REGISTER_CURL_CONSTANT(CURLPROTO_ALL); + REGISTER_CURL_CONSTANT(CURLPROTO_DICT); + REGISTER_CURL_CONSTANT(CURLPROTO_FILE); REGISTER_CURL_CONSTANT(CURLPROTO_FTP); REGISTER_CURL_CONSTANT(CURLPROTO_FTPS); + REGISTER_CURL_CONSTANT(CURLPROTO_HTTP); + REGISTER_CURL_CONSTANT(CURLPROTO_HTTPS); + REGISTER_CURL_CONSTANT(CURLPROTO_LDAP); + REGISTER_CURL_CONSTANT(CURLPROTO_LDAPS); REGISTER_CURL_CONSTANT(CURLPROTO_SCP); REGISTER_CURL_CONSTANT(CURLPROTO_SFTP); REGISTER_CURL_CONSTANT(CURLPROTO_TELNET); - REGISTER_CURL_CONSTANT(CURLPROTO_LDAP); - REGISTER_CURL_CONSTANT(CURLPROTO_LDAPS); - REGISTER_CURL_CONSTANT(CURLPROTO_DICT); - REGISTER_CURL_CONSTANT(CURLPROTO_FILE); REGISTER_CURL_CONSTANT(CURLPROTO_TFTP); - REGISTER_CURL_CONSTANT(CURLPROTO_ALL); #endif -#if LIBCURL_VERSION_NUM >= 0x070f01 - REGISTER_CURL_CONSTANT(CURLOPT_FTP_FILEMETHOD); - REGISTER_CURL_CONSTANT(CURLOPT_FTP_SKIP_PASV_IP); +#if LIBCURL_VERSION_NUM >= 0x071306 /* Available since 7.19.6 */ + REGISTER_CURL_CONSTANT(CURLOPT_SSH_KNOWNHOSTS); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */ + REGISTER_CURL_CONSTANT(CURLINFO_RTSP_CLIENT_CSEQ); + REGISTER_CURL_CONSTANT(CURLINFO_RTSP_CSEQ_RECV); + REGISTER_CURL_CONSTANT(CURLINFO_RTSP_SERVER_CSEQ); + REGISTER_CURL_CONSTANT(CURLINFO_RTSP_SESSION_ID); + REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_PRET); + REGISTER_CURL_CONSTANT(CURLOPT_MAIL_FROM); + REGISTER_CURL_CONSTANT(CURLOPT_MAIL_RCPT); + REGISTER_CURL_CONSTANT(CURLOPT_RTSP_CLIENT_CSEQ); + REGISTER_CURL_CONSTANT(CURLOPT_RTSP_REQUEST); + REGISTER_CURL_CONSTANT(CURLOPT_RTSP_SERVER_CSEQ); + REGISTER_CURL_CONSTANT(CURLOPT_RTSP_SESSION_ID); + REGISTER_CURL_CONSTANT(CURLOPT_RTSP_STREAM_URI); + REGISTER_CURL_CONSTANT(CURLOPT_RTSP_TRANSPORT); + REGISTER_CURL_CONSTANT(CURLPROTO_IMAP); + REGISTER_CURL_CONSTANT(CURLPROTO_IMAPS); + REGISTER_CURL_CONSTANT(CURLPROTO_POP3); + REGISTER_CURL_CONSTANT(CURLPROTO_POP3S); + REGISTER_CURL_CONSTANT(CURLPROTO_RTSP); + REGISTER_CURL_CONSTANT(CURLPROTO_SMTP); + REGISTER_CURL_CONSTANT(CURLPROTO_SMTPS); + REGISTER_CURL_CONSTANT(CURL_RTSPREQ_ANNOUNCE); + REGISTER_CURL_CONSTANT(CURL_RTSPREQ_DESCRIBE); + REGISTER_CURL_CONSTANT(CURL_RTSPREQ_GET_PARAMETER); + REGISTER_CURL_CONSTANT(CURL_RTSPREQ_OPTIONS); + REGISTER_CURL_CONSTANT(CURL_RTSPREQ_PAUSE); + REGISTER_CURL_CONSTANT(CURL_RTSPREQ_PLAY); + REGISTER_CURL_CONSTANT(CURL_RTSPREQ_RECEIVE); + REGISTER_CURL_CONSTANT(CURL_RTSPREQ_RECORD); + REGISTER_CURL_CONSTANT(CURL_RTSPREQ_SETUP); + REGISTER_CURL_CONSTANT(CURL_RTSPREQ_SET_PARAMETER); + REGISTER_CURL_CONSTANT(CURL_RTSPREQ_TEARDOWN); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ + REGISTER_CURL_CONSTANT(CURLINFO_LOCAL_IP); + REGISTER_CURL_CONSTANT(CURLINFO_LOCAL_PORT); + REGISTER_CURL_CONSTANT(CURLINFO_PRIMARY_PORT); + REGISTER_CURL_CONSTANT(CURLOPT_FNMATCH_FUNCTION); + REGISTER_CURL_CONSTANT(CURLOPT_WILDCARDMATCH); + REGISTER_CURL_CONSTANT(CURLPROTO_RTMP); + REGISTER_CURL_CONSTANT(CURLPROTO_RTMPE); + REGISTER_CURL_CONSTANT(CURLPROTO_RTMPS); + REGISTER_CURL_CONSTANT(CURLPROTO_RTMPT); + REGISTER_CURL_CONSTANT(CURLPROTO_RTMPTE); + REGISTER_CURL_CONSTANT(CURLPROTO_RTMPTS); + REGISTER_CURL_CONSTANT(CURL_FNMATCHFUNC_FAIL); + REGISTER_CURL_CONSTANT(CURL_FNMATCHFUNC_MATCH); + REGISTER_CURL_CONSTANT(CURL_FNMATCHFUNC_NOMATCH); #endif -#if LIBCURL_VERSION_NUM >= 0x071001 - REGISTER_CURL_CONSTANT(CURLFTPMETHOD_MULTICWD); - REGISTER_CURL_CONSTANT(CURLFTPMETHOD_NOCWD); - REGISTER_CURL_CONSTANT(CURLFTPMETHOD_SINGLECWD); +#if LIBCURL_VERSION_NUM >= 0x071502 /* Available since 7.21.2 */ + REGISTER_CURL_CONSTANT(CURLPROTO_GOPHER); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071503 /* Available since 7.21.3 */ + REGISTER_CURL_CONSTANT(CURLAUTH_ONLY); + REGISTER_CURL_CONSTANT(CURLOPT_RESOLVE); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071504 /* Available since 7.21.4 */ + REGISTER_CURL_CONSTANT(CURLOPT_TLSAUTH_PASSWORD); + REGISTER_CURL_CONSTANT(CURLOPT_TLSAUTH_TYPE); + REGISTER_CURL_CONSTANT(CURLOPT_TLSAUTH_USERNAME); + REGISTER_CURL_CONSTANT(CURL_TLSAUTH_SRP); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071506 /* Available since 7.21.6 */ + REGISTER_CURL_CONSTANT(CURLOPT_ACCEPT_ENCODING); + REGISTER_CURL_CONSTANT(CURLOPT_TRANSFER_ENCODING); #endif +#if LIBCURL_VERSION_NUM >= 0x071600 /* Available since 7.22.0 */ + REGISTER_CURL_CONSTANT(CURLGSSAPI_DELEGATION_FLAG); + REGISTER_CURL_CONSTANT(CURLGSSAPI_DELEGATION_POLICY_FLAG); + REGISTER_CURL_CONSTANT(CURLOPT_GSSAPI_DELEGATION); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071800 /* Available since 7.24.0 */ + REGISTER_CURL_CONSTANT(CURLOPT_ACCEPTTIMEOUT_MS); + REGISTER_CURL_CONSTANT(CURLOPT_DNS_SERVERS); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071900 /* Available since 7.25.0 */ + REGISTER_CURL_CONSTANT(CURLOPT_MAIL_AUTH); + REGISTER_CURL_CONSTANT(CURLOPT_SSL_OPTIONS); + REGISTER_CURL_CONSTANT(CURLOPT_TCP_KEEPALIVE); + REGISTER_CURL_CONSTANT(CURLOPT_TCP_KEEPIDLE); + REGISTER_CURL_CONSTANT(CURLOPT_TCP_KEEPINTVL); + REGISTER_CURL_CONSTANT(CURLSSLOPT_ALLOW_BEAST); +#endif + +#if CURLOPT_FTPASCII != 0 + REGISTER_CURL_CONSTANT(CURLOPT_FTPASCII); +#endif +#if CURLOPT_MUTE != 0 + REGISTER_CURL_CONSTANT(CURLOPT_MUTE); +#endif +#if CURLOPT_PASSWDFUNCTION != 0 + REGISTER_CURL_CONSTANT(CURLOPT_PASSWDFUNCTION); +#endif + REGISTER_CURL_CONSTANT(CURLOPT_SAFE_UPLOAD); + #ifdef PHP_CURL_NEED_OPENSSL_TSL if (!CRYPTO_get_id_callback()) { int i, c = CRYPTO_num_locks(); @@ -913,34 +1233,7 @@ PHP_MINIT_FUNCTION(curl) return FAILURE; } -#ifdef PHP_CURL_URL_WRAPPERS -# if HAVE_CURL_VERSION_INFO - { - curl_version_info_data *info = curl_version_info(CURLVERSION_NOW); - char **p = (char **)info->protocols; - - while (*p != NULL) { - /* Do not enable cURL "file" protocol and make sure cURL is always used when --with-curlwrappers is enabled */ - if (strncasecmp(*p, "file", sizeof("file")-1) != 0) { - php_unregister_url_stream_wrapper(*p TSRMLS_CC); - php_register_url_stream_wrapper(*p, &php_curl_wrapper TSRMLS_CC); - } - (void) *p++; - } - } -# else - php_unregister_url_stream_wrapper("http"); - php_register_url_stream_wrapper("http", &php_curl_wrapper TSRMLS_CC); - php_unregister_url_stream_wrapper("https"); - php_register_url_stream_wrapper("https", &php_curl_wrapper TSRMLS_CC); - php_unregister_url_stream_wrapper("ftp"); - php_register_url_stream_wrapper("ftp", &php_curl_wrapper TSRMLS_CC); - php_unregister_url_stream_wrapper("ftps"); - php_register_url_stream_wrapper("ftps", &php_curl_wrapper TSRMLS_CC); - php_unregister_url_stream_wrapper("ldap"); - php_register_url_stream_wrapper("ldap", &php_curl_wrapper TSRMLS_CC); -# endif -#endif + curlfile_register_class(TSRMLS_C); return SUCCESS; } @@ -950,12 +1243,6 @@ PHP_MINIT_FUNCTION(curl) */ PHP_MSHUTDOWN_FUNCTION(curl) { -#ifdef PHP_CURL_URL_WRAPPERS - php_unregister_url_stream_wrapper("http" TSRMLS_CC); - php_unregister_url_stream_wrapper("https" TSRMLS_CC); - php_unregister_url_stream_wrapper("ftp" TSRMLS_CC); - php_unregister_url_stream_wrapper("ldap" TSRMLS_CC); -#endif curl_global_cleanup(); #ifdef PHP_CURL_NEED_OPENSSL_TSL if (php_curl_openssl_tsl) { @@ -980,7 +1267,7 @@ PHP_MSHUTDOWN_FUNCTION(curl) /* {{{ curl_write_nothing * Used as a work around. See _php_curl_close_ex */ -static size_t curl_write_nothing(char *data, size_t size, size_t nmemb, void *ctx) +static size_t curl_write_nothing(char *data, size_t size, size_t nmemb, void *ctx) { return size * nmemb; } @@ -1062,6 +1349,71 @@ static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx) } /* }}} */ +#if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ +/* {{{ curl_fnmatch + */ +static int curl_fnmatch(void *ctx, const char *pattern, const char *string) +{ + php_curl *ch = (php_curl *) ctx; + php_curl_fnmatch *t = ch->handlers->fnmatch; + int rval = CURL_FNMATCHFUNC_FAIL; + switch (t->method) { + case PHP_CURL_USER: { + zval **argv[3]; + zval *zhandle = NULL; + zval *zpattern = NULL; + zval *zstring = NULL; + zval *retval_ptr; + int error; + zend_fcall_info fci; + TSRMLS_FETCH_FROM_CTX(ch->thread_ctx); + + MAKE_STD_ZVAL(zhandle); + MAKE_STD_ZVAL(zpattern); + MAKE_STD_ZVAL(zstring); + + ZVAL_RESOURCE(zhandle, ch->id); + zend_list_addref(ch->id); + ZVAL_STRING(zpattern, pattern, 1); + ZVAL_STRING(zstring, string, 1); + + argv[0] = &zhandle; + argv[1] = &zpattern; + argv[2] = &zstring; + + fci.size = sizeof(fci); + fci.function_table = EG(function_table); + fci.function_name = t->func_name; + fci.object_ptr = NULL; + fci.retval_ptr_ptr = &retval_ptr; + fci.param_count = 3; + fci.params = argv; + fci.no_separation = 0; + fci.symbol_table = NULL; + + ch->in_callback = 1; + error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC); + ch->in_callback = 0; + if (error == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot call the CURLOPT_FNMATCH_FUNCTION"); + } else if (retval_ptr) { + if (Z_TYPE_P(retval_ptr) != IS_LONG) { + convert_to_long_ex(&retval_ptr); + } + rval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + } + zval_ptr_dtor(argv[0]); + zval_ptr_dtor(argv[1]); + zval_ptr_dtor(argv[2]); + break; + } + } + return rval; +} +/* }}} */ +#endif + /* {{{ curl_progress */ static size_t curl_progress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) @@ -1077,7 +1429,8 @@ static size_t curl_progress(void *clientp, double dltotal, double dlnow, double switch (t->method) { case PHP_CURL_USER: { - zval **argv[4]; + zval **argv[5]; + zval *handle = NULL; zval *zdltotal = NULL; zval *zdlnow = NULL; zval *zultotal = NULL; @@ -1087,27 +1440,31 @@ static size_t curl_progress(void *clientp, double dltotal, double dlnow, double zend_fcall_info fci; TSRMLS_FETCH_FROM_CTX(ch->thread_ctx); + MAKE_STD_ZVAL(handle); MAKE_STD_ZVAL(zdltotal); MAKE_STD_ZVAL(zdlnow); MAKE_STD_ZVAL(zultotal); MAKE_STD_ZVAL(zulnow); + ZVAL_RESOURCE(handle, ch->id); + zend_list_addref(ch->id); ZVAL_LONG(zdltotal, (long) dltotal); ZVAL_LONG(zdlnow, (long) dlnow); ZVAL_LONG(zultotal, (long) ultotal); ZVAL_LONG(zulnow, (long) ulnow); - argv[0] = &zdltotal; - argv[1] = &zdlnow; - argv[2] = &zultotal; - argv[3] = &zulnow; + argv[0] = &handle; + argv[1] = &zdltotal; + argv[2] = &zdlnow; + argv[3] = &zultotal; + argv[4] = &zulnow; fci.size = sizeof(fci); fci.function_table = EG(function_table); fci.function_name = t->func_name; fci.object_ptr = NULL; fci.retval_ptr_ptr = &retval_ptr; - fci.param_count = 4; + fci.param_count = 5; fci.params = argv; fci.no_separation = 0; fci.symbol_table = NULL; @@ -1130,6 +1487,7 @@ static size_t curl_progress(void *clientp, double dltotal, double dlnow, double zval_ptr_dtor(argv[1]); zval_ptr_dtor(argv[2]); zval_ptr_dtor(argv[3]); + zval_ptr_dtor(argv[4]); break; } } @@ -1430,7 +1788,10 @@ static void alloc_curl_handle(php_curl **ch) (*ch)->handlers->write = ecalloc(1, sizeof(php_curl_write)); (*ch)->handlers->write_header = ecalloc(1, sizeof(php_curl_write)); (*ch)->handlers->read = ecalloc(1, sizeof(php_curl_read)); - (*ch)->handlers->progress = ecalloc(1, sizeof(php_curl_progress)); + (*ch)->handlers->progress = NULL; +#if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ + (*ch)->handlers->fnmatch = NULL; +#endif (*ch)->in_callback = 0; (*ch)->header.str_len = 0; @@ -1442,13 +1803,14 @@ static void alloc_curl_handle(php_curl **ch) zend_llist_init(&(*ch)->to_free->str, sizeof(char *), (llist_dtor_func_t) curl_free_string, 0); zend_llist_init(&(*ch)->to_free->post, sizeof(struct HttpPost), (llist_dtor_func_t) curl_free_post, 0); + (*ch)->safe_upload = 0; /* for now, for BC reason we allow unsafe API */ (*ch)->to_free->slist = emalloc(sizeof(HashTable)); zend_hash_init((*ch)->to_free->slist, 4, NULL, curl_free_slist, 0); } /* }}} */ -#if LIBCURL_VERSION_NUM > 0x071301 +#if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */ /* {{{ split_certinfo */ static void split_certinfo(char *string, zval *hash) @@ -1458,15 +1820,15 @@ static void split_certinfo(char *string, zval *hash) char *split; if(org) { - do { + do { char *key; char *val; char *tmp; - split = strstr(s, "; "); - if(split) - *split = '\0'; - + split = strstr(s, "; "); + if(split) + *split = '\0'; + key = s; tmp = memchr(key, '=', 64); if(tmp) { @@ -1486,13 +1848,13 @@ static void split_certinfo(char *string, zval *hash) static void create_certinfo(struct curl_certinfo *ci, zval *listcode TSRMLS_DC) { int i; - + if(ci) { zval *certhash = NULL; - + for(i=0; i<ci->num_of_certs; i++) { struct curl_slist *slist; - + MAKE_STD_ZVAL(certhash); array_init(certhash); for(slist = ci->certinfo[i]; slist; slist = slist->next) { @@ -1509,14 +1871,14 @@ static void create_certinfo(struct curl_certinfo *ci, zval *listcode TSRMLS_DC) MAKE_STD_ZVAL(hash); array_init(hash); - + split_certinfo(&slist->data[len+1], hash); add_assoc_zval(certhash, s, hash); } else { add_assoc_string(certhash, s, &slist->data[len+1], 1); } } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not extract hash key from certificate info"); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not extract hash key from certificate info"); } } add_next_index_zval(listcode, certhash); @@ -1526,6 +1888,36 @@ static void create_certinfo(struct curl_certinfo *ci, zval *listcode TSRMLS_DC) /* }}} */ #endif +/* {{{ _php_curl_set_default_options() + Set default options for a handle */ +static void _php_curl_set_default_options(php_curl *ch) +{ + char *cainfo; + + curl_easy_setopt(ch->cp, CURLOPT_NOPROGRESS, 1); + curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0); + curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER, ch->err.str); + curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write); + curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch); + curl_easy_setopt(ch->cp, CURLOPT_READFUNCTION, curl_read); + curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch); + curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_header); + curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch); + curl_easy_setopt(ch->cp, CURLOPT_DNS_USE_GLOBAL_CACHE, 1); + curl_easy_setopt(ch->cp, CURLOPT_DNS_CACHE_TIMEOUT, 120); + curl_easy_setopt(ch->cp, CURLOPT_MAXREDIRS, 20); /* prevent infinite redirects */ + + cainfo = INI_STR("curl.cainfo"); + if (cainfo && strlen(cainfo) > 0) { + curl_easy_setopt(ch->cp, CURLOPT_CAINFO, cainfo); + } + +#if defined(ZTS) + curl_easy_setopt(ch->cp, CURLOPT_NOSIGNAL, 1); +#endif +} +/* }}} */ + /* {{{ proto resource curl_init([string url]) Initialize a cURL session */ PHP_FUNCTION(curl_init) @@ -1535,7 +1927,6 @@ PHP_FUNCTION(curl_init) zval *clone; char *url = NULL; int url_len = 0; - char *cainfo; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &url, &url_len) == FAILURE) { return; @@ -1553,39 +1944,16 @@ PHP_FUNCTION(curl_init) ch->cp = cp; ch->handlers->write->method = PHP_CURL_STDOUT; - ch->handlers->write->type = PHP_CURL_ASCII; ch->handlers->read->method = PHP_CURL_DIRECT; ch->handlers->write_header->method = PHP_CURL_IGNORE; - ch->uses = 0; - MAKE_STD_ZVAL(clone); ch->clone = clone; - curl_easy_setopt(ch->cp, CURLOPT_NOPROGRESS, 1); - curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0); - curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER, ch->err.str); - curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write); - curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch); - curl_easy_setopt(ch->cp, CURLOPT_READFUNCTION, curl_read); - curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch); - curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_header); - curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch); - curl_easy_setopt(ch->cp, CURLOPT_DNS_USE_GLOBAL_CACHE, 1); - curl_easy_setopt(ch->cp, CURLOPT_DNS_CACHE_TIMEOUT, 120); - curl_easy_setopt(ch->cp, CURLOPT_MAXREDIRS, 20); /* prevent infinite redirects */ - - cainfo = INI_STR("curl.cainfo"); - if (cainfo && strlen(cainfo) > 0) { - curl_easy_setopt(ch->cp, CURLOPT_CAINFO, cainfo); - } - -#if defined(ZTS) - curl_easy_setopt(ch->cp, CURLOPT_NOSIGNAL, 1); -#endif + _php_curl_set_default_options(ch); if (url) { - if (!php_curl_option_url(ch, url, url_len TSRMLS_CC)) { + if (php_curl_option_url(ch, url, url_len TSRMLS_CC) == FAILURE) { _php_curl_close_ex(ch TSRMLS_CC); RETURN_FALSE; } @@ -1620,14 +1988,12 @@ PHP_FUNCTION(curl_copy_handle) TSRMLS_SET_CTX(dupch->thread_ctx); dupch->cp = cp; - dupch->uses = 0; - ch->uses++; + zend_list_addref(Z_LVAL_P(zid)); if (ch->handlers->write->stream) { Z_ADDREF_P(ch->handlers->write->stream); } dupch->handlers->write->stream = ch->handlers->write->stream; dupch->handlers->write->method = ch->handlers->write->method; - dupch->handlers->write->type = ch->handlers->write->type; if (ch->handlers->read->stream) { Z_ADDREF_P(ch->handlers->read->stream); } @@ -1662,18 +2028,34 @@ PHP_FUNCTION(curl_copy_handle) zval_add_ref(&ch->handlers->write_header->func_name); dupch->handlers->write_header->func_name = ch->handlers->write_header->func_name; } - - if (ch->handlers->progress->func_name) { - zval_add_ref(&ch->handlers->progress->func_name); - dupch->handlers->progress->func_name = ch->handlers->progress->func_name; - } - dupch->handlers->progress->method = ch->handlers->progress->method; curl_easy_setopt(dupch->cp, CURLOPT_ERRORBUFFER, dupch->err.str); curl_easy_setopt(dupch->cp, CURLOPT_FILE, (void *) dupch); curl_easy_setopt(dupch->cp, CURLOPT_INFILE, (void *) dupch); curl_easy_setopt(dupch->cp, CURLOPT_WRITEHEADER, (void *) dupch); - curl_easy_setopt(dupch->cp, CURLOPT_PROGRESSDATA, (void *) dupch); + + if (ch->handlers->progress) { + dupch->handlers->progress = ecalloc(1, sizeof(php_curl_progress)); + if (ch->handlers->progress->func_name) { + zval_add_ref(&ch->handlers->progress->func_name); + dupch->handlers->progress->func_name = ch->handlers->progress->func_name; + } + dupch->handlers->progress->method = ch->handlers->progress->method; + curl_easy_setopt(dupch->cp, CURLOPT_PROGRESSDATA, (void *) dupch); + } + +/* Available since 7.21.0 */ +#if LIBCURL_VERSION_NUM >= 0x071500 + if (ch->handlers->fnmatch) { + dupch->handlers->fnmatch = ecalloc(1, sizeof(php_curl_fnmatch)); + if (ch->handlers->fnmatch->func_name) { + zval_add_ref(&ch->handlers->fnmatch->func_name); + dupch->handlers->fnmatch->func_name = ch->handlers->fnmatch->func_name; + } + dupch->handlers->fnmatch->method = ch->handlers->fnmatch->method; + curl_easy_setopt(dupch->cp, CURLOPT_FNMATCH_DATA, (void *) dupch); + } +#endif efree(dupch->to_free->slist); efree(dupch->to_free); @@ -1688,7 +2070,7 @@ PHP_FUNCTION(curl_copy_handle) } /* }}} */ -static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *return_value TSRMLS_DC) /* {{{ */ +static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue TSRMLS_DC) /* {{{ */ { CURLcode error=CURLE_OK; @@ -1704,219 +2086,299 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu break; #endif } - case CURLOPT_INFILESIZE: - case CURLOPT_VERBOSE: - case CURLOPT_HEADER: - case CURLOPT_NOPROGRESS: - case CURLOPT_NOBODY: + case CURLOPT_AUTOREFERER: + case CURLOPT_BUFFERSIZE: + case CURLOPT_CLOSEPOLICY: + case CURLOPT_CONNECTTIMEOUT: + case CURLOPT_COOKIESESSION: + case CURLOPT_CRLF: + case CURLOPT_DNS_CACHE_TIMEOUT: + case CURLOPT_DNS_USE_GLOBAL_CACHE: case CURLOPT_FAILONERROR: - case CURLOPT_UPLOAD: - case CURLOPT_POST: - case CURLOPT_FTPLISTONLY: - case CURLOPT_FTPAPPEND: - case CURLOPT_NETRC: - case CURLOPT_PUT: -#if CURLOPT_MUTE != 0 - case CURLOPT_MUTE: -#endif - case CURLOPT_TIMEOUT: -#if LIBCURL_VERSION_NUM > 0x071002 - case CURLOPT_TIMEOUT_MS: -#endif + case CURLOPT_FILETIME: + case CURLOPT_FORBID_REUSE: + case CURLOPT_FRESH_CONNECT: + case CURLOPT_FTP_USE_EPRT: case CURLOPT_FTP_USE_EPSV: + case CURLOPT_HEADER: + case CURLOPT_HTTPGET: + case CURLOPT_HTTPPROXYTUNNEL: + case CURLOPT_HTTP_VERSION: + case CURLOPT_INFILESIZE: case CURLOPT_LOW_SPEED_LIMIT: - case CURLOPT_SSLVERSION: case CURLOPT_LOW_SPEED_TIME: - case CURLOPT_RESUME_FROM: - case CURLOPT_TIMEVALUE: - case CURLOPT_TIMECONDITION: - case CURLOPT_TRANSFERTEXT: - case CURLOPT_HTTPPROXYTUNNEL: - case CURLOPT_FILETIME: - case CURLOPT_MAXREDIRS: case CURLOPT_MAXCONNECTS: - case CURLOPT_CLOSEPOLICY: - case CURLOPT_FRESH_CONNECT: - case CURLOPT_FORBID_REUSE: - case CURLOPT_CONNECTTIMEOUT: -#if LIBCURL_VERSION_NUM > 0x071002 - case CURLOPT_CONNECTTIMEOUT_MS: -#endif - case CURLOPT_SSL_VERIFYPEER: - case CURLOPT_DNS_USE_GLOBAL_CACHE: + case CURLOPT_MAXREDIRS: + case CURLOPT_NETRC: + case CURLOPT_NOBODY: + case CURLOPT_NOPROGRESS: case CURLOPT_NOSIGNAL: - case CURLOPT_PROXYTYPE: - case CURLOPT_BUFFERSIZE: - case CURLOPT_HTTPGET: - case CURLOPT_HTTP_VERSION: - case CURLOPT_CRLF: - case CURLOPT_DNS_CACHE_TIMEOUT: + case CURLOPT_PORT: + case CURLOPT_POST: case CURLOPT_PROXYPORT: - case CURLOPT_FTP_USE_EPRT: -#if LIBCURL_VERSION_NUM > 0x070a05 /* CURLOPT_HTTPAUTH is available since curl 7.10.6 */ + case CURLOPT_PROXYTYPE: + case CURLOPT_PUT: + case CURLOPT_RESUME_FROM: + case CURLOPT_SSLVERSION: + case CURLOPT_SSL_VERIFYPEER: + case CURLOPT_TIMECONDITION: + case CURLOPT_TIMEOUT: + case CURLOPT_TIMEVALUE: + case CURLOPT_TRANSFERTEXT: + case CURLOPT_UNRESTRICTED_AUTH: + case CURLOPT_UPLOAD: + case CURLOPT_VERBOSE: +#if LIBCURL_VERSION_NUM >= 0x070a06 /* Available since 7.10.6 */ case CURLOPT_HTTPAUTH: #endif -#if LIBCURL_VERSION_NUM > 0x070a06 /* CURLOPT_PROXYAUTH & CURLOPT_FTP_CREATE_MISSING_DIRS are available since curl 7.10.7 */ - case CURLOPT_PROXYAUTH: +#if LIBCURL_VERSION_NUM >= 0x070a07 /* Available since 7.10.7 */ case CURLOPT_FTP_CREATE_MISSING_DIRS: + case CURLOPT_PROXYAUTH: #endif - -#if LIBCURL_VERSION_NUM >= 0x070c02 +#if LIBCURL_VERSION_NUM >= 0x070a08 /* Available since 7.10.8 */ + case CURLOPT_FTP_RESPONSE_TIMEOUT: + case CURLOPT_IPRESOLVE: + case CURLOPT_MAXFILESIZE: +#endif +#if LIBCURL_VERSION_NUM >= 0x070b02 /* Available since 7.11.2 */ + case CURLOPT_TCP_NODELAY: +#endif +#if LIBCURL_VERSION_NUM >= 0x070c02 /* Available since 7.12.2 */ case CURLOPT_FTPSSLAUTH: #endif -#if LIBCURL_VERSION_NUM > 0x070b00 +#if LIBCURL_VERSION_NUM >= 0x070e01 /* Available since 7.14.1 */ + case CURLOPT_IGNORE_CONTENT_LENGTH: +#endif +#if LIBCURL_VERSION_NUM >= 0x070f00 /* Available since 7.15.0 */ + case CURLOPT_FTP_SKIP_PASV_IP: +#endif +#if LIBCURL_VERSION_NUM >= 0x070f01 /* Available since 7.15.1 */ + case CURLOPT_FTP_FILEMETHOD: +#endif +#if LIBCURL_VERSION_NUM >= 0x070f02 /* Available since 7.15.2 */ + case CURLOPT_CONNECT_ONLY: + case CURLOPT_LOCALPORT: + case CURLOPT_LOCALPORTRANGE: +#endif +#if LIBCURL_VERSION_NUM >= 0x071000 /* Available since 7.16.0 */ + case CURLOPT_SSL_SESSIONID_CACHE: +#endif +#if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */ + case CURLOPT_FTP_SSL_CCC: + case CURLOPT_SSH_AUTH_TYPES: +#endif +#if LIBCURL_VERSION_NUM >= 0x071002 /* Available since 7.16.2 */ + case CURLOPT_CONNECTTIMEOUT_MS: + case CURLOPT_HTTP_CONTENT_DECODING: + case CURLOPT_HTTP_TRANSFER_DECODING: + case CURLOPT_TIMEOUT_MS: +#endif +#if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */ + case CURLOPT_NEW_DIRECTORY_PERMS: + case CURLOPT_NEW_FILE_PERMS: +#endif +#if LIBCURL_VERSION_NUM >= 0x071100 /* Available since 7.17.0 */ + case CURLOPT_USE_SSL: +#elif LIBCURL_VERSION_NUM >= 0x070b00 /* Available since 7.11.0 */ case CURLOPT_FTP_SSL: #endif - case CURLOPT_UNRESTRICTED_AUTH: - case CURLOPT_PORT: - case CURLOPT_AUTOREFERER: - case CURLOPT_COOKIESESSION: -#if LIBCURL_VERSION_NUM > 0x070b01 /* CURLOPT_TCP_NODELAY is available since curl 7.11.2 */ - case CURLOPT_TCP_NODELAY: +#if LIBCURL_VERSION_NUM >= 0x071100 /* Available since 7.17.0 */ + case CURLOPT_APPEND: + case CURLOPT_DIRLISTONLY: +#else + case CURLOPT_FTPAPPEND: + case CURLOPT_FTPLISTONLY: #endif -#if LIBCURL_VERSION_NUM >= 0x71304 - case CURLOPT_REDIR_PROTOCOLS: +#if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */ + case CURLOPT_PROXY_TRANSFER_MODE: +#endif +#if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */ + case CURLOPT_ADDRESS_SCOPE: +#endif +#if LIBCURL_VERSION_NUM > 0x071301 /* Available since 7.19.1 */ + case CURLOPT_CERTINFO: +#endif +#if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */ + case CURLOPT_NOPROXY: case CURLOPT_PROTOCOLS: + case CURLOPT_REDIR_PROTOCOLS: + case CURLOPT_SOCKS5_GSSAPI_NEC: + case CURLOPT_TFTP_BLKSIZE: #endif -#if LIBCURL_VERSION_NUM > 0x070a07 /* CURLOPT_IPRESOLVE is available since curl 7.10.8 */ - case CURLOPT_IPRESOLVE: +#if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */ + case CURLOPT_FTP_USE_PRET: + case CURLOPT_RTSP_CLIENT_CSEQ: + case CURLOPT_RTSP_REQUEST: + case CURLOPT_RTSP_SERVER_CSEQ: #endif -#if LIBCURL_VERSION_NUM >= 0x070f01 - case CURLOPT_FTP_FILEMETHOD: - case CURLOPT_FTP_SKIP_PASV_IP: +#if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ + case CURLOPT_WILDCARDMATCH: #endif -#if LIBCURL_VERSION_NUM > 0x071301 - case CURLOPT_CERTINFO: +#if LIBCURL_VERSION_NUM >= 0x071504 /* Available since 7.21.4 */ + case CURLOPT_TLSAUTH_TYPE: +#endif +#if LIBCURL_VERSION_NUM >= 0x071600 /* Available since 7.22.0 */ + case CURLOPT_GSSAPI_DELEGATION: +#endif +#if LIBCURL_VERSION_NUM >= 0x071800 /* Available since 7.24.0 */ + case CURLOPT_ACCEPTTIMEOUT_MS: +#endif +#if LIBCURL_VERSION_NUM >= 0x071900 /* Available since 7.25.0 */ + case CURLOPT_SSL_OPTIONS: + case CURLOPT_TCP_KEEPALIVE: + case CURLOPT_TCP_KEEPIDLE: + case CURLOPT_TCP_KEEPINTVL: +#endif +#if CURLOPT_MUTE != 0 + case CURLOPT_MUTE: #endif convert_to_long_ex(zvalue); #if LIBCURL_VERSION_NUM >= 0x71304 if ((option == CURLOPT_PROTOCOLS || option == CURLOPT_REDIR_PROTOCOLS) && (PG(open_basedir) && *PG(open_basedir)) && (Z_LVAL_PP(zvalue) & CURLPROTO_FILE)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLPROTO_FILE cannot be activated when an open_basedir is set"); - RETVAL_FALSE; return 1; } #endif error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue)); break; -#if LIBCURL_VERSION_NUM > 0x070f04 - case CURLOPT_MAX_RECV_SPEED_LARGE: - case CURLOPT_MAX_SEND_SPEED_LARGE: - convert_to_long_ex(zvalue); - error = curl_easy_setopt(ch->cp, option, (curl_off_t)Z_LVAL_PP(zvalue)); - break; -#endif - case CURLOPT_FOLLOWLOCATION: - convert_to_long_ex(zvalue); - if (PG(open_basedir) && *PG(open_basedir)) { - if (Z_LVAL_PP(zvalue) != 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set"); - RETVAL_FALSE; - return 1; - } - } - error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue)); - break; -#if LIBCURL_VERSION_NUM > 0x071301 - case CURLOPT_POSTREDIR: + case CURLOPT_SAFE_UPLOAD: convert_to_long_ex(zvalue); - error = curl_easy_setopt(ch->cp, CURLOPT_POSTREDIR, Z_LVAL_PP(zvalue) & CURL_REDIR_POST_ALL); + ch->safe_upload = (Z_LVAL_PP(zvalue) != 0); break; -#endif - case CURLOPT_PRIVATE: - case CURLOPT_URL: + + /* String options */ + case CURLOPT_CAINFO: + case CURLOPT_CAPATH: + case CURLOPT_COOKIE: + case CURLOPT_EGDSOCKET: + case CURLOPT_INTERFACE: case CURLOPT_PROXY: - case CURLOPT_USERPWD: case CURLOPT_PROXYUSERPWD: - case CURLOPT_RANGE: - case CURLOPT_CUSTOMREQUEST: - case CURLOPT_USERAGENT: - case CURLOPT_FTPPORT: - case CURLOPT_COOKIE: case CURLOPT_REFERER: - case CURLOPT_INTERFACE: - case CURLOPT_KRB4LEVEL: - case CURLOPT_EGDSOCKET: - case CURLOPT_CAINFO: - case CURLOPT_CAPATH: - case CURLOPT_SSL_CIPHER_LIST: - case CURLOPT_SSLKEY: - case CURLOPT_SSLKEYTYPE: - case CURLOPT_SSLKEYPASSWD: + case CURLOPT_SSLCERTTYPE: case CURLOPT_SSLENGINE: case CURLOPT_SSLENGINE_DEFAULT: - case CURLOPT_SSLCERTTYPE: + case CURLOPT_SSLKEY: + case CURLOPT_SSLKEYPASSWD: + case CURLOPT_SSLKEYTYPE: + case CURLOPT_SSL_CIPHER_LIST: + case CURLOPT_USERAGENT: + case CURLOPT_USERPWD: +#if LIBCURL_VERSION_NUM >= 0x070e01 /* Available since 7.14.1 */ + case CURLOPT_COOKIELIST: +#endif +#if LIBCURL_VERSION_NUM >= 0x070f05 /* Available since 7.15.5 */ + case CURLOPT_FTP_ALTERNATIVE_TO_USER: +#endif +#if LIBCURL_VERSION_NUM >= 0x071101 /* Available since 7.17.1 */ + case CURLOPT_SSH_HOST_PUBLIC_KEY_MD5: +#endif +#if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */ + case CURLOPT_PASSWORD: + case CURLOPT_PROXYPASSWORD: + case CURLOPT_PROXYUSERNAME: + case CURLOPT_USERNAME: +#endif +#if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */ + case CURLOPT_SOCKS5_GSSAPI_SERVICE: +#endif +#if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */ + case CURLOPT_MAIL_FROM: + case CURLOPT_RTSP_STREAM_URI: + case CURLOPT_RTSP_TRANSPORT: +#endif +#if LIBCURL_VERSION_NUM >= 0x071504 /* Available since 7.21.4 */ + case CURLOPT_TLSAUTH_PASSWORD: + case CURLOPT_TLSAUTH_USERNAME: +#endif +#if LIBCURL_VERSION_NUM >= 0x071506 /* Available since 7.21.6 */ + case CURLOPT_ACCEPT_ENCODING: + case CURLOPT_TRANSFER_ENCODING: +#else case CURLOPT_ENCODING: -#if LIBCURL_VERSION_NUM >= 0x071300 - case CURLOPT_SSH_PUBLIC_KEYFILE: - case CURLOPT_SSH_PRIVATE_KEYFILE: +#endif +#if LIBCURL_VERSION_NUM >= 0x071800 /* Available since 7.24.0 */ + case CURLOPT_DNS_SERVERS: +#endif +#if LIBCURL_VERSION_NUM >= 0x071900 /* Available since 7.25.0 */ + case CURLOPT_MAIL_AUTH: #endif { convert_to_string_ex(zvalue); -#if LIBCURL_VERSION_NUM >= 0x071300 - if ( - option == CURLOPT_SSH_PUBLIC_KEYFILE || option == CURLOPT_SSH_PRIVATE_KEYFILE + return php_curl_option_str(ch, option, Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue), 0 TSRMLS_CC); + } - ) { - if (php_check_open_basedir(Z_STRVAL_PP(zvalue) TSRMLS_CC)) { - RETVAL_FALSE; - return 1; - } - } + /* Curl nullable string options */ + case CURLOPT_CUSTOMREQUEST: + case CURLOPT_FTPPORT: + case CURLOPT_RANGE: +#if LIBCURL_VERSION_NUM >= 0x070d00 /* Available since 7.13.0 */ + case CURLOPT_FTP_ACCOUNT: #endif - if (option == CURLOPT_URL) { - if (!php_curl_option_url(ch, Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue) TSRMLS_CC)) { - RETVAL_FALSE; - return 1; - } - } else { - if (option == CURLOPT_PRIVATE) { - char *copystr; -#if LIBCURL_VERSION_NUM < 0x071100 -string_copy: -#endif - copystr = estrndup(Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue)); - error = curl_easy_setopt(ch->cp, option, copystr); - zend_llist_add_element(&ch->to_free->str, ©str); - } else { -#if LIBCURL_VERSION_NUM >= 0x071100 - /* Strings passed to libcurl as ’char *’ arguments, are copied by the library... NOTE: before 7.17.0 strings were not copied. */ - error = curl_easy_setopt(ch->cp, option, Z_STRVAL_PP(zvalue)); -#else - goto string_copy; +#if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */ + case CURLOPT_RTSP_SESSION_ID: #endif - } +#if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */ + case CURLOPT_KRBLEVEL: +#else + case CURLOPT_KRB4LEVEL: +#endif + { + if (Z_TYPE_PP(zvalue) == IS_NULL) { + error = curl_easy_setopt(ch->cp, option, NULL); + } else { + convert_to_string_ex(zvalue); + return php_curl_option_str(ch, option, Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue), 0 TSRMLS_CC); } break; } + + /* Curl private option */ + case CURLOPT_PRIVATE: + convert_to_string_ex(zvalue); + return php_curl_option_str(ch, option, Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue), 1 TSRMLS_CC); + + /* Curl url option */ + case CURLOPT_URL: + convert_to_string_ex(zvalue); + return php_curl_option_url(ch, Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue) TSRMLS_CC); + + /* Curl file handle options */ case CURLOPT_FILE: case CURLOPT_INFILE: - case CURLOPT_WRITEHEADER: - case CURLOPT_STDERR: { + case CURLOPT_STDERR: + case CURLOPT_WRITEHEADER: { FILE *fp = NULL; int type; - void * what; + void *what = NULL; - what = zend_fetch_resource(zvalue TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream(), php_file_le_pstream()); - if (!what) { - RETVAL_FALSE; - return 1; - } + if (Z_TYPE_PP(zvalue) != IS_NULL) { + what = zend_fetch_resource(zvalue TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream(), php_file_le_pstream()); + if (!what) { + return FAILURE; + } - if (FAILURE == php_stream_cast((php_stream *) what, PHP_STREAM_AS_STDIO, (void *) &fp, REPORT_ERRORS)) { - RETVAL_FALSE; - return 1; - } + if (FAILURE == php_stream_cast((php_stream *) what, PHP_STREAM_AS_STDIO, (void *) &fp, REPORT_ERRORS)) { + return FAILURE; + } - if (!fp) { - RETVAL_FALSE; - return 1; + if (!fp) { + return FAILURE; + } } error = CURLE_OK; switch (option) { case CURLOPT_FILE: - if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') { + if (!what) { + if (ch->handlers->write->stream) { + Z_DELREF_P(ch->handlers->write->stream); + ch->handlers->write->stream = NULL; + } + ch->handlers->write->fp = NULL; + ch->handlers->write->method = PHP_CURL_STDOUT; + } else if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') { if (ch->handlers->write->stream) { Z_DELREF_P(ch->handlers->write->stream); } @@ -1926,12 +2388,18 @@ string_copy: ch->handlers->write->stream = *zvalue; } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable"); - RETVAL_FALSE; - return 1; + return FAILURE; } break; case CURLOPT_WRITEHEADER: - if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') { + if (!what) { + if (ch->handlers->write_header->stream) { + Z_DELREF_P(ch->handlers->write_header->stream); + ch->handlers->write_header->stream = NULL; + } + ch->handlers->write_header->fp = NULL; + ch->handlers->write_header->method = PHP_CURL_IGNORE; + } else if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') { if (ch->handlers->write_header->stream) { Z_DELREF_P(ch->handlers->write_header->stream); } @@ -1941,21 +2409,34 @@ string_copy: ch->handlers->write_header->stream = *zvalue; } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable"); - RETVAL_FALSE; - return 1; + return FAILURE; } break; case CURLOPT_INFILE: - if (ch->handlers->read->stream) { - Z_DELREF_P(ch->handlers->read->stream); + if (!what) { + if (ch->handlers->read->stream) { + Z_DELREF_P(ch->handlers->read->stream); + ch->handlers->read->stream = NULL; + } + ch->handlers->read->fp = NULL; + ch->handlers->read->fd = 0; + } else { + if (ch->handlers->read->stream) { + Z_DELREF_P(ch->handlers->read->stream); + } + Z_ADDREF_PP(zvalue); + ch->handlers->read->fp = fp; + ch->handlers->read->fd = Z_LVAL_PP(zvalue); + ch->handlers->read->stream = *zvalue; } - Z_ADDREF_PP(zvalue); - ch->handlers->read->fp = fp; - ch->handlers->read->fd = Z_LVAL_PP(zvalue); - ch->handlers->read->stream = *zvalue; break; case CURLOPT_STDERR: - if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') { + if (!what) { + if (ch->handlers->std_err) { + zval_ptr_dtor(&ch->handlers->std_err); + ch->handlers->std_err = NULL; + } + } else if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') { if (ch->handlers->std_err) { zval_ptr_dtor(&ch->handlers->std_err); } @@ -1963,64 +2444,106 @@ string_copy: ch->handlers->std_err = *zvalue; } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable"); - RETVAL_FALSE; - return 1; + return FAILURE; } /* break omitted intentionally */ default: error = curl_easy_setopt(ch->cp, option, fp); break; } - break; } - case CURLOPT_RETURNTRANSFER: - convert_to_long_ex(zvalue); - if (Z_LVAL_PP(zvalue)) { - ch->handlers->write->method = PHP_CURL_RETURN; - } else { - ch->handlers->write->method = PHP_CURL_STDOUT; - } - break; - case CURLOPT_BINARYTRANSFER: - convert_to_long_ex(zvalue); + /* Curl linked list options */ + case CURLOPT_HTTP200ALIASES: + case CURLOPT_HTTPHEADER: + case CURLOPT_POSTQUOTE: + case CURLOPT_PREQUOTE: + case CURLOPT_QUOTE: + case CURLOPT_TELNETOPTIONS: +#if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */ + case CURLOPT_MAIL_RCPT: +#endif +#if LIBCURL_VERSION_NUM >= 0x071503 /* Available since 7.21.3 */ + case CURLOPT_RESOLVE: +#endif + { + zval **current; + HashTable *ph; + struct curl_slist *slist = NULL; - if (Z_LVAL_PP(zvalue)) { - ch->handlers->write->type = PHP_CURL_BINARY; - } else { - ch->handlers->write->type = PHP_CURL_ASCII; + ph = HASH_OF(*zvalue); + if (!ph) { + char *name = NULL; + switch (option) { + case CURLOPT_HTTPHEADER: + name = "CURLOPT_HTTPHEADER"; + break; + case CURLOPT_QUOTE: + name = "CURLOPT_QUOTE"; + break; + case CURLOPT_HTTP200ALIASES: + name = "CURLOPT_HTTP200ALIASES"; + break; + case CURLOPT_POSTQUOTE: + name = "CURLOPT_POSTQUOTE"; + break; + case CURLOPT_PREQUOTE: + name = "CURLOPT_PREQUOTE"; + break; + case CURLOPT_TELNETOPTIONS: + name = "CURLOPT_TELNETOPTIONS"; + break; +#if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */ + case CURLOPT_MAIL_RCPT: + name = "CURLOPT_MAIL_RCPT"; + break; +#endif +#if LIBCURL_VERSION_NUM >= 0x071503 /* Available since 7.21.3 */ + case CURLOPT_RESOLVE: + name = "CURLOPT_RESOLVE"; + break; +#endif + } + php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must pass either an object or an array with the %s argument", name); + return FAILURE; } - break; - case CURLOPT_WRITEFUNCTION: - if (ch->handlers->write->func_name) { - zval_ptr_dtor(&ch->handlers->write->func_name); - ch->handlers->write->fci_cache = empty_fcall_info_cache; + + for (zend_hash_internal_pointer_reset(ph); + zend_hash_get_current_data(ph, (void **) ¤t) == SUCCESS; + zend_hash_move_forward(ph) + ) { + SEPARATE_ZVAL(current); + convert_to_string_ex(current); + + slist = curl_slist_append(slist, Z_STRVAL_PP(current)); + if (!slist) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not build curl_slist"); + return 1; + } } - zval_add_ref(zvalue); - ch->handlers->write->func_name = *zvalue; - ch->handlers->write->method = PHP_CURL_USER; + zend_hash_index_update(ch->to_free->slist, (ulong) option, &slist, sizeof(struct curl_slist *), NULL); + + error = curl_easy_setopt(ch->cp, option, slist); + break; - case CURLOPT_READFUNCTION: - if (ch->handlers->read->func_name) { - zval_ptr_dtor(&ch->handlers->read->func_name); - ch->handlers->read->fci_cache = empty_fcall_info_cache; - } - zval_add_ref(zvalue); - ch->handlers->read->func_name = *zvalue; - ch->handlers->read->method = PHP_CURL_USER; + } + + case CURLOPT_BINARYTRANSFER: + /* Do nothing, just backward compatibility */ break; - case CURLOPT_PROGRESSFUNCTION: - curl_easy_setopt(ch->cp, CURLOPT_PROGRESSFUNCTION, curl_progress); - curl_easy_setopt(ch->cp, CURLOPT_PROGRESSDATA, ch); - if (ch->handlers->progress->func_name) { - zval_ptr_dtor(&ch->handlers->progress->func_name); - ch->handlers->progress->fci_cache = empty_fcall_info_cache; + + case CURLOPT_FOLLOWLOCATION: + convert_to_long_ex(zvalue); + if (PG(open_basedir) && *PG(open_basedir)) { + if (Z_LVAL_PP(zvalue) != 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set"); + return FAILURE; + } } - zval_add_ref(zvalue); - ch->handlers->progress->func_name = *zvalue; - ch->handlers->progress->method = PHP_CURL_USER; + error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue)); break; + case CURLOPT_HEADERFUNCTION: if (ch->handlers->write_header->func_name) { zval_ptr_dtor(&ch->handlers->write_header->func_name); @@ -2030,17 +2553,7 @@ string_copy: ch->handlers->write_header->func_name = *zvalue; ch->handlers->write_header->method = PHP_CURL_USER; break; -#if CURLOPT_PASSWDFUNCTION != 0 - case CURLOPT_PASSWDFUNCTION: - if (ch->handlers->passwd) { - zval_ptr_dtor(&ch->handlers->passwd); - } - zval_add_ref(zvalue); - ch->handlers->passwd = *zvalue; - error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDFUNCTION, curl_passwd); - error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDDATA, (void *) ch); - break; -#endif + case CURLOPT_POSTFIELDS: if (Z_TYPE_PP(zvalue) == IS_ARRAY || Z_TYPE_PP(zvalue) == IS_OBJECT) { zval **current; @@ -2051,22 +2564,18 @@ string_copy: postfields = HASH_OF(*zvalue); if (!postfields) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't get HashTable in CURLOPT_POSTFIELDS"); - RETVAL_FALSE; - return 1; + return FAILURE; } for (zend_hash_internal_pointer_reset(postfields); zend_hash_get_current_data(postfields, (void **) ¤t) == SUCCESS; zend_hash_move_forward(postfields) ) { - char *postval; - char *string_key = NULL; - uint string_key_len; - ulong num_key; - int numeric_key; - - SEPARATE_ZVAL(current); - convert_to_string_ex(current); + char *postval; + char *string_key = NULL; + uint string_key_len; + ulong num_key; + int numeric_key; zend_hash_get_current_key_ex(postfields, &string_key, &string_key_len, &num_key, 0, NULL); @@ -2079,15 +2588,58 @@ string_copy: numeric_key = 0; } + if(Z_TYPE_PP(current) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(current), curl_CURLFile_class TSRMLS_CC)) { + /* new-style file upload */ + zval *prop; + char *type = NULL, *filename = NULL; + + prop = zend_read_property(curl_CURLFile_class, *current, "name", sizeof("name")-1, 0 TSRMLS_CC); + if(Z_TYPE_P(prop) != IS_STRING) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid filename for key %s", string_key); + } else { + postval = Z_STRVAL_P(prop); + + if (php_check_open_basedir(postval TSRMLS_CC)) { + return 1; + } + + prop = zend_read_property(curl_CURLFile_class, *current, "mime", sizeof("mime")-1, 0 TSRMLS_CC); + if(Z_TYPE_P(prop) == IS_STRING && Z_STRLEN_P(prop) > 0) { + type = Z_STRVAL_P(prop); + } + prop = zend_read_property(curl_CURLFile_class, *current, "postname", sizeof("postname")-1, 0 TSRMLS_CC); + if(Z_TYPE_P(prop) == IS_STRING && Z_STRLEN_P(prop) > 0) { + filename = Z_STRVAL_P(prop); + } + error = curl_formadd(&first, &last, + CURLFORM_COPYNAME, string_key, + CURLFORM_NAMELENGTH, (long)string_key_len - 1, + CURLFORM_FILENAME, filename ? filename : postval, + CURLFORM_CONTENTTYPE, type ? type : "application/octet-stream", + CURLFORM_FILE, postval, + CURLFORM_END); + } + + if (numeric_key) { + efree(string_key); + } + continue; + } + + SEPARATE_ZVAL(current); + convert_to_string_ex(current); + postval = Z_STRVAL_PP(current); /* The arguments after _NAMELENGTH and _CONTENTSLENGTH * must be explicitly cast to long in curl_formadd * use since curl needs a long not an int. */ - if (*postval == '@') { + if (!ch->safe_upload && *postval == '@') { char *type, *filename; ++postval; + php_error_docref("curl.curlfile" TSRMLS_CC, E_DEPRECATED, "The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead"); + if ((type = php_memnstr(postval, ";type=", sizeof(";type=") - 1, postval + Z_STRLEN_PP(current)))) { *type = '\0'; } @@ -2096,8 +2648,7 @@ string_copy: } /* open_basedir check */ if (php_check_open_basedir(postval TSRMLS_CC)) { - RETVAL_FALSE; - return 1; + return FAILURE; } error = curl_formadd(&first, &last, CURLFORM_COPYNAME, string_key, @@ -2128,8 +2679,7 @@ string_copy: SAVE_CURL_ERROR(ch, error); if (error != CURLE_OK) { - RETVAL_FALSE; - return 1; + return FAILURE; } if (Z_REFCOUNT_P(ch->clone) <= 1) { @@ -2151,74 +2701,113 @@ string_copy: post = estrndup(Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue)); zend_llist_add_element(&ch->to_free->str, &post); - error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, post); + curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, post); error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, Z_STRLEN_PP(zvalue)); #endif } break; - case CURLOPT_HTTPHEADER: - case CURLOPT_QUOTE: - case CURLOPT_HTTP200ALIASES: - case CURLOPT_POSTQUOTE: { - zval **current; - HashTable *ph; - struct curl_slist *slist = NULL; - ph = HASH_OF(*zvalue); - if (!ph) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must pass either an object or an array with the CURLOPT_HTTPHEADER, CURLOPT_QUOTE, CURLOPT_HTTP200ALIASES and CURLOPT_POSTQUOTE arguments"); - RETVAL_FALSE; - return 1; + case CURLOPT_PROGRESSFUNCTION: + curl_easy_setopt(ch->cp, CURLOPT_PROGRESSFUNCTION, curl_progress); + curl_easy_setopt(ch->cp, CURLOPT_PROGRESSDATA, ch); + if (ch->handlers->progress == NULL) { + ch->handlers->progress = ecalloc(1, sizeof(php_curl_progress)); + } else if (ch->handlers->progress->func_name) { + zval_ptr_dtor(&ch->handlers->progress->func_name); + ch->handlers->progress->fci_cache = empty_fcall_info_cache; } + zval_add_ref(zvalue); + ch->handlers->progress->func_name = *zvalue; + ch->handlers->progress->method = PHP_CURL_USER; + break; - for (zend_hash_internal_pointer_reset(ph); - zend_hash_get_current_data(ph, (void **) ¤t) == SUCCESS; - zend_hash_move_forward(ph) - ) { - SEPARATE_ZVAL(current); - convert_to_string_ex(current); + case CURLOPT_READFUNCTION: + if (ch->handlers->read->func_name) { + zval_ptr_dtor(&ch->handlers->read->func_name); + ch->handlers->read->fci_cache = empty_fcall_info_cache; + } + zval_add_ref(zvalue); + ch->handlers->read->func_name = *zvalue; + ch->handlers->read->method = PHP_CURL_USER; + break; - slist = curl_slist_append(slist, Z_STRVAL_PP(current)); - if (!slist) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not build curl_slist"); - RETVAL_FALSE; - return 1; - } + case CURLOPT_RETURNTRANSFER: + convert_to_long_ex(zvalue); + if (Z_LVAL_PP(zvalue)) { + ch->handlers->write->method = PHP_CURL_RETURN; + } else { + ch->handlers->write->method = PHP_CURL_STDOUT; } - zend_hash_index_update(ch->to_free->slist, (ulong) option, &slist, sizeof(struct curl_slist *), NULL); + break; - error = curl_easy_setopt(ch->cp, option, slist); + case CURLOPT_WRITEFUNCTION: + if (ch->handlers->write->func_name) { + zval_ptr_dtor(&ch->handlers->write->func_name); + ch->handlers->write->fci_cache = empty_fcall_info_cache; + } + zval_add_ref(zvalue); + ch->handlers->write->func_name = *zvalue; + ch->handlers->write->method = PHP_CURL_USER; + break; + +#if LIBCURL_VERSION_NUM >= 0x070f05 /* Available since 7.15.5 */ + case CURLOPT_MAX_RECV_SPEED_LARGE: + case CURLOPT_MAX_SEND_SPEED_LARGE: + convert_to_long_ex(zvalue); + error = curl_easy_setopt(ch->cp, option, (curl_off_t)Z_LVAL_PP(zvalue)); + break; +#endif +#if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */ + case CURLOPT_POSTREDIR: + convert_to_long_ex(zvalue); + error = curl_easy_setopt(ch->cp, CURLOPT_POSTREDIR, Z_LVAL_PP(zvalue) & CURL_REDIR_POST_ALL); break; - } +#endif + +#if CURLOPT_PASSWDFUNCTION != 0 + case CURLOPT_PASSWDFUNCTION: + if (ch->handlers->passwd) { + zval_ptr_dtor(&ch->handlers->passwd); + } + zval_add_ref(zvalue); + ch->handlers->passwd = *zvalue; + error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDFUNCTION, curl_passwd); + error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDDATA, (void *) ch); + break; +#endif + /* the following options deal with files, therefore the open_basedir check * is required. */ + case CURLOPT_COOKIEFILE: case CURLOPT_COOKIEJAR: - case CURLOPT_SSLCERT: case CURLOPT_RANDOM_FILE: - case CURLOPT_COOKIEFILE: { -#if LIBCURL_VERSION_NUM < 0x071100 - char *copystr = NULL; + case CURLOPT_SSLCERT: +#if LIBCURL_VERSION_NUM >= 0x070b00 /* Available since 7.11.0 */ + case CURLOPT_NETRC_FILE: #endif - +#if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */ + case CURLOPT_SSH_PRIVATE_KEYFILE: + case CURLOPT_SSH_PUBLIC_KEYFILE: +#endif +#if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */ + case CURLOPT_CRLFILE: + case CURLOPT_ISSUERCERT: +#endif +#if LIBCURL_VERSION_NUM >= 0x071306 /* Available since 7.19.6 */ + case CURLOPT_SSH_KNOWNHOSTS: +#endif + { convert_to_string_ex(zvalue); if (Z_STRLEN_PP(zvalue) && php_check_open_basedir(Z_STRVAL_PP(zvalue) TSRMLS_CC)) { - RETVAL_FALSE; - return 1; + return FAILURE; } -#if LIBCURL_VERSION_NUM >= 0x071100 - error = curl_easy_setopt(ch->cp, option, Z_STRVAL_PP(zvalue)); -#else - copystr = estrndup(Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue)); - - error = curl_easy_setopt(ch->cp, option, copystr); - zend_llist_add_element(&ch->to_free->str, ©str); -#endif - break; + return php_curl_option_str(ch, option, Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue), 0 TSRMLS_CC); } + case CURLINFO_HEADER_OUT: convert_to_long_ex(zvalue); if (Z_LVAL_PP(zvalue) == 1) { @@ -2231,13 +2820,39 @@ string_copy: curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0); } break; + + case CURLOPT_SHARE: + { + php_curlsh *sh = NULL; + ZEND_FETCH_RESOURCE_NO_RETURN(sh, php_curlsh *, zvalue, -1, le_curl_share_handle_name, le_curl_share_handle); + if (sh) { + curl_easy_setopt(ch->cp, CURLOPT_SHARE, sh->share); + } + } + +#if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ + case CURLOPT_FNMATCH_FUNCTION: + curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_FUNCTION, curl_fnmatch); + curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_DATA, ch); + if (ch->handlers->fnmatch == NULL) { + ch->handlers->fnmatch = ecalloc(1, sizeof(php_curl_fnmatch)); + } else if (ch->handlers->fnmatch->func_name) { + zval_ptr_dtor(&ch->handlers->fnmatch->func_name); + ch->handlers->fnmatch->fci_cache = empty_fcall_info_cache; + } + zval_add_ref(zvalue); + ch->handlers->fnmatch->func_name = *zvalue; + ch->handlers->fnmatch->method = PHP_CURL_USER; + break; +#endif + } SAVE_CURL_ERROR(ch, error); if (error != CURLE_OK) { - return 1; + return FAILURE; } else { - return 0; + return SUCCESS; } } /* }}} */ @@ -2256,12 +2871,12 @@ PHP_FUNCTION(curl_setopt) ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl); - if (options <= 0) { + if (options <= 0 && options != CURLOPT_SAFE_UPLOAD) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid curl configuration option"); RETURN_FALSE; } - if (!_php_curl_setopt(ch, options, zvalue, return_value TSRMLS_CC)) { + if (_php_curl_setopt(ch, options, zvalue TSRMLS_CC) == SUCCESS) { RETURN_TRUE; } else { RETURN_FALSE; @@ -2292,7 +2907,7 @@ PHP_FUNCTION(curl_setopt_array) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array keys must be CURLOPT constants or equivalent integer values"); RETURN_FALSE; } - if (_php_curl_setopt(ch, (long) option, entry, return_value TSRMLS_CC)) { + if (_php_curl_setopt(ch, (long) option, entry TSRMLS_CC) == FAILURE) { RETURN_FALSE; } zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos); @@ -2467,7 +3082,17 @@ PHP_FUNCTION(curl_getinfo) if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME, &d_code) == CURLE_OK) { CAAD("redirect_time", d_code); } -#if LIBCURL_VERSION_NUM > 0x071301 +#if LIBCURL_VERSION_NUM >= 0x071202 /* Available since 7.18.2 */ + if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_URL, &s_code) == CURLE_OK) { + CAAS("redirect_url", s_code); + } +#endif +#if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */ + if (curl_easy_getinfo(ch->cp, CURLINFO_PRIMARY_IP, &s_code) == CURLE_OK) { + CAAS("primary_ip", s_code); + } +#endif +#if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */ if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) { MAKE_STD_ZVAL(listcode); array_init(listcode); @@ -2475,12 +3100,7 @@ PHP_FUNCTION(curl_getinfo) CAAZ("certinfo", listcode); } #endif -#if LIBCURL_VERSION_NUM >= 0x071300 /* 7.19.0 */ - if (curl_easy_getinfo(ch->cp, CURLINFO_PRIMARY_IP, &s_code) == CURLE_OK) { - CAAS("primary_ip", s_code); - } -#endif -#if LIBCURL_VERSION_NUM > 0x071500 +#if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ if (curl_easy_getinfo(ch->cp, CURLINFO_PRIMARY_PORT, &l_code) == CURLE_OK) { CAAL("primary_port", l_code); } @@ -2491,93 +3111,23 @@ PHP_FUNCTION(curl_getinfo) CAAL("local_port", l_code); } #endif -#if LIBCURL_VERSION_NUM >= 0x071202 - if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_URL, &s_code) == CURLE_OK) { - CAAS("redirect_url", s_code); - } -#endif if (ch->header.str_len > 0) { CAAS("request_header", ch->header.str); } } else { switch (option) { - /* string variable types */ -#if LIBCURL_VERSION_NUM >= 0x071300 /* 7.19.0 */ - case CURLINFO_PRIMARY_IP: -#endif -#if LIBCURL_VERSION_NUM >= 0x071500 /* 7.21.0 */ - case CURLINFO_LOCAL_IP: -#endif - case CURLINFO_PRIVATE: - case CURLINFO_EFFECTIVE_URL: - case CURLINFO_CONTENT_TYPE: -#if LIBCURL_VERSION_NUM >= 0x071202 - case CURLINFO_REDIRECT_URL: -#endif - { - char *s_code = NULL; - - if (curl_easy_getinfo(ch->cp, option, &s_code) == CURLE_OK && s_code) { - RETURN_STRING(s_code, 1); - } else { - RETURN_FALSE; - } - break; - } - /* Long variable types */ -#if LIBCURL_VERSION_NUM >= 0x071500 /* 7.21.0 */ - case CURLINFO_PRIMARY_PORT: - case CURLINFO_LOCAL_PORT: -#endif - case CURLINFO_HTTP_CODE: - case CURLINFO_HEADER_SIZE: - case CURLINFO_REQUEST_SIZE: - case CURLINFO_FILETIME: - case CURLINFO_SSL_VERIFYRESULT: - case CURLINFO_REDIRECT_COUNT: { - long code = 0; - - if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) { - RETURN_LONG(code); - } else { - RETURN_FALSE; - } - break; - } - /* Double variable types */ - case CURLINFO_TOTAL_TIME: - case CURLINFO_NAMELOOKUP_TIME: - case CURLINFO_CONNECT_TIME: - case CURLINFO_PRETRANSFER_TIME: - case CURLINFO_SIZE_UPLOAD: - case CURLINFO_SIZE_DOWNLOAD: - case CURLINFO_SPEED_DOWNLOAD: - case CURLINFO_SPEED_UPLOAD: - case CURLINFO_CONTENT_LENGTH_DOWNLOAD: - case CURLINFO_CONTENT_LENGTH_UPLOAD: - case CURLINFO_STARTTRANSFER_TIME: - case CURLINFO_REDIRECT_TIME: { - double code = 0.0; - - if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) { - RETURN_DOUBLE(code); - } else { - RETURN_FALSE; - } - break; - } case CURLINFO_HEADER_OUT: if (ch->header.str_len > 0) { RETURN_STRINGL(ch->header.str, ch->header.str_len, 1); } else { RETURN_FALSE; } -#if LIBCURL_VERSION_NUM > 0x071301 +#if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */ case CURLINFO_CERTINFO: { struct curl_certinfo *ci = NULL; array_init(return_value); - + if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) { create_certinfo(ci, return_value TSRMLS_CC); } else { @@ -2586,6 +3136,63 @@ PHP_FUNCTION(curl_getinfo) break; } #endif + default: { + int type = CURLINFO_TYPEMASK & option; + switch (type) { + case CURLINFO_STRING: + { + char *s_code = NULL; + + if (curl_easy_getinfo(ch->cp, option, &s_code) == CURLE_OK && s_code) { + RETURN_STRING(s_code, 1); + } else { + RETURN_FALSE; + } + break; + } + case CURLINFO_LONG: + { + long code = 0; + + if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) { + RETURN_LONG(code); + } else { + RETURN_FALSE; + } + break; + } + case CURLINFO_DOUBLE: + { + double code = 0.0; + + if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) { + RETURN_DOUBLE(code); + } else { + RETURN_FALSE; + } + break; + } +#if LIBCURL_VERSION_NUM >= 0x070c03 /* Available since 7.12.3 */ + case CURLINFO_SLIST: + { + struct curl_slist *slist; + array_init(return_value); + if (curl_easy_getinfo(ch->cp, option, &slist) == CURLE_OK) { + while (slist) { + add_next_index_string(return_value, slist->data, 1); + slist = slist->next; + } + curl_slist_free_all(slist); + } else { + RETURN_FALSE; + } + break; + } +#endif + default: + RETURN_FALSE; + } + } } } } @@ -2644,11 +3251,7 @@ PHP_FUNCTION(curl_close) return; } - if (ch->uses) { - ch->uses--; - } else { - zend_list_delete(Z_LVAL_P(zid)); - } + zend_list_delete(Z_LVAL_P(zid)); } /* }}} */ @@ -2662,16 +3265,16 @@ static void _php_curl_close_ex(php_curl *ch TSRMLS_DC) _php_curl_verify_handlers(ch, 0 TSRMLS_CC); - /* + /* * Libcurl is doing connection caching. When easy handle is cleaned up, - * if the handle was previously used by the curl_multi_api, the connection + * if the handle was previously used by the curl_multi_api, the connection * remains open un the curl multi handle is cleaned up. Some protocols are - * sending content like the FTP one, and libcurl try to use the + * sending content like the FTP one, and libcurl try to use the * WRITEFUNCTION or the HEADERFUNCTION. Since structures used in those * callback are freed, we need to use an other callback to which avoid * segfaults. * - * Libcurl commit d021f2e8a00 fix this issue and should be part of 7.28.2 + * Libcurl commit d021f2e8a00 fix this issue and should be part of 7.28.2 */ curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_nothing); curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write_nothing); @@ -2702,12 +3305,11 @@ static void _php_curl_close_ex(php_curl *ch TSRMLS_DC) if (ch->handlers->write_header->func_name) { zval_ptr_dtor(&ch->handlers->write_header->func_name); } - if (ch->handlers->progress->func_name) { - zval_ptr_dtor(&ch->handlers->progress->func_name); - } +#if CURLOPT_PASSWDFUNCTION != 0 if (ch->handlers->passwd) { zval_ptr_dtor(&ch->handlers->passwd); } +#endif if (ch->handlers->std_err) { zval_ptr_dtor(&ch->handlers->std_err); } @@ -2728,7 +3330,23 @@ static void _php_curl_close_ex(php_curl *ch TSRMLS_DC) efree(ch->handlers->write); efree(ch->handlers->write_header); efree(ch->handlers->read); - efree(ch->handlers->progress); + + if (ch->handlers->progress) { + if (ch->handlers->progress->func_name) { + zval_ptr_dtor(&ch->handlers->progress->func_name); + } + efree(ch->handlers->progress); + } + +#if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ + if (ch->handlers->fnmatch) { + if (ch->handlers->fnmatch->func_name) { + zval_ptr_dtor(&ch->handlers->fnmatch->func_name); + } + efree(ch->handlers->fnmatch); + } +#endif + efree(ch->handlers); efree(ch); } @@ -2743,6 +3361,176 @@ static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC) } /* }}} */ +#if LIBCURL_VERSION_NUM >= 0x070c00 /* Available since 7.12.0 */ +/* {{{ proto bool curl_strerror(int code) + return string describing error code */ +PHP_FUNCTION(curl_strerror) +{ + long code; + const char *str; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code) == FAILURE) { + return; + } + + str = curl_easy_strerror(code); + if (str) { + RETURN_STRING(str, 1); + } else { + RETURN_NULL(); + } +} +/* }}} */ +#endif + +#if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */ +/* {{{ _php_curl_reset_handlers() + Reset all handlers of a given php_curl */ +static void _php_curl_reset_handlers(php_curl *ch) +{ + if (ch->handlers->write->stream) { + Z_DELREF_P(ch->handlers->write->stream); + ch->handlers->write->stream = NULL; + } + ch->handlers->write->fp = NULL; + ch->handlers->write->method = PHP_CURL_STDOUT; + + if (ch->handlers->write_header->stream) { + Z_DELREF_P(ch->handlers->write_header->stream); + ch->handlers->write_header->stream = NULL; + } + ch->handlers->write_header->fp = NULL; + ch->handlers->write_header->method = PHP_CURL_IGNORE; + + if (ch->handlers->read->stream) { + Z_DELREF_P(ch->handlers->read->stream); + ch->handlers->read->stream = NULL; + } + ch->handlers->read->fp = NULL; + ch->handlers->read->fd = 0; + ch->handlers->read->method = PHP_CURL_DIRECT; + + if (ch->handlers->std_err) { + zval_ptr_dtor(&ch->handlers->std_err); + ch->handlers->std_err = NULL; + } + + if (ch->handlers->progress) { + if (ch->handlers->progress->func_name) { + zval_ptr_dtor(&ch->handlers->progress->func_name); + } + efree(ch->handlers->progress); + ch->handlers->progress = NULL; + } + +#if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ + if (ch->handlers->fnmatch) { + if (ch->handlers->fnmatch->func_name) { + zval_ptr_dtor(&ch->handlers->fnmatch->func_name); + } + efree(ch->handlers->fnmatch); + ch->handlers->fnmatch = NULL; + } +#endif + +} +/* }}} */ + +/* {{{ proto void curl_reset(resource ch) + Reset all options of a libcurl session handle */ +PHP_FUNCTION(curl_reset) +{ + zval *zid; + php_curl *ch; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl); + + if (ch->in_callback) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to reset cURL handle from a callback"); + return; + } + + curl_easy_reset(ch->cp); + _php_curl_reset_handlers(ch); + _php_curl_set_default_options(ch); +} +/* }}} */ +#endif + +#if LIBCURL_VERSION_NUM > 0x070f03 /* 7.15.4 */ +/* {{{ proto void curl_escape(resource ch, string str) + URL encodes the given string */ +PHP_FUNCTION(curl_escape) +{ + char *str = NULL, *res = NULL; + int str_len = 0; + zval *zid; + php_curl *ch; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &zid, &str, &str_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl); + + if ((res = curl_easy_escape(ch->cp, str, str_len))) { + RETVAL_STRING(res, 1); + curl_free(res); + } else { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto void curl_unescape(resource ch, string str) + URL decodes the given string */ +PHP_FUNCTION(curl_unescape) +{ + char *str = NULL, *out = NULL; + int str_len = 0, out_len; + zval *zid; + php_curl *ch; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &zid, &str, &str_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl); + + if ((out = curl_easy_unescape(ch->cp, str, str_len, &out_len))) { + RETVAL_STRINGL(out, out_len, 1); + curl_free(out); + } else { + RETURN_FALSE; + } +} +/* }}} */ +#endif + +#if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */ +/* {{{ proto void curl_pause(resource ch, int bitmask) + pause and unpause a connection */ +PHP_FUNCTION(curl_pause) +{ + long bitmask; + zval *zid; + php_curl *ch; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zid, &bitmask) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl); + + RETURN_LONG(curl_easy_pause(ch->cp, bitmask)); +} +/* }}} */ +#endif + #endif /* HAVE_CURL */ /* diff --git a/ext/curl/multi.c b/ext/curl/multi.c index c0985e5646..9fbea5518f 100644 --- a/ext/curl/multi.c +++ b/ext/curl/multi.c @@ -86,7 +86,6 @@ PHP_FUNCTION(curl_multi_add_handle) ZEND_FETCH_RESOURCE(ch, php_curl *, &z_ch, -1, le_curl_name, le_curl); _php_curl_cleanup_handle(ch); - ch->uses++; /* we want to create a copy of this zval that we store in the multihandle structure element "easyh" */ tmp_val = *z_ch; @@ -113,11 +112,7 @@ void _php_curl_multi_cleanup_list(void *data) /* {{{ */ return; } - if (ch->uses) { - ch->uses--; - } else { - zend_list_delete(Z_LVAL_P(z_ch)); - } + zend_list_delete(Z_LVAL_P(z_ch)); } /* }}} */ @@ -125,8 +120,8 @@ void _php_curl_multi_cleanup_list(void *data) /* {{{ */ static int curl_compare_resources( zval *z1, zval **z2 ) /* {{{ */ { return (Z_TYPE_P( z1 ) == Z_TYPE_PP( z2 ) && - Z_TYPE_P( z1 ) == IS_RESOURCE && - Z_LVAL_P( z1 ) == Z_LVAL_PP( z2 ) ); + Z_TYPE_P( z1 ) == IS_RESOURCE && + Z_LVAL_P( z1 ) == Z_LVAL_PP( z2 ) ); } /* }}} */ @@ -146,12 +141,12 @@ PHP_FUNCTION(curl_multi_remove_handle) ZEND_FETCH_RESOURCE(mh, php_curlm *, &z_mh, -1, le_curl_multi_handle_name, le_curl_multi_handle); ZEND_FETCH_RESOURCE(ch, php_curl *, &z_ch, -1, le_curl_name, le_curl); - --ch->uses; + + RETVAL_LONG((long) curl_multi_remove_handle(mh->multi, ch->cp)); zend_llist_del_element( &mh->easyh, &z_ch, (int (*)(void *, void *)) curl_compare_resources ); - - RETURN_LONG((long) curl_multi_remove_handle(mh->multi, ch->cp)); + } /* }}} */ @@ -361,6 +356,81 @@ void _php_curl_multi_close(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */ } /* }}} */ +#if LIBCURL_VERSION_NUM >= 0x070c00 /* Available since 7.12.0 */ +/* {{{ proto bool curl_multi_strerror(int code) + return string describing error code */ +PHP_FUNCTION(curl_multi_strerror) +{ + long code; + const char *str; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code) == FAILURE) { + return; + } + + str = curl_multi_strerror(code); + if (str) { + RETURN_STRING(str, 1); + } else { + RETURN_NULL(); + } +} +/* }}} */ +#endif + +#if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */ +static int _php_curl_multi_setopt(php_curlm *mh, long option, zval **zvalue, zval *return_value TSRMLS_DC) /* {{{ */ +{ + CURLMcode error = CURLM_OK; + + switch (option) { +#if LIBCURL_VERSION_NUM >= 0x071000 /* 7.16.0 */ + case CURLMOPT_PIPELINING: +#endif +#if LIBCURL_VERSION_NUM >= 0x071003 /* 7.16.3 */ + case CURLMOPT_MAXCONNECTS: +#endif + convert_to_long_ex(zvalue); + error = curl_multi_setopt(mh->multi, option, Z_LVAL_PP(zvalue)); + break; + + default: + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid curl multi configuration option"); + error = CURLM_UNKNOWN_OPTION; + break; + } + + if (error != CURLM_OK) { + return 1; + } else { + return 0; + } +} +/* }}} */ + +/* {{{ proto int curl_multi_setopt(resource mh, int option, mixed value) + Set an option for the curl multi handle */ +PHP_FUNCTION(curl_multi_setopt) +{ + zval *z_mh, **zvalue; + long options; + php_curlm *mh; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlZ", &z_mh, &options, &zvalue) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(mh, php_curlm *, &z_mh, -1, le_curl_multi_handle_name, le_curl_multi_handle); + + if (!_php_curl_multi_setopt(mh, options, zvalue, return_value TSRMLS_CC)) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ +#endif + #endif /* diff --git a/ext/curl/package.xml b/ext/curl/package.xml index 85cb634c63..c14321738d 100644 --- a/ext/curl/package.xml +++ b/ext/curl/package.xml @@ -39,6 +39,7 @@ package.xml added to support installation using pear installer <file role="src" name="curl.dsp"/> <file role="src" name="interface.c"/> <file role="src" name="multi.c"/> + <file role="src" name="share.c"/> <file role="src" name="streams.c"/> <file role="src" name="php_curl.h"/> </filelist> diff --git a/ext/curl/php_curl.h b/ext/curl/php_curl.h index c613da1dc6..96edb9ae03 100644 --- a/ext/curl/php_curl.h +++ b/ext/curl/php_curl.h @@ -34,6 +34,14 @@ #define PHP_CURL_DEBUG 0 +#ifdef PHP_WIN32 +# define PHP_CURL_API __declspec(dllexport) +#elif defined(__GNUC__) && __GNUC__ >= 4 +# define PHP_CURL_API __attribute__ ((visibility("default"))) +#else +# define PHP_CURL_API +#endif + #include <curl/curl.h> #include <curl/multi.h> @@ -41,43 +49,73 @@ extern zend_module_entry curl_module_entry; #define curl_module_ptr &curl_module_entry #define CURLOPT_RETURNTRANSFER 19913 -#define CURLOPT_BINARYTRANSFER 19914 +#define CURLOPT_BINARYTRANSFER 19914 /* For Backward compatibility */ #define PHP_CURL_STDOUT 0 #define PHP_CURL_FILE 1 #define PHP_CURL_USER 2 #define PHP_CURL_DIRECT 3 #define PHP_CURL_RETURN 4 -#define PHP_CURL_ASCII 5 -#define PHP_CURL_BINARY 6 #define PHP_CURL_IGNORE 7 extern int le_curl; #define le_curl_name "cURL handle" extern int le_curl_multi_handle; #define le_curl_multi_handle_name "cURL Multi Handle" +extern int le_curl_share_handle; +#define le_curl_share_handle_name "cURL Share Handle" PHP_MINIT_FUNCTION(curl); PHP_MSHUTDOWN_FUNCTION(curl); PHP_MINFO_FUNCTION(curl); -PHP_FUNCTION(curl_version); -PHP_FUNCTION(curl_init); + +PHP_FUNCTION(curl_close); PHP_FUNCTION(curl_copy_handle); -PHP_FUNCTION(curl_setopt); -PHP_FUNCTION(curl_setopt_array); +PHP_FUNCTION(curl_errno); +PHP_FUNCTION(curl_error); PHP_FUNCTION(curl_exec); PHP_FUNCTION(curl_getinfo); -PHP_FUNCTION(curl_error); -PHP_FUNCTION(curl_errno); -PHP_FUNCTION(curl_close); -PHP_FUNCTION(curl_multi_init); +PHP_FUNCTION(curl_init); +PHP_FUNCTION(curl_setopt); +PHP_FUNCTION(curl_setopt_array); +PHP_FUNCTION(curl_version); + PHP_FUNCTION(curl_multi_add_handle); -PHP_FUNCTION(curl_multi_remove_handle); -PHP_FUNCTION(curl_multi_select); +PHP_FUNCTION(curl_multi_close); PHP_FUNCTION(curl_multi_exec); PHP_FUNCTION(curl_multi_getcontent); PHP_FUNCTION(curl_multi_info_read); -PHP_FUNCTION(curl_multi_close); +PHP_FUNCTION(curl_multi_init); +PHP_FUNCTION(curl_multi_remove_handle); +PHP_FUNCTION(curl_multi_select); + +PHP_FUNCTION(curl_share_close); +PHP_FUNCTION(curl_share_init); +PHP_FUNCTION(curl_share_setopt); + +#if LIBCURL_VERSION_NUM >= 0x070c00 /* 7.12.0 */ +PHP_FUNCTION(curl_strerror); +PHP_FUNCTION(curl_multi_strerror); +#endif + +#if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */ +PHP_FUNCTION(curl_reset); +#endif + +#if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */ +PHP_FUNCTION(curl_escape); +PHP_FUNCTION(curl_unescape); + +PHP_FUNCTION(curl_multi_setopt); +#endif + +#if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */ +PHP_FUNCTION(curl_pause); +#endif +PHP_FUNCTION(curl_file_create); + + void _php_curl_multi_close(zend_rsrc_list_entry * TSRMLS_DC); +void _php_curl_share_close(zend_rsrc_list_entry * TSRMLS_DC); typedef struct { zval *func_name; @@ -85,7 +123,6 @@ typedef struct { FILE *fp; smart_str buf; int method; - int type; zval *stream; } php_curl_write; @@ -102,15 +139,20 @@ typedef struct { zval *func_name; zend_fcall_info_cache fci_cache; int method; -} php_curl_progress; +} php_curl_progress, php_curl_fnmatch; typedef struct { php_curl_write *write; php_curl_write *write_header; php_curl_read *read; +#if CURLOPT_PASSWDFUNCTION != 0 zval *passwd; +#endif zval *std_err; php_curl_progress *progress; +#if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ + php_curl_fnmatch *fnmatch; +#endif } php_curl_handlers; struct _php_curl_error { @@ -137,53 +179,29 @@ typedef struct { CURL *cp; php_curl_handlers *handlers; long id; - unsigned int uses; zend_bool in_callback; zval *clone; + zend_bool safe_upload; } php_curl; +#define CURLOPT_SAFE_UPLOAD -1 + typedef struct { int still_running; CURLM *multi; zend_llist easyh; } php_curlm; +typedef struct { + CURLSH *share; +} php_curlsh; + void _php_curl_cleanup_handle(php_curl *); void _php_curl_multi_cleanup_list(void *data); -int _php_curl_verify_handlers(php_curl *ch, int reporterror TSRMLS_DC); - -/* streams support */ - -extern php_stream_ops php_curl_stream_ops; -#define PHP_STREAM_IS_CURL &php_curl_stream_ops - -php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *filename, char *mode, - int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); - -extern php_stream_wrapper php_curl_wrapper; - -struct php_curl_buffer { - off_t readpos, writepos; - php_stream *buf; -}; - -typedef struct { - CURL *curl; - CURLM *multi; - char *url; - struct php_curl_buffer readbuffer; /* holds downloaded data */ - struct php_curl_buffer writebuffer; /* holds data to upload */ - - fd_set readfds, writefds, excfds; - int maxfd; - - char errstr[CURL_ERROR_SIZE + 1]; - CURLMcode mcode; - int pending; - zval *headers; - struct curl_slist *headers_slist; /* holds custom headers sent out in the request */ -} php_curl_stream; +void _php_curl_verify_handlers(php_curl *ch, int reporterror TSRMLS_DC); +void curlfile_register_class(TSRMLS_D); +PHP_CURL_API extern zend_class_entry *curl_CURLFile_class; #else #define curl_module_ptr NULL diff --git a/ext/curl/share.c b/ext/curl/share.c new file mode 100644 index 0000000000..d46361e0ae --- /dev/null +++ b/ext/curl/share.c @@ -0,0 +1,136 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2014 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Pierrick Charron <pierrick@php.net> | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php.h" + +#if HAVE_CURL + +#include "php_curl.h" + +#include <curl/curl.h> + +/* {{{ proto void curl_share_init() + Initialize a share curl handle */ +PHP_FUNCTION(curl_share_init) +{ + php_curlsh *sh; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + sh = ecalloc(1, sizeof(php_curlsh)); + + sh->share = curl_share_init(); + + ZEND_REGISTER_RESOURCE(return_value, sh, le_curl_share_handle); +} +/* }}} */ + +/* {{{ proto void curl_share_close(resource sh) + Close a set of cURL handles */ +PHP_FUNCTION(curl_share_close) +{ + zval *z_sh; + php_curlsh *sh; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_sh) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(sh, php_curlsh *, &z_sh, -1, le_curl_share_handle_name, le_curl_share_handle); + zend_list_delete(Z_LVAL_P(z_sh)); +} +/* }}} */ + +static int _php_curl_share_setopt(php_curlsh *sh, long option, zval **zvalue, zval *return_value TSRMLS_DC) /* {{{ */ +{ + CURLSHcode error = CURLSHE_OK; + + switch (option) { + case CURLSHOPT_SHARE: + case CURLSHOPT_UNSHARE: + convert_to_long_ex(zvalue); + error = curl_share_setopt(sh->share, option, Z_LVAL_PP(zvalue)); + break; + + default: + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid curl share configuration option"); + error = CURLSHE_BAD_OPTION; + break; + } + + if (error != CURLSHE_OK) { + return 1; + } else { + return 0; + } +} +/* }}} */ + +/* {{{ proto bool curl_share_setopt(resource sh, int option, mixed value) + Set an option for a cURL transfer */ +PHP_FUNCTION(curl_share_setopt) +{ + zval *zid, **zvalue; + long options; + php_curlsh *sh; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlZ", &zid, &options, &zvalue) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(sh, php_curlsh *, &zid, -1, le_curl_share_handle_name, le_curl_share_handle); + + if (!_php_curl_share_setopt(sh, options, zvalue, return_value TSRMLS_CC)) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + +void _php_curl_share_close(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */ +{ + php_curlsh *sh = (php_curlsh *) rsrc->ptr; + if (sh) { + curl_share_cleanup(sh->share); + efree(sh); + rsrc->ptr = NULL; + } +} +/* }}} */ + +#endif + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/ext/curl/streams.c b/ext/curl/streams.c deleted file mode 100644 index 9681e197ac..0000000000 --- a/ext/curl/streams.c +++ /dev/null @@ -1,542 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2014 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* This file implements cURL based wrappers. - * NOTE: If you are implementing your own streams that are intended to - * work independently of wrappers, this is not a good example to follow! - **/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" -#include "php_memory_streams.h" - -#if HAVE_CURL - -#include <stdio.h> -#include <string.h> - -#ifdef PHP_WIN32 -#include <winsock2.h> -#include <sys/types.h> -#endif - -#include <curl/curl.h> -#include <curl/easy.h> - -#define SMART_STR_PREALLOC 4096 - -#include "ext/standard/php_smart_str.h" -#include "ext/standard/info.h" -#include "ext/standard/file.h" -#include "ext/standard/php_string.h" -#include "php_curl.h" - -static size_t on_data_available(char *data, size_t size, size_t nmemb, void *ctx) -{ - php_stream *stream = (php_stream *) ctx; - php_curl_stream *curlstream = (php_curl_stream *) stream->abstract; - size_t wrote; - TSRMLS_FETCH(); - - /* TODO: I'd like to deprecate this. - * This code is here because until we start getting real data, we don't know - * if we have had all of the headers - * */ - if (curlstream->readbuffer.writepos == 0) { - zval *sym; - - if (!EG(active_symbol_table)) { - zend_rebuild_symbol_table(TSRMLS_C); - } - MAKE_STD_ZVAL(sym); - *sym = *curlstream->headers; - zval_copy_ctor(sym); - ZEND_SET_SYMBOL(EG(active_symbol_table), "http_response_header", sym); - } - - php_stream_seek(curlstream->readbuffer.buf, curlstream->readbuffer.writepos, SEEK_SET); - wrote = php_stream_write(curlstream->readbuffer.buf, data, size * nmemb); - curlstream->readbuffer.writepos = php_stream_tell(curlstream->readbuffer.buf); - - return wrote; -} - -/* cURL guarantees that headers are written as complete lines, with this function - * called once for each header */ -static size_t on_header_available(char *data, size_t size, size_t nmemb, void *ctx) -{ - size_t length = size * nmemb; - zval *header; - php_stream *stream = (php_stream *) ctx; - php_curl_stream *curlstream = (php_curl_stream *) stream->abstract; - TSRMLS_FETCH(); - - if (length < 2) { - /* invalid header ? */ - return length; - } - - if (!(length == 2 && data[0] == '\r' && data[1] == '\n')) { - MAKE_STD_ZVAL(header); - Z_STRLEN_P(header) = length; - Z_STRVAL_P(header) = estrndup(data, length); - if (Z_STRVAL_P(header)[length-1] == '\n') { - Z_STRVAL_P(header)[length-1] = '\0'; - Z_STRLEN_P(header)--; - - if (Z_STRVAL_P(header)[length-2] == '\r') { - Z_STRVAL_P(header)[length-2] = '\0'; - Z_STRLEN_P(header)--; - } - } - Z_TYPE_P(header) = IS_STRING; - zend_hash_next_index_insert(Z_ARRVAL_P(curlstream->headers), &header, sizeof(zval *), NULL); - - /* based on the header, we might need to trigger a notification */ - if (!strncasecmp(data, "Location: ", 10)) { - php_stream_notify_info(stream->context, PHP_STREAM_NOTIFY_REDIRECTED, data + 10, 0); - } else if (!strncasecmp(data, "Content-Type: ", 14)) { - php_stream_notify_info(stream->context, PHP_STREAM_NOTIFY_MIME_TYPE_IS, data + 14, 0); - } else if (!strncasecmp(data, "Context-Length: ", 16)) { - php_stream_notify_file_size(stream->context, atoi(data + 16), data, 0); - php_stream_notify_progress_init(stream->context, 0, 0); - } - } - return length; - -} - -static int on_progress_avail(php_stream *stream, double dltotal, double dlnow, double ultotal, double ulnow) -{ - TSRMLS_FETCH(); - - /* our notification system only works in a single direction; we should detect which - * direction is important and use the correct values in this call */ - php_stream_notify_progress(stream->context, (size_t) dlnow, (size_t) dltotal); - return 0; -} - -static size_t php_curl_stream_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) -{ - php_curl_stream *curlstream = (php_curl_stream *) stream->abstract; - - if (curlstream->writebuffer.buf) { - return php_stream_write(curlstream->writebuffer.buf, buf, count); - } - - return 0; -} - -static size_t php_curl_stream_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) -{ - php_curl_stream *curlstream = (php_curl_stream *) stream->abstract; - size_t didread = 0; - - if (curlstream->readbuffer.readpos >= curlstream->readbuffer.writepos && curlstream->pending) { - /* we need to read some more data */ - struct timeval tv; - - /* fire up the connection */ - if (curlstream->readbuffer.writepos == 0) { - while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(curlstream->multi, &curlstream->pending)); - } - - do { - FD_ZERO(&curlstream->readfds); - FD_ZERO(&curlstream->writefds); - FD_ZERO(&curlstream->excfds); - - /* get the descriptors from curl */ - curl_multi_fdset(curlstream->multi, &curlstream->readfds, &curlstream->writefds, &curlstream->excfds, &curlstream->maxfd); - - /* if we are in blocking mode, set a timeout */ - tv.tv_usec = 0; - tv.tv_sec = 15; /* TODO: allow this to be configured from the script */ - - /* wait for data */ - switch ((curlstream->maxfd < 0) ? 1 : - select(curlstream->maxfd + 1, &curlstream->readfds, &curlstream->writefds, &curlstream->excfds, &tv)) { - case -1: - /* error */ - return 0; - case 0: - /* no data yet: timed-out */ - return 0; - default: - /* fetch the data */ - do { - curlstream->mcode = curl_multi_perform(curlstream->multi, &curlstream->pending); - } while (curlstream->mcode == CURLM_CALL_MULTI_PERFORM); - } - } while (curlstream->maxfd >= 0 && - curlstream->readbuffer.readpos >= curlstream->readbuffer.writepos && curlstream->pending > 0); - - } - - /* if there is data in the buffer, try and read it */ - if (curlstream->readbuffer.writepos > 0 && curlstream->readbuffer.readpos < curlstream->readbuffer.writepos) { - php_stream_seek(curlstream->readbuffer.buf, curlstream->readbuffer.readpos, SEEK_SET); - didread = php_stream_read(curlstream->readbuffer.buf, buf, count); - curlstream->readbuffer.readpos = php_stream_tell(curlstream->readbuffer.buf); - } - - if (didread == 0) { - stream->eof = 1; - } - - return didread; -} - -static int php_curl_stream_close(php_stream *stream, int close_handle TSRMLS_DC) -{ - php_curl_stream *curlstream = (php_curl_stream *) stream->abstract; - - /* TODO: respect the close_handle flag here, so that casting to a FILE* on - * systems without fopencookie will work properly */ - - curl_multi_remove_handle(curlstream->multi, curlstream->curl); - curl_easy_cleanup(curlstream->curl); - curl_multi_cleanup(curlstream->multi); - - if (curlstream->headers_slist) { - curl_slist_free_all(curlstream->headers_slist); - } - - /* we are not closing curlstream->readbuf here, because we export - * it as a zval with the wrapperdata - the engine will garbage collect it */ - - efree(curlstream->url); - efree(curlstream); - - return 0; -} - -static int php_curl_stream_flush(php_stream *stream TSRMLS_DC) -{ -#ifdef ilia_0 - php_curl_stream *curlstream = (php_curl_stream *) stream->abstract; -#endif - return 0; -} - -static int php_curl_stream_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) -{ - /* TODO: fill in details based on Data: and Content-Length: headers, and/or data - * from curl_easy_getinfo(). - * For now, return -1 to indicate that it doesn't make sense to stat this stream */ - return -1; -} - -static int php_curl_stream_cast(php_stream *stream, int castas, void **ret TSRMLS_DC) -{ - php_curl_stream *curlstream = (php_curl_stream *) stream->abstract; - /* delegate to the readbuffer stream */ - return php_stream_cast(curlstream->readbuffer.buf, castas, ret, 0); -} - -php_stream_ops php_curl_stream_ops = { - php_curl_stream_write, - php_curl_stream_read, - php_curl_stream_close, - php_curl_stream_flush, - "cURL", - NULL, /* seek */ - php_curl_stream_cast, /* cast */ - php_curl_stream_stat /* stat */ -}; - - -php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *filename, char *mode, - int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) -{ - php_stream *stream; - php_curl_stream *curlstream; - zval *tmp, **ctx_opt = NULL; - - curlstream = emalloc(sizeof(php_curl_stream)); - memset(curlstream, 0, sizeof(php_curl_stream)); - - stream = php_stream_alloc(&php_curl_stream_ops, curlstream, 0, mode); - php_stream_context_set(stream, context); - - curlstream->curl = curl_easy_init(); - curlstream->multi = curl_multi_init(); - curlstream->pending = 1; - curlstream->headers_slist = NULL; - - /* if opening for an include statement, ensure that the local storage will - * have a FILE* associated with it. - * Otherwise, use the "smart" memory stream that will turn itself into a file - * when it gets large */ -#ifndef HAVE_FOPENCOOKIE - if (options & STREAM_WILL_CAST) { - curlstream->readbuffer.buf = php_stream_fopen_tmpfile(); - } else -#endif - { - curlstream->readbuffer.buf = php_stream_temp_new(); - } - - /* curl requires the URL to be valid throughout it's operation, so dup it */ - curlstream->url = estrdup(filename); - curl_easy_setopt(curlstream->curl, CURLOPT_URL, curlstream->url); - - /* feed curl data into our read buffer */ - curl_easy_setopt(curlstream->curl, CURLOPT_WRITEFUNCTION, on_data_available); - curl_easy_setopt(curlstream->curl, CURLOPT_FILE, stream); - - /* feed headers */ - curl_easy_setopt(curlstream->curl, CURLOPT_HEADERFUNCTION, on_header_available); - curl_easy_setopt(curlstream->curl, CURLOPT_WRITEHEADER, stream); - - curl_easy_setopt(curlstream->curl, CURLOPT_ERRORBUFFER, curlstream->errstr); - curl_easy_setopt(curlstream->curl, CURLOPT_VERBOSE, 0); - - /* enable progress notification */ - curl_easy_setopt(curlstream->curl, CURLOPT_PROGRESSFUNCTION, on_progress_avail); - curl_easy_setopt(curlstream->curl, CURLOPT_PROGRESSDATA, stream); - curl_easy_setopt(curlstream->curl, CURLOPT_NOPROGRESS, 0); - - curl_easy_setopt(curlstream->curl, CURLOPT_USERAGENT, FG(user_agent) ? FG(user_agent) : "PHP/" PHP_VERSION); - - /* TODO: read cookies and options from context */ - if (context && !strncasecmp(filename, "http", sizeof("http")-1)) { - /* Protocol version */ - if (SUCCESS == php_stream_context_get_option(context, "http", "protocol_version", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_DOUBLE) { - if (Z_DVAL_PP(ctx_opt) == 1.1) { - curl_easy_setopt(curlstream->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); - } else { - curl_easy_setopt(curlstream->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); - } - } - - if (SUCCESS == php_stream_context_get_option(context, "http", "curl_verify_ssl_host", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_BOOL && Z_LVAL_PP(ctx_opt) == 1) { - curl_easy_setopt(curlstream->curl, CURLOPT_SSL_VERIFYHOST, 2); - } else { - curl_easy_setopt(curlstream->curl, CURLOPT_SSL_VERIFYHOST, 0); - } - if (SUCCESS == php_stream_context_get_option(context, "http", "curl_verify_ssl_peer", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_BOOL && Z_LVAL_PP(ctx_opt) == 1) { - curl_easy_setopt(curlstream->curl, CURLOPT_SSL_VERIFYPEER, 1); - } else { - curl_easy_setopt(curlstream->curl, CURLOPT_SSL_VERIFYPEER, 0); - } - - /* HTTP(S) */ - if (SUCCESS == php_stream_context_get_option(context, "http", "user_agent", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_STRING) { - curl_easy_setopt(curlstream->curl, CURLOPT_USERAGENT, Z_STRVAL_PP(ctx_opt)); - } - if (SUCCESS == php_stream_context_get_option(context, "http", "header", &ctx_opt)) { - if (Z_TYPE_PP(ctx_opt) == IS_ARRAY) { - HashPosition pos; - zval **header = NULL; - - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(ctx_opt), &pos); - SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(ctx_opt), (void *)&header, &pos); - zend_hash_move_forward_ex(Z_ARRVAL_PP(ctx_opt), &pos) - ) { - if (Z_TYPE_PP(header) == IS_STRING) { - curlstream->headers_slist = curl_slist_append(curlstream->headers_slist, Z_STRVAL_PP(header)); - } - } - } else if (Z_TYPE_PP(ctx_opt) == IS_STRING && Z_STRLEN_PP(ctx_opt)) { - char *p, *token, *trimmed, *copy_ctx_opt; - - copy_ctx_opt = php_trim(Z_STRVAL_PP(ctx_opt), Z_STRLEN_PP(ctx_opt), NULL, 0, NULL, 3 TSRMLS_CC); - p = php_strtok_r(copy_ctx_opt, "\r\n", &token); - while (p) { - trimmed = php_trim(p, strlen(p), NULL, 0, NULL, 3 TSRMLS_CC); - curlstream->headers_slist = curl_slist_append(curlstream->headers_slist, trimmed); - efree(trimmed); - p = php_strtok_r(NULL, "\r\n", &token); - } - efree(copy_ctx_opt); - } - if (curlstream->headers_slist) { - curl_easy_setopt(curlstream->curl, CURLOPT_HTTPHEADER, curlstream->headers_slist); - } - } - if (SUCCESS == php_stream_context_get_option(context, "http", "method", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_STRING) { - if (strcasecmp(Z_STRVAL_PP(ctx_opt), "get")) { - if (!strcasecmp(Z_STRVAL_PP(ctx_opt), "head")) { - curl_easy_setopt(curlstream->curl, CURLOPT_NOBODY, 1); - } else { - if (!strcasecmp(Z_STRVAL_PP(ctx_opt), "post")) { - curl_easy_setopt(curlstream->curl, CURLOPT_POST, 1); - } else { - curl_easy_setopt(curlstream->curl, CURLOPT_CUSTOMREQUEST, Z_STRVAL_PP(ctx_opt)); - } - if (SUCCESS == php_stream_context_get_option(context, "http", "content", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_STRING) { - curl_easy_setopt(curlstream->curl, CURLOPT_POSTFIELDS, Z_STRVAL_PP(ctx_opt)); - curl_easy_setopt(curlstream->curl, CURLOPT_POSTFIELDSIZE, (long)Z_STRLEN_PP(ctx_opt)); - } - } - } - } - if (SUCCESS == php_stream_context_get_option(context, "http", "proxy", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_STRING) { - curl_easy_setopt(curlstream->curl, CURLOPT_PROXY, Z_STRVAL_PP(ctx_opt)); - } - if (SUCCESS == php_stream_context_get_option(context, "http", "max_redirects", &ctx_opt)) { - long mr = 20; - if (Z_TYPE_PP(ctx_opt) != IS_STRING || !is_numeric_string(Z_STRVAL_PP(ctx_opt), Z_STRLEN_PP(ctx_opt), &mr, NULL, 1)) { - if (Z_TYPE_PP(ctx_opt) == IS_LONG) { - mr = Z_LVAL_PP(ctx_opt); - } - } - if (mr > 1) { - if (PG(open_basedir) && *PG(open_basedir)) { - curl_easy_setopt(curlstream->curl, CURLOPT_FOLLOWLOCATION, 0); - } else { - curl_easy_setopt(curlstream->curl, CURLOPT_FOLLOWLOCATION, 1); - } - curl_easy_setopt(curlstream->curl, CURLOPT_MAXREDIRS, mr); - } - } else { - if (PG(open_basedir) && *PG(open_basedir)) { - curl_easy_setopt(curlstream->curl, CURLOPT_FOLLOWLOCATION, 0); - } else { - curl_easy_setopt(curlstream->curl, CURLOPT_FOLLOWLOCATION, 1); - } - curl_easy_setopt(curlstream->curl, CURLOPT_MAXREDIRS, 20L); - } - } else if (context && !strncasecmp(filename, "ftps", sizeof("ftps")-1)) { - if (SUCCESS == php_stream_context_get_option(context, "ftp", "curl_verify_ssl_host", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_BOOL && Z_LVAL_PP(ctx_opt) == 1) { - curl_easy_setopt(curlstream->curl, CURLOPT_SSL_VERIFYHOST, 2); - } else { - curl_easy_setopt(curlstream->curl, CURLOPT_SSL_VERIFYHOST, 0); - } - if (SUCCESS == php_stream_context_get_option(context, "ftp", "curl_verify_ssl_peer", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_BOOL && Z_LVAL_PP(ctx_opt) == 1) { - curl_easy_setopt(curlstream->curl, CURLOPT_SSL_VERIFYPEER, 1); - } else { - curl_easy_setopt(curlstream->curl, CURLOPT_SSL_VERIFYPEER, 0); - } - } - - /* prepare for "pull" mode */ - curl_multi_add_handle(curlstream->multi, curlstream->curl); - - /* Prepare stuff for file_get_wrapper_data: the data is an array: - * - * data = array( - * "headers" => array("Content-Type: text/html", "Xxx: Yyy"), - * "readbuf" => resource (equivalent to curlstream->readbuffer) - * ); - * */ - MAKE_STD_ZVAL(stream->wrapperdata); - array_init(stream->wrapperdata); - - MAKE_STD_ZVAL(curlstream->headers); - array_init(curlstream->headers); - - add_assoc_zval(stream->wrapperdata, "headers", curlstream->headers); - - MAKE_STD_ZVAL(tmp); - php_stream_to_zval(curlstream->readbuffer.buf, tmp); - add_assoc_zval(stream->wrapperdata, "readbuf", tmp); - -#ifndef HAVE_FOPENCOOKIE - if (options & STREAM_WILL_CAST) { - /* we will need to download the whole resource now, - * since we cannot get the actual FD for the download, - * so we won't be able to drive curl via stdio. */ - -/* TODO: this needs finishing */ - - curl_easy_perform(curlstream->curl); - } - else -#endif - { - /* fire up the connection; we need to detect a connection error here, - * otherwise the curlstream we return ends up doing nothing useful. */ - CURLMcode m; - CURLMsg *msg; - int msgs_left, msg_found = 0; - - while (CURLM_CALL_MULTI_PERFORM == (m = curl_multi_perform(curlstream->multi, &curlstream->pending))) { - ; /* spin */ - } - - if (m != CURLM_OK) { -#if HAVE_CURL_MULTI_STRERROR - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", curl_multi_strerror(m)); -#else - php_error_docref(NULL TSRMLS_CC, E_WARNING, "There was an error mcode=%d", m); -#endif - goto exit_fail; - } - - /* we have only one curl handle here, even though we use multi syntax, - * so it's ok to fail on any error */ - while ((msg = curl_multi_info_read(curlstream->multi, &msgs_left))) { - if (msg->data.result == CURLE_OK) { - continue; - } else { -#if HAVE_CURL_EASY_STRERROR - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", curl_easy_strerror(msg->data.result)); -#else - php_error_docref(NULL TSRMLS_CC, E_WARNING, "There was an error mcode=%d", msg->data.result); -#endif - msg_found++; - } - } - if (msg_found) { - goto exit_fail; - } - } - - return stream; - -exit_fail: - php_stream_close(stream); - return NULL; -} - -static php_stream_wrapper_ops php_curl_wrapper_ops = { - php_curl_stream_opener, - NULL, /* stream_close: curl streams know how to clean themselves up */ - NULL, /* stream_stat: curl streams know how to stat themselves */ - NULL, /* stat url */ - NULL, /* opendir */ - "cURL", /* label */ - NULL, /* unlink */ - NULL, /* rename */ - NULL, /* mkdir */ - NULL /* rmdir */ -}; - -php_stream_wrapper php_curl_wrapper = { - &php_curl_wrapper_ops, - NULL, - 1 /* is_url */ -}; - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/ext/curl/tests/bug27023.phpt b/ext/curl/tests/bug27023.phpt index b738c956e9..fce69f5708 100644 --- a/ext/curl/tests/bug27023.phpt +++ b/ext/curl/tests/bug27023.phpt @@ -1,19 +1,18 @@ --TEST-- Bug #27023 (CURLOPT_POSTFIELDS does not parse content types for files) +--INI-- +error_reporting = E_ALL & ~E_DEPRECATED --SKIPIF-- <?php -if (!extension_loaded("curl")) { - exit("skip curl extension not loaded"); -} -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) { - exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -} +include 'skipif.inc'; ?> --FILE-- <?php -$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); $ch = curl_init(); +curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 0); curl_setopt($ch, CURLOPT_URL, "{$host}/get.php?test=file"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); diff --git a/ext/curl/tests/bug27023_2.phpt b/ext/curl/tests/bug27023_2.phpt new file mode 100644 index 0000000000..c878ebac31 --- /dev/null +++ b/ext/curl/tests/bug27023_2.phpt @@ -0,0 +1,44 @@ +--TEST-- +Bug #27023 (CURLOPT_POSTFIELDS does not parse content types for files) +--INI-- +error_reporting = E_ALL & ~E_DEPRECATED +--SKIPIF-- +<?php include 'skipif.inc'; ?> +--FILE-- +<?php + +include 'server.inc'; +$host = curl_cli_server_start(); +$ch = curl_init(); +curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 1); +curl_setopt($ch, CURLOPT_URL, "{$host}/get.php?test=file"); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + +$file = curl_file_create(__DIR__ . '/curl_testdata1.txt'); +$params = array('file' => $file); +curl_setopt($ch, CURLOPT_POSTFIELDS, $params); +var_dump(curl_exec($ch)); + +$file = curl_file_create(__DIR__ . '/curl_testdata1.txt', "text/plain"); +$params = array('file' => $file); +curl_setopt($ch, CURLOPT_POSTFIELDS, $params); +var_dump(curl_exec($ch)); + +$file = curl_file_create(__DIR__ . '/curl_testdata1.txt', null, "foo.txt"); +$params = array('file' => $file); +curl_setopt($ch, CURLOPT_POSTFIELDS, $params); +var_dump(curl_exec($ch)); + +$file = curl_file_create(__DIR__ . '/curl_testdata1.txt', "text/plain", "foo.txt"); +$params = array('file' => $file); +curl_setopt($ch, CURLOPT_POSTFIELDS, $params); +var_dump(curl_exec($ch)); + + +curl_close($ch); +?> +--EXPECTF-- +string(%d) "curl_testdata1.txt|application/octet-stream" +string(%d) "curl_testdata1.txt|text/plain" +string(%d) "foo.txt|application/octet-stream" +string(%d) "foo.txt|text/plain" diff --git a/ext/curl/tests/bug45161.phpt b/ext/curl/tests/bug45161.phpt index 9fdc7a7e22..bfcd244004 100644 --- a/ext/curl/tests/bug45161.phpt +++ b/ext/curl/tests/bug45161.phpt @@ -8,9 +8,6 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { if (!extension_loaded("curl")) { exit("skip curl extension not loaded"); } -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) { - exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -} $curl_version = curl_version(); if ($curl_version['version_number'] < 0x071100) { exit("skip: test works only with curl >= 7.17.0"); diff --git a/ext/curl/tests/bug46711.phpt b/ext/curl/tests/bug46711.phpt index 8eef5562fe..3149c45d7e 100644 --- a/ext/curl/tests/bug46711.phpt +++ b/ext/curl/tests/bug46711.phpt @@ -5,9 +5,6 @@ Bug #46711 (lost memory when foreach is used for values passed to curl_setopt()) if (!extension_loaded("curl")) { exit("skip curl extension not loaded"); } -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) { - exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -} ?> --FILE-- <?php diff --git a/ext/curl/tests/bug48203.phpt b/ext/curl/tests/bug48203.phpt index d8f4d2269f..aae7fc51a4 100644 --- a/ext/curl/tests/bug48203.phpt +++ b/ext/curl/tests/bug48203.phpt @@ -1,24 +1,17 @@ --TEST-- Bug #48203 (Crash when CURLOPT_STDERR is set to regular file) --SKIPIF-- -<?php -if (!extension_loaded("curl")) { - exit("skip curl extension not loaded"); -} -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) { - exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -} -?> +<?php include 'skipif.inc'; ?> --FILE-- <?php - +include 'server.inc'; $fp = fopen(dirname(__FILE__) . '/bug48203.tmp', 'w'); $ch = curl_init(); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_STDERR, $fp); -curl_setopt($ch, CURLOPT_URL, getenv('PHP_CURL_HTTP_REMOTE_SERVER')); +curl_setopt($ch, CURLOPT_URL, curl_cli_server_start()); fclose($fp); // <-- premature close of $fp caused a crash! diff --git a/ext/curl/tests/bug48203_multi.phpt b/ext/curl/tests/bug48203_multi.phpt index 7d4ee4769e..e28c990e93 100644 --- a/ext/curl/tests/bug48203_multi.phpt +++ b/ext/curl/tests/bug48203_multi.phpt @@ -2,16 +2,11 @@ Variation of bug #48203 with curl_multi_exec (Crash when file pointers passed to curl are closed before calling curl_multi_exec) --SKIPIF-- <?php -if (!extension_loaded("curl")) { - exit("skip curl extension not loaded"); -} -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) { - exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -} +include 'skipif.inc'; ?> --FILE-- <?php - +include 'server.inc'; function checkForClosedFilePointer($curl_option, $description) { $fp = fopen(dirname(__FILE__) . '/bug48203.tmp', 'w'); @@ -21,7 +16,7 @@ function checkForClosedFilePointer($curl_option, $description) { $options = array( CURLOPT_RETURNTRANSFER => 1, $curl_option => $fp, - CURLOPT_URL => getenv("PHP_CURL_HTTP_REMOTE_SERVER") + CURLOPT_URL => curl_cli_server_start() ); // we also need to set CURLOPT_VERBOSE to test CURLOPT_STDERR properly @@ -81,8 +76,7 @@ Ok for CURLOPT_WRITEHEADER Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36 Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36 -%A -Ok for CURLOPT_FILE +%AOk for CURLOPT_FILE Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36 diff --git a/ext/curl/tests/bug48207.phpt b/ext/curl/tests/bug48207.phpt index 6ac16f5ea8..a3cd81544b 100644 --- a/ext/curl/tests/bug48207.phpt +++ b/ext/curl/tests/bug48207.phpt @@ -4,7 +4,7 @@ Test curl_setopt() CURLOPT_FILE readonly file handle Mark van der Velden #testfest Utrecht 2009 --SKIPIF-- -<?php if (!extension_loaded("curl")) print "skip"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php /* @@ -14,7 +14,8 @@ Mark van der Velden */ // Figure out what handler to use -$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); +include 'server.inc'; +$host = curl_cli_server_start(); if(!empty($host)) { // Use the set Environment variable diff --git a/ext/curl/tests/bug54798.phpt b/ext/curl/tests/bug54798.phpt index 7ec84addae..4a9b999940 100644 --- a/ext/curl/tests/bug54798.phpt +++ b/ext/curl/tests/bug54798.phpt @@ -2,12 +2,7 @@ Bug #54798 (Segfault when CURLOPT_STDERR file pointer is closed before calling curl_exec) --SKIPIF-- <?php -if (!extension_loaded("curl")) { - exit("skip curl extension not loaded"); -} -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) { - exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -} +include 'skipif.inc'; ?> --FILE-- <?php @@ -47,26 +42,20 @@ $options_to_check = array( "CURLOPT_INFILE" ); -$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); +include 'server.inc'; +$host = curl_cli_server_start(); foreach($options_to_check as $option) { checkForClosedFilePointer($host, constant($option), $option); } ?> +===DONE=== --CLEAN-- <?php @unlink(dirname(__FILE__) . '/bug54798.tmp'); ?> --EXPECTF-- -Warning: curl_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %sbug54798.php on line %d -* About to connect() %a -* Closing connection #%d -Ok for CURLOPT_STDERR - -Warning: curl_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %sbug54798.php on line 24 -Ok for CURLOPT_WRITEHEADER - -Warning: curl_exec(): CURLOPT_FILE resource has gone away, resetting to default in %sbug54798.php on line 24 %a -Ok for CURLOPT_FILE - -Warning: curl_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %sbug54798.php on line %d -Ok for CURLOPT_INFILE +%aOk for CURLOPT_STDERR +%aOk for CURLOPT_WRITEHEADER +%aOk for CURLOPT_FILE +%aOk for CURLOPT_INFILE +===DONE=== diff --git a/ext/curl/tests/bug54995.phpt b/ext/curl/tests/bug54995.phpt new file mode 100644 index 0000000000..4af59948be --- /dev/null +++ b/ext/curl/tests/bug54995.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #54995 (Missing CURLINFO_RESPONSE_CODE support) +--SKIPIF-- +<?php +include 'skipif.inc'; + +if ($curl_version['version_number'] > 0x070a08) { + exit("skip: tests works a versions of curl >= 7.10.8"); +} +?> +--FILE-- +<?php +include 'server.inc'; +$host = curl_cli_server_start(); +$ch = curl_init(); +curl_setopt($ch, CURLOPT_URL, "{$host}/get.php"); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + +var_dump(curl_getinfo($ch, CURLINFO_HTTP_CODE) == curl_getinfo($ch, CURLINFO_RESPONSE_CODE)); + +curl_exec($ch); +curl_close($ch); + +?> +--EXPECTF-- +bool(true) diff --git a/ext/curl/tests/bug55767.phpt b/ext/curl/tests/bug55767.phpt index 321f67ba60..161ced0bf1 100644 --- a/ext/curl/tests/bug55767.phpt +++ b/ext/curl/tests/bug55767.phpt @@ -2,8 +2,7 @@ Test curl_opt() function with POST params from array with a numeric key --SKIPIF-- <?php -if (!extension_loaded("curl")) exit("skip curl extension not loaded"); -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); +include 'skipinf.inc'; ?> --FILE-- <?php @@ -13,7 +12,8 @@ if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_R * Alias to functions: */ - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); // start testing echo '*** Testing curl sending through GET an POST ***' . "\n"; diff --git a/ext/curl/tests/bug64267.phpt b/ext/curl/tests/bug64267.phpt new file mode 100644 index 0000000000..1b115588ff --- /dev/null +++ b/ext/curl/tests/bug64267.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #64267 (CURLOPT_INFILE doesn't allow reset) +--SKIPIF-- +<?php +extension_loaded("curl") or die("skip need ext/curl"); +?> +--FILE-- +<?php + +echo "TEST\n"; + +$c = curl_init("http://google.com"); +$f = fopen(__FILE__,"r"); +var_dump(curl_setopt_array($c, [ + CURLOPT_RETURNTRANSFER => true, + CURLOPT_UPLOAD => true, + CURLOPT_INFILE => $f, + CURLOPT_INFILESIZE => filesize(__FILE__) +])); +fclose($f); +var_dump(curl_setopt_array($c, [ + CURLOPT_UPLOAD => false, + CURLOPT_INFILE => null, + CURLOPT_INFILESIZE => 0, +])); +curl_exec($c); +var_dump(curl_getinfo($c, CURLINFO_RESPONSE_CODE)); +?> +===DONE=== +--EXPECTF-- +TEST +bool(true) +bool(true) +int(30%d) +===DONE=== diff --git a/ext/curl/tests/bug66109.phpt b/ext/curl/tests/bug66109.phpt new file mode 100644 index 0000000000..5a18e97294 --- /dev/null +++ b/ext/curl/tests/bug66109.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #66109 (Option CURLOPT_CUSTOMREQUEST can't be reset to default.) +--SKIPIF-- +<?php include 'skipif.inc'; ?> +--FILE-- +<?php +include 'server.inc'; +$host = curl_cli_server_start(); +$ch = curl_init(); +curl_setopt($ch, CURLOPT_URL, "{$host}/get.php?test=method"); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + +curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); +var_dump(curl_exec($ch)); + +curl_setopt($ch, CURLOPT_CUSTOMREQUEST, NULL); +var_dump(curl_exec($ch)); + +curl_close($ch); + +?> +--EXPECTF-- +string(6) "DELETE" +string(3) "GET" diff --git a/ext/curl/tests/check_win_config.phpt b/ext/curl/tests/check_win_config.phpt new file mode 100644 index 0000000000..103f1cf692 --- /dev/null +++ b/ext/curl/tests/check_win_config.phpt @@ -0,0 +1,48 @@ +--TEST--
+Check libcurl config on windows
+--SKIPIF--
+<?php
+if (!extension_loaded("curl")) {
+ die('skip - curl extension not available in this build');
+}
+if(substr(PHP_OS, 0, 3) != 'WIN' )
+ die("skip for windows only");
+?>
+--FILE--
+<?php
+ ob_start();
+ phpinfo();
+ $s = ob_get_contents();
+ ob_end_clean();
+ preg_match('/curl\n\n(.+)\n\n/siU', $s, $m);
+
+ echo $m[1], "\n";
+
+?>
+DONE
+--EXPECTF--
+cURL support => enabled
+cURL Information => %s
+Age => %d
+Features
+AsynchDNS => Yes
+CharConv => No
+Debug => No
+GSS-Negotiate => Yes
+IDN => Yes
+IPv6 => Yes
+krb4 => No
+Largefile => Yes
+libz => Yes
+NTLM => Yes
+NTLMWB => No
+SPNEGO => Yes
+SSL => Yes
+SSPI => Yes
+TLS-SRP => No
+Protocols => dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, pop3, pop3s, rtsp, scp, sftp, smtp, smtps, telnet, tftp
+Host => %s-pc-win32
+SSL Version => OpenSSL/%s
+ZLib Version => %s
+libSSH Version => libssh2/%s
+DONE
diff --git a/ext/curl/tests/curl_CURLOPT_READDATA.phpt b/ext/curl/tests/curl_CURLOPT_READDATA.phpt index ea63d445ac..25bd0e9b49 100644 --- a/ext/curl/tests/curl_CURLOPT_READDATA.phpt +++ b/ext/curl/tests/curl_CURLOPT_READDATA.phpt @@ -4,12 +4,14 @@ Test CURLOPT_READDATA without a callback function Mattijs Hoitink mattijshoitink@gmail.com #Testfest Utrecht 2009 --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php +include 'server.inc'; +$host = curl_cli_server_start(); // The URL to POST to -$url = getenv('PHP_CURL_HTTP_REMOTE_SERVER') . '/get.php?test=post'; +$url = $host . '/get.php?test=post'; // Create a temporary file to read the data from $tempname = tempnam(sys_get_temp_dir(), 'CURL_DATA'); diff --git a/ext/curl/tests/curl_basic_001.phpt b/ext/curl/tests/curl_basic_001.phpt index fa362b33ce..4921b69bdd 100644 --- a/ext/curl/tests/curl_basic_001.phpt +++ b/ext/curl/tests/curl_basic_001.phpt @@ -4,10 +4,7 @@ Test curl_exec() function with basic functionality Sebastian Deutsch <sebastian.deutsch@9elements.com> TestFest 2009 - AFUP - Jean-Marc Fontaine <jmf@durcommefaire.net> --SKIPIF-- -<?php -if (!extension_loaded("curl")) exit("skip curl extension not loaded"); -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -?> +<?php include 'skipif.inc'; ?> --FILE-- <?php /* Prototype : bool curl_exec(resource ch) @@ -15,8 +12,8 @@ if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_R * Source code: ext/curl/interface.c * Alias to functions: */ - - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); // start testing echo "*** Testing curl_exec() : basic functionality ***\n"; diff --git a/ext/curl/tests/curl_basic_002.phpt b/ext/curl/tests/curl_basic_002.phpt index e46f323b5a..69aef4b825 100644 --- a/ext/curl/tests/curl_basic_002.phpt +++ b/ext/curl/tests/curl_basic_002.phpt @@ -4,10 +4,7 @@ Test curl_opt() function with CURLOPT_RETURNTRANSFER parameter set to 1 Sebastian Deutsch <sebastian.deutsch@9elements.com> TestFest 2009 - AFUP - Jean-Marc Fontaine <jmf@durcommefaire.net> --SKIPIF-- -<?php -if (!extension_loaded("curl")) exit("skip curl extension not loaded"); -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -?> +<?php include 'skipif.inc'; ?> --FILE-- <?php /* Prototype : bool curl_setopt(resource ch, int option, mixed value) @@ -16,7 +13,8 @@ if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_R * Alias to functions: */ - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); // start testing echo '*** Testing curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); ***' . "\n"; diff --git a/ext/curl/tests/curl_basic_003.phpt b/ext/curl/tests/curl_basic_003.phpt index eb2aecdd8f..9c5967db8f 100644 --- a/ext/curl/tests/curl_basic_003.phpt +++ b/ext/curl/tests/curl_basic_003.phpt @@ -4,10 +4,7 @@ Test curl_opt() function with POST parameters Sebastian Deutsch <sebastian.deutsch@9elements.com> TestFest 2009 - AFUP - Jean-Marc Fontaine <jmf@durcommefaire.net> --SKIPIF-- -<?php -if (!extension_loaded("curl")) exit("skip curl extension not loaded"); -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -?> +<?php include 'skipif.inc'; ?> --FILE-- <?php /* Prototype : bool curl_setopt(resource ch, int option, mixed value) @@ -16,7 +13,8 @@ if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_R * Alias to functions: */ - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); // start testing echo '*** Testing curl sending through GET an POST ***' . "\n"; diff --git a/ext/curl/tests/curl_basic_004.phpt b/ext/curl/tests/curl_basic_004.phpt index ea2eeca87c..08dc7a1005 100644 --- a/ext/curl/tests/curl_basic_004.phpt +++ b/ext/curl/tests/curl_basic_004.phpt @@ -4,10 +4,7 @@ Test curl_opt() function with setting referer Sebastian Deutsch <sebastian.deutsch@9elements.com> TestFest 2009 - AFUP - Jean-Marc Fontaine <jmf@durcommefaire.net> --SKIPIF-- -<?php -if (!extension_loaded("curl")) exit("skip curl extension not loaded"); -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -?> +<?php include 'skipif.inc'; ?> --FILE-- <?php /* Prototype : bool curl_setopt(resource ch, int option, mixed value) @@ -16,7 +13,8 @@ if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_R * Alias to functions: */ - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); // start testing echo '*** Testing curl setting referer ***' . "\n"; diff --git a/ext/curl/tests/curl_basic_005.phpt b/ext/curl/tests/curl_basic_005.phpt index 9285c108e2..200db765dc 100644 --- a/ext/curl/tests/curl_basic_005.phpt +++ b/ext/curl/tests/curl_basic_005.phpt @@ -4,10 +4,7 @@ Test curl_opt() function with user agent Sebastian Deutsch <sebastian.deutsch@9elements.com> TestFest 2009 - AFUP - Jean-Marc Fontaine <jmf@durcommefaire.net> --SKIPIF-- -<?php -if (!extension_loaded("curl")) exit("skip curl extension not loaded"); -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -?> +<?php include 'skipif.inc'; ?> --FILE-- <?php /* Prototype : bool curl_setopt(resource ch, int option, mixed value) @@ -16,7 +13,8 @@ if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_R * Alias to functions: */ - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); // start testing echo '*** Testing curl with user agent ***' . "\n"; diff --git a/ext/curl/tests/curl_basic_006.phpt b/ext/curl/tests/curl_basic_006.phpt index 25bba72f84..e48a5ba70d 100644 --- a/ext/curl/tests/curl_basic_006.phpt +++ b/ext/curl/tests/curl_basic_006.phpt @@ -4,10 +4,7 @@ Test curl_opt() function with CURLOPT_WRITEFUNCTION parameter set to a closure ? TestFest 2009 - AFUP - Jean-Marc Fontaine <jmf@durcommefaire.net> --SKIPIF-- -<?php -if (!extension_loaded("curl")) exit("skip curl extension not loaded"); -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -?> +<?php include 'skipif.inc'; ?> --FILE-- <?php /* Prototype : bool curl_setopt(resource ch, int option, mixed value) @@ -16,7 +13,8 @@ if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_R * Alias to functions: */ - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); // start testing echo '*** Testing curl_setopt($ch, CURLOPT_WRITEFUNCTION, <closure>); ***' . "\n"; diff --git a/ext/curl/tests/curl_basic_008.phpt b/ext/curl/tests/curl_basic_008.phpt index 29e3343707..4f0a29d7ff 100644 --- a/ext/curl/tests/curl_basic_008.phpt +++ b/ext/curl/tests/curl_basic_008.phpt @@ -25,5 +25,5 @@ curl_close($ch); ?> --EXPECTF-- -%unicode|string%(%d) "%r(Couldn't resolve host|Could not resolve host:)%r %Swww.%s" +%s resolve%s int(6) diff --git a/ext/curl/tests/curl_basic_010.phpt b/ext/curl/tests/curl_basic_010.phpt index 0fc2fe6656..72a591ff16 100644 --- a/ext/curl/tests/curl_basic_010.phpt +++ b/ext/curl/tests/curl_basic_010.phpt @@ -26,5 +26,5 @@ curl_close($ch); ?> --EXPECTF-- -%unicode|string%(%d) "%r(Couldn't resolve proxy|Could not resolve proxy:|Could not resolve host:)%r %s" +%unicode|string%(%d) "%r(Couldn't resolve proxy|Could not resolve proxy:|Could not resolve host:|Could not resolve:)%r %s" int(5) diff --git a/ext/curl/tests/curl_basic_011.phpt b/ext/curl/tests/curl_basic_011.phpt index 10c90b123a..4e33082409 100644 --- a/ext/curl/tests/curl_basic_011.phpt +++ b/ext/curl/tests/curl_basic_011.phpt @@ -3,7 +3,7 @@ Test curl_opt() function with COOKIE --CREDITS-- TestFest 2009 - AFUP - Xavier Gorse <xgorse@elao.com> --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv(b'PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php /* Prototype : bool curl_setopt(resource ch, int option, mixed value) @@ -12,7 +12,8 @@ TestFest 2009 - AFUP - Xavier Gorse <xgorse@elao.com> * Alias to functions: */ - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); // start testing echo '*** Testing curl with cookie ***' . "\n"; diff --git a/ext/curl/tests/curl_basic_012.phpt b/ext/curl/tests/curl_basic_012.phpt index e4706fad46..f136880dff 100644 --- a/ext/curl/tests/curl_basic_012.phpt +++ b/ext/curl/tests/curl_basic_012.phpt @@ -3,7 +3,7 @@ Test curl_opt() function with CURLOPT_HTTP_VERSION/CURL_HTTP_VERSION_1_0 --CREDITS-- TestFest 2009 - AFUP - Xavier Gorse <xgorse@elao.com> --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv(b'PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php /* Prototype : bool curl_setopt(resource ch, int option, mixed value) @@ -12,7 +12,8 @@ TestFest 2009 - AFUP - Xavier Gorse <xgorse@elao.com> * Alias to functions: */ - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); // start testing echo '*** Testing curl with HTTP/1.0 ***' . "\n"; diff --git a/ext/curl/tests/curl_basic_013.phpt b/ext/curl/tests/curl_basic_013.phpt index c49d187be3..6d09517e8d 100644 --- a/ext/curl/tests/curl_basic_013.phpt +++ b/ext/curl/tests/curl_basic_013.phpt @@ -3,7 +3,7 @@ Test curl_opt() function with CURLOPT_HTTP_VERSION/CURL_HTTP_VERSION_1_1 --CREDITS-- TestFest 2009 - AFUP - Xavier Gorse <xgorse@elao.com> --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv(b'PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php /* Prototype : bool curl_setopt(resource ch, int option, mixed value) @@ -12,7 +12,8 @@ TestFest 2009 - AFUP - Xavier Gorse <xgorse@elao.com> * Alias to functions: */ - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); // start testing echo '*** Testing curl with HTTP/1.1 ***' . "\n"; diff --git a/ext/curl/tests/curl_basic_017.phpt b/ext/curl/tests/curl_basic_017.phpt index 09247b2c69..dc0bee926b 100644 --- a/ext/curl/tests/curl_basic_017.phpt +++ b/ext/curl/tests/curl_basic_017.phpt @@ -3,7 +3,7 @@ Test curl_multi_exec() function with basic functionality --CREDITS-- TestFest 2009 - AFUP - Thomas Rabaix <thomas.rabaix@gmail.com> --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php /* Prototype : bool curl_multi_exec(resource ch) @@ -12,7 +12,8 @@ TestFest 2009 - AFUP - Thomas Rabaix <thomas.rabaix@gmail.com> * Alias to functions: */ - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); // start testing echo "*** Testing curl_exec() : basic functionality ***\n"; diff --git a/ext/curl/tests/curl_basic_018.phpt b/ext/curl/tests/curl_basic_018.phpt index 7cffb89f01..359421fc0a 100644 --- a/ext/curl/tests/curl_basic_018.phpt +++ b/ext/curl/tests/curl_basic_018.phpt @@ -3,7 +3,7 @@ Test curl_setopt() with curl_multi function with basic functionality --CREDITS-- TestFest 2009 - AFUP - Thomas Rabaix <thomas.rabaix@gmail.com> --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php /* Prototype : bool curl_setopt(resource ch, int option, mixed value) @@ -12,7 +12,8 @@ TestFest 2009 - AFUP - Thomas Rabaix <thomas.rabaix@gmail.com> * Alias to functions: */ - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); // start testing echo "*** Testing curl_exec() : basic functionality ***\n"; diff --git a/ext/curl/tests/curl_basic_019.phpt b/ext/curl/tests/curl_basic_019.phpt index ab605a8c7d..2c58500ef7 100644 --- a/ext/curl/tests/curl_basic_019.phpt +++ b/ext/curl/tests/curl_basic_019.phpt @@ -3,22 +3,19 @@ Test curl_getinfo() function with CURLINFO_EFFECTIVE_URL parameter --CREDITS-- Jean-Marc Fontaine <jmf@durcommefaire.net> --SKIPIF-- -<?php -if (!extension_loaded("curl")) exit("skip curl extension not loaded"); -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -?> +<?php include 'skipif.inc'; ?> --FILE-- <?php - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); - $url = "{$host}/get.php?test="; + $url = "http://{$host}/get.php?test="; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_exec($ch); $info = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); var_dump($url == $info); - curl_close($ch); ?> ===DONE=== diff --git a/ext/curl/tests/curl_basic_020.phpt b/ext/curl/tests/curl_basic_020.phpt index d622053506..1227ad3261 100644 --- a/ext/curl/tests/curl_basic_020.phpt +++ b/ext/curl/tests/curl_basic_020.phpt @@ -3,13 +3,11 @@ Test curl_getinfo() function with CURLINFO_HTTP_CODE parameter --CREDITS-- Jean-Marc Fontaine <jmf@durcommefaire.net> --SKIPIF-- -<?php -if (!extension_loaded("curl")) exit("skip curl extension not loaded"); -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -?> +<?php include 'skipif.inc'; ?> --FILE-- <?php - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); $url = "{$host}/get.php?test="; $ch = curl_init(); diff --git a/ext/curl/tests/curl_basic_021.phpt b/ext/curl/tests/curl_basic_021.phpt index 3b4798d515..d9f5a90bef 100644 --- a/ext/curl/tests/curl_basic_021.phpt +++ b/ext/curl/tests/curl_basic_021.phpt @@ -3,13 +3,11 @@ Test curl_getinfo() function with CURLINFO_CONTENT_TYPE parameter --CREDITS-- Jean-Marc Fontaine <jmf@durcommefaire.net> --SKIPIF-- -<?php -if (!extension_loaded("curl")) exit("skip curl extension not loaded"); -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -?> +<?php include 'skipif.inc'; ?> --FILE-- <?php - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); $url = "{$host}/get.php?test=contenttype"; $ch = curl_init(); diff --git a/ext/curl/tests/curl_basic_022.phpt b/ext/curl/tests/curl_basic_022.phpt new file mode 100644 index 0000000000..d4277a3f89 --- /dev/null +++ b/ext/curl/tests/curl_basic_022.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test curl_getinfo() function with CURLINFO_COOKIELIST parameter +--SKIPIF-- +<?php if (!extension_loaded("curl")) print "skip"; +$curl_version = curl_version(); +if ($curl_version['version_number'] < 0x070e01) { + exit("skip: test works only with curl >= 7.14.1"); +} +?> +--FILE-- +<?php + +$ch = curl_init(); +curl_setopt($ch, CURLOPT_COOKIELIST, 'Set-Cookie: C1=v1; expires=Thu, 31-Dec-2037 23:59:59 GMT; path=/; domain=.php.net'); +curl_setopt($ch, CURLOPT_COOKIELIST, 'Set-Cookie: C2=v2; expires=Thu, 31-Dec-2037 23:59:59 GMT; path=/; domain=.php.net'); +var_dump(curl_getinfo($ch, CURLINFO_COOKIELIST)); + +?> +--EXPECT-- +array(2) { + [0]=> + string(38) ".php.net TRUE / FALSE 2145916799 C1 v1" + [1]=> + string(38) ".php.net TRUE / FALSE 2145916799 C2 v2" +} diff --git a/ext/curl/tests/curl_copy_handle_basic_001.phpt b/ext/curl/tests/curl_copy_handle_basic_001.phpt index f1b4db3ce5..aafa41ee2e 100644 --- a/ext/curl/tests/curl_copy_handle_basic_001.phpt +++ b/ext/curl/tests/curl_copy_handle_basic_001.phpt @@ -4,11 +4,12 @@ Test curl_copy_handle() with simple get Rick Buitenman <rick@meritos.nl> #testfest Utrecht 2009 --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); echo '*** Testing curl copy handle with simple GET ***' . "\n"; diff --git a/ext/curl/tests/curl_copy_handle_basic_002.phpt b/ext/curl/tests/curl_copy_handle_basic_002.phpt index 9ab33635fb..6e8214ad2b 100644 --- a/ext/curl/tests/curl_copy_handle_basic_002.phpt +++ b/ext/curl/tests/curl_copy_handle_basic_002.phpt @@ -4,10 +4,11 @@ Test curl_copy_handle() with simple POST Rick Buitenman <rick@meritos.nl> #testfest Utrecht 2009 --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); echo '*** Testing curl copy handle with simple POST ***' . "\n"; diff --git a/ext/curl/tests/curl_copy_handle_basic_004.phpt b/ext/curl/tests/curl_copy_handle_basic_004.phpt index 9b794e91b4..c690180a55 100644 --- a/ext/curl/tests/curl_copy_handle_basic_004.phpt +++ b/ext/curl/tests/curl_copy_handle_basic_004.phpt @@ -4,11 +4,12 @@ Test curl_copy_handle() after exec() Rick Buitenman <rick@meritos.nl> #testfest Utrecht 2009 --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); echo '*** Test curl_copy_handle() after exec() ***' . "\n"; diff --git a/ext/curl/tests/curl_copy_handle_basic_005.phpt b/ext/curl/tests/curl_copy_handle_basic_005.phpt index aa9e2fa998..e92603324e 100644 --- a/ext/curl/tests/curl_copy_handle_basic_005.phpt +++ b/ext/curl/tests/curl_copy_handle_basic_005.phpt @@ -4,11 +4,12 @@ Test curl_copy_handle() after exec() with POST Rick Buitenman <rick@meritos.nl> #testfest Utrecht 2009 --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); echo '*** Test curl_copy_handle() after exec() with POST ***' . "\n"; diff --git a/ext/curl/tests/curl_copy_handle_basic_006.phpt b/ext/curl/tests/curl_copy_handle_basic_006.phpt index defc0f232a..0a5c2a25e6 100644 --- a/ext/curl/tests/curl_copy_handle_basic_006.phpt +++ b/ext/curl/tests/curl_copy_handle_basic_006.phpt @@ -4,11 +4,12 @@ Test curl_copy_handle() with User Agent Rick Buitenman <rick@meritos.nl> #testfest Utrecht 2009 --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); echo '*** Testing curl copy handle with User Agent ***' . "\n"; diff --git a/ext/curl/tests/curl_copy_handle_basic_007.phpt b/ext/curl/tests/curl_copy_handle_basic_007.phpt index aa7306c1c9..6334d2a4b8 100644 --- a/ext/curl/tests/curl_copy_handle_basic_007.phpt +++ b/ext/curl/tests/curl_copy_handle_basic_007.phpt @@ -1,10 +1,11 @@ --TEST-- Test curl_copy_handle() with simple POST --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); echo '*** Testing curl copy handle with simple POST using array as arguments ***' . "\n"; diff --git a/ext/curl/tests/curl_copy_handle_basic_008.phpt b/ext/curl/tests/curl_copy_handle_basic_008.phpt index 692c2df192..cdb7de374d 100644 --- a/ext/curl/tests/curl_copy_handle_basic_008.phpt +++ b/ext/curl/tests/curl_copy_handle_basic_008.phpt @@ -1,10 +1,11 @@ --TEST-- Test curl_copy_handle() with CURLOPT_PROGRESSFUNCTION --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); $url = "{$host}/get.php"; $ch = curl_init($url); diff --git a/ext/curl/tests/curl_escape.phpt b/ext/curl/tests/curl_escape.phpt Binary files differnew file mode 100644 index 0000000000..e759144c8a --- /dev/null +++ b/ext/curl/tests/curl_escape.phpt diff --git a/ext/curl/tests/curl_file_deleted_before_curl_close.phpt b/ext/curl/tests/curl_file_deleted_before_curl_close.phpt index 592f110fbe..5e806add08 100644 --- a/ext/curl/tests/curl_file_deleted_before_curl_close.phpt +++ b/ext/curl/tests/curl_file_deleted_before_curl_close.phpt @@ -3,11 +3,13 @@ Memory corruption error if fp of just created file is closed before curl_close. --CREDITS-- Alexey Shein <confik@gmail.com> --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php -$ch = curl_init(getenv('PHP_CURL_HTTP_REMOTE_SERVER')); +include 'server.inc'; +$host = curl_cli_server_start(); +$ch = curl_init($host); $temp_file = dirname(__FILE__) . '/curl_file_deleted_before_curl_close.tmp'; if (file_exists($temp_file)) { @@ -33,6 +35,5 @@ echo "Closed correctly\n"; <?php unlink(dirname(__FILE__) . '/curl_file_deleted_before_curl_close.tmp'); ?> ---EXPECTF-- -* Closing connection #%d +--EXPECT-- Closed correctly diff --git a/ext/curl/tests/curl_file_serialize.phpt b/ext/curl/tests/curl_file_serialize.phpt new file mode 100644 index 0000000000..43b272ad64 --- /dev/null +++ b/ext/curl/tests/curl_file_serialize.phpt @@ -0,0 +1,21 @@ +--TEST-- +CURL file uploading +--SKIPIF-- +<?php +if (!extension_loaded("curl")) { + exit("skip curl extension not loaded"); +} +?> +--FILE-- +<?php +$data = 'a:2:{s:4:"file";O:8:"CURLFile":3:{s:4:"name";s:13:"testdata1.txt";s:4:"mime";s:0:"";s:8:"postname";s:0:"";}s:4:"data";s:3:"foo";}'; +var_dump(unserialize($data)); +?> +--EXPECTF-- +Fatal error: Uncaught exception 'Exception' with message 'Unserialization of CURLFile instances is not allowed' in %s +Stack trace: +#0 [internal function]: CURLFile->__wakeup() +#1 %s +#2 {main} + thrown in %s on line %d + diff --git a/ext/curl/tests/curl_file_upload.phpt b/ext/curl/tests/curl_file_upload.phpt new file mode 100644 index 0000000000..b06dedb688 --- /dev/null +++ b/ext/curl/tests/curl_file_upload.phpt @@ -0,0 +1,79 @@ +--TEST-- +CURL file uploading +--SKIPIF-- +<?php include 'skipif.inc'; ?> +--FILE-- +<?php + +function testcurl($ch, $name, $mime = '', $postname = '') +{ + if(!empty($postname)) { + $file = new CurlFile($name, $mime, $postname); + } else if(!empty($mime)) { + $file = new CurlFile($name, $mime); + } else { + $file = new CurlFile($name); + } + curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file)); + var_dump(curl_exec($ch)); +} + +include 'server.inc'; +$host = curl_cli_server_start(); +$ch = curl_init(); +curl_setopt($ch, CURLOPT_URL, "{$host}/get.php?test=file"); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + +testcurl($ch, __DIR__ . '/curl_testdata1.txt'); +testcurl($ch, __DIR__ . '/curl_testdata1.txt', 'text/plain'); +testcurl($ch, __DIR__ . '/curl_testdata1.txt', '', 'foo.txt'); +testcurl($ch, __DIR__ . '/curl_testdata1.txt', 'text/plain', 'foo.txt'); + +$file = new CurlFile(__DIR__ . '/curl_testdata1.txt'); +$file->setMimeType('text/plain'); +var_dump($file->getMimeType()); +var_dump($file->getFilename()); +curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file)); +var_dump(curl_exec($ch)); + +$file = curl_file_create(__DIR__ . '/curl_testdata1.txt'); +$file->setPostFilename('foo.txt'); +var_dump($file->getPostFilename()); +curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file)); +var_dump(curl_exec($ch)); + +$params = array('file' => '@' . __DIR__ . '/curl_testdata1.txt'); +curl_setopt($ch, CURLOPT_POSTFIELDS, $params); +var_dump(curl_exec($ch)); + +curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true); +$params = array('file' => '@' . __DIR__ . '/curl_testdata1.txt'); +curl_setopt($ch, CURLOPT_POSTFIELDS, $params); +var_dump(curl_exec($ch)); + +curl_setopt($ch, CURLOPT_URL, "{$host}/get.php?test=post"); +$params = array('file' => '@' . __DIR__ . '/curl_testdata1.txt'); +curl_setopt($ch, CURLOPT_POSTFIELDS, $params); +var_dump(curl_exec($ch)); + +curl_close($ch); +?> +--EXPECTF-- +string(%d) "curl_testdata1.txt|application/octet-stream" +string(%d) "curl_testdata1.txt|text/plain" +string(%d) "foo.txt|application/octet-stream" +string(%d) "foo.txt|text/plain" +string(%d) "text/plain" +string(%d) "%s/curl_testdata1.txt" +string(%d) "curl_testdata1.txt|text/plain" +string(%d) "foo.txt" +string(%d) "foo.txt|application/octet-stream" + +Deprecated: curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead in %s on line %d +string(%d) "curl_testdata1.txt|application/octet-stream" +string(0) "" +string(%d) "array(1) { + ["file"]=> + string(%d) "@%s/curl_testdata1.txt" +} +" diff --git a/ext/curl/tests/curl_multi_getcontent_basic3.phpt b/ext/curl/tests/curl_multi_getcontent_basic3.phpt index ac2a371724..190fe9d9c0 100644 --- a/ext/curl/tests/curl_multi_getcontent_basic3.phpt +++ b/ext/curl/tests/curl_multi_getcontent_basic3.phpt @@ -4,12 +4,7 @@ Curl_multi_getcontent() basic test with different sources (local file/http) Rein Velt (rein@velt.org) #TestFest Utrecht 20090509 --SKIPIF-- -<?php -if (!extension_loaded('curl')) print 'skip need ext/curl'; -if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) { - exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); -} -?> +<?php include 'skipif.inc'; ?> --FILE-- <?php //CURL_MULTI_GETCONTENT TEST @@ -19,7 +14,8 @@ if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) { $ch2=curl_init(); //SET URL AND OTHER OPTIONS - $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + include 'server.inc'; + $host = curl_cli_server_start(); curl_setopt($ch1, CURLOPT_URL, "{$host}/get.php?test=getpost&get_param=Hello%20World"); curl_setopt($ch2, CURLOPT_URL, "file://".dirname(__FILE__). DIRECTORY_SEPARATOR . "curl_testdata2.txt"); curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true); diff --git a/ext/curl/tests/curl_multi_setopt_basic001.phpt b/ext/curl/tests/curl_multi_setopt_basic001.phpt new file mode 100644 index 0000000000..a13cf6d716 --- /dev/null +++ b/ext/curl/tests/curl_multi_setopt_basic001.phpt @@ -0,0 +1,25 @@ +--TEST-- +curl_multi_setopt basic test +--SKIPIF-- +<?php +if (!extension_loaded("curl")) { + exit("skip curl extension not loaded"); +} +$curl_version = curl_version(); +if ($curl_version['version_number'] < 0x071000) { + exit("skip: test works only with curl >= 7.16.0"); +} +?> +--FILE-- +<?php + +$mh = curl_multi_init(); +var_dump(curl_multi_setopt($mh, CURLMOPT_PIPELINING, 0)); +var_dump(curl_multi_setopt($mh, -1, 0)); + +?> +--EXPECTF-- +bool(true) + +Warning: curl_multi_setopt(): Invalid curl multi configuration option in %s on line %d +bool(false) diff --git a/ext/curl/tests/curl_multi_strerror_001.phpt b/ext/curl/tests/curl_multi_strerror_001.phpt new file mode 100644 index 0000000000..ac330acaee --- /dev/null +++ b/ext/curl/tests/curl_multi_strerror_001.phpt @@ -0,0 +1,22 @@ +--TEST-- +curl_multi_strerror basic test +--SKIPIF-- +<?php +if (!extension_loaded("curl")) { + exit("skip curl extension not loaded"); +} +$curl_version = curl_version(); +if ($curl_version['version_number'] < 0x070c00) { + exit("skip: test works only with curl >= 7.12.0"); +} +?> +--FILE-- +<?php + +var_dump(strtolower(curl_multi_strerror(CURLM_OK))); +var_dump(strtolower(curl_multi_strerror(CURLM_BAD_HANDLE))); + +?> +--EXPECTF-- +string(8) "no error" +string(20) "invalid multi handle" diff --git a/ext/curl/tests/curl_reset.phpt b/ext/curl/tests/curl_reset.phpt new file mode 100644 index 0000000000..3572e69543 --- /dev/null +++ b/ext/curl/tests/curl_reset.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test curl_reset +--SKIPIF-- +<?php if (!extension_loaded("curl")) print "skip"; +if (!function_exists("curl_reset")) exit("skip curl_reset doesn't exists (require libcurl >= 7.12.1)"); +?> +--FILE-- +<?php + +$test_file = tempnam(sys_get_temp_dir(), 'php-curl-test'); +$log_file = tempnam(sys_get_temp_dir(), 'php-curl-test'); + +$fp = fopen($log_file, 'w+'); +fwrite($fp, "test"); +fclose($fp); + +$testfile_fp = fopen($test_file, 'w+'); + +$ch = curl_init(); +curl_setopt($ch, CURLOPT_FILE, $testfile_fp); +curl_setopt($ch, CURLOPT_URL, 'file://' . $log_file); +curl_exec($ch); + +curl_reset($ch); +curl_setopt($ch, CURLOPT_URL, 'file://' . $log_file); +curl_exec($ch); + +curl_close($ch); + +fclose($testfile_fp); + +echo file_get_contents($test_file); + +// cleanup +unlink($test_file); +unlink($log_file); + +?> + +===DONE=== +--EXPECT-- +testtest +===DONE=== diff --git a/ext/curl/tests/curl_setopt_array_basic.phpt b/ext/curl/tests/curl_setopt_array_basic.phpt index 427de7fc75..d858241b78 100644 --- a/ext/curl/tests/curl_setopt_array_basic.phpt +++ b/ext/curl/tests/curl_setopt_array_basic.phpt @@ -4,7 +4,7 @@ curl_setopt_array() function - tests setting multiple cURL options with curl_set Mattijs Hoitink mattijshoitink@gmail.com #Testfest Utrecht 2009 --SKIPIF-- -<?php if (!extension_loaded("curl")) print "skip"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php /* @@ -15,7 +15,8 @@ Mattijs Hoitink mattijshoitink@gmail.com */ // Figure out what handler to use -$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); +include 'server.inc'; +$host = curl_cli_server_start(); if (!empty($host)) { // Use the set Environment variable $url = "{$host}/get.php?test=get"; diff --git a/ext/curl/tests/curl_setopt_basic002.phpt b/ext/curl/tests/curl_setopt_basic002.phpt index d90ecb7bd2..7a11493ed2 100644 --- a/ext/curl/tests/curl_setopt_basic002.phpt +++ b/ext/curl/tests/curl_setopt_basic002.phpt @@ -4,11 +4,12 @@ curl_setopt basic tests with CURLOPT_STDERR. Paul Sohier #phptestfest utrecht --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php -$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); +include 'server.inc'; +$host = curl_cli_server_start(); // start testing echo "*** Testing curl_setopt with CURLOPT_STDERR\n"; @@ -48,5 +49,4 @@ curl_close($ch); *** Testing curl_setopt with CURLOPT_STDERR string(%d) "%S" string(%d) "%S" -* Closing connection #%d diff --git a/ext/curl/tests/curl_setopt_basic003.phpt b/ext/curl/tests/curl_setopt_basic003.phpt index 7849140766..246b83b418 100644 --- a/ext/curl/tests/curl_setopt_basic003.phpt +++ b/ext/curl/tests/curl_setopt_basic003.phpt @@ -4,11 +4,12 @@ curl_setopt() call with CURLOPT_HTTPHEADER Paul Sohier #phptestfest utrecht --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php -$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); +include 'server.inc'; +$host = curl_cli_server_start(); // start testing echo "*** curl_setopt() call with CURLOPT_HTTPHEADER\n"; @@ -38,6 +39,6 @@ var_dump( $curl_content ); --EXPECTF-- *** curl_setopt() call with CURLOPT_HTTPHEADER -Warning: curl_setopt(): You must pass either an object or an array with the CURLOPT_HTTPHEADER, CURLOPT_QUOTE, CURLOPT_HTTP200ALIASES and CURLOPT_POSTQUOTE arguments in %s on line %d +Warning: curl_setopt(): You must pass either an object or an array with the CURLOPT_HTTPHEADER argument in %s on line %d bool(false) bool(true) diff --git a/ext/curl/tests/curl_setopt_basic004.phpt b/ext/curl/tests/curl_setopt_basic004.phpt index 97b4115e3c..ee0b4921d5 100644 --- a/ext/curl/tests/curl_setopt_basic004.phpt +++ b/ext/curl/tests/curl_setopt_basic004.phpt @@ -4,11 +4,12 @@ curl_setopt() call with CURLOPT_RETURNTRANSFER Paul Sohier #phptestfest utrecht --SKIPIF-- -<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?> +<?php include 'skipif.inc'; ?> --FILE-- <?php -$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); +include 'server.inc'; +$host = curl_cli_server_start(); // start testing echo "*** curl_setopt() call with CURLOPT_RETURNTRANSFER set to 1\n"; diff --git a/ext/curl/tests/curl_setopt_error.phpt b/ext/curl/tests/curl_setopt_error.phpt index ad73318f1c..01593aff22 100644 --- a/ext/curl/tests/curl_setopt_error.phpt +++ b/ext/curl/tests/curl_setopt_error.phpt @@ -14,14 +14,14 @@ curl_setopt(false); curl_setopt($ch); curl_setopt($ch, false); -curl_setopt($ch, -1); +curl_setopt($ch, -10); curl_setopt($ch, ''); curl_setopt($ch, 1, false); curl_setopt(false, false, false); curl_setopt($ch, '', false); curl_setopt($ch, 1, ''); -curl_setopt($ch, -1, 0); +curl_setopt($ch, -10, 0); ?> --EXPECTF-- *** curl_setopt() call with incorrect parameters diff --git a/ext/curl/tests/curl_share_setopt_basic001.phpt b/ext/curl/tests/curl_share_setopt_basic001.phpt new file mode 100644 index 0000000000..33c03e3337 --- /dev/null +++ b/ext/curl/tests/curl_share_setopt_basic001.phpt @@ -0,0 +1,23 @@ +--TEST-- +curl_share_setopt basic test +--SKIPIF-- +<?php +if (!extension_loaded("curl")) { + exit("skip curl extension not loaded"); +} +?> +--FILE-- +<?php + +$sh = curl_share_init(); +var_dump(curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE)); +var_dump(curl_share_setopt($sh, CURLSHOPT_UNSHARE, CURL_LOCK_DATA_DNS)); +var_dump(curl_share_setopt($sh, -1, 0)); + +?> +--EXPECTF-- +bool(true) +bool(true) + +Warning: curl_share_setopt(): Invalid curl share configuration option in %s on line %d +bool(false) diff --git a/ext/curl/tests/curl_strerror_001.phpt b/ext/curl/tests/curl_strerror_001.phpt new file mode 100644 index 0000000000..f8a0de311b --- /dev/null +++ b/ext/curl/tests/curl_strerror_001.phpt @@ -0,0 +1,24 @@ +--TEST-- +curl_strerror basic test +--SKIPIF-- +<?php +if (!extension_loaded("curl")) { + exit("skip curl extension not loaded"); +} +$curl_version = curl_version(); +if ($curl_version['version_number'] < 0x070c00) { + exit("skip: test works only with curl >= 7.12.0"); +} +?> +--FILE-- +<?php + +var_dump(strtolower(curl_strerror(CURLE_OK))); +var_dump(strtolower(curl_strerror(CURLE_UNSUPPORTED_PROTOCOL))); +var_dump(strtolower(curl_strerror(-1))); + +?> +--EXPECTF-- +string(8) "no error" +string(20) "unsupported protocol" +string(13) "unknown error" diff --git a/ext/curl/tests/curl_version_error.phpt b/ext/curl/tests/curl_version_error.phpt index fb4793af16..a9b80c55be 100644 --- a/ext/curl/tests/curl_version_error.phpt +++ b/ext/curl/tests/curl_version_error.phpt @@ -1,14 +1,7 @@ --TEST--
Test curl_version() function : error conditions
--SKIPIF--
-<?php
-if (!extension_loaded("curl")) {
- die('skip - curl extension not available in this build');
-}
-if (!getenv('PHP_CURL_HTTP_REMOTE_SERVER')) {
- echo "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable";
-}
-?>
+<?php if (!extension_loaded("curl")) exit("skip curl extension not loaded"); ?>
--FILE--
<?php
diff --git a/ext/curl/tests/curl_version_variation1.phpt b/ext/curl/tests/curl_version_variation1.phpt index cd912c4803..927b4ac317 100644 --- a/ext/curl/tests/curl_version_variation1.phpt +++ b/ext/curl/tests/curl_version_variation1.phpt @@ -1,14 +1,7 @@ --TEST--
Test curl_version() function : usage variations - test values for $ascii argument
--SKIPIF--
-<?php
-if (!extension_loaded("curl")) {
- echo "skip - curl extension not available in this build";
-}
-if (!getenv('PHP_CURL_HTTP_REMOTE_SERVER')) {
- echo "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable";
-}
-?>
+<?php if (!extension_loaded("curl")) exit("skip curl extension not loaded"); ?>
--FILE--
<?php
diff --git a/ext/curl/tests/curl_writeheader_callback.phpt b/ext/curl/tests/curl_writeheader_callback.phpt index fa27363a41..46e0cc18ba 100644 --- a/ext/curl/tests/curl_writeheader_callback.phpt +++ b/ext/curl/tests/curl_writeheader_callback.phpt @@ -4,16 +4,9 @@ Test curl option CURLOPT_HEADERFUNCTION Mathieu Kooiman <mathieuk@gmail.com> Dutch UG, TestFest 2009, Utrecht --DESCRIPTION-- -Hit the host identified by PHP_CURL_HTTP_REMOTE_SERVER and determine that the headers are sent to the callback specified for CURLOPT_HEADERFUNCTION. Different test servers specified for PHP_CURL_HTTP_REMOTE_SERVER might return different sets of headers. Just test for HTTP/1.1 200 OK. +Hit the host and determine that the headers are sent to the callback specified for CURLOPT_HEADERFUNCTION. Different test servers might return different sets of headers. Just test for HTTP/1.1 200 OK. --SKIPIF-- -<?php -if (!extension_loaded("curl")) { - echo "skip - curl extension not available in this build"; -} -if (!getenv('PHP_CURL_HTTP_REMOTE_SERVER')) { - echo "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; -} -?> +<?php include 'skipif.inc'; ?> --FILE-- <?php @@ -23,7 +16,8 @@ function curl_header_callback($curl_handle, $data) echo $data; } -$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER'); +include 'server.inc'; +$host = curl_cli_server_start(); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); diff --git a/ext/curl/tests/responder/get.php b/ext/curl/tests/responder/get.php index 9e13d6a746..60aafc03d4 100644 --- a/ext/curl/tests/responder/get.php +++ b/ext/curl/tests/responder/get.php @@ -31,6 +31,9 @@ echo $_FILES['file']['name'] . '|' . $_FILES['file']['type']; } break; + case 'method': + echo $_SERVER['REQUEST_METHOD']; + break; default: echo "Hello World!\n"; echo "Hello World!"; diff --git a/ext/curl/tests/server.inc b/ext/curl/tests/server.inc new file mode 100644 index 0000000000..6d96a9850c --- /dev/null +++ b/ext/curl/tests/server.inc @@ -0,0 +1,56 @@ +<?php + +define ("PHP_CURL_SERVER_HOSTNAME", "localhost"); +define ("PHP_CURL_SERVER_PORT", 8964); +define ("PHP_CURL_SERVER_ADDRESS", PHP_CURL_SERVER_HOSTNAME.":".PHP_CURL_SERVER_PORT); + +function curl_cli_server_start() { + if(getenv('PHP_CURL_HTTP_REMOTE_SERVER')) { + return getenv('PHP_CURL_HTTP_REMOTE_SERVER'); + } + + $php_executable = getenv('TEST_PHP_EXECUTABLE'); + $doc_root = __DIR__; + $router = "responder/get.php"; + + $descriptorspec = array( + 0 => STDIN, + 1 => STDOUT, + 2 => STDERR, + ); + + if (substr(PHP_OS, 0, 3) == 'WIN') { + $cmd = "{$php_executable} -t {$doc_root} -n -S " . PHP_CURL_SERVER_ADDRESS; + $cmd .= " {$router}"; + $handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL, array("bypass_shell" => true, "suppress_errors" => true)); + } else { + $cmd = "exec {$php_executable} -t {$doc_root} -n -S " . PHP_CURL_SERVER_ADDRESS; + $cmd .= " {$router}"; + $cmd .= " 2>/dev/null"; + + $handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root); + } + + // note: even when server prints 'Listening on localhost:8964...Press Ctrl-C to quit.' + // it might not be listening yet...need to wait until fsockopen() call returns + $i = 0; + while (($i++ < 30) && !($fp = @fsockopen(PHP_CURL_SERVER_HOSTNAME, PHP_CURL_SERVER_PORT))) { + usleep(10000); + } + + if ($fp) { + fclose($fp); + } + + register_shutdown_function( + function($handle) use($router) { + proc_terminate($handle); + }, + $handle + ); + // don't bother sleeping, server is already up + // server can take a variable amount of time to be up, so just sleeping a guessed amount of time + // does not work. this is why tests sometimes pass and sometimes fail. to get a reliable pass + // sleeping doesn't work. + return PHP_CURL_SERVER_ADDRESS; +} diff --git a/ext/curl/tests/skipif.inc b/ext/curl/tests/skipif.inc new file mode 100644 index 0000000000..62b252bcd1 --- /dev/null +++ b/ext/curl/tests/skipif.inc @@ -0,0 +1,7 @@ +<?php + if (!extension_loaded("curl")) exit("skip curl extension not loaded"); + if(false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) { + if (php_sapi_name() != "cli") { + die("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined"); + } + } |