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