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

Generated by: LCOV version 1.10

Generated at Wed, 02 Sep 2015 17:19:08 +0000 (34 hours ago)

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