diff options
Diffstat (limited to 'ext/standard')
| -rw-r--r-- | ext/standard/basic_functions.c | 10 | ||||
| -rw-r--r-- | ext/standard/file.c | 17 | ||||
| -rw-r--r-- | ext/standard/fsock.c | 218 | ||||
| -rw-r--r-- | ext/standard/fsock.h | 4 | ||||
| -rw-r--r-- | ext/standard/ftp_fopen_wrapper.c | 16 | ||||
| -rw-r--r-- | ext/standard/http_fopen_wrapper.c | 29 |
6 files changed, 56 insertions, 238 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 9a14905b3a..84c1347f50 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1166,9 +1166,6 @@ PHP_RINIT_FUNCTION(basic) BG(locale_string) = NULL; BG(user_compare_func_name) = NULL; BG(array_walk_func_name) = NULL; -#ifdef HAVE_MMAP - BG(mmap_file) = NULL; -#endif BG(page_uid) = -1; BG(page_gid) = -1; BG(page_inode) = -1; @@ -1219,7 +1216,6 @@ PHP_RSHUTDOWN_FUNCTION(basic) } STR_FREE(BG(locale_string)); - PHP_RSHUTDOWN(fsock)(SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_RSHUTDOWN(filestat)(SHUTDOWN_FUNC_ARGS_PASSTHRU); #ifdef HAVE_SYSLOG_H PHP_RSHUTDOWN(syslog)(SHUTDOWN_FUNC_ARGS_PASSTHRU); @@ -1246,12 +1242,6 @@ PHP_RSHUTDOWN_FUNCTION(basic) BG(user_filter_map) = NULL; } -#ifdef HAVE_MMAP - if (BG(mmap_file)) { - munmap(BG(mmap_file), BG(mmap_len)); - } -#endif - return SUCCESS; } diff --git a/ext/standard/file.c b/ext/standard/file.c index 0674f4b3fd..9da076e08a 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -647,6 +647,7 @@ PHP_FUNCTION(stream_get_meta_data) add_assoc_long(return_value, "unread_bytes", stream->writepos - stream->readpos); +#if 0 if (php_stream_is(stream, PHP_STREAM_IS_SOCKET)) { php_netstream_data_t *sock = PHP_NETSTREAM_DATA_FROM_STREAM(stream); @@ -654,10 +655,13 @@ PHP_FUNCTION(stream_get_meta_data) add_assoc_bool(return_value, "blocked", sock->is_blocked); add_assoc_bool(return_value, "eof", stream->eof); } else { +#endif add_assoc_bool(return_value, "timed_out", 0); add_assoc_bool(return_value, "blocked", 1); add_assoc_bool(return_value, "eof", php_stream_eof(stream)); +#if 0 } +#endif } /* }}} */ @@ -2237,7 +2241,7 @@ PHP_FUNCTION(unlink) } /* }}} */ -/* {{{ proto int ftruncate(resource fp, int size) +/* {{{ proto bool ftruncate(resource fp, int size) Truncate file to 'size' length */ PHP_NAMED_FUNCTION(php_if_ftruncate) { @@ -2254,15 +2258,12 @@ PHP_NAMED_FUNCTION(php_if_ftruncate) convert_to_long_ex(size); - if (php_stream_is(stream, PHP_STREAM_IS_SOCKET)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't truncate sockets!"); + if (!php_stream_truncate_supported(stream)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't truncate this stream!"); RETURN_FALSE; } - if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fd, 1)) { - ret = ftruncate(fd, Z_LVAL_PP(size)); - RETURN_LONG(ret + 1); - } - RETURN_FALSE; + + RETURN_BOOL(0 == php_stream_truncate_set_size(stream, Z_LVAL_PP(size))); } /* }}} */ diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c index bbe6d7debb..8f41cf4d3f 100644 --- a/ext/standard/fsock.c +++ b/ext/standard/fsock.c @@ -20,122 +20,19 @@ /* $Id$ */ -/* converted to PHP Streams and moved much code to main/network.c [wez] */ - -/* Synced with php 3.0 revision 1.121 1999-06-18 [ssb] */ -/* Synced with php 3.0 revision 1.133 1999-07-21 [sas] */ - #include "php.h" #include "php_globals.h" #include <stdlib.h> #include <stddef.h> -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif - -#ifdef HAVE_FCNTL_H -# include <fcntl.h> -#endif - -#ifdef HAVE_SYS_TIME_H -# include <sys/time.h> -#endif - -#include <sys/types.h> -#ifdef HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif -#ifdef PHP_WIN32 -#include <winsock2.h> -#elif defined(NETWARE) -#ifdef NEW_LIBC -#ifdef USE_WINSOCK -#include <novsock2.h> -#else -#include <netinet/in.h> -#include <netdb.h> -/*#include <sys/socket.h>*/ -#include <sys/select.h> -/*#else -#include <sys/socket.h>*/ -#endif -#endif -#else -#include <netinet/in.h> -#include <netdb.h> -#if HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif -#endif -#if defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE) -#undef AF_UNIX -#endif -#if defined(AF_UNIX) -#include <sys/un.h> -#endif -#ifdef HAVE_SYS_SELECT_H -#include <sys/select.h> -#endif - -#ifndef PF_INET -#define PF_INET AF_INET -#endif - -#ifndef PF_UNIX -#define PF_UNIX AF_UNIX -#endif - -#include <string.h> -#include <errno.h> - -#include "base64.h" -#include "file.h" -#include "url.h" -#include "fsock.h" - #include "php_network.h" - -#ifdef ZTS -static int fsock_globals_id; -#endif - -#ifdef PHP_WIN32 -#define EWOULDBLOCK WSAEWOULDBLOCK -#elif defined(NETWARE) -#ifdef USE_WINSOCK -#define EWOULDBLOCK WSAEWOULDBLOCK -#endif -#endif - -/* {{{ php_lookup_hostname */ - -/* - * Converts a host name to an IP address. - * TODO: This looks like unused code suitable for nuking. - */ -PHPAPI int php_lookup_hostname(const char *addr, struct in_addr *in) -{ - struct hostent *host_info; - - if (!inet_aton(addr, in)) { - /* XXX NOT THREAD SAFE */ - host_info = gethostbyname(addr); - if (host_info == 0) { - /* Error: unknown host */ - return -1; - } - *in = *((struct in_addr *) host_info->h_addr); - } - return 0; -} -/* }}} */ +#include "file.h" /* {{{ php_fsockopen() */ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) { char *host; - int host_len; + long host_len; int port = -1; zval *zerrno = NULL, *zerrstr = NULL; double timeout = FG(default_socket_timeout); @@ -144,6 +41,9 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) char *hashkey = NULL; php_stream *stream = NULL; int err; + char *hostname = NULL; + long hostname_len; + char *errstr = NULL; RETVAL_FALSE; @@ -151,22 +51,17 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) RETURN_FALSE; } - if (persistent) { spprintf(&hashkey, 0, "pfsockopen__%s:%d", host, port); - - switch(php_stream_from_persistent_id(hashkey, &stream TSRMLS_CC)) { - case PHP_STREAM_PERSISTENT_SUCCESS: - /* TODO: could check if the socket is still alive here */ - php_stream_to_zval(stream, return_value); - - /* fall through */ - case PHP_STREAM_PERSISTENT_FAILURE: - efree(hashkey); - return; - } } + if (port > 0) { + hostname_len = spprintf(&hostname, 0, "%s:%d", host, port); + } else { + hostname_len = host_len; + hostname = host; + } + /* prepare the timeout value for use */ conv = (unsigned long) (timeout * 1000000.0); tv.tv_sec = conv / 1000000; @@ -181,88 +76,29 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) ZVAL_STRING(zerrstr, "", 1); } - if (port > 0) { /* connect to a host */ - enum php_sslflags_t { php_ssl_none, php_ssl_v23, php_ssl_tls }; - enum php_sslflags_t ssl_flags = php_ssl_none; - struct { - char *proto; - int protolen; - int socktype; - enum php_sslflags_t ssl_flags; - /* more flags to be added here */ - } sockmodes[] = { - { "udp://", 6, SOCK_DGRAM, php_ssl_none }, - { "tcp://", 6, SOCK_STREAM, php_ssl_none }, - { "ssl://", 6, SOCK_STREAM, php_ssl_v23 }, - { "tls://", 6, SOCK_STREAM, php_ssl_tls }, - /* more modes to be added here */ - { NULL, 0, 0 } - }; - int socktype = SOCK_STREAM; - int i; - - for (i = 0; sockmodes[i].proto != NULL; i++) { - if (strncmp(host, sockmodes[i].proto, sockmodes[i].protolen) == 0) { - ssl_flags = sockmodes[i].ssl_flags; - socktype = sockmodes[i].socktype; - host += sockmodes[i].protolen; - break; - } - } -#if !HAVE_OPENSSL_EXT - if (ssl_flags != php_ssl_none) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no SSL support in this build"); - } - else -#endif - stream = php_stream_sock_open_host(host, (unsigned short)port, socktype, &tv, hashkey); - - /* Preserve error */ - err = php_socket_errno(); + stream = php_stream_xport_create(hostname, hostname_len, ENFORCE_SAFE_MODE | REPORT_ERRORS, + STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, hashkey, &tv, NULL, &errstr, &err); - if (stream == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s:%d", host, port); - } - -#if HAVE_OPENSSL_EXT - if (stream && ssl_flags != php_ssl_none) { - int ssl_ret = FAILURE; - switch(ssl_flags) { - case php_ssl_v23: - ssl_ret = php_stream_sock_ssl_activate_with_method(stream, 1, SSLv23_client_method(), NULL TSRMLS_CC); - break; - case php_ssl_tls: - ssl_ret = php_stream_sock_ssl_activate_with_method(stream, 1, TLSv1_client_method(), NULL TSRMLS_CC); - break; - default: - /* unknown ?? */ - break; - } - if (ssl_ret == FAILURE) - php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to activate SSL mode %d", ssl_flags); - } -#endif - - } else { - /* FIXME: Win32 - this probably does not return sensible errno and errstr */ - stream = php_stream_sock_open_unix(host, host_len, hashkey, &tv); - err = php_socket_errno(); + if (port > 0) { + efree(hostname); + } + if (stream == NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s:%d", host, port); } - if (hashkey) + if (hashkey) { efree(hashkey); + } if (stream == NULL) { if (zerrno) { zval_dtor(zerrno); ZVAL_LONG(zerrno, err); } - if (zerrstr) { - char *buf = php_socket_strerror(err, NULL, 0); - - /* no need to dup; we would only need to efree buf anyway */ + if (zerrstr && errstr) { + /* no need to dup; we need to efree buf anyway */ zval_dtor(zerrstr); - ZVAL_STRING(zerrstr, buf, 0); + ZVAL_STRING(zerrstr, errstr, 0); } RETURN_FALSE; } @@ -287,12 +123,6 @@ PHP_FUNCTION(pfsockopen) } /* }}} */ -/* {{{ RSHUTDOWN_FUNCTION(fsock) */ -PHP_RSHUTDOWN_FUNCTION(fsock) -{ - return SUCCESS; -} -/* }}} */ /* * Local variables: * tab-width: 4 diff --git a/ext/standard/fsock.h b/ext/standard/fsock.h index 966fc1ecec..7d263c31e1 100644 --- a/ext/standard/fsock.h +++ b/ext/standard/fsock.h @@ -40,10 +40,6 @@ PHP_FUNCTION(fsockopen); PHP_FUNCTION(pfsockopen); -PHPAPI int php_lookup_hostname(const char *addr, struct in_addr *in); - -PHP_RSHUTDOWN_FUNCTION(fsock); - /* * Local variables: * tab-width: 4 diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index 98b5a27892..192786058d 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -142,10 +142,8 @@ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, char *path, ch char *scratch; int result; int i, use_ssl; -#if HAVE_OPENSSL_EXT int use_ssl_on_data=0; php_stream *reuseid=NULL; -#endif char *tpath, *ttpath, *hoststart=NULL; size_t file_size = 0; @@ -182,7 +180,6 @@ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, char *path, ch goto errexit; } -#if HAVE_OPENSSL_EXT if (use_ssl) { /* send the AUTH TLS request name */ @@ -212,7 +209,9 @@ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, char *path, ch } if (use_ssl) { - if (use_ssl && php_stream_sock_ssl_activate(stream, 1) == FAILURE) { + if (php_stream_xport_crypto_setup(stream, + STREAM_CRYPTO_METHOD_SSLv23_CLIENT, NULL TSRMLS_CC) < 0 + || php_stream_xport_crypto_enable(stream, 1 TSRMLS_CC) < 0) { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Unable to activate SSL mode"); php_stream_close(stream); stream = NULL; @@ -240,8 +239,6 @@ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, char *path, ch #endif } -#endif - /* send the user name */ php_stream_write_string(stream, "USER "); if (resource->user != NULL) { @@ -433,14 +430,15 @@ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, char *path, ch php_stream_context_set(datastream, context); php_stream_notify_progress_init(context, 0, file_size); -#if HAVE_OPENSSL_EXT - if (use_ssl_on_data && php_stream_sock_ssl_activate_with_method(datastream, 1, SSLv23_method(), reuseid TSRMLS_CC) == FAILURE) { + if (use_ssl_on_data && (php_stream_xport_crypto_setup(stream, + STREAM_CRYPTO_METHOD_SSLv23_CLIENT, NULL TSRMLS_CC) < 0 || + php_stream_xport_crypto_enable(stream, 1 TSRMLS_CC) < 0)) { + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Unable to activate SSL mode"); php_stream_close(datastream); datastream = NULL; goto errexit; } -#endif /* remember control stream */ datastream->wrapperdata = (zval *)stream; diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index e6da657882..dbe7340a9a 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -99,6 +99,8 @@ php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, ch char tmp_line[128]; size_t chunk_size = 0, file_size = 0; int eol_detect; + char *transport_string, *errstr = NULL; + int transport_len; if (strpbrk(mode, "awx+")) { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "HTTP wrapper does not support writeable connections."); @@ -110,14 +112,26 @@ php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, ch return NULL; use_ssl = resource->scheme && (strlen(resource->scheme) > 4) && resource->scheme[4] == 's'; - /* choose default ports */ if (use_ssl && resource->port == 0) resource->port = 443; else if (resource->port == 0) resource->port = 80; - stream = php_stream_sock_open_host(resource->host, resource->port, SOCK_STREAM, NULL, 0); + transport_len = spprintf(&transport_string, 0, "%s://%s:%d", use_ssl ? "ssl" : "tcp", resource->host, resource->port); + + stream = php_stream_xport_create(transport_string, transport_len, options, + STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, + NULL, NULL, context, &errstr, NULL); + + if (errstr) { + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "%s", errstr); + efree(errstr); + errstr = NULL; + } + + efree(transport_string); + if (stream == NULL) goto out; @@ -133,17 +147,6 @@ php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, ch php_stream_context_set(stream, context); php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0); - -#if HAVE_OPENSSL_EXT - if (use_ssl) { - if (php_stream_sock_ssl_activate(stream, 1) == FAILURE) { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Unable to activate SSL mode"); - php_stream_close(stream); - stream = NULL; - goto out; - } - } -#endif scratch_len = strlen(path) + 32; scratch = emalloc(scratch_len); |
