PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LTP GCOV extension - code coverage report
Current view: directory - curl - interface.c
Test: PHP Code Coverage
Date: 2009-11-21 Instrumented lines: 1037
Code covered: 76.5 % Executed lines: 793
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | PHP Version 5                                                        |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1997-2009 The PHP Group                                |
       6                 :    +----------------------------------------------------------------------+
       7                 :    | This source file is subject to version 3.01 of the PHP license,      |
       8                 :    | that is bundled with this package in the file LICENSE, and is        |
       9                 :    | available through the world-wide-web at the following url:           |
      10                 :    | http://www.php.net/license/3_01.txt                                  |
      11                 :    | If you did not receive a copy of the PHP license and are unable to   |
      12                 :    | obtain it through the world-wide-web, please send a note to          |
      13                 :    | license@php.net so we can mail you a copy immediately.               |
      14                 :    +----------------------------------------------------------------------+
      15                 :    | Author: Sterling Hughes <sterling@php.net>                           |
      16                 :    +----------------------------------------------------------------------+
      17                 : */
      18                 : 
      19                 : /* $Id: interface.c 289934 2009-10-26 12:57:01Z iliaa $ */
      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                 : 
      94                 : #ifdef PHP_CURL_NEED_OPENSSL_TSL /* {{{ */
      95                 : static MUTEX_T *php_curl_openssl_tsl = NULL;
      96                 : 
      97                 : static void php_curl_ssl_lock(int mode, int n, const char * file, int line)
      98                 : {
      99                 :         if (mode & CRYPTO_LOCK) {
     100                 :                 tsrm_mutex_lock(php_curl_openssl_tsl[n]);
     101                 :         } else {
     102                 :                 tsrm_mutex_unlock(php_curl_openssl_tsl[n]);
     103                 :         }
     104                 : }
     105                 : 
     106                 : static unsigned long php_curl_ssl_id(void)
     107                 : {
     108                 :         return (unsigned long) tsrm_thread_id();
     109                 : }
     110                 : #endif
     111                 : /* }}} */
     112                 : 
     113                 : #ifdef PHP_CURL_NEED_GNUTLS_TSL /* {{{ */
     114                 : static int php_curl_ssl_mutex_create(void **m)
     115                 : {
     116                 :         if (*((MUTEX_T *) m) = tsrm_mutex_alloc()) {
     117                 :                 return SUCCESS;
     118                 :         } else {
     119                 :                 return FAILURE;
     120                 :         }
     121                 : }
     122                 : 
     123                 : static int php_curl_ssl_mutex_destroy(void **m)
     124                 : {
     125                 :         tsrm_mutex_free(*((MUTEX_T *) m));
     126                 :         return SUCCESS;
     127                 : }
     128                 : 
     129                 : static int php_curl_ssl_mutex_lock(void **m)
     130                 : {
     131                 :         return tsrm_mutex_lock(*((MUTEX_T *) m));
     132                 : }
     133                 : 
     134                 : static int php_curl_ssl_mutex_unlock(void **m)
     135                 : {
     136                 :         return tsrm_mutex_unlock(*((MUTEX_T *) m));
     137                 : }
     138                 : 
     139                 : static struct gcry_thread_cbs php_curl_gnutls_tsl = {
     140                 :         GCRY_THREAD_OPTION_USER,
     141                 :         NULL,
     142                 :         php_curl_ssl_mutex_create,
     143                 :         php_curl_ssl_mutex_destroy,
     144                 :         php_curl_ssl_mutex_lock,
     145                 :         php_curl_ssl_mutex_unlock
     146                 : };
     147                 : #endif
     148                 : /* }}} */
     149                 : 
     150                 : static void _php_curl_close_ex(php_curl *ch TSRMLS_DC);
     151                 : static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC);
     152                 : 
     153                 : #define SAVE_CURL_ERROR(__handle, __err) (__handle)->err.no = (int) __err;
     154                 : 
     155                 : #define CAAL(s, v) add_assoc_long_ex(return_value, s, sizeof(s), (long) v);
     156                 : #define CAAD(s, v) add_assoc_double_ex(return_value, s, sizeof(s), (double) v);
     157                 : #define CAAS(s, v) add_assoc_string_ex(return_value, s, sizeof(s), (char *) (v ? v : ""), 1);
     158                 : #define CAAZ(s, v) add_assoc_zval_ex(return_value, s, sizeof(s), (zval *) v);
     159                 : 
     160                 : #if defined(PHP_WIN32) || defined(__GNUC__)
     161                 : # define php_curl_ret(__ret) RETVAL_FALSE; return __ret;
     162                 : #else
     163                 : # define php_curl_ret(__ret) RETVAL_FALSE; return;
     164                 : #endif
     165                 : 
     166                 : static int php_curl_option_url(php_curl *ch, const char *url, const int len) /* {{{ */
     167              60 : {
     168              60 :         CURLcode error = CURLE_OK;
     169                 : #if LIBCURL_VERSION_NUM < 0x071100
     170              60 :         char *copystr = NULL;
     171                 : #endif
     172                 :         TSRMLS_FETCH();
     173                 : 
     174                 :         /* Disable file:// if open_basedir or safe_mode are used */
     175              60 :         if ((PG(open_basedir) && *PG(open_basedir)) || PG(safe_mode)) {
     176                 : #if LIBCURL_VERSION_NUM >= 0x071304
     177                 :                 error = curl_easy_setopt(ch->cp, CURLOPT_PROTOCOLS, CURLPROTO_ALL & ~CURLPROTO_FILE);
     178                 : #else
     179                 :                 php_url *uri;
     180                 : 
     181               0 :                 if (!(uri = php_url_parse_ex(url, len))) {
     182               0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid URL '%s'", url);
     183               0 :                         return 0;
     184                 :                 }
     185                 : 
     186               0 :                 if (uri->scheme && !strncasecmp("file", uri->scheme, sizeof("file"))) {
     187               0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Protocol 'file' disabled in cURL");
     188               0 :                         php_url_free(uri);
     189               0 :                         return 0;
     190                 :                 }
     191               0 :                 php_url_free(uri);
     192                 : #endif
     193                 :         }
     194                 :         /* Strings passed to libcurl as 'char *' arguments, are copied by the library... NOTE: before 7.17.0 strings were not copied. */
     195                 : #if LIBCURL_VERSION_NUM >= 0x071100
     196                 :         error = curl_easy_setopt(ch->cp, CURLOPT_URL, url);
     197                 : #else
     198              60 :         copystr = estrndup(url, len);
     199              60 :         error = curl_easy_setopt(ch->cp, CURLOPT_URL, copystr);
     200              60 :         zend_llist_add_element(&ch->to_free.str, &copystr);
     201                 : #endif
     202                 : 
     203              60 :         return (error == CURLE_OK ? 1 : 0);
     204                 : }
     205                 : /* }}} */
     206                 : 
     207                 : /* {{{ arginfo */
     208                 : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_version, 0, 0, 0)
     209                 :         ZEND_ARG_INFO(0, version)
     210                 : ZEND_END_ARG_INFO()
     211                 : 
     212                 : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_init, 0, 0, 0)
     213                 :         ZEND_ARG_INFO(0, url)
     214                 : ZEND_END_ARG_INFO()
     215                 : 
     216                 : ZEND_BEGIN_ARG_INFO(arginfo_curl_copy_handle, 0)
     217                 :         ZEND_ARG_INFO(0, ch)
     218                 : ZEND_END_ARG_INFO()
     219                 : 
     220                 : ZEND_BEGIN_ARG_INFO(arginfo_curl_setopt, 0)
     221                 :         ZEND_ARG_INFO(0, ch)
     222                 :         ZEND_ARG_INFO(0, option)
     223                 :         ZEND_ARG_INFO(0, value)
     224                 : ZEND_END_ARG_INFO()
     225                 : 
     226                 : ZEND_BEGIN_ARG_INFO(arginfo_curl_setopt_array, 0)
     227                 :         ZEND_ARG_INFO(0, ch)
     228                 :         ZEND_ARG_ARRAY_INFO(0, options, 0)
     229                 : ZEND_END_ARG_INFO()
     230                 : 
     231                 : ZEND_BEGIN_ARG_INFO(arginfo_curl_exec, 0)
     232                 :         ZEND_ARG_INFO(0, ch)
     233                 : ZEND_END_ARG_INFO()
     234                 : 
     235                 : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_getinfo, 0, 0, 1)
     236                 :         ZEND_ARG_INFO(0, ch)
     237                 :         ZEND_ARG_INFO(0, option)
     238                 : ZEND_END_ARG_INFO()
     239                 : 
     240                 : ZEND_BEGIN_ARG_INFO(arginfo_curl_error, 0)
     241                 :         ZEND_ARG_INFO(0, ch)
     242                 : ZEND_END_ARG_INFO()
     243                 : 
     244                 : ZEND_BEGIN_ARG_INFO(arginfo_curl_errno, 0)
     245                 :         ZEND_ARG_INFO(0, ch)
     246                 : ZEND_END_ARG_INFO()
     247                 : 
     248                 : ZEND_BEGIN_ARG_INFO(arginfo_curl_close, 0)
     249                 :         ZEND_ARG_INFO(0, ch)
     250                 : ZEND_END_ARG_INFO()
     251                 : 
     252                 : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_init, 0)
     253                 : ZEND_END_ARG_INFO()
     254                 : 
     255                 : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_add_handle, 0)
     256                 :         ZEND_ARG_INFO(0, mh)
     257                 :         ZEND_ARG_INFO(0, ch)
     258                 : ZEND_END_ARG_INFO()
     259                 : 
     260                 : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_remove_handle, 0)
     261                 :         ZEND_ARG_INFO(0, mh)
     262                 :         ZEND_ARG_INFO(0, ch)
     263                 : ZEND_END_ARG_INFO()
     264                 : 
     265                 : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_select, 0, 0, 1)
     266                 :         ZEND_ARG_INFO(0, mh)
     267                 :         ZEND_ARG_INFO(0, timeout)
     268                 : ZEND_END_ARG_INFO()
     269                 : 
     270                 : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_exec, 0, 0, 1)
     271                 :         ZEND_ARG_INFO(0, mh)
     272                 :         ZEND_ARG_INFO(1, still_running)
     273                 : ZEND_END_ARG_INFO()
     274                 : 
     275                 : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_getcontent, 0)
     276                 :         ZEND_ARG_INFO(0, ch)
     277                 : ZEND_END_ARG_INFO()
     278                 : 
     279                 : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_info_read, 0, 0, 1)
     280                 :         ZEND_ARG_INFO(0, mh)
     281                 :         ZEND_ARG_INFO(1, msgs_in_queue)
     282                 : ZEND_END_ARG_INFO()
     283                 : 
     284                 : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_close, 0)
     285                 :         ZEND_ARG_INFO(0, mh)
     286                 : ZEND_END_ARG_INFO()
     287                 : /* }}} */
     288                 : 
     289                 : /* {{{ curl_functions[]
     290                 :  */
     291                 : const zend_function_entry curl_functions[] = {
     292                 :         PHP_FE(curl_init,                arginfo_curl_init)
     293                 :         PHP_FE(curl_copy_handle,         arginfo_curl_copy_handle)
     294                 :         PHP_FE(curl_version,             arginfo_curl_version)
     295                 :         PHP_FE(curl_setopt,              arginfo_curl_setopt)
     296                 :         PHP_FE(curl_setopt_array,        arginfo_curl_setopt_array)
     297                 :         PHP_FE(curl_exec,                arginfo_curl_exec)
     298                 :         PHP_FE(curl_getinfo,             arginfo_curl_getinfo)
     299                 :         PHP_FE(curl_error,               arginfo_curl_error)
     300                 :         PHP_FE(curl_errno,               arginfo_curl_errno)
     301                 :         PHP_FE(curl_close,               arginfo_curl_close)
     302                 :         PHP_FE(curl_multi_init,          arginfo_curl_multi_init)
     303                 :         PHP_FE(curl_multi_add_handle,    arginfo_curl_multi_add_handle)
     304                 :         PHP_FE(curl_multi_remove_handle, arginfo_curl_multi_remove_handle)
     305                 :         PHP_FE(curl_multi_select,        arginfo_curl_multi_select)
     306                 :         PHP_FE(curl_multi_exec,          arginfo_curl_multi_exec)
     307                 :         PHP_FE(curl_multi_getcontent,    arginfo_curl_multi_getcontent)
     308                 :         PHP_FE(curl_multi_info_read,     arginfo_curl_multi_info_read)
     309                 :         PHP_FE(curl_multi_close,         arginfo_curl_multi_close)
     310                 :         {NULL, NULL, NULL}
     311                 : };
     312                 : /* }}} */
     313                 : 
     314                 : /* {{{ curl_module_entry
     315                 :  */
     316                 : zend_module_entry curl_module_entry = {
     317                 :         STANDARD_MODULE_HEADER,
     318                 :         "curl",
     319                 :         curl_functions,
     320                 :         PHP_MINIT(curl),
     321                 :         PHP_MSHUTDOWN(curl),
     322                 :         NULL,
     323                 :         NULL,
     324                 :         PHP_MINFO(curl),
     325                 :         NO_VERSION_YET,
     326                 :         STANDARD_MODULE_PROPERTIES
     327                 : };
     328                 : /* }}} */
     329                 : 
     330                 : #ifdef COMPILE_DL_CURL
     331                 : ZEND_GET_MODULE (curl)
     332                 : #endif
     333                 : 
     334                 : /* {{{ PHP_MINFO_FUNCTION
     335                 :  */
     336                 : PHP_MINFO_FUNCTION(curl)
     337              42 : {
     338                 :         curl_version_info_data *d;
     339                 :         char **p;
     340                 :         char str[1024];
     341              42 :         size_t n = 0;
     342                 : 
     343              42 :         d = curl_version_info(CURLVERSION_NOW);
     344              42 :         php_info_print_table_start();
     345              42 :         php_info_print_table_row(2, "cURL support",    "enabled");
     346              42 :         php_info_print_table_row(2, "cURL Information", d->version);
     347              42 :         sprintf(str, "%d", d->age);
     348              42 :         php_info_print_table_row(2, "Age", str);
     349                 : 
     350                 :         /* To update on each new cURL release using src/main.c in cURL sources */
     351              42 :         if (d->features) {
     352                 :                 struct feat {
     353                 :                         const char *name;
     354                 :                         int bitmask;
     355                 :                 };
     356                 : 
     357                 :                 unsigned int i;
     358                 : 
     359                 :                 static const struct feat feats[] = {
     360                 : #if LIBCURL_VERSION_NUM > 0x070a06 /* 7.10.7 */
     361                 :                         {"AsynchDNS", CURL_VERSION_ASYNCHDNS},
     362                 : #endif
     363                 : #if LIBCURL_VERSION_NUM > 0x070a05 /* 7.10.6 */
     364                 :                         {"Debug", CURL_VERSION_DEBUG},
     365                 :                         {"GSS-Negotiate", CURL_VERSION_GSSNEGOTIATE},
     366                 : #endif
     367                 : #if LIBCURL_VERSION_NUM > 0x070b02 /* 7.12.0 */
     368                 :                         {"IDN", CURL_VERSION_IDN},
     369                 : #endif
     370                 : #ifdef CURL_VERSION_IPV6
     371                 :                         {"IPv6", CURL_VERSION_IPV6},
     372                 : #endif
     373                 : #if LIBCURL_VERSION_NUM > 0x070a09 /* 7.10.1 */
     374                 :                         {"Largefile", CURL_VERSION_LARGEFILE},
     375                 : #endif
     376                 : #if LIBCURL_VERSION_NUM > 0x070a05 /* 7.10.6 */
     377                 :                         {"NTLM", CURL_VERSION_NTLM},
     378                 : #endif
     379                 : #if LIBCURL_VERSION_NUM > 0x070a07 /* 7.10.8 */
     380                 :                         {"SPNEGO", CURL_VERSION_SPNEGO},
     381                 : #endif
     382                 : #ifdef CURL_VERSION_SSL
     383                 :                         {"SSL",  CURL_VERSION_SSL},
     384                 : #endif
     385                 : #if LIBCURL_VERSION_NUM > 0x070d01 /* 7.13.2 */
     386                 :                         {"SSPI",  CURL_VERSION_SSPI},
     387                 : #endif
     388                 : #ifdef CURL_VERSION_KERBEROS4
     389                 :                         {"krb4", CURL_VERSION_KERBEROS4},
     390                 : #endif
     391                 : #ifdef CURL_VERSION_LIBZ
     392                 :                         {"libz", CURL_VERSION_LIBZ},
     393                 : #endif
     394                 : #if LIBCURL_VERSION_NUM > 0x070f03 /* 7.15.4 */
     395                 :                         {"CharConv", CURL_VERSION_CONV},
     396                 : #endif
     397                 :                         {NULL, 0}
     398                 :                 };
     399                 : 
     400              42 :                 php_info_print_table_row(1, "Features");
     401             630 :                 for(i=0; i<sizeof(feats)/sizeof(feats[0]); i++) {
     402             588 :                         if (feats[i].name) {
     403             546 :                                 php_info_print_table_row(2, feats[i].name, d->features & feats[i].bitmask ? "Yes" : "No");
     404                 :                         }
     405                 :                 }
     406                 :         }
     407                 : 
     408              42 :         n = 0;
     409              42 :         p = (char **) d->protocols;
     410             462 :         while (*p != NULL) {
     411             378 :                         n += sprintf(str + n, "%s%s", *p, *(p + 1) != NULL ? ", " : "");
     412             378 :                         p++;
     413                 :         }
     414              42 :         php_info_print_table_row(2, "Protocols", str);
     415                 : 
     416              42 :         php_info_print_table_row(2, "Host", d->host);
     417                 : 
     418              42 :         if (d->ssl_version) {
     419              42 :                 php_info_print_table_row(2, "SSL Version", d->ssl_version);
     420                 :         }
     421                 : 
     422              42 :         if (d->libz_version) {
     423              42 :                 php_info_print_table_row(2, "ZLib Version", d->libz_version);
     424                 :         }
     425                 : 
     426                 : #if defined(CURLVERSION_SECOND) && CURLVERSION_NOW >= CURLVERSION_SECOND
     427                 :         if (d->ares) {
     428                 :                 php_info_print_table_row(2, "ZLib Version", d->ares);
     429                 :         }
     430                 : #endif
     431                 : 
     432                 : #if defined(CURLVERSION_THIRD) && CURLVERSION_NOW >= CURLVERSION_THIRD
     433                 :         if (d->libidn) {
     434                 :                 php_info_print_table_row(2, "libIDN Version", d->libidn);
     435                 :         }
     436                 : #endif
     437                 : 
     438                 : #if LIBCURL_VERSION_NUM >= 0x071300
     439                 : 
     440                 :         if (d->iconv_ver_num) {
     441                 :                 php_info_print_table_row(2, "IconV Version", d->iconv_ver_num);
     442                 :         }
     443                 : 
     444                 :         if (d->libssh_version) {
     445                 :                 php_info_print_table_row(2, "libSSH Version", d->libssh_version);
     446                 :         }
     447                 : #endif
     448              42 :         php_info_print_table_end();
     449              42 : }
     450                 : /* }}} */
     451                 : 
     452                 : #define REGISTER_CURL_CONSTANT(__c) REGISTER_LONG_CONSTANT(#__c, __c, CONST_CS | CONST_PERSISTENT)
     453                 : 
     454                 : /* {{{ PHP_MINIT_FUNCTION
     455                 :  */
     456                 : PHP_MINIT_FUNCTION(curl)
     457           17633 : {
     458           17633 :         le_curl = zend_register_list_destructors_ex(_php_curl_close, NULL, "curl", module_number);
     459           17633 :         le_curl_multi_handle = zend_register_list_destructors_ex(_php_curl_multi_close, NULL, "curl_multi", module_number);
     460                 : 
     461                 :         /* See http://curl.haxx.se/lxr/source/docs/libcurl/symbols-in-versions
     462                 :            or curl src/docs/libcurl/symbols-in-versions for a (almost) complete list
     463                 :            of options and which version they were introduced */
     464                 : 
     465                 :         /* Constants for curl_setopt() */
     466                 : #if LIBCURL_VERSION_NUM > 0x070a07 /* CURLOPT_IPRESOLVE is available since curl 7.10.8 */
     467           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_IPRESOLVE);
     468           17633 :         REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_WHATEVER);
     469           17633 :         REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V4);
     470           17633 :         REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V6);
     471                 : #endif
     472           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_DNS_USE_GLOBAL_CACHE);
     473           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_DNS_CACHE_TIMEOUT);
     474           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_PORT);
     475           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FILE);
     476           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_READDATA);
     477           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_INFILE);
     478           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_INFILESIZE);
     479           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_URL);
     480           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXY);
     481           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_VERBOSE);
     482           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_HEADER);
     483           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTPHEADER);
     484           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_NOPROGRESS);
     485           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_PROGRESSFUNCTION);
     486           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_NOBODY);
     487           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FAILONERROR);
     488           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_UPLOAD);
     489           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_POST);
     490           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FTPLISTONLY);
     491           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FTPAPPEND);
     492           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_NETRC);
     493           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FOLLOWLOCATION);
     494                 : #if CURLOPT_FTPASCII != 0
     495                 :         REGISTER_CURL_CONSTANT(CURLOPT_FTPASCII);
     496                 : #endif
     497           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_PUT);
     498                 : #if CURLOPT_MUTE != 0
     499           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_MUTE);
     500                 : #endif
     501           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_USERPWD);
     502           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYUSERPWD);
     503           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_RANGE);
     504           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT);
     505                 : #if LIBCURL_VERSION_NUM > 0x071002
     506                 :         REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT_MS);
     507                 : #endif
     508           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_POSTFIELDS);
     509           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_REFERER);
     510           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_USERAGENT);
     511           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FTPPORT);
     512           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPSV);
     513           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_LIMIT);
     514           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_TIME);
     515           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_RESUME_FROM);
     516           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_COOKIE);
     517           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_COOKIESESSION);
     518           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_AUTOREFERER);
     519           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLCERT);
     520           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTPASSWD);
     521           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_WRITEHEADER);
     522           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYHOST);
     523           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_COOKIEFILE);
     524           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLVERSION);
     525           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_TIMECONDITION);
     526           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_TIMEVALUE);
     527           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_CUSTOMREQUEST);
     528           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_STDERR);
     529           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_TRANSFERTEXT);
     530           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_RETURNTRANSFER);
     531           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_QUOTE);
     532           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_POSTQUOTE);
     533           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_INTERFACE);
     534           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_KRB4LEVEL);
     535           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTPPROXYTUNNEL);
     536           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FILETIME);
     537           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_WRITEFUNCTION);
     538           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_READFUNCTION);
     539                 : #if CURLOPT_PASSWDFUNCTION != 0
     540           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_PASSWDFUNCTION);
     541                 : #endif
     542           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_HEADERFUNCTION);
     543           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_MAXREDIRS);
     544           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_MAXCONNECTS);
     545           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_CLOSEPOLICY);
     546           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FRESH_CONNECT);
     547           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FORBID_REUSE);
     548           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_RANDOM_FILE);
     549           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_EGDSOCKET);
     550           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT);
     551                 : #if LIBCURL_VERSION_NUM > 0x071002
     552                 :         REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT_MS);
     553                 : #endif
     554           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYPEER);
     555           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_CAINFO);
     556           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_CAPATH);
     557           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_COOKIEJAR);
     558           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_SSL_CIPHER_LIST);
     559           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_BINARYTRANSFER);
     560           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_NOSIGNAL);
     561           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYTYPE);
     562           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_BUFFERSIZE);
     563           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTPGET);
     564           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTP_VERSION);
     565           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLKEY);
     566           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYTYPE);
     567           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYPASSWD);
     568           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE);
     569           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE_DEFAULT);
     570           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTTYPE);
     571           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_CRLF);
     572           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_ENCODING);
     573           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYPORT);
     574           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_UNRESTRICTED_AUTH);
     575           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPRT);
     576                 : #if LIBCURL_VERSION_NUM > 0x070b01 /* CURLOPT_TCP_NODELAY is available since curl 7.11.2 */
     577           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_TCP_NODELAY);
     578                 : #endif
     579           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTP200ALIASES);
     580           17633 :         REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFMODSINCE);
     581           17633 :         REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFUNMODSINCE);
     582           17633 :         REGISTER_CURL_CONSTANT(CURL_TIMECOND_LASTMOD);
     583                 : 
     584                 : #if LIBCURL_VERSION_NUM > 0x070a05 /* CURLOPT_HTTPAUTH is available since curl 7.10.6 */
     585           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_HTTPAUTH);
     586                 :         /* http authentication options */
     587           17633 :         REGISTER_CURL_CONSTANT(CURLAUTH_BASIC);
     588           17633 :         REGISTER_CURL_CONSTANT(CURLAUTH_DIGEST);
     589           17633 :         REGISTER_CURL_CONSTANT(CURLAUTH_GSSNEGOTIATE);
     590           17633 :         REGISTER_CURL_CONSTANT(CURLAUTH_NTLM);
     591           17633 :         REGISTER_CURL_CONSTANT(CURLAUTH_ANY);
     592           17633 :         REGISTER_CURL_CONSTANT(CURLAUTH_ANYSAFE);
     593                 : #endif
     594                 : 
     595                 : #if LIBCURL_VERSION_NUM > 0x070a06 /* CURLOPT_PROXYAUTH & CURLOPT_FTP_CREATE_MISSING_DIRS are available since curl 7.10.7 */
     596           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_PROXYAUTH);
     597           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_CREATE_MISSING_DIRS);
     598                 : #endif
     599                 : 
     600           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_PRIVATE);
     601                 : 
     602                 :         /* Constants effecting the way CURLOPT_CLOSEPOLICY works */
     603           17633 :         REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_LEAST_RECENTLY_USED);
     604           17633 :         REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_LEAST_TRAFFIC);
     605           17633 :         REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_SLOWEST);
     606           17633 :         REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_CALLBACK);
     607           17633 :         REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_OLDEST);
     608                 : 
     609                 :         /* Info constants */
     610           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_EFFECTIVE_URL);
     611           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_HTTP_CODE);
     612           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_HEADER_SIZE);
     613           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_REQUEST_SIZE);
     614           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_TOTAL_TIME);
     615           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_NAMELOOKUP_TIME);
     616           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_CONNECT_TIME);
     617           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_PRETRANSFER_TIME);
     618           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_SIZE_UPLOAD);
     619           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_SIZE_DOWNLOAD);
     620           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_SPEED_DOWNLOAD);
     621           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_SPEED_UPLOAD);
     622           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_FILETIME);
     623           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_SSL_VERIFYRESULT);
     624           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_DOWNLOAD);
     625           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_UPLOAD);
     626           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_STARTTRANSFER_TIME);
     627           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_TYPE);
     628           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_TIME);
     629           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_COUNT);
     630           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_HEADER_OUT);
     631           17633 :         REGISTER_CURL_CONSTANT(CURLINFO_PRIVATE);
     632                 : #if LIBCURL_VERSION_NUM >  0x071301
     633                 :         REGISTER_CURL_CONSTANT(CURLINFO_CERTINFO);
     634                 : #endif
     635                 : 
     636                 :         /* cURL protocol constants (curl_version) */
     637           17633 :         REGISTER_CURL_CONSTANT(CURL_VERSION_IPV6);
     638           17633 :         REGISTER_CURL_CONSTANT(CURL_VERSION_KERBEROS4);
     639           17633 :         REGISTER_CURL_CONSTANT(CURL_VERSION_SSL);
     640           17633 :         REGISTER_CURL_CONSTANT(CURL_VERSION_LIBZ);
     641                 : 
     642                 :         /* version constants */
     643           17633 :         REGISTER_CURL_CONSTANT(CURLVERSION_NOW);
     644                 : 
     645                 :         /* Error Constants */
     646           17633 :         REGISTER_CURL_CONSTANT(CURLE_OK);
     647           17633 :         REGISTER_CURL_CONSTANT(CURLE_UNSUPPORTED_PROTOCOL);
     648           17633 :         REGISTER_CURL_CONSTANT(CURLE_FAILED_INIT);
     649           17633 :         REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT);
     650           17633 :         REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT_USER);
     651           17633 :         REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_PROXY);
     652           17633 :         REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_HOST);
     653           17633 :         REGISTER_CURL_CONSTANT(CURLE_COULDNT_CONNECT);
     654           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_SERVER_REPLY);
     655           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_ACCESS_DENIED);
     656           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_USER_PASSWORD_INCORRECT);
     657           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASS_REPLY);
     658           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_USER_REPLY);
     659           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASV_REPLY);
     660           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_227_FORMAT);
     661           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_GET_HOST);
     662           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_RECONNECT);
     663           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_BINARY);
     664           17633 :         REGISTER_CURL_CONSTANT(CURLE_PARTIAL_FILE);
     665           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_RETR_FILE);
     666           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_WRITE_ERROR);
     667           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_QUOTE_ERROR);
     668           17633 :         REGISTER_CURL_CONSTANT(CURLE_HTTP_NOT_FOUND);
     669           17633 :         REGISTER_CURL_CONSTANT(CURLE_WRITE_ERROR);
     670           17633 :         REGISTER_CURL_CONSTANT(CURLE_MALFORMAT_USER);
     671           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_STOR_FILE);
     672           17633 :         REGISTER_CURL_CONSTANT(CURLE_READ_ERROR);
     673           17633 :         REGISTER_CURL_CONSTANT(CURLE_OUT_OF_MEMORY);
     674           17633 :         REGISTER_CURL_CONSTANT(CURLE_OPERATION_TIMEOUTED);
     675           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_ASCII);
     676           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_PORT_FAILED);
     677           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_USE_REST);
     678           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_GET_SIZE);
     679           17633 :         REGISTER_CURL_CONSTANT(CURLE_HTTP_RANGE_ERROR);
     680           17633 :         REGISTER_CURL_CONSTANT(CURLE_HTTP_POST_ERROR);
     681           17633 :         REGISTER_CURL_CONSTANT(CURLE_SSL_CONNECT_ERROR);
     682           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_BAD_DOWNLOAD_RESUME);
     683           17633 :         REGISTER_CURL_CONSTANT(CURLE_FILE_COULDNT_READ_FILE);
     684           17633 :         REGISTER_CURL_CONSTANT(CURLE_LDAP_CANNOT_BIND);
     685           17633 :         REGISTER_CURL_CONSTANT(CURLE_LDAP_SEARCH_FAILED);
     686           17633 :         REGISTER_CURL_CONSTANT(CURLE_LIBRARY_NOT_FOUND);
     687           17633 :         REGISTER_CURL_CONSTANT(CURLE_FUNCTION_NOT_FOUND);
     688           17633 :         REGISTER_CURL_CONSTANT(CURLE_ABORTED_BY_CALLBACK);
     689           17633 :         REGISTER_CURL_CONSTANT(CURLE_BAD_FUNCTION_ARGUMENT);
     690           17633 :         REGISTER_CURL_CONSTANT(CURLE_BAD_CALLING_ORDER);
     691           17633 :         REGISTER_CURL_CONSTANT(CURLE_HTTP_PORT_FAILED);
     692           17633 :         REGISTER_CURL_CONSTANT(CURLE_BAD_PASSWORD_ENTERED);
     693           17633 :         REGISTER_CURL_CONSTANT(CURLE_TOO_MANY_REDIRECTS);
     694           17633 :         REGISTER_CURL_CONSTANT(CURLE_UNKNOWN_TELNET_OPTION);
     695           17633 :         REGISTER_CURL_CONSTANT(CURLE_TELNET_OPTION_SYNTAX);
     696           17633 :         REGISTER_CURL_CONSTANT(CURLE_OBSOLETE);
     697           17633 :         REGISTER_CURL_CONSTANT(CURLE_SSL_PEER_CERTIFICATE);
     698           17633 :         REGISTER_CURL_CONSTANT(CURLE_GOT_NOTHING);
     699           17633 :         REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_NOTFOUND);
     700           17633 :         REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_SETFAILED);
     701           17633 :         REGISTER_CURL_CONSTANT(CURLE_SEND_ERROR);
     702           17633 :         REGISTER_CURL_CONSTANT(CURLE_RECV_ERROR);
     703           17633 :         REGISTER_CURL_CONSTANT(CURLE_SHARE_IN_USE);
     704           17633 :         REGISTER_CURL_CONSTANT(CURLE_SSL_CERTPROBLEM);
     705           17633 :         REGISTER_CURL_CONSTANT(CURLE_SSL_CIPHER);
     706           17633 :         REGISTER_CURL_CONSTANT(CURLE_SSL_CACERT);
     707           17633 :         REGISTER_CURL_CONSTANT(CURLE_BAD_CONTENT_ENCODING);
     708                 : #if LIBCURL_VERSION_NUM >= 0x070a08
     709           17633 :         REGISTER_CURL_CONSTANT(CURLE_LDAP_INVALID_URL);
     710           17633 :         REGISTER_CURL_CONSTANT(CURLE_FILESIZE_EXCEEDED);
     711                 : #endif
     712                 : #if LIBCURL_VERSION_NUM >= 0x070b00
     713           17633 :         REGISTER_CURL_CONSTANT(CURLE_FTP_SSL_FAILED);
     714                 : #endif
     715           17633 :         REGISTER_CURL_CONSTANT(CURLPROXY_HTTP);
     716           17633 :         REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS4);
     717           17633 :         REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS5);
     718                 : 
     719           17633 :         REGISTER_CURL_CONSTANT(CURL_NETRC_OPTIONAL);
     720           17633 :         REGISTER_CURL_CONSTANT(CURL_NETRC_IGNORED);
     721           17633 :         REGISTER_CURL_CONSTANT(CURL_NETRC_REQUIRED);
     722                 : 
     723           17633 :         REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_NONE);
     724           17633 :         REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_0);
     725           17633 :         REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_1);
     726                 : 
     727           17633 :         REGISTER_CURL_CONSTANT(CURLM_CALL_MULTI_PERFORM);
     728           17633 :         REGISTER_CURL_CONSTANT(CURLM_OK);
     729           17633 :         REGISTER_CURL_CONSTANT(CURLM_BAD_HANDLE);
     730           17633 :         REGISTER_CURL_CONSTANT(CURLM_BAD_EASY_HANDLE);
     731           17633 :         REGISTER_CURL_CONSTANT(CURLM_OUT_OF_MEMORY);
     732           17633 :         REGISTER_CURL_CONSTANT(CURLM_INTERNAL_ERROR);
     733                 : 
     734           17633 :         REGISTER_CURL_CONSTANT(CURLMSG_DONE);
     735                 : 
     736                 : #if LIBCURL_VERSION_NUM >= 0x070c02
     737           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FTPSSLAUTH);
     738           17633 :         REGISTER_CURL_CONSTANT(CURLFTPAUTH_DEFAULT);
     739           17633 :         REGISTER_CURL_CONSTANT(CURLFTPAUTH_SSL);
     740           17633 :         REGISTER_CURL_CONSTANT(CURLFTPAUTH_TLS);
     741                 : #endif
     742                 : 
     743                 : #if LIBCURL_VERSION_NUM >  0x070b00
     744           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_SSL);
     745           17633 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_NONE);
     746           17633 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_TRY);
     747           17633 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_CONTROL);
     748           17633 :         REGISTER_CURL_CONSTANT(CURLFTPSSL_ALL);
     749                 : #endif
     750                 : 
     751                 : #if LIBCURL_VERSION_NUM > 0x071301
     752                 :         REGISTER_CURL_CONSTANT(CURLOPT_CERTINFO);
     753                 :         REGISTER_CURL_CONSTANT(CURLOPT_POSTREDIR);
     754                 : #endif
     755                 : 
     756                 : /* SSH support works in 7.19.0+ using libssh2 */
     757                 : #if LIBCURL_VERSION_NUM >= 0x071300
     758                 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_NONE);
     759                 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PUBLICKEY);
     760                 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PASSWORD);
     761                 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_HOST);
     762                 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_KEYBOARD);
     763                 :         REGISTER_CURL_CONSTANT(CURLSSH_AUTH_DEFAULT);
     764                 :         REGISTER_CURL_CONSTANT(CURLOPT_SSH_AUTH_TYPES);
     765                 :         REGISTER_CURL_CONSTANT(CURLOPT_KEYPASSWD);
     766                 :         REGISTER_CURL_CONSTANT(CURLOPT_SSH_PUBLIC_KEYFILE);
     767                 :         REGISTER_CURL_CONSTANT(CURLOPT_SSH_PRIVATE_KEYFILE);
     768                 :         REGISTER_CURL_CONSTANT(CURLOPT_SSH_HOST_PUBLIC_KEY_MD5);
     769                 :         REGISTER_CURL_CONSTANT(CURLE_SSH);
     770                 : #endif
     771                 : 
     772                 : #if LIBCURL_VERSION_NUM >= 0x071304
     773                 :         REGISTER_CURL_CONSTANT(CURLOPT_REDIR_PROTOCOLS);
     774                 :         REGISTER_CURL_CONSTANT(CURLOPT_PROTOCOLS);
     775                 :         REGISTER_CURL_CONSTANT(CURLPROTO_HTTP);
     776                 :         REGISTER_CURL_CONSTANT(CURLPROTO_HTTPS);
     777                 :         REGISTER_CURL_CONSTANT(CURLPROTO_FTP);
     778                 :         REGISTER_CURL_CONSTANT(CURLPROTO_FTPS);
     779                 :         REGISTER_CURL_CONSTANT(CURLPROTO_SCP);
     780                 :         REGISTER_CURL_CONSTANT(CURLPROTO_SFTP);
     781                 :         REGISTER_CURL_CONSTANT(CURLPROTO_TELNET);
     782                 :         REGISTER_CURL_CONSTANT(CURLPROTO_LDAP);
     783                 :         REGISTER_CURL_CONSTANT(CURLPROTO_LDAPS);
     784                 :         REGISTER_CURL_CONSTANT(CURLPROTO_DICT);
     785                 :         REGISTER_CURL_CONSTANT(CURLPROTO_FILE);
     786                 :         REGISTER_CURL_CONSTANT(CURLPROTO_TFTP);
     787                 :         REGISTER_CURL_CONSTANT(CURLPROTO_ALL);
     788                 : #endif
     789                 : 
     790                 : #if LIBCURL_VERSION_NUM >= 0x070f01
     791           17633 :         REGISTER_CURL_CONSTANT(CURLOPT_FTP_FILEMETHOD);
     792                 : #endif
     793                 : 
     794                 : #if LIBCURL_VERSION_NUM >= 0x071001
     795                 :         REGISTER_CURL_CONSTANT(CURLFTPMETHOD_MULTICWD);
     796                 :         REGISTER_CURL_CONSTANT(CURLFTPMETHOD_NOCWD);
     797                 :         REGISTER_CURL_CONSTANT(CURLFTPMETHOD_SINGLECWD);
     798                 : #endif
     799                 : 
     800                 : #ifdef PHP_CURL_NEED_OPENSSL_TSL
     801                 :         if (!CRYPTO_get_id_callback()) {
     802                 :                 int i, c = CRYPTO_num_locks();
     803                 : 
     804                 :                 php_curl_openssl_tsl = malloc(c * sizeof(MUTEX_T));
     805                 : 
     806                 :                 for (i = 0; i < c; ++i) {
     807                 :                         php_curl_openssl_tsl[i] = tsrm_mutex_alloc();
     808                 :                 }
     809                 : 
     810                 :                 CRYPTO_set_id_callback(php_curl_ssl_id);
     811                 :                 CRYPTO_set_locking_callback(php_curl_ssl_lock);
     812                 :         }
     813                 : #endif
     814                 : #ifdef PHP_CURL_NEED_GNUTLS_TSL
     815                 :         gcry_control(GCRYCTL_SET_THREAD_CBS, &php_curl_gnutls_tsl);
     816                 : #endif
     817                 : 
     818           17633 :         if (curl_global_init(CURL_GLOBAL_SSL) != CURLE_OK) {
     819               0 :                 return FAILURE;
     820                 :         }
     821                 : 
     822                 : #ifdef PHP_CURL_URL_WRAPPERS
     823                 : # if HAVE_CURL_VERSION_INFO
     824                 :         {
     825           17633 :                 curl_version_info_data *info = curl_version_info(CURLVERSION_NOW);
     826           17633 :                 char **p = (char **)info->protocols;
     827                 : 
     828          193963 :                 while (*p != NULL) {
     829                 :                         /* Do not enable cURL "file" protocol and make sure cURL is always used when --with-curlwrappers is enabled */
     830          158697 :                         if (strncasecmp(*p, "file", sizeof("file")-1) != 0) {
     831          141064 :                                 php_unregister_url_stream_wrapper(*p TSRMLS_CC);
     832          141064 :                                 php_register_url_stream_wrapper(*p, &php_curl_wrapper TSRMLS_CC);
     833                 :                         }
     834          158697 :                         (void) *p++;
     835                 :                 }
     836                 :         }
     837                 : # else
     838                 :         php_unregister_url_stream_wrapper("http");
     839                 :         php_register_url_stream_wrapper("http", &php_curl_wrapper TSRMLS_CC);
     840                 :         php_unregister_url_stream_wrapper("https");
     841                 :         php_register_url_stream_wrapper("https", &php_curl_wrapper TSRMLS_CC);
     842                 :         php_unregister_url_stream_wrapper("ftp");
     843                 :         php_register_url_stream_wrapper("ftp", &php_curl_wrapper TSRMLS_CC);
     844                 :         php_unregister_url_stream_wrapper("ftps");
     845                 :         php_register_url_stream_wrapper("ftps", &php_curl_wrapper TSRMLS_CC);
     846                 :         php_unregister_url_stream_wrapper("ldap");
     847                 :         php_register_url_stream_wrapper("ldap", &php_curl_wrapper TSRMLS_CC);
     848                 : # endif
     849                 : #endif
     850                 : 
     851           17633 :         return SUCCESS;
     852                 : }
     853                 : /* }}} */
     854                 : 
     855                 : /* {{{ PHP_MSHUTDOWN_FUNCTION
     856                 :  */
     857                 : PHP_MSHUTDOWN_FUNCTION(curl)
     858           17665 : {
     859                 : #ifdef PHP_CURL_URL_WRAPPERS
     860           17665 :         php_unregister_url_stream_wrapper("http" TSRMLS_CC);
     861           17665 :         php_unregister_url_stream_wrapper("https" TSRMLS_CC);
     862           17665 :         php_unregister_url_stream_wrapper("ftp" TSRMLS_CC);
     863           17665 :         php_unregister_url_stream_wrapper("ldap" TSRMLS_CC);
     864                 : #endif
     865           17665 :         curl_global_cleanup();
     866                 : #ifdef PHP_CURL_NEED_OPENSSL_TSL
     867                 :         if (php_curl_openssl_tsl) {
     868                 :                 int i, c = CRYPTO_num_locks();
     869                 : 
     870                 :                 CRYPTO_set_id_callback(NULL);
     871                 :                 CRYPTO_set_locking_callback(NULL);
     872                 : 
     873                 :                 for (i = 0; i < c; ++i) {
     874                 :                         tsrm_mutex_free(php_curl_openssl_tsl[i]);
     875                 :                 }
     876                 : 
     877                 :                 free(php_curl_openssl_tsl);
     878                 :                 php_curl_openssl_tsl = NULL;
     879                 :         }
     880                 : #endif
     881           17665 :         return SUCCESS;
     882                 : }
     883                 : /* }}} */
     884                 : 
     885                 : /* {{{ curl_write
     886                 :  */
     887                 : static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx)
     888              46 : {
     889              46 :         php_curl       *ch     = (php_curl *) ctx;
     890              46 :         php_curl_write *t      = ch->handlers->write;
     891              46 :         size_t          length = size * nmemb;
     892                 :         TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
     893                 : 
     894                 : #if PHP_CURL_DEBUG
     895                 :         fprintf(stderr, "curl_write() called\n");
     896                 :         fprintf(stderr, "data = %s, size = %d, nmemb = %d, ctx = %x\n", data, size, nmemb, ctx);
     897                 : #endif
     898                 : 
     899              46 :         switch (t->method) {
     900                 :                 case PHP_CURL_STDOUT:
     901              10 :                         PHPWRITE(data, length);
     902              10 :                         break;
     903                 :                 case PHP_CURL_FILE:
     904               2 :                         return fwrite(data, size, nmemb, t->fp);
     905                 :                 case PHP_CURL_RETURN:
     906              32 :                         if (length > 0) {
     907              32 :                                 smart_str_appendl(&t->buf, data, (int) length);
     908                 :                         }
     909              32 :                         break;
     910                 :                 case PHP_CURL_USER: {
     911                 :                         zval **argv[2];
     912               2 :                         zval *retval_ptr = NULL;
     913               2 :                         zval *handle = NULL;
     914               2 :                         zval *zdata = NULL;
     915                 :                         int   error;
     916                 :                         zend_fcall_info fci;
     917                 : 
     918               2 :                         MAKE_STD_ZVAL(handle);
     919               2 :                         ZVAL_RESOURCE(handle, ch->id);
     920               2 :                         zend_list_addref(ch->id);
     921               2 :                         argv[0] = &handle;
     922                 : 
     923               2 :                         MAKE_STD_ZVAL(zdata);
     924               2 :                         ZVAL_STRINGL(zdata, data, length, 1);
     925               2 :                         argv[1] = &zdata;
     926                 : 
     927               2 :                         fci.size = sizeof(fci);
     928               2 :                         fci.function_table = EG(function_table);
     929               2 :                         fci.object_ptr = NULL;
     930               2 :                         fci.function_name = t->func_name;
     931               2 :                         fci.retval_ptr_ptr = &retval_ptr;
     932               2 :                         fci.param_count = 2;
     933               2 :                         fci.params = argv;
     934               2 :                         fci.no_separation = 0;
     935               2 :                         fci.symbol_table = NULL;
     936                 : 
     937               2 :                         ch->in_callback = 1;
     938               2 :                         error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC);
     939               2 :                         ch->in_callback = 0;
     940               2 :                         if (error == FAILURE) {
     941               0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the CURLOPT_WRITEFUNCTION");
     942               0 :                                 length = -1;
     943               2 :                         } else if (retval_ptr) {
     944               2 :                                 if (Z_TYPE_P(retval_ptr) != IS_LONG) {
     945               0 :                                         convert_to_long_ex(&retval_ptr);
     946                 :                                 }
     947               2 :                                 length = Z_LVAL_P(retval_ptr);
     948               2 :                                 zval_ptr_dtor(&retval_ptr);
     949                 :                         }
     950                 : 
     951               2 :                         zval_ptr_dtor(argv[0]);
     952               2 :                         zval_ptr_dtor(argv[1]);
     953                 :                         break;
     954                 :                 }
     955                 :         }
     956                 : 
     957              44 :         return length;
     958                 : }
     959                 : /* }}} */
     960                 : 
     961                 : /* {{{ curl_progress
     962                 :  */
     963                 : static size_t curl_progress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
     964               0 : {
     965               0 :         php_curl       *ch = (php_curl *) clientp;
     966               0 :         php_curl_progress  *t  = ch->handlers->progress;
     967               0 :         int             length = -1;
     968               0 :         size_t  rval = 0;
     969                 : 
     970                 : #if PHP_CURL_DEBUG
     971                 :         fprintf(stderr, "curl_progress() called\n");
     972                 :         fprintf(stderr, "clientp = %x, dltotal = %f, dlnow = %f, ultotal = %f, ulnow = %f\n", clientp, dltotal, dlnow, ultotal, ulnow);
     973                 : #endif
     974                 : 
     975               0 :         switch (t->method) {
     976                 :                 case PHP_CURL_USER: {
     977                 :                         zval **argv[4];
     978               0 :                         zval  *zdltotal = NULL;
     979               0 :                         zval  *zdlnow = NULL;
     980               0 :                         zval  *zultotal = NULL;
     981               0 :                         zval  *zulnow = NULL;
     982                 :                         zval  *retval_ptr;
     983                 :                         int   error;
     984                 :                         zend_fcall_info fci;
     985                 :                         TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
     986                 : 
     987               0 :                         MAKE_STD_ZVAL(zdltotal);
     988               0 :                         MAKE_STD_ZVAL(zdlnow);
     989               0 :                         MAKE_STD_ZVAL(zultotal);
     990               0 :                         MAKE_STD_ZVAL(zulnow);
     991                 : 
     992               0 :                         ZVAL_LONG(zdltotal, (long) dltotal);
     993               0 :                         ZVAL_LONG(zdlnow, (long) dlnow);
     994               0 :                         ZVAL_LONG(zultotal, (long) ultotal);
     995               0 :                         ZVAL_LONG(zulnow, (long) ulnow);
     996                 : 
     997               0 :                         argv[0] = &zdltotal;
     998               0 :                         argv[1] = &zdlnow;
     999               0 :                         argv[2] = &zultotal;
    1000               0 :                         argv[3] = &zulnow;
    1001                 : 
    1002               0 :                         fci.size = sizeof(fci);
    1003               0 :                         fci.function_table = EG(function_table);
    1004               0 :                         fci.function_name = t->func_name;
    1005               0 :                         fci.object_ptr = NULL;
    1006               0 :                         fci.retval_ptr_ptr = &retval_ptr;
    1007               0 :                         fci.param_count = 4;
    1008               0 :                         fci.params = argv;
    1009               0 :                         fci.no_separation = 0;
    1010               0 :                         fci.symbol_table = NULL;
    1011                 : 
    1012               0 :                         ch->in_callback = 1;
    1013               0 :                         error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC);
    1014               0 :                         ch->in_callback = 0;
    1015               0 :                         if (error == FAILURE) {
    1016               0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot call the CURLOPT_PROGRESSFUNCTION");
    1017               0 :                                 length = -1;
    1018               0 :                         } else if (retval_ptr) {
    1019               0 :                                 if (Z_TYPE_P(retval_ptr) != IS_LONG) {
    1020               0 :                                         convert_to_long_ex(&retval_ptr);
    1021                 :                                 }
    1022               0 :                                 if (0 != Z_LVAL_P(retval_ptr)) {
    1023               0 :                                         rval = 1;
    1024                 :                                 }
    1025               0 :                                 zval_ptr_dtor(&retval_ptr);
    1026                 :                         }
    1027               0 :                         zval_ptr_dtor(argv[0]);
    1028               0 :                         zval_ptr_dtor(argv[1]);
    1029               0 :                         zval_ptr_dtor(argv[2]);
    1030               0 :                         zval_ptr_dtor(argv[3]);
    1031                 :                         break;
    1032                 :                 }
    1033                 :         }
    1034               0 :         return rval;
    1035                 : }
    1036                 : /* }}} */
    1037                 : 
    1038                 : /* {{{ curl_read
    1039                 :  */
    1040                 : static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx)
    1041               4 : {
    1042               4 :         php_curl       *ch = (php_curl *) ctx;
    1043               4 :         php_curl_read  *t  = ch->handlers->read;
    1044               4 :         int             length = 0;
    1045                 : 
    1046               4 :         switch (t->method) {
    1047                 :                 case PHP_CURL_DIRECT:
    1048               2 :                         if (t->fp) {
    1049               2 :                                 length = fread(data, size, nmemb, t->fp);
    1050                 :                         }
    1051               2 :                         break;
    1052                 :                 case PHP_CURL_USER: {
    1053                 :                         zval **argv[3];
    1054               2 :                         zval  *handle = NULL;
    1055               2 :                         zval  *zfd = NULL;
    1056               2 :                         zval  *zlength = NULL;
    1057                 :                         zval  *retval_ptr;
    1058                 :                         int   error;
    1059                 :                         zend_fcall_info fci;
    1060                 :                         TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
    1061                 : 
    1062               2 :                         MAKE_STD_ZVAL(handle);
    1063               2 :                         MAKE_STD_ZVAL(zfd);
    1064               2 :                         MAKE_STD_ZVAL(zlength);
    1065                 : 
    1066               2 :                         ZVAL_RESOURCE(handle, ch->id);
    1067               2 :                         zend_list_addref(ch->id);
    1068               2 :                         ZVAL_RESOURCE(zfd, t->fd);
    1069               2 :                         zend_list_addref(t->fd);
    1070               2 :                         ZVAL_LONG(zlength, (int) size * nmemb);
    1071                 : 
    1072               2 :                         argv[0] = &handle;
    1073               2 :                         argv[1] = &zfd;
    1074               2 :                         argv[2] = &zlength;
    1075                 : 
    1076               2 :                         fci.size = sizeof(fci);
    1077               2 :                         fci.function_table = EG(function_table);
    1078               2 :                         fci.function_name = t->func_name;
    1079               2 :                         fci.object_ptr = NULL;
    1080               2 :                         fci.retval_ptr_ptr = &retval_ptr;
    1081               2 :                         fci.param_count = 3;
    1082               2 :                         fci.params = argv;
    1083               2 :                         fci.no_separation = 0;
    1084               2 :                         fci.symbol_table = NULL;
    1085                 : 
    1086               2 :                         ch->in_callback = 1;
    1087               2 :                         error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC);
    1088               2 :                         ch->in_callback = 0;
    1089               2 :                         if (error == FAILURE) {
    1090               0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot call the CURLOPT_READFUNCTION");
    1091                 : #if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */
    1092               0 :                                 length = CURL_READFUNC_ABORT;
    1093                 : #endif
    1094               2 :                         } else if (retval_ptr) {
    1095               2 :                                 if (Z_TYPE_P(retval_ptr) == IS_STRING) {
    1096               2 :                                         length = MIN((int) (size * nmemb), Z_STRLEN_P(retval_ptr));
    1097               2 :                                         memcpy(data, Z_STRVAL_P(retval_ptr), length);
    1098                 :                                 }
    1099               2 :                                 zval_ptr_dtor(&retval_ptr);
    1100                 :                         }
    1101                 : 
    1102               2 :                         zval_ptr_dtor(argv[0]);
    1103               2 :                         zval_ptr_dtor(argv[1]);
    1104               2 :                         zval_ptr_dtor(argv[2]);
    1105                 :                         break;
    1106                 :                 }
    1107                 :         }
    1108                 : 
    1109               4 :         return length;
    1110                 : }
    1111                 : /* }}} */
    1112                 : 
    1113                 : /* {{{ curl_write_header
    1114                 :  */
    1115                 : static size_t curl_write_header(char *data, size_t size, size_t nmemb, void *ctx)
    1116             280 : {
    1117             280 :         php_curl       *ch  = (php_curl *) ctx;
    1118             280 :         php_curl_write *t   = ch->handlers->write_header;
    1119             280 :         size_t          length = size * nmemb;
    1120                 :         TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
    1121                 : 
    1122             280 :         switch (t->method) {
    1123                 :                 case PHP_CURL_STDOUT:
    1124                 :                         /* Handle special case write when we're returning the entire transfer
    1125                 :                          */
    1126               0 :                         if (ch->handlers->write->method == PHP_CURL_RETURN && length > 0) {
    1127               0 :                                 smart_str_appendl(&ch->handlers->write->buf, data, (int) length);
    1128                 :                         } else {
    1129               0 :                                 PHPWRITE(data, length);
    1130                 :                         }
    1131               0 :                         break;
    1132                 :                 case PHP_CURL_FILE:
    1133               0 :                         return fwrite(data, size, nmemb, t->fp);
    1134                 :                 case PHP_CURL_USER: {
    1135                 :                         zval **argv[2];
    1136               1 :                         zval  *handle = NULL;
    1137               1 :                         zval  *zdata = NULL;
    1138                 :                         zval  *retval_ptr;
    1139                 :                         int   error;
    1140                 :                         zend_fcall_info fci;
    1141                 : 
    1142               1 :                         MAKE_STD_ZVAL(handle);
    1143               1 :                         MAKE_STD_ZVAL(zdata);
    1144                 : 
    1145               1 :                         ZVAL_RESOURCE(handle, ch->id);
    1146               1 :                         zend_list_addref(ch->id);
    1147               1 :                         ZVAL_STRINGL(zdata, data, length, 1);
    1148                 : 
    1149               1 :                         argv[0] = &handle;
    1150               1 :                         argv[1] = &zdata;
    1151                 : 
    1152               1 :                         fci.size = sizeof(fci);
    1153               1 :                         fci.function_table = EG(function_table);
    1154               1 :                         fci.function_name = t->func_name;
    1155               1 :                         fci.symbol_table = NULL;
    1156               1 :                         fci.object_ptr = NULL;
    1157               1 :                         fci.retval_ptr_ptr = &retval_ptr;
    1158               1 :                         fci.param_count = 2;
    1159               1 :                         fci.params = argv;
    1160               1 :                         fci.no_separation = 0;
    1161                 : 
    1162               1 :                         ch->in_callback = 1;
    1163               1 :                         error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC);
    1164               1 :                         ch->in_callback = 0;
    1165               1 :                         if (error == FAILURE) {
    1166               0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the CURLOPT_HEADERFUNCTION");
    1167               0 :                                 length = -1;
    1168               1 :                         } else if (retval_ptr) {
    1169               1 :                                 if (Z_TYPE_P(retval_ptr) != IS_LONG) {
    1170               1 :                                         convert_to_long_ex(&retval_ptr);
    1171                 :                                 }
    1172               1 :                                 length = Z_LVAL_P(retval_ptr);
    1173               1 :                                 zval_ptr_dtor(&retval_ptr);
    1174                 :                         }
    1175               1 :                         zval_ptr_dtor(argv[0]);
    1176               1 :                         zval_ptr_dtor(argv[1]);
    1177               1 :                         break;
    1178                 :                 }
    1179                 : 
    1180                 :                 case PHP_CURL_IGNORE:
    1181             279 :                         return length;
    1182                 : 
    1183                 :                 default:
    1184               0 :                         return -1;
    1185                 :         }
    1186                 : 
    1187               1 :         return length;
    1188                 : }
    1189                 : /* }}} */
    1190                 : 
    1191                 : static int curl_debug(CURL *cp, curl_infotype type, char *buf, size_t buf_len, void *ctx) /* {{{ */
    1192               0 : {
    1193               0 :         php_curl    *ch   = (php_curl *) ctx;
    1194                 : 
    1195               0 :         if (type == CURLINFO_HEADER_OUT) {
    1196               0 :                 if (ch->header.str_len) {
    1197               0 :                         efree(ch->header.str);
    1198                 :                 }
    1199               0 :                 if (buf_len > 0) {
    1200               0 :                         ch->header.str = estrndup(buf, buf_len);
    1201               0 :                         ch->header.str_len = buf_len;
    1202                 :                 }
    1203                 :         }
    1204                 : 
    1205               0 :         return 0;
    1206                 : }
    1207                 : /* }}} */
    1208                 : 
    1209                 : #if CURLOPT_PASSWDFUNCTION != 0
    1210                 : /* {{{ curl_passwd
    1211                 :  */
    1212                 : static size_t curl_passwd(void *ctx, char *prompt, char *buf, int buflen)
    1213               0 : {
    1214               0 :         php_curl    *ch   = (php_curl *) ctx;
    1215               0 :         zval        *func = ch->handlers->passwd;
    1216                 :         zval        *argv[3];
    1217               0 :         zval        *retval = NULL;
    1218                 :         int          error;
    1219               0 :         int          ret = -1;
    1220                 :         TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
    1221                 : 
    1222               0 :         MAKE_STD_ZVAL(argv[0]);
    1223               0 :         MAKE_STD_ZVAL(argv[1]);
    1224               0 :         MAKE_STD_ZVAL(argv[2]);
    1225                 : 
    1226               0 :         ZVAL_RESOURCE(argv[0], ch->id);
    1227               0 :         zend_list_addref(ch->id);
    1228               0 :         ZVAL_STRING(argv[1], prompt, 1);
    1229               0 :         ZVAL_LONG(argv[2], buflen);
    1230                 : 
    1231               0 :         error = call_user_function(EG(function_table), NULL, func, retval, 2, argv TSRMLS_CC);
    1232               0 :         if (error == FAILURE) {
    1233               0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the CURLOPT_PASSWDFUNCTION");
    1234               0 :         } else if (Z_TYPE_P(retval) == IS_STRING) {
    1235               0 :                 if (Z_STRLEN_P(retval) > buflen) {
    1236               0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Returned password is too long for libcurl to handle");
    1237                 :                 } else {
    1238               0 :                         strlcpy(buf, Z_STRVAL_P(retval), Z_STRLEN_P(retval));
    1239                 :                 }
    1240                 :         } else {
    1241               0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "User handler '%s' did not return a string", Z_STRVAL_P(func));
    1242                 :         }
    1243                 : 
    1244               0 :         zval_ptr_dtor(&argv[0]);
    1245               0 :         zval_ptr_dtor(&argv[1]);
    1246               0 :         zval_ptr_dtor(&argv[2]);
    1247               0 :         zval_ptr_dtor(&retval);
    1248                 : 
    1249               0 :         return ret;
    1250                 : }
    1251                 : /* }}} */
    1252                 : #endif
    1253                 : 
    1254                 : #if LIBCURL_VERSION_NUM < 0x071101
    1255                 : /* {{{ curl_free_string
    1256                 :  */
    1257                 : static void curl_free_string(void **string)
    1258              65 : {
    1259              65 :         efree(*string);
    1260              65 : }
    1261                 : /* }}} */
    1262                 : #endif
    1263                 : 
    1264                 : /* {{{ curl_free_post
    1265                 :  */
    1266                 : static void curl_free_post(void **post)
    1267               1 : {
    1268               1 :         curl_formfree((struct HttpPost *) *post);
    1269               1 : }
    1270                 : /* }}} */
    1271                 : 
    1272                 : /* {{{ curl_free_slist
    1273                 :  */
    1274                 : static void curl_free_slist(void **slist)
    1275               3 : {
    1276               3 :         curl_slist_free_all((struct curl_slist *) *slist);
    1277               3 : }
    1278                 : /* }}} */
    1279                 : 
    1280                 : /* {{{ proto array curl_version([int version])
    1281                 :    Return cURL version information. */
    1282                 : PHP_FUNCTION(curl_version)
    1283              27 : {
    1284                 :         curl_version_info_data *d;
    1285              27 :         long uversion = CURLVERSION_NOW;
    1286                 : 
    1287              27 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &uversion) == FAILURE) {
    1288               8 :                 return;
    1289                 :         }
    1290                 : 
    1291              19 :         d = curl_version_info(uversion);
    1292              19 :         if (d == NULL) {
    1293               0 :                 RETURN_FALSE;
    1294                 :         }
    1295                 : 
    1296              19 :         array_init(return_value);
    1297                 : 
    1298              19 :         CAAL("version_number", d->version_num);
    1299              19 :         CAAL("age", d->age);
    1300              19 :         CAAL("features", d->features);
    1301              19 :         CAAL("ssl_version_number", d->ssl_version_num);
    1302              19 :         CAAS("version", d->version);
    1303              19 :         CAAS("host", d->host);
    1304              19 :         CAAS("ssl_version", d->ssl_version);
    1305              19 :         CAAS("libz_version", d->libz_version);
    1306                 :         /* Add an array of protocols */
    1307                 :         {
    1308              19 :                 char **p = (char **) d->protocols;
    1309              19 :                 zval  *protocol_list = NULL;
    1310                 : 
    1311              19 :                 MAKE_STD_ZVAL(protocol_list);
    1312              19 :                 array_init(protocol_list);
    1313                 : 
    1314             209 :                 while (*p != NULL) {
    1315             171 :                         add_next_index_string(protocol_list, *p, 1);
    1316             171 :                         p++;
    1317                 :                 }
    1318              19 :                 CAAZ("protocols", protocol_list);
    1319                 :         }
    1320                 : }
    1321                 : /* }}} */
    1322                 : 
    1323                 : /* {{{ alloc_curl_handle
    1324                 :  */
    1325                 : static void alloc_curl_handle(php_curl **ch)
    1326              75 : {
    1327              75 :         *ch                           = emalloc(sizeof(php_curl));
    1328              75 :         (*ch)->handlers               = ecalloc(1, sizeof(php_curl_handlers));
    1329              75 :         (*ch)->handlers->write        = ecalloc(1, sizeof(php_curl_write));
    1330              75 :         (*ch)->handlers->write_header = ecalloc(1, sizeof(php_curl_write));
    1331              75 :         (*ch)->handlers->read         = ecalloc(1, sizeof(php_curl_read));
    1332              75 :         (*ch)->handlers->progress     = ecalloc(1, sizeof(php_curl_progress));
    1333                 : 
    1334              75 :         (*ch)->in_callback = 0;
    1335              75 :         (*ch)->header.str_len = 0;
    1336                 : 
    1337              75 :         memset(&(*ch)->err, 0, sizeof((*ch)->err));
    1338                 : 
    1339                 : #if LIBCURL_VERSION_NUM < 0x071101
    1340              75 :         zend_llist_init(&(*ch)->to_free.str,   sizeof(char *),            (llist_dtor_func_t) curl_free_string, 0);
    1341                 : #endif
    1342              75 :         zend_llist_init(&(*ch)->to_free.slist, sizeof(struct curl_slist), (llist_dtor_func_t) curl_free_slist,  0);
    1343              75 :         zend_llist_init(&(*ch)->to_free.post,  sizeof(struct HttpPost),   (llist_dtor_func_t) curl_free_post,   0);
    1344              75 : }
    1345                 : /* }}} */
    1346                 : 
    1347                 : #if LIBCURL_VERSION_NUM > 0x071301
    1348                 : /* {{{ split_certinfo
    1349                 :  */
    1350                 : static void split_certinfo(char *string, zval *hash)
    1351                 : {
    1352                 :         char *org = estrdup(string);
    1353                 :         char *s = org;
    1354                 :         char *split;
    1355                 : 
    1356                 :         if(org) {
    1357                 :         do {
    1358                 :                         char *key;
    1359                 :                         char *val;
    1360                 :                         char *tmp;
    1361                 : 
    1362                 :             split = strstr(s, "; ");
    1363                 :             if(split)
    1364                 :                 *split = '\0';
    1365                 :                         
    1366                 :                         key = s;
    1367                 :                         tmp = memchr(key, '=', 64);
    1368                 :                         if(tmp) {
    1369                 :                                 *tmp = '\0';
    1370                 :                                 val = tmp+1;
    1371                 :                                 add_assoc_string(hash, key, val, 1);
    1372                 :                         }
    1373                 :                         s = split+2;
    1374                 :                 } while(split);
    1375                 :                 efree(org);
    1376                 :         }
    1377                 : }
    1378                 : 
    1379                 : /* {{{ create_certinfo
    1380                 :  */
    1381                 : static void create_certinfo(struct curl_certinfo *ci, zval *listcode TSRMLS_DC)
    1382                 : {
    1383                 :         int i;
    1384                 :                         
    1385                 :         if(ci) {
    1386                 :                 zval *certhash = NULL;
    1387                 :                 
    1388                 :                 for(i=0; i<ci->num_of_certs; i++) {
    1389                 :                         struct curl_slist *slist;
    1390                 :                         
    1391                 :                         MAKE_STD_ZVAL(certhash);
    1392                 :                         array_init(certhash);
    1393                 :                         for(slist = ci->certinfo[i]; slist; slist = slist->next) {
    1394                 :                                 int len;
    1395                 :                                 char s[64];
    1396                 :                                 char *tmp;
    1397                 :                                 strncpy(s, slist->data, 64);
    1398                 :                                 tmp = memchr(s, ':', 64);
    1399                 :                                 if(tmp) {
    1400                 :                                         *tmp = '\0';
    1401                 :                                         len = strlen(s);
    1402                 :                                         if(!strcmp(s, "Subject") || !strcmp(s, "Issuer")) {
    1403                 :                                                 zval *hash;
    1404                 : 
    1405                 :                                                 MAKE_STD_ZVAL(hash);
    1406                 :                                                 array_init(hash);
    1407                 :                                                 
    1408                 :                                                 split_certinfo(&slist->data[len+1], hash);
    1409                 :                                                 add_assoc_zval(certhash, s, hash);
    1410                 :                                         } else {
    1411                 :                                                 add_assoc_string(certhash, s, &slist->data[len+1], 1);
    1412                 :                                         }
    1413                 :                                 } else {
    1414                 :                                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not extract hash key from certificate info"); 
    1415                 :                                 }
    1416                 :                         }
    1417                 :                         add_next_index_zval(listcode, certhash);
    1418                 :                 }
    1419                 :         }
    1420                 : }
    1421                 : /* }}} */
    1422                 : #endif
    1423                 : 
    1424                 : /* {{{ proto resource curl_init([string url])
    1425                 :    Initialize a cURL session */
    1426                 : PHP_FUNCTION(curl_init)
    1427              66 : {
    1428                 :         php_curl        *ch;
    1429                 :         CURL            *cp;
    1430                 :         zval            *clone;
    1431              66 :         char            *url = NULL;
    1432              66 :         int             url_len = 0;
    1433                 : 
    1434              66 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &url, &url_len) == FAILURE) {
    1435               0 :                 return;
    1436                 :         }
    1437                 : 
    1438              66 :         cp = curl_easy_init();
    1439              66 :         if (!cp) {
    1440               0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not initialize a new cURL handle");
    1441               0 :                 RETURN_FALSE;
    1442                 :         }
    1443                 : 
    1444              66 :         alloc_curl_handle(&ch);
    1445                 :         TSRMLS_SET_CTX(ch->thread_ctx);
    1446                 : 
    1447              66 :         ch->cp = cp;
    1448                 : 
    1449              66 :         ch->handlers->write->method = PHP_CURL_STDOUT;
    1450              66 :         ch->handlers->write->type   = PHP_CURL_ASCII;
    1451              66 :         ch->handlers->read->method  = PHP_CURL_DIRECT;
    1452              66 :         ch->handlers->write_header->method = PHP_CURL_IGNORE;
    1453                 : 
    1454              66 :         ch->uses = 0;
    1455                 : 
    1456              66 :         MAKE_STD_ZVAL(clone);
    1457              66 :         ch->clone = clone;
    1458                 : 
    1459              66 :         curl_easy_setopt(ch->cp, CURLOPT_NOPROGRESS,        1);
    1460              66 :         curl_easy_setopt(ch->cp, CURLOPT_VERBOSE,           0);
    1461              66 :         curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER,       ch->err.str);
    1462              66 :         curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION,     curl_write);
    1463              66 :         curl_easy_setopt(ch->cp, CURLOPT_FILE,              (void *) ch);
    1464              66 :         curl_easy_setopt(ch->cp, CURLOPT_READFUNCTION,      curl_read);
    1465              66 :         curl_easy_setopt(ch->cp, CURLOPT_INFILE,            (void *) ch);
    1466              66 :         curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION,    curl_write_header);
    1467              66 :         curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER,       (void *) ch);
    1468              66 :         curl_easy_setopt(ch->cp, CURLOPT_DNS_USE_GLOBAL_CACHE, 1);
    1469              66 :         curl_easy_setopt(ch->cp, CURLOPT_DNS_CACHE_TIMEOUT, 120);
    1470              66 :         curl_easy_setopt(ch->cp, CURLOPT_MAXREDIRS, 20); /* prevent infinite redirects */
    1471                 : #if defined(ZTS)
    1472                 :         curl_easy_setopt(ch->cp, CURLOPT_NOSIGNAL, 1);
    1473                 : #endif
    1474                 : 
    1475              66 :         if (url) {
    1476               5 :                 if (!php_curl_option_url(ch, url, url_len)) {
    1477               0 :                         _php_curl_close_ex(ch TSRMLS_CC);
    1478               0 :                         RETURN_FALSE;
    1479                 :                 }
    1480                 :         }
    1481                 : 
    1482              66 :         ZEND_REGISTER_RESOURCE(return_value, ch, le_curl);
    1483              66 :         ch->id = Z_LVAL_P(return_value);
    1484                 : }
    1485                 : /* }}} */
    1486                 : 
    1487                 : /* {{{ proto resource curl_copy_handle(resource ch)
    1488                 :    Copy a cURL handle along with all of it's preferences */
    1489                 : PHP_FUNCTION(curl_copy_handle)
    1490               9 : {
    1491                 :         CURL            *cp;
    1492                 :         zval            *zid;
    1493                 :         php_curl        *ch, *dupch;
    1494                 : 
    1495               9 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
    1496               0 :                 return;
    1497                 :         }
    1498                 : 
    1499               9 :         ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
    1500                 : 
    1501               9 :         cp = curl_easy_duphandle(ch->cp);
    1502               9 :         if (!cp) {
    1503               0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot duplicate cURL handle");
    1504               0 :                 RETURN_FALSE;
    1505                 :         }
    1506                 : 
    1507               9 :         alloc_curl_handle(&dupch);
    1508                 :         TSRMLS_SET_CTX(dupch->thread_ctx);
    1509                 : 
    1510               9 :         dupch->cp = cp;
    1511               9 :         dupch->uses = 0;
    1512               9 :         if (ch->handlers->write->stream) {
    1513               0 :                 Z_ADDREF_P(dupch->handlers->write->stream);
    1514               0 :                 dupch->handlers->write->stream = ch->handlers->write->stream;
    1515                 :         }
    1516               9 :         dupch->handlers->write->method = ch->handlers->write->method;
    1517               9 :         dupch->handlers->write->type   = ch->handlers->write->type;
    1518               9 :         if (ch->handlers->read->stream) {
    1519               0 :                 Z_ADDREF_P(ch->handlers->read->stream);
    1520                 :         }
    1521               9 :         dupch->handlers->read->stream  = ch->handlers->read->stream;
    1522               9 :         dupch->handlers->read->method  = ch->handlers->read->method;
    1523               9 :         dupch->handlers->write_header->method = ch->handlers->write_header->method;
    1524               9 :         if (ch->handlers->write_header->stream) {
    1525               0 :                 Z_ADDREF_P(ch->handlers->write_header->stream);
    1526                 :         }
    1527               9 :         dupch->handlers->write_header->stream = ch->handlers->write_header->stream;
    1528                 : 
    1529               9 :         dupch->handlers->write->fp = ch->handlers->write->fp;
    1530               9 :         dupch->handlers->write_header->fp = ch->handlers->write_header->fp;
    1531               9 :         dupch->handlers->read->fp = ch->handlers->read->fp;
    1532               9 :         dupch->handlers->read->fd = ch->handlers->read->fd;
    1533                 : #if CURLOPT_PASSWDDATA != 0
    1534               9 :         if (ch->handlers->passwd) {
    1535               0 :                 zval_add_ref(&ch->handlers->passwd);
    1536               0 :                 dupch->handlers->passwd = ch->handlers->passwd;
    1537               0 :                 curl_easy_setopt(ch->cp, CURLOPT_PASSWDDATA, (void *) dupch);
    1538                 :         }
    1539                 : #endif
    1540               9 :         if (ch->handlers->write->func_name) {
    1541               0 :                 zval_add_ref(&ch->handlers->write->func_name);
    1542               0 :                 dupch->handlers->write->func_name = ch->handlers->write->func_name;
    1543                 :         }
    1544               9 :         if (ch->handlers->read->func_name) {
    1545               0 :                 zval_add_ref(&ch->handlers->read->func_name);
    1546               0 :                 dupch->handlers->read->func_name = ch->handlers->read->func_name;
    1547                 :         }
    1548               9 :         if (ch->handlers->write_header->func_name) {
    1549               0 :                 zval_add_ref(&ch->handlers->write_header->func_name);
    1550               0 :                 dupch->handlers->write_header->func_name = ch->handlers->write_header->func_name;
    1551                 :         }
    1552                 : 
    1553               9 :         curl_easy_setopt(dupch->cp, CURLOPT_ERRORBUFFER,       dupch->err.str);
    1554               9 :         curl_easy_setopt(dupch->cp, CURLOPT_FILE,              (void *) dupch);
    1555               9 :         curl_easy_setopt(dupch->cp, CURLOPT_INFILE,            (void *) dupch);
    1556               9 :         curl_easy_setopt(dupch->cp, CURLOPT_WRITEHEADER,       (void *) dupch);
    1557                 : 
    1558                 : #if LIBCURL_VERSION_NUM < 0x071101
    1559               9 :         zend_llist_copy(&dupch->to_free.str, &ch->to_free.str);
    1560                 :         /* Don't try to free copied strings, they're free'd when the original handle is destroyed */
    1561               9 :         dupch->to_free.str.dtor = NULL;
    1562                 : #endif
    1563               9 :         zend_llist_copy(&dupch->to_free.slist, &ch->to_free.slist);
    1564               9 :         zend_llist_copy(&dupch->to_free.post, &ch->to_free.post);
    1565                 : 
    1566                 :         /* Keep track of cloned copies to avoid invoking curl destructors for every clone */
    1567               9 :         Z_ADDREF_P(ch->clone);
    1568               9 :         dupch->clone = ch->clone;
    1569                 : 
    1570               9 :         ZEND_REGISTER_RESOURCE(return_value, dupch, le_curl);
    1571               9 :         dupch->id = Z_LVAL_P(return_value);
    1572                 : }
    1573                 : /* }}} */
    1574                 : 
    1575                 : static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *return_value TSRMLS_DC) /* {{{ */
    1576             130 : {
    1577             130 :         CURLcode     error=CURLE_OK;
    1578                 : 
    1579             130 :         switch (option) {
    1580                 :                 case CURLOPT_INFILESIZE:
    1581                 :                 case CURLOPT_VERBOSE:
    1582                 :                 case CURLOPT_HEADER:
    1583                 :                 case CURLOPT_NOPROGRESS:
    1584                 :                 case CURLOPT_NOBODY:
    1585                 :                 case CURLOPT_FAILONERROR:
    1586                 :                 case CURLOPT_UPLOAD:
    1587                 :                 case CURLOPT_POST:
    1588                 :                 case CURLOPT_FTPLISTONLY:
    1589                 :                 case CURLOPT_FTPAPPEND:
    1590                 :                 case CURLOPT_NETRC:
    1591                 :                 case CURLOPT_PUT:
    1592                 : #if CURLOPT_MUTE != 0
    1593                 :                  case CURLOPT_MUTE:
    1594                 : #endif
    1595                 :                 case CURLOPT_TIMEOUT:
    1596                 : #if LIBCURL_VERSION_NUM > 0x071002
    1597                 :                 case CURLOPT_TIMEOUT_MS:
    1598                 : #endif
    1599                 :                 case CURLOPT_FTP_USE_EPSV:
    1600                 :                 case CURLOPT_LOW_SPEED_LIMIT:
    1601                 :                 case CURLOPT_SSLVERSION:
    1602                 :                 case CURLOPT_LOW_SPEED_TIME:
    1603                 :                 case CURLOPT_RESUME_FROM:
    1604                 :                 case CURLOPT_TIMEVALUE:
    1605                 :                 case CURLOPT_TIMECONDITION:
    1606                 :                 case CURLOPT_TRANSFERTEXT:
    1607                 :                 case CURLOPT_HTTPPROXYTUNNEL:
    1608                 :                 case CURLOPT_FILETIME:
    1609                 :                 case CURLOPT_MAXREDIRS:
    1610                 :                 case CURLOPT_MAXCONNECTS:
    1611                 :                 case CURLOPT_CLOSEPOLICY:
    1612                 :                 case CURLOPT_FRESH_CONNECT:
    1613                 :                 case CURLOPT_FORBID_REUSE:
    1614                 :                 case CURLOPT_CONNECTTIMEOUT:
    1615                 : #if LIBCURL_VERSION_NUM > 0x071002
    1616                 :                 case CURLOPT_CONNECTTIMEOUT_MS:
    1617                 : #endif
    1618                 :                 case CURLOPT_SSL_VERIFYHOST:
    1619                 :                 case CURLOPT_SSL_VERIFYPEER:
    1620                 :                 case CURLOPT_DNS_USE_GLOBAL_CACHE:
    1621                 :                 case CURLOPT_NOSIGNAL:
    1622                 :                 case CURLOPT_PROXYTYPE:
    1623                 :                 case CURLOPT_BUFFERSIZE:
    1624                 :                 case CURLOPT_HTTPGET:
    1625                 :                 case CURLOPT_HTTP_VERSION:
    1626                 :                 case CURLOPT_CRLF:
    1627                 :                 case CURLOPT_DNS_CACHE_TIMEOUT:
    1628                 :                 case CURLOPT_PROXYPORT:
    1629                 :                 case CURLOPT_FTP_USE_EPRT:
    1630                 : #if LIBCURL_VERSION_NUM > 0x070a05 /* CURLOPT_HTTPAUTH is available since curl 7.10.6 */
    1631                 :                 case CURLOPT_HTTPAUTH:
    1632                 : #endif
    1633                 : #if LIBCURL_VERSION_NUM > 0x070a06 /* CURLOPT_PROXYAUTH & CURLOPT_FTP_CREATE_MISSING_DIRS are available since curl 7.10.7 */
    1634                 :                 case CURLOPT_PROXYAUTH:
    1635                 :                 case CURLOPT_FTP_CREATE_MISSING_DIRS:
    1636                 : #endif
    1637                 : 
    1638                 : #if LIBCURL_VERSION_NUM >= 0x070c02
    1639                 :                 case CURLOPT_FTPSSLAUTH:
    1640                 : #endif
    1641                 : #if LIBCURL_VERSION_NUM >  0x070b00
    1642                 :                 case CURLOPT_FTP_SSL:
    1643                 : #endif
    1644                 :                 case CURLOPT_UNRESTRICTED_AUTH:
    1645                 :                 case CURLOPT_PORT:
    1646                 :                 case CURLOPT_AUTOREFERER:
    1647                 :                 case CURLOPT_COOKIESESSION:
    1648                 : #if LIBCURL_VERSION_NUM > 0x070b01 /* CURLOPT_TCP_NODELAY is available since curl 7.11.2 */
    1649                 :                 case CURLOPT_TCP_NODELAY:
    1650                 : #endif
    1651                 : #if LIBCURL_VERSION_NUM >= 0x71304
    1652                 :                 case CURLOPT_REDIR_PROTOCOLS:
    1653                 :                 case CURLOPT_PROTOCOLS:
    1654                 : #endif
    1655                 : #if LIBCURL_VERSION_NUM > 0x070a07 /* CURLOPT_IPRESOLVE is available since curl 7.10.8 */
    1656                 :                 case CURLOPT_IPRESOLVE:
    1657                 : #endif
    1658                 : #if LIBCURL_VERSION_NUM >= 0x070f01
    1659                 :                 case CURLOPT_FTP_FILEMETHOD:
    1660                 : #endif
    1661                 : #if LIBCURL_VERSION_NUM >  0x071301
    1662                 :                 case CURLOPT_CERTINFO:
    1663                 : #endif
    1664              13 :                         convert_to_long_ex(zvalue);
    1665                 : #if LIBCURL_VERSION_NUM >= 0x71304
    1666                 :                         if ((option == CURLOPT_PROTOCOLS || option == CURLOPT_REDIR_PROTOCOLS) &&
    1667                 :                                 ((PG(open_basedir) && *PG(open_basedir)) || PG(safe_mode)) && (Z_LVAL_PP(zvalue) & CURLPROTO_FILE)) {
    1668                 :                                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLPROTO_FILE cannot be activated when in safe_mode or an open_basedir is set");
    1669                 :                                         RETVAL_FALSE;
    1670                 :                                         return 1;
    1671                 :                         }
    1672                 : #endif
    1673              13 :                         error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue));
    1674              13 :                         break;
    1675                 :                 case CURLOPT_FOLLOWLOCATION:
    1676               2 :                         convert_to_long_ex(zvalue);
    1677               2 :                         if ((PG(open_basedir) && *PG(open_basedir)) || PG(safe_mode)) {
    1678               2 :                                 if (Z_LVAL_PP(zvalue) != 0) {
    1679               2 :                                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set");
    1680               2 :                                         RETVAL_FALSE;
    1681               2 :                                         return 1;
    1682                 :                                 }
    1683                 :                         }
    1684               0 :                         error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue));
    1685               0 :                         break;
    1686                 : #if LIBCURL_VERSION_NUM > 0x071301
    1687                 :                 case CURLOPT_POSTREDIR:
    1688                 :                         convert_to_long_ex(zvalue);
    1689                 :                         error = curl_easy_setopt(ch->cp, CURLOPT_POSTREDIR, Z_LVAL_PP(zvalue) & CURL_REDIR_POST_ALL);
    1690                 :                         break;
    1691                 : #endif
    1692                 :                 case CURLOPT_PRIVATE:
    1693                 :                 case CURLOPT_URL:
    1694                 :                 case CURLOPT_PROXY:
    1695                 :                 case CURLOPT_USERPWD:
    1696                 :                 case CURLOPT_PROXYUSERPWD:
    1697                 :                 case CURLOPT_RANGE:
    1698                 :                 case CURLOPT_CUSTOMREQUEST:
    1699                 :                 case CURLOPT_USERAGENT:
    1700                 :                 case CURLOPT_FTPPORT:
    1701                 :                 case CURLOPT_COOKIE:
    1702                 :                 case CURLOPT_REFERER:
    1703                 :                 case CURLOPT_INTERFACE:
    1704                 :                 case CURLOPT_KRB4LEVEL:
    1705                 :                 case CURLOPT_EGDSOCKET:
    1706                 :                 case CURLOPT_CAINFO:
    1707                 :                 case CURLOPT_CAPATH:
    1708                 :                 case CURLOPT_SSL_CIPHER_LIST:
    1709                 :                 case CURLOPT_SSLKEY:
    1710                 :                 case CURLOPT_SSLKEYTYPE:
    1711                 :                 case CURLOPT_SSLKEYPASSWD:
    1712                 :                 case CURLOPT_SSLENGINE:
    1713                 :                 case CURLOPT_SSLENGINE_DEFAULT:
    1714                 :                 case CURLOPT_SSLCERTTYPE:
    1715                 :                 case CURLOPT_ENCODING:
    1716                 : #if LIBCURL_VERSION_NUM >= 0x071300
    1717                 :                 case CURLOPT_SSH_PUBLIC_KEYFILE:
    1718                 :                 case CURLOPT_SSH_PRIVATE_KEYFILE:
    1719                 : #endif
    1720                 :                 {
    1721                 : #if LIBCURL_VERSION_NUM < 0x071100
    1722              60 :                         char *copystr = NULL;
    1723                 : #endif
    1724                 : 
    1725              60 :                         convert_to_string_ex(zvalue);
    1726                 : #if LIBCURL_VERSION_NUM >= 0x071300
    1727                 :                         if (
    1728                 :                                 option == CURLOPT_SSH_PUBLIC_KEYFILE || option == CURLOPT_SSH_PRIVATE_KEYFILE
    1729                 : 
    1730                 :                         ) {
    1731                 :                                 if (php_check_open_basedir(Z_STRVAL_PP(zvalue) TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(Z_STRVAL_PP(zvalue), "rb+", CHECKUID_CHECK_MODE_PARAM))) {
    1732                 :                                         RETVAL_FALSE;
    1733                 :                                         return 1;
    1734                 :                                 }
    1735                 :                         }
    1736                 : #endif
    1737              60 :                         if (option == CURLOPT_URL) {
    1738              55 :                                 if (!php_curl_option_url(ch, Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue))) {
    1739               0 :                                         RETVAL_FALSE;
    1740               0 :                                         return 1;
    1741                 :                                 }
    1742                 :                         } else {
    1743                 : #if LIBCURL_VERSION_NUM >= 0x071100
    1744                 :                                 /* Strings passed to libcurl as ’char *’ arguments, are copied by the library... NOTE: before 7.17.0 strings were not copied. */
    1745                 :                                 error = curl_easy_setopt(ch->cp, option, Z_STRVAL_PP(zvalue));
    1746                 : #else
    1747               5 :                                 copystr = estrndup(Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue));
    1748               5 :                                 error = curl_easy_setopt(ch->cp, option, copystr);
    1749               5 :                                 zend_llist_add_element(&ch->to_free.str, &copystr);
    1750                 : #endif
    1751                 :                         }
    1752              60 :                         break;
    1753                 :                 }
    1754                 :                 case CURLOPT_FILE:
    1755                 :                 case CURLOPT_INFILE:
    1756                 :                 case CURLOPT_WRITEHEADER:
    1757                 :                 case CURLOPT_STDERR: {
    1758               8 :                         FILE *fp = NULL;
    1759                 :                         int type;
    1760                 :                         void * what;
    1761                 : 
    1762               8 :                         what = zend_fetch_resource(zvalue TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream());
    1763               8 :                         if (!what) {
    1764               0 :                                 RETVAL_FALSE;
    1765               0 :                                 return 1;
    1766                 :                         }
    1767                 : 
    1768               8 :                         if (FAILURE == php_stream_cast((php_stream *) what, PHP_STREAM_AS_STDIO, (void *) &fp, REPORT_ERRORS)) {
    1769               0 :                                 RETVAL_FALSE;
    1770               0 :                                 return 1;
    1771                 :                         }
    1772                 : 
    1773               8 :                         if (!fp) {
    1774               0 :                                 RETVAL_FALSE;
    1775               0 :                                 return 1;
    1776                 :                         }
    1777                 : 
    1778               8 :                         error = CURLE_OK;
    1779               8 :                         switch (option) {
    1780                 :                                 case CURLOPT_FILE:
    1781               3 :                                         if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
    1782               2 :                                                 Z_ADDREF_PP(zvalue);
    1783               2 :                                                 ch->handlers->write->fp = fp;
    1784               2 :                                                 ch->handlers->write->method = PHP_CURL_FILE;
    1785               2 :                                                 ch->handlers->write->stream = *zvalue;
    1786                 :                                         } else {
    1787               1 :                                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
    1788               1 :                                                 RETVAL_FALSE;
    1789               1 :                                                 return 1;
    1790                 :                                         }
    1791               2 :                                         break;
    1792                 :                                 case CURLOPT_WRITEHEADER:
    1793               0 :                                         if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
    1794               0 :                                                 Z_ADDREF_PP(zvalue);
    1795               0 :                                                 ch->handlers->write_header->fp = fp;
    1796               0 :                                                 ch->handlers->write_header->method = PHP_CURL_FILE;
    1797               0 :                                                 ch->handlers->write_header->stream = *zvalue;
    1798                 :                                         } else {
    1799               0 :                                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
    1800               0 :                                                 RETVAL_FALSE;
    1801               0 :                                                 return 1;
    1802                 :                                         }
    1803               0 :                                         break;
    1804                 :                                 case CURLOPT_INFILE:
    1805               2 :                                         Z_ADDREF_PP(zvalue);
    1806               2 :                                         ch->handlers->read->fp = fp;
    1807               2 :                                         ch->handlers->read->fd = Z_LVAL_PP(zvalue);
    1808               2 :                                         ch->handlers->read->stream = *zvalue;
    1809               2 :                                         break;
    1810                 :                                 case CURLOPT_STDERR:
    1811               6 :                                         if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
    1812               3 :                                                 if (ch->handlers->std_err) {
    1813               1 :                                                         zval_ptr_dtor(&ch->handlers->std_err);
    1814                 :                                                 }
    1815               3 :                                                 zval_add_ref(zvalue);
    1816               3 :                                                 ch->handlers->std_err = *zvalue;
    1817               3 :                                                 zend_list_addref(Z_LVAL_PP(zvalue));
    1818                 :                                         } else {
    1819               0 :                                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
    1820               0 :                                                 RETVAL_FALSE;
    1821               0 :                                                 return 1;
    1822                 :                                         }
    1823                 :                                         /* break omitted intentionally */
    1824                 :                                 default:
    1825               3 :                                         error = curl_easy_setopt(ch->cp, option, fp);
    1826                 :                                         break;
    1827                 :                         }
    1828                 : 
    1829               7 :                         break;
    1830                 :                 }
    1831                 :                 case CURLOPT_RETURNTRANSFER:
    1832              31 :                         convert_to_long_ex(zvalue);
    1833                 : 
    1834              31 :                         if (Z_LVAL_PP(zvalue)) {
    1835              30 :                                 ch->handlers->write->method = PHP_CURL_RETURN;
    1836                 :                         } else {
    1837               1 :                                 ch->handlers->write->method = PHP_CURL_STDOUT;
    1838                 :                         }
    1839              31 :                         break;
    1840                 :                 case CURLOPT_BINARYTRANSFER:
    1841               1 :                         convert_to_long_ex(zvalue);
    1842                 : 
    1843               1 :                         if (Z_LVAL_PP(zvalue)) {
    1844               1 :                                 ch->handlers->write->type = PHP_CURL_BINARY;
    1845                 :                         } else {
    1846               0 :                                 ch->handlers->write->type = PHP_CURL_ASCII;
    1847                 :                         }
    1848               1 :                         break;
    1849                 :                 case CURLOPT_WRITEFUNCTION:
    1850               2 :                         if (ch->handlers->write->func_name) {
    1851               0 :                                 zval_ptr_dtor(&ch->handlers->write->func_name);
    1852               0 :                                 ch->handlers->write->fci_cache = empty_fcall_info_cache;
    1853                 :                         }
    1854               2 :                         zval_add_ref(zvalue);
    1855               2 :                         ch->handlers->write->func_name = *zvalue;
    1856               2 :                         ch->handlers->write->method = PHP_CURL_USER;
    1857               2 :                         break;
    1858                 :                 case CURLOPT_READFUNCTION:
    1859               1 :                         if (ch->handlers->read->func_name) {
    1860               0 :                                 zval_ptr_dtor(&ch->handlers->read->func_name);
    1861               0 :                                 ch->handlers->read->fci_cache = empty_fcall_info_cache;
    1862                 :                         }
    1863               1 :                         zval_add_ref(zvalue);
    1864               1 :                         ch->handlers->read->func_name = *zvalue;
    1865               1 :                         ch->handlers->read->method = PHP_CURL_USER;
    1866               1 :                         break;
    1867                 :                 case CURLOPT_PROGRESSFUNCTION:
    1868               0 :                         curl_easy_setopt(ch->cp, CURLOPT_PROGRESSFUNCTION,   curl_progress);
    1869               0 :                         curl_easy_setopt(ch->cp, CURLOPT_PROGRESSDATA, ch);
    1870               0 :                         if (ch->handlers->progress->func_name) {
    1871               0 :                                 zval_ptr_dtor(&ch->handlers->progress->func_name);
    1872               0 :                                 ch->handlers->progress->fci_cache = empty_fcall_info_cache;
    1873                 :                         }
    1874               0 :                         zval_add_ref(zvalue);
    1875               0 :                         ch->handlers->progress->func_name = *zvalue;
    1876               0 :                         ch->handlers->progress->method = PHP_CURL_USER;
    1877               0 :                         break;
    1878                 :                 case CURLOPT_HEADERFUNCTION:
    1879               1 :                         if (ch->handlers->write_header->func_name) {
    1880               0 :                                 zval_ptr_dtor(&ch->handlers->write_header->func_name);
    1881               0 :                                 ch->handlers->write_header->fci_cache = empty_fcall_info_cache;
    1882                 :                         }
    1883               1 :                         zval_add_ref(zvalue);
    1884               1 :                         ch->handlers->write_header->func_name = *zvalue;
    1885               1 :                         ch->handlers->write_header->method = PHP_CURL_USER;
    1886               1 :                         break;
    1887                 : #if CURLOPT_PASSWDFUNCTION != 0
    1888                 :                 case CURLOPT_PASSWDFUNCTION:
    1889               0 :                         if (ch->handlers->passwd) {
    1890               0 :                                 zval_ptr_dtor(&ch->handlers->passwd);
    1891                 :                         }
    1892               0 :                         zval_add_ref(zvalue);
    1893               0 :                         ch->handlers->passwd = *zvalue;
    1894               0 :                         error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDFUNCTION, curl_passwd);
    1895               0 :                         error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDDATA,     (void *) ch);
    1896               0 :                         break;
    1897                 : #endif
    1898                 :                 case CURLOPT_POSTFIELDS:
    1899               5 :                         if (Z_TYPE_PP(zvalue) == IS_ARRAY || Z_TYPE_PP(zvalue) == IS_OBJECT) {
    1900                 :                                 zval            **current;
    1901                 :                                 HashTable        *postfields;
    1902               1 :                                 struct HttpPost  *first = NULL;
    1903               1 :                                 struct HttpPost  *last  = NULL;
    1904                 :                                 char             *postval;
    1905               1 :                                 char             *string_key = NULL;
    1906                 :                                 ulong             num_key;
    1907                 :                                 uint              string_key_len;
    1908                 : 
    1909               1 :                                 postfields = HASH_OF(*zvalue);
    1910               1 :                                 if (!postfields) {
    1911               0 :                                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't get HashTable in CURLOPT_POSTFIELDS");
    1912               0 :                                         RETVAL_FALSE;
    1913               0 :                                         return 1;
    1914                 :                                 }
    1915                 : 
    1916               1 :                                 for (zend_hash_internal_pointer_reset(postfields);
    1917               5 :                                          zend_hash_get_current_data(postfields, (void **) &current) == SUCCESS;
    1918                 :                                          zend_hash_move_forward(postfields)
    1919               3 :                                 ) {
    1920                 : 
    1921               3 :                                         SEPARATE_ZVAL(current);
    1922               3 :                                         convert_to_string_ex(current);
    1923                 : 
    1924               3 :                                         zend_hash_get_current_key_ex(postfields, &string_key, &string_key_len, &num_key, 0, NULL);
    1925                 : 
    1926               3 :                                         postval = Z_STRVAL_PP(current);
    1927                 : 
    1928                 :                                         /* The arguments after _NAMELENGTH and _CONTENTSLENGTH
    1929                 :                                          * must be explicitly cast to long in curl_formadd
    1930                 :                                          * use since curl needs a long not an int. */
    1931               3 :                                         if (*postval == '@') {
    1932                 :                                                 char *type, *filename;
    1933               0 :                                                 ++postval;
    1934                 : 
    1935               0 :                                                 if ((type = php_memnstr(postval, ";type=", sizeof(";type=") - 1, postval + Z_STRLEN_PP(current)))) {
    1936               0 :                                                         *type = '\0';
    1937                 :                                                 }
    1938               0 :                                                 if ((filename = php_memnstr(postval, ";filename=", sizeof(";filename=") - 1, postval + Z_STRLEN_PP(current)))) {
    1939               0 :                                                         *filename = '\0';
    1940                 :                                                 }
    1941                 :                                                 /* safe_mode / open_basedir check */
    1942               0 :                                                 if (php_check_open_basedir(postval TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(postval, "rb+", CHECKUID_CHECK_MODE_PARAM))) {
    1943               0 :                                                         RETVAL_FALSE;
    1944               0 :                                                         return 1;
    1945                 :                                                 }
    1946               0 :                                                 error = curl_formadd(&first, &last,
    1947                 :                                                                                 CURLFORM_COPYNAME, string_key,
    1948                 :                                                                                 CURLFORM_NAMELENGTH, (long)string_key_len - 1,
    1949                 :                                                                                 CURLFORM_FILENAME, filename ? filename + sizeof(";filename=") - 1 : postval,
    1950                 :                                                                                 CURLFORM_CONTENTTYPE, type ? type + sizeof(";type=") - 1 : "application/octet-stream",
    1951                 :                                                                                 CURLFORM_FILE, postval,
    1952                 :                                                                                 CURLFORM_END);
    1953               0 :                                                 if (type) {
    1954               0 :                                                         *type = ';';
    1955                 :                                                 }
    1956               0 :                                                 if (filename) {
    1957               0 :                                                         *filename = ';';
    1958                 :                                                 }
    1959                 :                                         } else {
    1960               3 :                                                 error = curl_formadd(&first, &last,
    1961                 :                                                                                          CURLFORM_COPYNAME, string_key,
    1962                 :                                                                                          CURLFORM_NAMELENGTH, (long)string_key_len - 1,
    1963                 :                                                                                          CURLFORM_COPYCONTENTS, postval,
    1964                 :                                                                                          CURLFORM_CONTENTSLENGTH, (long)Z_STRLEN_PP(current),
    1965                 :                                                                                          CURLFORM_END);
    1966                 :                                         }
    1967                 :                                 }
    1968                 : 
    1969               1 :                                 SAVE_CURL_ERROR(ch, error);
    1970               1 :                                 if (error != CURLE_OK) {
    1971               0 :                                         RETVAL_FALSE
    1972               0 :                                         return 1;
    1973                 :                                 }
    1974                 : 
    1975               1 :                                 zend_llist_add_element(&ch->to_free.post, &first);
    1976               1 :                                 error = curl_easy_setopt(ch->cp, CURLOPT_HTTPPOST, first);
    1977                 : 
    1978                 :                         } else {
    1979                 : #if LIBCURL_VERSION_NUM >= 0x071101
    1980                 :                                 convert_to_string_ex(zvalue);
    1981                 :                                 /* with curl 7.17.0 and later, we can use COPYPOSTFIELDS, but we have to provide size before */
    1982                 :                                 error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, Z_STRLEN_PP(zvalue));
    1983                 :                                 error = curl_easy_setopt(ch->cp, CURLOPT_COPYPOSTFIELDS, Z_STRVAL_PP(zvalue));
    1984                 : #else
    1985               3 :                                 char *post = NULL;
    1986                 : 
    1987               3 :                                 convert_to_string_ex(zvalue);
    1988               3 :                                 post = estrndup(Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue));
    1989               3 :                                 zend_llist_add_element(&ch->to_free.str, &post);
    1990                 : 
    1991               3 :                                 error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, post);
    1992               3 :                                 error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, Z_STRLEN_PP(zvalue));
    1993                 : #endif
    1994                 :                         }
    1995               4 :                         break;
    1996                 :                 case CURLOPT_HTTPHEADER:
    1997                 :                 case CURLOPT_QUOTE:
    1998                 :                 case CURLOPT_HTTP200ALIASES:
    1999                 :                 case CURLOPT_POSTQUOTE: {
    2000                 :                         zval              **current;
    2001                 :                         HashTable          *ph;
    2002               4 :                         struct curl_slist  *slist = NULL;
    2003                 : 
    2004               4 :                         ph = HASH_OF(*zvalue);
    2005               4 :                         if (!ph) {
    2006               1 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must pass either an object or an array with the CURLOPT_HTTPHEADER, CURLOPT_QUOTE, CURLOPT_HTTP200ALIASES and CURLOPT_POSTQUOTE arguments");
    2007               1 :                                 RETVAL_FALSE;
    2008               1 :                                 return 1;
    2009                 :                         }
    2010                 : 
    2011               3 :                         for (zend_hash_internal_pointer_reset(ph);
    2012               9 :                                  zend_hash_get_current_data(ph, (void **) &current) == SUCCESS;
    2013                 :                                  zend_hash_move_forward(ph)
    2014               3 :                         ) {
    2015               3 :                                 SEPARATE_ZVAL(current);
    2016               3 :                                 convert_to_string_ex(current);
    2017                 : 
    2018               3 :                                 slist = curl_slist_append(slist, Z_STRVAL_PP(current));
    2019               3 :                                 if (!slist) {
    2020               0 :                                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not build curl_slist");
    2021               0 :                                         RETVAL_FALSE;
    2022               0 :                                         return 1;
    2023                 :                                 }
    2024                 :                         }
    2025               3 :                         zend_llist_add_element(&ch->to_free.slist, &slist);
    2026                 : 
    2027               3 :                         error = curl_easy_setopt(ch->cp, option, slist);
    2028                 : 
    2029               3 :                         break;
    2030                 :                 }
    2031                 :                 /* the following options deal with files, therefor safe_mode & open_basedir checks
    2032                 :                  * are required.
    2033                 :                  */
    2034                 :                 case CURLOPT_COOKIEJAR:
    2035                 :                 case CURLOPT_SSLCERT:
    2036                 :                 case CURLOPT_RANDOM_FILE:
    2037                 :                 case CURLOPT_COOKIEFILE: {
    2038                 : #if LIBCURL_VERSION_NUM < 0x071100
    2039               0 :                         char *copystr = NULL;
    2040                 : #endif
    2041                 : 
    2042               0 :                         convert_to_string_ex(zvalue);
    2043                 : 
    2044               0 :                         if (php_check_open_basedir(Z_STRVAL_PP(zvalue) TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(Z_STRVAL_PP(zvalue), "rb+", CHECKUID_CHECK_MODE_PARAM))) {
    2045               0 :                                 RETVAL_FALSE;
    2046               0 :                                 return 1;
    2047                 :                         }
    2048                 : 
    2049                 : #if LIBCURL_VERSION_NUM >= 0x071100
    2050                 :                         error = curl_easy_setopt(ch->cp, option, Z_STRVAL_PP(zvalue));
    2051                 : #else
    2052               0 :                         copystr = estrndup(Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue));
    2053                 : 
    2054               0 :                         error = curl_easy_setopt(ch->cp, option, copystr);
    2055               0 :                         zend_llist_add_element(&ch->to_free.str, &copystr);
    2056                 : #endif
    2057               0 :                         break;
    2058                 :                 }
    2059                 :                 case CURLINFO_HEADER_OUT:
    2060               0 :                         convert_to_long_ex(zvalue);
    2061               0 :                         if (Z_LVAL_PP(zvalue) == 1) {
    2062               0 :                                 curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, curl_debug);
    2063               0 :                                 curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, (void *)ch);
    2064               0 :                                 curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 1);
    2065                 :                         } else {
    2066               0 :                                 curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, NULL);
    2067               0 :                                 curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, NULL);
    2068               0 :                                 curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0);
    2069                 :                         }
    2070                 :                         break;
    2071                 :         }
    2072                 : 
    2073             126 :         SAVE_CURL_ERROR(ch, error);
    2074             126 :         if (error != CURLE_OK) {
    2075               0 :                 return 1;
    2076                 :         } else {
    2077             126 :                 return 0;
    2078                 :         }
    2079                 : }
    2080                 : /* }}} */
    2081                 : 
    2082                 : /* {{{ proto bool curl_setopt(resource ch, int option, mixed value)
    2083                 :    Set an option for a cURL transfer */
    2084                 : PHP_FUNCTION(curl_setopt)
    2085             132 : {
    2086                 :         zval       *zid, **zvalue;
    2087                 :         long        options;
    2088                 :         php_curl   *ch;
    2089                 : 
    2090             132 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlZ", &zid, &options, &zvalue) == FAILURE) {
    2091              10 :                 return;
    2092                 :         }
    2093                 : 
    2094             122 :         ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
    2095                 : 
    2096             122 :         if (!_php_curl_setopt(ch, options, zvalue, return_value TSRMLS_CC)) {
    2097             118 :                 RETURN_TRUE;
    2098                 :         } else {
    2099               4 :                 RETURN_FALSE;
    2100                 :         }
    2101                 : }
    2102                 : /* }}} */
    2103                 : 
    2104                 : /* {{{ proto bool curl_setopt_array(resource ch, array options)
    2105                 :    Set an array of option for a cURL transfer */
    2106                 : PHP_FUNCTION(curl_setopt_array)
    2107               4 : {
    2108                 :         zval            *zid, *arr, **entry;
    2109                 :         php_curl        *ch;
    2110                 :         ulong           option;
    2111                 :         HashPosition    pos;
    2112                 :         char            *string_key;
    2113                 :         uint            str_key_len;
    2114                 : 
    2115               4 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "za", &zid, &arr) == FAILURE) {
    2116               0 :                 return;
    2117                 :         }
    2118                 : 
    2119               4 :         ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
    2120                 : 
    2121               4 :         zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
    2122              16 :         while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **)&entry, &pos) == SUCCESS) {
    2123               8 :                 if (zend_hash_get_current_key_ex(Z_ARRVAL_P(arr), &string_key, &str_key_len, &option, 0, &pos) != HASH_KEY_IS_LONG) {
    2124               0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array keys must be CURLOPT constants or equivalent integer values");
    2125               0 :                         RETURN_FALSE;
    2126                 :                 }
    2127               8 :                 if (_php_curl_setopt(ch, (long) option, entry, return_value TSRMLS_CC)) {
    2128               0 :                         RETURN_FALSE;
    2129                 :                 }
    2130               8 :                 zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos);
    2131                 :         }
    2132               4 :         RETURN_TRUE;
    2133                 : }
    2134                 : /* }}} */
    2135                 : 
    2136                 : /* {{{ _php_curl_cleanup_handle(ch)
    2137                 :    Cleanup an execution phase */
    2138                 : void _php_curl_cleanup_handle(php_curl *ch)
    2139              59 : {
    2140              59 :         if (ch->handlers->write->buf.len > 0) {
    2141               0 :                 smart_str_free(&ch->handlers->write->buf);
    2142                 :         }
    2143              59 :         if (ch->header.str_len) {
    2144               0 :                 efree(ch->header.str);
    2145               0 :                 ch->header.str_len = 0;
    2146                 :         }
    2147                 : 
    2148              59 :         memset(ch->err.str, 0, CURL_ERROR_SIZE + 1);
    2149              59 :         ch->err.no = 0;
    2150              59 : }
    2151                 : /* }}} */
    2152                 : 
    2153                 : /* {{{ proto bool curl_exec(resource ch)
    2154                 :    Perform a cURL session */
    2155                 : PHP_FUNCTION(curl_exec)
    2156              44 : {
    2157                 :         CURLcode        error;
    2158                 :         zval            *zid;
    2159                 :         php_curl        *ch;
    2160                 : 
    2161              44 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
    2162               0 :                 return;
    2163                 :         }
    2164                 : 
    2165              44 :         ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
    2166                 : 
    2167              44 :         _php_curl_cleanup_handle(ch);
    2168                 : 
    2169              44 :         error = curl_easy_perform(ch->cp);
    2170              44 :         SAVE_CURL_ERROR(ch, error);
    2171                 :         /* CURLE_PARTIAL_FILE is returned by HEAD requests */
    2172              44 :         if (error != CURLE_OK && error != CURLE_PARTIAL_FILE) {
    2173              11 :                 if (ch->handlers->write->buf.len > 0) {
    2174               0 :                         smart_str_free(&ch->handlers->write->buf);
    2175                 :                 }
    2176              11 :                 RETURN_FALSE;
    2177                 :         }
    2178                 : 
    2179              33 :         if (ch->handlers->write->method == PHP_CURL_RETURN && ch->handlers->write->buf.len > 0) {
    2180              20 :                 smart_str_0(&ch->handlers->write->buf);
    2181              20 :                 RETURN_STRINGL(ch->handlers->write->buf.c, ch->handlers->write->buf.len, 1);
    2182                 :         }
    2183                 : 
    2184                 :         /* flush the file handle, so any remaining data is synched to disk */
    2185              13 :         if (ch->handlers->write->method == PHP_CURL_FILE && ch->handlers->write->fp) {
    2186               2 :                 fflush(ch->handlers->write->fp);
    2187                 :         }
    2188              13 :         if (ch->handlers->write_header->method == PHP_CURL_FILE && ch->handlers->write_header->fp) {
    2189               0 :                 fflush(ch->handlers->write_header->fp);
    2190                 :         }
    2191                 : 
    2192              13 :         if (ch->handlers->write->method == PHP_CURL_RETURN) {
    2193               0 :                 RETURN_EMPTY_STRING();
    2194                 :         } else {
    2195              13 :                 RETURN_TRUE;
    2196                 :         }
    2197                 : }
    2198                 : /* }}} */
    2199                 : 
    2200                 : /* {{{ proto mixed curl_getinfo(resource ch [, int option])
    2201                 :    Get information regarding a specific transfer */
    2202                 : PHP_FUNCTION(curl_getinfo)
    2203              18 : {
    2204                 :         zval            *zid;
    2205                 :         php_curl        *ch;
    2206              18 :         long            option = 0;
    2207                 : 
    2208              18 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zid, &option) == FAILURE) {
    2209               0 :                 return;
    2210                 :         }
    2211                 : 
    2212              18 :         ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
    2213                 : 
    2214              18 :         if (ZEND_NUM_ARGS() < 2) {
    2215                 :                 char   *s_code;
    2216                 :                 long    l_code;
    2217                 :                 double  d_code;
    2218                 : #if LIBCURL_VERSION_NUM >  0x071301
    2219                 :                 struct curl_certinfo *ci = NULL;
    2220                 :                 zval *listcode;
    2221                 : #endif
    2222                 : 
    2223              14 :                 array_init(return_value);
    2224                 : 
    2225              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_EFFECTIVE_URL, &s_code) == CURLE_OK) {
    2226              14 :                         CAAS("url", s_code);
    2227                 :                 }
    2228              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_TYPE, &s_code) == CURLE_OK) {
    2229              14 :                         if (s_code != NULL) {
    2230               0 :                                 CAAS("content_type", s_code);
    2231                 :                         } else {
    2232                 :                                 zval *retnull;
    2233              14 :                                 MAKE_STD_ZVAL(retnull);
    2234              14 :                                 ZVAL_NULL(retnull);
    2235              14 :                                 CAAZ("content_type", retnull);
    2236                 :                         }
    2237                 :                 }
    2238              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_HTTP_CODE, &l_code) == CURLE_OK) {
    2239              14 :                         CAAL("http_code", l_code);
    2240                 :                 }
    2241              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_HEADER_SIZE, &l_code) == CURLE_OK) {
    2242              14 :                         CAAL("header_size", l_code);
    2243                 :                 }
    2244              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_REQUEST_SIZE, &l_code) == CURLE_OK) {
    2245              14 :                         CAAL("request_size", l_code);
    2246                 :                 }
    2247              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_FILETIME, &l_code) == CURLE_OK) {
    2248              14 :                         CAAL("filetime", l_code);
    2249                 :                 }
    2250              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SSL_VERIFYRESULT, &l_code) == CURLE_OK) {
    2251              14 :                         CAAL("ssl_verify_result", l_code);
    2252                 :                 }
    2253              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_COUNT, &l_code) == CURLE_OK) {
    2254              14 :                         CAAL("redirect_count", l_code);
    2255                 :                 }
    2256              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME, &d_code) == CURLE_OK) {
    2257              14 :                         CAAD("total_time", d_code);
    2258                 :                 }
    2259              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_NAMELOOKUP_TIME, &d_code) == CURLE_OK) {
    2260              14 :                         CAAD("namelookup_time", d_code);
    2261                 :                 }
    2262              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CONNECT_TIME, &d_code) == CURLE_OK) {
    2263              14 :                         CAAD("connect_time", d_code);
    2264                 :                 }
    2265              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_PRETRANSFER_TIME, &d_code) == CURLE_OK) {
    2266              14 :                         CAAD("pretransfer_time", d_code);
    2267                 :                 }
    2268              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_UPLOAD, &d_code) == CURLE_OK) {
    2269              14 :                         CAAD("size_upload", d_code);
    2270                 :                 }
    2271              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_DOWNLOAD, &d_code) == CURLE_OK) {
    2272              14 :                         CAAD("size_download", d_code);
    2273                 :                 }
    2274              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_DOWNLOAD, &d_code) == CURLE_OK) {
    2275              14 :                         CAAD("speed_download", d_code);
    2276                 :                 }
    2277              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_UPLOAD, &d_code) == CURLE_OK) {
    2278              14 :                         CAAD("speed_upload", d_code);
    2279                 :                 }
    2280              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d_code) == CURLE_OK) {
    2281              14 :                         CAAD("download_content_length", d_code);
    2282                 :                 }
    2283              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_UPLOAD, &d_code) == CURLE_OK) {
    2284              14 :                         CAAD("upload_content_length", d_code);
    2285                 :                 }
    2286              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_STARTTRANSFER_TIME, &d_code) == CURLE_OK) {
    2287              14 :                         CAAD("starttransfer_time", d_code);
    2288                 :                 }
    2289              14 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME, &d_code) == CURLE_OK) {
    2290              14 :                         CAAD("redirect_time", d_code);
    2291                 :                 }
    2292                 : #if LIBCURL_VERSION_NUM > 0x071301
    2293                 :                 if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
    2294                 :                         MAKE_STD_ZVAL(listcode);
    2295                 :                         array_init(listcode);
    2296                 :                         create_certinfo(ci, listcode TSRMLS_CC);
    2297                 :                         CAAZ("certinfo", listcode);
    2298                 :                 }
    2299                 : #endif
    2300              14 :                 if (ch->header.str_len > 0) {
    2301               0 :                         CAAS("request_header", ch->header.str);
    2302                 :                 }
    2303                 :         } else {
    2304               4 :                 switch (option) {
    2305                 :                         case CURLINFO_PRIVATE:
    2306                 :                         case CURLINFO_EFFECTIVE_URL:
    2307                 :                         case CURLINFO_CONTENT_TYPE: {
    2308               3 :                                 char *s_code = NULL;
    2309                 : 
    2310               3 :                                 if (curl_easy_getinfo(ch->cp, option, &s_code) == CURLE_OK && s_code) {
    2311               3 :                                         RETURN_STRING(s_code, 1);
    2312                 :                                 } else {
    2313               0 :                                         RETURN_FALSE;
    2314                 :                                 }
    2315                 :                                 break;
    2316                 :                         }
    2317                 :                         case CURLINFO_HTTP_CODE:
    2318                 :                         case CURLINFO_HEADER_SIZE:
    2319                 :                         case CURLINFO_REQUEST_SIZE:
    2320                 :                         case CURLINFO_FILETIME:
    2321                 :                         case CURLINFO_SSL_VERIFYRESULT:
    2322                 :                         case CURLINFO_REDIRECT_COUNT: {
    2323               1 :                                 long code = 0;
    2324                 : 
    2325               1 :                                 if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) {
    2326               1 :                                         RETURN_LONG(code);
    2327                 :                                 } else {
    2328               0 :                                         RETURN_FALSE;
    2329                 :                                 }
    2330                 :                                 break;
    2331                 :                         }
    2332                 :                         case CURLINFO_TOTAL_TIME:
    2333                 :                         case CURLINFO_NAMELOOKUP_TIME:
    2334                 :                         case CURLINFO_CONNECT_TIME:
    2335                 :                         case CURLINFO_PRETRANSFER_TIME:
    2336                 :                         case CURLINFO_SIZE_UPLOAD:
    2337                 :                         case CURLINFO_SIZE_DOWNLOAD:
    2338                 :                         case CURLINFO_SPEED_DOWNLOAD:
    2339                 :                         case CURLINFO_SPEED_UPLOAD:
    2340                 :                         case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
    2341                 :                         case CURLINFO_CONTENT_LENGTH_UPLOAD:
    2342                 :                         case CURLINFO_STARTTRANSFER_TIME:
    2343                 :                         case CURLINFO_REDIRECT_TIME: {
    2344               0 :                                 double code = 0.0;
    2345                 : 
    2346               0 :                                 if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) {
    2347               0 :                                         RETURN_DOUBLE(code);
    2348                 :                                 } else {
    2349               0 :                                         RETURN_FALSE;
    2350                 :                                 }
    2351                 :                                 break;
    2352                 :                         }
    2353                 :                         case CURLINFO_HEADER_OUT:
    2354               0 :                                 if (ch->header.str_len > 0) {
    2355               0 :                                         RETURN_STRINGL(ch->header.str, ch->header.str_len, 1);
    2356                 :                                 } else {
    2357               0 :                                         RETURN_FALSE;
    2358                 :                                 }
    2359                 : #if LIBCURL_VERSION_NUM > 0x071301
    2360                 :                         case CURLINFO_CERTINFO: {
    2361                 :                                 struct curl_certinfo *ci = NULL;
    2362                 : 
    2363                 :                                 array_init(return_value);
    2364                 :                                 
    2365                 :                                 if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
    2366                 :                                         create_certinfo(ci, return_value TSRMLS_CC);
    2367                 :                                 } else {
    2368                 :                                         RETURN_FALSE;
    2369                 :                                 }
    2370                 :                                 break;
    2371                 :                         }
    2372                 : #endif
    2373                 :                 }
    2374                 :         }
    2375                 : }
    2376                 : /* }}} */
    2377                 : 
    2378                 : /* {{{ proto string curl_error(resource ch)
    2379                 :    Return a string contain the last error for the current session */
    2380                 : PHP_FUNCTION(curl_error)
    2381               5 : {
    2382                 :         zval            *zid;
    2383                 :         php_curl        *ch;
    2384                 : 
    2385               5 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
    2386               0 :                 return;
    2387                 :         }
    2388                 : 
    2389               5 :         ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
    2390                 : 
    2391               5 :         ch->err.str[CURL_ERROR_SIZE] = 0;
    2392               5 :         RETURN_STRING(ch->err.str, 1);
    2393                 : }
    2394                 : /* }}} */
    2395                 : 
    2396                 : /* {{{ proto int curl_errno(resource ch)
    2397                 :    Return an integer containing the last error number */
    2398                 : PHP_FUNCTION(curl_errno)
    2399               4 : {
    2400                 :         zval            *zid;
    2401                 :         php_curl        *ch;
    2402                 : 
    2403               4 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
    2404               0 :                 return;
    2405                 :         }
    2406                 : 
    2407               4 :         ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
    2408                 : 
    2409               4 :         RETURN_LONG(ch->err.no);
    2410                 : }
    2411                 : /* }}} */
    2412                 : 
    2413                 : /* {{{ proto void curl_close(resource ch)
    2414                 :    Close a cURL session */
    2415                 : PHP_FUNCTION(curl_close)
    2416              46 : {
    2417                 :         zval            *zid;
    2418                 :         php_curl        *ch;
    2419                 : 
    2420              46 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
    2421               0 :                 return;
    2422                 :         }
    2423                 : 
    2424              46 :         ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
    2425                 : 
    2426              46 :         if (ch->in_callback) {
    2427               0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to close cURL handle from a callback");
    2428               0 :                 return;
    2429                 :         }
    2430                 : 
    2431              46 :         if (ch->uses) {
    2432               0 :                 ch->uses--;
    2433                 :         } else {
    2434              46 :                 zend_list_delete(Z_LVAL_P(zid));
    2435                 :         }
    2436                 : }
    2437                 : /* }}} */
    2438                 : 
    2439                 : /* {{{ _php_curl_close()
    2440                 :    List destructor for curl handles */
    2441                 : static void _php_curl_close_ex(php_curl *ch TSRMLS_DC)
    2442              75 : {
    2443                 : #if PHP_CURL_DEBUG
    2444                 :         fprintf(stderr, "DTOR CALLED, ch = %x\n", ch);
    2445                 : #endif
    2446                 : 
    2447                 :         /* Prevent crash inside cURL if passed file has already been closed */
    2448              75 :         if (ch->handlers->std_err && Z_REFCOUNT_P(ch->handlers->std_err) <= 0) {
    2449               0 :                 curl_easy_setopt(ch->cp, CURLOPT_STDERR, stderr);
    2450                 :         }
    2451                 : 
    2452              75 :         curl_easy_cleanup(ch->cp);
    2453                 : #if LIBCURL_VERSION_NUM < 0x071101
    2454              75 :         zend_llist_clean(&ch->to_free.str);
    2455                 : #endif
    2456                 : 
    2457                 :         /* cURL destructors should be invoked only by last curl handle */
    2458              75 :         if (Z_REFCOUNT_P(ch->clone) <= 1) {
    2459              66 :                 zend_llist_clean(&ch->to_free.slist);
    2460              66 :                 zend_llist_clean(&ch->to_free.post);
    2461              66 :                 FREE_ZVAL(ch->clone);
    2462                 :         } else {
    2463               9 :                 Z_DELREF_P(ch->clone);
    2464               9 :                 ch->to_free.slist.dtor = NULL;
    2465               9 :                 ch->to_free.post.dtor = NULL;
    2466               9 :                 zend_llist_clean(&ch->to_free.slist);
    2467               9 :                 zend_llist_clean(&ch->to_free.post);
    2468                 :         }
    2469                 : 
    2470              75 :         if (ch->handlers->write->buf.len > 0) {
    2471              32 :                 smart_str_free(&ch->handlers->write->buf);
    2472                 :         }
    2473              75 :         if (ch->handlers->write->func_name) {
    2474               2 :                 zval_ptr_dtor(&ch->handlers->write->func_name);
    2475                 :         }
    2476              75 :         if (ch->handlers->read->func_name) {
    2477               1 :                 zval_ptr_dtor(&ch->handlers->read->func_name);
    2478                 :         }
    2479              75 :         if (ch->handlers->write_header->func_name) {
    2480               1 :                 zval_ptr_dtor(&ch->handlers->write_header->func_name);
    2481                 :         }
    2482              75 :         if (ch->handlers->progress->func_name) {
    2483               0 :                 zval_ptr_dtor(&ch->handlers->progress->func_name);
    2484                 :         }
    2485              75 :         if (ch->handlers->passwd) {
    2486               0 :                 zval_ptr_dtor(&ch->handlers->passwd);
    2487                 :         }
    2488              75 :         if (ch->handlers->std_err) {
    2489               2 :                 zval_ptr_dtor(&ch->handlers->std_err);
    2490                 :         }
    2491              75 :         if (ch->header.str_len > 0) {
    2492               0 :                 efree(ch->header.str);
    2493                 :         }
    2494                 : 
    2495              75 :         if (ch->handlers->write_header->stream) {
    2496               0 :                 zval_ptr_dtor(&ch->handlers->write_header->stream);
    2497                 :         }
    2498              75 :         if (ch->handlers->write->stream) {
    2499               2 :                 zval_ptr_dtor(&ch->handlers->write->stream);
    2500                 :         }
    2501              75 :         if (ch->handlers->read->stream) {
    2502               2 :                 zval_ptr_dtor(&ch->handlers->read->stream);
    2503                 :         }
    2504                 : 
    2505              75 :         efree(ch->handlers->write);
    2506              75 :         efree(ch->handlers->write_header);
    2507              75 :         efree(ch->handlers->read);
    2508              75 :         efree(ch->handlers->progress);
    2509              75 :         efree(ch->handlers);
    2510              75 :         efree(ch);
    2511              75 : }
    2512                 : /* }}} */
    2513                 : 
    2514                 : /* {{{ _php_curl_close()
    2515                 :    List destructor for curl handles */
    2516                 : static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC)
    2517              75 : {
    2518              75 :         php_curl *ch = (php_curl *) rsrc->ptr;
    2519              75 :         _php_curl_close_ex(ch TSRMLS_CC);
    2520              75 : }
    2521                 : /* }}} */
    2522                 : 
    2523                 : #endif /* HAVE_CURL */
    2524                 : 
    2525                 : /*
    2526                 :  * Local variables:
    2527                 :  * tab-width: 4
    2528                 :  * c-basic-offset: 4
    2529                 :  * End:
    2530                 :  * vim600: fdm=marker
    2531                 :  * vim: noet sw=4 ts=4
    2532                 :  */

Generated by: LTP GCOV extension version 1.5

Generated at Sat, 21 Nov 2009 12:26:58 +0000 (3 days ago)

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