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