2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Author: Sterling Hughes <sterling@php.net> |
16 +----------------------------------------------------------------------+
19 #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
34 #include <sys/types.h>
37 #include <curl/curl.h>
38 #include <curl/easy.h>
40 /* As of curl 7.11.1 this is no longer defined inside curl.h */
42 #define HttpPost curl_httppost
45 /* {{{ cruft for thread safe SSL crypto locks */
46 #if defined(ZTS) && defined(HAVE_CURL_SSL)
48 # define PHP_CURL_NEED_OPENSSL_TSL
49 # include <openssl/crypto.h>
50 # else /* !PHP_WIN32 */
51 # if defined(HAVE_CURL_OPENSSL)
52 # if defined(HAVE_OPENSSL_CRYPTO_H)
53 # define PHP_CURL_NEED_OPENSSL_TSL
54 # include <openssl/crypto.h>
57 "libcurl was compiled with OpenSSL support, but configure could not find " \
58 "openssl/crypto.h; thus no SSL crypto locking callbacks will be set, which may " \
59 "cause random crashes on SSL requests"
61 # elif defined(HAVE_CURL_GNUTLS)
62 /* Modern versions of GnuTLS use the nette backend rather than gcrypt, so there
63 * is nothing to do here anymore. */
66 "libcurl was compiled with SSL support, but configure could not determine which" \
67 "library was used; thus no SSL crypto locking callbacks will be set, which may " \
68 "cause random crashes on SSL requests"
69 # endif /* HAVE_CURL_OPENSSL || HAVE_CURL_GNUTLS */
70 # endif /* PHP_WIN32 */
71 #endif /* ZTS && HAVE_CURL_SSL */
74 #define SMART_STR_PREALLOC 4096
76 #include "zend_smart_str.h"
77 #include "ext/standard/info.h"
78 #include "ext/standard/file.h"
79 #include "ext/standard/url.h"
83 int le_curl_multi_handle;
84 int le_curl_share_handle;
86 #ifdef PHP_CURL_NEED_OPENSSL_TSL /* {{{ */
87 static MUTEX_T *php_curl_openssl_tsl = NULL;
89 /* Locking callbacks are no longer used since OpenSSL 1.1. Mark the functions as unused to
90 * avoid warnings due to this. */
91 static ZEND_ATTRIBUTE_UNUSED void php_curl_ssl_lock(int mode, int n, const char * file, int line)
93 if (mode & CRYPTO_LOCK) {
94 tsrm_mutex_lock(php_curl_openssl_tsl[n]);
96 tsrm_mutex_unlock(php_curl_openssl_tsl[n]);
100 static ZEND_ATTRIBUTE_UNUSED unsigned long php_curl_ssl_id(void)
102 return (unsigned long) tsrm_thread_id();
107 static void _php_curl_close_ex(php_curl *ch);
108 static void _php_curl_close(zend_resource *rsrc);
111 #define SAVE_CURL_ERROR(__handle, __err) (__handle)->err.no = (int) __err;
113 #define CAAL(s, v) add_assoc_long_ex(return_value, s, sizeof(s) - 1, (zend_long) v);
114 #define CAAD(s, v) add_assoc_double_ex(return_value, s, sizeof(s) - 1, (double) v);
115 #define CAAS(s, v) add_assoc_string_ex(return_value, s, sizeof(s) - 1, (char *) (v ? v : ""));
116 #define CAASTR(s, v) add_assoc_str_ex(return_value, s, sizeof(s) - 1, \
117 v ? zend_string_copy(v) : ZSTR_EMPTY_ALLOC());
118 #define CAAZ(s, v) add_assoc_zval_ex(return_value, s, sizeof(s) -1 , (zval *) v);
120 #if defined(PHP_WIN32) || defined(__GNUC__)
121 # define php_curl_ret(__ret) RETVAL_FALSE; return __ret;
123 # define php_curl_ret(__ret) RETVAL_FALSE; return;
126 static int php_curl_option_str(php_curl *ch, zend_long option, const char *str, const size_t len, zend_bool make_copy)
128 CURLcode error = CURLE_OK;
130 if (strlen(str) != len) {
131 php_error_docref(NULL, E_WARNING, "Curl option contains invalid characters (\\0)");
135 #if LIBCURL_VERSION_NUM >= 0x071100
140 /* Strings passed to libcurl as 'char *' arguments, are copied by the library since 7.17.0 */
141 copystr = estrndup(str, len);
142 error = curl_easy_setopt(ch->cp, option, copystr);
143 zend_llist_add_element(&ch->to_free->str, ©str);
144 #if LIBCURL_VERSION_NUM >= 0x071100
146 error = curl_easy_setopt(ch->cp, option, str);
150 SAVE_CURL_ERROR(ch, error)
152 return error == CURLE_OK ? SUCCESS : FAILURE;
155 static int php_curl_option_url(php_curl *ch, const char *url, const size_t len) /* {{{ */
157 /* Disable file:// if open_basedir are used */
158 if (PG(open_basedir) && *PG(open_basedir)) {
159 #if LIBCURL_VERSION_NUM >= 0x071304
160 curl_easy_setopt(ch->cp, CURLOPT_PROTOCOLS, CURLPROTO_ALL & ~CURLPROTO_FILE);
164 if (!(uri = php_url_parse_ex(url, len))) {
165 php_error_docref(NULL, E_WARNING, "Invalid URL '%s'", url);
169 if (uri->scheme && zend_string_equals_literal_ci(uri->scheme, "file")) {
170 php_error_docref(NULL, E_WARNING, "Protocol 'file' disabled in cURL");
178 #if LIBCURL_VERSION_NUM > 0x073800 && defined(PHP_WIN32)
179 if (len > sizeof("file://") - 1 && '/' != url[sizeof("file://") - 1] && !strncmp("file://", url, sizeof("file://") - 1) && len < MAXPATHLEN - 2) {
180 char _tmp[MAXPATHLEN] = {0};
182 memmove(_tmp, "file:///", sizeof("file:///") - 1);
183 memmove(_tmp + sizeof("file:///") - 1, url + sizeof("file://") - 1, len - sizeof("file://") + 1);
185 return php_curl_option_str(ch, CURLOPT_URL, _tmp, len + 1, 0);
189 return php_curl_option_str(ch, CURLOPT_URL, url, len, 0);
193 void _php_curl_verify_handlers(php_curl *ch, int reporterror) /* {{{ */
197 ZEND_ASSERT(ch && ch->handlers);
199 if (!Z_ISUNDEF(ch->handlers->std_err)) {
200 stream = (php_stream *)zend_fetch_resource2_ex(&ch->handlers->std_err, NULL, php_file_le_stream(), php_file_le_pstream());
201 if (stream == NULL) {
203 php_error_docref(NULL, E_WARNING, "CURLOPT_STDERR resource has gone away, resetting to stderr");
205 zval_ptr_dtor(&ch->handlers->std_err);
206 ZVAL_UNDEF(&ch->handlers->std_err);
208 curl_easy_setopt(ch->cp, CURLOPT_STDERR, stderr);
211 if (ch->handlers->read && !Z_ISUNDEF(ch->handlers->read->stream)) {
212 stream = (php_stream *)zend_fetch_resource2_ex(&ch->handlers->read->stream, NULL, php_file_le_stream(), php_file_le_pstream());
213 if (stream == NULL) {
215 php_error_docref(NULL, E_WARNING, "CURLOPT_INFILE resource has gone away, resetting to default");
217 zval_ptr_dtor(&ch->handlers->read->stream);
218 ZVAL_UNDEF(&ch->handlers->read->stream);
219 ch->handlers->read->res = NULL;
220 ch->handlers->read->fp = 0;
222 curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch);
225 if (ch->handlers->write_header && !Z_ISUNDEF(ch->handlers->write_header->stream)) {
226 stream = (php_stream *)zend_fetch_resource2_ex(&ch->handlers->write_header->stream, NULL, php_file_le_stream(), php_file_le_pstream());
227 if (stream == NULL) {
229 php_error_docref(NULL, E_WARNING, "CURLOPT_WRITEHEADER resource has gone away, resetting to default");
231 zval_ptr_dtor(&ch->handlers->write_header->stream);
232 ZVAL_UNDEF(&ch->handlers->write_header->stream);
233 ch->handlers->write_header->fp = 0;
235 ch->handlers->write_header->method = PHP_CURL_IGNORE;
236 curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
239 if (ch->handlers->write && !Z_ISUNDEF(ch->handlers->write->stream)) {
240 stream = (php_stream *)zend_fetch_resource2_ex(&ch->handlers->write->stream, NULL, php_file_le_stream(), php_file_le_pstream());
241 if (stream == NULL) {
243 php_error_docref(NULL, E_WARNING, "CURLOPT_FILE resource has gone away, resetting to default");
245 zval_ptr_dtor(&ch->handlers->write->stream);
246 ZVAL_UNDEF(&ch->handlers->write->stream);
247 ch->handlers->write->fp = 0;
249 ch->handlers->write->method = PHP_CURL_STDOUT;
250 curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch);
258 ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_version, 0, 0, 0)
259 ZEND_ARG_INFO(0, version)
262 ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_init, 0, 0, 0)
263 ZEND_ARG_INFO(0, url)
266 ZEND_BEGIN_ARG_INFO(arginfo_curl_copy_handle, 0)
270 ZEND_BEGIN_ARG_INFO(arginfo_curl_setopt, 0)
272 ZEND_ARG_INFO(0, option)
273 ZEND_ARG_INFO(0, value)
276 ZEND_BEGIN_ARG_INFO(arginfo_curl_setopt_array, 0)
278 ZEND_ARG_ARRAY_INFO(0, options, 0)
281 ZEND_BEGIN_ARG_INFO(arginfo_curl_exec, 0)
285 ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_getinfo, 0, 0, 1)
287 ZEND_ARG_INFO(0, option)
290 ZEND_BEGIN_ARG_INFO(arginfo_curl_error, 0)
294 ZEND_BEGIN_ARG_INFO(arginfo_curl_errno, 0)
298 ZEND_BEGIN_ARG_INFO(arginfo_curl_close, 0)
302 ZEND_BEGIN_ARG_INFO(arginfo_curl_reset, 0)
306 ZEND_BEGIN_ARG_INFO(arginfo_curl_escape, 0)
308 ZEND_ARG_INFO(0, str)
311 ZEND_BEGIN_ARG_INFO(arginfo_curl_unescape, 0)
313 ZEND_ARG_INFO(0, str)
316 ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_setopt, 0)
318 ZEND_ARG_INFO(0, option)
319 ZEND_ARG_INFO(0, value)
322 ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_init, 0)
325 ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_add_handle, 0)
330 ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_remove_handle, 0)
335 ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_select, 0, 0, 1)
337 ZEND_ARG_INFO(0, timeout)
340 ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_exec, 0, 0, 1)
342 ZEND_ARG_INFO(1, still_running)
345 ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_getcontent, 0)
349 ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_info_read, 0, 0, 1)
351 ZEND_ARG_INFO(1, msgs_in_queue)
354 ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_close, 0)
358 ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_errno, 0)
362 ZEND_BEGIN_ARG_INFO(arginfo_curl_strerror, 0)
363 ZEND_ARG_INFO(0, errornum)
366 ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_strerror, 0)
367 ZEND_ARG_INFO(0, errornum)
370 ZEND_BEGIN_ARG_INFO(arginfo_curl_share_strerror, 0)
371 ZEND_ARG_INFO(0, errornum)
374 ZEND_BEGIN_ARG_INFO(arginfo_curl_share_init, 0)
377 ZEND_BEGIN_ARG_INFO(arginfo_curl_share_close, 0)
381 ZEND_BEGIN_ARG_INFO(arginfo_curl_share_setopt, 0)
383 ZEND_ARG_INFO(0, option)
384 ZEND_ARG_INFO(0, value)
387 ZEND_BEGIN_ARG_INFO(arginfo_curl_share_errno, 0)
391 #if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */
392 ZEND_BEGIN_ARG_INFO(arginfo_curl_pause, 0)
394 ZEND_ARG_INFO(0, bitmask)
398 ZEND_BEGIN_ARG_INFO_EX(arginfo_curlfile_create, 0, 0, 1)
399 ZEND_ARG_INFO(0, filename)
400 ZEND_ARG_INFO(0, mimetype)
401 ZEND_ARG_INFO(0, postname)
405 /* {{{ curl_functions[]
407 static const zend_function_entry curl_functions[] = {
408 PHP_FE(curl_init, arginfo_curl_init)
409 PHP_FE(curl_copy_handle, arginfo_curl_copy_handle)
410 PHP_FE(curl_version, arginfo_curl_version)
411 PHP_FE(curl_setopt, arginfo_curl_setopt)
412 PHP_FE(curl_setopt_array, arginfo_curl_setopt_array)
413 PHP_FE(curl_exec, arginfo_curl_exec)
414 PHP_FE(curl_getinfo, arginfo_curl_getinfo)
415 PHP_FE(curl_error, arginfo_curl_error)
416 PHP_FE(curl_errno, arginfo_curl_errno)
417 PHP_FE(curl_close, arginfo_curl_close)
418 PHP_FE(curl_strerror, arginfo_curl_strerror)
419 PHP_FE(curl_multi_strerror, arginfo_curl_multi_strerror)
420 PHP_FE(curl_share_strerror, arginfo_curl_share_strerror)
421 PHP_FE(curl_reset, arginfo_curl_reset)
422 PHP_FE(curl_escape, arginfo_curl_escape)
423 PHP_FE(curl_unescape, arginfo_curl_unescape)
424 #if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */
425 PHP_FE(curl_pause, arginfo_curl_pause)
427 PHP_FE(curl_multi_init, arginfo_curl_multi_init)
428 PHP_FE(curl_multi_add_handle, arginfo_curl_multi_add_handle)
429 PHP_FE(curl_multi_remove_handle, arginfo_curl_multi_remove_handle)
430 PHP_FE(curl_multi_select, arginfo_curl_multi_select)
431 PHP_FE(curl_multi_exec, arginfo_curl_multi_exec)
432 PHP_FE(curl_multi_getcontent, arginfo_curl_multi_getcontent)
433 PHP_FE(curl_multi_info_read, arginfo_curl_multi_info_read)
434 PHP_FE(curl_multi_close, arginfo_curl_multi_close)
435 PHP_FE(curl_multi_errno, arginfo_curl_multi_errno)
436 PHP_FE(curl_multi_setopt, arginfo_curl_multi_setopt)
437 PHP_FE(curl_share_init, arginfo_curl_share_init)
438 PHP_FE(curl_share_close, arginfo_curl_share_close)
439 PHP_FE(curl_share_setopt, arginfo_curl_share_setopt)
440 PHP_FE(curl_share_errno, arginfo_curl_share_errno)
441 PHP_FE(curl_file_create, arginfo_curlfile_create)
446 /* {{{ curl_module_entry
448 zend_module_entry curl_module_entry = {
449 STANDARD_MODULE_HEADER,
458 STANDARD_MODULE_PROPERTIES
462 #ifdef COMPILE_DL_CURL
463 ZEND_GET_MODULE (curl)
466 /* {{{ PHP_INI_BEGIN */
468 PHP_INI_ENTRY("curl.cainfo", "", PHP_INI_SYSTEM, NULL)
472 /* {{{ PHP_MINFO_FUNCTION
474 PHP_MINFO_FUNCTION(curl)
476 curl_version_info_data *d;
481 d = curl_version_info(CURLVERSION_NOW);
482 php_info_print_table_start();
483 php_info_print_table_row(2, "cURL support", "enabled");
484 php_info_print_table_row(2, "cURL Information", d->version);
485 sprintf(str, "%d", d->age);
486 php_info_print_table_row(2, "Age", str);
488 /* To update on each new cURL release using src/main.c in cURL sources */
497 static const struct feat feats[] = {
498 {"AsynchDNS", CURL_VERSION_ASYNCHDNS},
499 {"CharConv", CURL_VERSION_CONV},
500 {"Debug", CURL_VERSION_DEBUG},
501 {"GSS-Negotiate", CURL_VERSION_GSSNEGOTIATE},
502 {"IDN", CURL_VERSION_IDN},
503 {"IPv6", CURL_VERSION_IPV6},
504 {"krb4", CURL_VERSION_KERBEROS4},
505 {"Largefile", CURL_VERSION_LARGEFILE},
506 {"libz", CURL_VERSION_LIBZ},
507 {"NTLM", CURL_VERSION_NTLM},
508 #if LIBCURL_VERSION_NUM >= 0x071600 /* 7.22.0 */
509 {"NTLMWB", CURL_VERSION_NTLM_WB},
511 {"SPNEGO", CURL_VERSION_SPNEGO},
512 {"SSL", CURL_VERSION_SSL},
513 {"SSPI", CURL_VERSION_SSPI},
514 #if LIBCURL_VERSION_NUM >= 0x071504 /* 7.21.4 */
515 {"TLS-SRP", CURL_VERSION_TLSAUTH_SRP},
517 #if LIBCURL_VERSION_NUM >= 0x072100 /* 7.33.0 */
518 {"HTTP2", CURL_VERSION_HTTP2},
520 #if LIBCURL_VERSION_NUM >= 0x072600 /* 7.38.0 */
521 {"GSSAPI", CURL_VERSION_GSSAPI},
523 #if LIBCURL_VERSION_NUM >= 0x072800 /* 7.40.0 */
524 {"KERBEROS5", CURL_VERSION_KERBEROS5},
525 {"UNIX_SOCKETS", CURL_VERSION_UNIX_SOCKETS},
527 #if LIBCURL_VERSION_NUM >= 0x072f00 /* 7.47.0 */
528 {"PSL", CURL_VERSION_PSL},
530 #if LIBCURL_VERSION_NUM >= 0x073400 /* 7.52.0 */
531 {"HTTPS_PROXY", CURL_VERSION_HTTPS_PROXY},
533 #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
534 {"MULTI_SSL", CURL_VERSION_MULTI_SSL},
536 #if LIBCURL_VERSION_NUM >= 0x073900 /* 7.57.0 */
537 {"BROTLI", CURL_VERSION_BROTLI},
542 php_info_print_table_row(1, "Features");
543 for(i=0; i<sizeof(feats)/sizeof(feats[0]); i++) {
545 php_info_print_table_row(2, feats[i].name, d->features & feats[i].bitmask ? "Yes" : "No");
551 p = (char **) d->protocols;
553 n += sprintf(str + n, "%s%s", *p, *(p + 1) != NULL ? ", " : "");
556 php_info_print_table_row(2, "Protocols", str);
558 php_info_print_table_row(2, "Host", d->host);
560 if (d->ssl_version) {
561 php_info_print_table_row(2, "SSL Version", d->ssl_version);
564 if (d->libz_version) {
565 php_info_print_table_row(2, "ZLib Version", d->libz_version);
568 #if defined(CURLVERSION_SECOND) && CURLVERSION_NOW >= CURLVERSION_SECOND
570 php_info_print_table_row(2, "ZLib Version", d->ares);
574 #if defined(CURLVERSION_THIRD) && CURLVERSION_NOW >= CURLVERSION_THIRD
576 php_info_print_table_row(2, "libIDN Version", d->libidn);
580 #if LIBCURL_VERSION_NUM >= 0x071300
582 if (d->iconv_ver_num) {
583 php_info_print_table_row(2, "IconV Version", d->iconv_ver_num);
586 if (d->libssh_version) {
587 php_info_print_table_row(2, "libSSH Version", d->libssh_version);
590 php_info_print_table_end();
592 DISPLAY_INI_ENTRIES();
596 #define REGISTER_CURL_CONSTANT(__c) REGISTER_LONG_CONSTANT(#__c, __c, CONST_CS | CONST_PERSISTENT)
598 /* {{{ PHP_MINIT_FUNCTION
600 PHP_MINIT_FUNCTION(curl)
602 le_curl = zend_register_list_destructors_ex(_php_curl_close, NULL, "curl", module_number);
603 le_curl_multi_handle = zend_register_list_destructors_ex(_php_curl_multi_close, NULL, "curl_multi", module_number);
604 le_curl_share_handle = zend_register_list_destructors_ex(_php_curl_share_close, NULL, "curl_share", module_number);
606 REGISTER_INI_ENTRIES();
608 /* See http://curl.haxx.se/lxr/source/docs/libcurl/symbols-in-versions
609 or curl src/docs/libcurl/symbols-in-versions for a (almost) complete list
610 of options and which version they were introduced */
612 /* Constants for curl_setopt() */
613 REGISTER_CURL_CONSTANT(CURLOPT_AUTOREFERER);
614 REGISTER_CURL_CONSTANT(CURLOPT_BINARYTRANSFER);
615 REGISTER_CURL_CONSTANT(CURLOPT_BUFFERSIZE);
616 REGISTER_CURL_CONSTANT(CURLOPT_CAINFO);
617 REGISTER_CURL_CONSTANT(CURLOPT_CAPATH);
618 REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT);
619 REGISTER_CURL_CONSTANT(CURLOPT_COOKIE);
620 REGISTER_CURL_CONSTANT(CURLOPT_COOKIEFILE);
621 REGISTER_CURL_CONSTANT(CURLOPT_COOKIEJAR);
622 REGISTER_CURL_CONSTANT(CURLOPT_COOKIESESSION);
623 REGISTER_CURL_CONSTANT(CURLOPT_CRLF);
624 REGISTER_CURL_CONSTANT(CURLOPT_CUSTOMREQUEST);
625 REGISTER_CURL_CONSTANT(CURLOPT_DNS_CACHE_TIMEOUT);
626 REGISTER_CURL_CONSTANT(CURLOPT_DNS_USE_GLOBAL_CACHE);
627 REGISTER_CURL_CONSTANT(CURLOPT_EGDSOCKET);
628 REGISTER_CURL_CONSTANT(CURLOPT_ENCODING);
629 REGISTER_CURL_CONSTANT(CURLOPT_FAILONERROR);
630 REGISTER_CURL_CONSTANT(CURLOPT_FILE);
631 REGISTER_CURL_CONSTANT(CURLOPT_FILETIME);
632 REGISTER_CURL_CONSTANT(CURLOPT_FOLLOWLOCATION);
633 REGISTER_CURL_CONSTANT(CURLOPT_FORBID_REUSE);
634 REGISTER_CURL_CONSTANT(CURLOPT_FRESH_CONNECT);
635 REGISTER_CURL_CONSTANT(CURLOPT_FTPAPPEND);
636 REGISTER_CURL_CONSTANT(CURLOPT_FTPLISTONLY);
637 REGISTER_CURL_CONSTANT(CURLOPT_FTPPORT);
638 REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPRT);
639 REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPSV);
640 REGISTER_CURL_CONSTANT(CURLOPT_HEADER);
641 REGISTER_CURL_CONSTANT(CURLOPT_HEADERFUNCTION);
642 REGISTER_CURL_CONSTANT(CURLOPT_HTTP200ALIASES);
643 REGISTER_CURL_CONSTANT(CURLOPT_HTTPGET);
644 REGISTER_CURL_CONSTANT(CURLOPT_HTTPHEADER);
645 REGISTER_CURL_CONSTANT(CURLOPT_HTTPPROXYTUNNEL);
646 REGISTER_CURL_CONSTANT(CURLOPT_HTTP_VERSION);
647 REGISTER_CURL_CONSTANT(CURLOPT_INFILE);
648 REGISTER_CURL_CONSTANT(CURLOPT_INFILESIZE);
649 REGISTER_CURL_CONSTANT(CURLOPT_INTERFACE);
650 REGISTER_CURL_CONSTANT(CURLOPT_KRB4LEVEL);
651 REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_LIMIT);
652 REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_TIME);
653 REGISTER_CURL_CONSTANT(CURLOPT_MAXCONNECTS);
654 REGISTER_CURL_CONSTANT(CURLOPT_MAXREDIRS);
655 REGISTER_CURL_CONSTANT(CURLOPT_NETRC);
656 REGISTER_CURL_CONSTANT(CURLOPT_NOBODY);
657 REGISTER_CURL_CONSTANT(CURLOPT_NOPROGRESS);
658 REGISTER_CURL_CONSTANT(CURLOPT_NOSIGNAL);
659 REGISTER_CURL_CONSTANT(CURLOPT_PORT);
660 REGISTER_CURL_CONSTANT(CURLOPT_POST);
661 REGISTER_CURL_CONSTANT(CURLOPT_POSTFIELDS);
662 REGISTER_CURL_CONSTANT(CURLOPT_POSTQUOTE);
663 REGISTER_CURL_CONSTANT(CURLOPT_PREQUOTE);
664 REGISTER_CURL_CONSTANT(CURLOPT_PRIVATE);
665 REGISTER_CURL_CONSTANT(CURLOPT_PROGRESSFUNCTION);
666 REGISTER_CURL_CONSTANT(CURLOPT_PROXY);
667 REGISTER_CURL_CONSTANT(CURLOPT_PROXYPORT);
668 REGISTER_CURL_CONSTANT(CURLOPT_PROXYTYPE);
669 REGISTER_CURL_CONSTANT(CURLOPT_PROXYUSERPWD);
670 REGISTER_CURL_CONSTANT(CURLOPT_PUT);
671 REGISTER_CURL_CONSTANT(CURLOPT_QUOTE);
672 REGISTER_CURL_CONSTANT(CURLOPT_RANDOM_FILE);
673 REGISTER_CURL_CONSTANT(CURLOPT_RANGE);
674 REGISTER_CURL_CONSTANT(CURLOPT_READDATA);
675 REGISTER_CURL_CONSTANT(CURLOPT_READFUNCTION);
676 REGISTER_CURL_CONSTANT(CURLOPT_REFERER);
677 REGISTER_CURL_CONSTANT(CURLOPT_RESUME_FROM);
678 REGISTER_CURL_CONSTANT(CURLOPT_RETURNTRANSFER);
679 REGISTER_CURL_CONSTANT(CURLOPT_SHARE);
680 REGISTER_CURL_CONSTANT(CURLOPT_SSLCERT);
681 REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTPASSWD);
682 REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTTYPE);
683 REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE);
684 REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE_DEFAULT);
685 REGISTER_CURL_CONSTANT(CURLOPT_SSLKEY);
686 REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYPASSWD);
687 REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYTYPE);
688 REGISTER_CURL_CONSTANT(CURLOPT_SSLVERSION);
689 REGISTER_CURL_CONSTANT(CURLOPT_SSL_CIPHER_LIST);
690 REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYHOST);
691 REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYPEER);
692 REGISTER_CURL_CONSTANT(CURLOPT_STDERR);
693 REGISTER_CURL_CONSTANT(CURLOPT_TELNETOPTIONS);
694 REGISTER_CURL_CONSTANT(CURLOPT_TIMECONDITION);
695 REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT);
696 REGISTER_CURL_CONSTANT(CURLOPT_TIMEVALUE);
697 REGISTER_CURL_CONSTANT(CURLOPT_TRANSFERTEXT);
698 REGISTER_CURL_CONSTANT(CURLOPT_UNRESTRICTED_AUTH);
699 REGISTER_CURL_CONSTANT(CURLOPT_UPLOAD);
700 REGISTER_CURL_CONSTANT(CURLOPT_URL);
701 REGISTER_CURL_CONSTANT(CURLOPT_USERAGENT);
702 REGISTER_CURL_CONSTANT(CURLOPT_USERPWD);
703 REGISTER_CURL_CONSTANT(CURLOPT_VERBOSE);
704 REGISTER_CURL_CONSTANT(CURLOPT_WRITEFUNCTION);
705 REGISTER_CURL_CONSTANT(CURLOPT_WRITEHEADER);
708 REGISTER_CURL_CONSTANT(CURLE_ABORTED_BY_CALLBACK);
709 REGISTER_CURL_CONSTANT(CURLE_BAD_CALLING_ORDER);
710 REGISTER_CURL_CONSTANT(CURLE_BAD_CONTENT_ENCODING);
711 REGISTER_CURL_CONSTANT(CURLE_BAD_DOWNLOAD_RESUME);
712 REGISTER_CURL_CONSTANT(CURLE_BAD_FUNCTION_ARGUMENT);
713 REGISTER_CURL_CONSTANT(CURLE_BAD_PASSWORD_ENTERED);
714 REGISTER_CURL_CONSTANT(CURLE_COULDNT_CONNECT);
715 REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_HOST);
716 REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_PROXY);
717 REGISTER_CURL_CONSTANT(CURLE_FAILED_INIT);
718 REGISTER_CURL_CONSTANT(CURLE_FILE_COULDNT_READ_FILE);
719 REGISTER_CURL_CONSTANT(CURLE_FTP_ACCESS_DENIED);
720 REGISTER_CURL_CONSTANT(CURLE_FTP_BAD_DOWNLOAD_RESUME);
721 REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_GET_HOST);
722 REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_RECONNECT);
723 REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_GET_SIZE);
724 REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_RETR_FILE);
725 REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_ASCII);
726 REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_BINARY);
727 REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_STOR_FILE);
728 REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_USE_REST);
729 REGISTER_CURL_CONSTANT(CURLE_FTP_PARTIAL_FILE);
730 REGISTER_CURL_CONSTANT(CURLE_FTP_PORT_FAILED);
731 REGISTER_CURL_CONSTANT(CURLE_FTP_QUOTE_ERROR);
732 REGISTER_CURL_CONSTANT(CURLE_FTP_USER_PASSWORD_INCORRECT);
733 REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_227_FORMAT);
734 REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASS_REPLY);
735 REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASV_REPLY);
736 REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_SERVER_REPLY);
737 REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_USER_REPLY);
738 REGISTER_CURL_CONSTANT(CURLE_FTP_WRITE_ERROR);
739 REGISTER_CURL_CONSTANT(CURLE_FUNCTION_NOT_FOUND);
740 REGISTER_CURL_CONSTANT(CURLE_GOT_NOTHING);
741 REGISTER_CURL_CONSTANT(CURLE_HTTP_NOT_FOUND);
742 REGISTER_CURL_CONSTANT(CURLE_HTTP_PORT_FAILED);
743 REGISTER_CURL_CONSTANT(CURLE_HTTP_POST_ERROR);
744 REGISTER_CURL_CONSTANT(CURLE_HTTP_RANGE_ERROR);
745 REGISTER_CURL_CONSTANT(CURLE_HTTP_RETURNED_ERROR);
746 REGISTER_CURL_CONSTANT(CURLE_LDAP_CANNOT_BIND);
747 REGISTER_CURL_CONSTANT(CURLE_LDAP_SEARCH_FAILED);
748 REGISTER_CURL_CONSTANT(CURLE_LIBRARY_NOT_FOUND);
749 REGISTER_CURL_CONSTANT(CURLE_MALFORMAT_USER);
750 REGISTER_CURL_CONSTANT(CURLE_OBSOLETE);
751 REGISTER_CURL_CONSTANT(CURLE_OK);
752 REGISTER_CURL_CONSTANT(CURLE_OPERATION_TIMEDOUT);
753 REGISTER_CURL_CONSTANT(CURLE_OPERATION_TIMEOUTED);
754 REGISTER_CURL_CONSTANT(CURLE_OUT_OF_MEMORY);
755 REGISTER_CURL_CONSTANT(CURLE_PARTIAL_FILE);
756 REGISTER_CURL_CONSTANT(CURLE_READ_ERROR);
757 REGISTER_CURL_CONSTANT(CURLE_RECV_ERROR);
758 REGISTER_CURL_CONSTANT(CURLE_SEND_ERROR);
759 REGISTER_CURL_CONSTANT(CURLE_SHARE_IN_USE);
760 REGISTER_CURL_CONSTANT(CURLE_SSL_CACERT);
761 REGISTER_CURL_CONSTANT(CURLE_SSL_CERTPROBLEM);
762 REGISTER_CURL_CONSTANT(CURLE_SSL_CIPHER);
763 REGISTER_CURL_CONSTANT(CURLE_SSL_CONNECT_ERROR);
764 REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_NOTFOUND);
765 REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_SETFAILED);
766 REGISTER_CURL_CONSTANT(CURLE_SSL_PEER_CERTIFICATE);
767 #if LIBCURL_VERSION_NUM >= 0x072700 /* Available since 7.39.0 */
768 REGISTER_CURL_CONSTANT(CURLE_SSL_PINNEDPUBKEYNOTMATCH);
770 REGISTER_CURL_CONSTANT(CURLE_TELNET_OPTION_SYNTAX);
771 REGISTER_CURL_CONSTANT(CURLE_TOO_MANY_REDIRECTS);
772 REGISTER_CURL_CONSTANT(CURLE_UNKNOWN_TELNET_OPTION);
773 REGISTER_CURL_CONSTANT(CURLE_UNSUPPORTED_PROTOCOL);
774 REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT);
775 REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT_USER);
776 REGISTER_CURL_CONSTANT(CURLE_WRITE_ERROR);
778 /* cURL info constants */
779 REGISTER_CURL_CONSTANT(CURLINFO_CONNECT_TIME);
780 REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_DOWNLOAD);
781 REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_UPLOAD);
782 REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_TYPE);
783 REGISTER_CURL_CONSTANT(CURLINFO_EFFECTIVE_URL);
784 REGISTER_CURL_CONSTANT(CURLINFO_FILETIME);
785 REGISTER_CURL_CONSTANT(CURLINFO_HEADER_OUT);
786 REGISTER_CURL_CONSTANT(CURLINFO_HEADER_SIZE);
787 REGISTER_CURL_CONSTANT(CURLINFO_HTTP_CODE);
788 REGISTER_CURL_CONSTANT(CURLINFO_LASTONE);
789 REGISTER_CURL_CONSTANT(CURLINFO_NAMELOOKUP_TIME);
790 REGISTER_CURL_CONSTANT(CURLINFO_PRETRANSFER_TIME);
791 REGISTER_CURL_CONSTANT(CURLINFO_PRIVATE);
792 REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_COUNT);
793 REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_TIME);
794 REGISTER_CURL_CONSTANT(CURLINFO_REQUEST_SIZE);
795 REGISTER_CURL_CONSTANT(CURLINFO_SIZE_DOWNLOAD);
796 REGISTER_CURL_CONSTANT(CURLINFO_SIZE_UPLOAD);
797 REGISTER_CURL_CONSTANT(CURLINFO_SPEED_DOWNLOAD);
798 REGISTER_CURL_CONSTANT(CURLINFO_SPEED_UPLOAD);
799 REGISTER_CURL_CONSTANT(CURLINFO_SSL_VERIFYRESULT);
800 REGISTER_CURL_CONSTANT(CURLINFO_STARTTRANSFER_TIME);
801 REGISTER_CURL_CONSTANT(CURLINFO_TOTAL_TIME);
804 REGISTER_CURL_CONSTANT(CURLMSG_DONE);
805 REGISTER_CURL_CONSTANT(CURLVERSION_NOW);
807 /* Curl Multi Constants */
808 REGISTER_CURL_CONSTANT(CURLM_BAD_EASY_HANDLE);
809 REGISTER_CURL_CONSTANT(CURLM_BAD_HANDLE);
810 REGISTER_CURL_CONSTANT(CURLM_CALL_MULTI_PERFORM);
811 REGISTER_CURL_CONSTANT(CURLM_INTERNAL_ERROR);
812 REGISTER_CURL_CONSTANT(CURLM_OK);
813 REGISTER_CURL_CONSTANT(CURLM_OUT_OF_MEMORY);
814 #if LIBCURL_VERSION_NUM >= 0x072001 /* Available since 7.32.1 */
815 REGISTER_CURL_CONSTANT(CURLM_ADDED_ALREADY);
818 /* Curl proxy constants */
819 REGISTER_CURL_CONSTANT(CURLPROXY_HTTP);
820 REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS4);
821 REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS5);
823 /* Curl Share constants */
824 REGISTER_CURL_CONSTANT(CURLSHOPT_NONE);
825 REGISTER_CURL_CONSTANT(CURLSHOPT_SHARE);
826 REGISTER_CURL_CONSTANT(CURLSHOPT_UNSHARE);
828 /* Curl Http Version constants (CURLOPT_HTTP_VERSION) */
829 REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_0);
830 REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_1);
831 REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_NONE);
833 /* Curl Lock constants */
834 REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_COOKIE);
835 REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_DNS);
836 REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_SSL_SESSION);
838 /* Curl NETRC constants (CURLOPT_NETRC) */
839 REGISTER_CURL_CONSTANT(CURL_NETRC_IGNORED);
840 REGISTER_CURL_CONSTANT(CURL_NETRC_OPTIONAL);
841 REGISTER_CURL_CONSTANT(CURL_NETRC_REQUIRED);
843 /* Curl SSL Version constants (CURLOPT_SSLVERSION) */
844 REGISTER_CURL_CONSTANT(CURL_SSLVERSION_DEFAULT);
845 REGISTER_CURL_CONSTANT(CURL_SSLVERSION_SSLv2);
846 REGISTER_CURL_CONSTANT(CURL_SSLVERSION_SSLv3);
847 REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1);
849 /* Curl TIMECOND constants (CURLOPT_TIMECONDITION) */
850 REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFMODSINCE);
851 REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFUNMODSINCE);
852 REGISTER_CURL_CONSTANT(CURL_TIMECOND_LASTMOD);
853 REGISTER_CURL_CONSTANT(CURL_TIMECOND_NONE);
855 /* Curl version constants */
856 REGISTER_CURL_CONSTANT(CURL_VERSION_ASYNCHDNS);
857 REGISTER_CURL_CONSTANT(CURL_VERSION_CONV);
858 REGISTER_CURL_CONSTANT(CURL_VERSION_DEBUG);
859 REGISTER_CURL_CONSTANT(CURL_VERSION_GSSNEGOTIATE);
860 REGISTER_CURL_CONSTANT(CURL_VERSION_IDN);
861 REGISTER_CURL_CONSTANT(CURL_VERSION_IPV6);
862 REGISTER_CURL_CONSTANT(CURL_VERSION_KERBEROS4);
863 REGISTER_CURL_CONSTANT(CURL_VERSION_LARGEFILE);
864 REGISTER_CURL_CONSTANT(CURL_VERSION_LIBZ);
865 REGISTER_CURL_CONSTANT(CURL_VERSION_NTLM);
866 REGISTER_CURL_CONSTANT(CURL_VERSION_SPNEGO);
867 REGISTER_CURL_CONSTANT(CURL_VERSION_SSL);
868 REGISTER_CURL_CONSTANT(CURL_VERSION_SSPI);
870 /* Available since 7.10.6 */
871 REGISTER_CURL_CONSTANT(CURLOPT_HTTPAUTH);
872 /* http authentication options */
873 REGISTER_CURL_CONSTANT(CURLAUTH_ANY);
874 REGISTER_CURL_CONSTANT(CURLAUTH_ANYSAFE);
875 REGISTER_CURL_CONSTANT(CURLAUTH_BASIC);
876 REGISTER_CURL_CONSTANT(CURLAUTH_DIGEST);
877 REGISTER_CURL_CONSTANT(CURLAUTH_GSSNEGOTIATE);
878 REGISTER_CURL_CONSTANT(CURLAUTH_NONE);
879 REGISTER_CURL_CONSTANT(CURLAUTH_NTLM);
881 /* Available since 7.10.7 */
882 REGISTER_CURL_CONSTANT(CURLINFO_HTTP_CONNECTCODE);
883 REGISTER_CURL_CONSTANT(CURLOPT_FTP_CREATE_MISSING_DIRS);
884 REGISTER_CURL_CONSTANT(CURLOPT_PROXYAUTH);
886 /* Available since 7.10.8 */
887 REGISTER_CURL_CONSTANT(CURLE_FILESIZE_EXCEEDED);
888 REGISTER_CURL_CONSTANT(CURLE_LDAP_INVALID_URL);
889 REGISTER_CURL_CONSTANT(CURLINFO_HTTPAUTH_AVAIL);
890 REGISTER_CURL_CONSTANT(CURLINFO_RESPONSE_CODE);
891 REGISTER_CURL_CONSTANT(CURLINFO_PROXYAUTH_AVAIL);
892 REGISTER_CURL_CONSTANT(CURLOPT_FTP_RESPONSE_TIMEOUT);
893 REGISTER_CURL_CONSTANT(CURLOPT_IPRESOLVE);
894 REGISTER_CURL_CONSTANT(CURLOPT_MAXFILESIZE);
895 REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V4);
896 REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V6);
897 REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_WHATEVER);
899 /* Available since 7.11.0 */
900 REGISTER_CURL_CONSTANT(CURLE_FTP_SSL_FAILED);
901 REGISTER_CURL_CONSTANT(CURLFTPSSL_ALL);
902 REGISTER_CURL_CONSTANT(CURLFTPSSL_CONTROL);
903 REGISTER_CURL_CONSTANT(CURLFTPSSL_NONE);
904 REGISTER_CURL_CONSTANT(CURLFTPSSL_TRY);
905 REGISTER_CURL_CONSTANT(CURLOPT_FTP_SSL);
906 REGISTER_CURL_CONSTANT(CURLOPT_NETRC_FILE);
908 /* Available since 7.11.2 */
909 REGISTER_CURL_CONSTANT(CURLOPT_TCP_NODELAY);
911 /* Available since 7.12.2 */
912 REGISTER_CURL_CONSTANT(CURLFTPAUTH_DEFAULT);
913 REGISTER_CURL_CONSTANT(CURLFTPAUTH_SSL);
914 REGISTER_CURL_CONSTANT(CURLFTPAUTH_TLS);
915 REGISTER_CURL_CONSTANT(CURLOPT_FTPSSLAUTH);
917 /* Available since 7.13.0 */
918 REGISTER_CURL_CONSTANT(CURLOPT_FTP_ACCOUNT);
920 /* Available since 7.12.2 */
921 REGISTER_CURL_CONSTANT(CURLINFO_OS_ERRNO);
923 /* Available since 7.12.3 */
924 REGISTER_CURL_CONSTANT(CURLINFO_NUM_CONNECTS);
925 REGISTER_CURL_CONSTANT(CURLINFO_SSL_ENGINES);
927 /* Available since 7.14.1 */
928 REGISTER_CURL_CONSTANT(CURLINFO_COOKIELIST);
929 REGISTER_CURL_CONSTANT(CURLOPT_COOKIELIST);
930 REGISTER_CURL_CONSTANT(CURLOPT_IGNORE_CONTENT_LENGTH);
932 /* Available since 7.15.0 */
933 REGISTER_CURL_CONSTANT(CURLOPT_FTP_SKIP_PASV_IP);
935 /* Available since 7.15.1 */
936 REGISTER_CURL_CONSTANT(CURLOPT_FTP_FILEMETHOD);
938 /* Available since 7.15.2 */
939 REGISTER_CURL_CONSTANT(CURLOPT_CONNECT_ONLY);
940 REGISTER_CURL_CONSTANT(CURLOPT_LOCALPORT);
941 REGISTER_CURL_CONSTANT(CURLOPT_LOCALPORTRANGE);
943 /* Available since 7.15.3 */
944 REGISTER_CURL_CONSTANT(CURLFTPMETHOD_MULTICWD);
945 REGISTER_CURL_CONSTANT(CURLFTPMETHOD_NOCWD);
946 REGISTER_CURL_CONSTANT(CURLFTPMETHOD_SINGLECWD);
948 /* Available since 7.15.4 */
949 REGISTER_CURL_CONSTANT(CURLINFO_FTP_ENTRY_PATH);
951 /* Available since 7.15.5 */
952 REGISTER_CURL_CONSTANT(CURLOPT_FTP_ALTERNATIVE_TO_USER);
953 REGISTER_CURL_CONSTANT(CURLOPT_MAX_RECV_SPEED_LARGE);
954 REGISTER_CURL_CONSTANT(CURLOPT_MAX_SEND_SPEED_LARGE);
956 #if LIBCURL_VERSION_NUM >= 0x071000 /* Available since 7.16.0 */
957 REGISTER_CURL_CONSTANT(CURLE_SSL_CACERT_BADFILE);
958 REGISTER_CURL_CONSTANT(CURLOPT_SSL_SESSIONID_CACHE);
959 REGISTER_CURL_CONSTANT(CURLMOPT_PIPELINING);
962 #if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */
963 REGISTER_CURL_CONSTANT(CURLE_SSH);
964 REGISTER_CURL_CONSTANT(CURLOPT_FTP_SSL_CCC);
965 REGISTER_CURL_CONSTANT(CURLOPT_SSH_AUTH_TYPES);
966 REGISTER_CURL_CONSTANT(CURLOPT_SSH_PRIVATE_KEYFILE);
967 REGISTER_CURL_CONSTANT(CURLOPT_SSH_PUBLIC_KEYFILE);
968 REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_ACTIVE);
969 REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_NONE);
970 REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_PASSIVE);
973 #if LIBCURL_VERSION_NUM >= 0x071002 /* Available since 7.16.2 */
974 REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT_MS);
975 REGISTER_CURL_CONSTANT(CURLOPT_HTTP_CONTENT_DECODING);
976 REGISTER_CURL_CONSTANT(CURLOPT_HTTP_TRANSFER_DECODING);
977 REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT_MS);
980 #if LIBCURL_VERSION_NUM >= 0x071003 /* Available since 7.16.3 */
981 REGISTER_CURL_CONSTANT(CURLMOPT_MAXCONNECTS);
984 #if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */
985 REGISTER_CURL_CONSTANT(CURLOPT_KRBLEVEL);
986 REGISTER_CURL_CONSTANT(CURLOPT_NEW_DIRECTORY_PERMS);
987 REGISTER_CURL_CONSTANT(CURLOPT_NEW_FILE_PERMS);
990 #if LIBCURL_VERSION_NUM >= 0x071100 /* Available since 7.17.0 */
991 REGISTER_CURL_CONSTANT(CURLOPT_APPEND);
992 REGISTER_CURL_CONSTANT(CURLOPT_DIRLISTONLY);
993 REGISTER_CURL_CONSTANT(CURLOPT_USE_SSL);
994 /* Curl SSL Constants */
995 REGISTER_CURL_CONSTANT(CURLUSESSL_ALL);
996 REGISTER_CURL_CONSTANT(CURLUSESSL_CONTROL);
997 REGISTER_CURL_CONSTANT(CURLUSESSL_NONE);
998 REGISTER_CURL_CONSTANT(CURLUSESSL_TRY);
1001 #if LIBCURL_VERSION_NUM >= 0x071101 /* Available since 7.17.1 */
1002 REGISTER_CURL_CONSTANT(CURLOPT_SSH_HOST_PUBLIC_KEY_MD5);
1005 #if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */
1006 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_TRANSFER_MODE);
1007 REGISTER_CURL_CONSTANT(CURLPAUSE_ALL);
1008 REGISTER_CURL_CONSTANT(CURLPAUSE_CONT);
1009 REGISTER_CURL_CONSTANT(CURLPAUSE_RECV);
1010 REGISTER_CURL_CONSTANT(CURLPAUSE_RECV_CONT);
1011 REGISTER_CURL_CONSTANT(CURLPAUSE_SEND);
1012 REGISTER_CURL_CONSTANT(CURLPAUSE_SEND_CONT);
1013 REGISTER_CURL_CONSTANT(CURL_READFUNC_PAUSE);
1014 REGISTER_CURL_CONSTANT(CURL_WRITEFUNC_PAUSE);
1016 REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS4A);
1017 REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS5_HOSTNAME);
1020 #if LIBCURL_VERSION_NUM >= 0x071202 /* Available since 7.18.2 */
1021 REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_URL);
1024 #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
1025 REGISTER_CURL_CONSTANT(CURLINFO_APPCONNECT_TIME);
1026 REGISTER_CURL_CONSTANT(CURLINFO_PRIMARY_IP);
1028 REGISTER_CURL_CONSTANT(CURLOPT_ADDRESS_SCOPE);
1029 REGISTER_CURL_CONSTANT(CURLOPT_CRLFILE);
1030 REGISTER_CURL_CONSTANT(CURLOPT_ISSUERCERT);
1031 REGISTER_CURL_CONSTANT(CURLOPT_KEYPASSWD);
1033 REGISTER_CURL_CONSTANT(CURLSSH_AUTH_ANY);
1034 REGISTER_CURL_CONSTANT(CURLSSH_AUTH_DEFAULT);
1035 REGISTER_CURL_CONSTANT(CURLSSH_AUTH_HOST);
1036 REGISTER_CURL_CONSTANT(CURLSSH_AUTH_KEYBOARD);
1037 REGISTER_CURL_CONSTANT(CURLSSH_AUTH_NONE);
1038 REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PASSWORD);
1039 REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PUBLICKEY);
1042 #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
1043 REGISTER_CURL_CONSTANT(CURLINFO_CERTINFO);
1044 REGISTER_CURL_CONSTANT(CURLOPT_CERTINFO);
1045 REGISTER_CURL_CONSTANT(CURLOPT_PASSWORD);
1046 REGISTER_CURL_CONSTANT(CURLOPT_POSTREDIR);
1047 REGISTER_CURL_CONSTANT(CURLOPT_PROXYPASSWORD);
1048 REGISTER_CURL_CONSTANT(CURLOPT_PROXYUSERNAME);
1049 REGISTER_CURL_CONSTANT(CURLOPT_USERNAME);
1050 REGISTER_CURL_CONSTANT(CURL_REDIR_POST_301);
1051 REGISTER_CURL_CONSTANT(CURL_REDIR_POST_302);
1052 REGISTER_CURL_CONSTANT(CURL_REDIR_POST_ALL);
1055 #if LIBCURL_VERSION_NUM >= 0x071303 /* Available since 7.19.3 */
1056 REGISTER_CURL_CONSTANT(CURLAUTH_DIGEST_IE);
1059 #if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */
1060 REGISTER_CURL_CONSTANT(CURLINFO_CONDITION_UNMET);
1062 REGISTER_CURL_CONSTANT(CURLOPT_NOPROXY);
1063 REGISTER_CURL_CONSTANT(CURLOPT_PROTOCOLS);
1064 REGISTER_CURL_CONSTANT(CURLOPT_REDIR_PROTOCOLS);
1065 REGISTER_CURL_CONSTANT(CURLOPT_SOCKS5_GSSAPI_NEC);
1066 REGISTER_CURL_CONSTANT(CURLOPT_SOCKS5_GSSAPI_SERVICE);
1067 REGISTER_CURL_CONSTANT(CURLOPT_TFTP_BLKSIZE);
1069 REGISTER_CURL_CONSTANT(CURLPROTO_ALL);
1070 REGISTER_CURL_CONSTANT(CURLPROTO_DICT);
1071 REGISTER_CURL_CONSTANT(CURLPROTO_FILE);
1072 REGISTER_CURL_CONSTANT(CURLPROTO_FTP);
1073 REGISTER_CURL_CONSTANT(CURLPROTO_FTPS);
1074 REGISTER_CURL_CONSTANT(CURLPROTO_HTTP);
1075 REGISTER_CURL_CONSTANT(CURLPROTO_HTTPS);
1076 REGISTER_CURL_CONSTANT(CURLPROTO_LDAP);
1077 REGISTER_CURL_CONSTANT(CURLPROTO_LDAPS);
1078 REGISTER_CURL_CONSTANT(CURLPROTO_SCP);
1079 REGISTER_CURL_CONSTANT(CURLPROTO_SFTP);
1080 REGISTER_CURL_CONSTANT(CURLPROTO_TELNET);
1081 REGISTER_CURL_CONSTANT(CURLPROTO_TFTP);
1083 REGISTER_CURL_CONSTANT(CURLPROXY_HTTP_1_0);
1085 REGISTER_CURL_CONSTANT(CURLFTP_CREATE_DIR);
1086 REGISTER_CURL_CONSTANT(CURLFTP_CREATE_DIR_NONE);
1087 REGISTER_CURL_CONSTANT(CURLFTP_CREATE_DIR_RETRY);
1090 #if LIBCURL_VERSION_NUM >= 0x071306 /* Available since 7.19.6 */
1091 REGISTER_CURL_CONSTANT(CURL_VERSION_CURLDEBUG);
1092 REGISTER_CURL_CONSTANT(CURLOPT_SSH_KNOWNHOSTS);
1095 #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
1096 REGISTER_CURL_CONSTANT(CURLINFO_RTSP_CLIENT_CSEQ);
1097 REGISTER_CURL_CONSTANT(CURLINFO_RTSP_CSEQ_RECV);
1098 REGISTER_CURL_CONSTANT(CURLINFO_RTSP_SERVER_CSEQ);
1099 REGISTER_CURL_CONSTANT(CURLINFO_RTSP_SESSION_ID);
1100 REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_PRET);
1101 REGISTER_CURL_CONSTANT(CURLOPT_MAIL_FROM);
1102 REGISTER_CURL_CONSTANT(CURLOPT_MAIL_RCPT);
1103 REGISTER_CURL_CONSTANT(CURLOPT_RTSP_CLIENT_CSEQ);
1104 REGISTER_CURL_CONSTANT(CURLOPT_RTSP_REQUEST);
1105 REGISTER_CURL_CONSTANT(CURLOPT_RTSP_SERVER_CSEQ);
1106 REGISTER_CURL_CONSTANT(CURLOPT_RTSP_SESSION_ID);
1107 REGISTER_CURL_CONSTANT(CURLOPT_RTSP_STREAM_URI);
1108 REGISTER_CURL_CONSTANT(CURLOPT_RTSP_TRANSPORT);
1109 REGISTER_CURL_CONSTANT(CURLPROTO_IMAP);
1110 REGISTER_CURL_CONSTANT(CURLPROTO_IMAPS);
1111 REGISTER_CURL_CONSTANT(CURLPROTO_POP3);
1112 REGISTER_CURL_CONSTANT(CURLPROTO_POP3S);
1113 REGISTER_CURL_CONSTANT(CURLPROTO_RTSP);
1114 REGISTER_CURL_CONSTANT(CURLPROTO_SMTP);
1115 REGISTER_CURL_CONSTANT(CURLPROTO_SMTPS);
1116 REGISTER_CURL_CONSTANT(CURL_RTSPREQ_ANNOUNCE);
1117 REGISTER_CURL_CONSTANT(CURL_RTSPREQ_DESCRIBE);
1118 REGISTER_CURL_CONSTANT(CURL_RTSPREQ_GET_PARAMETER);
1119 REGISTER_CURL_CONSTANT(CURL_RTSPREQ_OPTIONS);
1120 REGISTER_CURL_CONSTANT(CURL_RTSPREQ_PAUSE);
1121 REGISTER_CURL_CONSTANT(CURL_RTSPREQ_PLAY);
1122 REGISTER_CURL_CONSTANT(CURL_RTSPREQ_RECEIVE);
1123 REGISTER_CURL_CONSTANT(CURL_RTSPREQ_RECORD);
1124 REGISTER_CURL_CONSTANT(CURL_RTSPREQ_SET_PARAMETER);
1125 REGISTER_CURL_CONSTANT(CURL_RTSPREQ_SETUP);
1126 REGISTER_CURL_CONSTANT(CURL_RTSPREQ_TEARDOWN);
1129 #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
1130 REGISTER_CURL_CONSTANT(CURLINFO_LOCAL_IP);
1131 REGISTER_CURL_CONSTANT(CURLINFO_LOCAL_PORT);
1132 REGISTER_CURL_CONSTANT(CURLINFO_PRIMARY_PORT);
1133 REGISTER_CURL_CONSTANT(CURLOPT_FNMATCH_FUNCTION);
1134 REGISTER_CURL_CONSTANT(CURLOPT_WILDCARDMATCH);
1135 REGISTER_CURL_CONSTANT(CURLPROTO_RTMP);
1136 REGISTER_CURL_CONSTANT(CURLPROTO_RTMPE);
1137 REGISTER_CURL_CONSTANT(CURLPROTO_RTMPS);
1138 REGISTER_CURL_CONSTANT(CURLPROTO_RTMPT);
1139 REGISTER_CURL_CONSTANT(CURLPROTO_RTMPTE);
1140 REGISTER_CURL_CONSTANT(CURLPROTO_RTMPTS);
1141 REGISTER_CURL_CONSTANT(CURL_FNMATCHFUNC_FAIL);
1142 REGISTER_CURL_CONSTANT(CURL_FNMATCHFUNC_MATCH);
1143 REGISTER_CURL_CONSTANT(CURL_FNMATCHFUNC_NOMATCH);
1146 #if LIBCURL_VERSION_NUM >= 0x071502 /* Available since 7.21.2 */
1147 REGISTER_CURL_CONSTANT(CURLPROTO_GOPHER);
1150 #if LIBCURL_VERSION_NUM >= 0x071503 /* Available since 7.21.3 */
1151 REGISTER_CURL_CONSTANT(CURLAUTH_ONLY);
1152 REGISTER_CURL_CONSTANT(CURLOPT_RESOLVE);
1155 #if LIBCURL_VERSION_NUM >= 0x071504 /* Available since 7.21.4 */
1156 REGISTER_CURL_CONSTANT(CURLOPT_TLSAUTH_PASSWORD);
1157 REGISTER_CURL_CONSTANT(CURLOPT_TLSAUTH_TYPE);
1158 REGISTER_CURL_CONSTANT(CURLOPT_TLSAUTH_USERNAME);
1159 REGISTER_CURL_CONSTANT(CURL_TLSAUTH_SRP);
1160 REGISTER_CURL_CONSTANT(CURL_VERSION_TLSAUTH_SRP);
1163 #if LIBCURL_VERSION_NUM >= 0x071506 /* Available since 7.21.6 */
1164 REGISTER_CURL_CONSTANT(CURLOPT_ACCEPT_ENCODING);
1165 REGISTER_CURL_CONSTANT(CURLOPT_TRANSFER_ENCODING);
1168 #if LIBCURL_VERSION_NUM >= 0x071600 /* Available since 7.22.0 */
1169 REGISTER_CURL_CONSTANT(CURLAUTH_NTLM_WB);
1170 REGISTER_CURL_CONSTANT(CURLGSSAPI_DELEGATION_FLAG);
1171 REGISTER_CURL_CONSTANT(CURLGSSAPI_DELEGATION_POLICY_FLAG);
1172 REGISTER_CURL_CONSTANT(CURLOPT_GSSAPI_DELEGATION);
1173 REGISTER_CURL_CONSTANT(CURL_VERSION_NTLM_WB);
1176 #if LIBCURL_VERSION_NUM >= 0x071800 /* Available since 7.24.0 */
1177 REGISTER_CURL_CONSTANT(CURLOPT_ACCEPTTIMEOUT_MS);
1178 REGISTER_CURL_CONSTANT(CURLOPT_DNS_SERVERS);
1181 #if LIBCURL_VERSION_NUM >= 0x071900 /* Available since 7.25.0 */
1182 REGISTER_CURL_CONSTANT(CURLOPT_MAIL_AUTH);
1183 REGISTER_CURL_CONSTANT(CURLOPT_SSL_OPTIONS);
1184 REGISTER_CURL_CONSTANT(CURLOPT_TCP_KEEPALIVE);
1185 REGISTER_CURL_CONSTANT(CURLOPT_TCP_KEEPIDLE);
1186 REGISTER_CURL_CONSTANT(CURLOPT_TCP_KEEPINTVL);
1187 REGISTER_CURL_CONSTANT(CURLSSLOPT_ALLOW_BEAST);
1190 #if LIBCURL_VERSION_NUM >= 0x071901 /* Available since 7.25.1 */
1191 REGISTER_CURL_CONSTANT(CURL_REDIR_POST_303);
1194 #if LIBCURL_VERSION_NUM >= 0x071c00 /* Available since 7.28.0 */
1195 REGISTER_CURL_CONSTANT(CURLSSH_AUTH_AGENT);
1198 #if LIBCURL_VERSION_NUM >= 0x071e00 /* Available since 7.30.0 */
1199 REGISTER_CURL_CONSTANT(CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE);
1200 REGISTER_CURL_CONSTANT(CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE);
1201 REGISTER_CURL_CONSTANT(CURLMOPT_MAX_HOST_CONNECTIONS);
1202 REGISTER_CURL_CONSTANT(CURLMOPT_MAX_PIPELINE_LENGTH);
1203 REGISTER_CURL_CONSTANT(CURLMOPT_MAX_TOTAL_CONNECTIONS);
1206 #if LIBCURL_VERSION_NUM >= 0x071f00 /* Available since 7.31.0 */
1207 REGISTER_CURL_CONSTANT(CURLOPT_SASL_IR);
1210 #if LIBCURL_VERSION_NUM >= 0x072100 /* Available since 7.33.0 */
1211 REGISTER_CURL_CONSTANT(CURLOPT_DNS_INTERFACE);
1212 REGISTER_CURL_CONSTANT(CURLOPT_DNS_LOCAL_IP4);
1213 REGISTER_CURL_CONSTANT(CURLOPT_DNS_LOCAL_IP6);
1214 REGISTER_CURL_CONSTANT(CURLOPT_XOAUTH2_BEARER);
1216 REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_2_0);
1217 REGISTER_CURL_CONSTANT(CURL_VERSION_HTTP2);
1220 #if LIBCURL_VERSION_NUM >= 0x072200 /* Available since 7.34.0 */
1221 REGISTER_CURL_CONSTANT(CURLOPT_LOGIN_OPTIONS);
1223 REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1_0);
1224 REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1_1);
1225 REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1_2);
1228 #if LIBCURL_VERSION_NUM >= 0x072400 /* Available since 7.36.0 */
1229 REGISTER_CURL_CONSTANT(CURLOPT_EXPECT_100_TIMEOUT_MS);
1230 REGISTER_CURL_CONSTANT(CURLOPT_SSL_ENABLE_ALPN);
1231 REGISTER_CURL_CONSTANT(CURLOPT_SSL_ENABLE_NPN);
1234 #if LIBCURL_VERSION_NUM >= 0x072500 /* Available since 7.37.0 */
1235 REGISTER_CURL_CONSTANT(CURLHEADER_SEPARATE);
1236 REGISTER_CURL_CONSTANT(CURLHEADER_UNIFIED);
1237 REGISTER_CURL_CONSTANT(CURLOPT_HEADEROPT);
1238 REGISTER_CURL_CONSTANT(CURLOPT_PROXYHEADER);
1241 #if LIBCURL_VERSION_NUM >= 0x072600 /* Available since 7.38.0 */
1242 REGISTER_CURL_CONSTANT(CURLAUTH_NEGOTIATE);
1243 REGISTER_CURL_CONSTANT(CURL_VERSION_GSSAPI);
1246 #if LIBCURL_VERSION_NUM >= 0x072700 /* Available since 7.39.0 */
1247 REGISTER_CURL_CONSTANT(CURLOPT_PINNEDPUBLICKEY);
1250 #if LIBCURL_VERSION_NUM >= 0x072800 /* Available since 7.40.0 */
1251 REGISTER_CURL_CONSTANT(CURLOPT_UNIX_SOCKET_PATH);
1252 REGISTER_CURL_CONSTANT(CURLPROTO_SMB);
1253 REGISTER_CURL_CONSTANT(CURLPROTO_SMBS);
1254 REGISTER_CURL_CONSTANT(CURL_VERSION_KERBEROS5);
1255 REGISTER_CURL_CONSTANT(CURL_VERSION_UNIX_SOCKETS);
1258 #if LIBCURL_VERSION_NUM >= 0x072900 /* Available since 7.41.0 */
1259 REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYSTATUS);
1262 #if LIBCURL_VERSION_NUM >= 0x072a00 /* Available since 7.42.0 */
1263 REGISTER_CURL_CONSTANT(CURLOPT_PATH_AS_IS);
1264 REGISTER_CURL_CONSTANT(CURLOPT_SSL_FALSESTART);
1267 #if LIBCURL_VERSION_NUM >= 0x072b00 /* Available since 7.43.0 */
1268 REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_2);
1270 REGISTER_CURL_CONSTANT(CURLOPT_PIPEWAIT);
1271 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SERVICE_NAME);
1272 REGISTER_CURL_CONSTANT(CURLOPT_SERVICE_NAME);
1274 REGISTER_CURL_CONSTANT(CURLPIPE_NOTHING);
1275 REGISTER_CURL_CONSTANT(CURLPIPE_HTTP1);
1276 REGISTER_CURL_CONSTANT(CURLPIPE_MULTIPLEX);
1279 #if LIBCURL_VERSION_NUM >= 0x072c00 /* Available since 7.44.0 */
1280 REGISTER_CURL_CONSTANT(CURLSSLOPT_NO_REVOKE);
1283 #if LIBCURL_VERSION_NUM >= 0x072d00 /* Available since 7.45.0 */
1284 REGISTER_CURL_CONSTANT(CURLOPT_DEFAULT_PROTOCOL);
1287 #if LIBCURL_VERSION_NUM >= 0x072e00 /* Available since 7.46.0 */
1288 REGISTER_CURL_CONSTANT(CURLOPT_STREAM_WEIGHT);
1289 REGISTER_CURL_CONSTANT(CURLMOPT_PUSHFUNCTION);
1290 REGISTER_CURL_CONSTANT(CURL_PUSH_OK);
1291 REGISTER_CURL_CONSTANT(CURL_PUSH_DENY);
1294 #if LIBCURL_VERSION_NUM >= 0x072f00 /* Available since 7.47.0 */
1295 REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_2TLS);
1296 REGISTER_CURL_CONSTANT(CURL_VERSION_PSL);
1299 #if LIBCURL_VERSION_NUM >= 0x073000 /* Available since 7.48.0 */
1300 REGISTER_CURL_CONSTANT(CURLOPT_TFTP_NO_OPTIONS);
1303 #if LIBCURL_VERSION_NUM >= 0x073100 /* Available since 7.49.0 */
1304 REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE);
1305 REGISTER_CURL_CONSTANT(CURLOPT_CONNECT_TO);
1306 REGISTER_CURL_CONSTANT(CURLOPT_TCP_FASTOPEN);
1309 #if LIBCURL_VERSION_NUM >= 0x073200 /* Available since 7.50.0 */
1310 REGISTER_CURL_CONSTANT(CURLINFO_HTTP_VERSION);
1313 #if LIBCURL_VERSION_NUM >= 0x073300 /* Available since 7.51.0 */
1314 REGISTER_CURL_CONSTANT(CURLE_WEIRD_SERVER_REPLY);
1315 REGISTER_CURL_CONSTANT(CURLOPT_KEEP_SENDING_ON_ERROR);
1318 #if LIBCURL_VERSION_NUM >= 0x073400 /* Available since 7.52.0 */
1319 REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1_3);
1320 REGISTER_CURL_CONSTANT(CURL_VERSION_HTTPS_PROXY);
1321 REGISTER_CURL_CONSTANT(CURLINFO_PROTOCOL);
1322 REGISTER_CURL_CONSTANT(CURLINFO_PROXY_SSL_VERIFYRESULT);
1323 REGISTER_CURL_CONSTANT(CURLINFO_SCHEME);
1324 REGISTER_CURL_CONSTANT(CURLOPT_PRE_PROXY);
1325 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_CAINFO);
1326 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_CAPATH);
1327 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_CRLFILE);
1328 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_KEYPASSWD);
1329 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_PINNEDPUBLICKEY);
1330 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSL_CIPHER_LIST);
1331 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSL_OPTIONS);
1332 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSL_VERIFYHOST);
1333 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSL_VERIFYPEER);
1334 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSLCERT);
1335 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSLCERTTYPE);
1336 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSLKEY);
1337 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSLKEYTYPE);
1338 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSLVERSION);
1339 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_TLSAUTH_PASSWORD);
1340 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_TLSAUTH_TYPE);
1341 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_TLSAUTH_USERNAME);
1342 REGISTER_CURL_CONSTANT(CURLPROXY_HTTPS);
1345 #if LIBCURL_VERSION_NUM >= 0x073500 /* Available since 7.53.0 */
1346 REGISTER_CURL_CONSTANT(CURL_MAX_READ_SIZE);
1347 REGISTER_CURL_CONSTANT(CURLOPT_ABSTRACT_UNIX_SOCKET);
1350 #if LIBCURL_VERSION_NUM >= 0x073600 /* Available since 7.54.0 */
1351 REGISTER_CURL_CONSTANT(CURL_SSLVERSION_MAX_DEFAULT);
1352 REGISTER_CURL_CONSTANT(CURL_SSLVERSION_MAX_NONE);
1353 REGISTER_CURL_CONSTANT(CURL_SSLVERSION_MAX_TLSv1_0);
1354 REGISTER_CURL_CONSTANT(CURL_SSLVERSION_MAX_TLSv1_1);
1355 REGISTER_CURL_CONSTANT(CURL_SSLVERSION_MAX_TLSv1_2);
1356 REGISTER_CURL_CONSTANT(CURL_SSLVERSION_MAX_TLSv1_3);
1357 REGISTER_CURL_CONSTANT(CURLOPT_SUPPRESS_CONNECT_HEADERS);
1360 #if LIBCURL_VERSION_NUM >= 0x073601 /* Available since 7.54.1 */
1361 REGISTER_CURL_CONSTANT(CURLAUTH_GSSAPI);
1364 #if LIBCURL_VERSION_NUM >= 0x073700 /* Available since 7.55.0 */
1365 REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_DOWNLOAD_T);
1366 REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_UPLOAD_T);
1367 REGISTER_CURL_CONSTANT(CURLINFO_SIZE_DOWNLOAD_T);
1368 REGISTER_CURL_CONSTANT(CURLINFO_SIZE_UPLOAD_T);
1369 REGISTER_CURL_CONSTANT(CURLINFO_SPEED_DOWNLOAD_T);
1370 REGISTER_CURL_CONSTANT(CURLINFO_SPEED_UPLOAD_T);
1371 REGISTER_CURL_CONSTANT(CURLOPT_REQUEST_TARGET);
1372 REGISTER_CURL_CONSTANT(CURLOPT_SOCKS5_AUTH);
1375 #if LIBCURL_VERSION_NUM >= 0x073800 /* Available since 7.56.0 */
1376 REGISTER_CURL_CONSTANT(CURLOPT_SSH_COMPRESSION);
1377 REGISTER_CURL_CONSTANT(CURL_VERSION_MULTI_SSL);
1380 #if LIBCURL_VERSION_NUM >= 0x073900 /* Available since 7.57.0 */
1381 REGISTER_CURL_CONSTANT(CURL_VERSION_BROTLI);
1382 REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_CONNECT);
1385 #if LIBCURL_VERSION_NUM >= 0x073a00 /* Available since 7.58.0 */
1386 REGISTER_CURL_CONSTANT(CURLSSH_AUTH_GSSAPI);
1389 #if LIBCURL_VERSION_NUM >= 0x073b00 /* Available since 7.59.0 */
1390 REGISTER_CURL_CONSTANT(CURLINFO_FILETIME_T);
1391 REGISTER_CURL_CONSTANT(CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS);
1392 REGISTER_CURL_CONSTANT(CURLOPT_TIMEVALUE_LARGE);
1395 #if LIBCURL_VERSION_NUM >= 0x073c00 /* Available since 7.60.0 */
1396 REGISTER_CURL_CONSTANT(CURLOPT_DNS_SHUFFLE_ADDRESSES);
1397 REGISTER_CURL_CONSTANT(CURLOPT_HAPROXYPROTOCOL);
1400 #if LIBCURL_VERSION_NUM >= 0x073d00 /* Available since 7.61.0 */
1401 REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_PSL);
1402 REGISTER_CURL_CONSTANT(CURLAUTH_BEARER);
1403 REGISTER_CURL_CONSTANT(CURLINFO_APPCONNECT_TIME_T);
1404 REGISTER_CURL_CONSTANT(CURLINFO_CONNECT_TIME_T);
1405 REGISTER_CURL_CONSTANT(CURLINFO_NAMELOOKUP_TIME_T);
1406 REGISTER_CURL_CONSTANT(CURLINFO_PRETRANSFER_TIME_T);
1407 REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_TIME_T);
1408 REGISTER_CURL_CONSTANT(CURLINFO_STARTTRANSFER_TIME_T);
1409 REGISTER_CURL_CONSTANT(CURLINFO_TOTAL_TIME_T);
1410 REGISTER_CURL_CONSTANT(CURLOPT_DISALLOW_USERNAME_IN_URL);
1411 REGISTER_CURL_CONSTANT(CURLOPT_PROXY_TLS13_CIPHERS);
1412 REGISTER_CURL_CONSTANT(CURLOPT_TLS13_CIPHERS);
1415 #if LIBCURL_VERSION_NUM >= 0x074001 /* Available since 7.64.1 */
1416 REGISTER_CURL_CONSTANT(CURL_VERSION_ALTSVC);
1419 REGISTER_CURL_CONSTANT(CURLOPT_SAFE_UPLOAD);
1421 #ifdef PHP_CURL_NEED_OPENSSL_TSL
1422 if (!CRYPTO_get_id_callback()) {
1423 int i, c = CRYPTO_num_locks();
1425 php_curl_openssl_tsl = malloc(c * sizeof(MUTEX_T));
1426 if (!php_curl_openssl_tsl) {
1430 for (i = 0; i < c; ++i) {
1431 php_curl_openssl_tsl[i] = tsrm_mutex_alloc();
1434 CRYPTO_set_id_callback(php_curl_ssl_id);
1435 CRYPTO_set_locking_callback(php_curl_ssl_lock);
1439 if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK) {
1443 curlfile_register_class();
1449 /* {{{ PHP_MSHUTDOWN_FUNCTION
1451 PHP_MSHUTDOWN_FUNCTION(curl)
1453 curl_global_cleanup();
1454 #ifdef PHP_CURL_NEED_OPENSSL_TSL
1455 if (php_curl_openssl_tsl) {
1456 int i, c = CRYPTO_num_locks();
1458 CRYPTO_set_id_callback(NULL);
1459 CRYPTO_set_locking_callback(NULL);
1461 for (i = 0; i < c; ++i) {
1462 tsrm_mutex_free(php_curl_openssl_tsl[i]);
1465 free(php_curl_openssl_tsl);
1466 php_curl_openssl_tsl = NULL;
1469 UNREGISTER_INI_ENTRIES();
1474 /* {{{ curl_write_nothing
1475 * Used as a work around. See _php_curl_close_ex
1477 static size_t curl_write_nothing(char *data, size_t size, size_t nmemb, void *ctx)
1479 return size * nmemb;
1485 static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx)
1487 php_curl *ch = (php_curl *) ctx;
1488 php_curl_write *t = ch->handlers->write;
1489 size_t length = size * nmemb;
1492 fprintf(stderr, "curl_write() called\n");
1493 fprintf(stderr, "data = %s, size = %d, nmemb = %d, ctx = %x\n", data, size, nmemb, ctx);
1496 switch (t->method) {
1497 case PHP_CURL_STDOUT:
1498 PHPWRITE(data, length);
1501 return fwrite(data, size, nmemb, t->fp);
1502 case PHP_CURL_RETURN:
1504 smart_str_appendl(&t->buf, data, (int) length);
1507 case PHP_CURL_USER: {
1511 zend_fcall_info fci;
1514 ZVAL_RES(&argv[0], ch->res);
1515 ZVAL_STRINGL(&argv[1], data, length);
1517 fci.size = sizeof(fci);
1519 ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
1520 fci.retval = &retval;
1521 fci.param_count = 2;
1523 fci.no_separation = 0;
1525 ch->in_callback = 1;
1526 error = zend_call_function(&fci, &t->fci_cache);
1527 ch->in_callback = 0;
1528 if (error == FAILURE) {
1529 php_error_docref(NULL, E_WARNING, "Could not call the CURLOPT_WRITEFUNCTION");
1531 } else if (!Z_ISUNDEF(retval)) {
1532 _php_curl_verify_handlers(ch, 1);
1533 length = zval_get_long(&retval);
1536 zval_ptr_dtor(&argv[0]);
1537 zval_ptr_dtor(&argv[1]);
1546 #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
1549 static int curl_fnmatch(void *ctx, const char *pattern, const char *string)
1551 php_curl *ch = (php_curl *) ctx;
1552 php_curl_fnmatch *t = ch->handlers->fnmatch;
1553 int rval = CURL_FNMATCHFUNC_FAIL;
1554 switch (t->method) {
1555 case PHP_CURL_USER: {
1559 zend_fcall_info fci;
1562 ZVAL_RES(&argv[0], ch->res);
1563 ZVAL_STRING(&argv[1], pattern);
1564 ZVAL_STRING(&argv[2], string);
1566 fci.size = sizeof(fci);
1567 ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
1569 fci.retval = &retval;
1570 fci.param_count = 3;
1572 fci.no_separation = 0;
1574 ch->in_callback = 1;
1575 error = zend_call_function(&fci, &t->fci_cache);
1576 ch->in_callback = 0;
1577 if (error == FAILURE) {
1578 php_error_docref(NULL, E_WARNING, "Cannot call the CURLOPT_FNMATCH_FUNCTION");
1579 } else if (!Z_ISUNDEF(retval)) {
1580 _php_curl_verify_handlers(ch, 1);
1581 rval = zval_get_long(&retval);
1583 zval_ptr_dtor(&argv[0]);
1584 zval_ptr_dtor(&argv[1]);
1585 zval_ptr_dtor(&argv[2]);
1594 /* {{{ curl_progress
1596 static size_t curl_progress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
1598 php_curl *ch = (php_curl *)clientp;
1599 php_curl_progress *t = ch->handlers->progress;
1603 fprintf(stderr, "curl_progress() called\n");
1604 fprintf(stderr, "clientp = %x, dltotal = %f, dlnow = %f, ultotal = %f, ulnow = %f\n", clientp, dltotal, dlnow, ultotal, ulnow);
1607 switch (t->method) {
1608 case PHP_CURL_USER: {
1612 zend_fcall_info fci;
1615 ZVAL_RES(&argv[0], ch->res);
1616 ZVAL_LONG(&argv[1], (zend_long)dltotal);
1617 ZVAL_LONG(&argv[2], (zend_long)dlnow);
1618 ZVAL_LONG(&argv[3], (zend_long)ultotal);
1619 ZVAL_LONG(&argv[4], (zend_long)ulnow);
1621 fci.size = sizeof(fci);
1622 ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
1624 fci.retval = &retval;
1625 fci.param_count = 5;
1627 fci.no_separation = 0;
1629 ch->in_callback = 1;
1630 error = zend_call_function(&fci, &t->fci_cache);
1631 ch->in_callback = 0;
1632 if (error == FAILURE) {
1633 php_error_docref(NULL, E_WARNING, "Cannot call the CURLOPT_PROGRESSFUNCTION");
1634 } else if (!Z_ISUNDEF(retval)) {
1635 _php_curl_verify_handlers(ch, 1);
1636 if (0 != zval_get_long(&retval)) {
1640 zval_ptr_dtor(&argv[0]);
1650 static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx)
1652 php_curl *ch = (php_curl *)ctx;
1653 php_curl_read *t = ch->handlers->read;
1656 switch (t->method) {
1657 case PHP_CURL_DIRECT:
1659 length = fread(data, size, nmemb, t->fp);
1662 case PHP_CURL_USER: {
1666 zend_fcall_info fci;
1669 ZVAL_RES(&argv[0], ch->res);
1672 ZVAL_RES(&argv[1], t->res);
1674 ZVAL_NULL(&argv[1]);
1676 ZVAL_LONG(&argv[2], (int)size * nmemb);
1678 fci.size = sizeof(fci);
1679 ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
1681 fci.retval = &retval;
1682 fci.param_count = 3;
1684 fci.no_separation = 0;
1686 ch->in_callback = 1;
1687 error = zend_call_function(&fci, &t->fci_cache);
1688 ch->in_callback = 0;
1689 if (error == FAILURE) {
1690 php_error_docref(NULL, E_WARNING, "Cannot call the CURLOPT_READFUNCTION");
1691 length = CURL_READFUNC_ABORT;
1692 } else if (!Z_ISUNDEF(retval)) {
1693 _php_curl_verify_handlers(ch, 1);
1694 if (Z_TYPE(retval) == IS_STRING) {
1695 length = MIN((int) (size * nmemb), Z_STRLEN(retval));
1696 memcpy(data, Z_STRVAL(retval), length);
1698 zval_ptr_dtor(&retval);
1701 zval_ptr_dtor(&argv[0]);
1702 zval_ptr_dtor(&argv[1]);
1711 /* {{{ curl_write_header
1713 static size_t curl_write_header(char *data, size_t size, size_t nmemb, void *ctx)
1715 php_curl *ch = (php_curl *) ctx;
1716 php_curl_write *t = ch->handlers->write_header;
1717 size_t length = size * nmemb;
1719 switch (t->method) {
1720 case PHP_CURL_STDOUT:
1721 /* Handle special case write when we're returning the entire transfer
1723 if (ch->handlers->write->method == PHP_CURL_RETURN && length > 0) {
1724 smart_str_appendl(&ch->handlers->write->buf, data, (int) length);
1726 PHPWRITE(data, length);
1730 return fwrite(data, size, nmemb, t->fp);
1731 case PHP_CURL_USER: {
1735 zend_fcall_info fci;
1738 ZVAL_RES(&argv[0], ch->res);
1739 ZVAL_STRINGL(&argv[1], data, length);
1741 fci.size = sizeof(fci);
1742 ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
1744 fci.retval = &retval;
1745 fci.param_count = 2;
1747 fci.no_separation = 0;
1749 ch->in_callback = 1;
1750 error = zend_call_function(&fci, &t->fci_cache);
1751 ch->in_callback = 0;
1752 if (error == FAILURE) {
1753 php_error_docref(NULL, E_WARNING, "Could not call the CURLOPT_HEADERFUNCTION");
1755 } else if (!Z_ISUNDEF(retval)) {
1756 _php_curl_verify_handlers(ch, 1);
1757 length = zval_get_long(&retval);
1759 zval_ptr_dtor(&argv[0]);
1760 zval_ptr_dtor(&argv[1]);
1764 case PHP_CURL_IGNORE:
1775 static int curl_debug(CURL *cp, curl_infotype type, char *buf, size_t buf_len, void *ctx) /* {{{ */
1777 php_curl *ch = (php_curl *)ctx;
1779 if (type == CURLINFO_HEADER_OUT) {
1780 if (ch->header.str) {
1781 zend_string_release_ex(ch->header.str, 0);
1784 ch->header.str = zend_string_init(buf, buf_len, 0);
1792 /* {{{ curl_free_string
1794 static void curl_free_string(void **string)
1796 efree((char *)*string);
1800 /* {{{ curl_free_post
1802 static void curl_free_post(void **post)
1804 #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
1805 curl_mime_free((curl_mime *)*post);
1807 curl_formfree((struct HttpPost *)*post);
1812 /* {{{ curl_free_stream
1814 static void curl_free_stream(void **post)
1816 php_stream_close((php_stream *)*post);
1820 /* {{{ curl_free_slist
1822 static void curl_free_slist(zval *el)
1824 curl_slist_free_all(((struct curl_slist *)Z_PTR_P(el)));
1828 /* {{{ proto array curl_version([int version])
1829 Return cURL version information. */
1830 PHP_FUNCTION(curl_version)
1832 curl_version_info_data *d;
1833 zend_long uversion = CURLVERSION_NOW;
1835 ZEND_PARSE_PARAMETERS_START(0, 1)
1837 Z_PARAM_LONG(uversion)
1838 ZEND_PARSE_PARAMETERS_END();
1840 d = curl_version_info(uversion);
1845 array_init(return_value);
1847 CAAL("version_number", d->version_num);
1848 CAAL("age", d->age);
1849 CAAL("features", d->features);
1850 CAAL("ssl_version_number", d->ssl_version_num);
1851 CAAS("version", d->version);
1852 CAAS("host", d->host);
1853 CAAS("ssl_version", d->ssl_version);
1854 CAAS("libz_version", d->libz_version);
1855 /* Add an array of protocols */
1857 char **p = (char **) d->protocols;
1860 array_init(&protocol_list);
1862 while (*p != NULL) {
1863 add_next_index_string(&protocol_list, *p);
1866 CAAZ("protocols", &protocol_list);
1869 CAAS("ares", d->ares);
1870 CAAL("ares_num", d->ares_num);
1873 CAAS("libidn", d->libidn);
1875 #if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */
1877 CAAL("iconv_ver_num", d->iconv_ver_num);
1878 CAAS("libssh_version", d->libssh_version);
1881 #if LIBCURL_VERSION_NUM >= 0x073900 /* Available since 7.57.0 */
1883 CAAL("brotli_ver_num", d->brotli_ver_num);
1884 CAAS("brotli_version", d->brotli_version);
1890 /* {{{ alloc_curl_handle
1892 php_curl *alloc_curl_handle()
1894 php_curl *ch = ecalloc(1, sizeof(php_curl));
1895 ch->to_free = ecalloc(1, sizeof(struct _php_curl_free));
1896 ch->handlers = ecalloc(1, sizeof(php_curl_handlers));
1897 ch->handlers->write = ecalloc(1, sizeof(php_curl_write));
1898 ch->handlers->write_header = ecalloc(1, sizeof(php_curl_write));
1899 ch->handlers->read = ecalloc(1, sizeof(php_curl_read));
1900 ch->handlers->progress = NULL;
1901 #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
1902 ch->handlers->fnmatch = NULL;
1904 ch->clone = emalloc(sizeof(uint32_t));
1907 memset(&ch->err, 0, sizeof(struct _php_curl_error));
1909 zend_llist_init(&ch->to_free->str, sizeof(char *), (llist_dtor_func_t)curl_free_string, 0);
1910 zend_llist_init(&ch->to_free->post, sizeof(struct HttpPost *), (llist_dtor_func_t)curl_free_post, 0);
1911 zend_llist_init(&ch->to_free->stream, sizeof(php_stream *), (llist_dtor_func_t)curl_free_stream, 0);
1913 ch->to_free->slist = emalloc(sizeof(HashTable));
1914 zend_hash_init(ch->to_free->slist, 4, NULL, curl_free_slist, 0);
1920 #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
1921 /* {{{ create_certinfo
1923 static void create_certinfo(struct curl_certinfo *ci, zval *listcode)
1930 for (i=0; i<ci->num_of_certs; i++) {
1931 struct curl_slist *slist;
1933 array_init(&certhash);
1934 for (slist = ci->certinfo[i]; slist; slist = slist->next) {
1938 strncpy(s, slist->data, sizeof(s));
1939 s[sizeof(s)-1] = '\0';
1940 tmp = memchr(s, ':', sizeof(s));
1944 add_assoc_string(&certhash, s, &slist->data[len+1]);
1946 php_error_docref(NULL, E_WARNING, "Could not extract hash key from certificate info");
1949 add_next_index_zval(listcode, &certhash);
1956 /* {{{ _php_curl_set_default_options()
1957 Set default options for a handle */
1958 static void _php_curl_set_default_options(php_curl *ch)
1962 curl_easy_setopt(ch->cp, CURLOPT_NOPROGRESS, 1);
1963 curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0);
1964 curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER, ch->err.str);
1965 curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write);
1966 curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch);
1967 curl_easy_setopt(ch->cp, CURLOPT_READFUNCTION, curl_read);
1968 curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch);
1969 curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_header);
1970 curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
1972 curl_easy_setopt(ch->cp, CURLOPT_DNS_USE_GLOBAL_CACHE, 1);
1974 curl_easy_setopt(ch->cp, CURLOPT_DNS_CACHE_TIMEOUT, 120);
1975 curl_easy_setopt(ch->cp, CURLOPT_MAXREDIRS, 20); /* prevent infinite redirects */
1977 cainfo = INI_STR("openssl.cafile");
1978 if (!(cainfo && cainfo[0] != '\0')) {
1979 cainfo = INI_STR("curl.cainfo");
1981 if (cainfo && cainfo[0] != '\0') {
1982 curl_easy_setopt(ch->cp, CURLOPT_CAINFO, cainfo);
1986 curl_easy_setopt(ch->cp, CURLOPT_NOSIGNAL, 1);
1991 /* {{{ proto resource curl_init([string url])
1992 Initialize a cURL session */
1993 PHP_FUNCTION(curl_init)
1997 zend_string *url = NULL;
1999 ZEND_PARSE_PARAMETERS_START(0,1)
2002 ZEND_PARSE_PARAMETERS_END();
2004 cp = curl_easy_init();
2006 php_error_docref(NULL, E_WARNING, "Could not initialize a new cURL handle");
2010 ch = alloc_curl_handle();
2014 ch->handlers->write->method = PHP_CURL_STDOUT;
2015 ch->handlers->read->method = PHP_CURL_DIRECT;
2016 ch->handlers->write_header->method = PHP_CURL_IGNORE;
2018 _php_curl_set_default_options(ch);
2021 if (php_curl_option_url(ch, ZSTR_VAL(url), ZSTR_LEN(url)) == FAILURE) {
2022 _php_curl_close_ex(ch);
2027 ZVAL_RES(return_value, zend_register_resource(ch, le_curl));
2028 ch->res = Z_RES_P(return_value);
2032 void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
2034 if (!Z_ISUNDEF(source->handlers->write->stream)) {
2035 Z_ADDREF(source->handlers->write->stream);
2037 ch->handlers->write->stream = source->handlers->write->stream;
2038 ch->handlers->write->method = source->handlers->write->method;
2039 if (!Z_ISUNDEF(source->handlers->read->stream)) {
2040 Z_ADDREF(source->handlers->read->stream);
2042 ch->handlers->read->stream = source->handlers->read->stream;
2043 ch->handlers->read->method = source->handlers->read->method;
2044 ch->handlers->write_header->method = source->handlers->write_header->method;
2045 if (!Z_ISUNDEF(source->handlers->write_header->stream)) {
2046 Z_ADDREF(source->handlers->write_header->stream);
2048 ch->handlers->write_header->stream = source->handlers->write_header->stream;
2050 ch->handlers->write->fp = source->handlers->write->fp;
2051 ch->handlers->write_header->fp = source->handlers->write_header->fp;
2052 ch->handlers->read->fp = source->handlers->read->fp;
2053 ch->handlers->read->res = source->handlers->read->res;
2054 #if CURLOPT_PASSWDDATA != 0
2055 if (!Z_ISUNDEF(source->handlers->passwd)) {
2056 ZVAL_COPY(&ch->handlers->passwd, &source->handlers->passwd);
2057 curl_easy_setopt(source->cp, CURLOPT_PASSWDDATA, (void *) ch);
2060 if (!Z_ISUNDEF(source->handlers->write->func_name)) {
2061 ZVAL_COPY(&ch->handlers->write->func_name, &source->handlers->write->func_name);
2063 if (!Z_ISUNDEF(source->handlers->read->func_name)) {
2064 ZVAL_COPY(&ch->handlers->read->func_name, &source->handlers->read->func_name);
2066 if (!Z_ISUNDEF(source->handlers->write_header->func_name)) {
2067 ZVAL_COPY(&ch->handlers->write_header->func_name, &source->handlers->write_header->func_name);
2070 curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER, ch->err.str);
2071 curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch);
2072 curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch);
2073 curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
2075 if (source->handlers->progress) {
2076 ch->handlers->progress = ecalloc(1, sizeof(php_curl_progress));
2077 if (!Z_ISUNDEF(source->handlers->progress->func_name)) {
2078 ZVAL_COPY(&ch->handlers->progress->func_name, &source->handlers->progress->func_name);
2080 ch->handlers->progress->method = source->handlers->progress->method;
2081 curl_easy_setopt(ch->cp, CURLOPT_PROGRESSDATA, (void *) ch);
2084 #if LIBCURL_VERSION_NUM >= 0x071500
2085 if (source->handlers->fnmatch) {
2086 ch->handlers->fnmatch = ecalloc(1, sizeof(php_curl_fnmatch));
2087 if (!Z_ISUNDEF(source->handlers->fnmatch->func_name)) {
2088 ZVAL_COPY(&ch->handlers->fnmatch->func_name, &source->handlers->fnmatch->func_name);
2090 ch->handlers->fnmatch->method = source->handlers->fnmatch->method;
2091 curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_DATA, (void *) ch);
2095 efree(ch->to_free->slist);
2097 ch->to_free = source->to_free;
2099 ch->clone = source->clone;
2101 /* Keep track of cloned copies to avoid invoking curl destructors for every clone */
2105 /* {{{ proto resource curl_copy_handle(resource ch)
2106 Copy a cURL handle along with all of it's preferences */
2107 PHP_FUNCTION(curl_copy_handle)
2111 php_curl *ch, *dupch;
2113 ZEND_PARSE_PARAMETERS_START(1,1)
2114 Z_PARAM_RESOURCE(zid)
2115 ZEND_PARSE_PARAMETERS_END();
2117 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
2121 cp = curl_easy_duphandle(ch->cp);
2123 php_error_docref(NULL, E_WARNING, "Cannot duplicate cURL handle");
2127 dupch = alloc_curl_handle();
2130 _php_setup_easy_copy_handlers(dupch, ch);
2134 ZVAL_RES(return_value, zend_register_resource(dupch, le_curl));
2135 dupch->res = Z_RES_P(return_value);
2139 #if LIBCURL_VERSION_NUM >= 0x073800
2140 static size_t read_cb(char *buffer, size_t size, size_t nitems, void *arg) /* {{{ */
2142 php_stream *stream = (php_stream *) arg;
2143 size_t numread = php_stream_read(stream, buffer, nitems * size);
2145 if (numread == (size_t)-1) {
2146 return CURL_READFUNC_ABORT;
2152 static int seek_cb(void *arg, curl_off_t offset, int origin) /* {{{ */
2154 php_stream *stream = (php_stream *) arg;
2155 int res = php_stream_seek(stream, offset, origin);
2158 return CURL_SEEKFUNC_CANTSEEK;
2160 return CURL_SEEKFUNC_OK;
2165 static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ */
2167 CURLcode error = CURLE_OK;
2172 case CURLOPT_SSL_VERIFYHOST:
2173 lval = zval_get_long(zvalue);
2175 #if LIBCURL_VERSION_NUM <= 0x071c00 /* 7.28.0 */
2176 php_error_docref(NULL, E_NOTICE, "CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of libcurl 7.28.1. It is recommended to use value 2 instead");
2178 php_error_docref(NULL, E_NOTICE, "CURLOPT_SSL_VERIFYHOST no longer accepts the value 1, value 2 will be used instead");
2179 error = curl_easy_setopt(ch->cp, option, 2);
2183 case CURLOPT_AUTOREFERER:
2184 case CURLOPT_BUFFERSIZE:
2185 case CURLOPT_CONNECTTIMEOUT:
2186 case CURLOPT_COOKIESESSION:
2188 case CURLOPT_DNS_CACHE_TIMEOUT:
2189 case CURLOPT_DNS_USE_GLOBAL_CACHE:
2190 case CURLOPT_FAILONERROR:
2191 case CURLOPT_FILETIME:
2192 case CURLOPT_FORBID_REUSE:
2193 case CURLOPT_FRESH_CONNECT:
2194 case CURLOPT_FTP_USE_EPRT:
2195 case CURLOPT_FTP_USE_EPSV:
2196 case CURLOPT_HEADER:
2197 case CURLOPT_HTTPGET:
2198 case CURLOPT_HTTPPROXYTUNNEL:
2199 case CURLOPT_HTTP_VERSION:
2200 case CURLOPT_INFILESIZE:
2201 case CURLOPT_LOW_SPEED_LIMIT:
2202 case CURLOPT_LOW_SPEED_TIME:
2203 case CURLOPT_MAXCONNECTS:
2204 case CURLOPT_MAXREDIRS:
2206 case CURLOPT_NOBODY:
2207 case CURLOPT_NOPROGRESS:
2208 case CURLOPT_NOSIGNAL:
2211 case CURLOPT_PROXYPORT:
2212 case CURLOPT_PROXYTYPE:
2214 case CURLOPT_RESUME_FROM:
2215 case CURLOPT_SSLVERSION:
2216 case CURLOPT_SSL_VERIFYPEER:
2217 case CURLOPT_TIMECONDITION:
2218 case CURLOPT_TIMEOUT:
2219 case CURLOPT_TIMEVALUE:
2220 case CURLOPT_TRANSFERTEXT:
2221 case CURLOPT_UNRESTRICTED_AUTH:
2222 case CURLOPT_UPLOAD:
2223 case CURLOPT_VERBOSE:
2224 case CURLOPT_HTTPAUTH:
2225 case CURLOPT_FTP_CREATE_MISSING_DIRS:
2226 case CURLOPT_PROXYAUTH:
2227 case CURLOPT_FTP_RESPONSE_TIMEOUT:
2228 case CURLOPT_IPRESOLVE:
2229 case CURLOPT_MAXFILESIZE:
2230 case CURLOPT_TCP_NODELAY:
2231 case CURLOPT_FTPSSLAUTH:
2232 case CURLOPT_IGNORE_CONTENT_LENGTH:
2233 case CURLOPT_FTP_SKIP_PASV_IP:
2234 case CURLOPT_FTP_FILEMETHOD:
2235 case CURLOPT_CONNECT_ONLY:
2236 case CURLOPT_LOCALPORT:
2237 case CURLOPT_LOCALPORTRANGE:
2238 #if LIBCURL_VERSION_NUM >= 0x071000 /* Available since 7.16.0 */
2239 case CURLOPT_SSL_SESSIONID_CACHE:
2241 #if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */
2242 case CURLOPT_FTP_SSL_CCC:
2243 case CURLOPT_SSH_AUTH_TYPES:
2245 #if LIBCURL_VERSION_NUM >= 0x071002 /* Available since 7.16.2 */
2246 case CURLOPT_CONNECTTIMEOUT_MS:
2247 case CURLOPT_HTTP_CONTENT_DECODING:
2248 case CURLOPT_HTTP_TRANSFER_DECODING:
2249 case CURLOPT_TIMEOUT_MS:
2251 #if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */
2252 case CURLOPT_NEW_DIRECTORY_PERMS:
2253 case CURLOPT_NEW_FILE_PERMS:
2255 #if LIBCURL_VERSION_NUM >= 0x071100 /* Available since 7.17.0 */
2256 case CURLOPT_USE_SSL:
2257 case CURLOPT_APPEND:
2258 case CURLOPT_DIRLISTONLY:
2260 case CURLOPT_FTP_SSL:
2261 case CURLOPT_FTPAPPEND:
2262 case CURLOPT_FTPLISTONLY:
2264 #if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */
2265 case CURLOPT_PROXY_TRANSFER_MODE:
2267 #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
2268 case CURLOPT_ADDRESS_SCOPE:
2270 #if LIBCURL_VERSION_NUM > 0x071301 /* Available since 7.19.1 */
2271 case CURLOPT_CERTINFO:
2273 #if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */
2274 case CURLOPT_PROTOCOLS:
2275 case CURLOPT_REDIR_PROTOCOLS:
2276 case CURLOPT_SOCKS5_GSSAPI_NEC:
2277 case CURLOPT_TFTP_BLKSIZE:
2279 #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
2280 case CURLOPT_FTP_USE_PRET:
2281 case CURLOPT_RTSP_CLIENT_CSEQ:
2282 case CURLOPT_RTSP_REQUEST:
2283 case CURLOPT_RTSP_SERVER_CSEQ:
2285 #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
2286 case CURLOPT_WILDCARDMATCH:
2288 #if LIBCURL_VERSION_NUM >= 0x071504 /* Available since 7.21.4 */
2289 case CURLOPT_TLSAUTH_TYPE:
2291 #if LIBCURL_VERSION_NUM >= 0x071600 /* Available since 7.22.0 */
2292 case CURLOPT_GSSAPI_DELEGATION:
2294 #if LIBCURL_VERSION_NUM >= 0x071800 /* Available since 7.24.0 */
2295 case CURLOPT_ACCEPTTIMEOUT_MS:
2297 #if LIBCURL_VERSION_NUM >= 0x071900 /* Available since 7.25.0 */
2298 case CURLOPT_SSL_OPTIONS:
2299 case CURLOPT_TCP_KEEPALIVE:
2300 case CURLOPT_TCP_KEEPIDLE:
2301 case CURLOPT_TCP_KEEPINTVL:
2303 #if LIBCURL_VERSION_NUM >= 0x071f00 /* Available since 7.31.0 */
2304 case CURLOPT_SASL_IR:
2306 #if LIBCURL_VERSION_NUM >= 0x072400 /* Available since 7.36.0 */
2307 case CURLOPT_EXPECT_100_TIMEOUT_MS:
2308 case CURLOPT_SSL_ENABLE_ALPN:
2309 case CURLOPT_SSL_ENABLE_NPN:
2311 #if LIBCURL_VERSION_NUM >= 0x072500 /* Available since 7.37.0 */
2312 case CURLOPT_HEADEROPT:
2314 #if LIBCURL_VERSION_NUM >= 0x072900 /* Available since 7.41.0 */
2315 case CURLOPT_SSL_VERIFYSTATUS:
2317 #if LIBCURL_VERSION_NUM >= 0x072a00 /* Available since 7.42.0 */
2318 case CURLOPT_PATH_AS_IS:
2319 case CURLOPT_SSL_FALSESTART:
2321 #if LIBCURL_VERSION_NUM >= 0x072b00 /* Available since 7.43.0 */
2322 case CURLOPT_PIPEWAIT:
2324 #if LIBCURL_VERSION_NUM >= 0x072e00 /* Available since 7.46.0 */
2325 case CURLOPT_STREAM_WEIGHT:
2327 #if LIBCURL_VERSION_NUM >= 0x073000 /* Available since 7.48.0 */
2328 case CURLOPT_TFTP_NO_OPTIONS:
2330 #if LIBCURL_VERSION_NUM >= 0x073100 /* Available since 7.49.0 */
2331 case CURLOPT_TCP_FASTOPEN:
2333 #if LIBCURL_VERSION_NUM >= 0x073300 /* Available since 7.51.0 */
2334 case CURLOPT_KEEP_SENDING_ON_ERROR:
2336 #if LIBCURL_VERSION_NUM >= 0x073400 /* Available since 7.52.0 */
2337 case CURLOPT_PROXY_SSL_OPTIONS:
2338 case CURLOPT_PROXY_SSL_VERIFYHOST:
2339 case CURLOPT_PROXY_SSL_VERIFYPEER:
2340 case CURLOPT_PROXY_SSLVERSION:
2342 #if LIBCURL_VERSION_NUM >= 0x073600 /* Available since 7.54.0 */
2343 case CURLOPT_SUPPRESS_CONNECT_HEADERS:
2345 #if LIBCURL_VERSION_NUM >= 0x073700 /* Available since 7.55.0 */
2346 case CURLOPT_SOCKS5_AUTH:
2348 #if LIBCURL_VERSION_NUM >= 0x073800 /* Available since 7.56.0 */
2349 case CURLOPT_SSH_COMPRESSION:
2351 #if LIBCURL_VERSION_NUM >= 0x073b00 /* Available since 7.59.0 */
2352 case CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS:
2354 #if LIBCURL_VERSION_NUM >= 0x073c00 /* Available since 7.60.0 */
2355 case CURLOPT_DNS_SHUFFLE_ADDRESSES:
2356 case CURLOPT_HAPROXYPROTOCOL:
2358 #if LIBCURL_VERSION_NUM >= 0x073d00 /* Available since 7.61.0 */
2359 case CURLOPT_DISALLOW_USERNAME_IN_URL:
2361 lval = zval_get_long(zvalue);
2362 #if LIBCURL_VERSION_NUM >= 0x071304
2363 if ((option == CURLOPT_PROTOCOLS || option == CURLOPT_REDIR_PROTOCOLS) &&
2364 (PG(open_basedir) && *PG(open_basedir)) && (lval & CURLPROTO_FILE)) {
2365 php_error_docref(NULL, E_WARNING, "CURLPROTO_FILE cannot be activated when an open_basedir is set");
2370 if (option == CURLOPT_DNS_USE_GLOBAL_CACHE && lval) {
2371 php_error_docref(NULL, E_WARNING, "CURLOPT_DNS_USE_GLOBAL_CACHE cannot be activated when thread safety is enabled");
2375 error = curl_easy_setopt(ch->cp, option, lval);
2377 case CURLOPT_SAFE_UPLOAD:
2378 if (!zend_is_true(zvalue)) {
2379 php_error_docref(NULL, E_WARNING, "Disabling safe uploads is no longer supported");
2384 /* String options */
2385 case CURLOPT_CAINFO:
2386 case CURLOPT_CAPATH:
2387 case CURLOPT_COOKIE:
2388 case CURLOPT_EGDSOCKET:
2389 case CURLOPT_INTERFACE:
2391 case CURLOPT_PROXYUSERPWD:
2392 case CURLOPT_REFERER:
2393 case CURLOPT_SSLCERTTYPE:
2394 case CURLOPT_SSLENGINE:
2395 case CURLOPT_SSLENGINE_DEFAULT:
2396 case CURLOPT_SSLKEY:
2397 case CURLOPT_SSLKEYPASSWD:
2398 case CURLOPT_SSLKEYTYPE:
2399 case CURLOPT_SSL_CIPHER_LIST:
2400 case CURLOPT_USERAGENT:
2401 case CURLOPT_USERPWD:
2402 case CURLOPT_COOKIELIST:
2403 case CURLOPT_FTP_ALTERNATIVE_TO_USER:
2404 #if LIBCURL_VERSION_NUM >= 0x071101 /* Available since 7.17.1 */
2405 case CURLOPT_SSH_HOST_PUBLIC_KEY_MD5:
2407 #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
2408 case CURLOPT_PASSWORD:
2409 case CURLOPT_PROXYPASSWORD:
2410 case CURLOPT_PROXYUSERNAME:
2411 case CURLOPT_USERNAME:
2413 #if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */
2414 case CURLOPT_NOPROXY:
2415 case CURLOPT_SOCKS5_GSSAPI_SERVICE:
2417 #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
2418 case CURLOPT_MAIL_FROM:
2419 case CURLOPT_RTSP_STREAM_URI:
2420 case CURLOPT_RTSP_TRANSPORT:
2422 #if LIBCURL_VERSION_NUM >= 0x071504 /* Available since 7.21.4 */
2423 case CURLOPT_TLSAUTH_PASSWORD:
2424 case CURLOPT_TLSAUTH_USERNAME:
2426 #if LIBCURL_VERSION_NUM >= 0x071506 /* Available since 7.21.6 */
2427 case CURLOPT_ACCEPT_ENCODING:
2428 case CURLOPT_TRANSFER_ENCODING:
2430 case CURLOPT_ENCODING:
2432 #if LIBCURL_VERSION_NUM >= 0x071800 /* Available since 7.24.0 */
2433 case CURLOPT_DNS_SERVERS:
2435 #if LIBCURL_VERSION_NUM >= 0x071900 /* Available since 7.25.0 */
2436 case CURLOPT_MAIL_AUTH:
2438 #if LIBCURL_VERSION_NUM >= 0x072200 /* Available since 7.34.0 */
2439 case CURLOPT_LOGIN_OPTIONS:
2441 #if LIBCURL_VERSION_NUM >= 0x072700 /* Available since 7.39.0 */
2442 case CURLOPT_PINNEDPUBLICKEY:
2444 #if LIBCURL_VERSION_NUM >= 0x072b00 /* Available since 7.43.0 */
2445 case CURLOPT_PROXY_SERVICE_NAME:
2446 case CURLOPT_SERVICE_NAME:
2448 #if LIBCURL_VERSION_NUM >= 0x072d00 /* Available since 7.45.0 */
2449 case CURLOPT_DEFAULT_PROTOCOL:
2451 #if LIBCURL_VERSION_NUM >= 0x073400 /* Available since 7.52.0 */
2452 case CURLOPT_PRE_PROXY:
2453 case CURLOPT_PROXY_CAINFO:
2454 case CURLOPT_PROXY_CAPATH:
2455 case CURLOPT_PROXY_CRLFILE:
2456 case CURLOPT_PROXY_KEYPASSWD:
2457 case CURLOPT_PROXY_PINNEDPUBLICKEY:
2458 case CURLOPT_PROXY_SSL_CIPHER_LIST:
2459 case CURLOPT_PROXY_SSLCERT:
2460 case CURLOPT_PROXY_SSLCERTTYPE:
2461 case CURLOPT_PROXY_SSLKEY:
2462 case CURLOPT_PROXY_SSLKEYTYPE:
2463 case CURLOPT_PROXY_TLSAUTH_PASSWORD:
2464 case CURLOPT_PROXY_TLSAUTH_TYPE:
2465 case CURLOPT_PROXY_TLSAUTH_USERNAME:
2467 #if LIBCURL_VERSION_NUM >= 0x073500 /* Available since 7.53.0 */
2468 case CURLOPT_ABSTRACT_UNIX_SOCKET:
2470 #if LIBCURL_VERSION_NUM >= 0x073700 /* Available since 7.55.0 */
2471 case CURLOPT_REQUEST_TARGET:
2473 #if LIBCURL_VERSION_NUM >= 0x073d00 /* Available since 7.61.0 */
2474 case CURLOPT_PROXY_TLS13_CIPHERS:
2475 case CURLOPT_TLS13_CIPHERS:
2478 zend_string *tmp_str;
2479 zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
2480 int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0);
2481 zend_tmp_string_release(tmp_str);
2485 /* Curl nullable string options */
2486 case CURLOPT_CUSTOMREQUEST:
2487 case CURLOPT_FTPPORT:
2489 case CURLOPT_FTP_ACCOUNT:
2490 #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
2491 case CURLOPT_RTSP_SESSION_ID:
2493 #if LIBCURL_VERSION_NUM >= 0x072100 /* Available since 7.33.0 */
2494 case CURLOPT_DNS_INTERFACE:
2495 case CURLOPT_DNS_LOCAL_IP4:
2496 case CURLOPT_DNS_LOCAL_IP6:
2497 case CURLOPT_XOAUTH2_BEARER:
2499 #if LIBCURL_VERSION_NUM >= 0x072800 /* Available since 7.40.0 */
2500 case CURLOPT_UNIX_SOCKET_PATH:
2502 #if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */
2503 case CURLOPT_KRBLEVEL:
2505 case CURLOPT_KRB4LEVEL:
2508 if (Z_ISNULL_P(zvalue)) {
2509 error = curl_easy_setopt(ch->cp, option, NULL);
2511 zend_string *tmp_str;
2512 zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
2513 int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0);
2514 zend_tmp_string_release(tmp_str);
2520 /* Curl private option */
2521 case CURLOPT_PRIVATE:
2523 zend_string *tmp_str;
2524 zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
2525 int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 1);
2526 zend_tmp_string_release(tmp_str);
2530 /* Curl url option */
2533 zend_string *tmp_str;
2534 zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
2535 int ret = php_curl_option_url(ch, ZSTR_VAL(str), ZSTR_LEN(str));
2536 zend_tmp_string_release(tmp_str);
2540 /* Curl file handle options */
2542 case CURLOPT_INFILE:
2543 case CURLOPT_STDERR:
2544 case CURLOPT_WRITEHEADER: {
2546 php_stream *what = NULL;
2548 if (Z_TYPE_P(zvalue) != IS_NULL) {
2549 what = (php_stream *)zend_fetch_resource2_ex(zvalue, "File-Handle", php_file_le_stream(), php_file_le_pstream());
2554 if (FAILURE == php_stream_cast(what, PHP_STREAM_AS_STDIO, (void *) &fp, REPORT_ERRORS)) {
2567 if (!Z_ISUNDEF(ch->handlers->write->stream)) {
2568 zval_ptr_dtor(&ch->handlers->write->stream);
2569 ZVAL_UNDEF(&ch->handlers->write->stream);
2571 ch->handlers->write->fp = NULL;
2572 ch->handlers->write->method = PHP_CURL_STDOUT;
2573 } else if (what->mode[0] != 'r' || what->mode[1] == '+') {
2574 zval_ptr_dtor(&ch->handlers->write->stream);
2575 ch->handlers->write->fp = fp;
2576 ch->handlers->write->method = PHP_CURL_FILE;
2577 ZVAL_COPY(&ch->handlers->write->stream, zvalue);
2579 php_error_docref(NULL, E_WARNING, "the provided file handle is not writable");
2583 case CURLOPT_WRITEHEADER:
2585 if (!Z_ISUNDEF(ch->handlers->write_header->stream)) {
2586 zval_ptr_dtor(&ch->handlers->write_header->stream);
2587 ZVAL_UNDEF(&ch->handlers->write_header->stream);
2589 ch->handlers->write_header->fp = NULL;
2590 ch->handlers->write_header->method = PHP_CURL_IGNORE;
2591 } else if (what->mode[0] != 'r' || what->mode[1] == '+') {
2592 zval_ptr_dtor(&ch->handlers->write_header->stream);
2593 ch->handlers->write_header->fp = fp;
2594 ch->handlers->write_header->method = PHP_CURL_FILE;
2595 ZVAL_COPY(&ch->handlers->write_header->stream, zvalue);
2597 php_error_docref(NULL, E_WARNING, "the provided file handle is not writable");
2601 case CURLOPT_INFILE:
2603 if (!Z_ISUNDEF(ch->handlers->read->stream)) {
2604 zval_ptr_dtor(&ch->handlers->read->stream);
2605 ZVAL_UNDEF(&ch->handlers->read->stream);
2607 ch->handlers->read->fp = NULL;
2608 ch->handlers->read->res = NULL;
2610 zval_ptr_dtor(&ch->handlers->read->stream);
2611 ch->handlers->read->fp = fp;
2612 ch->handlers->read->res = Z_RES_P(zvalue);
2613 ZVAL_COPY(&ch->handlers->read->stream, zvalue);
2616 case CURLOPT_STDERR:
2618 if (!Z_ISUNDEF(ch->handlers->std_err)) {
2619 zval_ptr_dtor(&ch->handlers->std_err);
2620 ZVAL_UNDEF(&ch->handlers->std_err);
2622 } else if (what->mode[0] != 'r' || what->mode[1] == '+') {
2623 zval_ptr_dtor(&ch->handlers->std_err);
2624 ZVAL_COPY(&ch->handlers->std_err, zvalue);
2626 php_error_docref(NULL, E_WARNING, "the provided file handle is not writable");
2629 /* break omitted intentionally */
2631 error = curl_easy_setopt(ch->cp, option, fp);
2637 /* Curl linked list options */
2638 case CURLOPT_HTTP200ALIASES:
2639 case CURLOPT_HTTPHEADER:
2640 case CURLOPT_POSTQUOTE:
2641 case CURLOPT_PREQUOTE:
2643 case CURLOPT_TELNETOPTIONS:
2644 #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
2645 case CURLOPT_MAIL_RCPT:
2647 #if LIBCURL_VERSION_NUM >= 0x071503 /* Available since 7.21.3 */
2648 case CURLOPT_RESOLVE:
2650 #if LIBCURL_VERSION_NUM >= 0x072500 /* Available since 7.37.0 */
2651 case CURLOPT_PROXYHEADER:
2653 #if LIBCURL_VERSION_NUM >= 0x073100 /* Available since 7.49.0 */
2654 case CURLOPT_CONNECT_TO:
2659 zend_string *val, *tmp_val;
2660 struct curl_slist *slist = NULL;
2662 ph = HASH_OF(zvalue);
2666 case CURLOPT_HTTPHEADER:
2667 name = "CURLOPT_HTTPHEADER";
2670 name = "CURLOPT_QUOTE";
2672 case CURLOPT_HTTP200ALIASES:
2673 name = "CURLOPT_HTTP200ALIASES";
2675 case CURLOPT_POSTQUOTE:
2676 name = "CURLOPT_POSTQUOTE";
2678 case CURLOPT_PREQUOTE:
2679 name = "CURLOPT_PREQUOTE";
2681 case CURLOPT_TELNETOPTIONS:
2682 name = "CURLOPT_TELNETOPTIONS";
2684 #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
2685 case CURLOPT_MAIL_RCPT:
2686 name = "CURLOPT_MAIL_RCPT";
2689 #if LIBCURL_VERSION_NUM >= 0x071503 /* Available since 7.21.3 */
2690 case CURLOPT_RESOLVE:
2691 name = "CURLOPT_RESOLVE";
2694 #if LIBCURL_VERSION_NUM >= 0x072500 /* Available since 7.37.0 */
2695 case CURLOPT_PROXYHEADER:
2696 name = "CURLOPT_PROXYHEADER";
2699 #if LIBCURL_VERSION_NUM >= 0x073100 /* Available since 7.49.0 */
2700 case CURLOPT_CONNECT_TO:
2701 name = "CURLOPT_CONNECT_TO";
2705 php_error_docref(NULL, E_WARNING, "You must pass either an object or an array with the %s argument", name);
2709 ZEND_HASH_FOREACH_VAL(ph, current) {
2710 ZVAL_DEREF(current);
2711 val = zval_get_tmp_string(current, &tmp_val);
2712 slist = curl_slist_append(slist, ZSTR_VAL(val));
2713 zend_tmp_string_release(tmp_val);
2715 php_error_docref(NULL, E_WARNING, "Could not build curl_slist");
2718 } ZEND_HASH_FOREACH_END();
2721 if ((*ch->clone) == 1) {
2722 zend_hash_index_update_ptr(ch->to_free->slist, option, slist);
2724 zend_hash_next_index_insert_ptr(ch->to_free->slist, slist);
2728 error = curl_easy_setopt(ch->cp, option, slist);
2733 case CURLOPT_BINARYTRANSFER:
2734 /* Do nothing, just backward compatibility */
2737 case CURLOPT_FOLLOWLOCATION:
2738 lval = zend_is_true(zvalue);
2739 #if LIBCURL_VERSION_NUM < 0x071304
2740 if (lval && PG(open_basedir) && *PG(open_basedir)) {
2741 php_error_docref(NULL, E_WARNING, "CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set");
2745 error = curl_easy_setopt(ch->cp, option, lval);
2748 case CURLOPT_HEADERFUNCTION:
2749 if (!Z_ISUNDEF(ch->handlers->write_header->func_name)) {
2750 zval_ptr_dtor(&ch->handlers->write_header->func_name);
2751 ch->handlers->write_header->fci_cache = empty_fcall_info_cache;
2753 ZVAL_COPY(&ch->handlers->write_header->func_name, zvalue);
2754 ch->handlers->write_header->method = PHP_CURL_USER;
2757 case CURLOPT_POSTFIELDS:
2758 if (Z_TYPE_P(zvalue) == IS_ARRAY || Z_TYPE_P(zvalue) == IS_OBJECT) {
2760 HashTable *postfields;
2761 zend_string *string_key;
2763 #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2765 curl_mimepart *part;
2766 CURLcode form_error;
2768 struct HttpPost *first = NULL;
2769 struct HttpPost *last = NULL;
2770 CURLFORMcode form_error;
2772 postfields = HASH_OF(zvalue);
2774 php_error_docref(NULL, E_WARNING, "Couldn't get HashTable in CURLOPT_POSTFIELDS");
2778 #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2779 mime = curl_mime_init(ch->cp);
2785 ZEND_HASH_FOREACH_KEY_VAL(postfields, num_key, string_key, current) {
2786 zend_string *postval, *tmp_postval;
2787 /* Pretend we have a string_key here */
2789 string_key = zend_long_to_str(num_key);
2791 zend_string_addref(string_key);
2794 ZVAL_DEREF(current);
2795 if (Z_TYPE_P(current) == IS_OBJECT &&
2796 instanceof_function(Z_OBJCE_P(current), curl_CURLFile_class)) {
2797 /* new-style file upload */
2799 char *type = NULL, *filename = NULL;
2800 #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2804 prop = zend_read_property(curl_CURLFile_class, current, "name", sizeof("name")-1, 0, &rv);
2805 if (Z_TYPE_P(prop) != IS_STRING) {
2806 php_error_docref(NULL, E_WARNING, "Invalid filename for key %s", ZSTR_VAL(string_key));
2808 postval = Z_STR_P(prop);
2810 if (php_check_open_basedir(ZSTR_VAL(postval))) {
2814 prop = zend_read_property(curl_CURLFile_class, current, "mime", sizeof("mime")-1, 0, &rv);
2815 if (Z_TYPE_P(prop) == IS_STRING && Z_STRLEN_P(prop) > 0) {
2816 type = Z_STRVAL_P(prop);
2818 prop = zend_read_property(curl_CURLFile_class, current, "postname", sizeof("postname")-1, 0, &rv);
2819 if (Z_TYPE_P(prop) == IS_STRING && Z_STRLEN_P(prop) > 0) {
2820 filename = Z_STRVAL_P(prop);
2823 #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2824 if (!(stream = php_stream_open_wrapper(ZSTR_VAL(postval), "rb", IGNORE_PATH, NULL))) {
2825 zend_string_release_ex(string_key, 0);
2828 part = curl_mime_addpart(mime);
2830 php_stream_close(stream);
2831 zend_string_release_ex(string_key, 0);
2834 if ((form_error = curl_mime_name(part, ZSTR_VAL(string_key))) != CURLE_OK
2835 || (form_error = curl_mime_data_cb(part, -1, read_cb, seek_cb, NULL, stream)) != CURLE_OK
2836 || (form_error = curl_mime_filename(part, filename ? filename : ZSTR_VAL(postval))) != CURLE_OK
2837 || (form_error = curl_mime_type(part, type ? type : "application/octet-stream")) != CURLE_OK) {
2838 php_stream_close(stream);
2841 zend_llist_add_element(&ch->to_free->stream, &stream);
2843 form_error = curl_formadd(&first, &last,
2844 CURLFORM_COPYNAME, ZSTR_VAL(string_key),
2845 CURLFORM_NAMELENGTH, ZSTR_LEN(string_key),
2846 CURLFORM_FILENAME, filename ? filename : ZSTR_VAL(postval),
2847 CURLFORM_CONTENTTYPE, type ? type : "application/octet-stream",
2848 CURLFORM_FILE, ZSTR_VAL(postval),
2850 if (form_error != CURL_FORMADD_OK) {
2851 /* Not nice to convert between enums but we only have place for one error type */
2852 error = (CURLcode)form_error;
2857 zend_string_release_ex(string_key, 0);
2861 postval = zval_get_tmp_string(current, &tmp_postval);
2863 #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2864 part = curl_mime_addpart(mime);
2866 zend_tmp_string_release(tmp_postval);
2867 zend_string_release_ex(string_key, 0);
2870 if ((form_error = curl_mime_name(part, ZSTR_VAL(string_key))) != CURLE_OK
2871 || (form_error = curl_mime_data(part, ZSTR_VAL(postval), ZSTR_LEN(postval))) != CURLE_OK) {
2875 /* The arguments after _NAMELENGTH and _CONTENTSLENGTH
2876 * must be explicitly cast to long in curl_formadd
2877 * use since curl needs a long not an int. */
2878 form_error = curl_formadd(&first, &last,
2879 CURLFORM_COPYNAME, ZSTR_VAL(string_key),
2880 CURLFORM_NAMELENGTH, ZSTR_LEN(string_key),
2881 CURLFORM_COPYCONTENTS, ZSTR_VAL(postval),
2882 CURLFORM_CONTENTSLENGTH, ZSTR_LEN(postval),
2885 if (form_error != CURL_FORMADD_OK) {
2886 /* Not nice to convert between enums but we only have place for one error type */
2887 error = (CURLcode)form_error;
2890 zend_tmp_string_release(tmp_postval);
2891 zend_string_release_ex(string_key, 0);
2892 } ZEND_HASH_FOREACH_END();
2894 SAVE_CURL_ERROR(ch, error);
2895 if (error != CURLE_OK) {
2899 if ((*ch->clone) == 1) {
2900 zend_llist_clean(&ch->to_free->post);
2902 #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2903 zend_llist_add_element(&ch->to_free->post, &mime);
2904 error = curl_easy_setopt(ch->cp, CURLOPT_MIMEPOST, mime);
2906 zend_llist_add_element(&ch->to_free->post, &first);
2907 error = curl_easy_setopt(ch->cp, CURLOPT_HTTPPOST, first);
2910 #if LIBCURL_VERSION_NUM >= 0x071101
2911 zend_string *tmp_str;
2912 zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
2913 /* with curl 7.17.0 and later, we can use COPYPOSTFIELDS, but we have to provide size before */
2914 error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, ZSTR_LEN(str));
2915 error = curl_easy_setopt(ch->cp, CURLOPT_COPYPOSTFIELDS, ZSTR_VAL(str));
2916 zend_tmp_string_release(tmp_str);
2919 zend_string *tmp_str;
2920 zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
2922 post = estrndup(ZSTR_VAL(str), ZSTR_LEN(str));
2923 zend_llist_add_element(&ch->to_free->str, &post);
2925 curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, post);
2926 error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, ZSTR_LEN(str));
2927 zend_tmp_string_release(tmp_str);
2932 case CURLOPT_PROGRESSFUNCTION:
2933 curl_easy_setopt(ch->cp, CURLOPT_PROGRESSFUNCTION, curl_progress);
2934 curl_easy_setopt(ch->cp, CURLOPT_PROGRESSDATA, ch);
2935 if (ch->handlers->progress == NULL) {
2936 ch->handlers->progress = ecalloc(1, sizeof(php_curl_progress));
2937 } else if (!Z_ISUNDEF(ch->handlers->progress->func_name)) {
2938 zval_ptr_dtor(&ch->handlers->progress->func_name);
2939 ch->handlers->progress->fci_cache = empty_fcall_info_cache;
2941 ZVAL_COPY(&ch->handlers->progress->func_name, zvalue);
2942 ch->handlers->progress->method = PHP_CURL_USER;
2945 case CURLOPT_READFUNCTION:
2946 if (!Z_ISUNDEF(ch->handlers->read->func_name)) {
2947 zval_ptr_dtor(&ch->handlers->read->func_name);
2948 ch->handlers->read->fci_cache = empty_fcall_info_cache;
2950 ZVAL_COPY(&ch->handlers->read->func_name, zvalue);
2951 ch->handlers->read->method = PHP_CURL_USER;
2954 case CURLOPT_RETURNTRANSFER:
2955 if (zend_is_true(zvalue)) {
2956 ch->handlers->write->method = PHP_CURL_RETURN;
2958 ch->handlers->write->method = PHP_CURL_STDOUT;
2962 case CURLOPT_WRITEFUNCTION:
2963 if (!Z_ISUNDEF(ch->handlers->write->func_name)) {
2964 zval_ptr_dtor(&ch->handlers->write->func_name);
2965 ch->handlers->write->fci_cache = empty_fcall_info_cache;
2967 ZVAL_COPY(&ch->handlers->write->func_name, zvalue);
2968 ch->handlers->write->method = PHP_CURL_USER;
2971 /* Curl off_t options */
2972 case CURLOPT_MAX_RECV_SPEED_LARGE:
2973 case CURLOPT_MAX_SEND_SPEED_LARGE:
2974 #if LIBCURL_VERSION_NUM >= 0x073b00 /* Available since 7.59.0 */
2975 case CURLOPT_TIMEVALUE_LARGE:
2977 lval = zval_get_long(zvalue);
2978 error = curl_easy_setopt(ch->cp, option, (curl_off_t)lval);
2981 #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
2982 case CURLOPT_POSTREDIR:
2983 lval = zval_get_long(zvalue);
2984 error = curl_easy_setopt(ch->cp, CURLOPT_POSTREDIR, lval & CURL_REDIR_POST_ALL);
2988 /* the following options deal with files, therefore the open_basedir check
2991 case CURLOPT_COOKIEFILE:
2992 case CURLOPT_COOKIEJAR:
2993 case CURLOPT_RANDOM_FILE:
2994 case CURLOPT_SSLCERT:
2995 case CURLOPT_NETRC_FILE:
2996 #if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */
2997 case CURLOPT_SSH_PRIVATE_KEYFILE:
2998 case CURLOPT_SSH_PUBLIC_KEYFILE:
3000 #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
3001 case CURLOPT_CRLFILE:
3002 case CURLOPT_ISSUERCERT:
3004 #if LIBCURL_VERSION_NUM >= 0x071306 /* Available since 7.19.6 */
3005 case CURLOPT_SSH_KNOWNHOSTS:
3008 zend_string *tmp_str;
3009 zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
3012 if (ZSTR_LEN(str) && php_check_open_basedir(ZSTR_VAL(str))) {
3013 zend_tmp_string_release(tmp_str);
3017 ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0);
3018 zend_tmp_string_release(tmp_str);
3022 case CURLINFO_HEADER_OUT:
3023 if (zend_is_true(zvalue)) {
3024 curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, curl_debug);
3025 curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, (void *)ch);
3026 curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 1);
3028 curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, NULL);
3029 curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, NULL);
3030 curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0);
3037 if ((sh = (php_curlsh *)zend_fetch_resource_ex(zvalue, le_curl_share_handle_name, le_curl_share_handle))) {
3038 curl_easy_setopt(ch->cp, CURLOPT_SHARE, sh->share);
3043 #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
3044 case CURLOPT_FNMATCH_FUNCTION:
3045 curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_FUNCTION, curl_fnmatch);
3046 curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_DATA, ch);
3047 if (ch->handlers->fnmatch == NULL) {
3048 ch->handlers->fnmatch = ecalloc(1, sizeof(php_curl_fnmatch));
3049 } else if (!Z_ISUNDEF(ch->handlers->fnmatch->func_name)) {
3050 zval_ptr_dtor(&ch->handlers->fnmatch->func_name);
3051 ch->handlers->fnmatch->fci_cache = empty_fcall_info_cache;
3053 ZVAL_COPY(&ch->handlers->fnmatch->func_name, zvalue);
3054 ch->handlers->fnmatch->method = PHP_CURL_USER;
3060 SAVE_CURL_ERROR(ch, error);
3061 if (error != CURLE_OK) {
3069 /* {{{ proto bool curl_setopt(resource ch, int option, mixed value)
3070 Set an option for a cURL transfer */
3071 PHP_FUNCTION(curl_setopt)
3077 ZEND_PARSE_PARAMETERS_START(3, 3)
3078 Z_PARAM_RESOURCE(zid)
3079 Z_PARAM_LONG(options)
3080 Z_PARAM_ZVAL(zvalue)
3081 ZEND_PARSE_PARAMETERS_END();
3083 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
3087 if (options <= 0 && options != CURLOPT_SAFE_UPLOAD) {
3088 php_error_docref(NULL, E_WARNING, "Invalid curl configuration option");
3092 if (_php_curl_setopt(ch, options, zvalue) == SUCCESS) {
3100 /* {{{ proto bool curl_setopt_array(resource ch, array options)
3101 Set an array of option for a cURL transfer */
3102 PHP_FUNCTION(curl_setopt_array)
3104 zval *zid, *arr, *entry;
3107 zend_string *string_key;
3109 ZEND_PARSE_PARAMETERS_START(2, 2)
3110 Z_PARAM_RESOURCE(zid)
3112 ZEND_PARSE_PARAMETERS_END();
3114 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
3118 ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arr), option, string_key, entry) {
3120 php_error_docref(NULL, E_WARNING,
3121 "Array keys must be CURLOPT constants or equivalent integer values");
3125 if (_php_curl_setopt(ch, (zend_long) option, entry) == FAILURE) {
3128 } ZEND_HASH_FOREACH_END();
3134 /* {{{ _php_curl_cleanup_handle(ch)
3135 Cleanup an execution phase */
3136 void _php_curl_cleanup_handle(php_curl *ch)
3138 smart_str_free(&ch->handlers->write->buf);
3139 if (ch->header.str) {
3140 zend_string_release_ex(ch->header.str, 0);
3141 ch->header.str = NULL;
3144 memset(ch->err.str, 0, CURL_ERROR_SIZE + 1);
3149 /* {{{ proto bool curl_exec(resource ch)
3150 Perform a cURL session */
3151 PHP_FUNCTION(curl_exec)
3157 ZEND_PARSE_PARAMETERS_START(1, 1)
3158 Z_PARAM_RESOURCE(zid)
3159 ZEND_PARSE_PARAMETERS_END();
3161 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
3165 _php_curl_verify_handlers(ch, 1);
3167 _php_curl_cleanup_handle(ch);
3169 error = curl_easy_perform(ch->cp);
3170 SAVE_CURL_ERROR(ch, error);
3172 if (error != CURLE_OK) {
3173 smart_str_free(&ch->handlers->write->buf);
3177 if (!Z_ISUNDEF(ch->handlers->std_err)) {
3179 stream = (php_stream*)zend_fetch_resource2_ex(&ch->handlers->std_err, NULL, php_file_le_stream(), php_file_le_pstream());
3181 php_stream_flush(stream);
3185 if (ch->handlers->write->method == PHP_CURL_RETURN && ch->handlers->write->buf.s) {
3186 smart_str_0(&ch->handlers->write->buf);
3187 RETURN_STR_COPY(ch->handlers->write->buf.s);
3190 /* flush the file handle, so any remaining data is synched to disk */
3191 if (ch->handlers->write->method == PHP_CURL_FILE && ch->handlers->write->fp) {
3192 fflush(ch->handlers->write->fp);
3194 if (ch->handlers->write_header->method == PHP_CURL_FILE && ch->handlers->write_header->fp) {
3195 fflush(ch->handlers->write_header->fp);
3198 if (ch->handlers->write->method == PHP_CURL_RETURN) {
3199 RETURN_EMPTY_STRING();
3206 /* {{{ proto mixed curl_getinfo(resource ch [, int option])
3207 Get information regarding a specific transfer */
3208 PHP_FUNCTION(curl_getinfo)
3212 zend_long option = 0;
3214 ZEND_PARSE_PARAMETERS_START(1, 2)
3215 Z_PARAM_RESOURCE(zid)
3217 Z_PARAM_LONG(option)
3218 ZEND_PARSE_PARAMETERS_END();
3220 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
3224 if (ZEND_NUM_ARGS() < 2) {
3226 /* libcurl expects long datatype. So far no cases are known where
3227 it would be an issue. Using zend_long would truncate a 64-bit
3228 var on Win64, so the exact long datatype fits everywhere, as
3229 long as there's no 32-bit int overflow. */
3232 #if LIBCURL_VERSION_NUM > 0x071301 /* 7.19.1 */
3233 struct curl_certinfo *ci = NULL;
3236 #if LIBCURL_VERSION_NUM >= 0x073d00 /* 7.61.0 */
3240 array_init(return_value);
3242 if (curl_easy_getinfo(ch->cp, CURLINFO_EFFECTIVE_URL, &s_code) == CURLE_OK) {
3243 CAAS("url", s_code);
3245 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_TYPE, &s_code) == CURLE_OK) {
3246 if (s_code != NULL) {
3247 CAAS("content_type", s_code);
3250 ZVAL_NULL(&retnull);
3251 CAAZ("content_type", &retnull);
3254 if (curl_easy_getinfo(ch->cp, CURLINFO_HTTP_CODE, &l_code) == CURLE_OK) {
3255 CAAL("http_code", l_code);
3257 if (curl_easy_getinfo(ch->cp, CURLINFO_HEADER_SIZE, &l_code) == CURLE_OK) {
3258 CAAL("header_size", l_code);
3260 if (curl_easy_getinfo(ch->cp, CURLINFO_REQUEST_SIZE, &l_code) == CURLE_OK) {
3261 CAAL("request_size", l_code);
3263 if (curl_easy_getinfo(ch->cp, CURLINFO_FILETIME, &l_code) == CURLE_OK) {
3264 CAAL("filetime", l_code);
3266 if (curl_easy_getinfo(ch->cp, CURLINFO_SSL_VERIFYRESULT, &l_code) == CURLE_OK) {
3267 CAAL("ssl_verify_result", l_code);
3269 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_COUNT, &l_code) == CURLE_OK) {
3270 CAAL("redirect_count", l_code);
3272 if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME, &d_code) == CURLE_OK) {
3273 CAAD("total_time", d_code);
3275 if (curl_easy_getinfo(ch->cp, CURLINFO_NAMELOOKUP_TIME, &d_code) == CURLE_OK) {
3276 CAAD("namelookup_time", d_code);
3278 if (curl_easy_getinfo(ch->cp, CURLINFO_CONNECT_TIME, &d_code) == CURLE_OK) {
3279 CAAD("connect_time", d_code);
3281 if (curl_easy_getinfo(ch->cp, CURLINFO_PRETRANSFER_TIME, &d_code) == CURLE_OK) {
3282 CAAD("pretransfer_time", d_code);
3284 if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_UPLOAD, &d_code) == CURLE_OK) {
3285 CAAD("size_upload", d_code);
3287 if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_DOWNLOAD, &d_code) == CURLE_OK) {
3288 CAAD("size_download", d_code);
3290 if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_DOWNLOAD, &d_code) == CURLE_OK) {
3291 CAAD("speed_download", d_code);
3293 if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_UPLOAD, &d_code) == CURLE_OK) {
3294 CAAD("speed_upload", d_code);
3296 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d_code) == CURLE_OK) {
3297 CAAD("download_content_length", d_code);
3299 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_UPLOAD, &d_code) == CURLE_OK) {
3300 CAAD("upload_content_length", d_code);
3302 if (curl_easy_getinfo(ch->cp, CURLINFO_STARTTRANSFER_TIME, &d_code) == CURLE_OK) {
3303 CAAD("starttransfer_time", d_code);
3305 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME, &d_code) == CURLE_OK) {
3306 CAAD("redirect_time", d_code);
3308 #if LIBCURL_VERSION_NUM >= 0x071202 /* Available since 7.18.2 */
3309 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_URL, &s_code) == CURLE_OK) {
3310 CAAS("redirect_url", s_code);
3313 #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
3314 if (curl_easy_getinfo(ch->cp, CURLINFO_PRIMARY_IP, &s_code) == CURLE_OK) {
3315 CAAS("primary_ip", s_code);
3318 #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
3319 if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
3320 array_init(&listcode);
3321 create_certinfo(ci, &listcode);
3322 CAAZ("certinfo", &listcode);
3325 #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
3326 if (curl_easy_getinfo(ch->cp, CURLINFO_PRIMARY_PORT, &l_code) == CURLE_OK) {
3327 CAAL("primary_port", l_code);
3329 if (curl_easy_getinfo(ch->cp, CURLINFO_LOCAL_IP, &s_code) == CURLE_OK) {
3330 CAAS("local_ip", s_code);
3332 if (curl_easy_getinfo(ch->cp, CURLINFO_LOCAL_PORT, &l_code) == CURLE_OK) {
3333 CAAL("local_port", l_code);
3336 #if LIBCURL_VERSION_NUM >= 0x073200 /* Available since 7.50.0 */
3337 if (curl_easy_getinfo(ch->cp, CURLINFO_HTTP_VERSION, &l_code) == CURLE_OK) {
3338 CAAL("http_version", l_code);
3341 #if LIBCURL_VERSION_NUM >= 0x073400 /* Available since 7.52.0 */
3342 if (curl_easy_getinfo(ch->cp, CURLINFO_PROTOCOL, &l_code) == CURLE_OK) {
3343 CAAL("protocol", l_code);
3345 if (curl_easy_getinfo(ch->cp, CURLINFO_PROXY_SSL_VERIFYRESULT, &l_code) == CURLE_OK) {
3346 CAAL("ssl_verifyresult", l_code);
3348 if (curl_easy_getinfo(ch->cp, CURLINFO_SCHEME, &s_code) == CURLE_OK) {
3349 CAAS("scheme", s_code);
3352 #if LIBCURL_VERSION_NUM >= 0x073d00 /* Available since 7.61.0 */
3353 if (curl_easy_getinfo(ch->cp, CURLINFO_APPCONNECT_TIME_T, &co) == CURLE_OK) {
3354 CAAL("appconnect_time_us", co);
3356 if (curl_easy_getinfo(ch->cp, CURLINFO_CONNECT_TIME_T, &co) == CURLE_OK) {
3357 CAAL("connect_time_us", co);
3359 if (curl_easy_getinfo(ch->cp, CURLINFO_NAMELOOKUP_TIME_T, &co) == CURLE_OK) {
3360 CAAL("namelookup_time_us", co);
3362 if (curl_easy_getinfo(ch->cp, CURLINFO_PRETRANSFER_TIME_T, &co) == CURLE_OK) {
3363 CAAL("pretransfer_time_us", co);
3365 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME_T, &co) == CURLE_OK) {
3366 CAAL("redirect_time_us", co);
3368 if (curl_easy_getinfo(ch->cp, CURLINFO_STARTTRANSFER_TIME_T, &co) == CURLE_OK) {
3369 CAAL("starttransfer_time_us", co);
3371 if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME_T, &co) == CURLE_OK) {
3372 CAAL("total_time_us", co);
3375 if (ch->header.str) {
3376 CAASTR("request_header", ch->header.str);
3380 case CURLINFO_HEADER_OUT:
3381 if (ch->header.str) {
3382 RETURN_STR_COPY(ch->header.str);
3386 #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
3387 case CURLINFO_CERTINFO: {
3388 struct curl_certinfo *ci = NULL;
3390 array_init(return_value);
3392 if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
3393 create_certinfo(ci, return_value);
3401 int type = CURLINFO_TYPEMASK & option;
3403 case CURLINFO_STRING:
3405 char *s_code = NULL;
3407 if (curl_easy_getinfo(ch->cp, option, &s_code) == CURLE_OK && s_code) {
3408 RETURN_STRING(s_code);
3418 if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) {
3425 case CURLINFO_DOUBLE:
3429 if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) {
3430 RETURN_DOUBLE(code);
3436 case CURLINFO_SLIST:
3438 struct curl_slist *slist;
3439 array_init(return_value);
3440 if (curl_easy_getinfo(ch->cp, option, &slist) == CURLE_OK) {
3442 add_next_index_string(return_value, slist->data);
3443 slist = slist->next;
3445 curl_slist_free_all(slist);
3451 #if LIBCURL_VERSION_NUM >= 0x073700 /* Available since 7.55.0 */
3452 case CURLINFO_OFF_T:
3455 if (curl_easy_getinfo(ch->cp, option, &c_off) == CURLE_OK) {
3456 RETURN_LONG((long) c_off);
3472 /* {{{ proto string curl_error(resource ch)
3473 Return a string contain the last error for the current session */
3474 PHP_FUNCTION(curl_error)
3479 ZEND_PARSE_PARAMETERS_START(1, 1)
3480 Z_PARAM_RESOURCE(zid)
3481 ZEND_PARSE_PARAMETERS_END();
3483 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
3488 ch->err.str[CURL_ERROR_SIZE] = 0;
3489 RETURN_STRING(ch->err.str);
3491 RETURN_EMPTY_STRING();
3496 /* {{{ proto int curl_errno(resource ch)
3497 Return an integer containing the last error number */
3498 PHP_FUNCTION(curl_errno)
3503 ZEND_PARSE_PARAMETERS_START(1,1)
3504 Z_PARAM_RESOURCE(zid)
3505 ZEND_PARSE_PARAMETERS_END();
3507 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
3511 RETURN_LONG(ch->err.no);
3515 /* {{{ proto void curl_close(resource ch)
3516 Close a cURL session */
3517 PHP_FUNCTION(curl_close)
3522 ZEND_PARSE_PARAMETERS_START(1, 1)
3523 Z_PARAM_RESOURCE(zid)
3524 ZEND_PARSE_PARAMETERS_END();
3526 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
3530 if (ch->in_callback) {
3531 php_error_docref(NULL, E_WARNING, "Attempt to close cURL handle from a callback");
3535 zend_list_close(Z_RES_P(zid));
3539 /* {{{ _php_curl_close_ex()
3540 List destructor for curl handles */
3541 static void _php_curl_close_ex(php_curl *ch)
3544 fprintf(stderr, "DTOR CALLED, ch = %x\n", ch);
3547 _php_curl_verify_handlers(ch, 0);
3550 * Libcurl is doing connection caching. When easy handle is cleaned up,
3551 * if the handle was previously used by the curl_multi_api, the connection
3552 * remains open un the curl multi handle is cleaned up. Some protocols are
3553 * sending content like the FTP one, and libcurl try to use the
3554 * WRITEFUNCTION or the HEADERFUNCTION. Since structures used in those
3555 * callback are freed, we need to use an other callback to which avoid
3558 * Libcurl commit d021f2e8a00 fix this issue and should be part of 7.28.2
3560 if (ch->cp != NULL) {
3561 curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_nothing);
3562 curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write_nothing);
3564 curl_easy_cleanup(ch->cp);
3567 /* cURL destructors should be invoked only by last curl handle */
3568 if (--(*ch->clone) == 0) {
3569 zend_llist_clean(&ch->to_free->str);
3570 zend_llist_clean(&ch->to_free->post);
3571 zend_llist_clean(&ch->to_free->stream);
3572 zend_hash_destroy(ch->to_free->slist);
3573 efree(ch->to_free->slist);
3578 smart_str_free(&ch->handlers->write->buf);
3579 zval_ptr_dtor(&ch->handlers->write->func_name);
3580 zval_ptr_dtor(&ch->handlers->read->func_name);
3581 zval_ptr_dtor(&ch->handlers->write_header->func_name);
3582 zval_ptr_dtor(&ch->handlers->std_err);
3583 if (ch->header.str) {
3584 zend_string_release_ex(ch->header.str, 0);
3587 zval_ptr_dtor(&ch->handlers->write_header->stream);
3588 zval_ptr_dtor(&ch->handlers->write->stream);
3589 zval_ptr_dtor(&ch->handlers->read->stream);
3591 efree(ch->handlers->write);
3592 efree(ch->handlers->write_header);
3593 efree(ch->handlers->read);
3595 if (ch->handlers->progress) {
3596 zval_ptr_dtor(&ch->handlers->progress->func_name);
3597 efree(ch->handlers->progress);
3600 #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
3601 if (ch->handlers->fnmatch) {
3602 zval_ptr_dtor(&ch->handlers->fnmatch->func_name);
3603 efree(ch->handlers->fnmatch);
3607 efree(ch->handlers);
3612 /* {{{ _php_curl_close()
3613 List destructor for curl handles */
3614 static void _php_curl_close(zend_resource *rsrc)
3616 php_curl *ch = (php_curl *) rsrc->ptr;
3617 _php_curl_close_ex(ch);
3621 /* {{{ proto bool curl_strerror(int code)
3622 return string describing error code */
3623 PHP_FUNCTION(curl_strerror)
3628 ZEND_PARSE_PARAMETERS_START(1, 1)
3630 ZEND_PARSE_PARAMETERS_END();
3632 str = curl_easy_strerror(code);
3641 /* {{{ _php_curl_reset_handlers()
3642 Reset all handlers of a given php_curl */
3643 static void _php_curl_reset_handlers(php_curl *ch)
3645 if (!Z_ISUNDEF(ch->handlers->write->stream)) {
3646 zval_ptr_dtor(&ch->handlers->write->stream);
3647 ZVAL_UNDEF(&ch->handlers->write->stream);
3649 ch->handlers->write->fp = NULL;
3650 ch->handlers->write->method = PHP_CURL_STDOUT;
3652 if (!Z_ISUNDEF(ch->handlers->write_header->stream)) {
3653 zval_ptr_dtor(&ch->handlers->write_header->stream);
3654 ZVAL_UNDEF(&ch->handlers->write_header->stream);
3656 ch->handlers->write_header->fp = NULL;
3657 ch->handlers->write_header->method = PHP_CURL_IGNORE;
3659 if (!Z_ISUNDEF(ch->handlers->read->stream)) {
3660 zval_ptr_dtor(&ch->handlers->read->stream);
3661 ZVAL_UNDEF(&ch->handlers->read->stream);
3663 ch->handlers->read->fp = NULL;
3664 ch->handlers->read->res = NULL;
3665 ch->handlers->read->method = PHP_CURL_DIRECT;
3667 if (!Z_ISUNDEF(ch->handlers->std_err)) {
3668 zval_ptr_dtor(&ch->handlers->std_err);
3669 ZVAL_UNDEF(&ch->handlers->std_err);
3672 if (ch->handlers->progress) {
3673 zval_ptr_dtor(&ch->handlers->progress->func_name);
3674 efree(ch->handlers->progress);
3675 ch->handlers->progress = NULL;
3678 #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
3679 if (ch->handlers->fnmatch) {
3680 zval_ptr_dtor(&ch->handlers->fnmatch->func_name);
3681 efree(ch->handlers->fnmatch);
3682 ch->handlers->fnmatch = NULL;
3689 /* {{{ proto void curl_reset(resource ch)
3690 Reset all options of a libcurl session handle */
3691 PHP_FUNCTION(curl_reset)
3696 ZEND_PARSE_PARAMETERS_START(1, 1)
3697 Z_PARAM_RESOURCE(zid)
3698 ZEND_PARSE_PARAMETERS_END();
3700 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
3704 if (ch->in_callback) {
3705 php_error_docref(NULL, E_WARNING, "Attempt to reset cURL handle from a callback");
3709 curl_easy_reset(ch->cp);
3710 _php_curl_reset_handlers(ch);
3711 _php_curl_set_default_options(ch);
3715 /* {{{ proto void curl_escape(resource ch, string str)
3716 URL encodes the given string */
3717 PHP_FUNCTION(curl_escape)
3724 ZEND_PARSE_PARAMETERS_START(2,2)
3725 Z_PARAM_RESOURCE(zid)
3727 ZEND_PARSE_PARAMETERS_END();
3729 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
3733 if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(str))) {
3737 if ((res = curl_easy_escape(ch->cp, ZSTR_VAL(str), ZSTR_LEN(str)))) {
3746 /* {{{ proto void curl_unescape(resource ch, string str)
3747 URL decodes the given string */
3748 PHP_FUNCTION(curl_unescape)
3756 ZEND_PARSE_PARAMETERS_START(2,2)
3757 Z_PARAM_RESOURCE(zid)
3759 ZEND_PARSE_PARAMETERS_END();
3761 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
3765 if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(str))) {
3769 if ((out = curl_easy_unescape(ch->cp, ZSTR_VAL(str), ZSTR_LEN(str), &out_len))) {
3770 RETVAL_STRINGL(out, out_len);
3778 #if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */
3779 /* {{{ proto void curl_pause(resource ch, int bitmask)
3780 pause and unpause a connection */
3781 PHP_FUNCTION(curl_pause)
3787 ZEND_PARSE_PARAMETERS_START(2,2)
3788 Z_PARAM_RESOURCE(zid)
3789 Z_PARAM_LONG(bitmask)
3790 ZEND_PARSE_PARAMETERS_END();
3792 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
3796 RETURN_LONG(curl_easy_pause(ch->cp, bitmask));
3801 #endif /* HAVE_CURL */