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 1276 84.0 %
Date: 2016-08-24 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        3214 : void _php_curl_verify_handlers(php_curl *ch, int reporterror) /* {{{ */
     227             : {
     228             :         php_stream *stream;
     229             : 
     230             :         ZEND_ASSERT(ch && ch->handlers);
     231             : 
     232        6428 :         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        6428 :         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        6428 :         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        6428 :         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        3214 :         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       23504 : PHP_MINIT_FUNCTION(curl)
     653             : {
     654       23504 :         le_curl = zend_register_list_destructors_ex(_php_curl_close, NULL, "curl", module_number);
     655       23504 :         le_curl_multi_handle = zend_register_list_destructors_ex(_php_curl_multi_close, NULL, "curl_multi", module_number);
     656       23504 :         le_curl_share_handle = zend_register_list_destructors_ex(_php_curl_share_close, NULL, "curl_share", module_number);
     657             : 
     658       23504 :         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       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_AUTOREFERER);
     666       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_BINARYTRANSFER);
     667       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_BUFFERSIZE);
     668       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_CAINFO);
     669       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_CAPATH);
     670       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT);
     671       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_COOKIE);
     672       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_COOKIEFILE);
     673       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_COOKIEJAR);
     674       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_COOKIESESSION);
     675       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_CRLF);
     676       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_CUSTOMREQUEST);
     677       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_DNS_CACHE_TIMEOUT);
     678       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_DNS_USE_GLOBAL_CACHE);
     679       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_EGDSOCKET);
     680       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_ENCODING);
     681       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FAILONERROR);
     682       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FILE);
     683       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FILETIME);
     684       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FOLLOWLOCATION);
     685       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FORBID_REUSE);
     686       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FRESH_CONNECT);
     687       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FTPAPPEND);
     688       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FTPLISTONLY);
     689       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FTPPORT);
     690       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPRT);
     691       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPSV);
     692       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_HEADER);
     693       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_HEADERFUNCTION);
     694       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTP200ALIASES);
     695       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTPGET);
     696       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTPHEADER);
     697       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTPPROXYTUNNEL);
     698       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTP_VERSION);
     699       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_INFILE);
     700       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_INFILESIZE);
     701       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_INTERFACE);
     702       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_KRB4LEVEL);
     703       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_LIMIT);
     704       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_TIME);
     705       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_MAXCONNECTS);
     706       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_MAXREDIRS);
     707       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_NETRC);
     708       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_NOBODY);
     709       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_NOPROGRESS);
     710       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_NOSIGNAL);
     711       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PORT);
     712       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_POST);
     713       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_POSTFIELDS);
     714       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_POSTQUOTE);
     715       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PREQUOTE);
     716       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PRIVATE);
     717       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PROGRESSFUNCTION);
     718       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXY);
     719       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYPORT);
     720       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYTYPE);
     721       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYUSERPWD);
     722       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PUT);
     723       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_QUOTE);
     724       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_RANDOM_FILE);
     725       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_RANGE);
     726       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_READDATA);
     727       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_READFUNCTION);
     728       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_REFERER);
     729       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_RESUME_FROM);
     730       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_RETURNTRANSFER);
     731       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SHARE);
     732       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLCERT);
     733       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTPASSWD);
     734       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTTYPE);
     735       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE);
     736       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE_DEFAULT);
     737       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLKEY);
     738       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYPASSWD);
     739       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYTYPE);
     740       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLVERSION);
     741       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSL_CIPHER_LIST);
     742       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYHOST);
     743       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYPEER);
     744       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_STDERR);
     745       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_TELNETOPTIONS);
     746       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_TIMECONDITION);
     747       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT);
     748       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_TIMEVALUE);
     749       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_TRANSFERTEXT);
     750       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_UNRESTRICTED_AUTH);
     751       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_UPLOAD);
     752       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_URL);
     753       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_USERAGENT);
     754       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_USERPWD);
     755       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_VERBOSE);
     756       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_WRITEFUNCTION);
     757       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_WRITEHEADER);
     758             : 
     759             :         /* */
     760       23504 :         REGISTER_CURL_CONSTANT(CURLE_ABORTED_BY_CALLBACK);
     761       23504 :         REGISTER_CURL_CONSTANT(CURLE_BAD_CALLING_ORDER);
     762       23504 :         REGISTER_CURL_CONSTANT(CURLE_BAD_CONTENT_ENCODING);
     763       23504 :         REGISTER_CURL_CONSTANT(CURLE_BAD_DOWNLOAD_RESUME);
     764       23504 :         REGISTER_CURL_CONSTANT(CURLE_BAD_FUNCTION_ARGUMENT);
     765       23504 :         REGISTER_CURL_CONSTANT(CURLE_BAD_PASSWORD_ENTERED);
     766       23504 :         REGISTER_CURL_CONSTANT(CURLE_COULDNT_CONNECT);
     767       23504 :         REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_HOST);
     768       23504 :         REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_PROXY);
     769       23504 :         REGISTER_CURL_CONSTANT(CURLE_FAILED_INIT);
     770       23504 :         REGISTER_CURL_CONSTANT(CURLE_FILE_COULDNT_READ_FILE);
     771       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_ACCESS_DENIED);
     772       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_BAD_DOWNLOAD_RESUME);
     773       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_GET_HOST);
     774       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_RECONNECT);
     775       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_GET_SIZE);
     776       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_RETR_FILE);
     777       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_ASCII);
     778       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_BINARY);
     779       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_STOR_FILE);
     780       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_USE_REST);
     781       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_PARTIAL_FILE);
     782       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_PORT_FAILED);
     783       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_QUOTE_ERROR);
     784       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_USER_PASSWORD_INCORRECT);
     785       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_227_FORMAT);
     786       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASS_REPLY);
     787       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASV_REPLY);
     788       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_SERVER_REPLY);
     789       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_USER_REPLY);
     790       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WRITE_ERROR);
     791       23504 :         REGISTER_CURL_CONSTANT(CURLE_FUNCTION_NOT_FOUND);
     792       23504 :         REGISTER_CURL_CONSTANT(CURLE_GOT_NOTHING);
     793       23504 :         REGISTER_CURL_CONSTANT(CURLE_HTTP_NOT_FOUND);
     794       23504 :         REGISTER_CURL_CONSTANT(CURLE_HTTP_PORT_FAILED);
     795       23504 :         REGISTER_CURL_CONSTANT(CURLE_HTTP_POST_ERROR);
     796       23504 :         REGISTER_CURL_CONSTANT(CURLE_HTTP_RANGE_ERROR);
     797       23504 :         REGISTER_CURL_CONSTANT(CURLE_HTTP_RETURNED_ERROR);
     798       23504 :         REGISTER_CURL_CONSTANT(CURLE_LDAP_CANNOT_BIND);
     799       23504 :         REGISTER_CURL_CONSTANT(CURLE_LDAP_SEARCH_FAILED);
     800       23504 :         REGISTER_CURL_CONSTANT(CURLE_LIBRARY_NOT_FOUND);
     801       23504 :         REGISTER_CURL_CONSTANT(CURLE_MALFORMAT_USER);
     802       23504 :         REGISTER_CURL_CONSTANT(CURLE_OBSOLETE);
     803       23504 :         REGISTER_CURL_CONSTANT(CURLE_OK);
     804       23504 :         REGISTER_CURL_CONSTANT(CURLE_OPERATION_TIMEDOUT);
     805       23504 :         REGISTER_CURL_CONSTANT(CURLE_OPERATION_TIMEOUTED);
     806       23504 :         REGISTER_CURL_CONSTANT(CURLE_OUT_OF_MEMORY);
     807       23504 :         REGISTER_CURL_CONSTANT(CURLE_PARTIAL_FILE);
     808       23504 :         REGISTER_CURL_CONSTANT(CURLE_READ_ERROR);
     809       23504 :         REGISTER_CURL_CONSTANT(CURLE_RECV_ERROR);
     810       23504 :         REGISTER_CURL_CONSTANT(CURLE_SEND_ERROR);
     811       23504 :         REGISTER_CURL_CONSTANT(CURLE_SHARE_IN_USE);
     812       23504 :         REGISTER_CURL_CONSTANT(CURLE_SSL_CACERT);
     813       23504 :         REGISTER_CURL_CONSTANT(CURLE_SSL_CERTPROBLEM);
     814       23504 :         REGISTER_CURL_CONSTANT(CURLE_SSL_CIPHER);
     815       23504 :         REGISTER_CURL_CONSTANT(CURLE_SSL_CONNECT_ERROR);
     816       23504 :         REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_NOTFOUND);
     817       23504 :         REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_SETFAILED);
     818       23504 :         REGISTER_CURL_CONSTANT(CURLE_SSL_PEER_CERTIFICATE);
     819       23504 :         REGISTER_CURL_CONSTANT(CURLE_TELNET_OPTION_SYNTAX);
     820       23504 :         REGISTER_CURL_CONSTANT(CURLE_TOO_MANY_REDIRECTS);
     821       23504 :         REGISTER_CURL_CONSTANT(CURLE_UNKNOWN_TELNET_OPTION);
     822       23504 :         REGISTER_CURL_CONSTANT(CURLE_UNSUPPORTED_PROTOCOL);
     823       23504 :         REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT);
     824       23504 :         REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT_USER);
     825       23504 :         REGISTER_CURL_CONSTANT(CURLE_WRITE_ERROR);
     826             : 
     827             :         /* cURL info constants */
     828       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_CONNECT_TIME);
     829       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_DOWNLOAD);
     830       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_UPLOAD);
     831       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_TYPE);
     832       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_EFFECTIVE_URL);
     833       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_FILETIME);
     834       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_HEADER_OUT);
     835       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_HEADER_SIZE);
     836       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_HTTP_CODE);
     837       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_LASTONE);
     838       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_NAMELOOKUP_TIME);
     839       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_PRETRANSFER_TIME);
     840       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_PRIVATE);
     841       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_COUNT);
     842       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_TIME);
     843       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_REQUEST_SIZE);
     844       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_SIZE_DOWNLOAD);
     845       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_SIZE_UPLOAD);
     846       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_SPEED_DOWNLOAD);
     847       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_SPEED_UPLOAD);
     848       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_SSL_VERIFYRESULT);
     849       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_STARTTRANSFER_TIME);
     850       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_TOTAL_TIME);
     851             : 
     852             :         /* Other */
     853       23504 :         REGISTER_CURL_CONSTANT(CURLMSG_DONE);
     854       23504 :         REGISTER_CURL_CONSTANT(CURLVERSION_NOW);
     855             : 
     856             :         /* Curl Multi Constants */
     857       23504 :         REGISTER_CURL_CONSTANT(CURLM_BAD_EASY_HANDLE);
     858       23504 :         REGISTER_CURL_CONSTANT(CURLM_BAD_HANDLE);
     859       23504 :         REGISTER_CURL_CONSTANT(CURLM_CALL_MULTI_PERFORM);
     860       23504 :         REGISTER_CURL_CONSTANT(CURLM_INTERNAL_ERROR);
     861       23504 :         REGISTER_CURL_CONSTANT(CURLM_OK);
     862       23504 :         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       23504 :         REGISTER_CURL_CONSTANT(CURLPROXY_HTTP);
     869       23504 :         REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS4);
     870       23504 :         REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS5);
     871             : 
     872             :         /* Curl Share constants */
     873       23504 :         REGISTER_CURL_CONSTANT(CURLSHOPT_NONE);
     874       23504 :         REGISTER_CURL_CONSTANT(CURLSHOPT_SHARE);
     875       23504 :         REGISTER_CURL_CONSTANT(CURLSHOPT_UNSHARE);
     876             : 
     877             :         /* Curl Http Version constants (CURLOPT_HTTP_VERSION) */
     878       23504 :         REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_0);
     879       23504 :         REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_1);
     880       23504 :         REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_NONE);
     881             : 
     882             :         /* Curl Lock constants */
     883       23504 :         REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_COOKIE);
     884       23504 :         REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_DNS);
     885       23504 :         REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_SSL_SESSION);
     886             : 
     887             :         /* Curl NETRC constants (CURLOPT_NETRC) */
     888       23504 :         REGISTER_CURL_CONSTANT(CURL_NETRC_IGNORED);
     889       23504 :         REGISTER_CURL_CONSTANT(CURL_NETRC_OPTIONAL);
     890       23504 :         REGISTER_CURL_CONSTANT(CURL_NETRC_REQUIRED);
     891             : 
     892             :         /* Curl SSL Version constants (CURLOPT_SSLVERSION) */
     893       23504 :         REGISTER_CURL_CONSTANT(CURL_SSLVERSION_DEFAULT);
     894       23504 :         REGISTER_CURL_CONSTANT(CURL_SSLVERSION_SSLv2);
     895       23504 :         REGISTER_CURL_CONSTANT(CURL_SSLVERSION_SSLv3);
     896       23504 :         REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1);
     897             : 
     898             :         /* Curl TIMECOND constants (CURLOPT_TIMECONDITION) */
     899       23504 :         REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFMODSINCE);
     900       23504 :         REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFUNMODSINCE);
     901       23504 :         REGISTER_CURL_CONSTANT(CURL_TIMECOND_LASTMOD);
     902       23504 :         REGISTER_CURL_CONSTANT(CURL_TIMECOND_NONE);
     903             : 
     904             :         /* Curl version constants */
     905       23504 :         REGISTER_CURL_CONSTANT(CURL_VERSION_IPV6);
     906       23504 :         REGISTER_CURL_CONSTANT(CURL_VERSION_KERBEROS4);
     907       23504 :         REGISTER_CURL_CONSTANT(CURL_VERSION_LIBZ);
     908       23504 :         REGISTER_CURL_CONSTANT(CURL_VERSION_SSL);
     909             : 
     910             : #if LIBCURL_VERSION_NUM >= 0x070a06 /* Available since 7.10.6 */
     911       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTPAUTH);
     912             :         /* http authentication options */
     913       23504 :         REGISTER_CURL_CONSTANT(CURLAUTH_ANY);
     914       23504 :         REGISTER_CURL_CONSTANT(CURLAUTH_ANYSAFE);
     915       23504 :         REGISTER_CURL_CONSTANT(CURLAUTH_BASIC);
     916       23504 :         REGISTER_CURL_CONSTANT(CURLAUTH_DIGEST);
     917       23504 :         REGISTER_CURL_CONSTANT(CURLAUTH_GSSNEGOTIATE);
     918       23504 :         REGISTER_CURL_CONSTANT(CURLAUTH_NONE);
     919       23504 :         REGISTER_CURL_CONSTANT(CURLAUTH_NTLM);
     920             : #endif
     921             : 
     922             : #if LIBCURL_VERSION_NUM >= 0x070a07 /* Available since 7.10.7 */
     923       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_HTTP_CONNECTCODE);
     924       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_CREATE_MISSING_DIRS);
     925       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYAUTH);
     926             : #endif
     927             : 
     928             : #if LIBCURL_VERSION_NUM >= 0x070a08 /* Available since 7.10.8 */
     929       23504 :         REGISTER_CURL_CONSTANT(CURLE_FILESIZE_EXCEEDED);
     930       23504 :         REGISTER_CURL_CONSTANT(CURLE_LDAP_INVALID_URL);
     931       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_HTTPAUTH_AVAIL);
     932       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_RESPONSE_CODE);
     933       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_PROXYAUTH_AVAIL);
     934       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_RESPONSE_TIMEOUT);
     935       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_IPRESOLVE);
     936       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_MAXFILESIZE);
     937       23504 :         REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V4);
     938       23504 :         REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V6);
     939       23504 :         REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_WHATEVER);
     940             : #endif
     941             : 
     942             : #if LIBCURL_VERSION_NUM >= 0x070b00 /* Available since 7.11.0 */
     943       23504 :         REGISTER_CURL_CONSTANT(CURLE_FTP_SSL_FAILED);
     944       23504 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_ALL);
     945       23504 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_CONTROL);
     946       23504 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_NONE);
     947       23504 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_TRY);
     948       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_SSL);
     949       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_NETRC_FILE);
     950             : #endif
     951             : 
     952             : #if LIBCURL_VERSION_NUM >= 0x070c02 /* Available since 7.12.2 */
     953       23504 :         REGISTER_CURL_CONSTANT(CURLFTPAUTH_DEFAULT);
     954       23504 :         REGISTER_CURL_CONSTANT(CURLFTPAUTH_SSL);
     955       23504 :         REGISTER_CURL_CONSTANT(CURLFTPAUTH_TLS);
     956       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FTPSSLAUTH);
     957             : #endif
     958             : 
     959             : #if LIBCURL_VERSION_NUM >= 0x070d00 /* Available since 7.13.0 */
     960       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_ACCOUNT);
     961             : #endif
     962             : 
     963             : #if LIBCURL_VERSION_NUM >= 0x070b02 /* Available since 7.11.2 */
     964       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_TCP_NODELAY);
     965             : #endif
     966             : 
     967             : #if LIBCURL_VERSION_NUM >= 0x070c02 /* Available since 7.12.2 */
     968       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_OS_ERRNO);
     969             : #endif
     970             : 
     971             : #if LIBCURL_VERSION_NUM >= 0x070c03 /* Available since 7.12.3 */
     972       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_NUM_CONNECTS);
     973       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_SSL_ENGINES);
     974             : #endif
     975             : 
     976             : #if LIBCURL_VERSION_NUM >= 0x070e01 /* Available since 7.14.1 */
     977       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_COOKIELIST);
     978       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_COOKIELIST);
     979       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_IGNORE_CONTENT_LENGTH);
     980             : #endif
     981             : 
     982             : #if LIBCURL_VERSION_NUM >= 0x070f00 /* Available since 7.15.0 */
     983       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_SKIP_PASV_IP);
     984             : #endif
     985             : 
     986             : #if LIBCURL_VERSION_NUM >= 0x070f01 /* Available since 7.15.1 */
     987       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_FILEMETHOD);
     988             : #endif
     989             : 
     990             : #if LIBCURL_VERSION_NUM >= 0x070f02 /* Available since 7.15.2 */
     991       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_CONNECT_ONLY);
     992       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_LOCALPORT);
     993       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_LOCALPORTRANGE);
     994             : #endif
     995             : 
     996             : #if LIBCURL_VERSION_NUM >= 0x070f03 /* Available since 7.15.3 */
     997       23504 :         REGISTER_CURL_CONSTANT(CURLFTPMETHOD_MULTICWD);
     998       23504 :         REGISTER_CURL_CONSTANT(CURLFTPMETHOD_NOCWD);
     999       23504 :         REGISTER_CURL_CONSTANT(CURLFTPMETHOD_SINGLECWD);
    1000             : #endif
    1001             : 
    1002             : #if LIBCURL_VERSION_NUM >= 0x070f04 /* Available since 7.15.4 */
    1003       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_FTP_ENTRY_PATH);
    1004             : #endif
    1005             : 
    1006             : #if LIBCURL_VERSION_NUM >= 0x070f05 /* Available since 7.15.5 */
    1007       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_ALTERNATIVE_TO_USER);
    1008       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_MAX_RECV_SPEED_LARGE);
    1009       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_MAX_SEND_SPEED_LARGE);
    1010             : #endif
    1011             : 
    1012             : #if LIBCURL_VERSION_NUM >= 0x071000 /* Available since 7.16.0 */
    1013       23504 :         REGISTER_CURL_CONSTANT(CURLE_SSL_CACERT_BADFILE);
    1014       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSL_SESSIONID_CACHE);
    1015       23504 :         REGISTER_CURL_CONSTANT(CURLMOPT_PIPELINING);
    1016             : #endif
    1017             : 
    1018             : #if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */
    1019       23504 :         REGISTER_CURL_CONSTANT(CURLE_SSH);
    1020       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_SSL_CCC);
    1021       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSH_AUTH_TYPES);
    1022       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSH_PRIVATE_KEYFILE);
    1023       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSH_PUBLIC_KEYFILE);
    1024       23504 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_ACTIVE);
    1025       23504 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_NONE);
    1026       23504 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_PASSIVE);
    1027             : #endif
    1028             : 
    1029             : #if LIBCURL_VERSION_NUM >= 0x071002 /* Available since 7.16.2 */
    1030       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT_MS);
    1031       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTP_CONTENT_DECODING);
    1032       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTP_TRANSFER_DECODING);
    1033       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT_MS);
    1034             : #endif
    1035             : 
    1036             : #if LIBCURL_VERSION_NUM >= 0x071003 /* Available since 7.16.3 */
    1037       23504 :         REGISTER_CURL_CONSTANT(CURLMOPT_MAXCONNECTS);
    1038             : #endif
    1039             : 
    1040             : #if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */
    1041       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_KRBLEVEL);
    1042       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_NEW_DIRECTORY_PERMS);
    1043       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_NEW_FILE_PERMS);
    1044             : #endif
    1045             : 
    1046             : #if LIBCURL_VERSION_NUM >= 0x071100 /* Available since 7.17.0 */
    1047       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_APPEND);
    1048       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_DIRLISTONLY);
    1049       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_USE_SSL);
    1050             :         /* Curl SSL Constants */
    1051       23504 :         REGISTER_CURL_CONSTANT(CURLUSESSL_ALL);
    1052       23504 :         REGISTER_CURL_CONSTANT(CURLUSESSL_CONTROL);
    1053       23504 :         REGISTER_CURL_CONSTANT(CURLUSESSL_NONE);
    1054       23504 :         REGISTER_CURL_CONSTANT(CURLUSESSL_TRY);
    1055             : #endif
    1056             : 
    1057             : #if LIBCURL_VERSION_NUM >= 0x071101 /* Available since 7.17.1 */
    1058       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SSH_HOST_PUBLIC_KEY_MD5);
    1059             : #endif
    1060             : 
    1061             : #if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */
    1062       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXY_TRANSFER_MODE);
    1063       23504 :         REGISTER_CURL_CONSTANT(CURLPAUSE_ALL);
    1064       23504 :         REGISTER_CURL_CONSTANT(CURLPAUSE_CONT);
    1065       23504 :         REGISTER_CURL_CONSTANT(CURLPAUSE_RECV);
    1066       23504 :         REGISTER_CURL_CONSTANT(CURLPAUSE_RECV_CONT);
    1067       23504 :         REGISTER_CURL_CONSTANT(CURLPAUSE_SEND);
    1068       23504 :         REGISTER_CURL_CONSTANT(CURLPAUSE_SEND_CONT);
    1069       23504 :         REGISTER_CURL_CONSTANT(CURL_READFUNC_PAUSE);
    1070       23504 :         REGISTER_CURL_CONSTANT(CURL_WRITEFUNC_PAUSE);
    1071             : 
    1072       23504 :         REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS4A);
    1073       23504 :         REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS5_HOSTNAME);
    1074             : #endif
    1075             : 
    1076             : #if LIBCURL_VERSION_NUM >= 0x071202 /* Available since 7.18.2 */
    1077       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_URL);
    1078             : #endif
    1079             : 
    1080             : #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
    1081       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_APPCONNECT_TIME);
    1082       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_PRIMARY_IP);
    1083             : 
    1084       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_ADDRESS_SCOPE);
    1085       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_CRLFILE);
    1086       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_ISSUERCERT);
    1087       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_KEYPASSWD);
    1088             : 
    1089       23504 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_ANY);
    1090       23504 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_DEFAULT);
    1091       23504 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_HOST);
    1092       23504 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_KEYBOARD);
    1093       23504 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_NONE);
    1094       23504 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PASSWORD);
    1095       23504 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PUBLICKEY);
    1096             : #endif
    1097             : 
    1098             : #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
    1099       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_CERTINFO);
    1100       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_CERTINFO);
    1101       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PASSWORD);
    1102       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_POSTREDIR);
    1103       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYPASSWORD);
    1104       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYUSERNAME);
    1105       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_USERNAME);
    1106       23504 :         REGISTER_CURL_CONSTANT(CURL_REDIR_POST_301);
    1107       23504 :         REGISTER_CURL_CONSTANT(CURL_REDIR_POST_302);
    1108       23504 :         REGISTER_CURL_CONSTANT(CURL_REDIR_POST_ALL);
    1109             : #endif
    1110             : 
    1111             : #if LIBCURL_VERSION_NUM >= 0x071303 /* Available since 7.19.3 */
    1112       23504 :         REGISTER_CURL_CONSTANT(CURLAUTH_DIGEST_IE);
    1113             : #endif
    1114             : 
    1115             : #if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */
    1116       23504 :         REGISTER_CURL_CONSTANT(CURLINFO_CONDITION_UNMET);
    1117             : 
    1118       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_NOPROXY);
    1119       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_PROTOCOLS);
    1120       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_REDIR_PROTOCOLS);
    1121       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SOCKS5_GSSAPI_NEC);
    1122       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_SOCKS5_GSSAPI_SERVICE);
    1123       23504 :         REGISTER_CURL_CONSTANT(CURLOPT_TFTP_BLKSIZE);
    1124             : 
    1125       23504 :         REGISTER_CURL_CONSTANT(CURLPROTO_ALL);
    1126       23504 :         REGISTER_CURL_CONSTANT(CURLPROTO_DICT);
    1127       23504 :         REGISTER_CURL_CONSTANT(CURLPROTO_FILE);
    1128       23504 :         REGISTER_CURL_CONSTANT(CURLPROTO_FTP);
    1129       23504 :         REGISTER_CURL_CONSTANT(CURLPROTO_FTPS);
    1130       23504 :         REGISTER_CURL_CONSTANT(CURLPROTO_HTTP);
    1131       23504 :         REGISTER_CURL_CONSTANT(CURLPROTO_HTTPS);
    1132       23504 :         REGISTER_CURL_CONSTANT(CURLPROTO_LDAP);
    1133       23504 :         REGISTER_CURL_CONSTANT(CURLPROTO_LDAPS);
    1134       23504 :         REGISTER_CURL_CONSTANT(CURLPROTO_SCP);
    1135       23504 :         REGISTER_CURL_CONSTANT(CURLPROTO_SFTP);
    1136       23504 :         REGISTER_CURL_CONSTANT(CURLPROTO_TELNET);
    1137       23504 :         REGISTER_CURL_CONSTANT(CURLPROTO_TFTP);
    1138             : 
    1139       23504 :         REGISTER_CURL_CONSTANT(CURLPROXY_HTTP_1_0);
    1140             : 
    1141       23504 :         REGISTER_CURL_CONSTANT(CURLFTP_CREATE_DIR);
    1142       23504 :         REGISTER_CURL_CONSTANT(CURLFTP_CREATE_DIR_NONE);
    1143       23504 :         REGISTER_CURL_CONSTANT(CURLFTP_CREATE_DIR_RETRY);
    1144             : #endif
    1145             : 
    1146             : #if LIBCURL_VERSION_NUM >= 0x071306 /* Available since 7.19.6 */
    1147       23504 :         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       23504 :         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       23504 :         if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK) {
    1392           0 :                 return FAILURE;
    1393             :         }
    1394             : 
    1395       23504 :         curlfile_register_class();
    1396             : 
    1397       23504 :         return SUCCESS;
    1398             : }
    1399             : /* }}} */
    1400             : 
    1401             : /* {{{ PHP_MSHUTDOWN_FUNCTION
    1402             :  */
    1403       23544 : PHP_MSHUTDOWN_FUNCTION(curl)
    1404             : {
    1405       23544 :         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       23544 :         UNREGISTER_INI_ENTRIES();
    1422       23544 :         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         102 : static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx)
    1438             : {
    1439         102 :         php_curl *ch = (php_curl *) ctx;
    1440         102 :         php_curl_write *t = ch->handlers->write;
    1441         102 :         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         102 :         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          75 :                         if (length > 0) {
    1456          75 :                                 smart_str_appendl(&t->buf, data, (int) length);
    1457             :                         }
    1458          75 :                         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          99 :         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, 64);
    1905           0 :                                 tmp = memchr(s, ':', 64);
    1906           0 :                                 if(tmp) {
    1907           0 :                                         *tmp = '\0';
    1908           0 :                                         len = strlen(s);
    1909           0 :                                         add_assoc_string(&certhash, s, &slist->data[len+1]);
    1910             :                                 } else {
    1911           0 :                                         php_error_docref(NULL, E_WARNING, "Could not extract hash key from certificate info");
    1912             :                                 }
    1913             :                         }
    1914           0 :                         add_next_index_zval(listcode, &certhash);
    1915             :                 }
    1916             :         }
    1917          13 : }
    1918             : /* }}} */
    1919             : #endif
    1920             : 
    1921             : /* {{{ _php_curl_set_default_options()
    1922             :    Set default options for a handle */
    1923         112 : static void _php_curl_set_default_options(php_curl *ch)
    1924             : {
    1925             :         char *cainfo;
    1926             : 
    1927         112 :         curl_easy_setopt(ch->cp, CURLOPT_NOPROGRESS,        1);
    1928         112 :         curl_easy_setopt(ch->cp, CURLOPT_VERBOSE,           0);
    1929         112 :         curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER,       ch->err.str);
    1930         112 :         curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION,     curl_write);
    1931         112 :         curl_easy_setopt(ch->cp, CURLOPT_FILE,              (void *) ch);
    1932         112 :         curl_easy_setopt(ch->cp, CURLOPT_READFUNCTION,      curl_read);
    1933         112 :         curl_easy_setopt(ch->cp, CURLOPT_INFILE,            (void *) ch);
    1934         112 :         curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION,    curl_write_header);
    1935         112 :         curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER,       (void *) ch);
    1936             : #if !defined(ZTS)
    1937         112 :         curl_easy_setopt(ch->cp, CURLOPT_DNS_USE_GLOBAL_CACHE, 1);
    1938             : #endif
    1939         112 :         curl_easy_setopt(ch->cp, CURLOPT_DNS_CACHE_TIMEOUT, 120);
    1940         112 :         curl_easy_setopt(ch->cp, CURLOPT_MAXREDIRS, 20); /* prevent infinite redirects */
    1941             : 
    1942         112 :         cainfo = INI_STR("openssl.cafile");
    1943         112 :         if (!(cainfo && cainfo[0] != '\0')) {
    1944         112 :                 cainfo = INI_STR("curl.cainfo");
    1945             :         }
    1946         112 :         if (cainfo && cainfo[0] != '\0') {
    1947           0 :                 curl_easy_setopt(ch->cp, CURLOPT_CAINFO, cainfo);
    1948             :         }
    1949             : 
    1950             : #if defined(ZTS)
    1951             :         curl_easy_setopt(ch->cp, CURLOPT_NOSIGNAL, 1);
    1952             : #endif
    1953         112 : }
    1954             : /* }}} */
    1955             : 
    1956             : /* {{{ proto resource curl_init([string url])
    1957             :    Initialize a cURL session */
    1958         111 : PHP_FUNCTION(curl_init)
    1959             : {
    1960             :         php_curl *ch;
    1961             :         CURL     *cp;
    1962         111 :         char     *url = NULL;
    1963         111 :         size_t            url_len = 0;
    1964             : 
    1965         111 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &url, &url_len) == FAILURE) {
    1966           0 :                 return;
    1967             :         }
    1968             : 
    1969         111 :         cp = curl_easy_init();
    1970         111 :         if (!cp) {
    1971           0 :                 php_error_docref(NULL, E_WARNING, "Could not initialize a new cURL handle");
    1972           0 :                 RETURN_FALSE;
    1973             :         }
    1974             : 
    1975         111 :         ch = alloc_curl_handle();
    1976             : 
    1977         111 :         ch->cp = cp;
    1978             : 
    1979         111 :         ch->handlers->write->method = PHP_CURL_STDOUT;
    1980         111 :         ch->handlers->read->method  = PHP_CURL_DIRECT;
    1981         111 :         ch->handlers->write_header->method = PHP_CURL_IGNORE;
    1982             : 
    1983         111 :         _php_curl_set_default_options(ch);
    1984             : 
    1985         111 :         if (url) {
    1986          14 :                 if (php_curl_option_url(ch, url, url_len) == FAILURE) {
    1987           0 :                         _php_curl_close_ex(ch);
    1988           0 :                         RETURN_FALSE;
    1989             :                 }
    1990             :         }
    1991             : 
    1992         111 :         ZVAL_RES(return_value, zend_register_resource(ch, le_curl));
    1993         111 :         ch->res = Z_RES_P(return_value);
    1994             : }
    1995             : /* }}} */
    1996             : 
    1997          17 : void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
    1998             : {
    1999          34 :         if (!Z_ISUNDEF(source->handlers->write->stream)) {
    2000           1 :                 Z_ADDREF(source->handlers->write->stream);
    2001             :         }
    2002          17 :         ch->handlers->write->stream = source->handlers->write->stream;
    2003          17 :         ch->handlers->write->method = source->handlers->write->method;
    2004          34 :         if (!Z_ISUNDEF(source->handlers->read->stream)) {
    2005           0 :                 Z_ADDREF(source->handlers->read->stream);
    2006             :         }
    2007          17 :         ch->handlers->read->stream  = source->handlers->read->stream;
    2008          17 :         ch->handlers->read->method  = source->handlers->read->method;
    2009          17 :         ch->handlers->write_header->method = source->handlers->write_header->method;
    2010          34 :         if (!Z_ISUNDEF(source->handlers->write_header->stream)) {
    2011           0 :                 Z_ADDREF(source->handlers->write_header->stream);
    2012             :         }
    2013          17 :         ch->handlers->write_header->stream = source->handlers->write_header->stream;
    2014             : 
    2015          17 :         ch->handlers->write->fp = source->handlers->write->fp;
    2016          17 :         ch->handlers->write_header->fp = source->handlers->write_header->fp;
    2017          17 :         ch->handlers->read->fp = source->handlers->read->fp;
    2018          17 :         ch->handlers->read->res = source->handlers->read->res;
    2019             : #if CURLOPT_PASSWDDATA != 0
    2020             :         if (!Z_ISUNDEF(source->handlers->passwd)) {
    2021             :                 ZVAL_COPY(&ch->handlers->passwd, &source->handlers->passwd);
    2022             :                 curl_easy_setopt(source->cp, CURLOPT_PASSWDDATA, (void *) ch);
    2023             :         }
    2024             : #endif
    2025          34 :         if (!Z_ISUNDEF(source->handlers->write->func_name)) {
    2026           0 :                 ZVAL_COPY(&ch->handlers->write->func_name, &source->handlers->write->func_name);
    2027             :         }
    2028          34 :         if (!Z_ISUNDEF(source->handlers->read->func_name)) {
    2029           0 :                 ZVAL_COPY(&ch->handlers->read->func_name, &source->handlers->read->func_name);
    2030             :         }
    2031          34 :         if (!Z_ISUNDEF(source->handlers->write_header->func_name)) {
    2032           0 :                 ZVAL_COPY(&ch->handlers->write_header->func_name, &source->handlers->write_header->func_name);
    2033             :         }
    2034             : 
    2035          17 :         curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER,       ch->err.str);
    2036          17 :         curl_easy_setopt(ch->cp, CURLOPT_FILE,              (void *) ch);
    2037          17 :         curl_easy_setopt(ch->cp, CURLOPT_INFILE,            (void *) ch);
    2038          17 :         curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER,       (void *) ch);
    2039             : 
    2040          17 :         if (source->handlers->progress) {
    2041           1 :                 ch->handlers->progress = ecalloc(1, sizeof(php_curl_progress));
    2042           2 :                 if (!Z_ISUNDEF(source->handlers->progress->func_name)) {
    2043           1 :                         ZVAL_COPY(&ch->handlers->progress->func_name, &source->handlers->progress->func_name);
    2044             :                 }
    2045           1 :                 ch->handlers->progress->method = source->handlers->progress->method;
    2046           1 :                 curl_easy_setopt(ch->cp, CURLOPT_PROGRESSDATA, (void *) ch);
    2047             :         }
    2048             : 
    2049             : #if LIBCURL_VERSION_NUM >= 0x071500
    2050             :         if (source->handlers->fnmatch) {
    2051             :                 ch->handlers->fnmatch = ecalloc(1, sizeof(php_curl_fnmatch));
    2052             :                 if (!Z_ISUNDEF(source->handlers->fnmatch->func_name)) {
    2053             :                         ZVAL_COPY(&ch->handlers->fnmatch->func_name, &source->handlers->fnmatch->func_name);
    2054             :                 }
    2055             :                 ch->handlers->fnmatch->method = source->handlers->fnmatch->method;
    2056             :                 curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_DATA, (void *) ch);
    2057             :         }
    2058             : #endif
    2059             : 
    2060          17 :         efree(ch->to_free->slist);
    2061          17 :         efree(ch->to_free);
    2062          17 :         ch->to_free = source->to_free;
    2063          17 :         efree(ch->clone);
    2064          17 :         ch->clone = source->clone;
    2065             : 
    2066             :         /* Keep track of cloned copies to avoid invoking curl destructors for every clone */
    2067          17 :         (*source->clone)++;
    2068          17 : }
    2069             : 
    2070             : /* {{{ proto resource curl_copy_handle(resource ch)
    2071             :    Copy a cURL handle along with all of it's preferences */
    2072          17 : PHP_FUNCTION(curl_copy_handle)
    2073             : {
    2074             :         CURL            *cp;
    2075             :         zval            *zid;
    2076             :         php_curl        *ch, *dupch;
    2077             : 
    2078          17 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zid) == FAILURE) {
    2079           0 :                 return;
    2080             :         }
    2081             : 
    2082          17 :         if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
    2083           0 :                 RETURN_FALSE;
    2084             :         }
    2085             : 
    2086          17 :         cp = curl_easy_duphandle(ch->cp);
    2087          17 :         if (!cp) {
    2088           0 :                 php_error_docref(NULL, E_WARNING, "Cannot duplicate cURL handle");
    2089           0 :                 RETURN_FALSE;
    2090             :         }
    2091             : 
    2092          17 :         dupch = alloc_curl_handle();
    2093          17 :         dupch->cp = cp;
    2094             : 
    2095          17 :         _php_setup_easy_copy_handlers(dupch, ch);
    2096             : 
    2097          17 :         Z_ADDREF_P(zid);
    2098             : 
    2099          17 :         ZVAL_RES(return_value, zend_register_resource(dupch, le_curl));
    2100          17 :         dupch->res = Z_RES_P(return_value);
    2101             : }
    2102             : /* }}} */
    2103             : 
    2104       12318 : static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ */
    2105             : {
    2106       12318 :         CURLcode error = CURLE_OK;
    2107             :         zend_long lval;
    2108             : 
    2109       12318 :         ZVAL_DEREF(zvalue);
    2110       12318 :         switch (option) {
    2111             :                 /* Long options */
    2112             :                 case CURLOPT_SSL_VERIFYHOST:
    2113           5 :                         lval = zval_get_long(zvalue);
    2114           5 :                         if (lval == 1) {
    2115             : #if LIBCURL_VERSION_NUM <= 0x071c00 /* 7.28.0 */
    2116           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");
    2117             : #else
    2118             :                                 php_error_docref(NULL, E_NOTICE, "CURLOPT_SSL_VERIFYHOST no longer accepts the value 1, value 2 will be used instead");
    2119             :                                 error = curl_easy_setopt(ch->cp, option, 2);
    2120             :                                 break;
    2121             : #endif
    2122             :                         }
    2123             :                 case CURLOPT_AUTOREFERER:
    2124             :                 case CURLOPT_BUFFERSIZE:
    2125             :                 case CURLOPT_CONNECTTIMEOUT:
    2126             :                 case CURLOPT_COOKIESESSION:
    2127             :                 case CURLOPT_CRLF:
    2128             :                 case CURLOPT_DNS_CACHE_TIMEOUT:
    2129             :                 case CURLOPT_DNS_USE_GLOBAL_CACHE:
    2130             :                 case CURLOPT_FAILONERROR:
    2131             :                 case CURLOPT_FILETIME:
    2132             :                 case CURLOPT_FORBID_REUSE:
    2133             :                 case CURLOPT_FRESH_CONNECT:
    2134             :                 case CURLOPT_FTP_USE_EPRT:
    2135             :                 case CURLOPT_FTP_USE_EPSV:
    2136             :                 case CURLOPT_HEADER:
    2137             :                 case CURLOPT_HTTPGET:
    2138             :                 case CURLOPT_HTTPPROXYTUNNEL:
    2139             :                 case CURLOPT_HTTP_VERSION:
    2140             :                 case CURLOPT_INFILESIZE:
    2141             :                 case CURLOPT_LOW_SPEED_LIMIT:
    2142             :                 case CURLOPT_LOW_SPEED_TIME:
    2143             :                 case CURLOPT_MAXCONNECTS:
    2144             :                 case CURLOPT_MAXREDIRS:
    2145             :                 case CURLOPT_NETRC:
    2146             :                 case CURLOPT_NOBODY:
    2147             :                 case CURLOPT_NOPROGRESS:
    2148             :                 case CURLOPT_NOSIGNAL:
    2149             :                 case CURLOPT_PORT:
    2150             :                 case CURLOPT_POST:
    2151             :                 case CURLOPT_PROXYPORT:
    2152             :                 case CURLOPT_PROXYTYPE:
    2153             :                 case CURLOPT_PUT:
    2154             :                 case CURLOPT_RESUME_FROM:
    2155             :                 case CURLOPT_SSLVERSION:
    2156             :                 case CURLOPT_SSL_VERIFYPEER:
    2157             :                 case CURLOPT_TIMECONDITION:
    2158             :                 case CURLOPT_TIMEOUT:
    2159             :                 case CURLOPT_TIMEVALUE:
    2160             :                 case CURLOPT_TRANSFERTEXT:
    2161             :                 case CURLOPT_UNRESTRICTED_AUTH:
    2162             :                 case CURLOPT_UPLOAD:
    2163             :                 case CURLOPT_VERBOSE:
    2164             : #if LIBCURL_VERSION_NUM >= 0x070a06 /* Available since 7.10.6 */
    2165             :                 case CURLOPT_HTTPAUTH:
    2166             : #endif
    2167             : #if LIBCURL_VERSION_NUM >= 0x070a07 /* Available since 7.10.7 */
    2168             :                 case CURLOPT_FTP_CREATE_MISSING_DIRS:
    2169             :                 case CURLOPT_PROXYAUTH:
    2170             : #endif
    2171             : #if LIBCURL_VERSION_NUM >= 0x070a08 /* Available since 7.10.8 */
    2172             :                 case CURLOPT_FTP_RESPONSE_TIMEOUT:
    2173             :                 case CURLOPT_IPRESOLVE:
    2174             :                 case CURLOPT_MAXFILESIZE:
    2175             : #endif
    2176             : #if LIBCURL_VERSION_NUM >= 0x070b02 /* Available since 7.11.2 */
    2177             :                 case CURLOPT_TCP_NODELAY:
    2178             : #endif
    2179             : #if LIBCURL_VERSION_NUM >= 0x070c02 /* Available since 7.12.2 */
    2180             :                 case CURLOPT_FTPSSLAUTH:
    2181             : #endif
    2182             : #if LIBCURL_VERSION_NUM >= 0x070e01 /* Available since 7.14.1 */
    2183             :                 case CURLOPT_IGNORE_CONTENT_LENGTH:
    2184             : #endif
    2185             : #if LIBCURL_VERSION_NUM >= 0x070f00 /* Available since 7.15.0 */
    2186             :                 case CURLOPT_FTP_SKIP_PASV_IP:
    2187             : #endif
    2188             : #if LIBCURL_VERSION_NUM >= 0x070f01 /* Available since 7.15.1 */
    2189             :                 case CURLOPT_FTP_FILEMETHOD:
    2190             : #endif
    2191             : #if LIBCURL_VERSION_NUM >= 0x070f02 /* Available since 7.15.2 */
    2192             :                 case CURLOPT_CONNECT_ONLY:
    2193             :                 case CURLOPT_LOCALPORT:
    2194             :                 case CURLOPT_LOCALPORTRANGE:
    2195             : #endif
    2196             : #if LIBCURL_VERSION_NUM >= 0x071000 /* Available since 7.16.0 */
    2197             :                 case CURLOPT_SSL_SESSIONID_CACHE:
    2198             : #endif
    2199             : #if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */
    2200             :                 case CURLOPT_FTP_SSL_CCC:
    2201             :                 case CURLOPT_SSH_AUTH_TYPES:
    2202             : #endif
    2203             : #if LIBCURL_VERSION_NUM >= 0x071002 /* Available since 7.16.2 */
    2204             :                 case CURLOPT_CONNECTTIMEOUT_MS:
    2205             :                 case CURLOPT_HTTP_CONTENT_DECODING:
    2206             :                 case CURLOPT_HTTP_TRANSFER_DECODING:
    2207             :                 case CURLOPT_TIMEOUT_MS:
    2208             : #endif
    2209             : #if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */
    2210             :                 case CURLOPT_NEW_DIRECTORY_PERMS:
    2211             :                 case CURLOPT_NEW_FILE_PERMS:
    2212             : #endif
    2213             : #if LIBCURL_VERSION_NUM >= 0x071100 /* Available since 7.17.0 */
    2214             :                 case CURLOPT_USE_SSL:
    2215             : #elif LIBCURL_VERSION_NUM >= 0x070b00 /* Available since 7.11.0 */
    2216             :                 case CURLOPT_FTP_SSL:
    2217             : #endif
    2218             : #if LIBCURL_VERSION_NUM >= 0x071100 /* Available since 7.17.0 */
    2219             :                 case CURLOPT_APPEND:
    2220             :                 case CURLOPT_DIRLISTONLY:
    2221             : #else
    2222             :                 case CURLOPT_FTPAPPEND:
    2223             :                 case CURLOPT_FTPLISTONLY:
    2224             : #endif
    2225             : #if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */
    2226             :                 case CURLOPT_PROXY_TRANSFER_MODE:
    2227             : #endif
    2228             : #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
    2229             :                 case CURLOPT_ADDRESS_SCOPE:
    2230             : #endif
    2231             : #if LIBCURL_VERSION_NUM >  0x071301 /* Available since 7.19.1 */
    2232             :                 case CURLOPT_CERTINFO:
    2233             : #endif
    2234             : #if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */
    2235             :                 case CURLOPT_PROTOCOLS:
    2236             :                 case CURLOPT_REDIR_PROTOCOLS:
    2237             :                 case CURLOPT_SOCKS5_GSSAPI_NEC:
    2238             :                 case CURLOPT_TFTP_BLKSIZE:
    2239             : #endif
    2240             : #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
    2241             :                 case CURLOPT_FTP_USE_PRET:
    2242             :                 case CURLOPT_RTSP_CLIENT_CSEQ:
    2243             :                 case CURLOPT_RTSP_REQUEST:
    2244             :                 case CURLOPT_RTSP_SERVER_CSEQ:
    2245             : #endif
    2246             : #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
    2247             :                 case CURLOPT_WILDCARDMATCH:
    2248             : #endif
    2249             : #if LIBCURL_VERSION_NUM >= 0x071504 /* Available since 7.21.4 */
    2250             :                 case CURLOPT_TLSAUTH_TYPE:
    2251             : #endif
    2252             : #if LIBCURL_VERSION_NUM >= 0x071600 /* Available since 7.22.0 */
    2253             :                 case CURLOPT_GSSAPI_DELEGATION:
    2254             : #endif
    2255             : #if LIBCURL_VERSION_NUM >= 0x071800 /* Available since 7.24.0 */
    2256             :                 case CURLOPT_ACCEPTTIMEOUT_MS:
    2257             : #endif
    2258             : #if LIBCURL_VERSION_NUM >= 0x071900 /* Available since 7.25.0 */
    2259             :                 case CURLOPT_SSL_OPTIONS:
    2260             :                 case CURLOPT_TCP_KEEPALIVE:
    2261             :                 case CURLOPT_TCP_KEEPIDLE:
    2262             :                 case CURLOPT_TCP_KEEPINTVL:
    2263             : #endif
    2264             : #if LIBCURL_VERSION_NUM >= 0x071f00 /* Available since 7.31.0 */
    2265             :                 case CURLOPT_SASL_IR:
    2266             : #endif
    2267             : #if LIBCURL_VERSION_NUM >= 0x072400 /* Available since 7.36.0 */
    2268             :                 case CURLOPT_EXPECT_100_TIMEOUT_MS:
    2269             :                 case CURLOPT_SSL_ENABLE_ALPN:
    2270             :                 case CURLOPT_SSL_ENABLE_NPN:
    2271             : #endif
    2272             : #if LIBCURL_VERSION_NUM >= 0x072500 /* Available since 7.37.0 */
    2273             :                 case CURLOPT_HEADEROPT:
    2274             : #endif
    2275             : #if LIBCURL_VERSION_NUM >= 0x072900 /* Available since 7.41.0 */
    2276             :                 case CURLOPT_SSL_VERIFYSTATUS:
    2277             : #endif
    2278             : #if LIBCURL_VERSION_NUM >= 0x072a00 /* Available since 7.42.0 */
    2279             :                 case CURLOPT_PATH_AS_IS:
    2280             :                 case CURLOPT_SSL_FALSESTART:
    2281             : #endif
    2282             : #if LIBCURL_VERSION_NUM >= 0x072b00 /* Available since 7.43.0 */
    2283             :                 case CURLOPT_PIPEWAIT:
    2284             : #endif
    2285             : #if LIBCURL_VERSION_NUM >= 0x072e00 /* Available since 7.46.0 */
    2286             :                 case CURLOPT_STREAM_WEIGHT:
    2287             : #endif
    2288             : #if LIBCURL_VERSION_NUM >= 0x073000 /* Available since 7.48.0 */
    2289             :                 case CURLOPT_TFTP_NO_OPTIONS:
    2290             : #endif
    2291             : #if LIBCURL_VERSION_NUM >= 0x073100 /* Available since 7.49.0 */
    2292             :                 case CURLOPT_TCP_FASTOPEN:
    2293             : #endif
    2294             : #if CURLOPT_MUTE != 0
    2295             :                 case CURLOPT_MUTE:
    2296             : #endif
    2297          48 :                         lval = zval_get_long(zvalue);
    2298             : #if LIBCURL_VERSION_NUM >= 0x71304
    2299          54 :                         if ((option == CURLOPT_PROTOCOLS || option == CURLOPT_REDIR_PROTOCOLS) &&
    2300           6 :                                 (PG(open_basedir) && *PG(open_basedir)) && (lval & CURLPROTO_FILE)) {
    2301           2 :                                         php_error_docref(NULL, E_WARNING, "CURLPROTO_FILE cannot be activated when an open_basedir is set");
    2302           2 :                                         return 1;
    2303             :                         }
    2304             : #endif
    2305             : # if defined(ZTS)
    2306             :                         if (option == CURLOPT_DNS_USE_GLOBAL_CACHE) {
    2307             :                                 php_error_docref(NULL, E_WARNING, "CURLOPT_DNS_USE_GLOBAL_CACHE cannot be activated when thread safety is enabled");
    2308             :                                 return 1;
    2309             :                         }
    2310             : # endif
    2311          46 :                         error = curl_easy_setopt(ch->cp, option, lval);
    2312          46 :                         break;
    2313             :                 case CURLOPT_SAFE_UPLOAD:
    2314           3 :                         lval = zval_get_long(zvalue);
    2315           3 :                         if (lval == 0) {
    2316           1 :                                 php_error_docref(NULL, E_WARNING, "Disabling safe uploads is no longer supported");
    2317           1 :                                 return FAILURE;
    2318             :                         }
    2319           2 :                         break;
    2320             : 
    2321             :                 /* String options */
    2322             :                 case CURLOPT_CAINFO:
    2323             :                 case CURLOPT_CAPATH:
    2324             :                 case CURLOPT_COOKIE:
    2325             :                 case CURLOPT_EGDSOCKET:
    2326             :                 case CURLOPT_INTERFACE:
    2327             :                 case CURLOPT_PROXY:
    2328             :                 case CURLOPT_PROXYUSERPWD:
    2329             :                 case CURLOPT_REFERER:
    2330             :                 case CURLOPT_SSLCERTTYPE:
    2331             :                 case CURLOPT_SSLENGINE:
    2332             :                 case CURLOPT_SSLENGINE_DEFAULT:
    2333             :                 case CURLOPT_SSLKEY:
    2334             :                 case CURLOPT_SSLKEYPASSWD:
    2335             :                 case CURLOPT_SSLKEYTYPE:
    2336             :                 case CURLOPT_SSL_CIPHER_LIST:
    2337             :                 case CURLOPT_USERAGENT:
    2338             :                 case CURLOPT_USERPWD:
    2339             : #if LIBCURL_VERSION_NUM >= 0x070e01 /* Available since 7.14.1 */
    2340             :                 case CURLOPT_COOKIELIST:
    2341             : #endif
    2342             : #if LIBCURL_VERSION_NUM >= 0x070f05 /* Available since 7.15.5 */
    2343             :                 case CURLOPT_FTP_ALTERNATIVE_TO_USER:
    2344             : #endif
    2345             : #if LIBCURL_VERSION_NUM >= 0x071101 /* Available since 7.17.1 */
    2346             :                 case CURLOPT_SSH_HOST_PUBLIC_KEY_MD5:
    2347             : #endif
    2348             : #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
    2349             :                 case CURLOPT_PASSWORD:
    2350             :                 case CURLOPT_PROXYPASSWORD:
    2351             :                 case CURLOPT_PROXYUSERNAME:
    2352             :                 case CURLOPT_USERNAME:
    2353             : #endif
    2354             : #if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */
    2355             :                 case CURLOPT_NOPROXY:
    2356             :                 case CURLOPT_SOCKS5_GSSAPI_SERVICE:
    2357             : #endif
    2358             : #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
    2359             :                 case CURLOPT_MAIL_FROM:
    2360             :                 case CURLOPT_RTSP_STREAM_URI:
    2361             :                 case CURLOPT_RTSP_TRANSPORT:
    2362             : #endif
    2363             : #if LIBCURL_VERSION_NUM >= 0x071504 /* Available since 7.21.4 */
    2364             :                 case CURLOPT_TLSAUTH_PASSWORD:
    2365             :                 case CURLOPT_TLSAUTH_USERNAME:
    2366             : #endif
    2367             : #if LIBCURL_VERSION_NUM >= 0x071506 /* Available since 7.21.6 */
    2368             :                 case CURLOPT_ACCEPT_ENCODING:
    2369             :                 case CURLOPT_TRANSFER_ENCODING:
    2370             : #else
    2371             :                 case CURLOPT_ENCODING:
    2372             : #endif
    2373             : #if LIBCURL_VERSION_NUM >= 0x071800 /* Available since 7.24.0 */
    2374             :                 case CURLOPT_DNS_SERVERS:
    2375             : #endif
    2376             : #if LIBCURL_VERSION_NUM >= 0x071900 /* Available since 7.25.0 */
    2377             :                 case CURLOPT_MAIL_AUTH:
    2378             : #endif
    2379             : #if LIBCURL_VERSION_NUM >= 0x072200 /* Available since 7.34.0 */
    2380             :                 case CURLOPT_LOGIN_OPTIONS:
    2381             : #endif
    2382             : #if LIBCURL_VERSION_NUM >= 0x072700 /* Available since 7.39.0 */
    2383             :                 case CURLOPT_PINNEDPUBLICKEY:
    2384             : #endif
    2385             : #if LIBCURL_VERSION_NUM >= 0x072b00 /* Available since 7.43.0 */
    2386             :                 case CURLOPT_PROXY_SERVICE_NAME:
    2387             :                 case CURLOPT_SERVICE_NAME:
    2388             : #endif
    2389             : #if LIBCURL_VERSION_NUM >= 0x072d00 /* Available since 7.45.0 */
    2390             :                 case CURLOPT_DEFAULT_PROTOCOL:
    2391             : #endif
    2392             :                 {
    2393           8 :                         zend_string *str = zval_get_string(zvalue);
    2394           8 :                         int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0);
    2395             :                         zend_string_release(str);
    2396           8 :                         return ret;
    2397             :                 }
    2398             : 
    2399             :                 /* Curl nullable string options */
    2400             :                 case CURLOPT_CUSTOMREQUEST:
    2401             :                 case CURLOPT_FTPPORT:
    2402             :                 case CURLOPT_RANGE:
    2403             : #if LIBCURL_VERSION_NUM >= 0x070d00 /* Available since 7.13.0 */
    2404             :                 case CURLOPT_FTP_ACCOUNT:
    2405             : #endif
    2406             : #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
    2407             :                 case CURLOPT_RTSP_SESSION_ID:
    2408             : #endif
    2409             : #if LIBCURL_VERSION_NUM >= 0x072100 /* Available since 7.33.0 */
    2410             :                 case CURLOPT_DNS_INTERFACE:
    2411             :                 case CURLOPT_DNS_LOCAL_IP4:
    2412             :                 case CURLOPT_DNS_LOCAL_IP6:
    2413             :                 case CURLOPT_XOAUTH2_BEARER:
    2414             : #endif
    2415             : #if LIBCURL_VERSION_NUM >= 0x072800 /* Available since 7.40.0 */
    2416             :                 case CURLOPT_UNIX_SOCKET_PATH:
    2417             : #endif
    2418             : #if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */
    2419             :                 case CURLOPT_KRBLEVEL:
    2420             : #else
    2421             :                 case CURLOPT_KRB4LEVEL:
    2422             : #endif
    2423             :                 {
    2424           2 :                         if (Z_ISNULL_P(zvalue)) {
    2425           1 :                                 error = curl_easy_setopt(ch->cp, option, NULL);
    2426             :                         } else {
    2427           1 :                                 zend_string *str = zval_get_string(zvalue);
    2428           1 :                                 int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0);
    2429             :                                 zend_string_release(str);
    2430           1 :                                 return ret;
    2431             :                         }
    2432           1 :                         break;
    2433             :                 }
    2434             : 
    2435             :                 /* Curl private option */
    2436             :                 case CURLOPT_PRIVATE:
    2437             :                 {
    2438           1 :                         zend_string *str = zval_get_string(zvalue);
    2439           1 :                         int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 1);
    2440             :                         zend_string_release(str);
    2441           1 :                         return ret;
    2442             :                 }
    2443             : 
    2444             :                 /* Curl url option */
    2445             :                 case CURLOPT_URL:
    2446             :                 {
    2447        1102 :                         zend_string *str = zval_get_string(zvalue);
    2448        1102 :                         int ret = php_curl_option_url(ch, ZSTR_VAL(str), ZSTR_LEN(str));
    2449             :                         zend_string_release(str);
    2450        1102 :                         return ret;
    2451             :                 }
    2452             : 
    2453             :                 /* Curl file handle options */
    2454             :                 case CURLOPT_FILE:
    2455             :                 case CURLOPT_INFILE:
    2456             :                 case CURLOPT_STDERR:
    2457             :                 case CURLOPT_WRITEHEADER: {
    2458        1053 :                         FILE *fp = NULL;
    2459        1053 :                         php_stream *what = NULL;
    2460             : 
    2461        1053 :                         if (Z_TYPE_P(zvalue) != IS_NULL) {
    2462        1052 :                                 what = (php_stream *)zend_fetch_resource2_ex(zvalue, "File-Handle", php_file_le_stream(), php_file_le_pstream());
    2463        1052 :                                 if (!what) {
    2464           0 :                                         return FAILURE;
    2465             :                                 }
    2466             : 
    2467        1052 :                                 if (FAILURE == php_stream_cast(what, PHP_STREAM_AS_STDIO, (void *) &fp, REPORT_ERRORS)) {
    2468           0 :                                         return FAILURE;
    2469             :                                 }
    2470             : 
    2471        1052 :                                 if (!fp) {
    2472           0 :                                         return FAILURE;
    2473             :                                 }
    2474             :                         }
    2475             : 
    2476        1053 :                         error = CURLE_OK;
    2477        1053 :                         switch (option) {
    2478             :                                 case CURLOPT_FILE:
    2479        1034 :                                         if (!what) {
    2480           0 :                                                 if (!Z_ISUNDEF(ch->handlers->write->stream)) {
    2481           0 :                                                         zval_ptr_dtor(&ch->handlers->write->stream);
    2482           0 :                                                         ZVAL_UNDEF(&ch->handlers->write->stream);
    2483             :                                                 }
    2484           0 :                                                 ch->handlers->write->fp = NULL;
    2485           0 :                                                 ch->handlers->write->method = PHP_CURL_STDOUT;
    2486        2067 :                                         } else if (what->mode[0] != 'r' || what->mode[1] == '+') {
    2487        1033 :                                                 zval_ptr_dtor(&ch->handlers->write->stream);
    2488        1033 :                                                 ch->handlers->write->fp = fp;
    2489        1033 :                                                 ch->handlers->write->method = PHP_CURL_FILE;
    2490        1033 :                                                 ZVAL_COPY(&ch->handlers->write->stream, zvalue);
    2491             :                                         } else {
    2492           1 :                                                 php_error_docref(NULL, E_WARNING, "the provided file handle is not writable");
    2493           1 :                                                 return FAILURE;
    2494             :                                         }
    2495        1033 :                                         break;
    2496             :                                 case CURLOPT_WRITEHEADER:
    2497           3 :                                         if (!what) {
    2498           0 :                                                 if (!Z_ISUNDEF(ch->handlers->write_header->stream)) {
    2499           0 :                                                         zval_ptr_dtor(&ch->handlers->write_header->stream);
    2500           0 :                                                         ZVAL_UNDEF(&ch->handlers->write_header->stream);
    2501             :                                                 }
    2502           0 :                                                 ch->handlers->write_header->fp = NULL;
    2503           0 :                                                 ch->handlers->write_header->method = PHP_CURL_IGNORE;
    2504           6 :                                         } else if (what->mode[0] != 'r' || what->mode[1] == '+') {
    2505           3 :                                                 zval_ptr_dtor(&ch->handlers->write_header->stream);
    2506           3 :                                                 ch->handlers->write_header->fp = fp;
    2507           3 :                                                 ch->handlers->write_header->method = PHP_CURL_FILE;
    2508           3 :                                                 ZVAL_COPY(&ch->handlers->write_header->stream, zvalue);;
    2509             :                                         } else {
    2510           0 :                                                 php_error_docref(NULL, E_WARNING, "the provided file handle is not writable");
    2511           0 :                                                 return FAILURE;
    2512             :                                         }
    2513           3 :                                         break;
    2514             :                                 case CURLOPT_INFILE:
    2515           8 :                                         if (!what) {
    2516           2 :                                                 if (!Z_ISUNDEF(ch->handlers->read->stream)) {
    2517           1 :                                                         zval_ptr_dtor(&ch->handlers->read->stream);
    2518           1 :                                                         ZVAL_UNDEF(&ch->handlers->read->stream);
    2519             :                                                 }
    2520           1 :                                                 ch->handlers->read->fp = NULL;
    2521           1 :                                                 ch->handlers->read->res = NULL;
    2522             :                                         } else {
    2523           7 :                                                 zval_ptr_dtor(&ch->handlers->read->stream);
    2524           7 :                                                 ch->handlers->read->fp = fp;
    2525           7 :                                                 ch->handlers->read->res = Z_RES_P(zvalue);
    2526           7 :                                                 ZVAL_COPY(&ch->handlers->read->stream, zvalue);
    2527             :                                         }
    2528           8 :                                         break;
    2529             :                                 case CURLOPT_STDERR:
    2530           8 :                                         if (!what) {
    2531           0 :                                                 if (!Z_ISUNDEF(ch->handlers->std_err)) {
    2532           0 :                                                         zval_ptr_dtor(&ch->handlers->std_err);
    2533           0 :                                                         ZVAL_UNDEF(&ch->handlers->std_err);
    2534             :                                                 }
    2535          16 :                                         } else if (what->mode[0] != 'r' || what->mode[1] == '+') {
    2536           8 :                                                 zval_ptr_dtor(&ch->handlers->std_err);
    2537           8 :                                                 ZVAL_COPY(&ch->handlers->std_err, zvalue);
    2538             :                                         } else {
    2539           0 :                                                 php_error_docref(NULL, E_WARNING, "the provided file handle is not writable");
    2540           0 :                                                 return FAILURE;
    2541             :                                         }
    2542             :                                         /* break omitted intentionally */
    2543             :                                 default:
    2544           8 :                                         error = curl_easy_setopt(ch->cp, option, fp);
    2545             :                                         break;
    2546             :                         }
    2547        1052 :                         break;
    2548             :                 }
    2549             : 
    2550             :                 /* Curl linked list options */
    2551             :                 case CURLOPT_HTTP200ALIASES:
    2552             :                 case CURLOPT_HTTPHEADER:
    2553             :                 case CURLOPT_POSTQUOTE:
    2554             :                 case CURLOPT_PREQUOTE:
    2555             :                 case CURLOPT_QUOTE:
    2556             :                 case CURLOPT_TELNETOPTIONS:
    2557             : #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
    2558             :                 case CURLOPT_MAIL_RCPT:
    2559             : #endif
    2560             : #if LIBCURL_VERSION_NUM >= 0x071503 /* Available since 7.21.3 */
    2561             :                 case CURLOPT_RESOLVE:
    2562             : #endif
    2563             : #if LIBCURL_VERSION_NUM >= 0x072500 /* Available since 7.37.0 */
    2564             :                 case CURLOPT_PROXYHEADER:
    2565             : #endif
    2566             : #if LIBCURL_VERSION_NUM >= 0x073100 /* Available since 7.49.0 */
    2567             :                 case CURLOPT_CONNECT_TO:
    2568             : #endif
    2569             :                 {
    2570             :                         zval *current;
    2571             :                         HashTable *ph;
    2572             :                         zend_string *val;
    2573       10008 :                         struct curl_slist *slist = NULL;
    2574             : 
    2575       10009 :                         ph = HASH_OF(zvalue);
    2576       10008 :                         if (!ph) {
    2577           1 :                                 char *name = NULL;
    2578           1 :                                 switch (option) {
    2579             :                                         case CURLOPT_HTTPHEADER:
    2580           1 :                                                 name = "CURLOPT_HTTPHEADER";
    2581           1 :                                                 break;
    2582             :                                         case CURLOPT_QUOTE:
    2583           0 :                                                 name = "CURLOPT_QUOTE";
    2584           0 :                                                 break;
    2585             :                                         case CURLOPT_HTTP200ALIASES:
    2586           0 :                                                 name = "CURLOPT_HTTP200ALIASES";
    2587           0 :                                                 break;
    2588             :                                         case CURLOPT_POSTQUOTE:
    2589           0 :                                                 name = "CURLOPT_POSTQUOTE";
    2590           0 :                                                 break;
    2591             :                                         case CURLOPT_PREQUOTE:
    2592           0 :                                                 name = "CURLOPT_PREQUOTE";
    2593           0 :                                                 break;
    2594             :                                         case CURLOPT_TELNETOPTIONS:
    2595           0 :                                                 name = "CURLOPT_TELNETOPTIONS";
    2596             :                                                 break;
    2597             : #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
    2598             :                                         case CURLOPT_MAIL_RCPT:
    2599             :                                                 name = "CURLOPT_MAIL_RCPT";
    2600             :                                                 break;
    2601             : #endif
    2602             : #if LIBCURL_VERSION_NUM >= 0x071503 /* Available since 7.21.3 */
    2603             :                                         case CURLOPT_RESOLVE:
    2604             :                                                 name = "CURLOPT_RESOLVE";
    2605             :                                                 break;
    2606             : #endif
    2607             : #if LIBCURL_VERSION_NUM >= 0x072500 /* Available since 7.37.0 */
    2608             :                                         case CURLOPT_PROXYHEADER:
    2609             :                                                 name = "CURLOPT_PROXYHEADER";
    2610             :                                                 break;
    2611             : #endif
    2612             : #if LIBCURL_VERSION_NUM >= 0x073100 /* Available since 7.49.0 */
    2613             :                                         case CURLOPT_CONNECT_TO:
    2614             :                                                 name = "CURLOPT_CONNECT_TO";
    2615             :                                                 break;
    2616             : #endif
    2617             :                                 }
    2618           1 :                                 php_error_docref(NULL, E_WARNING, "You must pass either an object or an array with the %s argument", name);
    2619           1 :                                 return FAILURE;
    2620             :                         }
    2621             : 
    2622       30025 :                         ZEND_HASH_FOREACH_VAL(ph, current) {
    2623       10009 :                                 ZVAL_DEREF(current);
    2624       10009 :                                 val = zval_get_string(current);
    2625       10009 :                                 slist = curl_slist_append(slist, ZSTR_VAL(val));
    2626             :                                 zend_string_release(val);
    2627       10009 :                                 if (!slist) {
    2628           0 :                                         php_error_docref(NULL, E_WARNING, "Could not build curl_slist");
    2629           0 :                                         return 1;
    2630             :                                 }
    2631             :                         } ZEND_HASH_FOREACH_END();
    2632             : 
    2633       10007 :                         if (slist) {
    2634       10006 :                                 if ((*ch->clone) == 1) {
    2635       10004 :                                         zend_hash_index_update_ptr(ch->to_free->slist, option, slist);
    2636             :                                 } else {
    2637           2 :                                         zend_hash_next_index_insert_ptr(ch->to_free->slist, slist);
    2638             :                                 }
    2639             :                         }
    2640             : 
    2641       10007 :                         error = curl_easy_setopt(ch->cp, option, slist);
    2642             : 
    2643       10007 :                         break;
    2644             :                 }
    2645             : 
    2646             :                 case CURLOPT_BINARYTRANSFER:
    2647             :                         /* Do nothing, just backward compatibility */
    2648           1 :                         break;
    2649             : 
    2650             :                 case CURLOPT_FOLLOWLOCATION:
    2651           2 :                         lval = zval_get_long(zvalue);
    2652             : #if LIBCURL_VERSION_NUM < 0x071304
    2653             :                         if (PG(open_basedir) && *PG(open_basedir)) {
    2654             :                                 if (lval != 0) {
    2655             :                                         php_error_docref(NULL, E_WARNING, "CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set");
    2656             :                                         return FAILURE;
    2657             :                                 }
    2658             :                         }
    2659             : #endif
    2660           2 :                         error = curl_easy_setopt(ch->cp, option, lval);
    2661           2 :                         break;
    2662             : 
    2663             :                 case CURLOPT_HEADERFUNCTION:
    2664           6 :                         if (!Z_ISUNDEF(ch->handlers->write_header->func_name)) {
    2665           0 :                                 zval_ptr_dtor(&ch->handlers->write_header->func_name);
    2666           0 :                                 ch->handlers->write_header->fci_cache = empty_fcall_info_cache;
    2667             :                         }
    2668           3 :                         ZVAL_COPY(&ch->handlers->write_header->func_name, zvalue);
    2669           3 :                         ch->handlers->write_header->method = PHP_CURL_USER;
    2670           3 :                         break;
    2671             : 
    2672             :                 case CURLOPT_POSTFIELDS:
    2673          36 :                         if (Z_TYPE_P(zvalue) == IS_ARRAY || Z_TYPE_P(zvalue) == IS_OBJECT) {
    2674             :                                 zval *current;
    2675             :                                 HashTable *postfields;
    2676             :                                 zend_string *string_key;
    2677             :                                 zend_ulong  num_key;
    2678          15 :                                 struct HttpPost *first = NULL;
    2679          15 :                                 struct HttpPost *last  = NULL;
    2680             :                                 CURLFORMcode form_error;
    2681             : 
    2682          15 :                                 postfields = HASH_OF(zvalue);
    2683          15 :                                 if (!postfields) {
    2684           0 :                                         php_error_docref(NULL, E_WARNING, "Couldn't get HashTable in CURLOPT_POSTFIELDS");
    2685           0 :                                         return FAILURE;
    2686             :                                 }
    2687             : 
    2688          53 :                                 ZEND_HASH_FOREACH_KEY_VAL(postfields, num_key, string_key, current) {
    2689             :                                         zend_string *postval;
    2690             :                                         /* Pretend we have a string_key here */
    2691          19 :                                         if (!string_key) {
    2692           1 :                                                 string_key = zend_long_to_str(num_key);
    2693             :                                         } else {
    2694             :                                                 zend_string_addref(string_key);
    2695             :                                         }
    2696             : 
    2697          19 :                                         ZVAL_DEREF(current);
    2698          29 :                                         if (Z_TYPE_P(current) == IS_OBJECT &&
    2699          10 :                                                         instanceof_function(Z_OBJCE_P(current), curl_CURLFile_class)) {
    2700             :                                                 /* new-style file upload */
    2701             :                                                 zval *prop, rv;
    2702          10 :                                                 char *type = NULL, *filename = NULL;
    2703             : 
    2704          10 :                                                 prop = zend_read_property(curl_CURLFile_class, current, "name", sizeof("name")-1, 0, &rv);
    2705          10 :                                                 if (Z_TYPE_P(prop) != IS_STRING) {
    2706           0 :                                                         php_error_docref(NULL, E_WARNING, "Invalid filename for key %s", ZSTR_VAL(string_key));
    2707             :                                                 } else {
    2708          10 :                                                         postval = Z_STR_P(prop);
    2709             : 
    2710          10 :                                                         if (php_check_open_basedir(ZSTR_VAL(postval))) {
    2711           0 :                                                                 return 1;
    2712             :                                                         }
    2713             : 
    2714          10 :                                                         prop = zend_read_property(curl_CURLFile_class, current, "mime", sizeof("mime")-1, 0, &rv);
    2715          10 :                                                         if (Z_TYPE_P(prop) == IS_STRING && Z_STRLEN_P(prop) > 0) {
    2716           5 :                                                                 type = Z_STRVAL_P(prop);
    2717             :                                                         }
    2718          10 :                                                         prop = zend_read_property(curl_CURLFile_class, current, "postname", sizeof("postname")-1, 0, &rv);
    2719          10 :                                                         if (Z_TYPE_P(prop) == IS_STRING && Z_STRLEN_P(prop) > 0) {
    2720           5 :                                                                 filename = Z_STRVAL_P(prop);
    2721             :                                                         }
    2722          10 :                                                         form_error = curl_formadd(&first, &last,
    2723             :                                                                                         CURLFORM_COPYNAME, ZSTR_VAL(string_key),
    2724             :                                                                                         CURLFORM_NAMELENGTH, ZSTR_LEN(string_key),
    2725             :                                                                                         CURLFORM_FILENAME, filename ? filename : ZSTR_VAL(postval),
    2726             :                                                                                         CURLFORM_CONTENTTYPE, type ? type : "application/octet-stream",
    2727             :                                                                                         CURLFORM_FILE, ZSTR_VAL(postval),
    2728             :                                                                                         CURLFORM_END);
    2729          10 :                                                         if (form_error != CURL_FORMADD_OK) {
    2730             :                                                                 /* Not nice to convert between enums but we only have place for one error type */
    2731           0 :                                                                 error = (CURLcode)form_error;
    2732             :                                                         }
    2733             :                                                 }
    2734             : 
    2735             :                                                 zend_string_release(string_key);
    2736          10 :                                                 continue;
    2737             :                                         }
    2738             : 
    2739           9 :                                         postval = zval_get_string(current);
    2740             : 
    2741             :                                         /* The arguments after _NAMELENGTH and _CONTENTSLENGTH
    2742             :                                          * must be explicitly cast to long in curl_formadd
    2743             :                                          * use since curl needs a long not an int. */
    2744           9 :                                         form_error = curl_formadd(&first, &last,
    2745             :                                                                                  CURLFORM_COPYNAME, ZSTR_VAL(string_key),
    2746             :                                                                                  CURLFORM_NAMELENGTH, ZSTR_LEN(string_key),
    2747             :                                                                                  CURLFORM_COPYCONTENTS, ZSTR_VAL(postval),
    2748             :                                                                                  CURLFORM_CONTENTSLENGTH, ZSTR_LEN(postval),
    2749             :                                                                                  CURLFORM_END);
    2750             : 
    2751           9 :                                         if (form_error != CURL_FORMADD_OK) {
    2752             :                                                 /* Not nice to convert between enums but we only have place for one error type */
    2753           0 :                                                 error = (CURLcode)form_error;
    2754             :                                         }
    2755             :                                         zend_string_release(postval);
    2756             :                                         zend_string_release(string_key);
    2757             :                                 } ZEND_HASH_FOREACH_END();
    2758             : 
    2759          15 :                                 SAVE_CURL_ERROR(ch, error);
    2760          15 :                                 if (error != CURLE_OK) {
    2761           0 :                                         return FAILURE;
    2762             :                                 }
    2763             : 
    2764          15 :                                 if ((*ch->clone) == 1) {
    2765          15 :                                         zend_llist_clean(&ch->to_free->post);
    2766             :                                 }
    2767          15 :                                 zend_llist_add_element(&ch->to_free->post, &first);
    2768          15 :                                 error = curl_easy_setopt(ch->cp, CURLOPT_HTTPPOST, first);
    2769             :                         } else {
    2770             : #if LIBCURL_VERSION_NUM >= 0x071101
    2771           3 :                                 zend_string *str = zval_get_string(zvalue);
    2772             :                                 /* with curl 7.17.0 and later, we can use COPYPOSTFIELDS, but we have to provide size before */
    2773           3 :                                 error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, ZSTR_LEN(str));
    2774           3 :                                 error = curl_easy_setopt(ch->cp, CURLOPT_COPYPOSTFIELDS, ZSTR_VAL(str));
    2775             :                                 zend_string_release(str);
    2776             : #else
    2777             :                                 char *post = NULL;
    2778             :                                 zend_string *str = zval_get_string(zvalue);
    2779             : 
    2780             :                                 post = estrndup(ZSTR_VAL(str), ZSTR_LEN(str));
    2781             :                                 zend_llist_add_element(&ch->to_free->str, &post);
    2782             : 
    2783             :                                 curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, post);
    2784             :                                 error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, ZSTR_LEN(str));
    2785             :                                 zend_string_release(str);
    2786             : #endif
    2787             :                         }
    2788          18 :                         break;
    2789             : 
    2790             :                 case CURLOPT_PROGRESSFUNCTION:
    2791           1 :                         curl_easy_setopt(ch->cp, CURLOPT_PROGRESSFUNCTION,   curl_progress);
    2792           1 :                         curl_easy_setopt(ch->cp, CURLOPT_PROGRESSDATA, ch);
    2793           1 :                         if (ch->handlers->progress == NULL) {
    2794           1 :                                 ch->handlers->progress = ecalloc(1, sizeof(php_curl_progress));
    2795           0 :                         } else if (!Z_ISUNDEF(ch->handlers->progress->func_name)) {
    2796           0 :                                 zval_ptr_dtor(&ch->handlers->progress->func_name);
    2797           0 :                                 ch->handlers->progress->fci_cache = empty_fcall_info_cache;
    2798             :                         }
    2799           1 :                         ZVAL_COPY(&ch->handlers->progress->func_name, zvalue);
    2800           1 :                         ch->handlers->progress->method = PHP_CURL_USER;
    2801           1 :                         break;
    2802             : 
    2803             :                 case CURLOPT_READFUNCTION:
    2804           6 :                         if (!Z_ISUNDEF(ch->handlers->read->func_name)) {
    2805           0 :                                 zval_ptr_dtor(&ch->handlers->read->func_name);
    2806           0 :                                 ch->handlers->read->fci_cache = empty_fcall_info_cache;
    2807             :                         }
    2808           3 :                         ZVAL_COPY(&ch->handlers->read->func_name, zvalue);
    2809           3 :                         ch->handlers->read->method = PHP_CURL_USER;
    2810           3 :                         break;
    2811             : 
    2812             :                 case CURLOPT_RETURNTRANSFER:
    2813          57 :                         lval = zval_get_long(zvalue);
    2814          57 :                         if (lval) {
    2815          55 :                                 ch->handlers->write->method = PHP_CURL_RETURN;
    2816             :                         } else {
    2817           2 :                                 ch->handlers->write->method = PHP_CURL_STDOUT;
    2818             :                         }
    2819          57 :                         break;
    2820             : 
    2821             :                 case CURLOPT_WRITEFUNCTION:
    2822           6 :                         if (!Z_ISUNDEF(ch->handlers->write->func_name)) {
    2823           0 :                                 zval_ptr_dtor(&ch->handlers->write->func_name);
    2824           0 :                                 ch->handlers->write->fci_cache = empty_fcall_info_cache;
    2825             :                         }
    2826           3 :                         ZVAL_COPY(&ch->handlers->write->func_name, zvalue);
    2827           3 :                         ch->handlers->write->method = PHP_CURL_USER;
    2828           3 :                         break;
    2829             : 
    2830             : #if LIBCURL_VERSION_NUM >= 0x070f05 /* Available since 7.15.5 */
    2831             :                 case CURLOPT_MAX_RECV_SPEED_LARGE:
    2832             :                 case CURLOPT_MAX_SEND_SPEED_LARGE:
    2833           0 :                         lval = zval_get_long(zvalue);
    2834           0 :                         error = curl_easy_setopt(ch->cp, option, (curl_off_t)lval);
    2835           0 :                         break;
    2836             : #endif
    2837             : 
    2838             : #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
    2839             :                 case CURLOPT_POSTREDIR:
    2840           0 :                         lval = zval_get_long(zvalue);
    2841           0 :                         error = curl_easy_setopt(ch->cp, CURLOPT_POSTREDIR, lval & CURL_REDIR_POST_ALL);
    2842           0 :                         break;
    2843             : #endif
    2844             : 
    2845             : #if CURLOPT_PASSWDFUNCTION != 0
    2846             :                 case CURLOPT_PASSWDFUNCTION:
    2847             :                         zval_ptr_dtor(&ch->handlers->passwd);
    2848             :                         ZVAL_COPY(&ch->handlers->passwd, zvalue);
    2849             :                         error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDFUNCTION, curl_passwd);
    2850             :                         error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDDATA,     (void *) ch);
    2851             :                         break;
    2852             : #endif
    2853             : 
    2854             :                 /* the following options deal with files, therefore the open_basedir check
    2855             :                  * is required.
    2856             :                  */
    2857             :                 case CURLOPT_COOKIEFILE:
    2858             :                 case CURLOPT_COOKIEJAR:
    2859             :                 case CURLOPT_RANDOM_FILE:
    2860             :                 case CURLOPT_SSLCERT:
    2861             : #if LIBCURL_VERSION_NUM >= 0x070b00 /* Available since 7.11.0 */
    2862             :                 case CURLOPT_NETRC_FILE:
    2863             : #endif
    2864             : #if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */
    2865             :                 case CURLOPT_SSH_PRIVATE_KEYFILE:
    2866             :                 case CURLOPT_SSH_PUBLIC_KEYFILE:
    2867             : #endif
    2868             : #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
    2869             :                 case CURLOPT_CRLFILE:
    2870             :                 case CURLOPT_ISSUERCERT:
    2871             : #endif
    2872             : #if LIBCURL_VERSION_NUM >= 0x071306 /* Available since 7.19.6 */
    2873             :                 case CURLOPT_SSH_KNOWNHOSTS:
    2874             : #endif
    2875             :                 {
    2876           3 :                         zend_string *str = zval_get_string(zvalue);
    2877             :                         int ret;
    2878             : 
    2879           3 :                         if (ZSTR_LEN(str) && php_check_open_basedir(ZSTR_VAL(str))) {
    2880             :                                 zend_string_release(str);
    2881           1 :                                 return FAILURE;
    2882             :                         }
    2883             : 
    2884           2 :                         ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0);
    2885             :                         zend_string_release(str);
    2886           2 :                         return ret;
    2887             :                 }
    2888             : 
    2889             :                 case CURLINFO_HEADER_OUT:
    2890           0 :                         lval = zval_get_long(zvalue);
    2891           0 :                         if (lval == 1) {
    2892           0 :                                 curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, curl_debug);
    2893           0 :                                 curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, (void *)ch);
    2894           0 :                                 curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 1);
    2895             :                         } else {
    2896           0 :                                 curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, NULL);
    2897           0 :                                 curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, NULL);
    2898           0 :                                 curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0);
    2899             :                         }
    2900           0 :                         break;
    2901             : 
    2902             :                 case CURLOPT_SHARE:
    2903             :                         {
    2904             :                                 php_curlsh *sh;
    2905           0 :                                 if ((sh = (php_curlsh *)zend_fetch_resource_ex(zvalue, le_curl_share_handle_name, le_curl_share_handle))) {
    2906           0 :                                         curl_easy_setopt(ch->cp, CURLOPT_SHARE, sh->share);
    2907             :                                 }
    2908             :                         }
    2909             :                         break;
    2910             : 
    2911             : #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
    2912             :                 case CURLOPT_FNMATCH_FUNCTION:
    2913             :                         curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_FUNCTION, curl_fnmatch);
    2914             :                         curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_DATA, ch);
    2915             :                         if (ch->handlers->fnmatch == NULL) {
    2916             :                                 ch->handlers->fnmatch = ecalloc(1, sizeof(php_curl_fnmatch));
    2917             :                         } else if (!Z_ISUNDEF(ch->handlers->fnmatch->func_name)) {
    2918             :                                 zval_ptr_dtor(&ch->handlers->fnmatch->func_name);
    2919             :                                 ch->handlers->fnmatch->fci_cache = empty_fcall_info_cache;
    2920             :                         }
    2921             :                         ZVAL_COPY(&ch->handlers->fnmatch->func_name, zvalue);
    2922             :                         ch->handlers->fnmatch->method = PHP_CURL_USER;
    2923             :                         break;
    2924             : #endif
    2925             : 
    2926             :         }
    2927             : 
    2928       11198 :         SAVE_CURL_ERROR(ch, error);
    2929       11198 :         if (error != CURLE_OK) {
    2930           0 :                 return FAILURE;
    2931             :         } else {
    2932       11198 :                 return SUCCESS;
    2933             :         }
    2934             : }
    2935             : /* }}} */
    2936             : 
    2937             : /* {{{ proto bool curl_setopt(resource ch, int option, mixed value)
    2938             :    Set an option for a cURL transfer */
    2939       12267 : PHP_FUNCTION(curl_setopt)
    2940             : {
    2941             :         zval       *zid, *zvalue;
    2942             :         zend_long        options;
    2943             :         php_curl   *ch;
    2944             : 
    2945       12267 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &zid, &options, &zvalue) == FAILURE) {
    2946          10 :                 return;
    2947             :         }
    2948             : 
    2949       12257 :         if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
    2950           0 :                 RETURN_FALSE;
    2951             :         }
    2952             : 
    2953       12257 :         if (options <= 0 && options != CURLOPT_SAFE_UPLOAD) {
    2954           1 :                 php_error_docref(NULL, E_WARNING, "Invalid curl configuration option");
    2955           1 :                 RETURN_FALSE;
    2956             :         }
    2957             : 
    2958       12256 :         if (_php_curl_setopt(ch, options, zvalue) == SUCCESS) {
    2959       12249 :                 RETURN_TRUE;
    2960             :         } else {
    2961           7 :                 RETURN_FALSE;
    2962             :         }
    2963             : }
    2964             : /* }}} */
    2965             : 
    2966             : /* {{{ proto bool curl_setopt_array(resource ch, array options)
    2967             :    Set an array of option for a cURL transfer */
    2968          16 : PHP_FUNCTION(curl_setopt_array)
    2969             : {
    2970             :         zval            *zid, *arr, *entry;
    2971             :         php_curl        *ch;
    2972             :         zend_ulong      option;
    2973             :         zend_string     *string_key;
    2974             : 
    2975          16 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "ra", &zid, &arr) == FAILURE) {
    2976           0 :                 return;
    2977             :         }
    2978             : 
    2979          16 :         if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
    2980           0 :                 RETURN_FALSE;
    2981             :         }
    2982             : 
    2983         140 :         ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arr), option, string_key, entry) {
    2984          62 :                 if (string_key) {
    2985           0 :                         php_error_docref(NULL, E_WARNING,
    2986             :                                         "Array keys must be CURLOPT constants or equivalent integer values");
    2987           0 :                         RETURN_FALSE;
    2988             :                 }
    2989          62 :                 if (_php_curl_setopt(ch, (zend_long) option, entry) == FAILURE) {
    2990           0 :                         RETURN_FALSE;
    2991             :                 }
    2992             :         } ZEND_HASH_FOREACH_END();
    2993             : 
    2994          16 :         RETURN_TRUE;
    2995             : }
    2996             : /* }}} */
    2997             : 
    2998             : /* {{{ _php_curl_cleanup_handle(ch)
    2999             :    Cleanup an execution phase */
    3000        1128 : void _php_curl_cleanup_handle(php_curl *ch)
    3001             : {
    3002        1128 :         smart_str_free(&ch->handlers->write->buf);
    3003        1128 :         if (ch->header.str) {
    3004           0 :                 zend_string_release(ch->header.str);
    3005           0 :                 ch->header.str = NULL;
    3006             :         }
    3007             : 
    3008        1128 :         memset(ch->err.str, 0, CURL_ERROR_SIZE + 1);
    3009        1128 :         ch->err.no = 0;
    3010        1128 : }
    3011             : /* }}} */
    3012             : 
    3013             : /* {{{ proto bool curl_exec(resource ch)
    3014             :    Perform a cURL session */
    3015        1098 : PHP_FUNCTION(curl_exec)
    3016             : {
    3017             :         CURLcode        error;
    3018             :         zval            *zid;
    3019             :         php_curl        *ch;
    3020             : 
    3021        1098 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zid) == FAILURE) {
    3022           0 :                 return;
    3023             :         }
    3024             : 
    3025        1098 :         if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
    3026           0 :                 RETURN_FALSE;
    3027             :         }
    3028             : 
    3029        1098 :         _php_curl_verify_handlers(ch, 1);
    3030             : 
    3031        1098 :         _php_curl_cleanup_handle(ch);
    3032             : 
    3033        1098 :         error = curl_easy_perform(ch->cp);
    3034        1096 :         SAVE_CURL_ERROR(ch, error);
    3035             :         /* CURLE_PARTIAL_FILE is returned by HEAD requests */
    3036        1096 :         if (error != CURLE_OK && error != CURLE_PARTIAL_FILE) {
    3037        1034 :                 smart_str_free(&ch->handlers->write->buf);
    3038        1034 :                 RETURN_FALSE;
    3039             :         }
    3040             : 
    3041         124 :         if (!Z_ISUNDEF(ch->handlers->std_err)) {
    3042             :                 php_stream  *stream;
    3043           2 :                 stream = (php_stream*)zend_fetch_resource2_ex(&ch->handlers->std_err, NULL, php_file_le_stream(), php_file_le_pstream());
    3044           2 :                 if (stream) {
    3045           2 :                         php_stream_flush(stream);
    3046             :                 }
    3047             :         }
    3048             : 
    3049          62 :         if (ch->handlers->write->method == PHP_CURL_RETURN && ch->handlers->write->buf.s) {
    3050          43 :                 smart_str_0(&ch->handlers->write->buf);
    3051          43 :                 RETURN_STR_COPY(ch->handlers->write->buf.s);
    3052             :         }
    3053             : 
    3054             :         /* flush the file handle, so any remaining data is synched to disk */
    3055          19 :         if (ch->handlers->write->method == PHP_CURL_FILE && ch->handlers->write->fp) {
    3056           3 :                 fflush(ch->handlers->write->fp);
    3057             :         }
    3058          19 :         if (ch->handlers->write_header->method == PHP_CURL_FILE && ch->handlers->write_header->fp) {
    3059           0 :                 fflush(ch->handlers->write_header->fp);
    3060             :         }
    3061             : 
    3062          19 :         if (ch->handlers->write->method == PHP_CURL_RETURN) {
    3063           2 :                 RETURN_EMPTY_STRING();
    3064             :         } else {
    3065          17 :                 RETURN_TRUE;
    3066             :         }
    3067             : }
    3068             : /* }}} */
    3069             : 
    3070             : /* {{{ proto mixed curl_getinfo(resource ch [, int option])
    3071             :    Get information regarding a specific transfer */
    3072          22 : PHP_FUNCTION(curl_getinfo)
    3073             : {
    3074             :         zval            *zid;
    3075             :         php_curl        *ch;
    3076          22 :         zend_long       option = 0;
    3077             : 
    3078          22 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &zid, &option) == FAILURE) {
    3079           0 :                 return;
    3080             :         }
    3081             : 
    3082          22 :         if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
    3083           0 :                 RETURN_FALSE;
    3084             :         }
    3085             : 
    3086          22 :         if (ZEND_NUM_ARGS() < 2) {
    3087             :                 char *s_code;
    3088             :                 /* libcurl expects long datatype. So far no cases are known where
    3089             :                    it would be an issue. Using zend_long would truncate a 64-bit
    3090             :                    var on Win64, so the exact long datatype fits everywhere, as
    3091             :                    long as there's no 32-bit int overflow. */
    3092             :                 long l_code;
    3093             :                 double d_code;
    3094             : #if LIBCURL_VERSION_NUM >  0x071301
    3095          13 :                 struct curl_certinfo *ci = NULL;
    3096             :                 zval listcode;
    3097             : #endif
    3098             : 
    3099          13 :                 array_init(return_value);
    3100             : 
    3101          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_EFFECTIVE_URL, &s_code) == CURLE_OK) {
    3102          13 :                         CAAS("url", s_code);
    3103             :                 }
    3104          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_TYPE, &s_code) == CURLE_OK) {
    3105          13 :                         if (s_code != NULL) {
    3106           0 :                                 CAAS("content_type", s_code);
    3107             :                         } else {
    3108             :                                 zval retnull;
    3109          13 :                                 ZVAL_NULL(&retnull);
    3110          13 :                                 CAAZ("content_type", &retnull);
    3111             :                         }
    3112             :                 }
    3113          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_HTTP_CODE, &l_code) == CURLE_OK) {
    3114          13 :                         CAAL("http_code", l_code);
    3115             :                 }
    3116          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_HEADER_SIZE, &l_code) == CURLE_OK) {
    3117          13 :                         CAAL("header_size", l_code);
    3118             :                 }
    3119          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_REQUEST_SIZE, &l_code) == CURLE_OK) {
    3120          13 :                         CAAL("request_size", l_code);
    3121             :                 }
    3122          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_FILETIME, &l_code) == CURLE_OK) {
    3123          13 :                         CAAL("filetime", l_code);
    3124             :                 }
    3125          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SSL_VERIFYRESULT, &l_code) == CURLE_OK) {
    3126          13 :                         CAAL("ssl_verify_result", l_code);
    3127             :                 }
    3128          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_COUNT, &l_code) == CURLE_OK) {
    3129          13 :                         CAAL("redirect_count", l_code);
    3130             :                 }
    3131          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME, &d_code) == CURLE_OK) {
    3132          13 :                         CAAD("total_time", d_code);
    3133             :                 }
    3134          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_NAMELOOKUP_TIME, &d_code) == CURLE_OK) {
    3135          13 :                         CAAD("namelookup_time", d_code);
    3136             :                 }
    3137          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CONNECT_TIME, &d_code) == CURLE_OK) {
    3138          13 :                         CAAD("connect_time", d_code);
    3139             :                 }
    3140          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_PRETRANSFER_TIME, &d_code) == CURLE_OK) {
    3141          13 :                         CAAD("pretransfer_time", d_code);
    3142             :                 }
    3143          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_UPLOAD, &d_code) == CURLE_OK) {
    3144          13 :                         CAAD("size_upload", d_code);
    3145             :                 }
    3146          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_DOWNLOAD, &d_code) == CURLE_OK) {
    3147          13 :                         CAAD("size_download", d_code);
    3148             :                 }
    3149          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_DOWNLOAD, &d_code) == CURLE_OK) {
    3150          13 :                         CAAD("speed_download", d_code);
    3151             :                 }
    3152          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_UPLOAD, &d_code) == CURLE_OK) {
    3153          13 :                         CAAD("speed_upload", d_code);
    3154             :                 }
    3155          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d_code) == CURLE_OK) {
    3156          13 :                         CAAD("download_content_length", d_code);
    3157             :                 }
    3158          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_UPLOAD, &d_code) == CURLE_OK) {
    3159          13 :                         CAAD("upload_content_length", d_code);
    3160             :                 }
    3161          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_STARTTRANSFER_TIME, &d_code) == CURLE_OK) {
    3162          13 :                         CAAD("starttransfer_time", d_code);
    3163             :                 }
    3164          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME, &d_code) == CURLE_OK) {
    3165          13 :                         CAAD("redirect_time", d_code);
    3166             :                 }
    3167             : #if LIBCURL_VERSION_NUM >= 0x071202 /* Available since 7.18.2 */
    3168          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_URL, &s_code) == CURLE_OK) {
    3169          13 :                         CAAS("redirect_url", s_code);
    3170             :                 }
    3171             : #endif
    3172             : #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
    3173          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_PRIMARY_IP, &s_code) == CURLE_OK) {
    3174          13 :                         CAAS("primary_ip", s_code);
    3175             :                 }
    3176             : #endif
    3177             : #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
    3178          13 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
    3179          13 :                         array_init(&listcode);
    3180          13 :                         create_certinfo(ci, &listcode);
    3181          13 :                         CAAZ("certinfo", &listcode);
    3182             :                 }
    3183             : #endif
    3184             : #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
    3185             :                 if (curl_easy_getinfo(ch->cp, CURLINFO_PRIMARY_PORT, &l_code) == CURLE_OK) {
    3186             :                         CAAL("primary_port", l_code);
    3187             :                 }
    3188             :                 if (curl_easy_getinfo(ch->cp, CURLINFO_LOCAL_IP, &s_code) == CURLE_OK) {
    3189             :                         CAAS("local_ip", s_code);
    3190             :                 }
    3191             :                 if (curl_easy_getinfo(ch->cp, CURLINFO_LOCAL_PORT, &l_code) == CURLE_OK) {
    3192             :                         CAAL("local_port", l_code);
    3193             :                 }
    3194             : #endif
    3195          13 :                 if (ch->header.str) {
    3196           0 :                         CAASTR("request_header", ch->header.str);
    3197             :                 }
    3198             :         } else {
    3199           9 :                 switch (option) {
    3200             :                         case CURLINFO_HEADER_OUT:
    3201           0 :                                 if (ch->header.str) {
    3202           0 :                                         RETURN_STR_COPY(ch->header.str);
    3203             :                                 } else {
    3204           0 :                                         RETURN_FALSE;
    3205             :                                 }
    3206             : #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
    3207             :                         case CURLINFO_CERTINFO: {
    3208           0 :                                 struct curl_certinfo *ci = NULL;
    3209             : 
    3210           0 :                                 array_init(return_value);
    3211             : 
    3212           0 :                                 if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
    3213           0 :                                         create_certinfo(ci, return_value);
    3214             :                                 } else {
    3215           0 :                                         RETURN_FALSE;
    3216             :                                 }
    3217           0 :                                 break;
    3218             :                         }
    3219             : #endif
    3220             :                         default: {
    3221           9 :                                 int type = CURLINFO_TYPEMASK & option;
    3222           9 :                                 switch (type) {
    3223             :                                         case CURLINFO_STRING:
    3224             :                                         {
    3225           4 :                                                 char *s_code = NULL;
    3226             : 
    3227           4 :                                                 if (curl_easy_getinfo(ch->cp, option, &s_code) == CURLE_OK && s_code) {
    3228           8 :                                                         RETURN_STRING(s_code);
    3229             :                                                 } else {
    3230           0 :                                                         RETURN_FALSE;
    3231             :                                                 }
    3232             :                                                 break;
    3233             :                                         }
    3234             :                                         case CURLINFO_LONG:
    3235             :                                         {
    3236           4 :                                                 zend_long code = 0;
    3237             : 
    3238           4 :                                                 if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) {
    3239           4 :                                                         RETURN_LONG(code);
    3240             :                                                 } else {
    3241           0 :                                                         RETURN_FALSE;
    3242             :                                                 }
    3243             :                                                 break;
    3244             :                                         }
    3245             :                                         case CURLINFO_DOUBLE:
    3246             :                                         {
    3247           0 :                                                 double code = 0.0;
    3248             : 
    3249           0 :                                                 if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) {
    3250           0 :                                                         RETURN_DOUBLE(code);
    3251             :                                                 } else {
    3252           0 :                                                         RETURN_FALSE;
    3253             :                                                 }
    3254             :                                                 break;
    3255             :                                         }
    3256             : #if LIBCURL_VERSION_NUM >= 0x070c03 /* Available since 7.12.3 */
    3257             :                                         case CURLINFO_SLIST:
    3258             :                                         {
    3259             :                                                 struct curl_slist *slist;
    3260           1 :                                                 array_init(return_value);
    3261           1 :                                                 if (curl_easy_getinfo(ch->cp, option, &slist) == CURLE_OK) {
    3262           4 :                                                         while (slist) {
    3263           2 :                                                                 add_next_index_string(return_value, slist->data);
    3264           2 :                                                                 slist = slist->next;
    3265             :                                                         }
    3266           1 :                                                         curl_slist_free_all(slist);
    3267             :                                                 } else {
    3268           0 :                                                         RETURN_FALSE;
    3269             :                                                 }
    3270           1 :                                                 break;
    3271             :                                         }
    3272             : #endif
    3273             :                                         default:
    3274           0 :                                                 RETURN_FALSE;
    3275             :                                 }
    3276             :                         }
    3277             :                 }
    3278             :         }
    3279             : }
    3280             : /* }}} */
    3281             : 
    3282             : /* {{{ proto string curl_error(resource ch)
    3283             :    Return a string contain the last error for the current session */
    3284           5 : PHP_FUNCTION(curl_error)
    3285             : {
    3286             :         zval            *zid;
    3287             :         php_curl        *ch;
    3288             : 
    3289           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zid) == FAILURE) {
    3290           0 :                 return;
    3291             :         }
    3292             : 
    3293           5 :         if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
    3294           0 :                 RETURN_FALSE;
    3295             :         }
    3296             : 
    3297           5 :         ch->err.str[CURL_ERROR_SIZE] = 0;
    3298          10 :         RETURN_STRING(ch->err.str);
    3299             : }
    3300             : /* }}} */
    3301             : 
    3302             : /* {{{ proto int curl_errno(resource ch)
    3303             :    Return an integer containing the last error number */
    3304           4 : PHP_FUNCTION(curl_errno)
    3305             : {
    3306             :         zval            *zid;
    3307             :         php_curl        *ch;
    3308             : 
    3309           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zid) == FAILURE) {
    3310           0 :                 return;
    3311             :         }
    3312             : 
    3313           4 :         if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
    3314           0 :                 RETURN_FALSE;
    3315             :         }
    3316             : 
    3317           4 :         RETURN_LONG(ch->err.no);
    3318             : }
    3319             : /* }}} */
    3320             : 
    3321             : /* {{{ proto void curl_close(resource ch)
    3322             :    Close a cURL session */
    3323          63 : PHP_FUNCTION(curl_close)
    3324             : {
    3325             :         zval            *zid;
    3326             :         php_curl        *ch;
    3327             : 
    3328          63 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zid) == FAILURE) {
    3329           0 :                 return;
    3330             :         }
    3331             : 
    3332          63 :         if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
    3333           0 :                 RETURN_FALSE;
    3334             :         }
    3335             : 
    3336          63 :         if (ch->in_callback) {
    3337           0 :                 php_error_docref(NULL, E_WARNING, "Attempt to close cURL handle from a callback");
    3338           0 :                 return;
    3339             :         }
    3340             : 
    3341          63 :         zend_list_close(Z_RES_P(zid));
    3342             : }
    3343             : /* }}} */
    3344             : 
    3345             : /* {{{ _php_curl_close_ex()
    3346             :    List destructor for curl handles */
    3347         128 : static void _php_curl_close_ex(php_curl *ch)
    3348             : {
    3349             : #if PHP_CURL_DEBUG
    3350             :         fprintf(stderr, "DTOR CALLED, ch = %x\n", ch);
    3351             : #endif
    3352             : 
    3353         128 :         _php_curl_verify_handlers(ch, 0);
    3354             : 
    3355             :         /*
    3356             :          * Libcurl is doing connection caching. When easy handle is cleaned up,
    3357             :          * if the handle was previously used by the curl_multi_api, the connection
    3358             :          * remains open un the curl multi handle is cleaned up. Some protocols are
    3359             :          * sending content like the FTP one, and libcurl try to use the
    3360             :          * WRITEFUNCTION or the HEADERFUNCTION. Since structures used in those
    3361             :          * callback are freed, we need to use an other callback to which avoid
    3362             :          * segfaults.
    3363             :          *
    3364             :          * Libcurl commit d021f2e8a00 fix this issue and should be part of 7.28.2
    3365             :          */
    3366         128 :         if (ch->cp != NULL) {
    3367         128 :                 curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_nothing);
    3368         128 :                 curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write_nothing);
    3369             : 
    3370         128 :                 curl_easy_cleanup(ch->cp);
    3371             :         }
    3372             : 
    3373             :         /* cURL destructors should be invoked only by last curl handle */
    3374         128 :         if (--(*ch->clone) == 0) {
    3375         111 :                 zend_llist_clean(&ch->to_free->str);
    3376         111 :                 zend_llist_clean(&ch->to_free->post);
    3377         111 :                 zend_hash_destroy(ch->to_free->slist);
    3378         111 :                 efree(ch->to_free->slist);
    3379         111 :                 efree(ch->to_free);
    3380         111 :                 efree(ch->clone);
    3381             :         }
    3382             : 
    3383         128 :         smart_str_free(&ch->handlers->write->buf);
    3384         128 :         zval_ptr_dtor(&ch->handlers->write->func_name);
    3385         128 :         zval_ptr_dtor(&ch->handlers->read->func_name);
    3386         128 :         zval_ptr_dtor(&ch->handlers->write_header->func_name);
    3387             : #if CURLOPT_PASSWDFUNCTION != 0
    3388             :         zval_ptr_dtor(&ch->handlers->passwd);
    3389             : #endif
    3390         128 :         zval_ptr_dtor(&ch->handlers->std_err);
    3391         128 :         if (ch->header.str) {
    3392           0 :                 zend_string_release(ch->header.str);
    3393             :         }
    3394             : 
    3395         128 :         zval_ptr_dtor(&ch->handlers->write_header->stream);
    3396         128 :         zval_ptr_dtor(&ch->handlers->write->stream);
    3397         128 :         zval_ptr_dtor(&ch->handlers->read->stream);
    3398             : 
    3399         128 :         efree(ch->handlers->write);
    3400         128 :         efree(ch->handlers->write_header);
    3401         128 :         efree(ch->handlers->read);
    3402             : 
    3403         128 :         if (ch->handlers->progress) {
    3404           2 :                 zval_ptr_dtor(&ch->handlers->progress->func_name);
    3405           2 :                 efree(ch->handlers->progress);
    3406             :         }
    3407             : 
    3408             : #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
    3409             :         if (ch->handlers->fnmatch) {
    3410             :                 zval_ptr_dtor(&ch->handlers->fnmatch->func_name);
    3411             :                 efree(ch->handlers->fnmatch);
    3412             :         }
    3413             : #endif
    3414             : 
    3415         128 :         efree(ch->handlers);
    3416         128 :         efree(ch);
    3417         128 : }
    3418             : /* }}} */
    3419             : 
    3420             : /* {{{ _php_curl_close()
    3421             :    List destructor for curl handles */
    3422         128 : static void _php_curl_close(zend_resource *rsrc)
    3423             : {
    3424         128 :         php_curl *ch = (php_curl *) rsrc->ptr;
    3425         128 :         _php_curl_close_ex(ch);
    3426         128 : }
    3427             : /* }}} */
    3428             : 
    3429             : #if LIBCURL_VERSION_NUM >= 0x070c00 /* Available since 7.12.0 */
    3430             : /* {{{ proto bool curl_strerror(int code)
    3431             :       return string describing error code */
    3432           3 : PHP_FUNCTION(curl_strerror)
    3433             : {
    3434             :         zend_long code;
    3435             :         const char *str;
    3436             : 
    3437           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &code) == FAILURE) {
    3438           0 :                 return;
    3439             :         }
    3440             : 
    3441           3 :         str = curl_easy_strerror(code);
    3442           3 :         if (str) {
    3443           6 :                 RETURN_STRING(str);
    3444             :         } else {
    3445           0 :                 RETURN_NULL();
    3446             :         }
    3447             : }
    3448             : /* }}} */
    3449             : #endif
    3450             : 
    3451             : #if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */
    3452             : /* {{{ _php_curl_reset_handlers()
    3453             :    Reset all handlers of a given php_curl */
    3454           1 : static void _php_curl_reset_handlers(php_curl *ch)
    3455             : {
    3456           2 :         if (!Z_ISUNDEF(ch->handlers->write->stream)) {
    3457           1 :                 zval_ptr_dtor(&ch->handlers->write->stream);
    3458           1 :                 ZVAL_UNDEF(&ch->handlers->write->stream);
    3459             :         }
    3460           1 :         ch->handlers->write->fp = NULL;
    3461           1 :         ch->handlers->write->method = PHP_CURL_STDOUT;
    3462             : 
    3463           2 :         if (!Z_ISUNDEF(ch->handlers->write_header->stream)) {
    3464           0 :                 zval_ptr_dtor(&ch->handlers->write_header->stream);
    3465           0 :                 ZVAL_UNDEF(&ch->handlers->write_header->stream);
    3466             :         }
    3467           1 :         ch->handlers->write_header->fp = NULL;
    3468           1 :         ch->handlers->write_header->method = PHP_CURL_IGNORE;
    3469             : 
    3470           2 :         if (!Z_ISUNDEF(ch->handlers->read->stream)) {
    3471           0 :                 zval_ptr_dtor(&ch->handlers->read->stream);
    3472           0 :                 ZVAL_UNDEF(&ch->handlers->read->stream);
    3473             :         }
    3474           1 :         ch->handlers->read->fp = NULL;
    3475           1 :         ch->handlers->read->res = NULL;
    3476           1 :         ch->handlers->read->method  = PHP_CURL_DIRECT;
    3477             : 
    3478           2 :         if (!Z_ISUNDEF(ch->handlers->std_err)) {
    3479           0 :                 zval_ptr_dtor(&ch->handlers->std_err);
    3480           0 :                 ZVAL_UNDEF(&ch->handlers->std_err);
    3481             :         }
    3482             : 
    3483           1 :         if (ch->handlers->progress) {
    3484           0 :                 zval_ptr_dtor(&ch->handlers->progress->func_name);
    3485           0 :                 efree(ch->handlers->progress);
    3486           0 :                 ch->handlers->progress = NULL;
    3487             :         }
    3488             : 
    3489             : #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
    3490             :         if (ch->handlers->fnmatch) {
    3491             :                 zval_ptr_dtor(&ch->handlers->fnmatch->func_name);
    3492             :                 efree(ch->handlers->fnmatch);
    3493             :                 ch->handlers->fnmatch = NULL;
    3494             :         }
    3495             : #endif
    3496             : 
    3497           1 : }
    3498             : /* }}} */
    3499             : 
    3500             : /* {{{ proto void curl_reset(resource ch)
    3501             :    Reset all options of a libcurl session handle */
    3502           1 : PHP_FUNCTION(curl_reset)
    3503             : {
    3504             :         zval       *zid;
    3505             :         php_curl   *ch;
    3506             : 
    3507           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zid) == FAILURE) {
    3508           0 :                 return;
    3509             :         }
    3510             : 
    3511           1 :         if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
    3512           0 :                 RETURN_FALSE;
    3513             :         }
    3514             : 
    3515           1 :         if (ch->in_callback) {
    3516           0 :                 php_error_docref(NULL, E_WARNING, "Attempt to reset cURL handle from a callback");
    3517           0 :                 return;
    3518             :         }
    3519             : 
    3520           1 :         curl_easy_reset(ch->cp);
    3521           1 :         _php_curl_reset_handlers(ch);
    3522           1 :         _php_curl_set_default_options(ch);
    3523             : }
    3524             : /* }}} */
    3525             : #endif
    3526             : 
    3527             : #if LIBCURL_VERSION_NUM > 0x070f03 /* 7.15.4 */
    3528             : /* {{{ proto void curl_escape(resource ch, string str)
    3529             :    URL encodes the given string */
    3530           0 : PHP_FUNCTION(curl_escape)
    3531             : {
    3532           0 :         char       *str = NULL, *res = NULL;
    3533           0 :         size_t        str_len = 0;
    3534             :         zval       *zid;
    3535             :         php_curl   *ch;
    3536             : 
    3537           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &zid, &str, &str_len) == FAILURE) {
    3538           0 :                 return;
    3539             :         }
    3540             : 
    3541           0 :         if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
    3542           0 :                 RETURN_FALSE;
    3543             :         }
    3544             : 
    3545           0 :         if ((res = curl_easy_escape(ch->cp, str, str_len))) {
    3546           0 :                 RETVAL_STRING(res);
    3547           0 :                 curl_free(res);
    3548             :         } else {
    3549           0 :                 RETURN_FALSE;
    3550             :         }
    3551             : }
    3552             : /* }}} */
    3553             : 
    3554             : /* {{{ proto void curl_unescape(resource ch, string str)
    3555             :    URL decodes the given string */
    3556           0 : PHP_FUNCTION(curl_unescape)
    3557             : {
    3558           0 :         char       *str = NULL, *out = NULL;
    3559           0 :         size_t     str_len = 0;
    3560             :         int        out_len;
    3561             :         zval       *zid;
    3562             :         php_curl   *ch;
    3563             : 
    3564           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &zid, &str, &str_len) == FAILURE) {
    3565           0 :                 return;
    3566             :         }
    3567             : 
    3568           0 :         if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
    3569           0 :                 RETURN_FALSE;
    3570             :         }
    3571             : 
    3572           0 :         if (str_len > INT_MAX) {
    3573           0 :                 RETURN_FALSE;
    3574             :         }
    3575             : 
    3576           0 :         if ((out = curl_easy_unescape(ch->cp, str, str_len, &out_len))) {
    3577           0 :                 RETVAL_STRINGL(out, out_len);
    3578           0 :                 curl_free(out);
    3579             :         } else {
    3580           0 :                 RETURN_FALSE;
    3581             :         }
    3582             : }
    3583             : /* }}} */
    3584             : #endif
    3585             : 
    3586             : #if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */
    3587             : /* {{{ proto void curl_pause(resource ch, int bitmask)
    3588             :        pause and unpause a connection */
    3589           0 : PHP_FUNCTION(curl_pause)
    3590             : {
    3591             :         zend_long       bitmask;
    3592             :         zval       *zid;
    3593             :         php_curl   *ch;
    3594             : 
    3595           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &zid, &bitmask) == FAILURE) {
    3596           0 :                 return;
    3597             :         }
    3598             : 
    3599           0 :         if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
    3600           0 :                 RETURN_FALSE;
    3601             :         }
    3602             : 
    3603           0 :         RETURN_LONG(curl_easy_pause(ch->cp, bitmask));
    3604             : }
    3605             : /* }}} */
    3606             : #endif
    3607             : 
    3608             : #endif /* HAVE_CURL */
    3609             : 
    3610             : /*
    3611             :  * Local variables:
    3612             :  * tab-width: 4
    3613             :  * c-basic-offset: 4
    3614             :  * End:
    3615             :  * vim600: fdm=marker
    3616             :  * vim: noet sw=4 ts=4
    3617             :  */

Generated by: LCOV version 1.10

Generated at Wed, 24 Aug 2016 12:20:18 +0000 (7 hours ago)

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