2000-07-17 03:37:33 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| PHP version 4.0 |
|
|
|
|
+----------------------------------------------------------------------+
|
2001-02-26 14:11:02 +08:00
|
|
|
| Copyright (c) 1997-2001 The PHP Group |
|
2000-07-17 03:37:33 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
|
|
|
| http://www.php.net/license/2_02.txt. |
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
2001-02-16 00:20:13 +08:00
|
|
|
| Author: Sterling Hughes <sterling@php.net> |
|
2000-07-17 03:37:33 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2001-05-24 18:07:29 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2000-07-17 03:37:33 +08:00
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
|
|
|
|
#if HAVE_CURL
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2000-09-30 11:09:54 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2000-08-16 00:50:14 +08:00
|
|
|
#ifdef PHP_WIN32
|
|
|
|
#include <winsock.h>
|
2000-08-20 16:28:00 +08:00
|
|
|
#include <sys/types.h>
|
2000-08-16 00:50:14 +08:00
|
|
|
#endif
|
2000-09-30 11:09:54 +08:00
|
|
|
|
2000-07-17 03:37:33 +08:00
|
|
|
#include <curl/curl.h>
|
|
|
|
#include <curl/easy.h>
|
2000-09-30 11:09:54 +08:00
|
|
|
|
2001-08-03 03:28:33 +08:00
|
|
|
#define SMART_STR_PREALLOC 4096
|
|
|
|
|
|
|
|
#include "ext/standard/php_smart_str.h"
|
2000-07-17 03:37:33 +08:00
|
|
|
#include "ext/standard/info.h"
|
2000-11-23 23:57:24 +08:00
|
|
|
#include "ext/standard/file.h"
|
2000-07-17 03:37:33 +08:00
|
|
|
#include "php_curl.h"
|
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
static int le_curl;
|
2001-05-27 09:16:45 +08:00
|
|
|
#define le_curl_name "cURL handle"
|
2000-10-20 12:57:14 +08:00
|
|
|
|
2001-07-31 13:44:11 +08:00
|
|
|
static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC);
|
2001-04-30 22:36:19 +08:00
|
|
|
|
|
|
|
#define SAVE_CURL_ERROR(__handle, __err) (__handle)->err.no = (int) __err;
|
2000-09-30 11:09:54 +08:00
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ curl_functions[]
|
|
|
|
*/
|
2000-07-17 03:37:33 +08:00
|
|
|
function_entry curl_functions[] = {
|
2000-08-14 03:32:09 +08:00
|
|
|
PHP_FE(curl_init, NULL)
|
|
|
|
PHP_FE(curl_version, NULL)
|
|
|
|
PHP_FE(curl_setopt, NULL)
|
|
|
|
PHP_FE(curl_exec, NULL)
|
2000-10-20 12:57:14 +08:00
|
|
|
PHP_FE(curl_getinfo, NULL)
|
2000-09-30 11:09:54 +08:00
|
|
|
PHP_FE(curl_error, NULL)
|
|
|
|
PHP_FE(curl_errno, NULL)
|
2000-08-14 03:32:09 +08:00
|
|
|
PHP_FE(curl_close, NULL)
|
2000-07-17 03:37:33 +08:00
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
2000-07-17 03:37:33 +08:00
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ curl_module_entry
|
|
|
|
*/
|
2000-07-17 03:37:33 +08:00
|
|
|
zend_module_entry curl_module_entry = {
|
2001-10-12 07:33:59 +08:00
|
|
|
STANDARD_MODULE_HEADER,
|
2000-07-17 03:37:33 +08:00
|
|
|
"curl",
|
|
|
|
curl_functions,
|
|
|
|
PHP_MINIT(curl),
|
2001-09-22 08:38:59 +08:00
|
|
|
PHP_MSHUTDOWN(curl),
|
2000-08-17 10:14:41 +08:00
|
|
|
NULL,
|
2000-07-17 03:37:33 +08:00
|
|
|
NULL,
|
|
|
|
PHP_MINFO(curl),
|
2001-10-12 07:33:59 +08:00
|
|
|
NO_VERSION_YET,
|
2000-07-17 03:37:33 +08:00
|
|
|
STANDARD_MODULE_PROPERTIES
|
|
|
|
};
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
2000-07-17 03:37:33 +08:00
|
|
|
|
|
|
|
#ifdef COMPILE_DL_CURL
|
|
|
|
ZEND_GET_MODULE (curl)
|
|
|
|
#endif
|
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ PHP_MINFO_FUNCTION
|
|
|
|
*/
|
2000-07-17 03:37:33 +08:00
|
|
|
PHP_MINFO_FUNCTION(curl)
|
|
|
|
{
|
2000-08-14 03:32:09 +08:00
|
|
|
php_info_print_table_start();
|
2001-03-21 05:30:42 +08:00
|
|
|
php_info_print_table_row(2, "CURL support", "enabled");
|
2000-08-14 03:32:09 +08:00
|
|
|
php_info_print_table_row(2, "CURL Information", curl_version());
|
|
|
|
php_info_print_table_end();
|
2000-07-17 03:37:33 +08:00
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
2000-07-17 03:37:33 +08:00
|
|
|
|
2001-09-22 08:38:59 +08:00
|
|
|
#define REGISTER_CURL_CONSTANT(__c) REGISTER_LONG_CONSTANT(#__c, __c, CONST_CS | CONST_PERSISTENT)
|
2001-04-30 22:36:19 +08:00
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ PHP_MINIT_FUNCTION
|
|
|
|
*/
|
2000-07-17 03:37:33 +08:00
|
|
|
PHP_MINIT_FUNCTION(curl)
|
|
|
|
{
|
2000-10-26 01:44:02 +08:00
|
|
|
le_curl = zend_register_list_destructors_ex(_php_curl_close, NULL, "curl", module_number);
|
2000-08-16 00:50:14 +08:00
|
|
|
|
|
|
|
/* Constants for curl_setopt() */
|
2001-09-22 08:38:59 +08:00
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_PORT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_FILE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_INFILE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_INFILESIZE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_URL);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_PROXY);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_VERBOSE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_HEADER);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_HTTPHEADER);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_NOPROGRESS);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_NOBODY);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_FAILONERROR);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_UPLOAD);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_POST);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_FTPLISTONLY);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_FTPAPPEND);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_NETRC);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_FOLLOWLOCATION);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_FTPASCII);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_PUT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_MUTE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_USERPWD);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_PROXYUSERPWD);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_RANGE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_POSTFIELDS);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_REFERER);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_USERAGENT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_FTPPORT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_LIMIT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_TIME);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_RESUME_FROM);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_COOKIE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_SSLCERT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTPASSWD);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_WRITEHEADER);
|
2001-11-13 09:01:47 +08:00
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYHOST);
|
2001-09-22 08:38:59 +08:00
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_COOKIEFILE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_SSLVERSION);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_TIMECONDITION);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_TIMEVALUE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_CUSTOMREQUEST);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_STDERR);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_TRANSFERTEXT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_RETURNTRANSFER);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_QUOTE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_POSTQUOTE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_INTERFACE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_KRB4LEVEL);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_HTTPPROXYTUNNEL);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_FILETIME);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_WRITEFUNCTION);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_READFUNCTION);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_PASSWDFUNCTION);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_HEADERFUNCTION);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_MAXREDIRS);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_MAXCONNECTS);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_CLOSEPOLICY);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_FRESH_CONNECT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_FORBID_REUSE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_RANDOM_FILE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_EGDSOCKET);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYPEER);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_CAINFO);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_COOKIEJAR);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_SSL_CIPHER_LIST);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLOPT_BINARYTRANSFER);
|
2001-05-15 05:02:31 +08:00
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
/* Constants effecting the way CURLOPT_CLOSEPOLICY works */
|
2001-09-22 08:38:59 +08:00
|
|
|
REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_LEAST_RECENTLY_USED);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_LEAST_TRAFFIC);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_SLOWEST);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_CALLBACK);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_OLDEST);
|
2000-10-20 12:57:14 +08:00
|
|
|
|
|
|
|
/* Info constants */
|
2001-09-22 08:38:59 +08:00
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_EFFECTIVE_URL);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_HTTP_CODE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_HEADER_SIZE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_REQUEST_SIZE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_TOTAL_TIME);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_NAMELOOKUP_TIME);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_CONNECT_TIME);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_PRETRANSFER_TIME);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_SIZE_UPLOAD);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_SIZE_DOWNLOAD);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_SPEED_DOWNLOAD);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_SPEED_UPLOAD);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_FILETIME);
|
2001-09-25 02:45:08 +08:00
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_SSL_VERIFYRESULT);
|
2001-09-22 08:38:59 +08:00
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_DOWNLOAD);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_UPLOAD);
|
2000-10-20 12:57:14 +08:00
|
|
|
|
2000-08-16 00:50:14 +08:00
|
|
|
/* Error Constants */
|
2001-09-22 08:38:59 +08:00
|
|
|
REGISTER_CURL_CONSTANT(CURLE_OK);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_UNSUPPORTED_PROTOCOL);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FAILED_INIT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT_USER);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_PROXY);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_HOST);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_COULDNT_CONNECT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_SERVER_REPLY);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_ACCESS_DENIED);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_USER_PASSWORD_INCORRECT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASS_REPLY);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_USER_REPLY);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASV_REPLY);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_227_FORMAT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_GET_HOST);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_RECONNECT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_BINARY);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_PARTIAL_FILE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_RETR_FILE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_WRITE_ERROR);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_QUOTE_ERROR);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_HTTP_NOT_FOUND);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_WRITE_ERROR);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_MALFORMAT_USER);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_STOR_FILE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_READ_ERROR);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_OUT_OF_MEMORY);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_OPERATION_TIMEOUTED);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_ASCII);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_PORT_FAILED);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_USE_REST);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_GET_SIZE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_HTTP_RANGE_ERROR);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_HTTP_POST_ERROR);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_SSL_CONNECT_ERROR);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FTP_BAD_DOWNLOAD_RESUME);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FILE_COULDNT_READ_FILE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_LDAP_CANNOT_BIND);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_LDAP_SEARCH_FAILED);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_LIBRARY_NOT_FOUND);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_FUNCTION_NOT_FOUND);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_ABORTED_BY_CALLBACK);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_BAD_FUNCTION_ARGUMENT);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_BAD_CALLING_ORDER);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_HTTP_PORT_FAILED);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_BAD_PASSWORD_ENTERED);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_TOO_MANY_REDIRECTS);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_UNKNOWN_TELNET_OPTION);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_TELNET_OPTION_SYNTAX);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_OBSOLETE);
|
|
|
|
REGISTER_CURL_CONSTANT(CURLE_SSL_PEER_CERTIFICATE);
|
|
|
|
|
2001-11-13 09:01:47 +08:00
|
|
|
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
|
2001-09-22 08:38:59 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ PHP_MSHUTDOWN_FUNCTION
|
|
|
|
*/
|
|
|
|
PHP_MSHUTDOWN_FUNCTION(curl)
|
|
|
|
{
|
|
|
|
curl_global_cleanup();
|
2001-04-30 22:36:19 +08:00
|
|
|
|
2000-10-23 01:29:33 +08:00
|
|
|
return SUCCESS;
|
2000-08-16 00:50:14 +08:00
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
2000-08-16 00:50:14 +08:00
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
#define PHP_CURL_STDOUT 0
|
|
|
|
#define PHP_CURL_FILE 1
|
|
|
|
#define PHP_CURL_USER 2
|
|
|
|
#define PHP_CURL_DIRECT 3
|
|
|
|
#define PHP_CURL_RETURN 4
|
2001-05-15 05:02:31 +08:00
|
|
|
#define PHP_CURL_ASCII 5
|
|
|
|
#define PHP_CURL_BINARY 6
|
2001-07-18 18:47:54 +08:00
|
|
|
#define PHP_CURL_IGNORE 7
|
2001-04-30 22:36:19 +08:00
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ curl_write
|
|
|
|
*/
|
2001-10-19 03:24:51 +08:00
|
|
|
static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx)
|
2001-04-30 22:36:19 +08:00
|
|
|
{
|
|
|
|
php_curl *ch = (php_curl *) ctx;
|
2001-05-04 12:20:38 +08:00
|
|
|
php_curl_write *t = ch->handlers->write;
|
2001-04-30 22:36:19 +08:00
|
|
|
size_t length = size * nmemb;
|
2001-10-19 03:24:51 +08:00
|
|
|
TSRMLS_FETCH();
|
2001-04-30 22:36:19 +08:00
|
|
|
|
|
|
|
switch (t->method) {
|
2001-05-28 03:11:09 +08:00
|
|
|
case PHP_CURL_STDOUT:
|
|
|
|
PUTS(data);
|
|
|
|
break;
|
2001-04-30 22:36:19 +08:00
|
|
|
case PHP_CURL_FILE:
|
2001-05-04 12:20:38 +08:00
|
|
|
return fwrite(data, size, nmemb, t->fp);
|
2001-04-30 22:36:19 +08:00
|
|
|
case PHP_CURL_RETURN:
|
|
|
|
smart_str_appendl(&t->buf, data, (int) length);
|
|
|
|
break;
|
|
|
|
case PHP_CURL_USER: {
|
|
|
|
zval *argv[2];
|
|
|
|
zval *retval;
|
|
|
|
int error;
|
2001-09-22 08:38:59 +08:00
|
|
|
TSRMLS_FETCH();
|
2001-04-30 22:36:19 +08:00
|
|
|
|
|
|
|
MAKE_STD_ZVAL(argv[0]);
|
|
|
|
MAKE_STD_ZVAL(argv[1]);
|
|
|
|
MAKE_STD_ZVAL(retval);
|
|
|
|
|
|
|
|
ZVAL_RESOURCE(argv[0], ch->id);
|
|
|
|
zend_list_addref(ch->id);
|
|
|
|
ZVAL_STRINGL(argv[1], data, (int) length, 1);
|
|
|
|
|
|
|
|
error = call_user_function(EG(function_table),
|
|
|
|
NULL,
|
|
|
|
t->func,
|
2001-07-30 16:24:42 +08:00
|
|
|
retval, 2, argv TSRMLS_CC);
|
2001-04-30 22:36:19 +08:00
|
|
|
if (error == FAILURE) {
|
2001-09-08 08:42:25 +08:00
|
|
|
php_error(E_WARNING, "Couldn't call the CURLOPT_WRITEFUNCTION");
|
2001-06-25 23:14:20 +08:00
|
|
|
length = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
length = Z_LVAL_P(retval);
|
2001-04-30 22:36:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
zval_ptr_dtor(&argv[0]);
|
|
|
|
zval_ptr_dtor(&argv[1]);
|
|
|
|
zval_ptr_dtor(&retval);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
2001-04-30 22:36:19 +08:00
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ curl_read
|
|
|
|
*/
|
2001-05-04 12:20:38 +08:00
|
|
|
static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx)
|
2001-04-30 22:36:19 +08:00
|
|
|
{
|
|
|
|
php_curl *ch = (php_curl *) ctx;
|
2001-05-04 12:20:38 +08:00
|
|
|
php_curl_read *t = ch->handlers->read;
|
2001-04-30 22:36:19 +08:00
|
|
|
int length = -1;
|
|
|
|
|
|
|
|
switch (t->method) {
|
|
|
|
case PHP_CURL_DIRECT:
|
2001-05-04 12:20:38 +08:00
|
|
|
length = fread(data, size, nmemb, t->fp);
|
2001-07-14 00:44:44 +08:00
|
|
|
break;
|
2001-04-30 22:36:19 +08:00
|
|
|
case PHP_CURL_USER: {
|
|
|
|
zval *argv[3];
|
|
|
|
zval *retval;
|
|
|
|
int length;
|
|
|
|
int error;
|
2001-09-22 08:38:59 +08:00
|
|
|
TSRMLS_FETCH();
|
2001-04-30 22:36:19 +08:00
|
|
|
|
|
|
|
MAKE_STD_ZVAL(argv[0]);
|
|
|
|
MAKE_STD_ZVAL(argv[1]);
|
|
|
|
MAKE_STD_ZVAL(argv[2]);
|
|
|
|
MAKE_STD_ZVAL(retval);
|
|
|
|
|
|
|
|
ZVAL_RESOURCE(argv[0], ch->id);
|
|
|
|
zend_list_addref(ch->id);
|
|
|
|
ZVAL_RESOURCE(argv[1], t->fd);
|
|
|
|
zend_list_addref(t->fd);
|
|
|
|
ZVAL_LONG(argv[2], size * nmemb);
|
|
|
|
|
|
|
|
error = call_user_function(EG(function_table),
|
|
|
|
NULL,
|
|
|
|
t->func,
|
2001-07-30 16:24:42 +08:00
|
|
|
retval, 3, argv TSRMLS_CC);
|
2001-04-30 22:36:19 +08:00
|
|
|
if (error == FAILURE) {
|
|
|
|
php_error(E_WARNING, "Cannot call the CURLOPT_READFUNCTION");
|
2001-06-25 23:14:20 +08:00
|
|
|
length = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
memcpy(data, Z_STRVAL_P(retval), size * nmemb);
|
|
|
|
length = Z_STRLEN_P(retval);
|
2001-04-30 22:36:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
zval_ptr_dtor(&argv[0]);
|
|
|
|
zval_ptr_dtor(&argv[1]);
|
|
|
|
zval_ptr_dtor(&argv[2]);
|
|
|
|
zval_ptr_dtor(&retval);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
2001-04-30 22:36:19 +08:00
|
|
|
|
2001-06-25 23:14:20 +08:00
|
|
|
/* {{{ curl_write_header
|
2001-06-05 21:12:10 +08:00
|
|
|
*/
|
2001-10-19 03:24:51 +08:00
|
|
|
static size_t curl_write_header(char *data, size_t size, size_t nmemb, void *ctx)
|
2001-04-30 22:36:19 +08:00
|
|
|
{
|
2001-06-25 23:14:20 +08:00
|
|
|
php_curl *ch = (php_curl *) ctx;
|
|
|
|
php_curl_write *t = ch->handlers->write_header;
|
|
|
|
int error;
|
|
|
|
int length;
|
2001-10-19 03:24:51 +08:00
|
|
|
TSRMLS_FETCH();
|
2001-06-25 23:14:20 +08:00
|
|
|
|
|
|
|
switch (t->method) {
|
|
|
|
case PHP_CURL_STDOUT:
|
|
|
|
/* Handle special case write when we're returning the entire transfer
|
|
|
|
*/
|
|
|
|
if (ch->handlers->write->method == PHP_CURL_RETURN)
|
|
|
|
smart_str_appendl(&ch->handlers->write->buf, data, size * nmemb);
|
|
|
|
else
|
|
|
|
PUTS(data);
|
2001-07-12 02:10:52 +08:00
|
|
|
|
|
|
|
length = size * nmemb;
|
|
|
|
|
2001-06-25 23:14:20 +08:00
|
|
|
break;
|
|
|
|
case PHP_CURL_FILE:
|
|
|
|
length = fwrite(data, size, nmemb, t->fp);
|
|
|
|
break;
|
|
|
|
case PHP_CURL_USER: {
|
|
|
|
zval *argv[2];
|
|
|
|
zval *retval;
|
2001-09-22 08:38:59 +08:00
|
|
|
TSRMLS_FETCH();
|
2001-06-25 23:14:20 +08:00
|
|
|
|
|
|
|
MAKE_STD_ZVAL(argv[0]);
|
|
|
|
MAKE_STD_ZVAL(argv[1]);
|
|
|
|
MAKE_STD_ZVAL(retval);
|
2001-04-30 22:36:19 +08:00
|
|
|
|
2001-06-25 23:14:20 +08:00
|
|
|
ZVAL_RESOURCE(argv[0], ch->id);
|
|
|
|
zend_list_addref(ch->id);
|
|
|
|
ZVAL_STRINGL(argv[0], data, size * nmemb, 1);
|
2001-04-30 22:36:19 +08:00
|
|
|
|
2001-06-25 23:14:20 +08:00
|
|
|
error = call_user_function(EG(function_table),
|
|
|
|
NULL,
|
|
|
|
t->func,
|
2001-07-30 16:24:42 +08:00
|
|
|
retval, 2, argv TSRMLS_CC);
|
2001-06-25 23:14:20 +08:00
|
|
|
if (error == FAILURE) {
|
|
|
|
php_error(E_WARNING, "Couldn't call the CURLOPT_HEADERFUNCTION");
|
|
|
|
length = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
length = Z_LVAL_P(retval);
|
|
|
|
}
|
2001-04-30 22:36:19 +08:00
|
|
|
|
2001-06-25 23:14:20 +08:00
|
|
|
zval_ptr_dtor(&argv[0]);
|
|
|
|
zval_ptr_dtor(&argv[1]);
|
|
|
|
zval_ptr_dtor(&retval);
|
|
|
|
break;
|
2001-04-30 22:36:19 +08:00
|
|
|
}
|
2001-07-18 18:47:54 +08:00
|
|
|
case PHP_CURL_IGNORE:
|
|
|
|
length = size * nmemb;
|
|
|
|
break;
|
2001-06-25 23:14:20 +08:00
|
|
|
}
|
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
return length;
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
2001-04-30 22:36:19 +08:00
|
|
|
|
2001-06-25 23:14:20 +08:00
|
|
|
/* {{{ curl_passwd
|
2001-06-05 21:12:10 +08:00
|
|
|
*/
|
2001-06-25 23:14:20 +08:00
|
|
|
static size_t curl_passwd(void *ctx, char *prompt, char *buf, int buflen)
|
2001-04-30 22:36:19 +08:00
|
|
|
{
|
|
|
|
php_curl *ch = (php_curl *) ctx;
|
|
|
|
zval *func = ch->handlers->passwd;
|
|
|
|
zval *argv[3];
|
2001-10-19 01:46:57 +08:00
|
|
|
zval *retval = NULL;
|
2001-04-30 22:36:19 +08:00
|
|
|
int error;
|
2001-06-25 23:14:20 +08:00
|
|
|
int ret = 0;
|
2001-07-27 18:16:41 +08:00
|
|
|
TSRMLS_FETCH();
|
2001-04-30 22:36:19 +08:00
|
|
|
|
|
|
|
MAKE_STD_ZVAL(argv[0]);
|
|
|
|
MAKE_STD_ZVAL(argv[1]);
|
|
|
|
MAKE_STD_ZVAL(argv[2]);
|
|
|
|
|
|
|
|
ZVAL_RESOURCE(argv[0], ch->id);
|
|
|
|
zend_list_addref(ch->id);
|
|
|
|
ZVAL_STRING(argv[1], prompt, 1);
|
|
|
|
ZVAL_LONG(argv[2], buflen);
|
|
|
|
|
|
|
|
error = call_user_function(EG(function_table),
|
|
|
|
NULL,
|
|
|
|
func,
|
2001-07-30 16:24:42 +08:00
|
|
|
retval, 2, argv TSRMLS_CC);
|
2001-04-30 22:36:19 +08:00
|
|
|
if (error == FAILURE) {
|
|
|
|
php_error(E_WARNING, "Couldn't call the CURLOPT_PASSWDFUNCTION");
|
2001-06-25 23:14:20 +08:00
|
|
|
ret = -1;
|
2001-04-30 22:36:19 +08:00
|
|
|
}
|
2001-06-25 23:14:20 +08:00
|
|
|
else {
|
|
|
|
if (Z_STRLEN_P(retval) > buflen) {
|
|
|
|
php_error(E_WARNING, "Returned password is too long for libcurl to handle");
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strlcpy(buf, Z_STRVAL_P(retval), buflen);
|
|
|
|
}
|
2001-04-30 22:36:19 +08:00
|
|
|
}
|
2001-06-25 23:14:20 +08:00
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
zval_ptr_dtor(&argv[0]);
|
|
|
|
zval_ptr_dtor(&argv[1]);
|
|
|
|
zval_ptr_dtor(&argv[2]);
|
|
|
|
zval_ptr_dtor(&retval);
|
|
|
|
|
2001-06-25 23:14:20 +08:00
|
|
|
return ret;
|
2001-04-30 22:36:19 +08:00
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
2001-04-30 22:36:19 +08:00
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ curl_free_string
|
|
|
|
*/
|
2001-04-30 22:36:19 +08:00
|
|
|
static void curl_free_string(void **string)
|
|
|
|
{
|
2000-11-24 00:31:58 +08:00
|
|
|
efree(*string);
|
2001-06-05 21:12:10 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
2000-08-16 00:50:14 +08:00
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ curl_free_post
|
|
|
|
*/
|
2001-04-30 22:36:19 +08:00
|
|
|
static void curl_free_post(void **post)
|
|
|
|
{
|
|
|
|
curl_formfree((struct HttpPost *) *post);
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
2001-04-30 22:36:19 +08:00
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ curl_free_slist
|
|
|
|
*/
|
2001-04-30 22:36:19 +08:00
|
|
|
static void curl_free_slist(void **slist)
|
|
|
|
{
|
|
|
|
curl_slist_free_all((struct curl_slist *) *slist);
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
2001-04-30 22:36:19 +08:00
|
|
|
|
2000-09-30 11:09:54 +08:00
|
|
|
/* {{{ proto string curl_version(void)
|
2000-07-26 06:15:26 +08:00
|
|
|
Return the CURL version string. */
|
2000-10-20 12:57:14 +08:00
|
|
|
PHP_FUNCTION(curl_version)
|
2000-07-26 06:15:26 +08:00
|
|
|
{
|
2001-08-13 15:55:39 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 0) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2001-08-13 14:43:47 +08:00
|
|
|
|
2000-08-28 06:53:33 +08:00
|
|
|
RETURN_STRING(curl_version(), 1);
|
2000-07-26 06:15:26 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ alloc_curl_handle
|
|
|
|
*/
|
2001-05-15 05:02:31 +08:00
|
|
|
static void alloc_curl_handle(php_curl **ch)
|
2001-05-07 06:24:25 +08:00
|
|
|
{
|
|
|
|
*ch = emalloc(sizeof(php_curl));
|
|
|
|
(*ch)->handlers = ecalloc(1, sizeof(php_curl_handlers));
|
|
|
|
(*ch)->handlers->write = ecalloc(1, sizeof(php_curl_write));
|
2001-06-25 23:14:20 +08:00
|
|
|
(*ch)->handlers->write_header = ecalloc(1, sizeof(php_curl_write));
|
2001-05-07 06:24:25 +08:00
|
|
|
(*ch)->handlers->read = ecalloc(1, sizeof(php_curl_read));
|
2001-07-02 20:08:21 +08:00
|
|
|
memset(&(*ch)->err, 0, sizeof((*ch)->err));
|
|
|
|
|
2001-05-07 06:24:25 +08:00
|
|
|
zend_llist_init(&(*ch)->to_free.str, sizeof(char *),
|
|
|
|
(void(*)(void *)) curl_free_string, 0);
|
|
|
|
zend_llist_init(&(*ch)->to_free.slist, sizeof(struct curl_slist),
|
|
|
|
(void(*)(void *)) curl_free_slist, 0);
|
|
|
|
zend_llist_init(&(*ch)->to_free.post, sizeof(struct HttpPost),
|
|
|
|
(void(*)(void *)) curl_free_post, 0);
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
2001-05-07 06:24:25 +08:00
|
|
|
|
2000-09-30 11:09:54 +08:00
|
|
|
/* {{{ proto int curl_init([string url])
|
2000-07-17 03:37:33 +08:00
|
|
|
Initialize a CURL session */
|
2000-08-14 03:32:09 +08:00
|
|
|
PHP_FUNCTION(curl_init)
|
2000-07-17 03:37:33 +08:00
|
|
|
{
|
2001-04-30 22:36:19 +08:00
|
|
|
zval **url;
|
|
|
|
php_curl *ch;
|
|
|
|
int argc = ZEND_NUM_ARGS();
|
|
|
|
|
2000-09-30 11:09:54 +08:00
|
|
|
if (argc < 0 || argc > 1 ||
|
|
|
|
zend_get_parameters_ex(argc, &url) == FAILURE) {
|
2000-07-17 03:37:33 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2000-11-22 23:46:13 +08:00
|
|
|
|
2001-05-15 05:02:31 +08:00
|
|
|
alloc_curl_handle(&ch);
|
2001-04-30 22:36:19 +08:00
|
|
|
|
|
|
|
ch->cp = curl_easy_init();
|
|
|
|
if (! ch->cp) {
|
|
|
|
php_error(E_WARNING, "Cannot initialize a new cURL handle");
|
2000-07-17 03:37:33 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2001-04-30 22:36:19 +08:00
|
|
|
|
2001-05-04 12:20:38 +08:00
|
|
|
ch->handlers->write->method = PHP_CURL_STDOUT;
|
2001-09-27 06:24:44 +08:00
|
|
|
ch->handlers->write->type = PHP_CURL_ASCII;
|
2001-05-04 12:20:38 +08:00
|
|
|
ch->handlers->read->method = PHP_CURL_DIRECT;
|
2001-07-18 18:47:54 +08:00
|
|
|
ch->handlers->write_header->method = PHP_CURL_IGNORE;
|
2001-04-30 22:36:19 +08:00
|
|
|
|
|
|
|
curl_easy_setopt(ch->cp, CURLOPT_NOPROGRESS, 1);
|
|
|
|
curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0);
|
|
|
|
curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER, ch->err.str);
|
|
|
|
curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write);
|
2001-05-04 12:20:38 +08:00
|
|
|
curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch);
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_setopt(ch->cp, CURLOPT_READFUNCTION, curl_read);
|
2001-05-04 12:20:38 +08:00
|
|
|
curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch);
|
2001-06-25 23:14:20 +08:00
|
|
|
curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_header);
|
|
|
|
curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
|
2000-09-30 11:09:54 +08:00
|
|
|
if (argc > 0) {
|
2001-04-30 22:36:19 +08:00
|
|
|
char *urlcopy;
|
2000-09-30 11:09:54 +08:00
|
|
|
convert_to_string_ex(url);
|
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
urlcopy = estrndup(Z_STRVAL_PP(url), Z_STRLEN_PP(url));
|
|
|
|
curl_easy_setopt(ch->cp, CURLOPT_URL, urlcopy);
|
|
|
|
zend_llist_add_element(&ch->to_free.str, &urlcopy);
|
2000-07-17 03:37:33 +08:00
|
|
|
}
|
2000-09-30 11:09:54 +08:00
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
ZEND_REGISTER_RESOURCE(return_value, ch, le_curl);
|
|
|
|
ch->id = Z_LVAL_P(return_value);
|
2000-07-17 03:37:33 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-09-30 11:09:54 +08:00
|
|
|
/* {{{ proto bool curl_setopt(int ch, string option, mixed value)
|
2000-07-17 03:37:33 +08:00
|
|
|
Set an option for a CURL transfer */
|
2000-08-14 03:32:09 +08:00
|
|
|
PHP_FUNCTION(curl_setopt)
|
2000-07-17 03:37:33 +08:00
|
|
|
{
|
2001-04-30 22:36:19 +08:00
|
|
|
zval **zid,
|
|
|
|
**zoption,
|
|
|
|
**zvalue;
|
|
|
|
php_curl *ch;
|
|
|
|
CURLcode error;
|
|
|
|
int option;
|
2000-07-17 03:37:33 +08:00
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() != 3 ||
|
2001-04-30 22:36:19 +08:00
|
|
|
zend_get_parameters_ex(3, &zid, &zoption, &zvalue) == FAILURE) {
|
2000-07-17 03:37:33 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2001-04-30 22:36:19 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
|
|
|
|
convert_to_long_ex(zoption);
|
2000-09-30 11:09:54 +08:00
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
option = Z_LVAL_PP(zoption);
|
|
|
|
switch (option) {
|
|
|
|
case CURLOPT_INFILESIZE:
|
|
|
|
case CURLOPT_VERBOSE:
|
|
|
|
case CURLOPT_HEADER:
|
|
|
|
case CURLOPT_NOPROGRESS:
|
|
|
|
case CURLOPT_NOBODY:
|
|
|
|
case CURLOPT_FAILONERROR:
|
|
|
|
case CURLOPT_UPLOAD:
|
|
|
|
case CURLOPT_POST:
|
|
|
|
case CURLOPT_FTPLISTONLY:
|
|
|
|
case CURLOPT_FTPAPPEND:
|
|
|
|
case CURLOPT_NETRC:
|
|
|
|
case CURLOPT_FOLLOWLOCATION:
|
|
|
|
case CURLOPT_PUT:
|
|
|
|
case CURLOPT_MUTE:
|
|
|
|
case CURLOPT_TIMEOUT:
|
|
|
|
case CURLOPT_LOW_SPEED_LIMIT:
|
|
|
|
case CURLOPT_SSLVERSION:
|
|
|
|
case CURLOPT_LOW_SPEED_TIME:
|
|
|
|
case CURLOPT_RESUME_FROM:
|
|
|
|
case CURLOPT_TIMEVALUE:
|
|
|
|
case CURLOPT_TIMECONDITION:
|
|
|
|
case CURLOPT_TRANSFERTEXT:
|
|
|
|
case CURLOPT_HTTPPROXYTUNNEL:
|
|
|
|
case CURLOPT_FILETIME:
|
|
|
|
case CURLOPT_MAXREDIRS:
|
|
|
|
case CURLOPT_MAXCONNECTS:
|
|
|
|
case CURLOPT_CLOSEPOLICY:
|
|
|
|
case CURLOPT_FRESH_CONNECT:
|
|
|
|
case CURLOPT_FORBID_REUSE:
|
|
|
|
case CURLOPT_CONNECTTIMEOUT:
|
2001-11-13 09:01:47 +08:00
|
|
|
case CURLOPT_SSL_VERIFYHOST:
|
2001-04-30 22:36:19 +08:00
|
|
|
case CURLOPT_SSL_VERIFYPEER:
|
|
|
|
convert_to_long_ex(zvalue);
|
|
|
|
error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue));
|
|
|
|
break;
|
|
|
|
case CURLOPT_URL:
|
|
|
|
case CURLOPT_PROXY:
|
|
|
|
case CURLOPT_USERPWD:
|
|
|
|
case CURLOPT_PROXYUSERPWD:
|
|
|
|
case CURLOPT_RANGE:
|
|
|
|
case CURLOPT_CUSTOMREQUEST:
|
|
|
|
case CURLOPT_USERAGENT:
|
|
|
|
case CURLOPT_FTPPORT:
|
|
|
|
case CURLOPT_COOKIE:
|
|
|
|
case CURLOPT_SSLCERT:
|
|
|
|
case CURLOPT_SSLCERTPASSWD:
|
|
|
|
case CURLOPT_COOKIEFILE:
|
|
|
|
case CURLOPT_REFERER:
|
|
|
|
case CURLOPT_INTERFACE:
|
|
|
|
case CURLOPT_KRB4LEVEL:
|
|
|
|
case CURLOPT_RANDOM_FILE:
|
|
|
|
case CURLOPT_EGDSOCKET:
|
2001-09-22 08:38:59 +08:00
|
|
|
case CURLOPT_CAINFO:
|
|
|
|
case CURLOPT_COOKIEJAR:
|
|
|
|
case CURLOPT_SSL_CIPHER_LIST: {
|
2001-04-30 22:36:19 +08:00
|
|
|
char *copystr = NULL;
|
2000-07-17 03:37:33 +08:00
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
convert_to_string_ex(zvalue);
|
|
|
|
copystr = estrndup(Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue));
|
|
|
|
|
|
|
|
error = curl_easy_setopt(ch->cp, option, copystr);
|
|
|
|
zend_llist_add_element(&ch->to_free.str, ©str);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2001-05-04 12:20:38 +08:00
|
|
|
case CURLOPT_FILE:
|
2001-04-30 22:36:19 +08:00
|
|
|
case CURLOPT_INFILE:
|
|
|
|
case CURLOPT_WRITEHEADER:
|
|
|
|
case CURLOPT_STDERR: {
|
|
|
|
FILE *fp;
|
|
|
|
ZEND_FETCH_RESOURCE(fp, FILE *, zvalue, -1, "File-Handle", php_file_le_fopen());
|
2001-08-24 09:12:37 +08:00
|
|
|
|
2001-06-25 23:14:20 +08:00
|
|
|
error = CURLE_OK;
|
|
|
|
switch (option) {
|
|
|
|
case CURLOPT_FILE:
|
2001-05-04 12:20:38 +08:00
|
|
|
ch->handlers->write->fp = fp;
|
|
|
|
ch->handlers->write->method = PHP_CURL_FILE;
|
2001-06-25 23:14:20 +08:00
|
|
|
break;
|
|
|
|
case CURLOPT_WRITEHEADER:
|
|
|
|
ch->handlers->write_header->fp = fp;
|
|
|
|
ch->handlers->write_header->method = PHP_CURL_FILE;
|
|
|
|
break;
|
|
|
|
case CURLOPT_INFILE:
|
2001-05-04 12:20:38 +08:00
|
|
|
zend_list_addref(Z_LVAL_PP(zvalue));
|
|
|
|
ch->handlers->read->fp = fp;
|
|
|
|
ch->handlers->read->fd = Z_LVAL_PP(zvalue);
|
2001-06-25 23:14:20 +08:00
|
|
|
break;
|
|
|
|
default:
|
2001-05-04 12:20:38 +08:00
|
|
|
error = curl_easy_setopt(ch->cp, option, fp);
|
2001-06-25 23:14:20 +08:00
|
|
|
break;
|
2001-04-30 22:36:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CURLOPT_RETURNTRANSFER:
|
|
|
|
convert_to_long_ex(zvalue);
|
|
|
|
|
|
|
|
if (Z_LVAL_PP(zvalue)) {
|
2001-05-04 12:20:38 +08:00
|
|
|
ch->handlers->write->method = PHP_CURL_RETURN;
|
2001-04-30 22:36:19 +08:00
|
|
|
}
|
|
|
|
break;
|
2001-05-15 05:02:31 +08:00
|
|
|
case CURLOPT_BINARYTRANSFER:
|
2001-07-14 00:44:44 +08:00
|
|
|
convert_to_long_ex(zvalue);
|
2001-09-27 06:24:44 +08:00
|
|
|
ch->handlers->write->type = PHP_CURL_BINARY;
|
2001-07-14 00:44:44 +08:00
|
|
|
break;
|
2001-04-30 22:36:19 +08:00
|
|
|
case CURLOPT_WRITEFUNCTION:
|
|
|
|
zval_add_ref(zvalue);
|
2001-06-25 23:14:20 +08:00
|
|
|
ch->handlers->write->func = *zvalue;
|
2001-05-04 12:20:38 +08:00
|
|
|
ch->handlers->write->method = PHP_CURL_USER;
|
2001-04-30 22:36:19 +08:00
|
|
|
break;
|
|
|
|
case CURLOPT_READFUNCTION:
|
|
|
|
zval_add_ref(zvalue);
|
2001-05-04 12:20:38 +08:00
|
|
|
ch->handlers->read->func = *zvalue;
|
|
|
|
ch->handlers->read->method = PHP_CURL_USER;
|
2001-04-30 22:36:19 +08:00
|
|
|
break;
|
|
|
|
case CURLOPT_HEADERFUNCTION:
|
|
|
|
zval_add_ref(zvalue);
|
2001-06-25 23:14:20 +08:00
|
|
|
ch->handlers->write_header->func = *zvalue;
|
|
|
|
ch->handlers->write_header->method = PHP_CURL_USER;
|
2001-04-30 22:36:19 +08:00
|
|
|
break;
|
|
|
|
case CURLOPT_PASSWDFUNCTION:
|
|
|
|
zval_add_ref(zvalue);
|
|
|
|
ch->handlers->passwd = *zvalue;
|
2001-06-25 23:14:20 +08:00
|
|
|
error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDFUNCTION, curl_passwd);
|
2001-04-30 22:36:19 +08:00
|
|
|
error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDDATA, (void *) ch);
|
|
|
|
break;
|
|
|
|
case CURLOPT_POSTFIELDS:
|
|
|
|
if (Z_TYPE_PP(zvalue) == IS_ARRAY || Z_TYPE_PP(zvalue) == IS_OBJECT) {
|
|
|
|
zval **current;
|
|
|
|
HashTable *postfields;
|
|
|
|
struct HttpPost *first = NULL;
|
|
|
|
struct HttpPost *last = NULL;
|
2001-09-22 08:38:59 +08:00
|
|
|
char *postval;
|
|
|
|
char *string_key = NULL;
|
|
|
|
ulong num_key;
|
|
|
|
uint string_key_len;
|
2001-08-24 09:12:37 +08:00
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
postfields = HASH_OF(*zvalue);
|
|
|
|
if (! postfields) {
|
|
|
|
php_error(E_WARNING, "Couldn't get HashTable in CURLOPT_POSTFIELDS");
|
|
|
|
RETURN_FALSE;
|
2000-09-30 11:09:54 +08:00
|
|
|
}
|
2001-02-16 22:31:37 +08:00
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
for (zend_hash_internal_pointer_reset(postfields);
|
|
|
|
zend_hash_get_current_data(postfields, (void **) ¤t) == SUCCESS;
|
|
|
|
zend_hash_move_forward(postfields)) {
|
2000-09-30 11:09:54 +08:00
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
SEPARATE_ZVAL(current);
|
|
|
|
convert_to_string_ex(current);
|
2000-12-22 20:57:09 +08:00
|
|
|
|
2001-09-23 00:56:21 +08:00
|
|
|
zend_hash_get_current_key_ex(postfields, &string_key, &string_key_len, &num_key, 0, NULL);
|
2000-09-30 11:09:54 +08:00
|
|
|
|
2001-09-22 08:38:59 +08:00
|
|
|
postval = emalloc((string_key_len - 1) + Z_STRLEN_PP(current) + 1);
|
|
|
|
snprintf(postval, (sizeof("%s=%s") - 1) + (string_key_len - 1) + Z_STRLEN_PP(current),
|
|
|
|
"%s=%s", string_key, Z_STRVAL_PP(current));
|
2000-08-16 00:50:14 +08:00
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
error = curl_formparse(postval, &first, &last);
|
2000-09-30 11:09:54 +08:00
|
|
|
}
|
2001-04-30 22:36:19 +08:00
|
|
|
|
|
|
|
if (error != CURLE_OK) {
|
|
|
|
SAVE_CURL_ERROR(ch, error);
|
|
|
|
RETURN_FALSE;
|
2000-09-30 11:09:54 +08:00
|
|
|
}
|
2001-04-30 22:36:19 +08:00
|
|
|
|
|
|
|
zend_llist_add_element(&ch->to_free.post, &first);
|
2001-05-01 00:30:46 +08:00
|
|
|
error = curl_easy_setopt(ch->cp, CURLOPT_HTTPPOST, first);
|
2001-04-30 22:36:19 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
char *post = NULL;
|
|
|
|
|
|
|
|
convert_to_string_ex(zvalue);
|
|
|
|
post = estrndup(Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue));
|
|
|
|
zend_llist_add_element(&ch->to_free.str, &post);
|
|
|
|
|
|
|
|
error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, post);
|
|
|
|
error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, Z_STRLEN_PP(zvalue));
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case CURLOPT_HTTPHEADER:
|
|
|
|
case CURLOPT_QUOTE:
|
|
|
|
case CURLOPT_POSTQUOTE: {
|
|
|
|
zval **current;
|
2001-09-22 08:38:59 +08:00
|
|
|
HashTable *ph;
|
2001-04-30 22:36:19 +08:00
|
|
|
struct curl_slist *slist = NULL;
|
|
|
|
|
2001-09-22 08:38:59 +08:00
|
|
|
ph = HASH_OF(*zvalue);
|
2001-09-23 00:56:21 +08:00
|
|
|
if (! ph) {
|
2001-04-30 22:36:19 +08:00
|
|
|
php_error(E_WARNING,
|
2001-09-22 08:38:59 +08:00
|
|
|
"You must pass either an object or an array with the CURLOPT_HTTPHEADER,"
|
|
|
|
"CURLOPT_QUOTE and CURLOPT_POSTQUOTE arguments");
|
2001-04-30 22:36:19 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-09-22 08:38:59 +08:00
|
|
|
for (zend_hash_internal_pointer_reset(ph);
|
|
|
|
zend_hash_get_current_data(ph, (void **) ¤t) == SUCCESS;
|
|
|
|
zend_hash_move_forward(ph)) {
|
2001-04-30 22:36:19 +08:00
|
|
|
char *indiv = NULL;
|
|
|
|
|
|
|
|
SEPARATE_ZVAL(current);
|
|
|
|
convert_to_string_ex(current);
|
|
|
|
|
2001-06-13 04:23:14 +08:00
|
|
|
indiv = estrndup(Z_STRVAL_PP(current), Z_STRLEN_PP(current) + 1);
|
2001-04-30 22:36:19 +08:00
|
|
|
slist = curl_slist_append(slist, indiv);
|
|
|
|
if (! slist) {
|
|
|
|
efree(indiv);
|
|
|
|
php_error(E_WARNING, "Couldn't build curl_slist from curl_setopt()");
|
|
|
|
RETURN_FALSE;
|
2000-10-20 12:57:14 +08:00
|
|
|
}
|
2001-04-30 22:36:19 +08:00
|
|
|
zend_llist_add_element(&ch->to_free.str, &indiv);
|
|
|
|
}
|
|
|
|
zend_llist_add_element(&ch->to_free.slist, &slist);
|
|
|
|
|
|
|
|
error = curl_easy_setopt(ch->cp, option, slist);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2000-09-30 11:09:54 +08:00
|
|
|
}
|
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
if (error != CURLE_OK) {
|
|
|
|
SAVE_CURL_ERROR(ch, error);
|
2000-09-30 11:09:54 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
} else {
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
2000-07-17 03:37:33 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-09-30 11:09:54 +08:00
|
|
|
/* {{{ proto bool curl_exec(int ch)
|
2000-07-17 03:37:33 +08:00
|
|
|
Perform a CURL session */
|
2000-08-28 06:53:33 +08:00
|
|
|
PHP_FUNCTION(curl_exec)
|
2000-07-17 03:37:33 +08:00
|
|
|
{
|
2001-04-30 22:36:19 +08:00
|
|
|
zval **zid;
|
|
|
|
php_curl *ch;
|
|
|
|
CURLcode error;
|
|
|
|
|
2000-07-17 03:37:33 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 ||
|
2001-04-30 22:36:19 +08:00
|
|
|
zend_get_parameters_ex(1, &zid) == FAILURE) {
|
2000-07-17 03:37:33 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2001-04-30 22:36:19 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
|
2000-08-28 06:53:33 +08:00
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
error = curl_easy_perform(ch->cp);
|
|
|
|
if (error != CURLE_OK) {
|
2001-07-11 09:06:09 +08:00
|
|
|
if (ch->handlers->write->buf.c)
|
2001-07-11 04:09:56 +08:00
|
|
|
smart_str_free(&ch->handlers->write->buf);
|
2001-04-30 22:36:19 +08:00
|
|
|
SAVE_CURL_ERROR(ch, error);
|
|
|
|
RETURN_FALSE;
|
2000-08-17 10:14:41 +08:00
|
|
|
}
|
2000-09-30 11:09:54 +08:00
|
|
|
|
2001-05-04 12:20:38 +08:00
|
|
|
if (ch->handlers->write->method == PHP_CURL_RETURN) {
|
2001-09-27 06:24:44 +08:00
|
|
|
if (ch->handlers->write->type != PHP_CURL_BINARY)
|
2001-05-15 05:02:31 +08:00
|
|
|
smart_str_0(&ch->handlers->write->buf);
|
2001-07-12 07:03:24 +08:00
|
|
|
RETURN_STRINGL(ch->handlers->write->buf.c, ch->handlers->write->buf.len, 0);
|
2000-08-28 06:53:33 +08:00
|
|
|
}
|
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
RETURN_TRUE;
|
2000-07-17 03:37:33 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-09-22 08:38:59 +08:00
|
|
|
#define CAAL(s, v) add_assoc_long_ex(return_value, s, sizeof(s), v);
|
|
|
|
#define CAAD(s, v) add_assoc_double_ex(return_value, s, sizeof(s), v);
|
|
|
|
#define CAAS(s, v) add_assoc_string_ex(return_value, s, sizeof(s), v, 1);
|
|
|
|
|
2000-10-20 12:57:14 +08:00
|
|
|
/* {{{ proto string curl_getinfo(int ch, int opt)
|
|
|
|
Get information regarding a specific transfer */
|
|
|
|
PHP_FUNCTION(curl_getinfo)
|
|
|
|
{
|
2001-04-30 22:36:19 +08:00
|
|
|
zval **zid,
|
|
|
|
**zoption;
|
|
|
|
php_curl *ch;
|
|
|
|
int option,
|
|
|
|
argc = ZEND_NUM_ARGS();
|
|
|
|
|
2000-10-20 12:57:14 +08:00
|
|
|
if (argc < 1 || argc > 2 ||
|
2001-04-30 22:36:19 +08:00
|
|
|
zend_get_parameters_ex(argc, &zid, &zoption) == FAILURE) {
|
2000-10-20 12:57:14 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2001-04-30 22:36:19 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
|
2000-10-20 12:57:14 +08:00
|
|
|
|
|
|
|
if (argc < 2) {
|
2001-04-30 22:36:19 +08:00
|
|
|
char *url;
|
|
|
|
long l_code;
|
|
|
|
double d_code;
|
2000-10-20 12:57:14 +08:00
|
|
|
|
|
|
|
array_init(return_value);
|
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_EFFECTIVE_URL, &url);
|
2001-09-22 08:38:59 +08:00
|
|
|
CAAS("url", url);
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_HTTP_CODE, &l_code);
|
2001-09-22 08:38:59 +08:00
|
|
|
CAAL("http_code", l_code);
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_HEADER_SIZE, &l_code);
|
2001-09-22 08:38:59 +08:00
|
|
|
CAAL("header_size", l_code);
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_REQUEST_SIZE, &l_code);
|
2001-09-22 08:38:59 +08:00
|
|
|
CAAL("request_size", l_code);
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_FILETIME, &l_code);
|
2001-09-22 08:38:59 +08:00
|
|
|
CAAL("filetime", l_code);
|
2001-09-25 02:45:08 +08:00
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_SSL_VERIFYRESULT, &l_code);
|
2001-09-22 08:38:59 +08:00
|
|
|
CAAL("ssl_verify_result", l_code);
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME, &d_code);
|
2001-09-22 08:38:59 +08:00
|
|
|
CAAD("total_time", d_code);
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_NAMELOOKUP_TIME, &d_code);
|
2001-09-22 08:38:59 +08:00
|
|
|
CAAD("namelookup_time", d_code);
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_CONNECT_TIME, &d_code);
|
2001-09-22 08:38:59 +08:00
|
|
|
CAAD("connect_time", d_code);
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_PRETRANSFER_TIME, &d_code);
|
2001-09-22 08:38:59 +08:00
|
|
|
CAAD("pretransfer_time", d_code);
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_SIZE_UPLOAD, &d_code);
|
2001-09-22 08:38:59 +08:00
|
|
|
CAAD("size_upload", d_code);
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_SIZE_DOWNLOAD, &d_code);
|
2001-09-22 08:38:59 +08:00
|
|
|
CAAD("size_download", d_code);
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_SPEED_DOWNLOAD, &d_code);
|
2001-09-22 08:38:59 +08:00
|
|
|
CAAD("speed_download", d_code);
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_SPEED_UPLOAD, &d_code);
|
2001-09-22 08:38:59 +08:00
|
|
|
CAAD("speed_upload", d_code);
|
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d_code);
|
|
|
|
CAAD("download_content_length", d_code);
|
|
|
|
curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_UPLOAD, &d_code);
|
|
|
|
CAAD("upload_content_length", d_code);
|
2000-10-20 12:57:14 +08:00
|
|
|
} else {
|
2001-04-30 22:36:19 +08:00
|
|
|
option = Z_LVAL_PP(zoption);
|
|
|
|
switch (option) {
|
|
|
|
case CURLINFO_EFFECTIVE_URL: {
|
|
|
|
char *url;
|
|
|
|
|
|
|
|
curl_easy_getinfo(ch->cp, option, &url);
|
|
|
|
RETURN_STRING(url, 1);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CURLINFO_HTTP_CODE:
|
|
|
|
case CURLINFO_HEADER_SIZE:
|
|
|
|
case CURLINFO_REQUEST_SIZE:
|
2001-09-22 08:38:59 +08:00
|
|
|
case CURLINFO_FILETIME:
|
2001-09-25 02:45:08 +08:00
|
|
|
case CURLINFO_SSL_VERIFYRESULT: {
|
2001-04-30 22:36:19 +08:00
|
|
|
long code;
|
2000-10-20 12:57:14 +08:00
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, option, &code);
|
|
|
|
RETURN_LONG(code);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CURLINFO_TOTAL_TIME:
|
|
|
|
case CURLINFO_NAMELOOKUP_TIME:
|
|
|
|
case CURLINFO_CONNECT_TIME:
|
|
|
|
case CURLINFO_PRETRANSFER_TIME:
|
|
|
|
case CURLINFO_SIZE_UPLOAD:
|
|
|
|
case CURLINFO_SIZE_DOWNLOAD:
|
|
|
|
case CURLINFO_SPEED_DOWNLOAD:
|
2001-09-22 08:38:59 +08:00
|
|
|
case CURLINFO_SPEED_UPLOAD:
|
|
|
|
case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
|
|
|
|
case CURLINFO_CONTENT_LENGTH_UPLOAD: {
|
2001-04-30 22:36:19 +08:00
|
|
|
double code;
|
2000-10-20 12:57:14 +08:00
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
curl_easy_getinfo(ch->cp, option, &code);
|
|
|
|
RETURN_DOUBLE(code);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2000-10-20 12:57:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-09-30 11:09:54 +08:00
|
|
|
/* {{{ proto string curl_error(int ch)
|
|
|
|
Return a string contain the last error for the current session */
|
|
|
|
PHP_FUNCTION(curl_error)
|
2000-07-17 03:37:33 +08:00
|
|
|
{
|
2001-04-30 22:36:19 +08:00
|
|
|
zval **zid;
|
|
|
|
php_curl *ch;
|
2000-07-17 03:37:33 +08:00
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() != 1 ||
|
2001-04-30 22:36:19 +08:00
|
|
|
zend_get_parameters_ex(1, &zid) == FAILURE) {
|
2000-07-17 03:37:33 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2001-04-30 22:36:19 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
|
2001-03-03 09:06:55 +08:00
|
|
|
|
2001-07-02 20:08:21 +08:00
|
|
|
ch->err.str[CURL_ERROR_SIZE] = 0;
|
2001-09-10 19:06:15 +08:00
|
|
|
RETURN_STRING(ch->err.str, 1);
|
2000-07-17 03:37:33 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-09-30 11:09:54 +08:00
|
|
|
/* {{{ proto int curl_errno(int ch)
|
|
|
|
Return an integer containing the last error number */
|
|
|
|
PHP_FUNCTION(curl_errno)
|
|
|
|
{
|
2001-04-30 22:36:19 +08:00
|
|
|
zval **zid;
|
|
|
|
php_curl *ch;
|
|
|
|
|
2000-09-30 11:09:54 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 ||
|
2001-04-30 22:36:19 +08:00
|
|
|
zend_get_parameters_ex(1, &zid) == FAILURE) {
|
2000-09-30 11:09:54 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2001-04-30 22:36:19 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
|
|
|
|
|
|
|
|
RETURN_LONG(ch->err.no);
|
2000-09-30 11:09:54 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
2000-08-14 03:32:09 +08:00
|
|
|
|
2000-09-30 11:09:54 +08:00
|
|
|
/* {{{ proto void curl_close(int ch)
|
|
|
|
Close a CURL session */
|
2000-10-20 12:57:14 +08:00
|
|
|
PHP_FUNCTION(curl_close)
|
2000-08-14 03:32:09 +08:00
|
|
|
{
|
2001-04-30 22:36:19 +08:00
|
|
|
zval **zid;
|
|
|
|
php_curl *ch;
|
|
|
|
|
2000-09-30 11:09:54 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 ||
|
2001-04-30 22:36:19 +08:00
|
|
|
zend_get_parameters_ex(1, &zid) == FAILURE) {
|
2000-09-30 11:09:54 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
2000-08-14 03:32:09 +08:00
|
|
|
}
|
2001-04-30 22:36:19 +08:00
|
|
|
ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
|
2000-09-30 11:09:54 +08:00
|
|
|
|
2001-04-30 22:36:19 +08:00
|
|
|
zend_list_delete(Z_LVAL_PP(zid));
|
2000-08-14 03:32:09 +08:00
|
|
|
}
|
2000-09-30 11:09:54 +08:00
|
|
|
/* }}} */
|
2000-08-14 03:32:09 +08:00
|
|
|
|
2000-09-30 11:09:54 +08:00
|
|
|
/* {{{ _php_curl_close()
|
|
|
|
List destructor for curl handles */
|
2001-07-31 13:44:11 +08:00
|
|
|
static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
2000-08-16 00:50:14 +08:00
|
|
|
{
|
2001-04-30 22:36:19 +08:00
|
|
|
php_curl *ch = (php_curl *) rsrc->ptr;
|
|
|
|
|
|
|
|
curl_easy_cleanup(ch->cp);
|
|
|
|
zend_llist_clean(&ch->to_free.str);
|
|
|
|
zend_llist_clean(&ch->to_free.slist);
|
|
|
|
zend_llist_clean(&ch->to_free.post);
|
|
|
|
|
2001-05-04 12:20:38 +08:00
|
|
|
if (ch->handlers->write->func) zval_ptr_dtor(&ch->handlers->write->func);
|
|
|
|
if (ch->handlers->read->func) zval_ptr_dtor(&ch->handlers->read->func);
|
2001-06-25 23:14:20 +08:00
|
|
|
if (ch->handlers->write_header->func) zval_ptr_dtor(&ch->handlers->write_header->func);
|
2001-04-30 22:36:19 +08:00
|
|
|
if (ch->handlers->passwd) zval_ptr_dtor(&ch->handlers->passwd);
|
|
|
|
|
2001-05-04 12:20:38 +08:00
|
|
|
efree(ch->handlers->write);
|
2001-06-25 23:14:20 +08:00
|
|
|
efree(ch->handlers->write_header);
|
2001-05-04 12:20:38 +08:00
|
|
|
efree(ch->handlers->read);
|
2001-04-30 22:36:19 +08:00
|
|
|
efree(ch->handlers);
|
|
|
|
efree(ch);
|
|
|
|
}
|
2000-09-30 11:09:54 +08:00
|
|
|
/* }}} */
|
2000-08-16 00:50:14 +08:00
|
|
|
|
2000-07-26 06:15:26 +08:00
|
|
|
#endif
|
2001-06-05 21:12:10 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-09-09 21:29:31 +08:00
|
|
|
* vim600: noet sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: noet sw=4 ts=4
|
2001-06-05 21:12:10 +08:00
|
|
|
*/
|