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