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