PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/curl - interface.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 1065 1281 83.1 %
Date: 2014-10-22 Functions: 33 39 84.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you 6 copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Author: Sterling Hughes <sterling@php.net>                           |
      16             :    +----------------------------------------------------------------------+
      17             : */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
      22             : 
      23             : #ifdef HAVE_CONFIG_H
      24             : #include "config.h"
      25             : #endif
      26             : 
      27             : #include "php.h"
      28             : 
      29             : #if HAVE_CURL
      30             : 
      31             : #include <stdio.h>
      32             : #include <string.h>
      33             : 
      34             : #ifdef PHP_WIN32
      35             : #include <winsock2.h>
      36             : #include <sys/types.h>
      37             : #endif
      38             : 
      39             : #include <curl/curl.h>
      40             : #include <curl/easy.h>
      41             : 
      42             : /* As of curl 7.11.1 this is no longer defined inside curl.h */
      43             : #ifndef HttpPost
      44             : #define HttpPost curl_httppost
      45             : #endif
      46             : 
      47             : /* {{{ cruft for thread safe SSL crypto locks */
      48             : #if defined(ZTS) && defined(HAVE_CURL_SSL)
      49             : # ifdef PHP_WIN32
      50             : #  define PHP_CURL_NEED_OPENSSL_TSL
      51             : #  include <openssl/crypto.h>
      52             : # else /* !PHP_WIN32 */
      53             : #  if defined(HAVE_CURL_OPENSSL)
      54             : #   if defined(HAVE_OPENSSL_CRYPTO_H)
      55             : #    define PHP_CURL_NEED_OPENSSL_TSL
      56             : #    include <openssl/crypto.h>
      57             : #   else
      58             : #    warning \
      59             :         "libcurl was compiled with OpenSSL support, but configure could not find " \
      60             :         "openssl/crypto.h; thus no SSL crypto locking callbacks will be set, which may " \
      61             :         "cause random crashes on SSL requests"
      62             : #   endif
      63             : #  elif defined(HAVE_CURL_GNUTLS)
      64             : #   if defined(HAVE_GCRYPT_H)
      65             : #    define PHP_CURL_NEED_GNUTLS_TSL
      66             : #    include <gcrypt.h>
      67             : #   else
      68             : #    warning \
      69             :         "libcurl was compiled with GnuTLS support, but configure could not find " \
      70             :         "gcrypt.h; thus no SSL crypto locking callbacks will be set, which may " \
      71             :         "cause random crashes on SSL requests"
      72             : #   endif
      73             : #  else
      74             : #   warning \
      75             :         "libcurl was compiled with SSL support, but configure could not determine which" \
      76             :         "library was used; thus no SSL crypto locking callbacks will be set, which may " \
      77             :         "cause random crashes on SSL requests"
      78             : #  endif /* HAVE_CURL_OPENSSL || HAVE_CURL_GNUTLS */
      79             : # endif /* PHP_WIN32 */
      80             : #endif /* ZTS && HAVE_CURL_SSL */
      81             : /* }}} */
      82             : 
      83             : #define SMART_STR_PREALLOC 4096
      84             : 
      85             : #include "zend_smart_str.h"
      86             : #include "ext/standard/info.h"
      87             : #include "ext/standard/file.h"
      88             : #include "ext/standard/url.h"
      89             : #include "php_curl.h"
      90             : 
      91             : int  le_curl;
      92             : int  le_curl_multi_handle;
      93             : int  le_curl_share_handle;
      94             : 
      95             : #ifdef PHP_CURL_NEED_OPENSSL_TSL /* {{{ */
      96             : static MUTEX_T *php_curl_openssl_tsl = NULL;
      97             : 
      98             : static void php_curl_ssl_lock(int mode, int n, const char * file, int line)
      99             : {
     100             :         if (mode & CRYPTO_LOCK) {
     101             :                 tsrm_mutex_lock(php_curl_openssl_tsl[n]);
     102             :         } else {
     103             :                 tsrm_mutex_unlock(php_curl_openssl_tsl[n]);
     104             :         }
     105             : }
     106             : 
     107             : static unsigned long php_curl_ssl_id(void)
     108             : {
     109             :         return (unsigned long) tsrm_thread_id();
     110             : }
     111             : #endif
     112             : /* }}} */
     113             : 
     114             : #ifdef PHP_CURL_NEED_GNUTLS_TSL /* {{{ */
     115             : static int php_curl_ssl_mutex_create(void **m)
     116             : {
     117             :         if (*((MUTEX_T *) m) = tsrm_mutex_alloc()) {
     118             :                 return SUCCESS;
     119             :         } else {
     120             :                 return FAILURE;
     121             :         }
     122             : }
     123             : 
     124             : static int php_curl_ssl_mutex_destroy(void **m)
     125             : {
     126             :         tsrm_mutex_free(*((MUTEX_T *) m));
     127             :         return SUCCESS;
     128             : }
     129             : 
     130             : static int php_curl_ssl_mutex_lock(void **m)
     131             : {
     132             :         return tsrm_mutex_lock(*((MUTEX_T *) m));
     133             : }
     134             : 
     135             : static int php_curl_ssl_mutex_unlock(void **m)
     136             : {
     137             :         return tsrm_mutex_unlock(*((MUTEX_T *) m));
     138             : }
     139             : 
     140             : static struct gcry_thread_cbs php_curl_gnutls_tsl = {
     141             :         GCRY_THREAD_OPTION_USER,
     142             :         NULL,
     143             :         php_curl_ssl_mutex_create,
     144             :         php_curl_ssl_mutex_destroy,
     145             :         php_curl_ssl_mutex_lock,
     146             :         php_curl_ssl_mutex_unlock
     147             : };
     148             : #endif
     149             : /* }}} */
     150             : 
     151             : static void _php_curl_close_ex(php_curl *ch TSRMLS_DC);
     152             : static void _php_curl_close(zend_resource *rsrc TSRMLS_DC);
     153             : 
     154             : 
     155             : #define SAVE_CURL_ERROR(__handle, __err) (__handle)->err.no = (int) __err;
     156             : 
     157             : #define CAAL(s, v) add_assoc_long_ex(return_value, s, sizeof(s) - 1, (zend_long) v);
     158             : #define CAAD(s, v) add_assoc_double_ex(return_value, s, sizeof(s) - 1, (double) v);
     159             : #define CAAS(s, v) add_assoc_string_ex(return_value, s, sizeof(s) - 1, (char *) (v ? v : ""));
     160             : #define CAASTR(s, v) add_assoc_str_ex(return_value, s, sizeof(s) - 1, v ? v : STR_EMPTY_ALLOC());
     161             : #define CAAZ(s, v) add_assoc_zval_ex(return_value, s, sizeof(s) -1 , (zval *) v);
     162             : 
     163             : #if defined(PHP_WIN32) || defined(__GNUC__)
     164             : # define php_curl_ret(__ret) RETVAL_FALSE; return __ret;
     165             : #else
     166             : # define php_curl_ret(__ret) RETVAL_FALSE; return;
     167             : #endif
     168             : 
     169        1123 : static int php_curl_option_str(php_curl *ch, zend_long option, const char *str, const int len, zend_bool make_copy TSRMLS_DC)
     170             : {
     171        1123 :         CURLcode error = CURLE_OK;
     172             : 
     173        1123 :         if (strlen(str) != len) {
     174           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Curl option contains invalid characters (\\0)");
     175           1 :                 return FAILURE;
     176             :         }
     177             : 
     178             : #if LIBCURL_VERSION_NUM >= 0x071100
     179        1122 :         if (make_copy) {
     180             : #endif
     181             :                 char *copystr;
     182             : 
     183             :                 /* Strings passed to libcurl as 'char *' arguments, are copied by the library since 7.17.0 */
     184           1 :                 copystr = estrndup(str, len);
     185           1 :                 error = curl_easy_setopt(ch->cp, option, copystr);
     186           1 :                 zend_llist_add_element(&ch->to_free->str, &copystr);
     187             : #if LIBCURL_VERSION_NUM >= 0x071100
     188             :         } else {
     189        1121 :                 error = curl_easy_setopt(ch->cp, option, str);
     190             :         }
     191             : #endif
     192             : 
     193        1122 :         SAVE_CURL_ERROR(ch, error)
     194             : 
     195        1122 :         return error == CURLE_OK ? SUCCESS : FAILURE;
     196             : }
     197             : 
     198        1112 : static int php_curl_option_url(php_curl *ch, const char *url, const int len TSRMLS_DC) /* {{{ */
     199             : {
     200             :         /* Disable file:// if open_basedir are used */
     201        1112 :         if (PG(open_basedir) && *PG(open_basedir)) {
     202             : #if LIBCURL_VERSION_NUM >= 0x071304
     203           0 :                 curl_easy_setopt(ch->cp, CURLOPT_PROTOCOLS, CURLPROTO_ALL & ~CURLPROTO_FILE);
     204             : #else
     205             :                 php_url *uri;
     206             : 
     207             :                 if (!(uri = php_url_parse_ex(url, len))) {
     208             :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid URL '%s'", url);
     209             :                         return FAILURE;
     210             :                 }
     211             : 
     212             :                 if (uri->scheme && !strncasecmp("file", uri->scheme, sizeof("file"))) {
     213             :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Protocol 'file' disabled in cURL");
     214             :                         php_url_free(uri);
     215             :                         return FAILURE;
     216             :                 }
     217             :                 php_url_free(uri);
     218             : #endif
     219             :         }
     220             : 
     221        1112 :         return php_curl_option_str(ch, CURLOPT_URL, url, len, 0 TSRMLS_CC);
     222             : }
     223             : /* }}} */
     224             : 
     225        1392 : void _php_curl_verify_handlers(php_curl *ch, int reporterror TSRMLS_DC) /* {{{ */
     226             : {
     227             :         php_stream *stream;
     228        1392 :         if (!ch || !ch->handlers) {
     229           0 :                 return;
     230             :         }
     231             : 
     232        1392 :         if (!Z_ISUNDEF(ch->handlers->std_err)) {
     233          10 :                 stream = zend_fetch_resource(&ch->handlers->std_err TSRMLS_CC, -1, NULL, NULL, 2, php_file_le_stream(), php_file_le_pstream());
     234          10 :                 if (stream == NULL) {
     235           6 :                         if (reporterror) {
     236           4 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLOPT_STDERR resource has gone away, resetting to stderr");
     237             :                         }
     238           6 :                         zval_ptr_dtor(&ch->handlers->std_err);
     239           6 :                         ZVAL_UNDEF(&ch->handlers->std_err);
     240             : 
     241           6 :                         curl_easy_setopt(ch->cp, CURLOPT_STDERR, stderr);
     242             :                 }
     243             :         }
     244        2784 :         if (ch->handlers->read && !Z_ISUNDEF(ch->handlers->read->stream)) {
     245           7 :                 stream = zend_fetch_resource(&ch->handlers->read->stream TSRMLS_CC, -1, NULL, NULL, 2, php_file_le_stream(), php_file_le_pstream());
     246           7 :                 if (stream == NULL) {
     247           3 :                         if (reporterror) {
     248           3 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLOPT_INFILE resource has gone away, resetting to default");
     249             :                         }
     250           3 :                         zval_ptr_dtor(&ch->handlers->read->stream);
     251           3 :                         ZVAL_UNDEF(&ch->handlers->read->stream);
     252           3 :                         ch->handlers->read->res = NULL;
     253           3 :                         ch->handlers->read->fp = 0;
     254             : 
     255           3 :                         curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch);
     256             :                 }
     257             :         }
     258        2784 :         if (ch->handlers->write_header && !Z_ISUNDEF(ch->handlers->write_header->stream)) {
     259           3 :                 stream = zend_fetch_resource(&ch->handlers->write_header->stream TSRMLS_CC, -1, NULL, NULL, 2, php_file_le_stream(), php_file_le_pstream());
     260           3 :                 if (stream == NULL) {
     261           3 :                         if (reporterror) {
     262           3 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLOPT_WRITEHEADER resource has gone away, resetting to default");
     263             :                         }
     264           3 :                         zval_ptr_dtor(&ch->handlers->write_header->stream);
     265           3 :                         ZVAL_UNDEF(&ch->handlers->write_header->stream);
     266           3 :                         ch->handlers->write_header->fp = 0;
     267             : 
     268           3 :                         ch->handlers->write_header->method = PHP_CURL_IGNORE;
     269           3 :                         curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
     270             :                 }
     271             :         }
     272        2784 :         if (ch->handlers->write && !Z_ISUNDEF(ch->handlers->write->stream)) {
     273        1036 :                 stream = zend_fetch_resource(&ch->handlers->write->stream TSRMLS_CC, -1, NULL, NULL, 2, php_file_le_stream(), php_file_le_pstream());
     274        1036 :                 if (stream == NULL) {
     275           5 :                         if (reporterror) {
     276           3 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLOPT_FILE resource has gone away, resetting to default");
     277             :                         }
     278           5 :                         zval_ptr_dtor(&ch->handlers->write->stream);
     279           5 :                         ZVAL_UNDEF(&ch->handlers->write->stream);
     280           5 :                         ch->handlers->write->fp = 0;
     281             : 
     282           5 :                         ch->handlers->write->method = PHP_CURL_STDOUT;
     283           5 :                         curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch);
     284             :                 }
     285             :         }
     286        1392 :         return ;
     287             : }
     288             : /* }}} */
     289             : 
     290             : /* {{{ arginfo */
     291             : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_version, 0, 0, 0)
     292             :         ZEND_ARG_INFO(0, version)
     293             : ZEND_END_ARG_INFO()
     294             : 
     295             : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_init, 0, 0, 0)
     296             :         ZEND_ARG_INFO(0, url)
     297             : ZEND_END_ARG_INFO()
     298             : 
     299             : ZEND_BEGIN_ARG_INFO(arginfo_curl_copy_handle, 0)
     300             :         ZEND_ARG_INFO(0, ch)
     301             : ZEND_END_ARG_INFO()
     302             : 
     303             : ZEND_BEGIN_ARG_INFO(arginfo_curl_setopt, 0)
     304             :         ZEND_ARG_INFO(0, ch)
     305             :         ZEND_ARG_INFO(0, option)
     306             :         ZEND_ARG_INFO(0, value)
     307             : ZEND_END_ARG_INFO()
     308             : 
     309             : ZEND_BEGIN_ARG_INFO(arginfo_curl_setopt_array, 0)
     310             :         ZEND_ARG_INFO(0, ch)
     311             :         ZEND_ARG_ARRAY_INFO(0, options, 0)
     312             : ZEND_END_ARG_INFO()
     313             : 
     314             : ZEND_BEGIN_ARG_INFO(arginfo_curl_exec, 0)
     315             :         ZEND_ARG_INFO(0, ch)
     316             : ZEND_END_ARG_INFO()
     317             : 
     318             : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_getinfo, 0, 0, 1)
     319             :         ZEND_ARG_INFO(0, ch)
     320             :         ZEND_ARG_INFO(0, option)
     321             : ZEND_END_ARG_INFO()
     322             : 
     323             : ZEND_BEGIN_ARG_INFO(arginfo_curl_error, 0)
     324             :         ZEND_ARG_INFO(0, ch)
     325             : ZEND_END_ARG_INFO()
     326             : 
     327             : ZEND_BEGIN_ARG_INFO(arginfo_curl_errno, 0)
     328             :         ZEND_ARG_INFO(0, ch)
     329             : ZEND_END_ARG_INFO()
     330             : 
     331             : ZEND_BEGIN_ARG_INFO(arginfo_curl_close, 0)
     332             :         ZEND_ARG_INFO(0, ch)
     333             : ZEND_END_ARG_INFO()
     334             : 
     335             : #if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */
     336             : ZEND_BEGIN_ARG_INFO(arginfo_curl_reset, 0)
     337             :         ZEND_ARG_INFO(0, ch)
     338             : ZEND_END_ARG_INFO()
     339             : #endif
     340             : 
     341             : #if LIBCURL_VERSION_NUM > 0x070f03 /* 7.15.4 */
     342             : ZEND_BEGIN_ARG_INFO(arginfo_curl_escape, 0)
     343             :         ZEND_ARG_INFO(0, ch)
     344             :         ZEND_ARG_INFO(0, str)
     345             : ZEND_END_ARG_INFO()
     346             : 
     347             : ZEND_BEGIN_ARG_INFO(arginfo_curl_unescape, 0)
     348             :         ZEND_ARG_INFO(0, ch)
     349             :         ZEND_ARG_INFO(0, str)
     350             : ZEND_END_ARG_INFO()
     351             : 
     352             : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_setopt, 0)
     353             :         ZEND_ARG_INFO(0, sh)
     354             :         ZEND_ARG_INFO(0, option)
     355             :         ZEND_ARG_INFO(0, value)
     356             : ZEND_END_ARG_INFO()
     357             : #endif
     358             : 
     359             : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_init, 0)
     360             : ZEND_END_ARG_INFO()
     361             : 
     362             : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_add_handle, 0)
     363             :         ZEND_ARG_INFO(0, mh)
     364             :         ZEND_ARG_INFO(0, ch)
     365             : ZEND_END_ARG_INFO()
     366             : 
     367             : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_remove_handle, 0)
     368             :         ZEND_ARG_INFO(0, mh)
     369             :         ZEND_ARG_INFO(0, ch)
     370             : ZEND_END_ARG_INFO()
     371             : 
     372             : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_select, 0, 0, 1)
     373             :         ZEND_ARG_INFO(0, mh)
     374             :         ZEND_ARG_INFO(0, timeout)
     375             : ZEND_END_ARG_INFO()
     376             : 
     377             : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_exec, 0, 0, 1)
     378             :         ZEND_ARG_INFO(0, mh)
     379             :         ZEND_ARG_INFO(1, still_running)
     380             : ZEND_END_ARG_INFO()
     381             : 
     382             : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_getcontent, 0)
     383             :         ZEND_ARG_INFO(0, ch)
     384             : ZEND_END_ARG_INFO()
     385             : 
     386             : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_info_read, 0, 0, 1)
     387             :         ZEND_ARG_INFO(0, mh)
     388             :         ZEND_ARG_INFO(1, msgs_in_queue)
     389             : ZEND_END_ARG_INFO()
     390             : 
     391             : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_close, 0)
     392             :         ZEND_ARG_INFO(0, mh)
     393             : ZEND_END_ARG_INFO()
     394             : 
     395             : #if LIBCURL_VERSION_NUM >= 0x070c00 /* Available since 7.12.0 */
     396             : ZEND_BEGIN_ARG_INFO(arginfo_curl_strerror, 0)
     397             :         ZEND_ARG_INFO(0, errornum)
     398             : ZEND_END_ARG_INFO()
     399             : 
     400             : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_strerror, 0)
     401             :         ZEND_ARG_INFO(0, errornum)
     402             : ZEND_END_ARG_INFO()
     403             : #endif
     404             : 
     405             : ZEND_BEGIN_ARG_INFO(arginfo_curl_share_init, 0)
     406             : ZEND_END_ARG_INFO()
     407             : 
     408             : ZEND_BEGIN_ARG_INFO(arginfo_curl_share_close, 0)
     409             :         ZEND_ARG_INFO(0, sh)
     410             : ZEND_END_ARG_INFO()
     411             : 
     412             : ZEND_BEGIN_ARG_INFO(arginfo_curl_share_setopt, 0)
     413             :         ZEND_ARG_INFO(0, sh)
     414             :         ZEND_ARG_INFO(0, option)
     415             :         ZEND_ARG_INFO(0, value)
     416             : ZEND_END_ARG_INFO()
     417             : 
     418             : #if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */
     419             : ZEND_BEGIN_ARG_INFO(arginfo_curl_pause, 0)
     420             :         ZEND_ARG_INFO(0, ch)
     421             :         ZEND_ARG_INFO(0, bitmask)
     422             : ZEND_END_ARG_INFO()
     423             : #endif
     424             : 
     425             : ZEND_BEGIN_ARG_INFO_EX(arginfo_curlfile_create, 0, 0, 1)
     426             :         ZEND_ARG_INFO(0, filename)
     427             :         ZEND_ARG_INFO(0, mimetype)
     428             :         ZEND_ARG_INFO(0, postname)
     429             : ZEND_END_ARG_INFO()
     430             : /* }}} */
     431             : 
     432             : /* {{{ curl_functions[]
     433             :  */
     434             : const zend_function_entry curl_functions[] = {
     435             :         PHP_FE(curl_init,                arginfo_curl_init)
     436             :         PHP_FE(curl_copy_handle,         arginfo_curl_copy_handle)
     437             :         PHP_FE(curl_version,             arginfo_curl_version)
     438             :         PHP_FE(curl_setopt,              arginfo_curl_setopt)
     439             :         PHP_FE(curl_setopt_array,        arginfo_curl_setopt_array)
     440             :         PHP_FE(curl_exec,                arginfo_curl_exec)
     441             :         PHP_FE(curl_getinfo,             arginfo_curl_getinfo)
     442             :         PHP_FE(curl_error,               arginfo_curl_error)
     443             :         PHP_FE(curl_errno,               arginfo_curl_errno)
     444             :         PHP_FE(curl_close,               arginfo_curl_close)
     445             : #if LIBCURL_VERSION_NUM >= 0x070c00 /* 7.12.0 */
     446             :         PHP_FE(curl_strerror,            arginfo_curl_strerror)
     447             :         PHP_FE(curl_multi_strerror,      arginfo_curl_multi_strerror)
     448             : #endif
     449             : #if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */
     450             :         PHP_FE(curl_reset,               arginfo_curl_reset)
     451             : #endif
     452             : #if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */
     453             :         PHP_FE(curl_escape,              arginfo_curl_escape)
     454             :         PHP_FE(curl_unescape,            arginfo_curl_unescape)
     455             : #endif
     456             : #if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */
     457             :         PHP_FE(curl_pause,               arginfo_curl_pause)
     458             : #endif
     459             :         PHP_FE(curl_multi_init,          arginfo_curl_multi_init)
     460             :         PHP_FE(curl_multi_add_handle,    arginfo_curl_multi_add_handle)
     461             :         PHP_FE(curl_multi_remove_handle, arginfo_curl_multi_remove_handle)
     462             :         PHP_FE(curl_multi_select,        arginfo_curl_multi_select)
     463             :         PHP_FE(curl_multi_exec,          arginfo_curl_multi_exec)
     464             :         PHP_FE(curl_multi_getcontent,    arginfo_curl_multi_getcontent)
     465             :         PHP_FE(curl_multi_info_read,     arginfo_curl_multi_info_read)
     466             :         PHP_FE(curl_multi_close,         arginfo_curl_multi_close)
     467             : #if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */
     468             :         PHP_FE(curl_multi_setopt,        arginfo_curl_multi_setopt)
     469             : #endif
     470             :         PHP_FE(curl_share_init,          arginfo_curl_share_init)
     471             :         PHP_FE(curl_share_close,         arginfo_curl_share_close)
     472             :         PHP_FE(curl_share_setopt,        arginfo_curl_share_setopt)
     473             :         PHP_FE(curl_file_create,         arginfo_curlfile_create)
     474             :         PHP_FE_END
     475             : };
     476             : /* }}} */
     477             : 
     478             : /* {{{ curl_module_entry
     479             :  */
     480             : zend_module_entry curl_module_entry = {
     481             :         STANDARD_MODULE_HEADER,
     482             :         "curl",
     483             :         curl_functions,
     484             :         PHP_MINIT(curl),
     485             :         PHP_MSHUTDOWN(curl),
     486             :         NULL,
     487             :         NULL,
     488             :         PHP_MINFO(curl),
     489             :         NO_VERSION_YET,
     490             :         STANDARD_MODULE_PROPERTIES
     491             : };
     492             : /* }}} */
     493             : 
     494             : #ifdef COMPILE_DL_CURL
     495             : ZEND_GET_MODULE (curl)
     496             : #endif
     497             : 
     498             : /* {{{ PHP_INI_BEGIN */
     499             : PHP_INI_BEGIN()
     500             :         PHP_INI_ENTRY("curl.cainfo", "", PHP_INI_SYSTEM, NULL)
     501             : PHP_INI_END()
     502             : /* }}} */
     503             : 
     504             : /* {{{ PHP_MINFO_FUNCTION
     505             :  */
     506         143 : PHP_MINFO_FUNCTION(curl)
     507             : {
     508             :         curl_version_info_data *d;
     509             :         char **p;
     510             :         char str[1024];
     511         143 :         size_t n = 0;
     512             : 
     513         143 :         d = curl_version_info(CURLVERSION_NOW);
     514         143 :         php_info_print_table_start();
     515         143 :         php_info_print_table_row(2, "cURL support",    "enabled");
     516         143 :         php_info_print_table_row(2, "cURL Information", d->version);
     517         143 :         sprintf(str, "%d", d->age);
     518         143 :         php_info_print_table_row(2, "Age", str);
     519             : 
     520             :         /* To update on each new cURL release using src/main.c in cURL sources */
     521         143 :         if (d->features) {
     522             :                 struct feat {
     523             :                         const char *name;
     524             :                         int bitmask;
     525             :                 };
     526             : 
     527             :                 unsigned int i;
     528             : 
     529             :                 static const struct feat feats[] = {
     530             : #if LIBCURL_VERSION_NUM >= 0x070a07 /* 7.10.7 */
     531             :                         {"AsynchDNS", CURL_VERSION_ASYNCHDNS},
     532             : #endif
     533             : #if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */
     534             :                         {"CharConv", CURL_VERSION_CONV},
     535             : #endif
     536             : #if LIBCURL_VERSION_NUM >= 0x070a06 /* 7.10.6 */
     537             :                         {"Debug", CURL_VERSION_DEBUG},
     538             :                         {"GSS-Negotiate", CURL_VERSION_GSSNEGOTIATE},
     539             : #endif
     540             : #if LIBCURL_VERSION_NUM >= 0x070c00 /* 7.12.0 */
     541             :                         {"IDN", CURL_VERSION_IDN},
     542             : #endif
     543             :                         {"IPv6", CURL_VERSION_IPV6},
     544             :                         {"krb4", CURL_VERSION_KERBEROS4},
     545             : #if LIBCURL_VERSION_NUM >= 0x070b01 /* 7.11.1 */
     546             :                         {"Largefile", CURL_VERSION_LARGEFILE},
     547             : #endif
     548             :                         {"libz", CURL_VERSION_LIBZ},
     549             : #if LIBCURL_VERSION_NUM >= 0x070a06 /* 7.10.6 */
     550             :                         {"NTLM", CURL_VERSION_NTLM},
     551             : #endif
     552             : #if LIBCURL_VERSION_NUM >= 0x071600 /* 7.22.0 */
     553             :                         {"NTLMWB", CURL_VERSION_NTLM_WB},
     554             : #endif
     555             : #if LIBCURL_VERSION_NUM >= 0x070a08 /* 7.10.8 */
     556             :                         {"SPNEGO", CURL_VERSION_SPNEGO},
     557             : #endif
     558             :                         {"SSL",  CURL_VERSION_SSL},
     559             : #if LIBCURL_VERSION_NUM >= 0x070d02 /* 7.13.2 */
     560             :                         {"SSPI",  CURL_VERSION_SSPI},
     561             : #endif
     562             : #if LIBCURL_VERSION_NUM >= 0x071504 /* 7.21.4 */
     563             :                         {"TLS-SRP", CURL_VERSION_TLSAUTH_SRP},
     564             : #endif
     565             : #if LIBCURL_VERSION_NUM >= 0x072100 /* 7.33.0 */
     566             :                         {"HTTP2", CURL_VERSION_HTTP2},
     567             : #endif
     568             : #if LIBCURL_VERSION_NUM >= 0x072600 /* 7.38.0 */
     569             :                         {"GSSAPI", CURL_VERSION_GSSAPI},
     570             : #endif
     571             :                         {NULL, 0}
     572             :                 };
     573             : 
     574         143 :                 php_info_print_table_row(1, "Features");
     575        2145 :                 for(i=0; i<sizeof(feats)/sizeof(feats[0]); i++) {
     576        2002 :                         if (feats[i].name) {
     577        1859 :                                 php_info_print_table_row(2, feats[i].name, d->features & feats[i].bitmask ? "Yes" : "No");
     578             :                         }
     579             :                 }
     580             :         }
     581             : 
     582         143 :         n = 0;
     583         143 :         p = (char **) d->protocols;
     584        2002 :         while (*p != NULL) {
     585        1716 :                         n += sprintf(str + n, "%s%s", *p, *(p + 1) != NULL ? ", " : "");
     586        1716 :                         p++;
     587             :         }
     588         143 :         php_info_print_table_row(2, "Protocols", str);
     589             : 
     590         143 :         php_info_print_table_row(2, "Host", d->host);
     591             : 
     592         143 :         if (d->ssl_version) {
     593         143 :                 php_info_print_table_row(2, "SSL Version", d->ssl_version);
     594             :         }
     595             : 
     596         143 :         if (d->libz_version) {
     597         143 :                 php_info_print_table_row(2, "ZLib Version", d->libz_version);
     598             :         }
     599             : 
     600             : #if defined(CURLVERSION_SECOND) && CURLVERSION_NOW >= CURLVERSION_SECOND
     601             :         if (d->ares) {
     602             :                 php_info_print_table_row(2, "ZLib Version", d->ares);
     603             :         }
     604             : #endif
     605             : 
     606             : #if defined(CURLVERSION_THIRD) && CURLVERSION_NOW >= CURLVERSION_THIRD
     607             :         if (d->libidn) {
     608             :                 php_info_print_table_row(2, "libIDN Version", d->libidn);
     609             :         }
     610             : #endif
     611             : 
     612             : #if LIBCURL_VERSION_NUM >= 0x071300
     613             : 
     614         143 :         if (d->iconv_ver_num) {
     615           0 :                 php_info_print_table_row(2, "IconV Version", d->iconv_ver_num);
     616             :         }
     617             : 
     618         143 :         if (d->libssh_version) {
     619         143 :                 php_info_print_table_row(2, "libSSH Version", d->libssh_version);
     620             :         }
     621             : #endif
     622         143 :         php_info_print_table_end();
     623         143 : }
     624             : /* }}} */
     625             : 
     626             : #define REGISTER_CURL_CONSTANT(__c) REGISTER_LONG_CONSTANT(#__c, __c, CONST_CS | CONST_PERSISTENT)
     627             : 
     628             : /* {{{ PHP_MINIT_FUNCTION
     629             :  */
     630       20423 : PHP_MINIT_FUNCTION(curl)
     631             : {
     632       20423 :         le_curl = zend_register_list_destructors_ex(_php_curl_close, NULL, "curl", module_number);
     633       20423 :         le_curl_multi_handle = zend_register_list_destructors_ex(_php_curl_multi_close, NULL, "curl_multi", module_number);
     634       20423 :         le_curl_share_handle = zend_register_list_destructors_ex(_php_curl_share_close, NULL, "curl_share", module_number);
     635             : 
     636       20423 :         REGISTER_INI_ENTRIES();
     637             : 
     638             :         /* See http://curl.haxx.se/lxr/source/docs/libcurl/symbols-in-versions
     639             :            or curl src/docs/libcurl/symbols-in-versions for a (almost) complete list
     640             :            of options and which version they were introduced */
     641             : 
     642             :         /* Constants for curl_setopt() */
     643       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_AUTOREFERER);
     644       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_BINARYTRANSFER);
     645       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_BUFFERSIZE);
     646       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_CAINFO);
     647       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_CAPATH);
     648       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT);
     649       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_COOKIE);
     650       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_COOKIEFILE);
     651       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_COOKIEJAR);
     652       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_COOKIESESSION);
     653       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_CRLF);
     654       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_CUSTOMREQUEST);
     655       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_DNS_CACHE_TIMEOUT);
     656       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_DNS_USE_GLOBAL_CACHE);
     657       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_EGDSOCKET);
     658       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_ENCODING);
     659       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FAILONERROR);
     660       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FILE);
     661       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FILETIME);
     662       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FOLLOWLOCATION);
     663       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FORBID_REUSE);
     664       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FRESH_CONNECT);
     665       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FTPAPPEND);
     666       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FTPLISTONLY);
     667       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FTPPORT);
     668       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPRT);
     669       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPSV);
     670       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_HEADER);
     671       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_HEADERFUNCTION);
     672       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTP200ALIASES);
     673       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTPGET);
     674       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTPHEADER);
     675       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTPPROXYTUNNEL);
     676       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTP_VERSION);
     677       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_INFILE);
     678       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_INFILESIZE);
     679       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_INTERFACE);
     680       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_KRB4LEVEL);
     681       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_LIMIT);
     682       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_TIME);
     683       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_MAXCONNECTS);
     684       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_MAXREDIRS);
     685       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_NETRC);
     686       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_NOBODY);
     687       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_NOPROGRESS);
     688       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_NOSIGNAL);
     689       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PORT);
     690       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_POST);
     691       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_POSTFIELDS);
     692       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_POSTQUOTE);
     693       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PREQUOTE);
     694       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PRIVATE);
     695       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PROGRESSFUNCTION);
     696       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXY);
     697       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYPORT);
     698       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYTYPE);
     699       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYUSERPWD);
     700       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PUT);
     701       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_QUOTE);
     702       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_RANDOM_FILE);
     703       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_RANGE);
     704       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_READDATA);
     705       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_READFUNCTION);
     706       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_REFERER);
     707       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_RESUME_FROM);
     708       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_RETURNTRANSFER);
     709       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SHARE);
     710       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLCERT);
     711       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTPASSWD);
     712       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTTYPE);
     713       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE);
     714       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE_DEFAULT);
     715       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLKEY);
     716       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYPASSWD);
     717       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYTYPE);
     718       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLVERSION);
     719       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSL_CIPHER_LIST);
     720       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYHOST);
     721       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYPEER);
     722       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_STDERR);
     723       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_TELNETOPTIONS);
     724       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_TIMECONDITION);
     725       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT);
     726       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_TIMEVALUE);
     727       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_TRANSFERTEXT);
     728       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_UNRESTRICTED_AUTH);
     729       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_UPLOAD);
     730       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_URL);
     731       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_USERAGENT);
     732       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_USERPWD);
     733       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_VERBOSE);
     734       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_WRITEFUNCTION);
     735       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_WRITEHEADER);
     736             : 
     737             :         /* */
     738       20423 :         REGISTER_CURL_CONSTANT(CURLE_ABORTED_BY_CALLBACK);
     739       20423 :         REGISTER_CURL_CONSTANT(CURLE_BAD_CALLING_ORDER);
     740       20423 :         REGISTER_CURL_CONSTANT(CURLE_BAD_CONTENT_ENCODING);
     741       20423 :         REGISTER_CURL_CONSTANT(CURLE_BAD_DOWNLOAD_RESUME);
     742       20423 :         REGISTER_CURL_CONSTANT(CURLE_BAD_FUNCTION_ARGUMENT);
     743       20423 :         REGISTER_CURL_CONSTANT(CURLE_BAD_PASSWORD_ENTERED);
     744       20423 :         REGISTER_CURL_CONSTANT(CURLE_COULDNT_CONNECT);
     745       20423 :         REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_HOST);
     746       20423 :         REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_PROXY);
     747       20423 :         REGISTER_CURL_CONSTANT(CURLE_FAILED_INIT);
     748       20423 :         REGISTER_CURL_CONSTANT(CURLE_FILE_COULDNT_READ_FILE);
     749       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_ACCESS_DENIED);
     750       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_BAD_DOWNLOAD_RESUME);
     751       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_GET_HOST);
     752       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_RECONNECT);
     753       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_GET_SIZE);
     754       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_RETR_FILE);
     755       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_ASCII);
     756       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_BINARY);
     757       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_STOR_FILE);
     758       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_USE_REST);
     759       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_PARTIAL_FILE);
     760       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_PORT_FAILED);
     761       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_QUOTE_ERROR);
     762       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_USER_PASSWORD_INCORRECT);
     763       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_227_FORMAT);
     764       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASS_REPLY);
     765       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASV_REPLY);
     766       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_SERVER_REPLY);
     767       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_USER_REPLY);
     768       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WRITE_ERROR);
     769       20423 :         REGISTER_CURL_CONSTANT(CURLE_FUNCTION_NOT_FOUND);
     770       20423 :         REGISTER_CURL_CONSTANT(CURLE_GOT_NOTHING);
     771       20423 :         REGISTER_CURL_CONSTANT(CURLE_HTTP_NOT_FOUND);
     772       20423 :         REGISTER_CURL_CONSTANT(CURLE_HTTP_PORT_FAILED);
     773       20423 :         REGISTER_CURL_CONSTANT(CURLE_HTTP_POST_ERROR);
     774       20423 :         REGISTER_CURL_CONSTANT(CURLE_HTTP_RANGE_ERROR);
     775       20423 :         REGISTER_CURL_CONSTANT(CURLE_HTTP_RETURNED_ERROR);
     776       20423 :         REGISTER_CURL_CONSTANT(CURLE_LDAP_CANNOT_BIND);
     777       20423 :         REGISTER_CURL_CONSTANT(CURLE_LDAP_SEARCH_FAILED);
     778       20423 :         REGISTER_CURL_CONSTANT(CURLE_LIBRARY_NOT_FOUND);
     779       20423 :         REGISTER_CURL_CONSTANT(CURLE_MALFORMAT_USER);
     780       20423 :         REGISTER_CURL_CONSTANT(CURLE_OBSOLETE);
     781       20423 :         REGISTER_CURL_CONSTANT(CURLE_OK);
     782       20423 :         REGISTER_CURL_CONSTANT(CURLE_OPERATION_TIMEDOUT);
     783       20423 :         REGISTER_CURL_CONSTANT(CURLE_OPERATION_TIMEOUTED);
     784       20423 :         REGISTER_CURL_CONSTANT(CURLE_OUT_OF_MEMORY);
     785       20423 :         REGISTER_CURL_CONSTANT(CURLE_PARTIAL_FILE);
     786       20423 :         REGISTER_CURL_CONSTANT(CURLE_READ_ERROR);
     787       20423 :         REGISTER_CURL_CONSTANT(CURLE_RECV_ERROR);
     788       20423 :         REGISTER_CURL_CONSTANT(CURLE_SEND_ERROR);
     789       20423 :         REGISTER_CURL_CONSTANT(CURLE_SHARE_IN_USE);
     790       20423 :         REGISTER_CURL_CONSTANT(CURLE_SSL_CACERT);
     791       20423 :         REGISTER_CURL_CONSTANT(CURLE_SSL_CERTPROBLEM);
     792       20423 :         REGISTER_CURL_CONSTANT(CURLE_SSL_CIPHER);
     793       20423 :         REGISTER_CURL_CONSTANT(CURLE_SSL_CONNECT_ERROR);
     794       20423 :         REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_NOTFOUND);
     795       20423 :         REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_SETFAILED);
     796       20423 :         REGISTER_CURL_CONSTANT(CURLE_SSL_PEER_CERTIFICATE);
     797       20423 :         REGISTER_CURL_CONSTANT(CURLE_TELNET_OPTION_SYNTAX);
     798       20423 :         REGISTER_CURL_CONSTANT(CURLE_TOO_MANY_REDIRECTS);
     799       20423 :         REGISTER_CURL_CONSTANT(CURLE_UNKNOWN_TELNET_OPTION);
     800       20423 :         REGISTER_CURL_CONSTANT(CURLE_UNSUPPORTED_PROTOCOL);
     801       20423 :         REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT);
     802       20423 :         REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT_USER);
     803       20423 :         REGISTER_CURL_CONSTANT(CURLE_WRITE_ERROR);
     804             : 
     805             :         /* cURL info constants */
     806       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_CONNECT_TIME);
     807       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_DOWNLOAD);
     808       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_UPLOAD);
     809       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_TYPE);
     810       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_EFFECTIVE_URL);
     811       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_FILETIME);
     812       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_HEADER_OUT);
     813       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_HEADER_SIZE);
     814       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_HTTP_CODE);
     815       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_LASTONE);
     816       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_NAMELOOKUP_TIME);
     817       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_PRETRANSFER_TIME);
     818       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_PRIVATE);
     819       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_COUNT);
     820       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_TIME);
     821       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_REQUEST_SIZE);
     822       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_SIZE_DOWNLOAD);
     823       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_SIZE_UPLOAD);
     824       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_SPEED_DOWNLOAD);
     825       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_SPEED_UPLOAD);
     826       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_SSL_VERIFYRESULT);
     827       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_STARTTRANSFER_TIME);
     828       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_TOTAL_TIME);
     829             : 
     830             :         /* Other */
     831       20423 :         REGISTER_CURL_CONSTANT(CURLMSG_DONE);
     832       20423 :         REGISTER_CURL_CONSTANT(CURLVERSION_NOW);
     833             : 
     834             :         /* Curl Multi Constants */
     835       20423 :         REGISTER_CURL_CONSTANT(CURLM_BAD_EASY_HANDLE);
     836       20423 :         REGISTER_CURL_CONSTANT(CURLM_BAD_HANDLE);
     837       20423 :         REGISTER_CURL_CONSTANT(CURLM_CALL_MULTI_PERFORM);
     838       20423 :         REGISTER_CURL_CONSTANT(CURLM_INTERNAL_ERROR);
     839       20423 :         REGISTER_CURL_CONSTANT(CURLM_OK);
     840       20423 :         REGISTER_CURL_CONSTANT(CURLM_OUT_OF_MEMORY);
     841             : 
     842             :         /* Curl proxy constants */
     843       20423 :         REGISTER_CURL_CONSTANT(CURLPROXY_HTTP);
     844       20423 :         REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS4);
     845       20423 :         REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS5);
     846             : 
     847             :         /* Curl Share constants */
     848       20423 :         REGISTER_CURL_CONSTANT(CURLSHOPT_NONE);
     849       20423 :         REGISTER_CURL_CONSTANT(CURLSHOPT_SHARE);
     850       20423 :         REGISTER_CURL_CONSTANT(CURLSHOPT_UNSHARE);
     851             : 
     852             :         /* Curl Http Version constants (CURLOPT_HTTP_VERSION) */
     853       20423 :         REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_0);
     854       20423 :         REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_1);
     855       20423 :         REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_NONE);
     856             : 
     857             :         /* Curl Lock constants */
     858       20423 :         REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_COOKIE);
     859       20423 :         REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_DNS);
     860       20423 :         REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_SSL_SESSION);
     861             : 
     862             :         /* Curl NETRC constants (CURLOPT_NETRC) */
     863       20423 :         REGISTER_CURL_CONSTANT(CURL_NETRC_IGNORED);
     864       20423 :         REGISTER_CURL_CONSTANT(CURL_NETRC_OPTIONAL);
     865       20423 :         REGISTER_CURL_CONSTANT(CURL_NETRC_REQUIRED);
     866             : 
     867             :         /* Curl SSL Version constants (CURLOPT_SSLVERSION) */
     868       20423 :         REGISTER_CURL_CONSTANT(CURL_SSLVERSION_DEFAULT);
     869       20423 :         REGISTER_CURL_CONSTANT(CURL_SSLVERSION_SSLv2);
     870       20423 :         REGISTER_CURL_CONSTANT(CURL_SSLVERSION_SSLv3);
     871       20423 :         REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1);
     872             : 
     873             :         /* Curl TIMECOND constants (CURLOPT_TIMECONDITION) */
     874       20423 :         REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFMODSINCE);
     875       20423 :         REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFUNMODSINCE);
     876       20423 :         REGISTER_CURL_CONSTANT(CURL_TIMECOND_LASTMOD);
     877       20423 :         REGISTER_CURL_CONSTANT(CURL_TIMECOND_NONE);
     878             : 
     879             :         /* Curl version constants */
     880       20423 :         REGISTER_CURL_CONSTANT(CURL_VERSION_IPV6);
     881       20423 :         REGISTER_CURL_CONSTANT(CURL_VERSION_KERBEROS4);
     882       20423 :         REGISTER_CURL_CONSTANT(CURL_VERSION_LIBZ);
     883       20423 :         REGISTER_CURL_CONSTANT(CURL_VERSION_SSL);
     884             : 
     885             : #if LIBCURL_VERSION_NUM >= 0x070a06 /* Available since 7.10.6 */
     886       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTPAUTH);
     887             :         /* http authentication options */
     888       20423 :         REGISTER_CURL_CONSTANT(CURLAUTH_ANY);
     889       20423 :         REGISTER_CURL_CONSTANT(CURLAUTH_ANYSAFE);
     890       20423 :         REGISTER_CURL_CONSTANT(CURLAUTH_BASIC);
     891       20423 :         REGISTER_CURL_CONSTANT(CURLAUTH_DIGEST);
     892       20423 :         REGISTER_CURL_CONSTANT(CURLAUTH_GSSNEGOTIATE);
     893       20423 :         REGISTER_CURL_CONSTANT(CURLAUTH_NONE);
     894       20423 :         REGISTER_CURL_CONSTANT(CURLAUTH_NTLM);
     895             : #endif
     896             : 
     897             : #if LIBCURL_VERSION_NUM >= 0x070a07 /* Available since 7.10.7 */
     898       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_HTTP_CONNECTCODE);
     899       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_CREATE_MISSING_DIRS);
     900       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYAUTH);
     901             : #endif
     902             : 
     903             : #if LIBCURL_VERSION_NUM >= 0x070a08 /* Available since 7.10.8 */
     904       20423 :         REGISTER_CURL_CONSTANT(CURLE_FILESIZE_EXCEEDED);
     905       20423 :         REGISTER_CURL_CONSTANT(CURLE_LDAP_INVALID_URL);
     906       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_HTTPAUTH_AVAIL);
     907       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_RESPONSE_CODE);
     908       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_PROXYAUTH_AVAIL);
     909       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_RESPONSE_TIMEOUT);
     910       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_IPRESOLVE);
     911       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_MAXFILESIZE);
     912       20423 :         REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V4);
     913       20423 :         REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V6);
     914       20423 :         REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_WHATEVER);
     915             : #endif
     916             : 
     917             : #if LIBCURL_VERSION_NUM >= 0x070b00 /* Available since 7.11.0 */
     918       20423 :         REGISTER_CURL_CONSTANT(CURLE_FTP_SSL_FAILED);
     919       20423 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_ALL);
     920       20423 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_CONTROL);
     921       20423 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_NONE);
     922       20423 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_TRY);
     923       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_SSL);
     924       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_NETRC_FILE);
     925             : #endif
     926             : 
     927             : #if LIBCURL_VERSION_NUM >= 0x070c02 /* Available since 7.12.2 */
     928       20423 :         REGISTER_CURL_CONSTANT(CURLFTPAUTH_DEFAULT);
     929       20423 :         REGISTER_CURL_CONSTANT(CURLFTPAUTH_SSL);
     930       20423 :         REGISTER_CURL_CONSTANT(CURLFTPAUTH_TLS);
     931       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FTPSSLAUTH);
     932             : #endif
     933             : 
     934             : #if LIBCURL_VERSION_NUM >= 0x070d00 /* Available since 7.13.0 */
     935       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_ACCOUNT);
     936             : #endif
     937             : 
     938             : #if LIBCURL_VERSION_NUM >= 0x070b02 /* Available since 7.11.2 */
     939       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_TCP_NODELAY);
     940             : #endif
     941             : 
     942             : #if LIBCURL_VERSION_NUM >= 0x070c02 /* Available since 7.12.2 */
     943       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_OS_ERRNO);
     944             : #endif
     945             : 
     946             : #if LIBCURL_VERSION_NUM >= 0x070c03 /* Available since 7.12.3 */
     947       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_NUM_CONNECTS);
     948       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_SSL_ENGINES);
     949             : #endif
     950             : 
     951             : #if LIBCURL_VERSION_NUM >= 0x070e01 /* Available since 7.14.1 */
     952       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_COOKIELIST);
     953       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_COOKIELIST);
     954       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_IGNORE_CONTENT_LENGTH);
     955             : #endif
     956             : 
     957             : #if LIBCURL_VERSION_NUM >= 0x070f00 /* Available since 7.15.0 */
     958       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_SKIP_PASV_IP);
     959             : #endif
     960             : 
     961             : #if LIBCURL_VERSION_NUM >= 0x070f01 /* Available since 7.15.1 */
     962       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_FILEMETHOD);
     963             : #endif
     964             : 
     965             : #if LIBCURL_VERSION_NUM >= 0x070f02 /* Available since 7.15.2 */
     966       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_CONNECT_ONLY);
     967       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_LOCALPORT);
     968       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_LOCALPORTRANGE);
     969             : #endif
     970             : 
     971             : #if LIBCURL_VERSION_NUM >= 0x070f03 /* Available since 7.15.3 */
     972       20423 :         REGISTER_CURL_CONSTANT(CURLFTPMETHOD_MULTICWD);
     973       20423 :         REGISTER_CURL_CONSTANT(CURLFTPMETHOD_NOCWD);
     974       20423 :         REGISTER_CURL_CONSTANT(CURLFTPMETHOD_SINGLECWD);
     975             : #endif
     976             : 
     977             : #if LIBCURL_VERSION_NUM >= 0x070f04 /* Available since 7.15.4 */
     978       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_FTP_ENTRY_PATH);
     979             : #endif
     980             : 
     981             : #if LIBCURL_VERSION_NUM >= 0x070f05 /* Available since 7.15.5 */
     982       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_ALTERNATIVE_TO_USER);
     983       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_MAX_RECV_SPEED_LARGE);
     984       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_MAX_SEND_SPEED_LARGE);
     985             : #endif
     986             : 
     987             : #if LIBCURL_VERSION_NUM >= 0x071000 /* Available since 7.16.0 */
     988       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSL_SESSIONID_CACHE);
     989       20423 :         REGISTER_CURL_CONSTANT(CURLMOPT_PIPELINING);
     990             : #endif
     991             : 
     992             : #if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */
     993       20423 :         REGISTER_CURL_CONSTANT(CURLE_SSH);
     994       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_SSL_CCC);
     995       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSH_AUTH_TYPES);
     996       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSH_PRIVATE_KEYFILE);
     997       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSH_PUBLIC_KEYFILE);
     998       20423 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_ACTIVE);
     999       20423 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_NONE);
    1000       20423 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_PASSIVE);
    1001             : #endif
    1002             : 
    1003             : #if LIBCURL_VERSION_NUM >= 0x071002 /* Available since 7.16.2 */
    1004       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT_MS);
    1005       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTP_CONTENT_DECODING);
    1006       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTP_TRANSFER_DECODING);
    1007       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT_MS);
    1008             : #endif
    1009             : 
    1010             : #if LIBCURL_VERSION_NUM >= 0x071003 /* Available since 7.16.3 */
    1011       20423 :         REGISTER_CURL_CONSTANT(CURLMOPT_MAXCONNECTS);
    1012             : #endif
    1013             : 
    1014             : #if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */
    1015       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_KRBLEVEL);
    1016       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_NEW_DIRECTORY_PERMS);
    1017       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_NEW_FILE_PERMS);
    1018             : #endif
    1019             : 
    1020             : #if LIBCURL_VERSION_NUM >= 0x071100 /* Available since 7.17.0 */
    1021       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_APPEND);
    1022       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_DIRLISTONLY);
    1023       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_USE_SSL);
    1024             :         /* Curl SSL Constants */
    1025       20423 :         REGISTER_CURL_CONSTANT(CURLUSESSL_ALL);
    1026       20423 :         REGISTER_CURL_CONSTANT(CURLUSESSL_CONTROL);
    1027       20423 :         REGISTER_CURL_CONSTANT(CURLUSESSL_NONE);
    1028       20423 :         REGISTER_CURL_CONSTANT(CURLUSESSL_TRY);
    1029             : #endif
    1030             : 
    1031             : #if LIBCURL_VERSION_NUM >= 0x071101 /* Available since 7.17.1 */
    1032       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSH_HOST_PUBLIC_KEY_MD5);
    1033             : #endif
    1034             : 
    1035             : #if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */
    1036       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXY_TRANSFER_MODE);
    1037       20423 :         REGISTER_CURL_CONSTANT(CURLPAUSE_ALL);
    1038       20423 :         REGISTER_CURL_CONSTANT(CURLPAUSE_CONT);
    1039       20423 :         REGISTER_CURL_CONSTANT(CURLPAUSE_RECV);
    1040       20423 :         REGISTER_CURL_CONSTANT(CURLPAUSE_RECV_CONT);
    1041       20423 :         REGISTER_CURL_CONSTANT(CURLPAUSE_SEND);
    1042       20423 :         REGISTER_CURL_CONSTANT(CURLPAUSE_SEND_CONT);
    1043       20423 :         REGISTER_CURL_CONSTANT(CURL_READFUNC_PAUSE);
    1044       20423 :         REGISTER_CURL_CONSTANT(CURL_WRITEFUNC_PAUSE);
    1045             : #endif
    1046             : 
    1047             : #if LIBCURL_VERSION_NUM >= 0x071202 /* Available since 7.18.2 */
    1048       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_URL);
    1049             : #endif
    1050             : 
    1051             : #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
    1052       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_APPCONNECT_TIME);
    1053       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_PRIMARY_IP);
    1054             : 
    1055       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_ADDRESS_SCOPE);
    1056       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_CRLFILE);
    1057       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_ISSUERCERT);
    1058       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_KEYPASSWD);
    1059             : 
    1060       20423 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_ANY);
    1061       20423 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_DEFAULT);
    1062       20423 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_HOST);
    1063       20423 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_KEYBOARD);
    1064       20423 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_NONE);
    1065       20423 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PASSWORD);
    1066       20423 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PUBLICKEY);
    1067             : #endif
    1068             : 
    1069             : #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
    1070       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_CERTINFO);
    1071       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_CERTINFO);
    1072       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PASSWORD);
    1073       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_POSTREDIR);
    1074       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYPASSWORD);
    1075       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYUSERNAME);
    1076       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_USERNAME);
    1077             : #endif
    1078             : 
    1079             : #if LIBCURL_VERSION_NUM >= 0x071303 /* Available since 7.19.3 */
    1080       20423 :         REGISTER_CURL_CONSTANT(CURLAUTH_DIGEST_IE);
    1081             : #endif
    1082             : 
    1083             : #if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */
    1084       20423 :         REGISTER_CURL_CONSTANT(CURLINFO_CONDITION_UNMET);
    1085             : 
    1086       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_NOPROXY);
    1087       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_PROTOCOLS);
    1088       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_REDIR_PROTOCOLS);
    1089       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SOCKS5_GSSAPI_NEC);
    1090       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SOCKS5_GSSAPI_SERVICE);
    1091       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_TFTP_BLKSIZE);
    1092             : 
    1093       20423 :         REGISTER_CURL_CONSTANT(CURLPROTO_ALL);
    1094       20423 :         REGISTER_CURL_CONSTANT(CURLPROTO_DICT);
    1095       20423 :         REGISTER_CURL_CONSTANT(CURLPROTO_FILE);
    1096       20423 :         REGISTER_CURL_CONSTANT(CURLPROTO_FTP);
    1097       20423 :         REGISTER_CURL_CONSTANT(CURLPROTO_FTPS);
    1098       20423 :         REGISTER_CURL_CONSTANT(CURLPROTO_HTTP);
    1099       20423 :         REGISTER_CURL_CONSTANT(CURLPROTO_HTTPS);
    1100       20423 :         REGISTER_CURL_CONSTANT(CURLPROTO_LDAP);
    1101       20423 :         REGISTER_CURL_CONSTANT(CURLPROTO_LDAPS);
    1102       20423 :         REGISTER_CURL_CONSTANT(CURLPROTO_SCP);
    1103       20423 :         REGISTER_CURL_CONSTANT(CURLPROTO_SFTP);
    1104       20423 :         REGISTER_CURL_CONSTANT(CURLPROTO_TELNET);
    1105       20423 :         REGISTER_CURL_CONSTANT(CURLPROTO_TFTP);
    1106             : #endif
    1107             : 
    1108             : #if LIBCURL_VERSION_NUM >= 0x071306 /* Available since 7.19.6 */
    1109       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SSH_KNOWNHOSTS);
    1110             : #endif
    1111             : 
    1112             : #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
    1113             :         REGISTER_CURL_CONSTANT(CURLINFO_RTSP_CLIENT_CSEQ);
    1114             :         REGISTER_CURL_CONSTANT(CURLINFO_RTSP_CSEQ_RECV);
    1115             :         REGISTER_CURL_CONSTANT(CURLINFO_RTSP_SERVER_CSEQ);
    1116             :         REGISTER_CURL_CONSTANT(CURLINFO_RTSP_SESSION_ID);
    1117             :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_PRET);
    1118             :         REGISTER_CURL_CONSTANT(CURLOPT_MAIL_FROM);
    1119             :         REGISTER_CURL_CONSTANT(CURLOPT_MAIL_RCPT);
    1120             :         REGISTER_CURL_CONSTANT(CURLOPT_RTSP_CLIENT_CSEQ);
    1121             :         REGISTER_CURL_CONSTANT(CURLOPT_RTSP_REQUEST);
    1122             :         REGISTER_CURL_CONSTANT(CURLOPT_RTSP_SERVER_CSEQ);
    1123             :         REGISTER_CURL_CONSTANT(CURLOPT_RTSP_SESSION_ID);
    1124             :         REGISTER_CURL_CONSTANT(CURLOPT_RTSP_STREAM_URI);
    1125             :         REGISTER_CURL_CONSTANT(CURLOPT_RTSP_TRANSPORT);
    1126             :         REGISTER_CURL_CONSTANT(CURLPROTO_IMAP);
    1127             :         REGISTER_CURL_CONSTANT(CURLPROTO_IMAPS);
    1128             :         REGISTER_CURL_CONSTANT(CURLPROTO_POP3);
    1129             :         REGISTER_CURL_CONSTANT(CURLPROTO_POP3S);
    1130             :         REGISTER_CURL_CONSTANT(CURLPROTO_RTSP);
    1131             :         REGISTER_CURL_CONSTANT(CURLPROTO_SMTP);
    1132             :         REGISTER_CURL_CONSTANT(CURLPROTO_SMTPS);
    1133             :         REGISTER_CURL_CONSTANT(CURL_RTSPREQ_ANNOUNCE);
    1134             :         REGISTER_CURL_CONSTANT(CURL_RTSPREQ_DESCRIBE);
    1135             :         REGISTER_CURL_CONSTANT(CURL_RTSPREQ_GET_PARAMETER);
    1136             :         REGISTER_CURL_CONSTANT(CURL_RTSPREQ_OPTIONS);
    1137             :         REGISTER_CURL_CONSTANT(CURL_RTSPREQ_PAUSE);
    1138             :         REGISTER_CURL_CONSTANT(CURL_RTSPREQ_PLAY);
    1139             :         REGISTER_CURL_CONSTANT(CURL_RTSPREQ_RECEIVE);
    1140             :         REGISTER_CURL_CONSTANT(CURL_RTSPREQ_RECORD);
    1141             :         REGISTER_CURL_CONSTANT(CURL_RTSPREQ_SETUP);
    1142             :         REGISTER_CURL_CONSTANT(CURL_RTSPREQ_SET_PARAMETER);
    1143             :         REGISTER_CURL_CONSTANT(CURL_RTSPREQ_TEARDOWN);
    1144             : #endif
    1145             : 
    1146             : #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
    1147             :         REGISTER_CURL_CONSTANT(CURLINFO_LOCAL_IP);
    1148             :         REGISTER_CURL_CONSTANT(CURLINFO_LOCAL_PORT);
    1149             :         REGISTER_CURL_CONSTANT(CURLINFO_PRIMARY_PORT);
    1150             :         REGISTER_CURL_CONSTANT(CURLOPT_FNMATCH_FUNCTION);
    1151             :         REGISTER_CURL_CONSTANT(CURLOPT_WILDCARDMATCH);
    1152             :         REGISTER_CURL_CONSTANT(CURLPROTO_RTMP);
    1153             :         REGISTER_CURL_CONSTANT(CURLPROTO_RTMPE);
    1154             :         REGISTER_CURL_CONSTANT(CURLPROTO_RTMPS);
    1155             :         REGISTER_CURL_CONSTANT(CURLPROTO_RTMPT);
    1156             :         REGISTER_CURL_CONSTANT(CURLPROTO_RTMPTE);
    1157             :         REGISTER_CURL_CONSTANT(CURLPROTO_RTMPTS);
    1158             :         REGISTER_CURL_CONSTANT(CURL_FNMATCHFUNC_FAIL);
    1159             :         REGISTER_CURL_CONSTANT(CURL_FNMATCHFUNC_MATCH);
    1160             :         REGISTER_CURL_CONSTANT(CURL_FNMATCHFUNC_NOMATCH);
    1161             : #endif
    1162             : 
    1163             : #if LIBCURL_VERSION_NUM >= 0x071502 /* Available since 7.21.2 */
    1164             :         REGISTER_CURL_CONSTANT(CURLPROTO_GOPHER);
    1165             : #endif
    1166             : 
    1167             : #if LIBCURL_VERSION_NUM >= 0x071503 /* Available since 7.21.3 */
    1168             :         REGISTER_CURL_CONSTANT(CURLAUTH_ONLY);
    1169             :         REGISTER_CURL_CONSTANT(CURLOPT_RESOLVE);
    1170             : #endif
    1171             : 
    1172             : #if LIBCURL_VERSION_NUM >= 0x071504 /* Available since 7.21.4 */
    1173             :         REGISTER_CURL_CONSTANT(CURLOPT_TLSAUTH_PASSWORD);
    1174             :         REGISTER_CURL_CONSTANT(CURLOPT_TLSAUTH_TYPE);
    1175             :         REGISTER_CURL_CONSTANT(CURLOPT_TLSAUTH_USERNAME);
    1176             :         REGISTER_CURL_CONSTANT(CURL_TLSAUTH_SRP);
    1177             : #endif
    1178             : 
    1179             : #if LIBCURL_VERSION_NUM >= 0x071506 /* Available since 7.21.6 */
    1180             :         REGISTER_CURL_CONSTANT(CURLOPT_ACCEPT_ENCODING);
    1181             :         REGISTER_CURL_CONSTANT(CURLOPT_TRANSFER_ENCODING);
    1182             : #endif
    1183             : 
    1184             : #if LIBCURL_VERSION_NUM >= 0x071600 /* Available since 7.22.0 */
    1185             :         REGISTER_CURL_CONSTANT(CURLGSSAPI_DELEGATION_FLAG);
    1186             :         REGISTER_CURL_CONSTANT(CURLGSSAPI_DELEGATION_POLICY_FLAG);
    1187             :         REGISTER_CURL_CONSTANT(CURLOPT_GSSAPI_DELEGATION);
    1188             : #endif
    1189             : 
    1190             : #if LIBCURL_VERSION_NUM >= 0x071800 /* Available since 7.24.0 */
    1191             :         REGISTER_CURL_CONSTANT(CURLOPT_ACCEPTTIMEOUT_MS);
    1192             :         REGISTER_CURL_CONSTANT(CURLOPT_DNS_SERVERS);
    1193             : #endif
    1194             : 
    1195             : #if LIBCURL_VERSION_NUM >= 0x071900 /* Available since 7.25.0 */
    1196             :         REGISTER_CURL_CONSTANT(CURLOPT_MAIL_AUTH);
    1197             :         REGISTER_CURL_CONSTANT(CURLOPT_SSL_OPTIONS);
    1198             :         REGISTER_CURL_CONSTANT(CURLOPT_TCP_KEEPALIVE);
    1199             :         REGISTER_CURL_CONSTANT(CURLOPT_TCP_KEEPIDLE);
    1200             :         REGISTER_CURL_CONSTANT(CURLOPT_TCP_KEEPINTVL);
    1201             :         REGISTER_CURL_CONSTANT(CURLSSLOPT_ALLOW_BEAST);
    1202             : #endif
    1203             : 
    1204             : #if LIBCURL_VERSION_NUM >= 0x072200 /* Available since 7.34.0 */
    1205             :         REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1_0);
    1206             :         REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1_1);
    1207             :         REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1_2);
    1208             : #endif
    1209             : 
    1210             : #if CURLOPT_FTPASCII != 0
    1211             :         REGISTER_CURL_CONSTANT(CURLOPT_FTPASCII);
    1212             : #endif
    1213             : #if CURLOPT_MUTE != 0
    1214             :         REGISTER_CURL_CONSTANT(CURLOPT_MUTE);
    1215             : #endif
    1216             : #if CURLOPT_PASSWDFUNCTION != 0
    1217             :         REGISTER_CURL_CONSTANT(CURLOPT_PASSWDFUNCTION);
    1218             : #endif
    1219       20423 :         REGISTER_CURL_CONSTANT(CURLOPT_SAFE_UPLOAD);
    1220             : 
    1221             : #ifdef PHP_CURL_NEED_OPENSSL_TSL
    1222             :         if (!CRYPTO_get_id_callback()) {
    1223             :                 int i, c = CRYPTO_num_locks();
    1224             : 
    1225             :                 php_curl_openssl_tsl = malloc(c * sizeof(MUTEX_T));
    1226             :                 if (!php_curl_openssl_tsl) {
    1227             :                         return FAILURE;
    1228             :                 }
    1229             : 
    1230             :                 for (i = 0; i < c; ++i) {
    1231             :                         php_curl_openssl_tsl[i] = tsrm_mutex_alloc();
    1232             :                 }
    1233             : 
    1234             :                 CRYPTO_set_id_callback(php_curl_ssl_id);
    1235             :                 CRYPTO_set_locking_callback(php_curl_ssl_lock);
    1236             :         }
    1237             : #endif
    1238             : #ifdef PHP_CURL_NEED_GNUTLS_TSL
    1239             :         gcry_control(GCRYCTL_SET_THREAD_CBS, &php_curl_gnutls_tsl);
    1240             : #endif
    1241             : 
    1242       20423 :         if (curl_global_init(CURL_GLOBAL_SSL) != CURLE_OK) {
    1243           0 :                 return FAILURE;
    1244             :         }
    1245             : 
    1246       20423 :         curlfile_register_class(TSRMLS_C);
    1247             : 
    1248       20423 :         return SUCCESS;
    1249             : }
    1250             : /* }}} */
    1251             : 
    1252             : /* {{{ PHP_MSHUTDOWN_FUNCTION
    1253             :  */
    1254       20457 : PHP_MSHUTDOWN_FUNCTION(curl)
    1255             : {
    1256       20457 :         curl_global_cleanup();
    1257             : #ifdef PHP_CURL_NEED_OPENSSL_TSL
    1258             :         if (php_curl_openssl_tsl) {
    1259             :                 int i, c = CRYPTO_num_locks();
    1260             : 
    1261             :                 CRYPTO_set_id_callback(NULL);
    1262             :                 CRYPTO_set_locking_callback(NULL);
    1263             : 
    1264             :                 for (i = 0; i < c; ++i) {
    1265             :                         tsrm_mutex_free(php_curl_openssl_tsl[i]);
    1266             :                 }
    1267             : 
    1268             :                 free(php_curl_openssl_tsl);
    1269             :                 php_curl_openssl_tsl = NULL;
    1270             :         }
    1271             : #endif
    1272       20457 :         UNREGISTER_INI_ENTRIES();
    1273       20457 :         return SUCCESS;
    1274             : }
    1275             : /* }}} */
    1276             : 
    1277             : /* {{{ curl_write_nothing
    1278             :  * Used as a work around. See _php_curl_close_ex
    1279             :  */
    1280           0 : static size_t curl_write_nothing(char *data, size_t size, size_t nmemb, void *ctx)
    1281             : {
    1282           0 :         return size * nmemb;
    1283             : }
    1284             : /* }}} */
    1285             : 
    1286             : /* {{{ curl_write
    1287             :  */
    1288          91 : static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx)
    1289             : {
    1290          91 :         php_curl *ch = (php_curl *) ctx;
    1291          91 :         php_curl_write *t = ch->handlers->write;
    1292          91 :         size_t length = size * nmemb;
    1293             :         TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
    1294             : 
    1295             : #if PHP_CURL_DEBUG
    1296             :         fprintf(stderr, "curl_write() called\n");
    1297             :         fprintf(stderr, "data = %s, size = %d, nmemb = %d, ctx = %x\n", data, size, nmemb, ctx);
    1298             : #endif
    1299             : 
    1300          91 :         switch (t->method) {
    1301             :                 case PHP_CURL_STDOUT:
    1302          14 :                         PHPWRITE(data, length);
    1303          14 :                         break;
    1304             :                 case PHP_CURL_FILE:
    1305           3 :                         return fwrite(data, size, nmemb, t->fp);
    1306             :                 case PHP_CURL_RETURN:
    1307          72 :                         if (length > 0) {
    1308          72 :                                 smart_str_appendl(&t->buf, data, (int) length);
    1309             :                         }
    1310          72 :                         break;
    1311             :                 case PHP_CURL_USER: {
    1312             :                         zval argv[2];
    1313             :                         zval retval;
    1314             :                         int  error;
    1315             :                         zend_fcall_info fci;
    1316             : 
    1317           2 :                         ZVAL_RES(&argv[0], ch->res);
    1318             :                         Z_ADDREF(argv[0]);
    1319           4 :                         ZVAL_STRINGL(&argv[1], data, length);
    1320             : 
    1321           2 :                         fci.size = sizeof(fci);
    1322           2 :                         fci.function_table = EG(function_table);
    1323           2 :                         fci.object = NULL;
    1324           2 :                         ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
    1325           2 :                         fci.retval = &retval;
    1326           2 :                         fci.param_count = 2;
    1327           2 :                         fci.params = argv;
    1328           2 :                         fci.no_separation = 0;
    1329           2 :                         fci.symbol_table = NULL;
    1330             : 
    1331           2 :                         ch->in_callback = 1;
    1332           2 :                         error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC);
    1333           2 :                         ch->in_callback = 0;
    1334           2 :                         if (error == FAILURE) {
    1335           0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the CURLOPT_WRITEFUNCTION");
    1336           0 :                                 length = -1;
    1337           2 :                         } else if (!Z_ISUNDEF(retval)) {
    1338           2 :                                 if (Z_TYPE(retval) != IS_LONG) {
    1339           0 :                                         convert_to_long_ex(&retval);
    1340             :                                 }
    1341           2 :                                 length = Z_LVAL(retval);
    1342             :                         }
    1343             : 
    1344           2 :                         zval_ptr_dtor(&argv[0]);
    1345           2 :                         zval_ptr_dtor(&argv[1]);
    1346             :                         break;
    1347             :                 }
    1348             :         }
    1349             : 
    1350          88 :         return length;
    1351             : }
    1352             : /* }}} */
    1353             : 
    1354             : #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
    1355             : /* {{{ curl_fnmatch
    1356             :  */
    1357             : static int curl_fnmatch(void *ctx, const char *pattern, const char *string)
    1358             : {
    1359             :         php_curl *ch = (php_curl *) ctx;
    1360             :         php_curl_fnmatch *t = ch->handlers->fnmatch;
    1361             :         int rval = CURL_FNMATCHFUNC_FAIL;
    1362             :         switch (t->method) {
    1363             :                 case PHP_CURL_USER: {
    1364             :                         zval argv[3];
    1365             :                         zval retval;
    1366             :                         int  error;
    1367             :                         zend_fcall_info fci;
    1368             :                         TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
    1369             : 
    1370             :                         ZVAL_RES(&argv[0], ch->res);
    1371             :                         Z_ADDREF(argv[0]);
    1372             :                         ZVAL_STRING(&argv[1], pattern);
    1373             :                         ZVAL_STRING(&argv[2], string);
    1374             : 
    1375             :                         fci.size = sizeof(fci);
    1376             :                         fci.function_table = EG(function_table);
    1377             :                         ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
    1378             :                         fci.object = NULL;
    1379             :                         fci.retval = &retval;
    1380             :                         fci.param_count = 3;
    1381             :                         fci.params = argv;
    1382             :                         fci.no_separation = 0;
    1383             :                         fci.symbol_table = NULL;
    1384             : 
    1385             :                         ch->in_callback = 1;
    1386             :                         error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC);
    1387             :                         ch->in_callback = 0;
    1388             :                         if (error == FAILURE) {
    1389             :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot call the CURLOPT_FNMATCH_FUNCTION");
    1390             :                         } else if (!Z_ISUNDEF(retval)) {
    1391             :                                 if (Z_TYPE(retval) != IS_LONG) {
    1392             :                                         convert_to_long_ex(&retval);
    1393             :                                 }
    1394             :                                 rval = Z_LVAL(retval);
    1395             :                         }
    1396             :                         zval_ptr_dtor(&argv[0]);
    1397             :                         zval_ptr_dtor(&argv[1]);
    1398             :                         zval_ptr_dtor(&argv[2]);
    1399             :                         break;
    1400             :                 }
    1401             :         }
    1402             :         return rval;
    1403             : }
    1404             : /* }}} */
    1405             : #endif
    1406             : 
    1407             : /* {{{ curl_progress
    1408             :  */
    1409           7 : static size_t curl_progress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
    1410             : {
    1411           7 :         php_curl *ch = (php_curl *)clientp;
    1412           7 :         php_curl_progress *t = ch->handlers->progress;
    1413           7 :         size_t  rval = 0;
    1414             : 
    1415             : #if PHP_CURL_DEBUG
    1416             :         fprintf(stderr, "curl_progress() called\n");
    1417             :         fprintf(stderr, "clientp = %x, dltotal = %f, dlnow = %f, ultotal = %f, ulnow = %f\n", clientp, dltotal, dlnow, ultotal, ulnow);
    1418             : #endif
    1419             : 
    1420           7 :         switch (t->method) {
    1421             :                 case PHP_CURL_USER: {
    1422             :                         zval argv[5];
    1423             :                         zval retval;
    1424             :                         int  error;
    1425             :                         zend_fcall_info fci;
    1426             :                         TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
    1427             : 
    1428           7 :                         ZVAL_RES(&argv[0], ch->res);
    1429             :                         Z_ADDREF(argv[0]);
    1430           7 :                         ZVAL_LONG(&argv[1], (zend_long)dltotal);
    1431           7 :                         ZVAL_LONG(&argv[2], (zend_long)dlnow);
    1432           7 :                         ZVAL_LONG(&argv[3], (zend_long)ultotal);
    1433           7 :                         ZVAL_LONG(&argv[4], (zend_long)ulnow);
    1434             : 
    1435           7 :                         fci.size = sizeof(fci);
    1436           7 :                         fci.function_table = EG(function_table);
    1437           7 :                         ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
    1438           7 :                         fci.object = NULL;
    1439           7 :                         fci.retval = &retval;
    1440           7 :                         fci.param_count = 5;
    1441           7 :                         fci.params = argv;
    1442           7 :                         fci.no_separation = 0;
    1443           7 :                         fci.symbol_table = NULL;
    1444             : 
    1445           7 :                         ch->in_callback = 1;
    1446           7 :                         error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC);
    1447           7 :                         ch->in_callback = 0;
    1448           7 :                         if (error == FAILURE) {
    1449           0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot call the CURLOPT_PROGRESSFUNCTION");
    1450           7 :                         } else if (!Z_ISUNDEF(retval)) {
    1451           7 :                                 if (Z_TYPE(retval) != IS_LONG) {
    1452           7 :                                         convert_to_long_ex(&retval);
    1453             :                                 }
    1454           7 :                                 if (0 != Z_LVAL(retval)) {
    1455           0 :                                         rval = 1;
    1456             :                                 }
    1457             :                         }
    1458           7 :                         zval_ptr_dtor(&argv[0]);
    1459           7 :                         zval_ptr_dtor(&argv[1]);
    1460           7 :                         zval_ptr_dtor(&argv[2]);
    1461           7 :                         zval_ptr_dtor(&argv[3]);
    1462           7 :                         zval_ptr_dtor(&argv[4]);
    1463             :                         break;
    1464             :                 }
    1465             :         }
    1466           7 :         return rval;
    1467             : }
    1468             : /* }}} */
    1469             : 
    1470             : /* {{{ curl_read
    1471             :  */
    1472           3 : static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx)
    1473             : {
    1474           3 :         php_curl *ch = (php_curl *)ctx;
    1475           3 :         php_curl_read *t = ch->handlers->read;
    1476           3 :         int length = 0;
    1477             : 
    1478           3 :         switch (t->method) {
    1479             :                 case PHP_CURL_DIRECT:
    1480           1 :                         if (t->fp) {
    1481           1 :                                 length = fread(data, size, nmemb, t->fp);
    1482             :                         }
    1483           1 :                         break;
    1484             :                 case PHP_CURL_USER: {
    1485             :                         zval argv[3];
    1486             :                         zval retval;
    1487             :                         int  error;
    1488             :                         zend_fcall_info fci;
    1489             :                         TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
    1490             : 
    1491           2 :                         ZVAL_RES(&argv[0], ch->res);
    1492             :                         Z_ADDREF(argv[0]);
    1493           2 :                         ZVAL_RES(&argv[1], t->res);
    1494             :                         Z_ADDREF(argv[1]);
    1495           2 :                         ZVAL_LONG(&argv[2], (int)size * nmemb);
    1496             : 
    1497           2 :                         fci.size = sizeof(fci);
    1498           2 :                         fci.function_table = EG(function_table);
    1499           2 :                         ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
    1500           2 :                         fci.object = NULL;
    1501           2 :                         fci.retval = &retval;
    1502           2 :                         fci.param_count = 3;
    1503           2 :                         fci.params = argv;
    1504           2 :                         fci.no_separation = 0;
    1505           2 :                         fci.symbol_table = NULL;
    1506             : 
    1507           2 :                         ch->in_callback = 1;
    1508           2 :                         error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC);
    1509           2 :                         ch->in_callback = 0;
    1510           2 :                         if (error == FAILURE) {
    1511           0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot call the CURLOPT_READFUNCTION");
    1512             : #if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */
    1513           0 :                                 length = CURL_READFUNC_ABORT;
    1514             : #endif
    1515           2 :                         } else if (!Z_ISUNDEF(retval)) {
    1516           2 :                                 if (Z_TYPE(retval) == IS_STRING) {
    1517           2 :                                         length = MIN((int) (size * nmemb), Z_STRLEN(retval));
    1518           2 :                                         memcpy(data, Z_STRVAL(retval), length);
    1519             :                                 }
    1520           2 :                                 zval_ptr_dtor(&retval);
    1521             :                         }
    1522             : 
    1523           2 :                         zval_ptr_dtor(&argv[0]);
    1524           2 :                         zval_ptr_dtor(&argv[1]);
    1525           2 :                         zval_ptr_dtor(&argv[2]);
    1526             :                         break;
    1527             :                 }
    1528             :         }
    1529             : 
    1530           3 :         return length;
    1531             : }
    1532             : /* }}} */
    1533             : 
    1534             : /* {{{ curl_write_header
    1535             :  */
    1536         584 : static size_t curl_write_header(char *data, size_t size, size_t nmemb, void *ctx)
    1537             : {
    1538         584 :         php_curl *ch = (php_curl *) ctx;
    1539         584 :         php_curl_write *t = ch->handlers->write_header;
    1540         584 :         size_t length = size * nmemb;
    1541             :         TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
    1542             : 
    1543         584 :         switch (t->method) {
    1544             :                 case PHP_CURL_STDOUT:
    1545             :                         /* Handle special case write when we're returning the entire transfer
    1546             :                          */
    1547           0 :                         if (ch->handlers->write->method == PHP_CURL_RETURN && length > 0) {
    1548           0 :                                 smart_str_appendl(&ch->handlers->write->buf, data, (int) length);
    1549             :                         } else {
    1550           0 :                                 PHPWRITE(data, length);
    1551             :                         }
    1552           0 :                         break;
    1553             :                 case PHP_CURL_FILE:
    1554           0 :                         return fwrite(data, size, nmemb, t->fp);
    1555             :                 case PHP_CURL_USER: {
    1556             :                         zval argv[2];
    1557             :                         zval retval;
    1558             :                         int  error;
    1559             :                         zend_fcall_info fci;
    1560             : 
    1561           1 :                         ZVAL_RES(&argv[0], ch->res);
    1562             :                         Z_ADDREF(argv[0]);
    1563           2 :                         ZVAL_STRINGL(&argv[1], data, length);
    1564             : 
    1565           1 :                         fci.size = sizeof(fci);
    1566           1 :                         fci.function_table = EG(function_table);
    1567           1 :                         ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
    1568           1 :                         fci.symbol_table = NULL;
    1569           1 :                         fci.object = NULL;
    1570           1 :                         fci.retval = &retval;
    1571           1 :                         fci.param_count = 2;
    1572           1 :                         fci.params = argv;
    1573           1 :                         fci.no_separation = 0;
    1574             : 
    1575           1 :                         ch->in_callback = 1;
    1576           1 :                         error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC);
    1577           1 :                         ch->in_callback = 0;
    1578           1 :                         if (error == FAILURE) {
    1579           0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the CURLOPT_HEADERFUNCTION");
    1580           0 :                                 length = -1;
    1581           1 :                         } else if (!Z_ISUNDEF(retval)) {
    1582           1 :                                 if (Z_TYPE(retval) != IS_LONG) {
    1583           1 :                                         convert_to_long_ex(&retval);
    1584             :                                 }
    1585           1 :                                 length = Z_LVAL(retval);
    1586             :                         }
    1587           1 :                         zval_ptr_dtor(&argv[0]);
    1588           1 :                         zval_ptr_dtor(&argv[1]);
    1589           1 :                         break;
    1590             :                 }
    1591             : 
    1592             :                 case PHP_CURL_IGNORE:
    1593         583 :                         return length;
    1594             : 
    1595             :                 default:
    1596           0 :                         return -1;
    1597             :         }
    1598             : 
    1599           1 :         return length;
    1600             : }
    1601             : /* }}} */
    1602             : 
    1603           0 : static int curl_debug(CURL *cp, curl_infotype type, char *buf, size_t buf_len, void *ctx) /* {{{ */
    1604             : {
    1605           0 :         php_curl *ch = (php_curl *)ctx;
    1606             : 
    1607           0 :         if (type == CURLINFO_HEADER_OUT) {
    1608           0 :                 if (ch->header.str) {
    1609           0 :                         zend_string_release(ch->header.str);
    1610             :                 }
    1611           0 :                 if (buf_len > 0) {
    1612           0 :                         ch->header.str = zend_string_init(buf, buf_len, 0);
    1613             :                 }
    1614             :         }
    1615             : 
    1616           0 :         return 0;
    1617             : }
    1618             : /* }}} */
    1619             : 
    1620             : #if CURLOPT_PASSWDFUNCTION != 0
    1621             : /* {{{ curl_passwd
    1622             :  */
    1623             : static size_t curl_passwd(void *ctx, char *prompt, char *buf, int buflen)
    1624             : {
    1625             :         php_curl *ch = (php_curl *) ctx;
    1626             :         zval *func = &ch->handlers->passwd;
    1627             :         zval  argv[3];
    1628             :         zval  retval;
    1629             :         int   error;
    1630             :         int   ret = -1;
    1631             :         TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
    1632             : 
    1633             :         ZVAL_RES(&argv[0], ch->res);
    1634             :         Z_ADDREF(argv[0]);
    1635             :         ZVAL_STRING(&argv[1], prompt);
    1636             :         ZVAL_LONG(&argv[2], buflen);
    1637             : 
    1638             :         error = call_user_function(EG(function_table), NULL, func, &retval, 2, argv TSRMLS_CC);
    1639             :         if (error == FAILURE) {
    1640             :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the CURLOPT_PASSWDFUNCTION");
    1641             :         } else if (Z_TYPE(retval) == IS_STRING) {
    1642             :                 if (Z_STRLEN(retval) > buflen) {
    1643             :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Returned password is too long for libcurl to handle");
    1644             :                 } else {
    1645             :                         memcpy(buf, Z_STRVAL(retval), Z_STRLEN(retval) + 1);
    1646             :                 }
    1647             :         } else {
    1648             :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "User handler '%s' did not return a string", Z_STRVAL_P(func));
    1649             :         }
    1650             : 
    1651             :         zval_ptr_dtor(&argv[0]);
    1652             :         zval_ptr_dtor(&argv[1]);
    1653             :         zval_ptr_dtor(&argv[2]);
    1654             :         zval_ptr_dtor(&retval);
    1655             : 
    1656             :         return ret;
    1657             : }
    1658             : /* }}} */
    1659             : #endif
    1660             : 
    1661             : /* {{{ curl_free_string
    1662             :  */
    1663           1 : static void curl_free_string(void **string)
    1664             : {
    1665           1 :         efree((char *)*string);
    1666           1 : }
    1667             : /* }}} */
    1668             : 
    1669             : /* {{{ curl_free_post
    1670             :  */
    1671          20 : static void curl_free_post(void **post)
    1672             : {
    1673          20 :         curl_formfree((struct HttpPost *)*post);
    1674          20 : }
    1675             : /* }}} */
    1676             : 
    1677             : /* {{{ curl_free_slist
    1678             :  */
    1679       10003 : static void curl_free_slist(zval *el)
    1680             : {
    1681       10003 :         curl_slist_free_all(((struct curl_slist *)Z_PTR_P(el)));
    1682       10003 : }
    1683             : /* }}} */
    1684             : 
    1685             : /* {{{ proto array curl_version([int version])
    1686             :    Return cURL version information. */
    1687          37 : PHP_FUNCTION(curl_version)
    1688             : {
    1689             :         curl_version_info_data *d;
    1690          37 :         zend_long uversion = CURLVERSION_NOW;
    1691             : 
    1692          37 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &uversion) == FAILURE) {
    1693           8 :                 return;
    1694             :         }
    1695             : 
    1696          29 :         d = curl_version_info(uversion);
    1697          29 :         if (d == NULL) {
    1698           0 :                 RETURN_FALSE;
    1699             :         }
    1700             : 
    1701          29 :         array_init(return_value);
    1702             : 
    1703          29 :         CAAL("version_number", d->version_num);
    1704          29 :         CAAL("age", d->age);
    1705          29 :         CAAL("features", d->features);
    1706          29 :         CAAL("ssl_version_number", d->ssl_version_num);
    1707          29 :         CAAS("version", d->version);
    1708          29 :         CAAS("host", d->host);
    1709          29 :         CAAS("ssl_version", d->ssl_version);
    1710          29 :         CAAS("libz_version", d->libz_version);
    1711             :         /* Add an array of protocols */
    1712             :         {
    1713          29 :                 char **p = (char **) d->protocols;
    1714             :                 zval protocol_list;
    1715             : 
    1716          29 :                 array_init(&protocol_list);
    1717             : 
    1718         406 :                 while (*p != NULL) {
    1719         348 :                         add_next_index_string(&protocol_list, *p);
    1720         348 :                         p++;
    1721             :                 }
    1722          29 :                 CAAZ("protocols", &protocol_list);
    1723             :         }
    1724             : }
    1725             : /* }}} */
    1726             : 
    1727             : /* {{{ alloc_curl_handle
    1728             :  */
    1729         108 : static php_curl *alloc_curl_handle()
    1730             : {
    1731         108 :         php_curl *ch               = ecalloc(1, sizeof(php_curl));
    1732         108 :         ch->to_free                = ecalloc(1, sizeof(struct _php_curl_free));
    1733         108 :         ch->handlers               = ecalloc(1, sizeof(php_curl_handlers));
    1734         108 :         ch->handlers->write        = ecalloc(1, sizeof(php_curl_write));
    1735         108 :         ch->handlers->write_header = ecalloc(1, sizeof(php_curl_write));
    1736         108 :         ch->handlers->read         = ecalloc(1, sizeof(php_curl_read));
    1737         108 :         ch->handlers->progress     = NULL;
    1738             : #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
    1739             :         ch->handlers->fnmatch      = NULL;
    1740             : #endif
    1741         108 :         ch->clone                               = 1;
    1742             : 
    1743         108 :         memset(&ch->err, 0, sizeof(struct _php_curl_error));
    1744             : 
    1745         108 :         zend_llist_init(&ch->to_free->str,   sizeof(char *),          (llist_dtor_func_t)curl_free_string, 0);
    1746         108 :         zend_llist_init(&ch->to_free->post,  sizeof(struct HttpPost), (llist_dtor_func_t)curl_free_post,   0);
    1747         108 :         ch->safe_upload = 1; /* for now, for BC reason we allow unsafe API */
    1748             : 
    1749         108 :         ch->to_free->slist = emalloc(sizeof(HashTable));
    1750         108 :         zend_hash_init(ch->to_free->slist, 4, NULL, curl_free_slist, 0);
    1751             : 
    1752         108 :         return ch;
    1753             : }
    1754             : /* }}} */
    1755             : 
    1756             : #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
    1757             : /* {{{ split_certinfo
    1758             :  */
    1759           0 : static void split_certinfo(char *string, zval *hash)
    1760             : {
    1761           0 :         char *org = estrdup(string);
    1762           0 :         char *s = org;
    1763             :         char *split;
    1764             : 
    1765           0 :         if(org) {
    1766             :                 do {
    1767             :                         char *key;
    1768             :                         char *val;
    1769             :                         char *tmp;
    1770             : 
    1771           0 :                         split = strstr(s, "; ");
    1772           0 :                         if(split)
    1773           0 :                                 *split = '\0';
    1774             : 
    1775           0 :                         key = s;
    1776           0 :                         tmp = memchr(key, '=', 64);
    1777           0 :                         if(tmp) {
    1778           0 :                                 *tmp = '\0';
    1779           0 :                                 val = tmp+1;
    1780           0 :                                 add_assoc_string(hash, key, val);
    1781             :                         }
    1782           0 :                         s = split+2;
    1783           0 :                 } while(split);
    1784           0 :                 efree(org);
    1785             :         }
    1786           0 : }
    1787             : /* }}} */
    1788             : 
    1789             : /* {{{ create_certinfo
    1790             :  */
    1791          13 : static void create_certinfo(struct curl_certinfo *ci, zval *listcode TSRMLS_DC)
    1792             : {
    1793             :         int i;
    1794             : 
    1795          13 :         if (ci) {
    1796             :                 zval certhash;
    1797             : 
    1798          13 :                 for (i=0; i<ci->num_of_certs; i++) {
    1799             :                         struct curl_slist *slist;
    1800             : 
    1801           0 :                         array_init(&certhash);
    1802           0 :                         for (slist = ci->certinfo[i]; slist; slist = slist->next) {
    1803             :                                 int len;
    1804             :                                 char s[64];
    1805             :                                 char *tmp;
    1806           0 :                                 strncpy(s, slist->data, 64);
    1807           0 :                                 tmp = memchr(s, ':', 64);
    1808           0 :                                 if(tmp) {
    1809           0 :                                         *tmp = '\0';
    1810           0 :                                         len = strlen(s);
    1811           0 :                                         if (!strcmp(s, "Subject") || !strcmp(s, "Issuer")) {
    1812             :                                                 zval hash;
    1813             : 
    1814           0 :                                                 array_init(&hash);
    1815             : 
    1816           0 :                                                 split_certinfo(&slist->data[len+1], &hash);
    1817           0 :                                                 add_assoc_zval(&certhash, s, &hash);
    1818             :                                         } else {
    1819           0 :                                                 add_assoc_string(&certhash, s, &slist->data[len+1]);
    1820             :                                         }
    1821             :                                 } else {
    1822           0 :                                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not extract hash key from certificate info");
    1823             :                                 }
    1824             :                         }
    1825           0 :                         add_next_index_zval(listcode, &certhash);
    1826             :                 }
    1827             :         }
    1828          13 : }
    1829             : /* }}} */
    1830             : #endif
    1831             : 
    1832             : /* {{{ _php_curl_set_default_options()
    1833             :    Set default options for a handle */
    1834          98 : static void _php_curl_set_default_options(php_curl *ch)
    1835             : {
    1836             :         char *cainfo;
    1837             : 
    1838          98 :         curl_easy_setopt(ch->cp, CURLOPT_NOPROGRESS,        1);
    1839          98 :         curl_easy_setopt(ch->cp, CURLOPT_VERBOSE,           0);
    1840          98 :         curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER,       ch->err.str);
    1841          98 :         curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION,     curl_write);
    1842          98 :         curl_easy_setopt(ch->cp, CURLOPT_FILE,              (void *) ch);
    1843          98 :         curl_easy_setopt(ch->cp, CURLOPT_READFUNCTION,      curl_read);
    1844          98 :         curl_easy_setopt(ch->cp, CURLOPT_INFILE,            (void *) ch);
    1845          98 :         curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION,    curl_write_header);
    1846          98 :         curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER,       (void *) ch);
    1847          98 :         curl_easy_setopt(ch->cp, CURLOPT_DNS_USE_GLOBAL_CACHE, 1);
    1848          98 :         curl_easy_setopt(ch->cp, CURLOPT_DNS_CACHE_TIMEOUT, 120);
    1849          98 :         curl_easy_setopt(ch->cp, CURLOPT_MAXREDIRS, 20); /* prevent infinite redirects */
    1850             : 
    1851          98 :         cainfo = INI_STR("openssl.cafile");
    1852          98 :         if (!(cainfo && cainfo[0] != '\0')) {
    1853          98 :                 cainfo = INI_STR("curl.cainfo");
    1854             :         }
    1855          98 :         if (cainfo && cainfo[0] != '\0') {
    1856           0 :                 curl_easy_setopt(ch->cp, CURLOPT_CAINFO, cainfo);
    1857             :         }
    1858             : 
    1859             : #if defined(ZTS)
    1860             :         curl_easy_setopt(ch->cp, CURLOPT_NOSIGNAL, 1);
    1861             : #endif
    1862          98 : }
    1863             : /* }}} */
    1864             : 
    1865             : /* {{{ proto resource curl_init([string url])
    1866             :    Initialize a cURL session */
    1867          97 : PHP_FUNCTION(curl_init)
    1868             : {
    1869             :         php_curl *ch;
    1870             :         CURL     *cp;
    1871          97 :         char     *url = NULL;
    1872          97 :         size_t            url_len = 0;
    1873             : 
    1874          97 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &url, &url_len) == FAILURE) {
    1875           0 :                 return;
    1876             :         }
    1877             : 
    1878          97 :         cp = curl_easy_init();
    1879          97 :         if (!cp) {
    1880           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not initialize a new cURL handle");
    1881           0 :                 RETURN_FALSE;
    1882             :         }
    1883             : 
    1884          97 :         ch = alloc_curl_handle();
    1885             :         TSRMLS_SET_CTX(ch->thread_ctx);
    1886             : 
    1887          97 :         ch->cp = cp;
    1888             : 
    1889          97 :         ch->handlers->write->method = PHP_CURL_STDOUT;
    1890          97 :         ch->handlers->read->method  = PHP_CURL_DIRECT;
    1891          97 :         ch->handlers->write_header->method = PHP_CURL_IGNORE;
    1892             : 
    1893          97 :         _php_curl_set_default_options(ch);
    1894             : 
    1895          97 :         if (url) {
    1896          11 :                 if (php_curl_option_url(ch, url, url_len TSRMLS_CC) == FAILURE) {
    1897           0 :                         _php_curl_close_ex(ch TSRMLS_CC);
    1898           0 :                         RETURN_FALSE;
    1899             :                 }
    1900             :         }
    1901             : 
    1902          97 :         ZEND_REGISTER_RESOURCE(return_value, ch, le_curl);
    1903          97 :         ch->res = Z_RES_P(return_value);
    1904             : }
    1905             : /* }}} */
    1906             : 
    1907             : /* {{{ proto resource curl_copy_handle(resource ch)
    1908             :    Copy a cURL handle along with all of it's preferences */
    1909          11 : PHP_FUNCTION(curl_copy_handle)
    1910             : {
    1911             :         CURL            *cp;
    1912             :         zval            *zid;
    1913             :         php_curl        *ch, *dupch;
    1914             : 
    1915          11 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
    1916           0 :                 return;
    1917             :         }
    1918             : 
    1919          11 :         ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
    1920             : 
    1921          11 :         cp = curl_easy_duphandle(ch->cp);
    1922          11 :         if (!cp) {
    1923           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot duplicate cURL handle");
    1924           0 :                 RETURN_FALSE;
    1925             :         }
    1926             : 
    1927          11 :         dupch = alloc_curl_handle();
    1928             :         TSRMLS_SET_CTX(dupch->thread_ctx);
    1929             : 
    1930          11 :         dupch->cp = cp;
    1931          11 :         Z_ADDREF_P(zid);
    1932          22 :         if (!Z_ISUNDEF(ch->handlers->write->stream)) {
    1933           1 :                 Z_ADDREF(ch->handlers->write->stream);
    1934             :         }
    1935          11 :         dupch->handlers->write->stream = ch->handlers->write->stream;
    1936          11 :         dupch->handlers->write->method = ch->handlers->write->method;
    1937          22 :         if (!Z_ISUNDEF(ch->handlers->read->stream)) {
    1938           0 :                 Z_ADDREF(ch->handlers->read->stream);
    1939             :         }
    1940          11 :         dupch->handlers->read->stream  = ch->handlers->read->stream;
    1941          11 :         dupch->handlers->read->method  = ch->handlers->read->method;
    1942          11 :         dupch->handlers->write_header->method = ch->handlers->write_header->method;
    1943          22 :         if (!Z_ISUNDEF(ch->handlers->write_header->stream)) {
    1944           0 :                 Z_ADDREF(ch->handlers->write_header->stream);
    1945             :         }
    1946          11 :         dupch->handlers->write_header->stream = ch->handlers->write_header->stream;
    1947             : 
    1948          11 :         dupch->handlers->write->fp = ch->handlers->write->fp;
    1949          11 :         dupch->handlers->write_header->fp = ch->handlers->write_header->fp;
    1950          11 :         dupch->handlers->read->fp = ch->handlers->read->fp;
    1951          11 :         dupch->handlers->read->res = ch->handlers->read->res;
    1952             : #if CURLOPT_PASSWDDATA != 0
    1953             :         if (!Z_ISUNDEF(ch->handlers->passwd)) {
    1954             :                 ZVAL_COPY(&dupch->handlers->passwd, &ch->handlers->passwd);
    1955             :                 curl_easy_setopt(ch->cp, CURLOPT_PASSWDDATA, (void *) dupch);
    1956             :         }
    1957             : #endif
    1958          22 :         if (!Z_ISUNDEF(ch->handlers->write->func_name)) {
    1959           0 :                 ZVAL_COPY(&dupch->handlers->write->func_name, &ch->handlers->write->func_name);
    1960             :         }
    1961          22 :         if (!Z_ISUNDEF(ch->handlers->read->func_name)) {
    1962           0 :                 ZVAL_COPY(&dupch->handlers->read->func_name, &ch->handlers->read->func_name);
    1963             :         }
    1964          22 :         if (!Z_ISUNDEF(ch->handlers->write_header->func_name)) {
    1965           0 :                 ZVAL_COPY(&dupch->handlers->write_header->func_name, &ch->handlers->write_header->func_name);
    1966             :         }
    1967             : 
    1968          11 :         curl_easy_setopt(dupch->cp, CURLOPT_ERRORBUFFER,       dupch->err.str);
    1969          11 :         curl_easy_setopt(dupch->cp, CURLOPT_FILE,              (void *) dupch);
    1970          11 :         curl_easy_setopt(dupch->cp, CURLOPT_INFILE,            (void *) dupch);
    1971          11 :         curl_easy_setopt(dupch->cp, CURLOPT_WRITEHEADER,       (void *) dupch);
    1972             : 
    1973          11 :         if (ch->handlers->progress) {
    1974           1 :                 dupch->handlers->progress = ecalloc(1, sizeof(php_curl_progress));
    1975           2 :                 if (!Z_ISUNDEF(ch->handlers->progress->func_name)) {
    1976           1 :                         ZVAL_COPY(&dupch->handlers->progress->func_name, &ch->handlers->progress->func_name);
    1977             :                 }
    1978           1 :                 dupch->handlers->progress->method = ch->handlers->progress->method;
    1979           1 :                 curl_easy_setopt(dupch->cp, CURLOPT_PROGRESSDATA, (void *) dupch);
    1980             :         }
    1981             : 
    1982             : /* Available since 7.21.0 */
    1983             : #if LIBCURL_VERSION_NUM >= 0x071500
    1984             :         if (ch->handlers->fnmatch) {
    1985             :                 dupch->handlers->fnmatch = ecalloc(1, sizeof(php_curl_fnmatch));
    1986             :                 if (!Z_ISUNDEF(ch->handlers->fnmatch->func_name)) {
    1987             :                         ZVAL_COPY(&dupch->handlers->fnmatch->func_name, &ch->handlers->fnmatch->func_name);
    1988             :                 }
    1989             :                 dupch->handlers->fnmatch->method = ch->handlers->fnmatch->method;
    1990             :                 curl_easy_setopt(dupch->cp, CURLOPT_FNMATCH_DATA, (void *) dupch);
    1991             :         }
    1992             : #endif
    1993             : 
    1994          11 :         efree(dupch->to_free->slist);
    1995          11 :         efree(dupch->to_free);
    1996          11 :         dupch->to_free = ch->to_free;
    1997             : 
    1998             :         /* Keep track of cloned copies to avoid invoking curl destructors for every clone */
    1999          11 :         ch->clone++;
    2000             : 
    2001          11 :         ZEND_REGISTER_RESOURCE(return_value, dupch, le_curl);
    2002          11 :         dupch->res = Z_RES_P(return_value);
    2003             : }
    2004             : /* }}} */
    2005             : 
    2006       12293 : static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue TSRMLS_DC) /* {{{ */
    2007             : {
    2008       12293 :         CURLcode error = CURLE_OK;
    2009             : 
    2010       12293 :         switch (option) {
    2011             :                 /* Long options */
    2012             :                 case CURLOPT_SSL_VERIFYHOST:
    2013           5 :                         convert_to_long(zvalue);
    2014           5 :                         if (Z_LVAL_P(zvalue) == 1) {
    2015             : #if LIBCURL_VERSION_NUM <= 0x071c00 /* 7.28.0 */
    2016           2 :                                 php_error_docref(NULL TSRMLS_CC, E_NOTICE, "CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of libcurl 7.28.1. It is recommended to use value 2 instead");
    2017             : #else
    2018             :                                 php_error_docref(NULL TSRMLS_CC, E_NOTICE, "CURLOPT_SSL_VERIFYHOST no longer accepts the value 1, value 2 will be used instead");
    2019             :                                 error = curl_easy_setopt(ch->cp, option, 2);
    2020             :                                 break;
    2021             : #endif
    2022             :                         }
    2023             :                 case CURLOPT_AUTOREFERER:
    2024             :                 case CURLOPT_BUFFERSIZE:
    2025             :                 case CURLOPT_CONNECTTIMEOUT:
    2026             :                 case CURLOPT_COOKIESESSION:
    2027             :                 case CURLOPT_CRLF:
    2028             :                 case CURLOPT_DNS_CACHE_TIMEOUT:
    2029             :                 case CURLOPT_DNS_USE_GLOBAL_CACHE:
    2030             :                 case CURLOPT_FAILONERROR:
    2031             :                 case CURLOPT_FILETIME:
    2032             :                 case CURLOPT_FORBID_REUSE:
    2033             :                 case CURLOPT_FRESH_CONNECT:
    2034             :                 case CURLOPT_FTP_USE_EPRT:
    2035             :                 case CURLOPT_FTP_USE_EPSV:
    2036             :                 case CURLOPT_HEADER:
    2037             :                 case CURLOPT_HTTPGET:
    2038             :                 case CURLOPT_HTTPPROXYTUNNEL:
    2039             :                 case CURLOPT_HTTP_VERSION:
    2040             :                 case CURLOPT_INFILESIZE:
    2041             :                 case CURLOPT_LOW_SPEED_LIMIT:
    2042             :                 case CURLOPT_LOW_SPEED_TIME:
    2043             :                 case CURLOPT_MAXCONNECTS:
    2044             :                 case CURLOPT_MAXREDIRS:
    2045             :                 case CURLOPT_NETRC:
    2046             :                 case CURLOPT_NOBODY:
    2047             :                 case CURLOPT_NOPROGRESS:
    2048             :                 case CURLOPT_NOSIGNAL:
    2049             :                 case CURLOPT_PORT:
    2050             :                 case CURLOPT_POST:
    2051             :                 case CURLOPT_PROXYPORT:
    2052             :                 case CURLOPT_PROXYTYPE:
    2053             :                 case CURLOPT_PUT:
    2054             :                 case CURLOPT_RESUME_FROM:
    2055             :                 case CURLOPT_SSLVERSION:
    2056             :                 case CURLOPT_SSL_VERIFYPEER:
    2057             :                 case CURLOPT_TIMECONDITION:
    2058             :                 case CURLOPT_TIMEOUT:
    2059             :                 case CURLOPT_TIMEVALUE:
    2060             :                 case CURLOPT_TRANSFERTEXT:
    2061             :                 case CURLOPT_UNRESTRICTED_AUTH:
    2062             :                 case CURLOPT_UPLOAD:
    2063             :                 case CURLOPT_VERBOSE:
    2064             : #if LIBCURL_VERSION_NUM >= 0x070a06 /* Available since 7.10.6 */
    2065             :                 case CURLOPT_HTTPAUTH:
    2066             : #endif
    2067             : #if LIBCURL_VERSION_NUM >= 0x070a07 /* Available since 7.10.7 */
    2068             :                 case CURLOPT_FTP_CREATE_MISSING_DIRS:
    2069             :                 case CURLOPT_PROXYAUTH:
    2070             : #endif
    2071             : #if LIBCURL_VERSION_NUM >= 0x070a08 /* Available since 7.10.8 */
    2072             :                 case CURLOPT_FTP_RESPONSE_TIMEOUT:
    2073             :                 case CURLOPT_IPRESOLVE:
    2074             :                 case CURLOPT_MAXFILESIZE:
    2075             : #endif
    2076             : #if LIBCURL_VERSION_NUM >= 0x070b02 /* Available since 7.11.2 */
    2077             :                 case CURLOPT_TCP_NODELAY:
    2078             : #endif
    2079             : #if LIBCURL_VERSION_NUM >= 0x070c02 /* Available since 7.12.2 */
    2080             :                 case CURLOPT_FTPSSLAUTH:
    2081             : #endif
    2082             : #if LIBCURL_VERSION_NUM >= 0x070e01 /* Available since 7.14.1 */
    2083             :                 case CURLOPT_IGNORE_CONTENT_LENGTH:
    2084             : #endif
    2085             : #if LIBCURL_VERSION_NUM >= 0x070f00 /* Available since 7.15.0 */
    2086             :                 case CURLOPT_FTP_SKIP_PASV_IP:
    2087             : #endif
    2088             : #if LIBCURL_VERSION_NUM >= 0x070f01 /* Available since 7.15.1 */
    2089             :                 case CURLOPT_FTP_FILEMETHOD:
    2090             : #endif
    2091             : #if LIBCURL_VERSION_NUM >= 0x070f02 /* Available since 7.15.2 */
    2092             :                 case CURLOPT_CONNECT_ONLY:
    2093             :                 case CURLOPT_LOCALPORT:
    2094             :                 case CURLOPT_LOCALPORTRANGE:
    2095             : #endif
    2096             : #if LIBCURL_VERSION_NUM >= 0x071000 /* Available since 7.16.0 */
    2097             :                 case CURLOPT_SSL_SESSIONID_CACHE:
    2098             : #endif
    2099             : #if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */
    2100             :                 case CURLOPT_FTP_SSL_CCC:
    2101             :                 case CURLOPT_SSH_AUTH_TYPES:
    2102             : #endif
    2103             : #if LIBCURL_VERSION_NUM >= 0x071002 /* Available since 7.16.2 */
    2104             :                 case CURLOPT_CONNECTTIMEOUT_MS:
    2105             :                 case CURLOPT_HTTP_CONTENT_DECODING:
    2106             :                 case CURLOPT_HTTP_TRANSFER_DECODING:
    2107             :                 case CURLOPT_TIMEOUT_MS:
    2108             : #endif
    2109             : #if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */
    2110             :                 case CURLOPT_NEW_DIRECTORY_PERMS:
    2111             :                 case CURLOPT_NEW_FILE_PERMS:
    2112             : #endif
    2113             : #if LIBCURL_VERSION_NUM >= 0x071100 /* Available since 7.17.0 */
    2114             :                 case CURLOPT_USE_SSL:
    2115             : #elif LIBCURL_VERSION_NUM >= 0x070b00 /* Available since 7.11.0 */
    2116             :                 case CURLOPT_FTP_SSL:
    2117             : #endif
    2118             : #if LIBCURL_VERSION_NUM >= 0x071100 /* Available since 7.17.0 */
    2119             :                 case CURLOPT_APPEND:
    2120             :                 case CURLOPT_DIRLISTONLY:
    2121             : #else
    2122             :                 case CURLOPT_FTPAPPEND:
    2123             :                 case CURLOPT_FTPLISTONLY:
    2124             : #endif
    2125             : #if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */
    2126             :                 case CURLOPT_PROXY_TRANSFER_MODE:
    2127             : #endif
    2128             : #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
    2129             :                 case CURLOPT_ADDRESS_SCOPE:
    2130             : #endif
    2131             : #if LIBCURL_VERSION_NUM >  0x071301 /* Available since 7.19.1 */
    2132             :                 case CURLOPT_CERTINFO:
    2133             : #endif
    2134             : #if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */
    2135             :                 case CURLOPT_NOPROXY:
    2136             :                 case CURLOPT_PROTOCOLS:
    2137             :                 case CURLOPT_REDIR_PROTOCOLS:
    2138             :                 case CURLOPT_SOCKS5_GSSAPI_NEC:
    2139             :                 case CURLOPT_TFTP_BLKSIZE:
    2140             : #endif
    2141             : #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
    2142             :                 case CURLOPT_FTP_USE_PRET:
    2143             :                 case CURLOPT_RTSP_CLIENT_CSEQ:
    2144             :                 case CURLOPT_RTSP_REQUEST:
    2145             :                 case CURLOPT_RTSP_SERVER_CSEQ:
    2146             : #endif
    2147             : #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
    2148             :                 case CURLOPT_WILDCARDMATCH:
    2149             : #endif
    2150             : #if LIBCURL_VERSION_NUM >= 0x071504 /* Available since 7.21.4 */
    2151             :                 case CURLOPT_TLSAUTH_TYPE:
    2152             : #endif
    2153             : #if LIBCURL_VERSION_NUM >= 0x071600 /* Available since 7.22.0 */
    2154             :                 case CURLOPT_GSSAPI_DELEGATION:
    2155             : #endif
    2156             : #if LIBCURL_VERSION_NUM >= 0x071800 /* Available since 7.24.0 */
    2157             :                 case CURLOPT_ACCEPTTIMEOUT_MS:
    2158             : #endif
    2159             : #if LIBCURL_VERSION_NUM >= 0x071900 /* Available since 7.25.0 */
    2160             :                 case CURLOPT_SSL_OPTIONS:
    2161             :                 case CURLOPT_TCP_KEEPALIVE:
    2162             :                 case CURLOPT_TCP_KEEPIDLE:
    2163             :                 case CURLOPT_TCP_KEEPINTVL:
    2164             : #endif
    2165             : #if CURLOPT_MUTE != 0
    2166             :                 case CURLOPT_MUTE:
    2167             : #endif
    2168          33 :                         convert_to_long_ex(zvalue);
    2169             : #if LIBCURL_VERSION_NUM >= 0x71304
    2170          39 :                         if ((option == CURLOPT_PROTOCOLS || option == CURLOPT_REDIR_PROTOCOLS) &&
    2171           6 :                                 (PG(open_basedir) && *PG(open_basedir)) && (Z_LVAL_P(zvalue) & CURLPROTO_FILE)) {
    2172           2 :                                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLPROTO_FILE cannot be activated when an open_basedir is set");
    2173           2 :                                         return 1;
    2174             :                         }
    2175             : #endif
    2176          31 :                         error = curl_easy_setopt(ch->cp, option, Z_LVAL_P(zvalue));
    2177          31 :                         break;
    2178             :                 case CURLOPT_SAFE_UPLOAD:
    2179           4 :                         convert_to_long_ex(zvalue);
    2180           4 :                         ch->safe_upload = (Z_LVAL_P(zvalue) != 0);
    2181           4 :                         break;
    2182             : 
    2183             :                 /* String options */
    2184             :                 case CURLOPT_CAINFO:
    2185             :                 case CURLOPT_CAPATH:
    2186             :                 case CURLOPT_COOKIE:
    2187             :                 case CURLOPT_EGDSOCKET:
    2188             :                 case CURLOPT_INTERFACE:
    2189             :                 case CURLOPT_PROXY:
    2190             :                 case CURLOPT_PROXYUSERPWD:
    2191             :                 case CURLOPT_REFERER:
    2192             :                 case CURLOPT_SSLCERTTYPE:
    2193             :                 case CURLOPT_SSLENGINE:
    2194             :                 case CURLOPT_SSLENGINE_DEFAULT:
    2195             :                 case CURLOPT_SSLKEY:
    2196             :                 case CURLOPT_SSLKEYPASSWD:
    2197             :                 case CURLOPT_SSLKEYTYPE:
    2198             :                 case CURLOPT_SSL_CIPHER_LIST:
    2199             :                 case CURLOPT_USERAGENT:
    2200             :                 case CURLOPT_USERPWD:
    2201             : #if LIBCURL_VERSION_NUM >= 0x070e01 /* Available since 7.14.1 */
    2202             :                 case CURLOPT_COOKIELIST:
    2203             : #endif
    2204             : #if LIBCURL_VERSION_NUM >= 0x070f05 /* Available since 7.15.5 */
    2205             :                 case CURLOPT_FTP_ALTERNATIVE_TO_USER:
    2206             : #endif
    2207             : #if LIBCURL_VERSION_NUM >= 0x071101 /* Available since 7.17.1 */
    2208             :                 case CURLOPT_SSH_HOST_PUBLIC_KEY_MD5:
    2209             : #endif
    2210             : #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
    2211             :                 case CURLOPT_PASSWORD:
    2212             :                 case CURLOPT_PROXYPASSWORD:
    2213             :                 case CURLOPT_PROXYUSERNAME:
    2214             :                 case CURLOPT_USERNAME:
    2215             : #endif
    2216             : #if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */
    2217             :                 case CURLOPT_SOCKS5_GSSAPI_SERVICE:
    2218             : #endif
    2219             : #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
    2220             :                 case CURLOPT_MAIL_FROM:
    2221             :                 case CURLOPT_RTSP_STREAM_URI:
    2222             :                 case CURLOPT_RTSP_TRANSPORT:
    2223             : #endif
    2224             : #if LIBCURL_VERSION_NUM >= 0x071504 /* Available since 7.21.4 */
    2225             :                 case CURLOPT_TLSAUTH_PASSWORD:
    2226             :                 case CURLOPT_TLSAUTH_USERNAME:
    2227             : #endif
    2228             : #if LIBCURL_VERSION_NUM >= 0x071506 /* Available since 7.21.6 */
    2229             :                 case CURLOPT_ACCEPT_ENCODING:
    2230             :                 case CURLOPT_TRANSFER_ENCODING:
    2231             : #else
    2232             :                 case CURLOPT_ENCODING:
    2233             : #endif
    2234             : #if LIBCURL_VERSION_NUM >= 0x071800 /* Available since 7.24.0 */
    2235             :                 case CURLOPT_DNS_SERVERS:
    2236             : #endif
    2237             : #if LIBCURL_VERSION_NUM >= 0x071900 /* Available since 7.25.0 */
    2238             :                 case CURLOPT_MAIL_AUTH:
    2239             : #endif
    2240             :                 {
    2241           7 :                         convert_to_string_ex(zvalue);
    2242           7 :                         return php_curl_option_str(ch, option, Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), 0 TSRMLS_CC);
    2243             :                 }
    2244             : 
    2245             :                 /* Curl nullable string options */
    2246             :                 case CURLOPT_CUSTOMREQUEST:
    2247             :                 case CURLOPT_FTPPORT:
    2248             :                 case CURLOPT_RANGE:
    2249             : #if LIBCURL_VERSION_NUM >= 0x070d00 /* Available since 7.13.0 */
    2250             :                 case CURLOPT_FTP_ACCOUNT:
    2251             : #endif
    2252             : #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
    2253             :                 case CURLOPT_RTSP_SESSION_ID:
    2254             : #endif
    2255             : #if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */
    2256             :                 case CURLOPT_KRBLEVEL:
    2257             : #else
    2258             :                 case CURLOPT_KRB4LEVEL:
    2259             : #endif
    2260             :                 {
    2261           2 :                         if (Z_ISNULL_P(zvalue)) {
    2262           1 :                                 error = curl_easy_setopt(ch->cp, option, NULL);
    2263             :                         } else {
    2264           1 :                                 convert_to_string_ex(zvalue);
    2265           1 :                                 return php_curl_option_str(ch, option, Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), 0 TSRMLS_CC);
    2266             :                         }
    2267           1 :                         break;
    2268             :                 }
    2269             : 
    2270             :                 /* Curl private option */
    2271             :                 case CURLOPT_PRIVATE:
    2272           1 :                         convert_to_string_ex(zvalue);
    2273           1 :                         return php_curl_option_str(ch, option, Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), 1 TSRMLS_CC);
    2274             : 
    2275             :                 /* Curl url option */
    2276             :                 case CURLOPT_URL:
    2277        1101 :                         convert_to_string_ex(zvalue);
    2278        1101 :                         return php_curl_option_url(ch, Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue) TSRMLS_CC);
    2279             : 
    2280             :                 /* Curl file handle options */
    2281             :                 case CURLOPT_FILE:
    2282             :                 case CURLOPT_INFILE:
    2283             :                 case CURLOPT_STDERR:
    2284             :                 case CURLOPT_WRITEHEADER: {
    2285        1051 :                         FILE *fp = NULL;
    2286             :                         int type;
    2287        1051 :                         php_stream *what = NULL;
    2288             : 
    2289        1051 :                         if (Z_TYPE_P(zvalue) != IS_NULL) {
    2290        1050 :                                 what = zend_fetch_resource(zvalue TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream(), php_file_le_pstream());
    2291        1050 :                                 if (!what) {
    2292           0 :                                         return FAILURE;
    2293             :                                 }
    2294             : 
    2295        1050 :                                 if (FAILURE == php_stream_cast(what, PHP_STREAM_AS_STDIO, (void *) &fp, REPORT_ERRORS)) {
    2296           0 :                                         return FAILURE;
    2297             :                                 }
    2298             : 
    2299        1050 :                                 if (!fp) {
    2300           0 :                                         return FAILURE;
    2301             :                                 }
    2302             :                         }
    2303             : 
    2304        1051 :                         error = CURLE_OK;
    2305        1051 :                         switch (option) {
    2306             :                                 case CURLOPT_FILE:
    2307        1033 :                                         if (!what) {
    2308           0 :                                                 if (!Z_ISUNDEF(ch->handlers->write->stream)) {
    2309           0 :                                                         zval_ptr_dtor(&ch->handlers->write->stream);
    2310           0 :                                                         ZVAL_UNDEF(&ch->handlers->write->stream);
    2311             :                                                 }
    2312           0 :                                                 ch->handlers->write->fp = NULL;
    2313           0 :                                                 ch->handlers->write->method = PHP_CURL_STDOUT;
    2314        2065 :                                         } else if (what->mode[0] != 'r' || what->mode[1] == '+') {
    2315        1032 :                                                 zval_ptr_dtor(&ch->handlers->write->stream);
    2316        1032 :                                                 ch->handlers->write->fp = fp;
    2317        1032 :                                                 ch->handlers->write->method = PHP_CURL_FILE;
    2318        1032 :                                                 ZVAL_COPY(&ch->handlers->write->stream, zvalue);
    2319             :                                         } else {
    2320           1 :                                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
    2321           1 :                                                 return FAILURE;
    2322             :                                         }
    2323        1032 :                                         break;
    2324             :                                 case CURLOPT_WRITEHEADER:
    2325           3 :                                         if (!what) {
    2326           0 :                                                 if (!Z_ISUNDEF(ch->handlers->write_header->stream)) {
    2327           0 :                                                         zval_ptr_dtor(&ch->handlers->write_header->stream);
    2328           0 :                                                         ZVAL_UNDEF(&ch->handlers->write_header->stream);
    2329             :                                                 }
    2330           0 :                                                 ch->handlers->write_header->fp = NULL;
    2331           0 :                                                 ch->handlers->write_header->method = PHP_CURL_IGNORE;
    2332           6 :                                         } else if (what->mode[0] != 'r' || what->mode[1] == '+') {
    2333           3 :                                                 zval_ptr_dtor(&ch->handlers->write_header->stream);
    2334           3 :                                                 ch->handlers->write_header->fp = fp;
    2335           3 :                                                 ch->handlers->write_header->method = PHP_CURL_FILE;
    2336           3 :                                                 ZVAL_COPY(&ch->handlers->write_header->stream, zvalue);;
    2337             :                                         } else {
    2338           0 :                                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
    2339           0 :                                                 return FAILURE;
    2340             :                                         }
    2341           3 :                                         break;
    2342             :                                 case CURLOPT_INFILE:
    2343           7 :                                         if (!what) {
    2344           2 :                                                 if (!Z_ISUNDEF(ch->handlers->read->stream)) {
    2345           1 :                                                         zval_ptr_dtor(&ch->handlers->read->stream);
    2346           1 :                                                         ZVAL_UNDEF(&ch->handlers->read->stream);
    2347             :                                                 }
    2348           1 :                                                 ch->handlers->read->fp = NULL;
    2349           1 :                                                 ch->handlers->read->res = NULL;
    2350             :                                         } else {
    2351           6 :                                                 zval_ptr_dtor(&ch->handlers->read->stream);
    2352           6 :                                                 ch->handlers->read->fp = fp;
    2353           6 :                                                 ch->handlers->read->res = Z_RES_P(zvalue);
    2354           6 :                                                 ZVAL_COPY(&ch->handlers->read->stream, zvalue);
    2355             :                                         }
    2356           7 :                                         break;
    2357             :                                 case CURLOPT_STDERR:
    2358           8 :                                         if (!what) {
    2359           0 :                                                 if (!Z_ISUNDEF(ch->handlers->std_err)) {
    2360           0 :                                                         zval_ptr_dtor(&ch->handlers->std_err);
    2361           0 :                                                         ZVAL_UNDEF(&ch->handlers->std_err);
    2362             :                                                 }
    2363          16 :                                         } else if (what->mode[0] != 'r' || what->mode[1] == '+') {
    2364           8 :                                                 zval_ptr_dtor(&ch->handlers->std_err);
    2365           8 :                                                 ZVAL_COPY(&ch->handlers->std_err, zvalue);
    2366             :                                         } else {
    2367           0 :                                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
    2368           0 :                                                 return FAILURE;
    2369             :                                         }
    2370             :                                         /* break omitted intentionally */
    2371             :                                 default:
    2372           8 :                                         error = curl_easy_setopt(ch->cp, option, fp);
    2373             :                                         break;
    2374             :                         }
    2375        1050 :                         break;
    2376             :                 }
    2377             : 
    2378             :                 /* Curl linked list options */
    2379             :                 case CURLOPT_HTTP200ALIASES:
    2380             :                 case CURLOPT_HTTPHEADER:
    2381             :                 case CURLOPT_POSTQUOTE:
    2382             :                 case CURLOPT_PREQUOTE:
    2383             :                 case CURLOPT_QUOTE:
    2384             :                 case CURLOPT_TELNETOPTIONS:
    2385             : #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
    2386             :                 case CURLOPT_MAIL_RCPT:
    2387             : #endif
    2388             : #if LIBCURL_VERSION_NUM >= 0x071503 /* Available since 7.21.3 */
    2389             :                 case CURLOPT_RESOLVE:
    2390             : #endif
    2391             :                 {
    2392             :                         zval *current;
    2393             :                         HashTable *ph;
    2394       10004 :                         struct curl_slist *slist = NULL;
    2395             : 
    2396       10005 :                         ph = HASH_OF(zvalue);
    2397       10004 :                         if (!ph) {
    2398           1 :                                 char *name = NULL;
    2399           1 :                                 switch (option) {
    2400             :                                         case CURLOPT_HTTPHEADER:
    2401           1 :                                                 name = "CURLOPT_HTTPHEADER";
    2402           1 :                                                 break;
    2403             :                                         case CURLOPT_QUOTE:
    2404           0 :                                                 name = "CURLOPT_QUOTE";
    2405           0 :                                                 break;
    2406             :                                         case CURLOPT_HTTP200ALIASES:
    2407           0 :                                                 name = "CURLOPT_HTTP200ALIASES";
    2408           0 :                                                 break;
    2409             :                                         case CURLOPT_POSTQUOTE:
    2410           0 :                                                 name = "CURLOPT_POSTQUOTE";
    2411           0 :                                                 break;
    2412             :                                         case CURLOPT_PREQUOTE:
    2413           0 :                                                 name = "CURLOPT_PREQUOTE";
    2414           0 :                                                 break;
    2415             :                                         case CURLOPT_TELNETOPTIONS:
    2416           0 :                                                 name = "CURLOPT_TELNETOPTIONS";
    2417             :                                                 break;
    2418             : #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
    2419             :                                         case CURLOPT_MAIL_RCPT:
    2420             :                                                 name = "CURLOPT_MAIL_RCPT";
    2421             :                                                 break;
    2422             : #endif
    2423             : #if LIBCURL_VERSION_NUM >= 0x071503 /* Available since 7.21.3 */
    2424             :                                         case CURLOPT_RESOLVE:
    2425             :                                                 name = "CURLOPT_RESOLVE";
    2426             :                                                 break;
    2427             : #endif
    2428             :                                 }
    2429           1 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must pass either an object or an array with the %s argument", name);
    2430           1 :                                 return FAILURE;
    2431             :                         }
    2432             : 
    2433       30009 :                         ZEND_HASH_FOREACH_VAL(ph, current) {
    2434       30006 :                                 SEPARATE_ZVAL(current);
    2435       10003 :                                 convert_to_string_ex(current);
    2436             : 
    2437       10003 :                                 slist = curl_slist_append(slist, Z_STRVAL_P(current));
    2438       10003 :                                 if (!slist) {
    2439           0 :                                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not build curl_slist");
    2440           0 :                                         return 1;
    2441             :                                 }
    2442             :                         } ZEND_HASH_FOREACH_END();
    2443             : 
    2444       10003 :                         zend_hash_index_update_ptr(ch->to_free->slist, option, slist);
    2445             : 
    2446       10003 :                         error = curl_easy_setopt(ch->cp, option, slist);
    2447             : 
    2448       10003 :                         break;
    2449             :                 }
    2450             : 
    2451             :                 case CURLOPT_BINARYTRANSFER:
    2452             :                         /* Do nothing, just backward compatibility */
    2453           1 :                         break;
    2454             : 
    2455             :                 case CURLOPT_FOLLOWLOCATION:
    2456           2 :                         convert_to_long_ex(zvalue);
    2457             : #if LIBCURL_VERSION_NUM < 0x071304
    2458             :                         if (PG(open_basedir) && *PG(open_basedir)) {
    2459             :                                 if (Z_LVAL_P(zvalue) != 0) {
    2460             :                                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set");
    2461             :                                         return FAILURE;
    2462             :                                 }
    2463             :                         }
    2464             : #endif
    2465           2 :                         error = curl_easy_setopt(ch->cp, option, Z_LVAL_P(zvalue));
    2466           2 :                         break;
    2467             : 
    2468             :                 case CURLOPT_HEADERFUNCTION:
    2469           2 :                         if (!Z_ISUNDEF(ch->handlers->write_header->func_name)) {
    2470           0 :                                 zval_ptr_dtor(&ch->handlers->write_header->func_name);
    2471           0 :                                 ch->handlers->write_header->fci_cache = empty_fcall_info_cache;
    2472             :                         }
    2473           1 :                         ZVAL_COPY(&ch->handlers->write_header->func_name, zvalue);
    2474           1 :                         ch->handlers->write_header->method = PHP_CURL_USER;
    2475           1 :                         break;
    2476             : 
    2477             :                 case CURLOPT_POSTFIELDS:
    2478          46 :                         if (Z_TYPE_P(zvalue) == IS_ARRAY || Z_TYPE_P(zvalue) == IS_OBJECT) {
    2479             :                                 zval *current;
    2480             :                                 HashTable *postfields;
    2481             :                                 zend_string *string_key;
    2482             :                                 zend_ulong  num_key;
    2483          20 :                                 struct HttpPost *first = NULL;
    2484          20 :                                 struct HttpPost *last  = NULL;
    2485             : 
    2486          20 :                                 postfields = HASH_OF(zvalue);
    2487          20 :                                 if (!postfields) {
    2488           0 :                                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't get HashTable in CURLOPT_POSTFIELDS");
    2489           0 :                                         return FAILURE;
    2490             :                                 }
    2491             : 
    2492          68 :                                 ZEND_HASH_FOREACH_KEY_VAL(postfields, num_key, string_key, current) {
    2493             :                                         char *postval;
    2494             :                                         /* Pretend we have a string_key here */
    2495          24 :                                         if (!string_key) {
    2496           1 :                                                 string_key = zend_long_to_str(num_key);
    2497             :                                         } else {
    2498             :                                                 zend_string_addref(string_key);
    2499             :                                         }
    2500             : 
    2501          34 :                                         if (Z_TYPE_P(current) == IS_OBJECT &&
    2502          10 :                                                         instanceof_function(Z_OBJCE_P(current), curl_CURLFile_class TSRMLS_CC)) {
    2503             :                                                 /* new-style file upload */
    2504             :                                                 zval *prop;
    2505          10 :                                                 char *type = NULL, *filename = NULL;
    2506             : 
    2507          10 :                                                 prop = zend_read_property(curl_CURLFile_class, current, "name", sizeof("name")-1, 0 TSRMLS_CC);
    2508          10 :                                                 if (Z_TYPE_P(prop) != IS_STRING) {
    2509           0 :                                                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid filename for key %s", string_key->val);
    2510             :                                                 } else {
    2511          10 :                                                         postval = Z_STRVAL_P(prop);
    2512             : 
    2513          10 :                                                         if (php_check_open_basedir(postval TSRMLS_CC)) {
    2514           0 :                                                                 return 1;
    2515             :                                                         }
    2516             : 
    2517          10 :                                                         prop = zend_read_property(curl_CURLFile_class, current, "mime", sizeof("mime")-1, 0 TSRMLS_CC);
    2518          10 :                                                         if (Z_TYPE_P(prop) == IS_STRING && Z_STRLEN_P(prop) > 0) {
    2519           5 :                                                                 type = Z_STRVAL_P(prop);
    2520             :                                                         }
    2521          10 :                                                         prop = zend_read_property(curl_CURLFile_class, current, "postname", sizeof("postname")-1, 0 TSRMLS_CC);
    2522          10 :                                                         if (Z_TYPE_P(prop) == IS_STRING && Z_STRLEN_P(prop) > 0) {
    2523           5 :                                                                 filename = Z_STRVAL_P(prop);
    2524             :                                                         }
    2525          10 :                                                         error = curl_formadd(&first, &last,
    2526             :                                                                                         CURLFORM_COPYNAME, string_key->val,
    2527             :                                                                                         CURLFORM_NAMELENGTH, string_key->len,
    2528             :                                                                                         CURLFORM_FILENAME, filename ? filename : postval,
    2529             :                                                                                         CURLFORM_CONTENTTYPE, type ? type : "application/octet-stream",
    2530             :                                                                                         CURLFORM_FILE, postval,
    2531             :                                                                                         CURLFORM_END);
    2532             :                                                 }
    2533             : 
    2534             :                                                 zend_string_release(string_key);
    2535          10 :                                                 continue;
    2536             :                                         }
    2537             : 
    2538          42 :                                         SEPARATE_ZVAL(current);
    2539          14 :                                         convert_to_string_ex(current);
    2540             : 
    2541          14 :                                         postval = Z_STRVAL_P(current);
    2542             : 
    2543             :                                         /* The arguments after _NAMELENGTH and _CONTENTSLENGTH
    2544             :                                          * must be explicitly cast to long in curl_formadd
    2545             :                                          * use since curl needs a long not an int. */
    2546          20 :                                         if (!ch->safe_upload && *postval == '@') {
    2547             :                                                 char *name, *type, *filename;
    2548           6 :                                                 ++postval;
    2549             : 
    2550           6 :                                                 php_error_docref("curl.curlfile" TSRMLS_CC, E_DEPRECATED,
    2551             :                                                                 "The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead");
    2552             : 
    2553           6 :                                                 name = estrndup(postval, Z_STRLEN_P(current));
    2554          12 :                                                 if ((type = (char *)php_memnstr(name, ";type=", sizeof(";type=") - 1,
    2555           6 :                                                                                 name + Z_STRLEN_P(current)))) {
    2556           3 :                                                         *type = '\0';
    2557             :                                                 }
    2558          12 :                                                 if ((filename = (char *)php_memnstr(name, ";filename=", sizeof(";filename=") - 1,
    2559           6 :                                                                                 name + Z_STRLEN_P(current)))) {
    2560           3 :                                                         *filename = '\0';
    2561             :                                                 }
    2562             :                                                 /* open_basedir check */
    2563           6 :                                                 if (php_check_open_basedir(name TSRMLS_CC)) {
    2564           0 :                                                         efree(name);
    2565           0 :                                                         return FAILURE;
    2566             :                                                 }
    2567           6 :                                                 error = curl_formadd(&first, &last,
    2568             :                                                                                 CURLFORM_COPYNAME, string_key->val,
    2569             :                                                                                 CURLFORM_NAMELENGTH, string_key->len,
    2570             :                                                                                 CURLFORM_FILENAME, filename ? filename + sizeof(";filename=") - 1 : name,
    2571             :                                                                                 CURLFORM_CONTENTTYPE, type ? type + sizeof(";type=") - 1 : "application/octet-stream",
    2572             :                                                                                 CURLFORM_FILE, name,
    2573             :                                                                                 CURLFORM_END);
    2574           6 :                                                 efree(name);
    2575             :                                         } else {
    2576           8 :                                                 error = curl_formadd(&first, &last,
    2577             :                                                                                          CURLFORM_COPYNAME, string_key->val,
    2578             :                                                                                          CURLFORM_NAMELENGTH, (zend_long)string_key->len,
    2579             :                                                                                          CURLFORM_COPYCONTENTS, postval,
    2580           8 :                                                                                          CURLFORM_CONTENTSLENGTH, (zend_long)Z_STRLEN_P(current),
    2581             :                                                                                          CURLFORM_END);
    2582             :                                         }
    2583             : 
    2584             :                                         zend_string_release(string_key);
    2585             :                                 } ZEND_HASH_FOREACH_END();
    2586             : 
    2587          20 :                                 SAVE_CURL_ERROR(ch, error);
    2588          20 :                                 if (error != CURLE_OK) {
    2589           0 :                                         return FAILURE;
    2590             :                                 }
    2591             : 
    2592          20 :                                 if (ch->clone == 0) {
    2593           0 :                                         zend_llist_clean(&ch->to_free->post);
    2594             :                                 } 
    2595          20 :                                 zend_llist_add_element(&ch->to_free->post, &first);
    2596          20 :                                 error = curl_easy_setopt(ch->cp, CURLOPT_HTTPPOST, first);
    2597             :                         } else {
    2598             : #if LIBCURL_VERSION_NUM >= 0x071101
    2599           3 :                                 convert_to_string_ex(zvalue);
    2600             :                                 /* with curl 7.17.0 and later, we can use COPYPOSTFIELDS, but we have to provide size before */
    2601           3 :                                 error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, Z_STRLEN_P(zvalue));
    2602           3 :                                 error = curl_easy_setopt(ch->cp, CURLOPT_COPYPOSTFIELDS, Z_STRVAL_P(zvalue));
    2603             : #else
    2604             :                                 char *post = NULL;
    2605             : 
    2606             :                                 convert_to_string_ex(zvalue);
    2607             :                                 post = estrndup(Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue));
    2608             :                                 zend_llist_add_element(&ch->to_free->str, &post);
    2609             : 
    2610             :                                 curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, post);
    2611             :                                 error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, Z_STRLEN_P(zvalue));
    2612             : #endif
    2613             :                         }
    2614          23 :                         break;
    2615             : 
    2616             :                 case CURLOPT_PROGRESSFUNCTION:
    2617           1 :                         curl_easy_setopt(ch->cp, CURLOPT_PROGRESSFUNCTION,   curl_progress);
    2618           1 :                         curl_easy_setopt(ch->cp, CURLOPT_PROGRESSDATA, ch);
    2619           1 :                         if (ch->handlers->progress == NULL) {
    2620           1 :                                 ch->handlers->progress = ecalloc(1, sizeof(php_curl_progress));
    2621           0 :                         } else if (!Z_ISUNDEF(ch->handlers->progress->func_name)) {
    2622           0 :                                 zval_ptr_dtor(&ch->handlers->progress->func_name);
    2623           0 :                                 ch->handlers->progress->fci_cache = empty_fcall_info_cache;
    2624             :                         }
    2625           1 :                         ZVAL_COPY(&ch->handlers->progress->func_name, zvalue);
    2626           1 :                         ch->handlers->progress->method = PHP_CURL_USER;
    2627           1 :                         break;
    2628             : 
    2629             :                 case CURLOPT_READFUNCTION:
    2630           2 :                         if (!Z_ISUNDEF(ch->handlers->read->func_name)) {
    2631           0 :                                 zval_ptr_dtor(&ch->handlers->read->func_name);
    2632           0 :                                 ch->handlers->read->fci_cache = empty_fcall_info_cache;
    2633             :                         }
    2634           1 :                         ZVAL_COPY(&ch->handlers->read->func_name, zvalue);
    2635           1 :                         ch->handlers->read->method = PHP_CURL_USER;
    2636           1 :                         break;
    2637             : 
    2638             :                 case CURLOPT_RETURNTRANSFER:
    2639          54 :                         convert_to_long_ex(zvalue);
    2640          54 :                         if (Z_LVAL_P(zvalue)) {
    2641          53 :                                 ch->handlers->write->method = PHP_CURL_RETURN;
    2642             :                         } else {
    2643           1 :                                 ch->handlers->write->method = PHP_CURL_STDOUT;
    2644             :                         }
    2645          54 :                         break;
    2646             : 
    2647             :                 case CURLOPT_WRITEFUNCTION:
    2648           4 :                         if (!Z_ISUNDEF(ch->handlers->write->func_name)) {
    2649           0 :                                 zval_ptr_dtor(&ch->handlers->write->func_name);
    2650           0 :                                 ch->handlers->write->fci_cache = empty_fcall_info_cache;
    2651             :                         }
    2652           2 :                         ZVAL_COPY(&ch->handlers->write->func_name, zvalue);
    2653           2 :                         ch->handlers->write->method = PHP_CURL_USER;
    2654           2 :                         break;
    2655             : 
    2656             : #if LIBCURL_VERSION_NUM >= 0x070f05 /* Available since 7.15.5 */
    2657             :                 case CURLOPT_MAX_RECV_SPEED_LARGE:
    2658             :                 case CURLOPT_MAX_SEND_SPEED_LARGE:
    2659           0 :                         convert_to_long_ex(zvalue);
    2660           0 :                         error = curl_easy_setopt(ch->cp, option, (curl_off_t)Z_LVAL_P(zvalue));
    2661           0 :                         break;
    2662             : #endif
    2663             : 
    2664             : #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
    2665             :                 case CURLOPT_POSTREDIR:
    2666           0 :                         convert_to_long_ex(zvalue);
    2667           0 :                         error = curl_easy_setopt(ch->cp, CURLOPT_POSTREDIR, Z_LVAL_P(zvalue) & CURL_REDIR_POST_ALL);
    2668           0 :                         break;
    2669             : #endif
    2670             : 
    2671             : #if CURLOPT_PASSWDFUNCTION != 0
    2672             :                 case CURLOPT_PASSWDFUNCTION:
    2673             :                         zval_ptr_dtor(&ch->handlers->passwd);
    2674             :                         ZVAL_COPY(&ch->handlers->passwd, zvalue);
    2675             :                         error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDFUNCTION, curl_passwd);
    2676             :                         error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDDATA,     (void *) ch);
    2677             :                         break;
    2678             : #endif
    2679             : 
    2680             :                 /* the following options deal with files, therefore the open_basedir check
    2681             :                  * is required.
    2682             :                  */
    2683             :                 case CURLOPT_COOKIEFILE:
    2684             :                 case CURLOPT_COOKIEJAR:
    2685             :                 case CURLOPT_RANDOM_FILE:
    2686             :                 case CURLOPT_SSLCERT:
    2687             : #if LIBCURL_VERSION_NUM >= 0x070b00 /* Available since 7.11.0 */
    2688             :                 case CURLOPT_NETRC_FILE:
    2689             : #endif
    2690             : #if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */
    2691             :                 case CURLOPT_SSH_PRIVATE_KEYFILE:
    2692             :                 case CURLOPT_SSH_PUBLIC_KEYFILE:
    2693             : #endif
    2694             : #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
    2695             :                 case CURLOPT_CRLFILE:
    2696             :                 case CURLOPT_ISSUERCERT:
    2697             : #endif
    2698             : #if LIBCURL_VERSION_NUM >= 0x071306 /* Available since 7.19.6 */
    2699             :                 case CURLOPT_SSH_KNOWNHOSTS:
    2700             : #endif
    2701             :                 {
    2702           3 :                         convert_to_string_ex(zvalue);
    2703             : 
    2704           3 :                         if (Z_STRLEN_P(zvalue) && php_check_open_basedir(Z_STRVAL_P(zvalue) TSRMLS_CC)) {
    2705           1 :                                 return FAILURE;
    2706             :                         }
    2707             : 
    2708           2 :                         return php_curl_option_str(ch, option, Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), 0 TSRMLS_CC);
    2709             :                 }
    2710             : 
    2711             :                 case CURLINFO_HEADER_OUT:
    2712           0 :                         convert_to_long_ex(zvalue);
    2713           0 :                         if (Z_LVAL_P(zvalue) == 1) {
    2714           0 :                                 curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, curl_debug);
    2715           0 :                                 curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, (void *)ch);
    2716           0 :                                 curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 1);
    2717             :                         } else {
    2718           0 :                                 curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, NULL);
    2719           0 :                                 curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, NULL);
    2720           0 :                                 curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0);
    2721             :                         }
    2722           0 :                         break;
    2723             : 
    2724             :                 case CURLOPT_SHARE:
    2725             :                         {
    2726           0 :                                 php_curlsh *sh = NULL;
    2727           0 :                                 ZEND_FETCH_RESOURCE_NO_RETURN(sh, php_curlsh *, zvalue, -1, le_curl_share_handle_name, le_curl_share_handle);
    2728           0 :                                 if (sh) {
    2729           0 :                                         curl_easy_setopt(ch->cp, CURLOPT_SHARE, sh->share);
    2730             :                                 }
    2731             :                         }
    2732             : 
    2733             : #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
    2734             :                 case CURLOPT_FNMATCH_FUNCTION:
    2735             :                         curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_FUNCTION, curl_fnmatch);
    2736             :                         curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_DATA, ch);
    2737             :                         if (ch->handlers->fnmatch == NULL) {
    2738             :                                 ch->handlers->fnmatch = ecalloc(1, sizeof(php_curl_fnmatch));
    2739             :                         } else if (!Z_ISUNDEF(ch->handlers->fnmatch->func_name)) {
    2740             :                                 zval_ptr_dtor(&ch->handlers->fnmatch->func_name);
    2741             :                                 ch->handlers->fnmatch->fci_cache = empty_fcall_info_cache;
    2742             :                         }
    2743             :                         ZVAL_COPY(&ch->handlers->fnmatch->func_name, zvalue);
    2744             :                         ch->handlers->fnmatch->method = PHP_CURL_USER;
    2745             :                         break;
    2746             : #endif
    2747             : 
    2748             :         }
    2749             : 
    2750       11176 :         SAVE_CURL_ERROR(ch, error);
    2751       11176 :         if (error != CURLE_OK) {
    2752           0 :                 return FAILURE;
    2753             :         } else {
    2754       11176 :                 return SUCCESS;
    2755             :         }
    2756             : }
    2757             : /* }}} */
    2758             : 
    2759             : /* {{{ proto bool curl_setopt(resource ch, int option, mixed value)
    2760             :    Set an option for a cURL transfer */
    2761       12261 : PHP_FUNCTION(curl_setopt)
    2762             : {
    2763             :         zval       *zid, *zvalue;
    2764             :         zend_long        options;
    2765             :         php_curl   *ch;
    2766             : 
    2767       12261 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz", &zid, &options, &zvalue) == FAILURE) {
    2768          10 :                 return;
    2769             :         }
    2770             : 
    2771       12251 :         ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
    2772             : 
    2773       12251 :         if (options <= 0 && options != CURLOPT_SAFE_UPLOAD) {
    2774           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid curl configuration option");
    2775           1 :                 RETURN_FALSE;
    2776             :         }
    2777             : 
    2778       12250 :         if (_php_curl_setopt(ch, options, zvalue TSRMLS_CC) == SUCCESS) {
    2779       12244 :                 RETURN_TRUE;
    2780             :         } else {
    2781           6 :                 RETURN_FALSE;
    2782             :         }
    2783             : }
    2784             : /* }}} */
    2785             : 
    2786             : /* {{{ proto bool curl_setopt_array(resource ch, array options)
    2787             :    Set an array of option for a cURL transfer */
    2788          14 : PHP_FUNCTION(curl_setopt_array)
    2789             : {
    2790             :         zval            *zid, *arr, *entry;
    2791             :         php_curl        *ch;
    2792             :         zend_ulong      option;
    2793             :         zend_string     *string_key;
    2794             : 
    2795          14 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "za", &zid, &arr) == FAILURE) {
    2796           0 :                 return;
    2797             :         }
    2798             : 
    2799          14 :         ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
    2800             : 
    2801         100 :         ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arr), option, string_key, entry) {
    2802          43 :                 if (string_key) {
    2803           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING,
    2804             :                                         "Array keys must be CURLOPT constants or equivalent integer values");
    2805           0 :                         RETURN_FALSE;
    2806             :                 }
    2807          43 :                 if (_php_curl_setopt(ch, (zend_long) option, entry TSRMLS_CC) == FAILURE) {
    2808           0 :                         RETURN_FALSE;
    2809             :                 }
    2810             :         } ZEND_HASH_FOREACH_END();
    2811             : 
    2812          14 :         RETURN_TRUE;
    2813             : }
    2814             : /* }}} */
    2815             : 
    2816             : /* {{{ _php_curl_cleanup_handle(ch)
    2817             :    Cleanup an execution phase */
    2818        1123 : void _php_curl_cleanup_handle(php_curl *ch)
    2819             : {
    2820        1123 :         smart_str_free(&ch->handlers->write->buf);
    2821        1123 :         if (ch->header.str) {
    2822           0 :                 zend_string_release(ch->header.str);
    2823           0 :                 ch->header.str = NULL;
    2824             :         }
    2825             : 
    2826        1123 :         memset(ch->err.str, 0, CURL_ERROR_SIZE + 1);
    2827        1123 :         ch->err.no = 0;
    2828        1123 : }
    2829             : /* }}} */
    2830             : 
    2831             : /* {{{ proto bool curl_exec(resource ch)
    2832             :    Perform a cURL session */
    2833        1100 : PHP_FUNCTION(curl_exec)
    2834             : {
    2835             :         CURLcode        error;
    2836             :         zval            *zid;
    2837             :         php_curl        *ch;
    2838             : 
    2839        1100 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
    2840           0 :                 return;
    2841             :         }
    2842             : 
    2843        1100 :         ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
    2844             : 
    2845        1100 :         _php_curl_verify_handlers(ch, 1 TSRMLS_CC);
    2846             : 
    2847        1100 :         _php_curl_cleanup_handle(ch);
    2848             : 
    2849        1100 :         error = curl_easy_perform(ch->cp);
    2850        1100 :         SAVE_CURL_ERROR(ch, error);
    2851             :         /* CURLE_PARTIAL_FILE is returned by HEAD requests */
    2852        1100 :         if (error != CURLE_OK && error != CURLE_PARTIAL_FILE) {
    2853        1034 :                 smart_str_free(&ch->handlers->write->buf);
    2854        1034 :                 RETURN_FALSE;
    2855             :         }
    2856             : 
    2857         132 :         if (!Z_ISUNDEF(ch->handlers->std_err)) {
    2858             :                 php_stream  *stream;
    2859           2 :                 stream = zend_fetch_resource(&ch->handlers->std_err TSRMLS_CC, -1, NULL, NULL, 2, php_file_le_stream(), php_file_le_pstream());
    2860           2 :                 if (stream) {
    2861           2 :                         php_stream_flush(stream);
    2862             :                 }
    2863             :         }
    2864             : 
    2865          66 :         if (ch->handlers->write->method == PHP_CURL_RETURN && ch->handlers->write->buf.s) {
    2866          49 :                 smart_str_0(&ch->handlers->write->buf);
    2867          98 :                 RETURN_STR(zend_string_copy(ch->handlers->write->buf.s));
    2868             :         }
    2869             : 
    2870             :         /* flush the file handle, so any remaining data is synched to disk */
    2871          17 :         if (ch->handlers->write->method == PHP_CURL_FILE && ch->handlers->write->fp) {
    2872           3 :                 fflush(ch->handlers->write->fp);
    2873             :         }
    2874          17 :         if (ch->handlers->write_header->method == PHP_CURL_FILE && ch->handlers->write_header->fp) {
    2875           0 :                 fflush(ch->handlers->write_header->fp);
    2876             :         }
    2877             : 
    2878          17 :         if (ch->handlers->write->method == PHP_CURL_RETURN) {
    2879           1 :                 RETURN_EMPTY_STRING();
    2880             :         } else {
    2881          16 :                 RETURN_TRUE;
    2882             :         }
    2883             : }
    2884             : /* }}} */
    2885             : 
    2886             : /* {{{ proto mixed curl_getinfo(resource ch [, int option])
    2887             :    Get information regarding a specific transfer */
    2888          22 : PHP_FUNCTION(curl_getinfo)
    2889             : {
    2890             :         zval            *zid;
    2891             :         php_curl        *ch;
    2892          22 :         zend_long               option = 0;
    2893             : 
    2894          22 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zid, &option) == FAILURE) {
    2895           0 :                 return;
    2896             :         }
    2897             : 
    2898          22 :         ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
    2899             : 
    2900          22 :         if (ZEND_NUM_ARGS() < 2) {
    2901             :                 char *s_code;
    2902             :                 zend_long l_code;
    2903             :                 double d_code;
    2904             : #if LIBCURL_VERSION_NUM >  0x071301
    2905          13 :                 struct curl_certinfo *ci = NULL;
    2906             :                 zval listcode;
    2907             : #endif
    2908             : 
    2909          13 :                 array_init(return_value);
    2910             : 
    2911          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_EFFECTIVE_URL, &s_code) == CURLE_OK) {
    2912          13 :                         CAAS("url", s_code);
    2913             :                 }
    2914          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_TYPE, &s_code) == CURLE_OK) {
    2915          13 :                         if (s_code != NULL) {
    2916           0 :                                 CAAS("content_type", s_code);
    2917             :                         } else {
    2918             :                                 zval retnull;
    2919          13 :                                 ZVAL_NULL(&retnull);
    2920          13 :                                 CAAZ("content_type", &retnull);
    2921             :                         }
    2922             :                 }
    2923          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_HTTP_CODE, &l_code) == CURLE_OK) {
    2924          13 :                         CAAL("http_code", l_code);
    2925             :                 }
    2926          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_HEADER_SIZE, &l_code) == CURLE_OK) {
    2927          13 :                         CAAL("header_size", l_code);
    2928             :                 }
    2929          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_REQUEST_SIZE, &l_code) == CURLE_OK) {
    2930          13 :                         CAAL("request_size", l_code);
    2931             :                 }
    2932          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_FILETIME, &l_code) == CURLE_OK) {
    2933          13 :                         CAAL("filetime", l_code);
    2934             :                 }
    2935          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SSL_VERIFYRESULT, &l_code) == CURLE_OK) {
    2936          13 :                         CAAL("ssl_verify_result", l_code);
    2937             :                 }
    2938          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_COUNT, &l_code) == CURLE_OK) {
    2939          13 :                         CAAL("redirect_count", l_code);
    2940             :                 }
    2941          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME, &d_code) == CURLE_OK) {
    2942          13 :                         CAAD("total_time", d_code);
    2943             :                 }
    2944          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_NAMELOOKUP_TIME, &d_code) == CURLE_OK) {
    2945          13 :                         CAAD("namelookup_time", d_code);
    2946             :                 }
    2947          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CONNECT_TIME, &d_code) == CURLE_OK) {
    2948          13 :                         CAAD("connect_time", d_code);
    2949             :                 }
    2950          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_PRETRANSFER_TIME, &d_code) == CURLE_OK) {
    2951          13 :                         CAAD("pretransfer_time", d_code);
    2952             :                 }
    2953          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_UPLOAD, &d_code) == CURLE_OK) {
    2954          13 :                         CAAD("size_upload", d_code);
    2955             :                 }
    2956          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_DOWNLOAD, &d_code) == CURLE_OK) {
    2957          13 :                         CAAD("size_download", d_code);
    2958             :                 }
    2959          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_DOWNLOAD, &d_code) == CURLE_OK) {
    2960          13 :                         CAAD("speed_download", d_code);
    2961             :                 }
    2962          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_UPLOAD, &d_code) == CURLE_OK) {
    2963          13 :                         CAAD("speed_upload", d_code);
    2964             :                 }
    2965          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d_code) == CURLE_OK) {
    2966          13 :                         CAAD("download_content_length", d_code);
    2967             :                 }
    2968          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_UPLOAD, &d_code) == CURLE_OK) {
    2969          13 :                         CAAD("upload_content_length", d_code);
    2970             :                 }
    2971          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_STARTTRANSFER_TIME, &d_code) == CURLE_OK) {
    2972          13 :                         CAAD("starttransfer_time", d_code);
    2973             :                 }
    2974          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME, &d_code) == CURLE_OK) {
    2975          13 :                         CAAD("redirect_time", d_code);
    2976             :                 }
    2977             : #if LIBCURL_VERSION_NUM >= 0x071202 /* Available since 7.18.2 */
    2978          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_URL, &s_code) == CURLE_OK) {
    2979          13 :                         CAAS("redirect_url", s_code);
    2980             :                 }
    2981             : #endif
    2982             : #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
    2983          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_PRIMARY_IP, &s_code) == CURLE_OK) {
    2984          13 :                         CAAS("primary_ip", s_code);
    2985             :                 }
    2986             : #endif
    2987             : #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
    2988          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
    2989          13 :                         array_init(&listcode);
    2990          13 :                         create_certinfo(ci, &listcode TSRMLS_CC);
    2991          13 :                         CAAZ("certinfo", &listcode);
    2992             :                 }
    2993             : #endif
    2994             : #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
    2995             :                 if (curl_easy_getinfo(ch->cp, CURLINFO_PRIMARY_PORT, &l_code) == CURLE_OK) {
    2996             :                         CAAL("primary_port", l_code);
    2997             :                 }
    2998             :                 if (curl_easy_getinfo(ch->cp, CURLINFO_LOCAL_IP, &s_code) == CURLE_OK) {
    2999             :                         CAAS("local_ip", s_code);
    3000             :                 }
    3001             :                 if (curl_easy_getinfo(ch->cp, CURLINFO_LOCAL_PORT, &l_code) == CURLE_OK) {
    3002             :                         CAAL("local_port", l_code);
    3003             :                 }
    3004             : #endif
    3005          13 :                 if (ch->header.str) {
    3006           0 :                         CAASTR("request_header", ch->header.str);
    3007             :                 }
    3008             :         } else {
    3009           9 :                 switch (option) {
    3010             :                         case CURLINFO_HEADER_OUT:
    3011           0 :                                 if (ch->header.str) {
    3012           0 :                                         RETURN_STR(zend_string_copy(ch->header.str));
    3013             :                                 } else {
    3014           0 :                                         RETURN_FALSE;
    3015             :                                 }
    3016             : #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
    3017             :                         case CURLINFO_CERTINFO: {
    3018           0 :                                 struct curl_certinfo *ci = NULL;
    3019             : 
    3020           0 :                                 array_init(return_value);
    3021             : 
    3022           0 :                                 if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
    3023           0 :                                         create_certinfo(ci, return_value TSRMLS_CC);
    3024             :                                 } else {
    3025           0 :                                         RETURN_FALSE;
    3026             :                                 }
    3027           0 :                                 break;
    3028             :                         }
    3029             : #endif
    3030             :                         default: {
    3031           9 :                                 int type = CURLINFO_TYPEMASK & option;
    3032           9 :                                 switch (type) {
    3033             :                                         case CURLINFO_STRING:
    3034             :                                         {
    3035           4 :                                                 char *s_code = NULL;
    3036             : 
    3037           4 :                                                 if (curl_easy_getinfo(ch->cp, option, &s_code) == CURLE_OK && s_code) {
    3038           8 :                                                         RETURN_STRING(s_code);
    3039             :                                                 } else {
    3040           0 :                                                         RETURN_FALSE;
    3041             :                                                 }
    3042             :                                                 break;
    3043             :                                         }
    3044             :                                         case CURLINFO_LONG:
    3045             :                                         {
    3046           4 :                                                 zend_long code = 0;
    3047             : 
    3048           4 :                                                 if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) {
    3049           4 :                                                         RETURN_LONG(code);
    3050             :                                                 } else {
    3051           0 :                                                         RETURN_FALSE;
    3052             :                                                 }
    3053             :                                                 break;
    3054             :                                         }
    3055             :                                         case CURLINFO_DOUBLE:
    3056             :                                         {
    3057           0 :                                                 double code = 0.0;
    3058             : 
    3059           0 :                                                 if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) {
    3060           0 :                                                         RETURN_DOUBLE(code);
    3061             :                                                 } else {
    3062           0 :                                                         RETURN_FALSE;
    3063             :                                                 }
    3064             :                                                 break;
    3065             :                                         }
    3066             : #if LIBCURL_VERSION_NUM >= 0x070c03 /* Available since 7.12.3 */
    3067             :                                         case CURLINFO_SLIST:
    3068             :                                         {
    3069             :                                                 struct curl_slist *slist;
    3070           1 :                                                 array_init(return_value);
    3071           1 :                                                 if (curl_easy_getinfo(ch->cp, option, &slist) == CURLE_OK) {
    3072           4 :                                                         while (slist) {
    3073           2 :                                                                 add_next_index_string(return_value, slist->data);
    3074           2 :                                                                 slist = slist->next;
    3075             :                                                         }
    3076           1 :                                                         curl_slist_free_all(slist);
    3077             :                                                 } else {
    3078           0 :                                                         RETURN_FALSE;
    3079             :                                                 }
    3080           1 :                                                 break;
    3081             :                                         }
    3082             : #endif
    3083             :                                         default:
    3084           0 :                                                 RETURN_FALSE;
    3085             :                                 }
    3086             :                         }
    3087             :                 }
    3088             :         }
    3089             : }
    3090             : /* }}} */
    3091             : 
    3092             : /* {{{ proto string curl_error(resource ch)
    3093             :    Return a string contain the last error for the current session */
    3094           5 : PHP_FUNCTION(curl_error)
    3095             : {
    3096             :         zval            *zid;
    3097             :         php_curl        *ch;
    3098             : 
    3099           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
    3100           0 :                 return;
    3101             :         }
    3102             : 
    3103           5 :         ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
    3104             : 
    3105           5 :         ch->err.str[CURL_ERROR_SIZE] = 0;
    3106          10 :         RETURN_STRING(ch->err.str);
    3107             : }
    3108             : /* }}} */
    3109             : 
    3110             : /* {{{ proto int curl_errno(resource ch)
    3111             :    Return an integer containing the last error number */
    3112           4 : PHP_FUNCTION(curl_errno)
    3113             : {
    3114             :         zval            *zid;
    3115             :         php_curl        *ch;
    3116             : 
    3117           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
    3118           0 :                 return;
    3119             :         }
    3120             : 
    3121           4 :         ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
    3122             : 
    3123           4 :         RETURN_LONG(ch->err.no);
    3124             : }
    3125             : /* }}} */
    3126             : 
    3127             : /* {{{ proto void curl_close(resource ch)
    3128             :    Close a cURL session */
    3129          62 : PHP_FUNCTION(curl_close)
    3130             : {
    3131             :         zval            *zid;
    3132             :         php_curl        *ch;
    3133             : 
    3134          62 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
    3135           0 :                 return;
    3136             :         }
    3137             : 
    3138          62 :         ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
    3139             : 
    3140          62 :         if (ch->in_callback) {
    3141           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to close cURL handle from a callback");
    3142           0 :                 return;
    3143             :         }
    3144             : 
    3145         124 :         if (Z_REFCOUNT_P(zid) <= 2) {
    3146          56 :                 zend_list_close(Z_RES_P(zid));
    3147             :         }
    3148             : }
    3149             : /* }}} */
    3150             : 
    3151             : /* {{{ _php_curl_close()
    3152             :    List destructor for curl handles */
    3153         108 : static void _php_curl_close_ex(php_curl *ch TSRMLS_DC)
    3154             : {
    3155             : #if PHP_CURL_DEBUG
    3156             :         fprintf(stderr, "DTOR CALLED, ch = %x\n", ch);
    3157             : #endif
    3158             : 
    3159         108 :         _php_curl_verify_handlers(ch, 0 TSRMLS_CC);
    3160             : 
    3161             :         /*
    3162             :          * Libcurl is doing connection caching. When easy handle is cleaned up,
    3163             :          * if the handle was previously used by the curl_multi_api, the connection
    3164             :          * remains open un the curl multi handle is cleaned up. Some protocols are
    3165             :          * sending content like the FTP one, and libcurl try to use the
    3166             :          * WRITEFUNCTION or the HEADERFUNCTION. Since structures used in those
    3167             :          * callback are freed, we need to use an other callback to which avoid
    3168             :          * segfaults.
    3169             :          *
    3170             :          * Libcurl commit d021f2e8a00 fix this issue and should be part of 7.28.2
    3171             :          */
    3172         108 :         curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_nothing);
    3173         108 :         curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write_nothing);
    3174             : 
    3175         108 :         curl_easy_cleanup(ch->cp);
    3176             : 
    3177             :         /* cURL destructors should be invoked only by last curl handle */
    3178         108 :         if (--ch->clone == 0) {
    3179          97 :                 zend_llist_clean(&ch->to_free->str);
    3180          97 :                 zend_llist_clean(&ch->to_free->post);
    3181          97 :                 zend_hash_destroy(ch->to_free->slist);
    3182          97 :                 efree(ch->to_free->slist);
    3183          97 :                 efree(ch->to_free);
    3184             :         }
    3185             : 
    3186         108 :         smart_str_free(&ch->handlers->write->buf);
    3187         108 :         zval_ptr_dtor(&ch->handlers->write->func_name);
    3188         108 :         zval_ptr_dtor(&ch->handlers->read->func_name);
    3189         108 :         zval_ptr_dtor(&ch->handlers->write_header->func_name);
    3190             : #if CURLOPT_PASSWDFUNCTION != 0
    3191             :         zval_ptr_dtor(&ch->handlers->passwd);
    3192             : #endif
    3193         108 :         zval_ptr_dtor(&ch->handlers->std_err);
    3194         108 :         if (ch->header.str) {
    3195           0 :                 zend_string_release(ch->header.str);
    3196             :         }
    3197             : 
    3198         108 :         zval_ptr_dtor(&ch->handlers->write_header->stream);
    3199         108 :         zval_ptr_dtor(&ch->handlers->write->stream);
    3200         108 :         zval_ptr_dtor(&ch->handlers->read->stream);
    3201             : 
    3202         108 :         efree(ch->handlers->write);
    3203         108 :         efree(ch->handlers->write_header);
    3204         108 :         efree(ch->handlers->read);
    3205             : 
    3206         108 :         if (ch->handlers->progress) {
    3207           2 :                 zval_ptr_dtor(&ch->handlers->progress->func_name);
    3208           2 :                 efree(ch->handlers->progress);
    3209             :         }
    3210             : 
    3211             : #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
    3212             :         if (ch->handlers->fnmatch) {
    3213             :                 zval_ptr_dtor(&ch->handlers->fnmatch->func_name);
    3214             :                 efree(ch->handlers->fnmatch);
    3215             :         }
    3216             : #endif
    3217             : 
    3218         108 :         efree(ch->handlers);
    3219         108 :         efree(ch);
    3220         108 : }
    3221             : /* }}} */
    3222             : 
    3223             : /* {{{ _php_curl_close()
    3224             :    List destructor for curl handles */
    3225         108 : static void _php_curl_close(zend_resource *rsrc TSRMLS_DC)
    3226             : {
    3227         108 :         php_curl *ch = (php_curl *) rsrc->ptr;
    3228         108 :         _php_curl_close_ex(ch TSRMLS_CC);
    3229         108 : }
    3230             : /* }}} */
    3231             : 
    3232             : #if LIBCURL_VERSION_NUM >= 0x070c00 /* Available since 7.12.0 */
    3233             : /* {{{ proto bool curl_strerror(int code)
    3234             :       return string describing error code */
    3235           3 : PHP_FUNCTION(curl_strerror)
    3236             : {
    3237             :         zend_long code;
    3238             :         const char *str;
    3239             : 
    3240           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code) == FAILURE) {
    3241           0 :                 return;
    3242             :         }
    3243             : 
    3244           3 :         str = curl_easy_strerror(code);
    3245           3 :         if (str) {
    3246           6 :                 RETURN_STRING(str);
    3247             :         } else {
    3248           0 :                 RETURN_NULL();
    3249             :         }
    3250             : }
    3251             : /* }}} */
    3252             : #endif
    3253             : 
    3254             : #if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */
    3255             : /* {{{ _php_curl_reset_handlers()
    3256             :    Reset all handlers of a given php_curl */
    3257           1 : static void _php_curl_reset_handlers(php_curl *ch)
    3258             : {
    3259           2 :         if (!Z_ISUNDEF(ch->handlers->write->stream)) {
    3260           1 :                 zval_ptr_dtor(&ch->handlers->write->stream);
    3261           1 :                 ZVAL_UNDEF(&ch->handlers->write->stream);
    3262             :         }
    3263           1 :         ch->handlers->write->fp = NULL;
    3264           1 :         ch->handlers->write->method = PHP_CURL_STDOUT;
    3265             : 
    3266           2 :         if (!Z_ISUNDEF(ch->handlers->write_header->stream)) {
    3267           0 :                 zval_ptr_dtor(&ch->handlers->write_header->stream);
    3268           0 :                 ZVAL_UNDEF(&ch->handlers->write_header->stream);
    3269             :         }
    3270           1 :         ch->handlers->write_header->fp = NULL;
    3271           1 :         ch->handlers->write_header->method = PHP_CURL_IGNORE;
    3272             : 
    3273           2 :         if (!Z_ISUNDEF(ch->handlers->read->stream)) {
    3274           0 :                 zval_ptr_dtor(&ch->handlers->read->stream);
    3275           0 :                 ZVAL_UNDEF(&ch->handlers->read->stream);
    3276             :         }
    3277           1 :         ch->handlers->read->fp = NULL;
    3278           1 :         ch->handlers->read->res = NULL;
    3279           1 :         ch->handlers->read->method  = PHP_CURL_DIRECT;
    3280             : 
    3281           2 :         if (!Z_ISUNDEF(ch->handlers->std_err)) {
    3282           0 :                 zval_ptr_dtor(&ch->handlers->std_err);
    3283           0 :                 ZVAL_UNDEF(&ch->handlers->std_err);
    3284             :         }
    3285             : 
    3286           1 :         if (ch->handlers->progress) {
    3287           0 :                 zval_ptr_dtor(&ch->handlers->progress->func_name);
    3288           0 :                 efree(ch->handlers->progress);
    3289           0 :                 ch->handlers->progress = NULL;
    3290             :         }
    3291             : 
    3292             : #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
    3293             :         if (ch->handlers->fnmatch) {
    3294             :                 zval_ptr_dtor(&ch->handlers->fnmatch->func_name);
    3295             :                 efree(ch->handlers->fnmatch);
    3296             :                 ch->handlers->fnmatch = NULL;
    3297             :         }
    3298             : #endif
    3299             : 
    3300           1 : }
    3301             : /* }}} */
    3302             : 
    3303             : /* {{{ proto void curl_reset(resource ch)
    3304             :    Reset all options of a libcurl session handle */
    3305           1 : PHP_FUNCTION(curl_reset)
    3306             : {
    3307             :         zval       *zid;
    3308             :         php_curl   *ch;
    3309             : 
    3310           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
    3311           0 :                 return;
    3312             :         }
    3313             : 
    3314           1 :         ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
    3315             : 
    3316           1 :         if (ch->in_callback) {
    3317           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to reset cURL handle from a callback");
    3318           0 :                 return;
    3319             :         }
    3320             : 
    3321           1 :         curl_easy_reset(ch->cp);
    3322           1 :         _php_curl_reset_handlers(ch);
    3323           1 :         _php_curl_set_default_options(ch);
    3324             : }
    3325             : /* }}} */
    3326             : #endif
    3327             : 
    3328             : #if LIBCURL_VERSION_NUM > 0x070f03 /* 7.15.4 */
    3329             : /* {{{ proto void curl_escape(resource ch, string str)
    3330             :    URL encodes the given string */
    3331           0 : PHP_FUNCTION(curl_escape)
    3332             : {
    3333           0 :         char       *str = NULL, *res = NULL;
    3334           0 :         size_t        str_len = 0;
    3335             :         zval       *zid;
    3336             :         php_curl   *ch;
    3337             : 
    3338           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &zid, &str, &str_len) == FAILURE) {
    3339           0 :                 return;
    3340             :         }
    3341             : 
    3342           0 :         ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
    3343             : 
    3344           0 :         if ((res = curl_easy_escape(ch->cp, str, str_len))) {
    3345           0 :                 RETVAL_STRING(res);
    3346           0 :                 curl_free(res);
    3347             :         } else {
    3348           0 :                 RETURN_FALSE;
    3349             :         }
    3350             : }
    3351             : /* }}} */
    3352             : 
    3353             : /* {{{ proto void curl_unescape(resource ch, string str)
    3354             :    URL decodes the given string */
    3355           0 : PHP_FUNCTION(curl_unescape)
    3356             : {
    3357           0 :         char       *str = NULL, *out = NULL;
    3358           0 :         int        str_len = 0, out_len;
    3359             :         zval       *zid;
    3360             :         php_curl   *ch;
    3361             : 
    3362           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &zid, &str, &str_len) == FAILURE) {
    3363           0 :                 return;
    3364             :         }
    3365             : 
    3366           0 :         ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
    3367             : 
    3368           0 :         if ((out = curl_easy_unescape(ch->cp, str, str_len, &out_len))) {
    3369           0 :                 RETVAL_STRINGL(out, out_len);
    3370           0 :                 curl_free(out);
    3371             :         } else {
    3372           0 :                 RETURN_FALSE;
    3373             :         }
    3374             : }
    3375             : /* }}} */
    3376             : #endif
    3377             : 
    3378             : #if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */
    3379             : /* {{{ proto void curl_pause(resource ch, int bitmask)
    3380             :        pause and unpause a connection */
    3381           0 : PHP_FUNCTION(curl_pause)
    3382             : {
    3383             :         zend_long       bitmask;
    3384             :         zval       *zid;
    3385             :         php_curl   *ch;
    3386             : 
    3387           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zid, &bitmask) == FAILURE) {
    3388           0 :                 return;
    3389             :         }
    3390             : 
    3391           0 :         ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
    3392             : 
    3393           0 :         RETURN_LONG(curl_easy_pause(ch->cp, bitmask));
    3394             : }
    3395             : /* }}} */
    3396             : #endif
    3397             : 
    3398             : #endif /* HAVE_CURL */
    3399             : 
    3400             : /*
    3401             :  * Local variables:
    3402             :  * tab-width: 4
    3403             :  * c-basic-offset: 4
    3404             :  * End:
    3405             :  * vim600: fdm=marker
    3406             :  * vim: noet sw=4 ts=4
    3407             :  */

Generated by: LCOV version 1.10

Generated at Wed, 22 Oct 2014 07:24:46 +0000 (35 minutes ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.