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

Generated by: LCOV version 1.10

Generated at Sun, 18 Sep 2016 08:20:04 +0000 (7 days ago)

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