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: 1153 1379 83.6 %
Date: 2014-08-04 Functions: 33 39 84.6 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Mon, 04 Aug 2014 15:49:02 +0000 (16 days ago)

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