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: 1143 1361 84.0 %
Date: 2022-01-21 Functions: 34 39 87.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Fri, 21 Jan 2022 14:15:09 +0000 (29 hours ago)

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