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

Generated by: LCOV version 1.10

Generated at Fri, 19 Sep 2014 17:11:05 +0000 (3 days ago)

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