1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 6 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 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: interface.c 289934 2009-10-26 12:57:01Z iliaa $ */
20 :
21 : #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
22 :
23 : #ifdef HAVE_CONFIG_H
24 : #include "config.h"
25 : #endif
26 :
27 : #include "php.h"
28 :
29 : #if HAVE_CURL
30 :
31 : #include <stdio.h>
32 : #include <string.h>
33 :
34 : #ifdef PHP_WIN32
35 : #include <winsock2.h>
36 : #include <sys/types.h>
37 : #endif
38 :
39 : #include <curl/curl.h>
40 : #include <curl/easy.h>
41 :
42 : /* As of curl 7.11.1 this is no longer defined inside curl.h */
43 : #ifndef HttpPost
44 : #define HttpPost curl_httppost
45 : #endif
46 :
47 : /* {{{ cruft for thread safe SSL crypto locks */
48 : #if defined(ZTS) && defined(HAVE_CURL_SSL)
49 : # ifdef PHP_WIN32
50 : # define PHP_CURL_NEED_OPENSSL_TSL
51 : # include <openssl/crypto.h>
52 : # else /* !PHP_WIN32 */
53 : # if defined(HAVE_CURL_OPENSSL)
54 : # if defined(HAVE_OPENSSL_CRYPTO_H)
55 : # define PHP_CURL_NEED_OPENSSL_TSL
56 : # include <openssl/crypto.h>
57 : # else
58 : # warning \
59 : "libcurl was compiled with OpenSSL support, but configure could not find " \
60 : "openssl/crypto.h; thus no SSL crypto locking callbacks will be set, which may " \
61 : "cause random crashes on SSL requests"
62 : # endif
63 : # elif defined(HAVE_CURL_GNUTLS)
64 : # if defined(HAVE_GCRYPT_H)
65 : # define PHP_CURL_NEED_GNUTLS_TSL
66 : # include <gcrypt.h>
67 : # else
68 : # warning \
69 : "libcurl was compiled with GnuTLS support, but configure could not find " \
70 : "gcrypt.h; thus no SSL crypto locking callbacks will be set, which may " \
71 : "cause random crashes on SSL requests"
72 : # endif
73 : # else
74 : # warning \
75 : "libcurl was compiled with SSL support, but configure could not determine which" \
76 : "library was used; thus no SSL crypto locking callbacks will be set, which may " \
77 : "cause random crashes on SSL requests"
78 : # endif /* HAVE_CURL_OPENSSL || HAVE_CURL_GNUTLS */
79 : # endif /* PHP_WIN32 */
80 : #endif /* ZTS && HAVE_CURL_SSL */
81 : /* }}} */
82 :
83 : #define SMART_STR_PREALLOC 4096
84 :
85 : #include "ext/standard/php_smart_str.h"
86 : #include "ext/standard/info.h"
87 : #include "ext/standard/file.h"
88 : #include "ext/standard/url.h"
89 : #include "php_curl.h"
90 :
91 : int le_curl;
92 : int le_curl_multi_handle;
93 :
94 : #ifdef PHP_CURL_NEED_OPENSSL_TSL /* {{{ */
95 : static MUTEX_T *php_curl_openssl_tsl = NULL;
96 :
97 : static void php_curl_ssl_lock(int mode, int n, const char * file, int line)
98 : {
99 : if (mode & CRYPTO_LOCK) {
100 : tsrm_mutex_lock(php_curl_openssl_tsl[n]);
101 : } else {
102 : tsrm_mutex_unlock(php_curl_openssl_tsl[n]);
103 : }
104 : }
105 :
106 : static unsigned long php_curl_ssl_id(void)
107 : {
108 : return (unsigned long) tsrm_thread_id();
109 : }
110 : #endif
111 : /* }}} */
112 :
113 : #ifdef PHP_CURL_NEED_GNUTLS_TSL /* {{{ */
114 : static int php_curl_ssl_mutex_create(void **m)
115 : {
116 : if (*((MUTEX_T *) m) = tsrm_mutex_alloc()) {
117 : return SUCCESS;
118 : } else {
119 : return FAILURE;
120 : }
121 : }
122 :
123 : static int php_curl_ssl_mutex_destroy(void **m)
124 : {
125 : tsrm_mutex_free(*((MUTEX_T *) m));
126 : return SUCCESS;
127 : }
128 :
129 : static int php_curl_ssl_mutex_lock(void **m)
130 : {
131 : return tsrm_mutex_lock(*((MUTEX_T *) m));
132 : }
133 :
134 : static int php_curl_ssl_mutex_unlock(void **m)
135 : {
136 : return tsrm_mutex_unlock(*((MUTEX_T *) m));
137 : }
138 :
139 : static struct gcry_thread_cbs php_curl_gnutls_tsl = {
140 : GCRY_THREAD_OPTION_USER,
141 : NULL,
142 : php_curl_ssl_mutex_create,
143 : php_curl_ssl_mutex_destroy,
144 : php_curl_ssl_mutex_lock,
145 : php_curl_ssl_mutex_unlock
146 : };
147 : #endif
148 : /* }}} */
149 :
150 : static void _php_curl_close_ex(php_curl *ch TSRMLS_DC);
151 : static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC);
152 :
153 : #define SAVE_CURL_ERROR(__handle, __err) (__handle)->err.no = (int) __err;
154 :
155 : #define CAAL(s, v) add_ascii_assoc_long_ex(return_value, s, sizeof(s), (long) v);
156 : #define CAAD(s, v) add_ascii_assoc_double_ex(return_value, s, sizeof(s), (double) v);
157 : #define CAAS(s, v) add_ascii_assoc_string(return_value, s, (v ? v : ""), 1);
158 : #define CAAZ(s, v) add_ascii_assoc_zval_ex(return_value, s, sizeof(s), (zval *) v);
159 :
160 : #if defined(PHP_WIN32) || defined(__GNUC__)
161 : # define php_curl_ret(__ret) RETVAL_FALSE; return __ret;
162 : #else
163 : # define php_curl_ret(__ret) RETVAL_FALSE; return;
164 : #endif
165 :
166 : static int php_curl_option_url(php_curl *ch, const char *url, const int len) /* {{{ */
167 60 : {
168 60 : CURLcode error = CURLE_OK;
169 : #if LIBCURL_VERSION_NUM < 0x071100
170 60 : char *copystr = NULL;
171 : #endif
172 : TSRMLS_FETCH();
173 :
174 : /* Disable file:// if open_basedir or safe_mode are used */
175 60 : if ((PG(open_basedir) && *PG(open_basedir))) {
176 : #if LIBCURL_VERSION_NUM >= 0x071304
177 : error = curl_easy_setopt(ch->cp, CURLOPT_PROTOCOLS, CURLPROTO_ALL & ~CURLPROTO_FILE);
178 : #else
179 : php_url *uri;
180 :
181 0 : if (!(uri = php_url_parse_ex(url, len))) {
182 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid URL '%s'", url);
183 0 : return 0;
184 : }
185 :
186 0 : if (uri->scheme && !strncasecmp("file", uri->scheme, sizeof("file"))) {
187 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Protocol 'file' disabled in cURL");
188 0 : php_url_free(uri);
189 0 : return 0;
190 : }
191 0 : php_url_free(uri);
192 : #endif
193 : }
194 : /* Strings passed to libcurl as 'char *' arguments, are copied by the library... NOTE: before 7.17.0 strings were not copied. */
195 : #if LIBCURL_VERSION_NUM >= 0x071100
196 : error = curl_easy_setopt(ch->cp, CURLOPT_URL, url);
197 : #else
198 60 : copystr = estrndup(url, len);
199 60 : error = curl_easy_setopt(ch->cp, CURLOPT_URL, copystr);
200 60 : zend_llist_add_element(&ch->to_free.str, ©str);
201 : #endif
202 :
203 60 : return (error == CURLE_OK ? 1 : 0);
204 : }
205 : /* }}} */
206 :
207 : /* {{{ arginfo */
208 : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_version, 0, 0, 0)
209 : ZEND_ARG_INFO(0, version)
210 : ZEND_END_ARG_INFO()
211 :
212 : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_init, 0, 0, 0)
213 : ZEND_ARG_INFO(0, url)
214 : ZEND_END_ARG_INFO()
215 :
216 : ZEND_BEGIN_ARG_INFO(arginfo_curl_copy_handle, 0)
217 : ZEND_ARG_INFO(0, ch)
218 : ZEND_END_ARG_INFO()
219 :
220 : ZEND_BEGIN_ARG_INFO(arginfo_curl_setopt, 0)
221 : ZEND_ARG_INFO(0, ch)
222 : ZEND_ARG_INFO(0, option)
223 : ZEND_ARG_INFO(0, value)
224 : ZEND_END_ARG_INFO()
225 :
226 : ZEND_BEGIN_ARG_INFO(arginfo_curl_setopt_array, 0)
227 : ZEND_ARG_INFO(0, ch)
228 : ZEND_ARG_ARRAY_INFO(0, options, 0)
229 : ZEND_END_ARG_INFO()
230 :
231 : ZEND_BEGIN_ARG_INFO(arginfo_curl_exec, 0)
232 : ZEND_ARG_INFO(0, ch)
233 : ZEND_END_ARG_INFO()
234 :
235 : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_getinfo, 0, 0, 1)
236 : ZEND_ARG_INFO(0, ch)
237 : ZEND_ARG_INFO(0, option)
238 : ZEND_END_ARG_INFO()
239 :
240 : ZEND_BEGIN_ARG_INFO(arginfo_curl_error, 0)
241 : ZEND_ARG_INFO(0, ch)
242 : ZEND_END_ARG_INFO()
243 :
244 : ZEND_BEGIN_ARG_INFO(arginfo_curl_errno, 0)
245 : ZEND_ARG_INFO(0, ch)
246 : ZEND_END_ARG_INFO()
247 :
248 : ZEND_BEGIN_ARG_INFO(arginfo_curl_close, 0)
249 : ZEND_ARG_INFO(0, ch)
250 : ZEND_END_ARG_INFO()
251 :
252 : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_init, 0)
253 : ZEND_END_ARG_INFO()
254 :
255 : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_add_handle, 0)
256 : ZEND_ARG_INFO(0, mh)
257 : ZEND_ARG_INFO(0, ch)
258 : ZEND_END_ARG_INFO()
259 :
260 : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_remove_handle, 0)
261 : ZEND_ARG_INFO(0, mh)
262 : ZEND_ARG_INFO(0, ch)
263 : ZEND_END_ARG_INFO()
264 :
265 : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_select, 0, 0, 1)
266 : ZEND_ARG_INFO(0, mh)
267 : ZEND_ARG_INFO(0, timeout)
268 : ZEND_END_ARG_INFO()
269 :
270 : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_exec, 0, 0, 1)
271 : ZEND_ARG_INFO(0, mh)
272 : ZEND_ARG_INFO(1, still_running)
273 : ZEND_END_ARG_INFO()
274 :
275 : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_getcontent, 0)
276 : ZEND_ARG_INFO(0, ch)
277 : ZEND_END_ARG_INFO()
278 :
279 : ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_info_read, 0, 0, 1)
280 : ZEND_ARG_INFO(0, mh)
281 : ZEND_ARG_INFO(1, msgs_in_queue)
282 : ZEND_END_ARG_INFO()
283 :
284 : ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_close, 0)
285 : ZEND_ARG_INFO(0, mh)
286 : ZEND_END_ARG_INFO()
287 : /* }}} */
288 :
289 : /* {{{ curl_functions[]
290 : */
291 : const zend_function_entry curl_functions[] = {
292 : PHP_FE(curl_init, arginfo_curl_init)
293 : PHP_FE(curl_copy_handle, arginfo_curl_copy_handle)
294 : PHP_FE(curl_version, arginfo_curl_version)
295 : PHP_FE(curl_setopt, arginfo_curl_setopt)
296 : PHP_FE(curl_setopt_array, arginfo_curl_setopt_array)
297 : PHP_FE(curl_exec, arginfo_curl_exec)
298 : PHP_FE(curl_getinfo, arginfo_curl_getinfo)
299 : PHP_FE(curl_error, arginfo_curl_error)
300 : PHP_FE(curl_errno, arginfo_curl_errno)
301 : PHP_FE(curl_close, arginfo_curl_close)
302 : PHP_FE(curl_multi_init, arginfo_curl_multi_init)
303 : PHP_FE(curl_multi_add_handle, arginfo_curl_multi_add_handle)
304 : PHP_FE(curl_multi_remove_handle, arginfo_curl_multi_remove_handle)
305 : PHP_FE(curl_multi_select, arginfo_curl_multi_select)
306 : PHP_FE(curl_multi_exec, arginfo_curl_multi_exec)
307 : PHP_FE(curl_multi_getcontent, arginfo_curl_multi_getcontent)
308 : PHP_FE(curl_multi_info_read, arginfo_curl_multi_info_read)
309 : PHP_FE(curl_multi_close, arginfo_curl_multi_close)
310 : {NULL, NULL, NULL}
311 : };
312 : /* }}} */
313 :
314 : /* {{{ curl_module_entry
315 : */
316 : zend_module_entry curl_module_entry = {
317 : STANDARD_MODULE_HEADER,
318 : "curl",
319 : curl_functions,
320 : PHP_MINIT(curl),
321 : PHP_MSHUTDOWN(curl),
322 : NULL,
323 : NULL,
324 : PHP_MINFO(curl),
325 : NO_VERSION_YET,
326 : STANDARD_MODULE_PROPERTIES
327 : };
328 : /* }}} */
329 :
330 : #ifdef COMPILE_DL_CURL
331 : ZEND_GET_MODULE (curl)
332 : #endif
333 :
334 : /* {{{ PHP_MINFO_FUNCTION
335 : */
336 : PHP_MINFO_FUNCTION(curl)
337 43 : {
338 : curl_version_info_data *d;
339 : char **p;
340 : char str[1024];
341 43 : size_t n = 0;
342 :
343 43 : d = curl_version_info(CURLVERSION_NOW);
344 43 : php_info_print_table_start();
345 43 : php_info_print_table_row(2, "cURL support", "enabled");
346 43 : php_info_print_table_row(2, "cURL Information", d->version);
347 43 : sprintf(str, "%d", d->age);
348 43 : php_info_print_table_row(2, "Age", str);
349 :
350 : /* To update on each new cURL release using src/main.c in cURL sources */
351 43 : if (d->features) {
352 : struct feat {
353 : const char *name;
354 : int bitmask;
355 : };
356 :
357 : unsigned int i;
358 :
359 : static const struct feat feats[] = {
360 : #if LIBCURL_VERSION_NUM > 0x070a06 /* 7.10.7 */
361 : {"AsynchDNS", CURL_VERSION_ASYNCHDNS},
362 : #endif
363 : #if LIBCURL_VERSION_NUM > 0x070a05 /* 7.10.6 */
364 : {"Debug", CURL_VERSION_DEBUG},
365 : {"GSS-Negotiate", CURL_VERSION_GSSNEGOTIATE},
366 : #endif
367 : #if LIBCURL_VERSION_NUM > 0x070b02 /* 7.12.0 */
368 : {"IDN", CURL_VERSION_IDN},
369 : #endif
370 : #ifdef CURL_VERSION_IPV6
371 : {"IPv6", CURL_VERSION_IPV6},
372 : #endif
373 : #if LIBCURL_VERSION_NUM > 0x070a09 /* 7.10.1 */
374 : {"Largefile", CURL_VERSION_LARGEFILE},
375 : #endif
376 : #if LIBCURL_VERSION_NUM > 0x070a05 /* 7.10.6 */
377 : {"NTLM", CURL_VERSION_NTLM},
378 : #endif
379 : #if LIBCURL_VERSION_NUM > 0x070a07 /* 7.10.8 */
380 : {"SPNEGO", CURL_VERSION_SPNEGO},
381 : #endif
382 : #ifdef CURL_VERSION_SSL
383 : {"SSL", CURL_VERSION_SSL},
384 : #endif
385 : #if LIBCURL_VERSION_NUM > 0x070d01 /* 7.13.2 */
386 : {"SSPI", CURL_VERSION_SSPI},
387 : #endif
388 : #ifdef CURL_VERSION_KERBEROS4
389 : {"krb4", CURL_VERSION_KERBEROS4},
390 : #endif
391 : #ifdef CURL_VERSION_LIBZ
392 : {"libz", CURL_VERSION_LIBZ},
393 : #endif
394 : #if LIBCURL_VERSION_NUM > 0x070f03 /* 7.15.4 */
395 : {"CharConv", CURL_VERSION_CONV},
396 : #endif
397 : {NULL, 0}
398 : };
399 :
400 43 : php_info_print_table_row(1, "Features");
401 645 : for(i=0; i<sizeof(feats)/sizeof(feats[0]); i++) {
402 602 : if (feats[i].name) {
403 559 : php_info_print_table_row(2, feats[i].name, d->features & feats[i].bitmask ? "Yes" : "No");
404 : }
405 : }
406 : }
407 :
408 43 : n = 0;
409 43 : p = (char **) d->protocols;
410 473 : while (*p != NULL) {
411 387 : n += sprintf(str + n, "%s%s", *p, *(p + 1) != NULL ? ", " : "");
412 387 : p++;
413 : }
414 43 : php_info_print_table_row(2, "Protocols", str);
415 :
416 43 : php_info_print_table_row(2, "Host", d->host);
417 :
418 43 : if (d->ssl_version) {
419 43 : php_info_print_table_row(2, "SSL Version", d->ssl_version);
420 : }
421 :
422 43 : if (d->libz_version) {
423 43 : php_info_print_table_row(2, "ZLib Version", d->libz_version);
424 : }
425 :
426 : #if defined(CURLVERSION_SECOND) && CURLVERSION_NOW >= CURLVERSION_SECOND
427 : if (d->ares) {
428 : php_info_print_table_row(2, "ZLib Version", d->ares);
429 : }
430 : #endif
431 :
432 : #if defined(CURLVERSION_THIRD) && CURLVERSION_NOW >= CURLVERSION_THIRD
433 : if (d->libidn) {
434 : php_info_print_table_row(2, "libIDN Version", d->libidn);
435 : }
436 : #endif
437 :
438 : #if LIBCURL_VERSION_NUM >= 0x071300
439 :
440 : if (d->iconv_ver_num) {
441 : php_info_print_table_row(2, "IconV Version", d->iconv_ver_num);
442 : }
443 :
444 : if (d->libssh_version) {
445 : php_info_print_table_row(2, "libSSH Version", d->libssh_version);
446 : }
447 : #endif
448 43 : php_info_print_table_end();
449 43 : }
450 : /* }}} */
451 :
452 : #define REGISTER_CURL_CONSTANT(__c) REGISTER_LONG_CONSTANT(#__c, __c, CONST_CS | CONST_PERSISTENT)
453 :
454 : /* {{{ PHP_MINIT_FUNCTION
455 : */
456 : PHP_MINIT_FUNCTION(curl)
457 17007 : {
458 17007 : le_curl = zend_register_list_destructors_ex(_php_curl_close, NULL, "curl", module_number);
459 17007 : le_curl_multi_handle = zend_register_list_destructors_ex(_php_curl_multi_close, NULL, "curl_multi", module_number);
460 :
461 : /* See http://curl.haxx.se/lxr/source/docs/libcurl/symbols-in-versions
462 : or curl src/docs/libcurl/symbols-in-versions for a (almost) complete list
463 : of options and which version they were introduced */
464 :
465 : /* Constants for curl_setopt() */
466 : #if LIBCURL_VERSION_NUM > 0x070a07 /* CURLOPT_IPRESOLVE is available since curl 7.10.8 */
467 17007 : REGISTER_CURL_CONSTANT(CURLOPT_IPRESOLVE);
468 17007 : REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_WHATEVER);
469 17007 : REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V4);
470 17007 : REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V6);
471 : #endif
472 17007 : REGISTER_CURL_CONSTANT(CURLOPT_DNS_USE_GLOBAL_CACHE);
473 17007 : REGISTER_CURL_CONSTANT(CURLOPT_DNS_CACHE_TIMEOUT);
474 17007 : REGISTER_CURL_CONSTANT(CURLOPT_PORT);
475 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FILE);
476 17007 : REGISTER_CURL_CONSTANT(CURLOPT_READDATA);
477 17007 : REGISTER_CURL_CONSTANT(CURLOPT_INFILE);
478 17007 : REGISTER_CURL_CONSTANT(CURLOPT_INFILESIZE);
479 17007 : REGISTER_CURL_CONSTANT(CURLOPT_URL);
480 17007 : REGISTER_CURL_CONSTANT(CURLOPT_PROXY);
481 17007 : REGISTER_CURL_CONSTANT(CURLOPT_VERBOSE);
482 17007 : REGISTER_CURL_CONSTANT(CURLOPT_HEADER);
483 17007 : REGISTER_CURL_CONSTANT(CURLOPT_HTTPHEADER);
484 17007 : REGISTER_CURL_CONSTANT(CURLOPT_NOPROGRESS);
485 17007 : REGISTER_CURL_CONSTANT(CURLOPT_PROGRESSFUNCTION);
486 17007 : REGISTER_CURL_CONSTANT(CURLOPT_NOBODY);
487 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FAILONERROR);
488 17007 : REGISTER_CURL_CONSTANT(CURLOPT_UPLOAD);
489 17007 : REGISTER_CURL_CONSTANT(CURLOPT_POST);
490 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FTPLISTONLY);
491 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FTPAPPEND);
492 17007 : REGISTER_CURL_CONSTANT(CURLOPT_NETRC);
493 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FOLLOWLOCATION);
494 : #if CURLOPT_FTPASCII != 0
495 : REGISTER_CURL_CONSTANT(CURLOPT_FTPASCII);
496 : #endif
497 17007 : REGISTER_CURL_CONSTANT(CURLOPT_PUT);
498 : #if CURLOPT_MUTE != 0
499 17007 : REGISTER_CURL_CONSTANT(CURLOPT_MUTE);
500 : #endif
501 17007 : REGISTER_CURL_CONSTANT(CURLOPT_USERPWD);
502 17007 : REGISTER_CURL_CONSTANT(CURLOPT_PROXYUSERPWD);
503 17007 : REGISTER_CURL_CONSTANT(CURLOPT_RANGE);
504 17007 : REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT);
505 : #if LIBCURL_VERSION_NUM > 0x071002
506 : REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT_MS);
507 : #endif
508 17007 : REGISTER_CURL_CONSTANT(CURLOPT_POSTFIELDS);
509 17007 : REGISTER_CURL_CONSTANT(CURLOPT_REFERER);
510 17007 : REGISTER_CURL_CONSTANT(CURLOPT_USERAGENT);
511 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FTPPORT);
512 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPSV);
513 17007 : REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_LIMIT);
514 17007 : REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_TIME);
515 17007 : REGISTER_CURL_CONSTANT(CURLOPT_RESUME_FROM);
516 17007 : REGISTER_CURL_CONSTANT(CURLOPT_COOKIE);
517 17007 : REGISTER_CURL_CONSTANT(CURLOPT_COOKIESESSION);
518 17007 : REGISTER_CURL_CONSTANT(CURLOPT_AUTOREFERER);
519 17007 : REGISTER_CURL_CONSTANT(CURLOPT_SSLCERT);
520 17007 : REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTPASSWD);
521 17007 : REGISTER_CURL_CONSTANT(CURLOPT_WRITEHEADER);
522 17007 : REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYHOST);
523 17007 : REGISTER_CURL_CONSTANT(CURLOPT_COOKIEFILE);
524 17007 : REGISTER_CURL_CONSTANT(CURLOPT_SSLVERSION);
525 17007 : REGISTER_CURL_CONSTANT(CURLOPT_TIMECONDITION);
526 17007 : REGISTER_CURL_CONSTANT(CURLOPT_TIMEVALUE);
527 17007 : REGISTER_CURL_CONSTANT(CURLOPT_CUSTOMREQUEST);
528 17007 : REGISTER_CURL_CONSTANT(CURLOPT_STDERR);
529 17007 : REGISTER_CURL_CONSTANT(CURLOPT_TRANSFERTEXT);
530 17007 : REGISTER_CURL_CONSTANT(CURLOPT_RETURNTRANSFER);
531 17007 : REGISTER_CURL_CONSTANT(CURLOPT_QUOTE);
532 17007 : REGISTER_CURL_CONSTANT(CURLOPT_POSTQUOTE);
533 17007 : REGISTER_CURL_CONSTANT(CURLOPT_INTERFACE);
534 17007 : REGISTER_CURL_CONSTANT(CURLOPT_KRB4LEVEL);
535 17007 : REGISTER_CURL_CONSTANT(CURLOPT_HTTPPROXYTUNNEL);
536 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FILETIME);
537 17007 : REGISTER_CURL_CONSTANT(CURLOPT_WRITEFUNCTION);
538 17007 : REGISTER_CURL_CONSTANT(CURLOPT_READFUNCTION);
539 : #if CURLOPT_PASSWDFUNCTION != 0
540 17007 : REGISTER_CURL_CONSTANT(CURLOPT_PASSWDFUNCTION);
541 : #endif
542 17007 : REGISTER_CURL_CONSTANT(CURLOPT_HEADERFUNCTION);
543 17007 : REGISTER_CURL_CONSTANT(CURLOPT_MAXREDIRS);
544 17007 : REGISTER_CURL_CONSTANT(CURLOPT_MAXCONNECTS);
545 17007 : REGISTER_CURL_CONSTANT(CURLOPT_CLOSEPOLICY);
546 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FRESH_CONNECT);
547 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FORBID_REUSE);
548 17007 : REGISTER_CURL_CONSTANT(CURLOPT_RANDOM_FILE);
549 17007 : REGISTER_CURL_CONSTANT(CURLOPT_EGDSOCKET);
550 17007 : REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT);
551 : #if LIBCURL_VERSION_NUM > 0x071002
552 : REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT_MS);
553 : #endif
554 17007 : REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYPEER);
555 17007 : REGISTER_CURL_CONSTANT(CURLOPT_CAINFO);
556 17007 : REGISTER_CURL_CONSTANT(CURLOPT_CAPATH);
557 17007 : REGISTER_CURL_CONSTANT(CURLOPT_COOKIEJAR);
558 17007 : REGISTER_CURL_CONSTANT(CURLOPT_SSL_CIPHER_LIST);
559 17007 : REGISTER_CURL_CONSTANT(CURLOPT_BINARYTRANSFER);
560 17007 : REGISTER_CURL_CONSTANT(CURLOPT_NOSIGNAL);
561 17007 : REGISTER_CURL_CONSTANT(CURLOPT_PROXYTYPE);
562 17007 : REGISTER_CURL_CONSTANT(CURLOPT_BUFFERSIZE);
563 17007 : REGISTER_CURL_CONSTANT(CURLOPT_HTTPGET);
564 17007 : REGISTER_CURL_CONSTANT(CURLOPT_HTTP_VERSION);
565 17007 : REGISTER_CURL_CONSTANT(CURLOPT_SSLKEY);
566 17007 : REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYTYPE);
567 17007 : REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYPASSWD);
568 17007 : REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE);
569 17007 : REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE_DEFAULT);
570 17007 : REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTTYPE);
571 17007 : REGISTER_CURL_CONSTANT(CURLOPT_CRLF);
572 17007 : REGISTER_CURL_CONSTANT(CURLOPT_ENCODING);
573 17007 : REGISTER_CURL_CONSTANT(CURLOPT_PROXYPORT);
574 17007 : REGISTER_CURL_CONSTANT(CURLOPT_UNRESTRICTED_AUTH);
575 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPRT);
576 : #if LIBCURL_VERSION_NUM > 0x070b01 /* CURLOPT_TCP_NODELAY is available since curl 7.11.2 */
577 17007 : REGISTER_CURL_CONSTANT(CURLOPT_TCP_NODELAY);
578 : #endif
579 17007 : REGISTER_CURL_CONSTANT(CURLOPT_HTTP200ALIASES);
580 17007 : REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFMODSINCE);
581 17007 : REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFUNMODSINCE);
582 17007 : REGISTER_CURL_CONSTANT(CURL_TIMECOND_LASTMOD);
583 :
584 : #if LIBCURL_VERSION_NUM > 0x070a05 /* CURLOPT_HTTPAUTH is available since curl 7.10.6 */
585 17007 : REGISTER_CURL_CONSTANT(CURLOPT_HTTPAUTH);
586 : /* http authentication options */
587 17007 : REGISTER_CURL_CONSTANT(CURLAUTH_BASIC);
588 17007 : REGISTER_CURL_CONSTANT(CURLAUTH_DIGEST);
589 17007 : REGISTER_CURL_CONSTANT(CURLAUTH_GSSNEGOTIATE);
590 17007 : REGISTER_CURL_CONSTANT(CURLAUTH_NTLM);
591 17007 : REGISTER_CURL_CONSTANT(CURLAUTH_ANY);
592 17007 : REGISTER_CURL_CONSTANT(CURLAUTH_ANYSAFE);
593 : #endif
594 :
595 : #if LIBCURL_VERSION_NUM > 0x070a06 /* CURLOPT_PROXYAUTH & CURLOPT_FTP_CREATE_MISSING_DIRS are available since curl 7.10.7 */
596 17007 : REGISTER_CURL_CONSTANT(CURLOPT_PROXYAUTH);
597 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FTP_CREATE_MISSING_DIRS);
598 : #endif
599 :
600 17007 : REGISTER_CURL_CONSTANT(CURLOPT_PRIVATE);
601 :
602 : /* Constants effecting the way CURLOPT_CLOSEPOLICY works */
603 17007 : REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_LEAST_RECENTLY_USED);
604 17007 : REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_LEAST_TRAFFIC);
605 17007 : REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_SLOWEST);
606 17007 : REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_CALLBACK);
607 17007 : REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_OLDEST);
608 :
609 : /* Info constants */
610 17007 : REGISTER_CURL_CONSTANT(CURLINFO_EFFECTIVE_URL);
611 17007 : REGISTER_CURL_CONSTANT(CURLINFO_HTTP_CODE);
612 17007 : REGISTER_CURL_CONSTANT(CURLINFO_HEADER_SIZE);
613 17007 : REGISTER_CURL_CONSTANT(CURLINFO_REQUEST_SIZE);
614 17007 : REGISTER_CURL_CONSTANT(CURLINFO_TOTAL_TIME);
615 17007 : REGISTER_CURL_CONSTANT(CURLINFO_NAMELOOKUP_TIME);
616 17007 : REGISTER_CURL_CONSTANT(CURLINFO_CONNECT_TIME);
617 17007 : REGISTER_CURL_CONSTANT(CURLINFO_PRETRANSFER_TIME);
618 17007 : REGISTER_CURL_CONSTANT(CURLINFO_SIZE_UPLOAD);
619 17007 : REGISTER_CURL_CONSTANT(CURLINFO_SIZE_DOWNLOAD);
620 17007 : REGISTER_CURL_CONSTANT(CURLINFO_SPEED_DOWNLOAD);
621 17007 : REGISTER_CURL_CONSTANT(CURLINFO_SPEED_UPLOAD);
622 17007 : REGISTER_CURL_CONSTANT(CURLINFO_FILETIME);
623 17007 : REGISTER_CURL_CONSTANT(CURLINFO_SSL_VERIFYRESULT);
624 17007 : REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_DOWNLOAD);
625 17007 : REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_UPLOAD);
626 17007 : REGISTER_CURL_CONSTANT(CURLINFO_STARTTRANSFER_TIME);
627 17007 : REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_TYPE);
628 17007 : REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_TIME);
629 17007 : REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_COUNT);
630 17007 : REGISTER_CURL_CONSTANT(CURLINFO_HEADER_OUT);
631 17007 : REGISTER_CURL_CONSTANT(CURLINFO_PRIVATE);
632 : #if LIBCURL_VERSION_NUM > 0x071301
633 : REGISTER_CURL_CONSTANT(CURLINFO_CERTINFO);
634 : #endif
635 :
636 : /* cURL protocol constants (curl_version) */
637 17007 : REGISTER_CURL_CONSTANT(CURL_VERSION_IPV6);
638 17007 : REGISTER_CURL_CONSTANT(CURL_VERSION_KERBEROS4);
639 17007 : REGISTER_CURL_CONSTANT(CURL_VERSION_SSL);
640 17007 : REGISTER_CURL_CONSTANT(CURL_VERSION_LIBZ);
641 :
642 : /* version constants */
643 17007 : REGISTER_CURL_CONSTANT(CURLVERSION_NOW);
644 :
645 : /* Error Constants */
646 17007 : REGISTER_CURL_CONSTANT(CURLE_OK);
647 17007 : REGISTER_CURL_CONSTANT(CURLE_UNSUPPORTED_PROTOCOL);
648 17007 : REGISTER_CURL_CONSTANT(CURLE_FAILED_INIT);
649 17007 : REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT);
650 17007 : REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT_USER);
651 17007 : REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_PROXY);
652 17007 : REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_HOST);
653 17007 : REGISTER_CURL_CONSTANT(CURLE_COULDNT_CONNECT);
654 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_SERVER_REPLY);
655 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_ACCESS_DENIED);
656 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_USER_PASSWORD_INCORRECT);
657 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASS_REPLY);
658 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_USER_REPLY);
659 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASV_REPLY);
660 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_227_FORMAT);
661 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_GET_HOST);
662 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_RECONNECT);
663 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_BINARY);
664 17007 : REGISTER_CURL_CONSTANT(CURLE_PARTIAL_FILE);
665 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_RETR_FILE);
666 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_WRITE_ERROR);
667 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_QUOTE_ERROR);
668 17007 : REGISTER_CURL_CONSTANT(CURLE_HTTP_NOT_FOUND);
669 17007 : REGISTER_CURL_CONSTANT(CURLE_WRITE_ERROR);
670 17007 : REGISTER_CURL_CONSTANT(CURLE_MALFORMAT_USER);
671 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_STOR_FILE);
672 17007 : REGISTER_CURL_CONSTANT(CURLE_READ_ERROR);
673 17007 : REGISTER_CURL_CONSTANT(CURLE_OUT_OF_MEMORY);
674 17007 : REGISTER_CURL_CONSTANT(CURLE_OPERATION_TIMEOUTED);
675 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_ASCII);
676 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_PORT_FAILED);
677 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_USE_REST);
678 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_GET_SIZE);
679 17007 : REGISTER_CURL_CONSTANT(CURLE_HTTP_RANGE_ERROR);
680 17007 : REGISTER_CURL_CONSTANT(CURLE_HTTP_POST_ERROR);
681 17007 : REGISTER_CURL_CONSTANT(CURLE_SSL_CONNECT_ERROR);
682 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_BAD_DOWNLOAD_RESUME);
683 17007 : REGISTER_CURL_CONSTANT(CURLE_FILE_COULDNT_READ_FILE);
684 17007 : REGISTER_CURL_CONSTANT(CURLE_LDAP_CANNOT_BIND);
685 17007 : REGISTER_CURL_CONSTANT(CURLE_LDAP_SEARCH_FAILED);
686 17007 : REGISTER_CURL_CONSTANT(CURLE_LIBRARY_NOT_FOUND);
687 17007 : REGISTER_CURL_CONSTANT(CURLE_FUNCTION_NOT_FOUND);
688 17007 : REGISTER_CURL_CONSTANT(CURLE_ABORTED_BY_CALLBACK);
689 17007 : REGISTER_CURL_CONSTANT(CURLE_BAD_FUNCTION_ARGUMENT);
690 17007 : REGISTER_CURL_CONSTANT(CURLE_BAD_CALLING_ORDER);
691 17007 : REGISTER_CURL_CONSTANT(CURLE_HTTP_PORT_FAILED);
692 17007 : REGISTER_CURL_CONSTANT(CURLE_BAD_PASSWORD_ENTERED);
693 17007 : REGISTER_CURL_CONSTANT(CURLE_TOO_MANY_REDIRECTS);
694 17007 : REGISTER_CURL_CONSTANT(CURLE_UNKNOWN_TELNET_OPTION);
695 17007 : REGISTER_CURL_CONSTANT(CURLE_TELNET_OPTION_SYNTAX);
696 17007 : REGISTER_CURL_CONSTANT(CURLE_OBSOLETE);
697 17007 : REGISTER_CURL_CONSTANT(CURLE_SSL_PEER_CERTIFICATE);
698 17007 : REGISTER_CURL_CONSTANT(CURLE_GOT_NOTHING);
699 17007 : REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_NOTFOUND);
700 17007 : REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_SETFAILED);
701 17007 : REGISTER_CURL_CONSTANT(CURLE_SEND_ERROR);
702 17007 : REGISTER_CURL_CONSTANT(CURLE_RECV_ERROR);
703 17007 : REGISTER_CURL_CONSTANT(CURLE_SHARE_IN_USE);
704 17007 : REGISTER_CURL_CONSTANT(CURLE_SSL_CERTPROBLEM);
705 17007 : REGISTER_CURL_CONSTANT(CURLE_SSL_CIPHER);
706 17007 : REGISTER_CURL_CONSTANT(CURLE_SSL_CACERT);
707 17007 : REGISTER_CURL_CONSTANT(CURLE_BAD_CONTENT_ENCODING);
708 : #if LIBCURL_VERSION_NUM >= 0x070a08
709 17007 : REGISTER_CURL_CONSTANT(CURLE_LDAP_INVALID_URL);
710 17007 : REGISTER_CURL_CONSTANT(CURLE_FILESIZE_EXCEEDED);
711 : #endif
712 : #if LIBCURL_VERSION_NUM >= 0x070b00
713 17007 : REGISTER_CURL_CONSTANT(CURLE_FTP_SSL_FAILED);
714 : #endif
715 17007 : REGISTER_CURL_CONSTANT(CURLPROXY_HTTP);
716 17007 : REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS4);
717 17007 : REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS5);
718 :
719 17007 : REGISTER_CURL_CONSTANT(CURL_NETRC_OPTIONAL);
720 17007 : REGISTER_CURL_CONSTANT(CURL_NETRC_IGNORED);
721 17007 : REGISTER_CURL_CONSTANT(CURL_NETRC_REQUIRED);
722 :
723 17007 : REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_NONE);
724 17007 : REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_0);
725 17007 : REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_1);
726 :
727 17007 : REGISTER_CURL_CONSTANT(CURLM_CALL_MULTI_PERFORM);
728 17007 : REGISTER_CURL_CONSTANT(CURLM_OK);
729 17007 : REGISTER_CURL_CONSTANT(CURLM_BAD_HANDLE);
730 17007 : REGISTER_CURL_CONSTANT(CURLM_BAD_EASY_HANDLE);
731 17007 : REGISTER_CURL_CONSTANT(CURLM_OUT_OF_MEMORY);
732 17007 : REGISTER_CURL_CONSTANT(CURLM_INTERNAL_ERROR);
733 :
734 17007 : REGISTER_CURL_CONSTANT(CURLMSG_DONE);
735 :
736 : #if LIBCURL_VERSION_NUM >= 0x070c02
737 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FTPSSLAUTH);
738 17007 : REGISTER_CURL_CONSTANT(CURLFTPAUTH_DEFAULT);
739 17007 : REGISTER_CURL_CONSTANT(CURLFTPAUTH_SSL);
740 17007 : REGISTER_CURL_CONSTANT(CURLFTPAUTH_TLS);
741 : #endif
742 :
743 : #if LIBCURL_VERSION_NUM > 0x070b00
744 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FTP_SSL);
745 17007 : REGISTER_CURL_CONSTANT(CURLFTPSSL_NONE);
746 17007 : REGISTER_CURL_CONSTANT(CURLFTPSSL_TRY);
747 17007 : REGISTER_CURL_CONSTANT(CURLFTPSSL_CONTROL);
748 17007 : REGISTER_CURL_CONSTANT(CURLFTPSSL_ALL);
749 : #endif
750 : #if LIBCURL_VERSION_NUM > 0x071301
751 : REGISTER_CURL_CONSTANT(CURLOPT_CERTINFO);
752 : #endif
753 :
754 : /* SSH support works in 7.19.0+ using libssh2 */
755 : #if LIBCURL_VERSION_NUM >= 0x071300
756 : REGISTER_CURL_CONSTANT(CURLSSH_AUTH_NONE);
757 : REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PUBLICKEY);
758 : REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PASSWORD);
759 : REGISTER_CURL_CONSTANT(CURLSSH_AUTH_HOST);
760 : REGISTER_CURL_CONSTANT(CURLSSH_AUTH_KEYBOARD);
761 : REGISTER_CURL_CONSTANT(CURLSSH_AUTH_DEFAULT);
762 : REGISTER_CURL_CONSTANT(CURLOPT_SSH_AUTH_TYPES);
763 : REGISTER_CURL_CONSTANT(CURLOPT_KEYPASSWD);
764 : REGISTER_CURL_CONSTANT(CURLOPT_SSH_PUBLIC_KEYFILE);
765 : REGISTER_CURL_CONSTANT(CURLOPT_SSH_PRIVATE_KEYFILE);
766 : REGISTER_CURL_CONSTANT(CURLOPT_SSH_HOST_PUBLIC_KEY_MD5);
767 : REGISTER_CURL_CONSTANT(CURLE_SSH);
768 : #endif
769 :
770 : #if LIBCURL_VERSION_NUM > 0x071301
771 : REGISTER_CURL_CONSTANT(CURLOPT_POSTREDIR);
772 : #endif
773 :
774 : #if LIBCURL_VERSION_NUM >= 0x071304
775 : REGISTER_CURL_CONSTANT(CURLOPT_REDIR_PROTOCOLS);
776 : REGISTER_CURL_CONSTANT(CURLOPT_PROTOCOLS);
777 : REGISTER_CURL_CONSTANT(CURLPROTO_HTTP);
778 : REGISTER_CURL_CONSTANT(CURLPROTO_HTTPS);
779 : REGISTER_CURL_CONSTANT(CURLPROTO_FTP);
780 : REGISTER_CURL_CONSTANT(CURLPROTO_FTPS);
781 : REGISTER_CURL_CONSTANT(CURLPROTO_SCP);
782 : REGISTER_CURL_CONSTANT(CURLPROTO_SFTP);
783 : REGISTER_CURL_CONSTANT(CURLPROTO_TELNET);
784 : REGISTER_CURL_CONSTANT(CURLPROTO_LDAP);
785 : REGISTER_CURL_CONSTANT(CURLPROTO_LDAPS);
786 : REGISTER_CURL_CONSTANT(CURLPROTO_DICT);
787 : REGISTER_CURL_CONSTANT(CURLPROTO_FILE);
788 : REGISTER_CURL_CONSTANT(CURLPROTO_TFTP);
789 : REGISTER_CURL_CONSTANT(CURLPROTO_ALL);
790 : #endif
791 :
792 : #if LIBCURL_VERSION_NUM >= 0x070f01
793 17007 : REGISTER_CURL_CONSTANT(CURLOPT_FTP_FILEMETHOD);
794 : #endif
795 :
796 : #if LIBCURL_VERSION_NUM >= 0x071001
797 : REGISTER_CURL_CONSTANT(CURLFTPMETHOD_MULTICWD);
798 : REGISTER_CURL_CONSTANT(CURLFTPMETHOD_NOCWD);
799 : REGISTER_CURL_CONSTANT(CURLFTPMETHOD_SINGLECWD);
800 : #endif
801 :
802 : #ifdef PHP_CURL_NEED_OPENSSL_TSL
803 : if (!CRYPTO_get_id_callback()) {
804 : int i, c = CRYPTO_num_locks();
805 :
806 : php_curl_openssl_tsl = malloc(c * sizeof(MUTEX_T));
807 :
808 : for (i = 0; i < c; ++i) {
809 : php_curl_openssl_tsl[i] = tsrm_mutex_alloc();
810 : }
811 :
812 : CRYPTO_set_id_callback(php_curl_ssl_id);
813 : CRYPTO_set_locking_callback(php_curl_ssl_lock);
814 : }
815 : #endif
816 : #ifdef PHP_CURL_NEED_GNUTLS_TSL
817 : gcry_control(GCRYCTL_SET_THREAD_CBS, &php_curl_gnutls_tsl);
818 : #endif
819 :
820 17007 : if (curl_global_init(CURL_GLOBAL_SSL) != CURLE_OK) {
821 0 : return FAILURE;
822 : }
823 :
824 : #ifdef PHP_CURL_URL_WRAPPERS
825 : # if HAVE_CURL_VERSION_INFO
826 : {
827 17007 : curl_version_info_data *info = curl_version_info(CURLVERSION_NOW);
828 17007 : char **p = (char **)info->protocols;
829 :
830 187077 : while (*p != NULL) {
831 : /* Do not enable cURL "file" protocol and make sure cURL is always used when --with-curlwrappers is enabled */
832 153063 : if (strncasecmp(*p, "file", sizeof("file")-1) != 0) {
833 136056 : php_unregister_url_stream_wrapper(*p TSRMLS_CC);
834 136056 : php_register_url_stream_wrapper(*p, &php_curl_wrapper TSRMLS_CC);
835 : }
836 153063 : (void) *p++;
837 : }
838 : }
839 : # else
840 : php_unregister_url_stream_wrapper("http");
841 : php_register_url_stream_wrapper("http", &php_curl_wrapper TSRMLS_CC);
842 : php_unregister_url_stream_wrapper("https");
843 : php_register_url_stream_wrapper("https", &php_curl_wrapper TSRMLS_CC);
844 : php_unregister_url_stream_wrapper("ftp");
845 : php_register_url_stream_wrapper("ftp", &php_curl_wrapper TSRMLS_CC);
846 : php_unregister_url_stream_wrapper("ftps");
847 : php_register_url_stream_wrapper("ftps", &php_curl_wrapper TSRMLS_CC);
848 : php_unregister_url_stream_wrapper("ldap");
849 : php_register_url_stream_wrapper("ldap", &php_curl_wrapper TSRMLS_CC);
850 : # endif
851 : #endif
852 :
853 17007 : return SUCCESS;
854 : }
855 : /* }}} */
856 :
857 : /* {{{ PHP_MSHUTDOWN_FUNCTION
858 : */
859 : PHP_MSHUTDOWN_FUNCTION(curl)
860 17039 : {
861 : #ifdef PHP_CURL_URL_WRAPPERS
862 17039 : php_unregister_url_stream_wrapper("http" TSRMLS_CC);
863 17039 : php_unregister_url_stream_wrapper("https" TSRMLS_CC);
864 17039 : php_unregister_url_stream_wrapper("ftp" TSRMLS_CC);
865 17039 : php_unregister_url_stream_wrapper("ldap" TSRMLS_CC);
866 : #endif
867 17039 : curl_global_cleanup();
868 : #ifdef PHP_CURL_NEED_OPENSSL_TSL
869 : if (php_curl_openssl_tsl) {
870 : int i, c = CRYPTO_num_locks();
871 :
872 : CRYPTO_set_id_callback(NULL);
873 : CRYPTO_set_locking_callback(NULL);
874 :
875 : for (i = 0; i < c; ++i) {
876 : tsrm_mutex_free(php_curl_openssl_tsl[i]);
877 : }
878 :
879 : free(php_curl_openssl_tsl);
880 : php_curl_openssl_tsl = NULL;
881 : }
882 : #endif
883 17039 : return SUCCESS;
884 : }
885 : /* }}} */
886 :
887 : /* {{{ curl_write
888 : */
889 : static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx)
890 46 : {
891 46 : php_curl *ch = (php_curl *) ctx;
892 46 : php_curl_write *t = ch->handlers->write;
893 46 : size_t length = size * nmemb;
894 : TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
895 :
896 : #if PHP_CURL_DEBUG
897 : fprintf(stderr, "curl_write() called\n");
898 : fprintf(stderr, "data = %s, size = %d, nmemb = %d, ctx = %x\n", data, size, nmemb, ctx);
899 : #endif
900 :
901 46 : switch (t->method) {
902 : case PHP_CURL_STDOUT:
903 10 : PHPWRITE(data, length);
904 10 : break;
905 : case PHP_CURL_FILE:
906 2 : return fwrite(data, size, nmemb, t->fp);
907 : case PHP_CURL_RETURN:
908 32 : if (length > 0) {
909 32 : smart_str_appendl(&t->buf, data, (int) length);
910 : }
911 32 : break;
912 : case PHP_CURL_USER: {
913 : zval **argv[2];
914 2 : zval *retval_ptr = NULL;
915 2 : zval *handle = NULL;
916 2 : zval *zdata = NULL;
917 : int error;
918 : zend_fcall_info fci;
919 :
920 2 : MAKE_STD_ZVAL(handle);
921 2 : ZVAL_RESOURCE(handle, ch->id);
922 2 : zend_list_addref(ch->id);
923 2 : argv[0] = &handle;
924 :
925 2 : MAKE_STD_ZVAL(zdata);
926 2 : ZVAL_STRINGL(zdata, data, length, 1);
927 2 : argv[1] = &zdata;
928 :
929 2 : fci.size = sizeof(fci);
930 2 : fci.function_table = EG(function_table);
931 2 : fci.object_ptr = NULL;
932 2 : fci.function_name = t->func_name;
933 2 : fci.retval_ptr_ptr = &retval_ptr;
934 2 : fci.param_count = 2;
935 2 : fci.params = argv;
936 2 : fci.no_separation = 0;
937 2 : fci.symbol_table = NULL;
938 :
939 2 : ch->in_callback = 1;
940 2 : error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC);
941 2 : ch->in_callback = 0;
942 2 : if (error == FAILURE) {
943 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the CURLOPT_WRITEFUNCTION");
944 0 : length = -1;
945 2 : } else if (retval_ptr) {
946 2 : if (Z_TYPE_P(retval_ptr) != IS_LONG) {
947 0 : convert_to_long_ex(&retval_ptr);
948 : }
949 2 : length = Z_LVAL_P(retval_ptr);
950 2 : zval_ptr_dtor(&retval_ptr);
951 : }
952 :
953 2 : zval_ptr_dtor(argv[0]);
954 2 : zval_ptr_dtor(argv[1]);
955 : break;
956 : }
957 : }
958 :
959 44 : return length;
960 : }
961 : /* }}} */
962 :
963 : /* {{{ curl_progress
964 : */
965 : static size_t curl_progress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
966 0 : {
967 0 : php_curl *ch = (php_curl *) clientp;
968 0 : php_curl_progress *t = ch->handlers->progress;
969 0 : int length = -1;
970 0 : size_t rval = 0;
971 :
972 : #if PHP_CURL_DEBUG
973 : fprintf(stderr, "curl_progress() called\n");
974 : fprintf(stderr, "clientp = %x, dltotal = %f, dlnow = %f, ultotal = %f, ulnow = %f\n", clientp, dltotal, dlnow, ultotal, ulnow);
975 : #endif
976 :
977 0 : switch (t->method) {
978 : case PHP_CURL_USER: {
979 : zval **argv[4];
980 0 : zval *zdltotal = NULL;
981 0 : zval *zdlnow = NULL;
982 0 : zval *zultotal = NULL;
983 0 : zval *zulnow = NULL;
984 : zval *retval_ptr;
985 : int error;
986 : zend_fcall_info fci;
987 : TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
988 :
989 0 : MAKE_STD_ZVAL(zdltotal);
990 0 : MAKE_STD_ZVAL(zdlnow);
991 0 : MAKE_STD_ZVAL(zultotal);
992 0 : MAKE_STD_ZVAL(zulnow);
993 :
994 0 : ZVAL_LONG(zdltotal, (long) dltotal);
995 0 : ZVAL_LONG(zdlnow, (long) dlnow);
996 0 : ZVAL_LONG(zultotal, (long) ultotal);
997 0 : ZVAL_LONG(zulnow, (long) ulnow);
998 :
999 0 : argv[0] = &zdltotal;
1000 0 : argv[1] = &zdlnow;
1001 0 : argv[2] = &zultotal;
1002 0 : argv[3] = &zulnow;
1003 :
1004 0 : fci.size = sizeof(fci);
1005 0 : fci.function_table = EG(function_table);
1006 0 : fci.function_name = t->func_name;
1007 0 : fci.object_ptr = NULL;
1008 0 : fci.retval_ptr_ptr = &retval_ptr;
1009 0 : fci.param_count = 4;
1010 0 : fci.params = argv;
1011 0 : fci.no_separation = 0;
1012 0 : fci.symbol_table = NULL;
1013 :
1014 0 : ch->in_callback = 1;
1015 0 : error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC);
1016 0 : ch->in_callback = 0;
1017 0 : if (error == FAILURE) {
1018 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot call the CURLOPT_PROGRESSFUNCTION");
1019 0 : length = -1;
1020 0 : } else if (retval_ptr) {
1021 0 : if (Z_TYPE_P(retval_ptr) != IS_LONG) {
1022 0 : convert_to_long_ex(&retval_ptr);
1023 : }
1024 0 : if (0 != Z_LVAL_P(retval_ptr)) {
1025 0 : rval = 1;
1026 : }
1027 0 : zval_ptr_dtor(&retval_ptr);
1028 : }
1029 0 : zval_ptr_dtor(argv[0]);
1030 0 : zval_ptr_dtor(argv[1]);
1031 0 : zval_ptr_dtor(argv[2]);
1032 0 : zval_ptr_dtor(argv[3]);
1033 : break;
1034 : }
1035 : }
1036 0 : return rval;
1037 : }
1038 : /* }}} */
1039 :
1040 : /* {{{ curl_read
1041 : */
1042 : static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx)
1043 3 : {
1044 3 : php_curl *ch = (php_curl *) ctx;
1045 3 : php_curl_read *t = ch->handlers->read;
1046 3 : int length = 0;
1047 :
1048 3 : switch (t->method) {
1049 : case PHP_CURL_DIRECT:
1050 2 : if (t->fp) {
1051 2 : length = fread(data, size, nmemb, t->fp);
1052 : }
1053 2 : break;
1054 : case PHP_CURL_USER: {
1055 : zval **argv[3];
1056 1 : zval *handle = NULL;
1057 1 : zval *zfd = NULL;
1058 1 : zval *zlength = NULL;
1059 : zval *retval_ptr;
1060 : int error;
1061 : zend_fcall_info fci;
1062 : TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
1063 :
1064 1 : MAKE_STD_ZVAL(handle);
1065 1 : MAKE_STD_ZVAL(zfd);
1066 1 : MAKE_STD_ZVAL(zlength);
1067 :
1068 1 : ZVAL_RESOURCE(handle, ch->id);
1069 1 : zend_list_addref(ch->id);
1070 1 : ZVAL_RESOURCE(zfd, t->fd);
1071 1 : zend_list_addref(t->fd);
1072 1 : ZVAL_LONG(zlength, (int) size * nmemb);
1073 :
1074 1 : argv[0] = &handle;
1075 1 : argv[1] = &zfd;
1076 1 : argv[2] = &zlength;
1077 :
1078 1 : fci.size = sizeof(fci);
1079 1 : fci.function_table = EG(function_table);
1080 1 : fci.function_name = t->func_name;
1081 1 : fci.object_ptr = NULL;
1082 1 : fci.retval_ptr_ptr = &retval_ptr;
1083 1 : fci.param_count = 3;
1084 1 : fci.params = argv;
1085 1 : fci.no_separation = 0;
1086 1 : fci.symbol_table = NULL;
1087 :
1088 1 : ch->in_callback = 1;
1089 1 : error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC);
1090 1 : ch->in_callback = 0;
1091 1 : if (error == FAILURE) {
1092 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot call the CURLOPT_READFUNCTION");
1093 : #if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */
1094 0 : length = CURL_READFUNC_ABORT;
1095 : #endif
1096 1 : } else if (retval_ptr) {
1097 1 : if (Z_TYPE_P(retval_ptr) == IS_STRING) {
1098 0 : length = MIN((int) (size * nmemb), Z_STRLEN_P(retval_ptr));
1099 0 : memcpy(data, Z_STRVAL_P(retval_ptr), length);
1100 : }
1101 1 : zval_ptr_dtor(&retval_ptr);
1102 : }
1103 :
1104 1 : zval_ptr_dtor(argv[0]);
1105 1 : zval_ptr_dtor(argv[1]);
1106 1 : zval_ptr_dtor(argv[2]);
1107 : break;
1108 : }
1109 : }
1110 :
1111 3 : return length;
1112 : }
1113 : /* }}} */
1114 :
1115 : /* {{{ curl_write_header
1116 : */
1117 : static size_t curl_write_header(char *data, size_t size, size_t nmemb, void *ctx)
1118 280 : {
1119 280 : php_curl *ch = (php_curl *) ctx;
1120 280 : php_curl_write *t = ch->handlers->write_header;
1121 280 : size_t length = size * nmemb;
1122 : TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
1123 :
1124 280 : switch (t->method) {
1125 : case PHP_CURL_STDOUT:
1126 : /* Handle special case write when we're returning the entire transfer
1127 : */
1128 0 : if (ch->handlers->write->method == PHP_CURL_RETURN && length > 0) {
1129 0 : smart_str_appendl(&ch->handlers->write->buf, data, (int) length);
1130 : } else {
1131 0 : PHPWRITE(data, length);
1132 : }
1133 0 : break;
1134 : case PHP_CURL_FILE:
1135 0 : return fwrite(data, size, nmemb, t->fp);
1136 : case PHP_CURL_USER: {
1137 : zval **argv[2];
1138 1 : zval *handle = NULL;
1139 1 : zval *zdata = NULL;
1140 : zval *retval_ptr;
1141 : int error;
1142 : zend_fcall_info fci;
1143 :
1144 1 : MAKE_STD_ZVAL(handle);
1145 1 : MAKE_STD_ZVAL(zdata);
1146 :
1147 1 : ZVAL_RESOURCE(handle, ch->id);
1148 1 : zend_list_addref(ch->id);
1149 1 : ZVAL_STRINGL(zdata, data, length, 1);
1150 :
1151 1 : argv[0] = &handle;
1152 1 : argv[1] = &zdata;
1153 :
1154 1 : fci.size = sizeof(fci);
1155 1 : fci.function_table = EG(function_table);
1156 1 : fci.function_name = t->func_name;
1157 1 : fci.symbol_table = NULL;
1158 1 : fci.object_ptr = NULL;
1159 1 : fci.retval_ptr_ptr = &retval_ptr;
1160 1 : fci.param_count = 2;
1161 1 : fci.params = argv;
1162 1 : fci.no_separation = 0;
1163 :
1164 1 : ch->in_callback = 1;
1165 1 : error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC);
1166 1 : ch->in_callback = 0;
1167 1 : if (error == FAILURE) {
1168 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the CURLOPT_HEADERFUNCTION");
1169 0 : length = -1;
1170 1 : } else if (retval_ptr) {
1171 1 : if (Z_TYPE_P(retval_ptr) != IS_LONG) {
1172 1 : convert_to_long_ex(&retval_ptr);
1173 : }
1174 1 : length = Z_LVAL_P(retval_ptr);
1175 1 : zval_ptr_dtor(&retval_ptr);
1176 : }
1177 1 : zval_ptr_dtor(argv[0]);
1178 1 : zval_ptr_dtor(argv[1]);
1179 1 : break;
1180 : }
1181 :
1182 : case PHP_CURL_IGNORE:
1183 279 : return length;
1184 :
1185 : default:
1186 0 : return -1;
1187 : }
1188 :
1189 1 : return length;
1190 : }
1191 : /* }}} */
1192 :
1193 : static int curl_debug(CURL *cp, curl_infotype type, char *buf, size_t buf_len, void *ctx) /* {{{ */
1194 0 : {
1195 0 : php_curl *ch = (php_curl *) ctx;
1196 :
1197 0 : if (type == CURLINFO_HEADER_OUT) {
1198 0 : if (ch->header.str_len) {
1199 0 : efree(ch->header.str);
1200 : }
1201 0 : if (buf_len > 0) {
1202 0 : ch->header.str = estrndup(buf, buf_len);
1203 0 : ch->header.str_len = buf_len;
1204 : }
1205 : }
1206 :
1207 0 : return 0;
1208 : }
1209 : /* }}} */
1210 :
1211 : #if CURLOPT_PASSWDFUNCTION != 0
1212 : /* {{{ curl_passwd
1213 : */
1214 : static size_t curl_passwd(void *ctx, char *prompt, char *buf, int buflen)
1215 0 : {
1216 0 : php_curl *ch = (php_curl *) ctx;
1217 0 : zval *func = ch->handlers->passwd;
1218 : zval *argv[3];
1219 0 : zval *retval = NULL;
1220 : int error;
1221 0 : int ret = -1;
1222 : TSRMLS_FETCH_FROM_CTX(ch->thread_ctx);
1223 :
1224 0 : MAKE_STD_ZVAL(argv[0]);
1225 0 : MAKE_STD_ZVAL(argv[1]);
1226 0 : MAKE_STD_ZVAL(argv[2]);
1227 :
1228 0 : ZVAL_RESOURCE(argv[0], ch->id);
1229 0 : zend_list_addref(ch->id);
1230 0 : ZVAL_STRING(argv[1], prompt, 1);
1231 0 : ZVAL_LONG(argv[2], buflen);
1232 :
1233 0 : error = call_user_function(EG(function_table), NULL, func, retval, 2, argv TSRMLS_CC);
1234 0 : if (error == FAILURE) {
1235 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the CURLOPT_PASSWDFUNCTION");
1236 0 : } else if (Z_TYPE_P(retval) == IS_STRING || Z_TYPE_P(retval) == IS_UNICODE) {
1237 0 : if (Z_TYPE_P(retval) == IS_UNICODE) {
1238 0 : convert_to_string_ex(&retval);
1239 : }
1240 0 : if (Z_STRLEN_P(retval) > buflen) {
1241 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Returned password is too long for libcurl to handle");
1242 : } else {
1243 0 : strlcpy(buf, Z_STRVAL_P(retval), Z_STRLEN_P(retval));
1244 : }
1245 : } else {
1246 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "User handler '%v' did not return a string", func);
1247 : }
1248 :
1249 0 : zval_ptr_dtor(&argv[0]);
1250 0 : zval_ptr_dtor(&argv[1]);
1251 0 : zval_ptr_dtor(&argv[2]);
1252 0 : zval_ptr_dtor(&retval);
1253 :
1254 0 : return ret;
1255 : }
1256 : /* }}} */
1257 : #endif
1258 :
1259 : #if LIBCURL_VERSION_NUM < 0x071101
1260 : /* {{{ curl_free_string
1261 : */
1262 : static void curl_free_string(void **string)
1263 65 : {
1264 65 : efree(*string);
1265 65 : }
1266 : /* }}} */
1267 : #endif
1268 :
1269 : /* {{{ curl_free_post
1270 : */
1271 : static void curl_free_post(void **post)
1272 1 : {
1273 1 : curl_formfree((struct HttpPost *) *post);
1274 1 : }
1275 : /* }}} */
1276 :
1277 : /* {{{ curl_free_slist
1278 : */
1279 : static void curl_free_slist(void **slist)
1280 3 : {
1281 3 : curl_slist_free_all((struct curl_slist *) *slist);
1282 3 : }
1283 : /* }}} */
1284 :
1285 : /* {{{ proto array curl_version([int version]) U
1286 : Return cURL version information. */
1287 : PHP_FUNCTION(curl_version)
1288 27 : {
1289 : curl_version_info_data *d;
1290 27 : long uversion = CURLVERSION_NOW;
1291 :
1292 27 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &uversion) == FAILURE) {
1293 8 : return;
1294 : }
1295 :
1296 19 : d = curl_version_info(uversion);
1297 19 : if (d == NULL) {
1298 0 : RETURN_FALSE;
1299 : }
1300 :
1301 19 : array_init(return_value);
1302 :
1303 19 : CAAL("version_number", d->version_num);
1304 19 : CAAL("age", d->age);
1305 19 : CAAL("features", d->features);
1306 19 : CAAL("ssl_version_number", d->ssl_version_num);
1307 19 : CAAS("version", d->version);
1308 19 : CAAS("host", d->host);
1309 19 : CAAS("ssl_version", d->ssl_version);
1310 19 : CAAS("libz_version", d->libz_version);
1311 : /* Add an array of protocols */
1312 : {
1313 19 : char **p = (char **) d->protocols;
1314 19 : zval *protocol_list = NULL;
1315 :
1316 19 : MAKE_STD_ZVAL(protocol_list);
1317 19 : array_init(protocol_list);
1318 :
1319 209 : while (*p != NULL) {
1320 171 : add_next_index_ascii_string(protocol_list, *p, 1);
1321 171 : p++;
1322 : }
1323 19 : CAAZ("protocols", protocol_list);
1324 : }
1325 : }
1326 : /* }}} */
1327 :
1328 : /* {{{ alloc_curl_handle
1329 : */
1330 : static void alloc_curl_handle(php_curl **ch)
1331 75 : {
1332 75 : *ch = emalloc(sizeof(php_curl));
1333 75 : (*ch)->handlers = ecalloc(1, sizeof(php_curl_handlers));
1334 75 : (*ch)->handlers->write = ecalloc(1, sizeof(php_curl_write));
1335 75 : (*ch)->handlers->write_header = ecalloc(1, sizeof(php_curl_write));
1336 75 : (*ch)->handlers->read = ecalloc(1, sizeof(php_curl_read));
1337 75 : (*ch)->handlers->progress = ecalloc(1, sizeof(php_curl_progress));
1338 :
1339 75 : (*ch)->in_callback = 0;
1340 75 : (*ch)->header.str_len = 0;
1341 :
1342 75 : memset(&(*ch)->err, 0, sizeof((*ch)->err));
1343 :
1344 : #if LIBCURL_VERSION_NUM < 0x071101
1345 75 : zend_llist_init(&(*ch)->to_free.str, sizeof(char *), (llist_dtor_func_t) curl_free_string, 0);
1346 : #endif
1347 75 : zend_llist_init(&(*ch)->to_free.slist, sizeof(struct curl_slist), (llist_dtor_func_t) curl_free_slist, 0);
1348 75 : zend_llist_init(&(*ch)->to_free.post, sizeof(struct HttpPost), (llist_dtor_func_t) curl_free_post, 0);
1349 75 : }
1350 : /* }}} */
1351 :
1352 : #if LIBCURL_VERSION_NUM > 0x071301
1353 : /* {{{ split_certinfo
1354 : */
1355 : static void split_certinfo(char *string, zval *hash)
1356 : {
1357 : char *org = estrdup(string);
1358 : char *s = org;
1359 : char *split;
1360 :
1361 : if(org) {
1362 : do {
1363 : char *key;
1364 : char *val;
1365 : char *tmp;
1366 :
1367 : split = strstr(s, "; ");
1368 : if(split)
1369 : *split = '\0';
1370 :
1371 : key = s;
1372 : tmp = memchr(key, '=', 64);
1373 : if(tmp) {
1374 : *tmp = '\0';
1375 : val = tmp+1;
1376 : add_assoc_string(hash, key, val, 1);
1377 : }
1378 : s = split+2;
1379 : } while(split);
1380 : efree(org);
1381 : }
1382 : }
1383 :
1384 : /* {{{ create_certinfo
1385 : */
1386 : static void create_certinfo(struct curl_certinfo *ci, zval *listcode TSRMLS_DC)
1387 : {
1388 : int i;
1389 :
1390 : if(ci) {
1391 : zval *certhash = NULL;
1392 :
1393 : for(i=0; i<ci->num_of_certs; i++) {
1394 : struct curl_slist *slist;
1395 :
1396 : MAKE_STD_ZVAL(certhash);
1397 : array_init(certhash);
1398 : for(slist = ci->certinfo[i]; slist; slist = slist->next) {
1399 : int len;
1400 : char s[64];
1401 : char *tmp;
1402 : strncpy(s, slist->data, 64);
1403 : tmp = memchr(s, ':', 64);
1404 : if(tmp) {
1405 : *tmp = '\0';
1406 : len = strlen(s);
1407 : if(!strcmp(s, "Subject") || !strcmp(s, "Issuer")) {
1408 : zval *hash;
1409 :
1410 : MAKE_STD_ZVAL(hash);
1411 : array_init(hash);
1412 :
1413 : split_certinfo(&slist->data[len+1], hash);
1414 : add_assoc_zval(certhash, s, hash);
1415 : } else {
1416 : add_assoc_string(certhash, s, &slist->data[len+1], 1);
1417 : }
1418 : } else {
1419 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not extract hash key from certificate info");
1420 : }
1421 : }
1422 : add_next_index_zval(listcode, certhash);
1423 : }
1424 : }
1425 : }
1426 : /* }}} */
1427 : #endif
1428 :
1429 : /* {{{ proto resource curl_init([string url]) U
1430 : Initialize a cURL session */
1431 : PHP_FUNCTION(curl_init)
1432 66 : {
1433 : php_curl *ch;
1434 : CURL *cp;
1435 : zval *clone;
1436 66 : zstr url = NULL_ZSTR;
1437 66 : int url_len = 0;
1438 66 : zend_uchar url_type = 0;
1439 :
1440 66 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|t", &url, &url_len, &url_type) == FAILURE) {
1441 0 : return;
1442 : }
1443 :
1444 66 : if (url.v && url_type == IS_UNICODE) {
1445 5 : url.s = zend_unicode_to_ascii((UChar*)url.u, url_len TSRMLS_CC);
1446 5 : if (!url.s) {
1447 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received");
1448 0 : RETURN_FALSE;
1449 : }
1450 : }
1451 :
1452 66 : cp = curl_easy_init();
1453 66 : if (!cp) {
1454 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not initialize a new cURL handle");
1455 0 : RETURN_FALSE;
1456 : }
1457 :
1458 66 : alloc_curl_handle(&ch);
1459 : TSRMLS_SET_CTX(ch->thread_ctx);
1460 :
1461 66 : ch->cp = cp;
1462 :
1463 66 : ch->handlers->write->method = PHP_CURL_STDOUT;
1464 66 : ch->handlers->write->type = PHP_CURL_ASCII;
1465 66 : ch->handlers->read->method = PHP_CURL_DIRECT;
1466 66 : ch->handlers->write_header->method = PHP_CURL_IGNORE;
1467 :
1468 66 : ch->uses = 0;
1469 :
1470 66 : MAKE_STD_ZVAL(clone);
1471 66 : ch->clone = clone;
1472 :
1473 66 : curl_easy_setopt(ch->cp, CURLOPT_NOPROGRESS, 1);
1474 66 : curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0);
1475 66 : curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER, ch->err.str);
1476 66 : curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write);
1477 66 : curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch);
1478 66 : curl_easy_setopt(ch->cp, CURLOPT_READFUNCTION, curl_read);
1479 66 : curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch);
1480 66 : curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_header);
1481 66 : curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
1482 66 : curl_easy_setopt(ch->cp, CURLOPT_DNS_USE_GLOBAL_CACHE, 1);
1483 66 : curl_easy_setopt(ch->cp, CURLOPT_DNS_CACHE_TIMEOUT, 120);
1484 66 : curl_easy_setopt(ch->cp, CURLOPT_MAXREDIRS, 20); /* prevent infinite redirects */
1485 : #if defined(ZTS)
1486 : curl_easy_setopt(ch->cp, CURLOPT_NOSIGNAL, 1);
1487 : #endif
1488 :
1489 66 : if (url.v) {
1490 5 : if (!php_curl_option_url(ch, url.s, url_len)) {
1491 0 : _php_curl_close_ex(ch TSRMLS_CC);
1492 0 : RETURN_FALSE;
1493 : }
1494 : }
1495 :
1496 66 : ZEND_REGISTER_RESOURCE(return_value, ch, le_curl);
1497 66 : ch->id = Z_LVAL_P(return_value);
1498 :
1499 66 : if (url_type == IS_UNICODE) {
1500 5 : efree(url.s);
1501 : }
1502 : }
1503 : /* }}} */
1504 :
1505 : /* {{{ proto resource curl_copy_handle(resource ch) U
1506 : Copy a cURL handle along with all of it's preferences */
1507 : PHP_FUNCTION(curl_copy_handle)
1508 9 : {
1509 : CURL *cp;
1510 : zval *zid;
1511 : php_curl *ch, *dupch;
1512 :
1513 9 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
1514 0 : return;
1515 : }
1516 :
1517 9 : ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
1518 :
1519 9 : cp = curl_easy_duphandle(ch->cp);
1520 9 : if (!cp) {
1521 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot duplicate cURL handle");
1522 0 : RETURN_FALSE;
1523 : }
1524 :
1525 9 : alloc_curl_handle(&dupch);
1526 : TSRMLS_SET_CTX(dupch->thread_ctx);
1527 :
1528 9 : dupch->cp = cp;
1529 9 : dupch->uses = 0;
1530 9 : if (ch->handlers->write->stream) {
1531 0 : Z_ADDREF_P(dupch->handlers->write->stream);
1532 0 : dupch->handlers->write->stream = ch->handlers->write->stream;
1533 : }
1534 9 : dupch->handlers->write->method = ch->handlers->write->method;
1535 9 : dupch->handlers->write->type = ch->handlers->write->type;
1536 9 : if (ch->handlers->read->stream) {
1537 0 : Z_ADDREF_P(ch->handlers->read->stream);
1538 : }
1539 9 : dupch->handlers->read->stream = ch->handlers->read->stream;
1540 9 : dupch->handlers->read->method = ch->handlers->read->method;
1541 9 : dupch->handlers->write_header->method = ch->handlers->write_header->method;
1542 9 : if (ch->handlers->write_header->stream) {
1543 0 : Z_ADDREF_P(ch->handlers->write_header->stream);
1544 : }
1545 9 : dupch->handlers->write_header->stream = ch->handlers->write_header->stream;
1546 :
1547 9 : dupch->handlers->write->fp = ch->handlers->write->fp;
1548 9 : dupch->handlers->write_header->fp = ch->handlers->write_header->fp;
1549 9 : dupch->handlers->read->fp = ch->handlers->read->fp;
1550 9 : dupch->handlers->read->fd = ch->handlers->read->fd;
1551 : #if CURLOPT_PASSWDDATA != 0
1552 9 : if (ch->handlers->passwd) {
1553 0 : zval_add_ref(&ch->handlers->passwd);
1554 0 : dupch->handlers->passwd = ch->handlers->passwd;
1555 0 : curl_easy_setopt(ch->cp, CURLOPT_PASSWDDATA, (void *) dupch);
1556 : }
1557 : #endif
1558 9 : if (ch->handlers->write->func_name) {
1559 0 : zval_add_ref(&ch->handlers->write->func_name);
1560 0 : dupch->handlers->write->func_name = ch->handlers->write->func_name;
1561 : }
1562 9 : if (ch->handlers->read->func_name) {
1563 0 : zval_add_ref(&ch->handlers->read->func_name);
1564 0 : dupch->handlers->read->func_name = ch->handlers->read->func_name;
1565 : }
1566 9 : if (ch->handlers->write_header->func_name) {
1567 0 : zval_add_ref(&ch->handlers->write_header->func_name);
1568 0 : dupch->handlers->write_header->func_name = ch->handlers->write_header->func_name;
1569 : }
1570 :
1571 9 : curl_easy_setopt(dupch->cp, CURLOPT_ERRORBUFFER, dupch->err.str);
1572 9 : curl_easy_setopt(dupch->cp, CURLOPT_FILE, (void *) dupch);
1573 9 : curl_easy_setopt(dupch->cp, CURLOPT_INFILE, (void *) dupch);
1574 9 : curl_easy_setopt(dupch->cp, CURLOPT_WRITEHEADER, (void *) dupch);
1575 :
1576 : #if LIBCURL_VERSION_NUM < 0x071101
1577 9 : zend_llist_copy(&dupch->to_free.str, &ch->to_free.str);
1578 : /* Don't try to free copied strings, they're free'd when the original handle is destroyed */
1579 9 : dupch->to_free.str.dtor = NULL;
1580 : #endif
1581 9 : zend_llist_copy(&dupch->to_free.slist, &ch->to_free.slist);
1582 9 : zend_llist_copy(&dupch->to_free.post, &ch->to_free.post);
1583 :
1584 : /* Keep track of cloned copies to avoid invoking curl destructors for every clone */
1585 9 : Z_ADDREF_P(ch->clone);
1586 9 : dupch->clone = ch->clone;
1587 :
1588 9 : ZEND_REGISTER_RESOURCE(return_value, dupch, le_curl);
1589 9 : dupch->id = Z_LVAL_P(return_value);
1590 : }
1591 : /* }}} */
1592 :
1593 : static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *return_value TSRMLS_DC) /* {{{ */
1594 130 : {
1595 130 : CURLcode error=CURLE_OK;
1596 :
1597 130 : switch (option) {
1598 : case CURLOPT_INFILESIZE:
1599 : case CURLOPT_VERBOSE:
1600 : case CURLOPT_HEADER:
1601 : case CURLOPT_NOPROGRESS:
1602 : case CURLOPT_NOBODY:
1603 : case CURLOPT_FAILONERROR:
1604 : case CURLOPT_UPLOAD:
1605 : case CURLOPT_POST:
1606 : case CURLOPT_FTPLISTONLY:
1607 : case CURLOPT_FTPAPPEND:
1608 : case CURLOPT_NETRC:
1609 : case CURLOPT_PUT:
1610 : #if CURLOPT_MUTE != 0
1611 : case CURLOPT_MUTE:
1612 : #endif
1613 : case CURLOPT_TIMEOUT:
1614 : #if LIBCURL_VERSION_NUM > 0x071002
1615 : case CURLOPT_TIMEOUT_MS:
1616 : #endif
1617 : case CURLOPT_FTP_USE_EPSV:
1618 : case CURLOPT_LOW_SPEED_LIMIT:
1619 : case CURLOPT_SSLVERSION:
1620 : case CURLOPT_LOW_SPEED_TIME:
1621 : case CURLOPT_RESUME_FROM:
1622 : case CURLOPT_TIMEVALUE:
1623 : case CURLOPT_TIMECONDITION:
1624 : case CURLOPT_TRANSFERTEXT:
1625 : case CURLOPT_HTTPPROXYTUNNEL:
1626 : case CURLOPT_FILETIME:
1627 : case CURLOPT_MAXREDIRS:
1628 : case CURLOPT_MAXCONNECTS:
1629 : case CURLOPT_CLOSEPOLICY:
1630 : case CURLOPT_FRESH_CONNECT:
1631 : case CURLOPT_FORBID_REUSE:
1632 : case CURLOPT_CONNECTTIMEOUT:
1633 : #if LIBCURL_VERSION_NUM > 0x071002
1634 : case CURLOPT_CONNECTTIMEOUT_MS:
1635 : #endif
1636 : case CURLOPT_SSL_VERIFYHOST:
1637 : case CURLOPT_SSL_VERIFYPEER:
1638 : case CURLOPT_DNS_USE_GLOBAL_CACHE:
1639 : case CURLOPT_NOSIGNAL:
1640 : case CURLOPT_PROXYTYPE:
1641 : case CURLOPT_BUFFERSIZE:
1642 : case CURLOPT_HTTPGET:
1643 : case CURLOPT_HTTP_VERSION:
1644 : case CURLOPT_CRLF:
1645 : case CURLOPT_DNS_CACHE_TIMEOUT:
1646 : case CURLOPT_PROXYPORT:
1647 : case CURLOPT_FTP_USE_EPRT:
1648 : #if LIBCURL_VERSION_NUM > 0x070a05 /* CURLOPT_HTTPAUTH is available since curl 7.10.6 */
1649 : case CURLOPT_HTTPAUTH:
1650 : #endif
1651 : #if LIBCURL_VERSION_NUM > 0x070a06 /* CURLOPT_PROXYAUTH & CURLOPT_FTP_CREATE_MISSING_DIRS are available since curl 7.10.7 */
1652 : case CURLOPT_PROXYAUTH:
1653 : case CURLOPT_FTP_CREATE_MISSING_DIRS:
1654 : #endif
1655 :
1656 : #if LIBCURL_VERSION_NUM >= 0x070c02
1657 : case CURLOPT_FTPSSLAUTH:
1658 : #endif
1659 : #if LIBCURL_VERSION_NUM > 0x070b00
1660 : case CURLOPT_FTP_SSL:
1661 : #endif
1662 : case CURLOPT_UNRESTRICTED_AUTH:
1663 : case CURLOPT_PORT:
1664 : case CURLOPT_AUTOREFERER:
1665 : case CURLOPT_COOKIESESSION:
1666 : #if LIBCURL_VERSION_NUM > 0x070b01 /* CURLOPT_TCP_NODELAY is available since curl 7.11.2 */
1667 : case CURLOPT_TCP_NODELAY:
1668 : #endif
1669 : #if LIBCURL_VERSION_NUM >= 0x71304
1670 : case CURLOPT_REDIR_PROTOCOLS:
1671 : case CURLOPT_PROTOCOLS:
1672 : #endif
1673 : #if LIBCURL_VERSION_NUM > 0x070a07 /* CURLOPT_IPRESOLVE is available since curl 7.10.8 */
1674 : case CURLOPT_IPRESOLVE:
1675 : #endif
1676 : #if LIBCURL_VERSION_NUM >= 0x070f01
1677 : case CURLOPT_FTP_FILEMETHOD:
1678 : #endif
1679 : #if LIBCURL_VERSION_NUM > 0x071301
1680 : case CURLOPT_CERTINFO:
1681 : #endif
1682 13 : convert_to_long_ex(zvalue);
1683 : #if LIBCURL_VERSION_NUM >= 0x71304
1684 : if ((option == CURLOPT_PROTOCOLS || option == CURLOPT_REDIR_PROTOCOLS) &&
1685 : (PG(open_basedir) && *PG(open_basedir)) && (Z_LVAL_PP(zvalue) & CURLPROTO_FILE)) {
1686 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLPROTO_FILE cannot be activated when open_basedir is set");
1687 : RETVAL_FALSE;
1688 : return 1;
1689 : }
1690 : #endif
1691 13 : error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue));
1692 13 : break;
1693 : case CURLOPT_FOLLOWLOCATION:
1694 2 : convert_to_long_ex(zvalue);
1695 2 : if (PG(open_basedir) && *PG(open_basedir)) {
1696 1 : if (Z_LVAL_PP(zvalue) != 0) {
1697 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLOPT_FOLLOWLOCATION cannot be activated when open_basedir is set");
1698 1 : RETVAL_FALSE;
1699 1 : return 1;
1700 : }
1701 : }
1702 1 : error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue));
1703 1 : break;
1704 : #if LIBCURL_VERSION_NUM > 0x071301
1705 : case CURLOPT_POSTREDIR:
1706 : convert_to_long_ex(zvalue);
1707 : error = curl_easy_setopt(ch->cp, CURLOPT_POSTREDIR, Z_LVAL_PP(zvalue) & CURL_REDIR_POST_ALL);
1708 : break;
1709 : #endif
1710 : case CURLOPT_PRIVATE:
1711 : case CURLOPT_URL:
1712 : case CURLOPT_PROXY:
1713 : case CURLOPT_USERPWD:
1714 : case CURLOPT_PROXYUSERPWD:
1715 : case CURLOPT_RANGE:
1716 : case CURLOPT_CUSTOMREQUEST:
1717 : case CURLOPT_USERAGENT:
1718 : case CURLOPT_FTPPORT:
1719 : case CURLOPT_COOKIE:
1720 : case CURLOPT_REFERER:
1721 : case CURLOPT_INTERFACE:
1722 : case CURLOPT_KRB4LEVEL:
1723 : case CURLOPT_EGDSOCKET:
1724 : case CURLOPT_CAINFO:
1725 : case CURLOPT_CAPATH:
1726 : case CURLOPT_SSL_CIPHER_LIST:
1727 : case CURLOPT_SSLKEY:
1728 : case CURLOPT_SSLKEYTYPE:
1729 : case CURLOPT_SSLKEYPASSWD:
1730 : case CURLOPT_SSLENGINE:
1731 : case CURLOPT_SSLENGINE_DEFAULT:
1732 : case CURLOPT_SSLCERTTYPE:
1733 : case CURLOPT_ENCODING:
1734 : #if LIBCURL_VERSION_NUM >= 0x071300
1735 : case CURLOPT_SSH_PUBLIC_KEYFILE:
1736 : case CURLOPT_SSH_PRIVATE_KEYFILE:
1737 : #endif
1738 : {
1739 : #if LIBCURL_VERSION_NUM < 0x071100
1740 60 : char *copystr = NULL;
1741 : #endif
1742 :
1743 60 : convert_to_string_ex(zvalue);
1744 : #if LIBCURL_VERSION_NUM >= 0x071300
1745 : if (
1746 : option == CURLOPT_SSH_PUBLIC_KEYFILE || option == CURLOPT_SSH_PRIVATE_KEYFILE
1747 :
1748 : ) {
1749 : if (php_check_open_basedir(Z_STRVAL_PP(zvalue) TSRMLS_CC)) {
1750 : RETVAL_FALSE;
1751 : return 1;
1752 : }
1753 : }
1754 : #endif
1755 60 : if (option == CURLOPT_URL) {
1756 55 : if (!php_curl_option_url(ch, Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue))) {
1757 0 : RETVAL_FALSE;
1758 0 : return 1;
1759 : }
1760 : } else {
1761 : #if LIBCURL_VERSION_NUM >= 0x071100
1762 : /* Strings passed to libcurl as ’char *’ arguments, are copied by the library... NOTE: before 7.17.0 strings were not copied. */
1763 : error = curl_easy_setopt(ch->cp, option, Z_STRVAL_PP(zvalue));
1764 : #else
1765 5 : copystr = estrndup(Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue));
1766 5 : error = curl_easy_setopt(ch->cp, option, copystr);
1767 5 : zend_llist_add_element(&ch->to_free.str, ©str);
1768 : #endif
1769 : }
1770 60 : break;
1771 : }
1772 : case CURLOPT_FILE:
1773 : case CURLOPT_INFILE:
1774 : case CURLOPT_WRITEHEADER:
1775 : case CURLOPT_STDERR: {
1776 8 : FILE *fp = NULL;
1777 : int type;
1778 : void * what;
1779 :
1780 8 : what = zend_fetch_resource(zvalue TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream());
1781 8 : if (!what) {
1782 0 : RETVAL_FALSE;
1783 0 : return 1;
1784 : }
1785 :
1786 8 : if (FAILURE == php_stream_cast((php_stream *) what, PHP_STREAM_AS_STDIO, (void *) &fp, REPORT_ERRORS)) {
1787 0 : RETVAL_FALSE;
1788 0 : return 1;
1789 : }
1790 :
1791 8 : if (!fp) {
1792 0 : RETVAL_FALSE;
1793 0 : return 1;
1794 : }
1795 :
1796 8 : error = CURLE_OK;
1797 8 : switch (option) {
1798 : case CURLOPT_FILE:
1799 3 : if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
1800 2 : Z_ADDREF_PP(zvalue);
1801 2 : ch->handlers->write->fp = fp;
1802 2 : ch->handlers->write->method = PHP_CURL_FILE;
1803 2 : ch->handlers->write->stream = *zvalue;
1804 : } else {
1805 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
1806 1 : RETVAL_FALSE;
1807 1 : return 1;
1808 : }
1809 2 : break;
1810 : case CURLOPT_WRITEHEADER:
1811 0 : if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
1812 0 : Z_ADDREF_PP(zvalue);
1813 0 : ch->handlers->write_header->fp = fp;
1814 0 : ch->handlers->write_header->method = PHP_CURL_FILE;
1815 0 : ch->handlers->write_header->stream = *zvalue;
1816 : } else {
1817 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
1818 0 : RETVAL_FALSE;
1819 0 : return 1;
1820 : }
1821 0 : break;
1822 : case CURLOPT_INFILE:
1823 2 : Z_ADDREF_PP(zvalue);
1824 2 : ch->handlers->read->fp = fp;
1825 2 : ch->handlers->read->fd = Z_LVAL_PP(zvalue);
1826 2 : ch->handlers->read->stream = *zvalue;
1827 2 : break;
1828 : case CURLOPT_STDERR:
1829 6 : if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
1830 3 : if (ch->handlers->std_err) {
1831 1 : zval_ptr_dtor(&ch->handlers->std_err);
1832 : }
1833 3 : zval_add_ref(zvalue);
1834 3 : ch->handlers->std_err = *zvalue;
1835 3 : zend_list_addref(Z_LVAL_PP(zvalue));
1836 : } else {
1837 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
1838 0 : RETVAL_FALSE;
1839 0 : return 1;
1840 : }
1841 : /* break omitted intentionally */
1842 : default:
1843 3 : error = curl_easy_setopt(ch->cp, option, fp);
1844 : break;
1845 : }
1846 :
1847 7 : break;
1848 : }
1849 : case CURLOPT_RETURNTRANSFER:
1850 31 : convert_to_long_ex(zvalue);
1851 :
1852 31 : if (Z_LVAL_PP(zvalue)) {
1853 30 : ch->handlers->write->method = PHP_CURL_RETURN;
1854 : } else {
1855 1 : ch->handlers->write->method = PHP_CURL_STDOUT;
1856 : }
1857 31 : break;
1858 : case CURLOPT_BINARYTRANSFER:
1859 1 : convert_to_long_ex(zvalue);
1860 :
1861 1 : if (Z_LVAL_PP(zvalue)) {
1862 1 : ch->handlers->write->type = PHP_CURL_BINARY;
1863 : } else {
1864 0 : ch->handlers->write->type = PHP_CURL_ASCII;
1865 : }
1866 1 : break;
1867 : case CURLOPT_WRITEFUNCTION:
1868 2 : if (ch->handlers->write->func_name) {
1869 0 : zval_ptr_dtor(&ch->handlers->write->func_name);
1870 0 : ch->handlers->write->fci_cache = empty_fcall_info_cache;
1871 : }
1872 2 : zval_add_ref(zvalue);
1873 2 : ch->handlers->write->func_name = *zvalue;
1874 2 : ch->handlers->write->method = PHP_CURL_USER;
1875 2 : break;
1876 : case CURLOPT_READFUNCTION:
1877 1 : if (ch->handlers->read->func_name) {
1878 0 : zval_ptr_dtor(&ch->handlers->read->func_name);
1879 0 : ch->handlers->read->fci_cache = empty_fcall_info_cache;
1880 : }
1881 1 : zval_add_ref(zvalue);
1882 1 : ch->handlers->read->func_name = *zvalue;
1883 1 : ch->handlers->read->method = PHP_CURL_USER;
1884 1 : break;
1885 : case CURLOPT_PROGRESSFUNCTION:
1886 0 : curl_easy_setopt(ch->cp, CURLOPT_PROGRESSFUNCTION, curl_progress);
1887 0 : curl_easy_setopt(ch->cp, CURLOPT_PROGRESSDATA, ch);
1888 0 : if (ch->handlers->progress->func_name) {
1889 0 : zval_ptr_dtor(&ch->handlers->progress->func_name);
1890 0 : ch->handlers->progress->fci_cache = empty_fcall_info_cache;
1891 : }
1892 0 : zval_add_ref(zvalue);
1893 0 : ch->handlers->progress->func_name = *zvalue;
1894 0 : ch->handlers->progress->method = PHP_CURL_USER;
1895 0 : break;
1896 : case CURLOPT_HEADERFUNCTION:
1897 1 : if (ch->handlers->write_header->func_name) {
1898 0 : zval_ptr_dtor(&ch->handlers->write_header->func_name);
1899 0 : ch->handlers->write_header->fci_cache = empty_fcall_info_cache;
1900 : }
1901 1 : zval_add_ref(zvalue);
1902 1 : ch->handlers->write_header->func_name = *zvalue;
1903 1 : ch->handlers->write_header->method = PHP_CURL_USER;
1904 1 : break;
1905 : #if CURLOPT_PASSWDFUNCTION != 0
1906 : case CURLOPT_PASSWDFUNCTION:
1907 0 : if (ch->handlers->passwd) {
1908 0 : zval_ptr_dtor(&ch->handlers->passwd);
1909 : }
1910 0 : zval_add_ref(zvalue);
1911 0 : ch->handlers->passwd = *zvalue;
1912 0 : error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDFUNCTION, curl_passwd);
1913 0 : error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDDATA, (void *) ch);
1914 0 : break;
1915 : #endif
1916 : case CURLOPT_POSTFIELDS:
1917 5 : if (Z_TYPE_PP(zvalue) == IS_ARRAY || Z_TYPE_PP(zvalue) == IS_OBJECT) {
1918 : zval **current;
1919 : HashTable *postfields;
1920 1 : struct HttpPost *first = NULL;
1921 1 : struct HttpPost *last = NULL;
1922 : char *postval;
1923 : zstr string_key;
1924 : char *key;
1925 : ulong num_key;
1926 : uint string_key_len;
1927 1 : int type = -1;
1928 :
1929 1 : postfields = HASH_OF(*zvalue);
1930 1 : if (!postfields) {
1931 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't get HashTable in CURLOPT_POSTFIELDS");
1932 0 : RETVAL_FALSE;
1933 0 : return 1;
1934 : }
1935 :
1936 1 : for (zend_hash_internal_pointer_reset(postfields);
1937 5 : zend_hash_get_current_data(postfields, (void **) ¤t) == SUCCESS;
1938 : zend_hash_move_forward(postfields)
1939 3 : ) {
1940 : int ntype;
1941 : int l;
1942 3 : UErrorCode status = U_ZERO_ERROR;
1943 : uint data_len;
1944 :
1945 3 : switch (Z_TYPE_PP(current)) {
1946 : case IS_UNICODE:
1947 3 : ntype = HASH_KEY_IS_UNICODE;
1948 3 : break;
1949 : case IS_STRING:
1950 0 : ntype = HASH_KEY_IS_STRING;
1951 0 : break;
1952 : default:
1953 0 : if (type != -1) {
1954 0 : ntype = type;
1955 : } else {
1956 0 : ntype = HASH_KEY_IS_STRING;
1957 : }
1958 : break;
1959 : }
1960 :
1961 3 : if (type == -1) {
1962 1 : type = ntype;
1963 2 : } else if (type != ntype) {
1964 0 : goto type_conflict;
1965 : }
1966 :
1967 3 : SEPARATE_ZVAL(current);
1968 3 : convert_to_string_with_converter_ex(current, UG(utf8_conv));
1969 3 : postval = Z_STRVAL_PP(current);
1970 3 : data_len = Z_STRLEN_PP(current);
1971 :
1972 3 : ntype = zend_hash_get_current_key_ex(postfields, &string_key, &string_key_len, &num_key, 0, NULL);
1973 3 : if (type != ntype && ntype != HASH_KEY_IS_LONG) {
1974 0 : type_conflict:
1975 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Form parameters must either be all unicode or all binary");
1976 0 : continue;
1977 : }
1978 :
1979 3 : switch (ntype) {
1980 : case HASH_KEY_IS_UNICODE:
1981 3 : zend_unicode_to_string_ex(UG(utf8_conv), &key, &l, string_key.u, string_key_len, &status);
1982 3 : break;
1983 : case HASH_KEY_IS_STRING:
1984 0 : key = string_key.s;
1985 0 : l = string_key_len - 1;
1986 0 : break;
1987 : case HASH_KEY_IS_LONG:
1988 0 : key = NULL;
1989 0 : l = 0;
1990 : break;
1991 : }
1992 :
1993 : /* The arguments after _NAMELENGTH and _CONTENTSLENGTH
1994 : * must be explicitly cast to long in curl_formadd
1995 : * use since curl needs a long not an int. */
1996 3 : if (*postval == '@') {
1997 : char *type, *filename;
1998 0 : ++postval;
1999 :
2000 0 : if ((type = php_memnstr(postval, ";type=", sizeof(";type=") - 1, postval + Z_STRLEN_PP(current)))) {
2001 0 : *type = '\0';
2002 : }
2003 0 : if ((filename = php_memnstr(postval, ";filename=", sizeof(";filename=") - 1, postval + Z_STRLEN_PP(current)))) {
2004 0 : *filename = '\0';
2005 : }
2006 : /* open_basedir check */
2007 0 : if (php_check_open_basedir(postval TSRMLS_CC)) {
2008 0 : RETVAL_FALSE;
2009 0 : return 1;
2010 : }
2011 0 : error = curl_formadd(&first, &last,
2012 : CURLFORM_COPYNAME, string_key,
2013 : CURLFORM_NAMELENGTH, (long)string_key_len - 1,
2014 : CURLFORM_FILENAME, filename ? filename + sizeof(";filename=") - 1 : postval,
2015 : CURLFORM_CONTENTTYPE, type ? type + sizeof(";type=") - 1 : "application/octet-stream",
2016 : CURLFORM_FILE, postval,
2017 : CURLFORM_END);
2018 0 : if (type) {
2019 0 : *type = ';';
2020 : }
2021 0 : if (filename) {
2022 0 : *filename = ';';
2023 : }
2024 : } else {
2025 3 : error = curl_formadd(&first, &last,
2026 : CURLFORM_COPYNAME, key,
2027 : CURLFORM_NAMELENGTH, l,
2028 : CURLFORM_COPYCONTENTS, postval,
2029 : CURLFORM_CONTENTSLENGTH, (long)data_len,
2030 : CURLFORM_END);
2031 : }
2032 3 : if (ntype == HASH_KEY_IS_UNICODE) {
2033 3 : efree(key);
2034 : }
2035 : }
2036 :
2037 1 : SAVE_CURL_ERROR(ch, error);
2038 1 : if (error != CURLE_OK) {
2039 0 : RETVAL_FALSE
2040 0 : return 1;
2041 : }
2042 :
2043 1 : zend_llist_add_element(&ch->to_free.post, &first);
2044 1 : error = curl_easy_setopt(ch->cp, CURLOPT_HTTPPOST, first);
2045 :
2046 : } else {
2047 : #if LIBCURL_VERSION_NUM >= 0x071101
2048 : convert_to_string_ex(zvalue);
2049 : /* with curl 7.17.0 and later, we can use COPYPOSTFIELDS, but we have to provide size before */
2050 : error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, Z_STRLEN_PP(zvalue));
2051 : error = curl_easy_setopt(ch->cp, CURLOPT_COPYPOSTFIELDS, Z_STRVAL_PP(zvalue));
2052 : #else
2053 3 : char *post = NULL;
2054 :
2055 3 : convert_to_string_ex(zvalue);
2056 3 : post = estrndup(Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue));
2057 3 : zend_llist_add_element(&ch->to_free.str, &post);
2058 :
2059 3 : error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, post);
2060 3 : error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, Z_STRLEN_PP(zvalue));
2061 : #endif
2062 : }
2063 4 : break;
2064 : case CURLOPT_HTTPHEADER:
2065 : case CURLOPT_QUOTE:
2066 : case CURLOPT_HTTP200ALIASES:
2067 : case CURLOPT_POSTQUOTE: {
2068 : zval **current;
2069 : HashTable *ph;
2070 4 : struct curl_slist *slist = NULL;
2071 :
2072 4 : ph = HASH_OF(*zvalue);
2073 4 : if (!ph) {
2074 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must pass either an object or an array with the CURLOPT_HTTPHEADER, CURLOPT_QUOTE, CURLOPT_HTTP200ALIASES and CURLOPT_POSTQUOTE arguments");
2075 1 : RETVAL_FALSE;
2076 1 : return 1;
2077 : }
2078 :
2079 3 : for (zend_hash_internal_pointer_reset(ph);
2080 9 : zend_hash_get_current_data(ph, (void **) ¤t) == SUCCESS;
2081 : zend_hash_move_forward(ph)
2082 3 : ) {
2083 3 : SEPARATE_ZVAL(current);
2084 3 : convert_to_string_ex(current);
2085 :
2086 3 : slist = curl_slist_append(slist, Z_STRVAL_PP(current));
2087 3 : if (!slist) {
2088 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not build curl_slist");
2089 0 : RETVAL_FALSE;
2090 0 : return 1;
2091 : }
2092 : }
2093 3 : zend_llist_add_element(&ch->to_free.slist, &slist);
2094 :
2095 3 : error = curl_easy_setopt(ch->cp, option, slist);
2096 :
2097 3 : break;
2098 : }
2099 : /* the following options deal with files, therefore open_basedir checks
2100 : * are required.
2101 : */
2102 : case CURLOPT_COOKIEJAR:
2103 : case CURLOPT_SSLCERT:
2104 : case CURLOPT_RANDOM_FILE:
2105 : case CURLOPT_COOKIEFILE: {
2106 : #if LIBCURL_VERSION_NUM < 0x071100
2107 0 : char *copystr = NULL;
2108 : #endif
2109 :
2110 0 : convert_to_string_ex(zvalue);
2111 :
2112 0 : if (php_check_open_basedir(Z_STRVAL_PP(zvalue) TSRMLS_CC)) {
2113 0 : RETVAL_FALSE;
2114 0 : return 1;
2115 : }
2116 :
2117 : #if LIBCURL_VERSION_NUM >= 0x071100
2118 : error = curl_easy_setopt(ch->cp, option, Z_STRVAL_PP(zvalue));
2119 : #else
2120 0 : copystr = estrndup(Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue));
2121 :
2122 0 : error = curl_easy_setopt(ch->cp, option, copystr);
2123 0 : zend_llist_add_element(&ch->to_free.str, ©str);
2124 : #endif
2125 0 : break;
2126 : }
2127 : case CURLINFO_HEADER_OUT:
2128 0 : convert_to_long_ex(zvalue);
2129 0 : if (Z_LVAL_PP(zvalue) == 1) {
2130 0 : curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, curl_debug);
2131 0 : curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, (void *)ch);
2132 0 : curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 1);
2133 : } else {
2134 0 : curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, NULL);
2135 0 : curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, NULL);
2136 0 : curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0);
2137 : }
2138 : break;
2139 : }
2140 :
2141 127 : SAVE_CURL_ERROR(ch, error);
2142 127 : if (error != CURLE_OK) {
2143 0 : return 1;
2144 : } else {
2145 127 : return 0;
2146 : }
2147 : }
2148 : /* }}} */
2149 :
2150 : /* {{{ proto bool curl_setopt(resource ch, int option, mixed value) U
2151 : Set an option for a cURL transfer */
2152 : PHP_FUNCTION(curl_setopt)
2153 132 : {
2154 : zval *zid, **zvalue;
2155 : long options;
2156 : php_curl *ch;
2157 :
2158 132 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlZ", &zid, &options, &zvalue) == FAILURE) {
2159 10 : return;
2160 : }
2161 :
2162 122 : ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
2163 :
2164 122 : if (!_php_curl_setopt(ch, options, zvalue, return_value TSRMLS_CC)) {
2165 119 : RETURN_TRUE;
2166 : } else {
2167 3 : RETURN_FALSE;
2168 : }
2169 : }
2170 : /* }}} */
2171 :
2172 : /* {{{ proto bool curl_setopt_array(resource ch, array options) U
2173 : Set an array of option for a cURL transfer */
2174 : PHP_FUNCTION(curl_setopt_array)
2175 4 : {
2176 : zval *zid, *arr, **entry;
2177 : php_curl *ch;
2178 : ulong option;
2179 : HashPosition pos;
2180 : zstr string_key;
2181 : uint str_key_len;
2182 :
2183 4 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "za", &zid, &arr) == FAILURE) {
2184 0 : return;
2185 : }
2186 :
2187 4 : ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
2188 :
2189 4 : zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
2190 16 : while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **)&entry, &pos) == SUCCESS) {
2191 8 : if (zend_hash_get_current_key_ex(Z_ARRVAL_P(arr), &string_key, &str_key_len, &option, 0, &pos) != HASH_KEY_IS_LONG) {
2192 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array keys must be CURLOPT constants or equivalent integer values");
2193 0 : RETURN_FALSE;
2194 : }
2195 8 : if (_php_curl_setopt(ch, (long) option, entry, return_value TSRMLS_CC)) {
2196 0 : RETURN_FALSE;
2197 : }
2198 8 : zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos);
2199 : }
2200 4 : RETURN_TRUE;
2201 : }
2202 : /* }}} */
2203 :
2204 : /* {{{ _php_curl_cleanup_handle(ch)
2205 : Cleanup an execution phase */
2206 : void _php_curl_cleanup_handle(php_curl *ch)
2207 59 : {
2208 59 : if (ch->handlers->write->buf.len > 0) {
2209 0 : smart_str_free(&ch->handlers->write->buf);
2210 : }
2211 59 : if (ch->header.str_len) {
2212 0 : efree(ch->header.str);
2213 0 : ch->header.str_len = 0;
2214 : }
2215 :
2216 59 : memset(ch->err.str, 0, CURL_ERROR_SIZE + 1);
2217 59 : ch->err.no = 0;
2218 59 : }
2219 : /* }}} */
2220 :
2221 : /* {{{ proto bool curl_exec(resource ch) U
2222 : Perform a cURL session */
2223 : PHP_FUNCTION(curl_exec)
2224 44 : {
2225 : CURLcode error;
2226 : zval *zid;
2227 : php_curl *ch;
2228 :
2229 44 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
2230 0 : return;
2231 : }
2232 :
2233 44 : ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
2234 :
2235 44 : _php_curl_cleanup_handle(ch);
2236 :
2237 44 : error = curl_easy_perform(ch->cp);
2238 44 : SAVE_CURL_ERROR(ch, error);
2239 : /* CURLE_PARTIAL_FILE is returned by HEAD requests */
2240 44 : if (error != CURLE_OK && error != CURLE_PARTIAL_FILE) {
2241 11 : if (ch->handlers->write->buf.len > 0) {
2242 0 : smart_str_free(&ch->handlers->write->buf);
2243 : }
2244 11 : RETURN_FALSE;
2245 : }
2246 :
2247 33 : if (ch->handlers->write->method == PHP_CURL_RETURN && ch->handlers->write->buf.len > 0) {
2248 20 : smart_str_0(&ch->handlers->write->buf);
2249 20 : RETURN_STRINGL(ch->handlers->write->buf.c, ch->handlers->write->buf.len, 1);
2250 : }
2251 :
2252 : /* flush the file handle, so any remaining data is synched to disk */
2253 13 : if (ch->handlers->write->method == PHP_CURL_FILE && ch->handlers->write->fp) {
2254 2 : fflush(ch->handlers->write->fp);
2255 : }
2256 13 : if (ch->handlers->write_header->method == PHP_CURL_FILE && ch->handlers->write_header->fp) {
2257 0 : fflush(ch->handlers->write_header->fp);
2258 : }
2259 :
2260 13 : if (ch->handlers->write->method == PHP_CURL_RETURN) {
2261 0 : RETURN_EMPTY_STRING();
2262 : } else {
2263 13 : RETURN_TRUE;
2264 : }
2265 : }
2266 : /* }}} */
2267 :
2268 : /* {{{ proto mixed curl_getinfo(resource ch [, int option]) U
2269 : Get information regarding a specific transfer */
2270 : PHP_FUNCTION(curl_getinfo)
2271 18 : {
2272 : zval *zid;
2273 : php_curl *ch;
2274 18 : long option = 0;
2275 :
2276 18 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zid, &option) == FAILURE) {
2277 0 : return;
2278 : }
2279 :
2280 18 : ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
2281 :
2282 18 : if (ZEND_NUM_ARGS() < 2) {
2283 : char *s_code;
2284 : long l_code;
2285 : double d_code;
2286 : #if LIBCURL_VERSION_NUM > 0x071301
2287 : struct curl_certinfo *ci = NULL;
2288 : zval *listcode;
2289 : #endif
2290 :
2291 14 : array_init(return_value);
2292 :
2293 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_EFFECTIVE_URL, &s_code) == CURLE_OK) {
2294 14 : CAAS("url", s_code);
2295 : }
2296 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_TYPE, &s_code) == CURLE_OK) {
2297 14 : if (s_code != NULL) {
2298 0 : CAAS("content_type", s_code);
2299 : } else {
2300 : zval *retnull;
2301 14 : MAKE_STD_ZVAL(retnull);
2302 14 : ZVAL_NULL(retnull);
2303 14 : CAAZ("content_type", retnull);
2304 : }
2305 : }
2306 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_HTTP_CODE, &l_code) == CURLE_OK) {
2307 14 : CAAL("http_code", l_code);
2308 : }
2309 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_HEADER_SIZE, &l_code) == CURLE_OK) {
2310 14 : CAAL("header_size", l_code);
2311 : }
2312 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_REQUEST_SIZE, &l_code) == CURLE_OK) {
2313 14 : CAAL("request_size", l_code);
2314 : }
2315 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_FILETIME, &l_code) == CURLE_OK) {
2316 14 : CAAL("filetime", l_code);
2317 : }
2318 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_SSL_VERIFYRESULT, &l_code) == CURLE_OK) {
2319 14 : CAAL("ssl_verify_result", l_code);
2320 : }
2321 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_COUNT, &l_code) == CURLE_OK) {
2322 14 : CAAL("redirect_count", l_code);
2323 : }
2324 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME, &d_code) == CURLE_OK) {
2325 14 : CAAD("total_time", d_code);
2326 : }
2327 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_NAMELOOKUP_TIME, &d_code) == CURLE_OK) {
2328 14 : CAAD("namelookup_time", d_code);
2329 : }
2330 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_CONNECT_TIME, &d_code) == CURLE_OK) {
2331 14 : CAAD("connect_time", d_code);
2332 : }
2333 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_PRETRANSFER_TIME, &d_code) == CURLE_OK) {
2334 14 : CAAD("pretransfer_time", d_code);
2335 : }
2336 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_UPLOAD, &d_code) == CURLE_OK) {
2337 14 : CAAD("size_upload", d_code);
2338 : }
2339 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_DOWNLOAD, &d_code) == CURLE_OK) {
2340 14 : CAAD("size_download", d_code);
2341 : }
2342 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_DOWNLOAD, &d_code) == CURLE_OK) {
2343 14 : CAAD("speed_download", d_code);
2344 : }
2345 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_UPLOAD, &d_code) == CURLE_OK) {
2346 14 : CAAD("speed_upload", d_code);
2347 : }
2348 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d_code) == CURLE_OK) {
2349 14 : CAAD("download_content_length", d_code);
2350 : }
2351 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_UPLOAD, &d_code) == CURLE_OK) {
2352 14 : CAAD("upload_content_length", d_code);
2353 : }
2354 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_STARTTRANSFER_TIME, &d_code) == CURLE_OK) {
2355 14 : CAAD("starttransfer_time", d_code);
2356 : }
2357 14 : if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME, &d_code) == CURLE_OK) {
2358 14 : CAAD("redirect_time", d_code);
2359 : }
2360 : #if LIBCURL_VERSION_NUM > 0x071301
2361 : if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
2362 : MAKE_STD_ZVAL(listcode);
2363 : array_init(listcode);
2364 : create_certinfo(ci, listcode TSRMLS_CC);
2365 : CAAZ("certinfo", listcode);
2366 : }
2367 : #endif
2368 14 : if (ch->header.str_len > 0) {
2369 0 : CAAS("request_header", ch->header.str);
2370 : }
2371 : } else {
2372 4 : switch (option) {
2373 : case CURLINFO_PRIVATE:
2374 : case CURLINFO_EFFECTIVE_URL:
2375 : case CURLINFO_CONTENT_TYPE: {
2376 3 : char *s_code = NULL;
2377 :
2378 3 : if (curl_easy_getinfo(ch->cp, option, &s_code) == CURLE_OK && s_code) {
2379 3 : RETURN_ASCII_STRING(s_code, 1);
2380 : } else {
2381 0 : RETURN_FALSE;
2382 : }
2383 : break;
2384 : }
2385 : case CURLINFO_HTTP_CODE:
2386 : case CURLINFO_HEADER_SIZE:
2387 : case CURLINFO_REQUEST_SIZE:
2388 : case CURLINFO_FILETIME:
2389 : case CURLINFO_SSL_VERIFYRESULT:
2390 : case CURLINFO_REDIRECT_COUNT: {
2391 1 : long code = 0;
2392 :
2393 1 : if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) {
2394 1 : RETURN_LONG(code);
2395 : } else {
2396 0 : RETURN_FALSE;
2397 : }
2398 : break;
2399 : }
2400 : case CURLINFO_TOTAL_TIME:
2401 : case CURLINFO_NAMELOOKUP_TIME:
2402 : case CURLINFO_CONNECT_TIME:
2403 : case CURLINFO_PRETRANSFER_TIME:
2404 : case CURLINFO_SIZE_UPLOAD:
2405 : case CURLINFO_SIZE_DOWNLOAD:
2406 : case CURLINFO_SPEED_DOWNLOAD:
2407 : case CURLINFO_SPEED_UPLOAD:
2408 : case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
2409 : case CURLINFO_CONTENT_LENGTH_UPLOAD:
2410 : case CURLINFO_STARTTRANSFER_TIME:
2411 : case CURLINFO_REDIRECT_TIME: {
2412 0 : double code = 0.0;
2413 :
2414 0 : if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) {
2415 0 : RETURN_DOUBLE(code);
2416 : } else {
2417 0 : RETURN_FALSE;
2418 : }
2419 : break;
2420 : }
2421 : case CURLINFO_HEADER_OUT:
2422 0 : if (ch->header.str_len > 0) {
2423 0 : RETURN_STRINGL(ch->header.str, ch->header.str_len, 1);
2424 : } else {
2425 0 : RETURN_FALSE;
2426 : }
2427 : #if LIBCURL_VERSION_NUM > 0x071301
2428 : case CURLINFO_CERTINFO: {
2429 : struct curl_certinfo *ci = NULL;
2430 :
2431 : array_init(return_value);
2432 :
2433 : if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
2434 : create_certinfo(ci, return_value TSRMLS_CC);
2435 : } else {
2436 : RETURN_FALSE;
2437 : }
2438 : break;
2439 : }
2440 : #endif
2441 : }
2442 : }
2443 : }
2444 : /* }}} */
2445 :
2446 : /* {{{ proto string curl_error(resource ch) U
2447 : Return a string contain the last error for the current session */
2448 : PHP_FUNCTION(curl_error)
2449 5 : {
2450 : zval *zid;
2451 : php_curl *ch;
2452 :
2453 5 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
2454 0 : return;
2455 : }
2456 :
2457 5 : ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
2458 :
2459 5 : ch->err.str[CURL_ERROR_SIZE] = 0;
2460 5 : RETURN_ASCII_STRING(ch->err.str, 1);
2461 : }
2462 : /* }}} */
2463 :
2464 : /* {{{ proto int curl_errno(resource ch) U
2465 : Return an integer containing the last error number */
2466 : PHP_FUNCTION(curl_errno)
2467 4 : {
2468 : zval *zid;
2469 : php_curl *ch;
2470 :
2471 4 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
2472 0 : return;
2473 : }
2474 :
2475 4 : ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
2476 :
2477 4 : RETURN_LONG(ch->err.no);
2478 : }
2479 : /* }}} */
2480 :
2481 : /* {{{ proto void curl_close(resource ch) U
2482 : Close a cURL session */
2483 : PHP_FUNCTION(curl_close)
2484 46 : {
2485 : zval *zid;
2486 : php_curl *ch;
2487 :
2488 46 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zid) == FAILURE) {
2489 0 : return;
2490 : }
2491 :
2492 46 : ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
2493 :
2494 46 : if (ch->in_callback) {
2495 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to close cURL handle from a callback");
2496 0 : return;
2497 : }
2498 :
2499 46 : if (ch->uses) {
2500 0 : ch->uses--;
2501 : } else {
2502 46 : zend_list_delete(Z_LVAL_P(zid));
2503 : }
2504 : }
2505 : /* }}} */
2506 :
2507 : /* {{{ _php_curl_close()
2508 : List destructor for curl handles */
2509 : static void _php_curl_close_ex(php_curl *ch TSRMLS_DC)
2510 75 : {
2511 : #if PHP_CURL_DEBUG
2512 : fprintf(stderr, "DTOR CALLED, ch = %x\n", ch);
2513 : #endif
2514 :
2515 : /* Prevent crash inside cURL if passed file has already been closed */
2516 75 : if (ch->handlers->std_err && Z_REFCOUNT_P(ch->handlers->std_err) <= 0) {
2517 0 : curl_easy_setopt(ch->cp, CURLOPT_STDERR, stderr);
2518 : }
2519 :
2520 75 : curl_easy_cleanup(ch->cp);
2521 : #if LIBCURL_VERSION_NUM < 0x071101
2522 75 : zend_llist_clean(&ch->to_free.str);
2523 : #endif
2524 :
2525 : /* cURL destructors should be invoked only by last curl handle */
2526 75 : if (Z_REFCOUNT_P(ch->clone) <= 1) {
2527 66 : zend_llist_clean(&ch->to_free.slist);
2528 66 : zend_llist_clean(&ch->to_free.post);
2529 66 : FREE_ZVAL(ch->clone);
2530 : } else {
2531 9 : Z_DELREF_P(ch->clone);
2532 9 : ch->to_free.slist.dtor = NULL;
2533 9 : ch->to_free.post.dtor = NULL;
2534 9 : zend_llist_clean(&ch->to_free.slist);
2535 9 : zend_llist_clean(&ch->to_free.post);
2536 : }
2537 :
2538 75 : if (ch->handlers->write->buf.len > 0) {
2539 32 : smart_str_free(&ch->handlers->write->buf);
2540 : }
2541 75 : if (ch->handlers->write->func_name) {
2542 2 : zval_ptr_dtor(&ch->handlers->write->func_name);
2543 : }
2544 75 : if (ch->handlers->read->func_name) {
2545 1 : zval_ptr_dtor(&ch->handlers->read->func_name);
2546 : }
2547 75 : if (ch->handlers->write_header->func_name) {
2548 1 : zval_ptr_dtor(&ch->handlers->write_header->func_name);
2549 : }
2550 75 : if (ch->handlers->progress->func_name) {
2551 0 : zval_ptr_dtor(&ch->handlers->progress->func_name);
2552 : }
2553 75 : if (ch->handlers->passwd) {
2554 0 : zval_ptr_dtor(&ch->handlers->passwd);
2555 : }
2556 75 : if (ch->handlers->std_err) {
2557 2 : zval_ptr_dtor(&ch->handlers->std_err);
2558 : }
2559 75 : if (ch->header.str_len > 0) {
2560 0 : efree(ch->header.str);
2561 : }
2562 :
2563 75 : if (ch->handlers->write_header->stream) {
2564 0 : zval_ptr_dtor(&ch->handlers->write_header->stream);
2565 : }
2566 75 : if (ch->handlers->write->stream) {
2567 2 : zval_ptr_dtor(&ch->handlers->write->stream);
2568 : }
2569 75 : if (ch->handlers->read->stream) {
2570 2 : zval_ptr_dtor(&ch->handlers->read->stream);
2571 : }
2572 :
2573 75 : efree(ch->handlers->write);
2574 75 : efree(ch->handlers->write_header);
2575 75 : efree(ch->handlers->read);
2576 75 : efree(ch->handlers->progress);
2577 75 : efree(ch->handlers);
2578 75 : efree(ch);
2579 75 : }
2580 : /* }}} */
2581 :
2582 : /* {{{ _php_curl_close()
2583 : List destructor for curl handles */
2584 : static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC)
2585 75 : {
2586 75 : php_curl *ch = (php_curl *) rsrc->ptr;
2587 75 : _php_curl_close_ex(ch TSRMLS_CC);
2588 75 : }
2589 : /* }}} */
2590 :
2591 : #endif /* HAVE_CURL */
2592 :
2593 : /*
2594 : * Local variables:
2595 : * tab-width: 4
2596 : * c-basic-offset: 4
2597 : * End:
2598 : * vim600: fdm=marker
2599 : * vim: noet sw=4 ts=4
2600 : */
|