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