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