diff options
Diffstat (limited to 'ext/curl')
| -rw-r--r-- | ext/curl/interface.c | 128 | ||||
| -rw-r--r-- | ext/curl/multi.c | 4 | ||||
| -rw-r--r-- | ext/curl/php_curl.h | 4 | ||||
| -rw-r--r-- | ext/curl/streams.c | 8 | ||||
| -rw-r--r-- | ext/curl/tests/curl_basic_016.phpt | 10 | ||||
| -rw-r--r-- | ext/curl/tests/curl_ftp_pasv.phpt | 59 | ||||
| -rw-r--r-- | ext/curl/tests/curl_setopt_basic001.phpt | 2 |
7 files changed, 201 insertions, 14 deletions
diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 98883e97d..1f6f6a928 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: interface.c 289495 2009-10-10 09:24:59Z pajoye $ */ +/* $Id: interface.c 294464 2010-02-03 20:53:31Z pajoye $ */ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS @@ -629,6 +629,9 @@ PHP_MINIT_FUNCTION(curl) REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_COUNT); REGISTER_CURL_CONSTANT(CURLINFO_HEADER_OUT); REGISTER_CURL_CONSTANT(CURLINFO_PRIVATE); +#if LIBCURL_VERSION_NUM > 0x071301 + REGISTER_CURL_CONSTANT(CURLINFO_CERTINFO); +#endif /* cURL protocol constants (curl_version) */ REGISTER_CURL_CONSTANT(CURL_VERSION_IPV6); @@ -745,6 +748,11 @@ PHP_MINIT_FUNCTION(curl) REGISTER_CURL_CONSTANT(CURLFTPSSL_ALL); #endif +#if LIBCURL_VERSION_NUM > 0x071301 + REGISTER_CURL_CONSTANT(CURLOPT_CERTINFO); + REGISTER_CURL_CONSTANT(CURLOPT_POSTREDIR); +#endif + /* SSH support works in 7.19.0+ using libssh2 */ #if LIBCURL_VERSION_NUM >= 0x071300 REGISTER_CURL_CONSTANT(CURLSSH_AUTH_NONE); @@ -781,6 +789,7 @@ PHP_MINIT_FUNCTION(curl) #if LIBCURL_VERSION_NUM >= 0x070f01 REGISTER_CURL_CONSTANT(CURLOPT_FTP_FILEMETHOD); + REGISTER_CURL_CONSTANT(CURLOPT_FTP_SKIP_PASV_IP); #endif #if LIBCURL_VERSION_NUM >= 0x071001 @@ -1336,6 +1345,83 @@ static void alloc_curl_handle(php_curl **ch) } /* }}} */ +#if LIBCURL_VERSION_NUM > 0x071301 +/* {{{ split_certinfo + */ +static void split_certinfo(char *string, zval *hash) +{ + char *org = estrdup(string); + char *s = org; + char *split; + + if(org) { + do { + char *key; + char *val; + char *tmp; + + split = strstr(s, "; "); + if(split) + *split = '\0'; + + key = s; + tmp = memchr(key, '=', 64); + if(tmp) { + *tmp = '\0'; + val = tmp+1; + add_assoc_string(hash, key, val, 1); + } + s = split+2; + } while(split); + efree(org); + } +} + +/* {{{ create_certinfo + */ +static void create_certinfo(struct curl_certinfo *ci, zval *listcode TSRMLS_DC) +{ + int i; + + if(ci) { + zval *certhash = NULL; + + for(i=0; i<ci->num_of_certs; i++) { + struct curl_slist *slist; + + MAKE_STD_ZVAL(certhash); + array_init(certhash); + for(slist = ci->certinfo[i]; slist; slist = slist->next) { + int len; + char s[64]; + char *tmp; + strncpy(s, slist->data, 64); + tmp = memchr(s, ':', 64); + if(tmp) { + *tmp = '\0'; + len = strlen(s); + if(!strcmp(s, "Subject") || !strcmp(s, "Issuer")) { + zval *hash; + + MAKE_STD_ZVAL(hash); + array_init(hash); + + split_certinfo(&slist->data[len+1], hash); + add_assoc_zval(certhash, s, hash); + } else { + add_assoc_string(certhash, s, &slist->data[len+1], 1); + } + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not extract hash key from certificate info"); + } + } + add_next_index_zval(listcode, certhash); + } + } +} +/* }}} */ +#endif + /* {{{ proto resource curl_init([string url]) Initialize a cURL session */ PHP_FUNCTION(curl_init) @@ -1572,6 +1658,10 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu #endif #if LIBCURL_VERSION_NUM >= 0x070f01 case CURLOPT_FTP_FILEMETHOD: + case CURLOPT_FTP_SKIP_PASV_IP: +#endif +#if LIBCURL_VERSION_NUM > 0x071301 + case CURLOPT_CERTINFO: #endif convert_to_long_ex(zvalue); #if LIBCURL_VERSION_NUM >= 0x71304 @@ -1595,6 +1685,12 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu } error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue)); break; +#if LIBCURL_VERSION_NUM > 0x071301 + case CURLOPT_POSTREDIR: + convert_to_long_ex(zvalue); + error = curl_easy_setopt(ch->cp, CURLOPT_POSTREDIR, Z_LVAL_PP(zvalue) & CURL_REDIR_POST_ALL); + break; +#endif case CURLOPT_PRIVATE: case CURLOPT_URL: case CURLOPT_PROXY: @@ -1852,7 +1948,7 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu error = curl_formadd(&first, &last, CURLFORM_COPYNAME, string_key, CURLFORM_NAMELENGTH, (long)string_key_len - 1, - CURLFORM_FILENAME, filename ? filename : postval, + CURLFORM_FILENAME, filename ? filename + sizeof(";filename=") - 1 : postval, CURLFORM_CONTENTTYPE, type ? type + sizeof(";type=") - 1 : "application/octet-stream", CURLFORM_FILE, postval, CURLFORM_END); @@ -2121,6 +2217,10 @@ PHP_FUNCTION(curl_getinfo) char *s_code; long l_code; double d_code; +#if LIBCURL_VERSION_NUM > 0x071301 + struct curl_certinfo *ci = NULL; + zval *listcode; +#endif array_init(return_value); @@ -2191,6 +2291,14 @@ PHP_FUNCTION(curl_getinfo) if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME, &d_code) == CURLE_OK) { CAAD("redirect_time", d_code); } +#if LIBCURL_VERSION_NUM > 0x071301 + if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) { + MAKE_STD_ZVAL(listcode); + array_init(listcode); + create_certinfo(ci, listcode TSRMLS_CC); + CAAZ("certinfo", listcode); + } +#endif if (ch->header.str_len > 0) { CAAS("request_header", ch->header.str); } @@ -2250,6 +2358,20 @@ PHP_FUNCTION(curl_getinfo) } else { RETURN_FALSE; } +#if LIBCURL_VERSION_NUM > 0x071301 + case CURLINFO_CERTINFO: { + struct curl_certinfo *ci = NULL; + + array_init(return_value); + + if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) { + create_certinfo(ci, return_value TSRMLS_CC); + } else { + RETURN_FALSE; + } + break; + } +#endif } } } diff --git a/ext/curl/multi.c b/ext/curl/multi.c index 91312e4ce..0fdad1a46 100644 --- a/ext/curl/multi.c +++ b/ext/curl/multi.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: multi.c 272370 2008-12-31 11:15:49Z sebastian $ */ +/* $Id: multi.c 293036 2010-01-03 09:23:27Z sebastian $ */ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS diff --git a/ext/curl/php_curl.h b/ext/curl/php_curl.h index 657a0cd9b..21e3ec1d2 100644 --- a/ext/curl/php_curl.h +++ b/ext/curl/php_curl.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_curl.h 289496 2009-10-10 09:29:34Z pajoye $ */ +/* $Id: php_curl.h 293036 2010-01-03 09:23:27Z sebastian $ */ #ifndef _PHP_CURL_H #define _PHP_CURL_H diff --git a/ext/curl/streams.c b/ext/curl/streams.c index 26786ad18..39d78f740 100644 --- a/ext/curl/streams.c +++ b/ext/curl/streams.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c 284747 2009-07-25 13:00:25Z jani $ */ +/* $Id: streams.c 294462 2010-02-03 20:49:03Z pajoye $ */ /* This file implements cURL based wrappers. * NOTE: If you are implementing your own streams that are intended to @@ -280,7 +280,7 @@ php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *filename, * have a FILE* associated with it. * Otherwise, use the "smart" memory stream that will turn itself into a file * when it gets large */ -#if !HAVE_FOPENCOOKIE +#ifndef HAVE_FOPENCOOKIE if (options & STREAM_WILL_CAST) { curlstream->readbuffer.buf = php_stream_fopen_tmpfile(); } else @@ -445,7 +445,7 @@ php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *filename, php_stream_to_zval(curlstream->readbuffer.buf, tmp); add_assoc_zval(stream->wrapperdata, "readbuf", tmp); -#if !HAVE_FOPENCOOKIE +#ifndef HAVE_FOPENCOOKIE if (options & STREAM_WILL_CAST) { /* we will need to download the whole resource now, * since we cannot get the actual FD for the download, diff --git a/ext/curl/tests/curl_basic_016.phpt b/ext/curl/tests/curl_basic_016.phpt index 5c947eb88..b5890c0f6 100644 --- a/ext/curl/tests/curl_basic_016.phpt +++ b/ext/curl/tests/curl_basic_016.phpt @@ -3,7 +3,13 @@ Test curl_getinfo() function with basic functionality --CREDITS-- Jean-Marc Fontaine <jmf@durcommefaire.net> --SKIPIF-- -<?php if (!extension_loaded("curl")) exit("skip curl extension not loaded"); ?> +<?php +if (!extension_loaded("curl")) exit("skip curl extension not loaded"); +$curl_version = curl_version(); +if ($curl_version['version_number'] > 0x071201) { + exit("skip: tests works only on older versions of curl"); +} +?> --FILE-- <?php $ch = curl_init(); @@ -12,7 +18,7 @@ Jean-Marc Fontaine <jmf@durcommefaire.net> ?> ===DONE=== --EXPECTF-- -array(20) { +array(2%d) { [%u|b%"url"]=> string(0) "" ["content_type"]=> diff --git a/ext/curl/tests/curl_ftp_pasv.phpt b/ext/curl/tests/curl_ftp_pasv.phpt new file mode 100644 index 000000000..6cd742910 --- /dev/null +++ b/ext/curl/tests/curl_ftp_pasv.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test curl_exec() function with basic functionality +--CREDITS-- +--SKIPIF-- +<?php +if (!extension_loaded("curl")) exit("skip curl extension not loaded"); +if (false === getenv('PHP_CURL_FTP_REMOTE_SERVER')) exit("skip PHP_CURL_FTP_REMOTE_SERVER env variable is not defined"); +if (false === getenv('PHP_CURL_FTP_REMOTE_USER')) exit("skip PHP_CURL_FTP_REMOTE_USER env variable is not defined"); +if (false === getenv('PHP_CURL_FTP_REMOTE_PASSWD')) exit("skip PHP_CURL_FTP_REMOTE_PASSWD env variable is not defined"); +?> +--FILE-- +<?php + $host = getenv('PHP_CURL_FTP_REMOTE_SERVER'); + $username = getenv('PHP_CURL_FTP_REMOTE_USER'); + $password = getenv('PHP_CURL_FTP_REMOTE_PASSWD'); + + // FTP this script to a server + $fp = fopen ( __FILE__ , "r" ); + $url = "ftp://$username:$password@$host/test.phpt" ; + + $ch = curl_init (); + + // enable below to get the output in verbose mode. + // curl_setopt ( $ch , CURLOPT_VERBOSE, 1 ); + + /* Without enabling SKIP_PASV_IP flag, the following output will be seen.. + < 227 Entering Passive Mode (10,5,80,146,100,199) + * Trying 10.5.80.146... * connected + * Connecting to 10.5.80.146 (10.5.80.146) port 25799 + */ + + /* After enabling SKIP_PASV_IP flag, the following output will be seen.. + < 227 Entering Passive Mode (10,5,80,146,50,229) + * Skips 10.5.80.146 for data connection, uses 10.5.80.146 instead + * Trying 10.5.80.146... * connected + */ + + curl_setopt ( $ch , CURLOPT_URL, $url ); + curl_setopt ( $ch , CURLOPT_TRANSFERTEXT, 1 ); + + //force passive connection + curl_setopt ( $ch , CURLOPT_FTP_USE_EPSV, 0 ); + curl_setopt ( $ch , CURLOPT_FTP_SKIP_PASV_IP, 1 ); + + // mark the file for upload.. + curl_setopt ( $ch , CURLOPT_INFILE, $fp ); + curl_setopt ( $ch , CURLOPT_INFILESIZE, filesize(__FILE__) ); + curl_setopt ( $ch , CURLOPT_PUT, 1 ); + curl_setopt ( $ch , CURLOPT_UPLOAD, 1 ); + + $result = curl_exec ( $ch ); + var_dump ( $result ); + curl_close ( $ch ); + +?> +===DONE=== +--EXPECTF-- +bool(true) +===DONE=== diff --git a/ext/curl/tests/curl_setopt_basic001.phpt b/ext/curl/tests/curl_setopt_basic001.phpt index 4167c0532..99cb538d3 100644 --- a/ext/curl/tests/curl_setopt_basic001.phpt +++ b/ext/curl/tests/curl_setopt_basic001.phpt @@ -27,7 +27,7 @@ curl_close($ch); var_dump( $curl_content ); ?> --EXPECTF-- -PHP Warning: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line 0 +Warning: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line 0 *** Testing curl_setopt with CURLOPT_FOLLOWLOCATION in safemode Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in %s on line %d |
