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