diff options
| author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:37:27 -0400 |
|---|---|---|
| committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:37:27 -0400 |
| commit | 2d4e5b09576bb4f0ba716cc82cdf29ea04d9184b (patch) | |
| tree | 41ccc042009cba53e4ce43e727fcba4c1cfbf7f3 /main/streams | |
| parent | d29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (diff) | |
| download | php-upstream/5.2.2.tar.gz | |
Imported Upstream version 5.2.2upstream/5.2.2
Diffstat (limited to 'main/streams')
| -rw-r--r-- | main/streams/cast.c | 4 | ||||
| -rw-r--r-- | main/streams/filter.c | 18 | ||||
| -rw-r--r-- | main/streams/memory.c | 65 | ||||
| -rw-r--r-- | main/streams/mmap.c | 4 | ||||
| -rw-r--r-- | main/streams/php_stream_context.h | 4 | ||||
| -rw-r--r-- | main/streams/php_stream_filter_api.h | 4 | ||||
| -rw-r--r-- | main/streams/php_stream_mmap.h | 4 | ||||
| -rw-r--r-- | main/streams/php_stream_plain_wrapper.h | 4 | ||||
| -rw-r--r-- | main/streams/php_stream_transport.h | 19 | ||||
| -rw-r--r-- | main/streams/php_stream_userspace.h | 4 | ||||
| -rw-r--r-- | main/streams/php_streams_int.h | 4 | ||||
| -rw-r--r-- | main/streams/plain_wrapper.c | 197 | ||||
| -rwxr-xr-x | main/streams/streams.c | 36 | ||||
| -rw-r--r-- | main/streams/transports.c | 34 | ||||
| -rw-r--r-- | main/streams/userspace.c | 30 | ||||
| -rw-r--r-- | main/streams/xp_socket.c | 23 |
16 files changed, 304 insertions, 150 deletions
diff --git a/main/streams/cast.c b/main/streams/cast.c index ac185aa5a..8e80fade0 100644 --- a/main/streams/cast.c +++ b/main/streams/cast.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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: cast.c,v 1.12.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: cast.c,v 1.12.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */ #define _GNU_SOURCE #include "php.h" diff --git a/main/streams/filter.c b/main/streams/filter.c index 0bb19c202..622e13201 100644 --- a/main/streams/filter.c +++ b/main/streams/filter.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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: filter.c,v 1.17.2.3.2.3 2006/10/11 23:11:26 pollita Exp $ */ +/* $Id: filter.c,v 1.17.2.3.2.9 2007/01/15 17:07:07 tony2001 Exp $ */ #include "php.h" #include "php_globals.h" @@ -46,12 +46,12 @@ PHPAPI HashTable *_php_get_stream_filters_hash(TSRMLS_D) /* API for registering GLOBAL filters */ PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory TSRMLS_DC) { - return zend_hash_add(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern), factory, sizeof(*factory), NULL); + return zend_hash_add(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern) + 1, factory, sizeof(*factory), NULL); } PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern TSRMLS_DC) { - return zend_hash_del(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern)); + return zend_hash_del(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern) + 1); } /* API for registering VOLATILE wrappers */ @@ -65,7 +65,7 @@ PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL, &tmpfactory, sizeof(php_stream_filter_factory)); } - return zend_hash_add(FG(stream_filters), (char*)filterpattern, strlen(filterpattern), factory, sizeof(*factory), NULL); + return zend_hash_add(FG(stream_filters), (char*)filterpattern, strlen(filterpattern) + 1, factory, sizeof(*factory), NULL); } /* Buckets */ @@ -102,6 +102,7 @@ PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, s } bucket->is_persistent = is_persistent; bucket->refcount = 1; + bucket->brigade = NULL; return bucket; } @@ -258,18 +259,19 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval n = strlen(filtername); - if (SUCCESS == zend_hash_find(filter_hash, (char*)filtername, n, (void**)&factory)) { + if (SUCCESS == zend_hash_find(filter_hash, (char*)filtername, n + 1, (void**)&factory)) { filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC); } else if ((period = strrchr(filtername, '.'))) { /* try a wildcard */ char *wildname; - wildname = estrdup(filtername); + wildname = emalloc(n+3); + memcpy(wildname, filtername, n+1); period = wildname + (period - filtername); while (period && !filter) { *period = '\0'; strcat(wildname, ".*"); - if (SUCCESS == zend_hash_find(filter_hash, wildname, strlen(wildname), (void**)&factory)) { + if (SUCCESS == zend_hash_find(filter_hash, wildname, strlen(wildname) + 1, (void**)&factory)) { filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC); } diff --git a/main/streams/memory.c b/main/streams/memory.c index 818e5a813..49469757d 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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: memory.c,v 1.8.2.6.2.8 2006/06/29 14:40:49 bjori Exp $ */ +/* $Id: memory.c,v 1.8.2.6.2.17 2007/02/22 23:26:03 helly Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -241,14 +241,48 @@ static int php_stream_memory_stat(php_stream *stream, php_stream_statbuf *ssb TS } /* }}} */ -php_stream_ops php_stream_memory_ops = { +static int php_stream_memory_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) /* {{{ */ +{ + php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract; + size_t newsize; + + switch(option) { + case PHP_STREAM_OPTION_TRUNCATE_API: + switch (value) { + case PHP_STREAM_TRUNCATE_SUPPORTED: + return PHP_STREAM_OPTION_RETURN_OK; + + case PHP_STREAM_TRUNCATE_SET_SIZE: + if (ms->mode & TEMP_STREAM_READONLY) { + return PHP_STREAM_OPTION_RETURN_ERR; + } + newsize = *(size_t*)ptrparam; + if (newsize <= ms->fsize) { + if (newsize < ms->fpos) { + ms->fpos = newsize; + } + } else { + ms->data = erealloc(ms->data, newsize); + memset(ms->data+ms->fsize, 0, newsize - ms->fsize); + ms->fsize = newsize; + } + ms->fsize = newsize; + return PHP_STREAM_OPTION_RETURN_OK; + } + default: + return PHP_STREAM_OPTION_RETURN_NOTIMPL; + } +} +/* }}} */ + +PHPAPI php_stream_ops php_stream_memory_ops = { php_stream_memory_write, php_stream_memory_read, php_stream_memory_close, php_stream_memory_flush, "MEMORY", php_stream_memory_seek, php_stream_memory_cast, php_stream_memory_stat, - NULL /* set_option */ + php_stream_memory_set_option }; @@ -266,7 +300,7 @@ PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC TSRMLS_DC) self->mode = mode; self->owner_ptr = NULL; - stream = php_stream_alloc(&php_stream_memory_ops, self, 0, mode & TEMP_STREAM_READONLY ? "r+b" : "w+b"); + stream = php_stream_alloc_rel(&php_stream_memory_ops, self, 0, mode & TEMP_STREAM_READONLY ? "rb" : "w+b"); stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; return stream; } @@ -493,12 +527,15 @@ static int php_stream_temp_set_option(php_stream *stream, int option, int value, } return PHP_STREAM_OPTION_RETURN_OK; default: + if (ts->innerstream) { + return php_stream_set_option(ts->innerstream, option, value, ptrparam); + } return PHP_STREAM_OPTION_RETURN_NOTIMPL; } } /* }}} */ -php_stream_ops php_stream_temp_ops = { +PHPAPI php_stream_ops php_stream_temp_ops = { php_stream_temp_write, php_stream_temp_read, php_stream_temp_close, php_stream_temp_flush, "TEMP", @@ -520,9 +557,9 @@ PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STR self->smax = max_memory_usage; self->mode = mode; self->meta = NULL; - stream = php_stream_alloc(&php_stream_temp_ops, self, 0, mode & TEMP_STREAM_READONLY ? "r+b" : "w+b"); + stream = php_stream_alloc_rel(&php_stream_temp_ops, self, 0, mode & TEMP_STREAM_READONLY ? "rb" : "w+b"); stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; - self->innerstream = php_stream_memory_create(mode); + self->innerstream = php_stream_memory_create_rel(mode); ((php_stream_memory_data*)self->innerstream->abstract)->owner_ptr = &self->innerstream; return stream; @@ -551,7 +588,7 @@ PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char } /* }}} */ -php_stream_ops php_stream_rfc2397_ops = { +PHPAPI php_stream_ops php_stream_rfc2397_ops = { php_stream_temp_write, php_stream_temp_read, php_stream_temp_close, php_stream_temp_flush, "RFC2397", @@ -673,7 +710,6 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, cha if ((stream = php_stream_temp_create_rel(0, ~0u)) != NULL) { /* store data */ php_stream_temp_write(stream, comma, ilen TSRMLS_CC); - efree(comma); php_stream_temp_seek(stream, 0, SEEK_SET, &newoffs TSRMLS_CC); /* set special stream stuff (enforce exact mode) */ vlen = strlen(mode); @@ -685,14 +721,15 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, cha stream->ops = &php_stream_rfc2397_ops; ts = (php_stream_temp_data*)stream->abstract; assert(ts != NULL); - ts->mode = mode && mode[0] == 'r' ? TEMP_STREAM_READONLY : 0; + ts->mode = mode && mode[0] == 'r' && mode[1] != '+' ? TEMP_STREAM_READONLY : 0; ts->meta = meta; } + efree(comma); return stream; } -static php_stream_wrapper_ops php_stream_rfc2397_wops = { +PHPAPI php_stream_wrapper_ops php_stream_rfc2397_wops = { php_stream_url_wrap_rfc2397, NULL, /* close */ NULL, /* fstat */ @@ -705,10 +742,10 @@ static php_stream_wrapper_ops php_stream_rfc2397_wops = { NULL /* rmdir */ }; -php_stream_wrapper php_stream_rfc2397_wrapper = { +PHPAPI php_stream_wrapper php_stream_rfc2397_wrapper = { &php_stream_rfc2397_wops, NULL, - 0, /* is_url */ + 1, /* is_url */ }; /* diff --git a/main/streams/mmap.c b/main/streams/mmap.c index 81642353b..5fee2bbad 100644 --- a/main/streams/mmap.c +++ b/main/streams/mmap.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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: mmap.c,v 1.8.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: mmap.c,v 1.8.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ /* Memory Mapping interface for streams */ #include "php.h" diff --git a/main/streams/php_stream_context.h b/main/streams/php_stream_context.h index d840944af..e52e2bc56 100644 --- a/main/streams/php_stream_context.h +++ b/main/streams/php_stream_context.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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: php_stream_context.h,v 1.11.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: php_stream_context.h,v 1.11.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ /* Stream context and status notification related definitions */ diff --git a/main/streams/php_stream_filter_api.h b/main/streams/php_stream_filter_api.h index 6f40a1d4b..97b232053 100644 --- a/main/streams/php_stream_filter_api.h +++ b/main/streams/php_stream_filter_api.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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 | @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_stream_filter_api.h,v 1.13.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: php_stream_filter_api.h,v 1.13.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ /* The filter API works on the principle of "Bucket-Brigades". This is * partially inspired by the Apache 2 method of doing things, although diff --git a/main/streams/php_stream_mmap.h b/main/streams/php_stream_mmap.h index 407bbfcd8..5cd5c4155 100644 --- a/main/streams/php_stream_mmap.h +++ b/main/streams/php_stream_mmap.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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: php_stream_mmap.h,v 1.5.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: php_stream_mmap.h,v 1.5.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ /* Memory Mapping interface for streams. * The intention is to provide a uniform interface over the most common diff --git a/main/streams/php_stream_plain_wrapper.h b/main/streams/php_stream_plain_wrapper.h index 9c310e343..6ce262184 100644 --- a/main/streams/php_stream_plain_wrapper.h +++ b/main/streams/php_stream_plain_wrapper.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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: php_stream_plain_wrapper.h,v 1.7.2.2 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: php_stream_plain_wrapper.h,v 1.7.2.2.2.1 2007/01/01 09:36:12 sebastian Exp $ */ /* definitions for the plain files wrapper */ diff --git a/main/streams/php_stream_transport.h b/main/streams/php_stream_transport.h index d8433831f..e797c1092 100644 --- a/main/streams/php_stream_transport.h +++ b/main/streams/php_stream_transport.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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: php_stream_transport.h,v 1.10.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: php_stream_transport.h,v 1.10.2.1.2.4 2007/02/05 05:15:16 andi Exp $ */ #if HAVE_SYS_SOCKET_H # include <sys/socket.h> @@ -104,8 +104,19 @@ PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t bufle * sending it as OOB data */ PHPAPI int php_stream_xport_sendto(php_stream *stream, const char *buf, size_t buflen, long flags, void *addr, socklen_t addrlen TSRMLS_DC); + +typedef enum { + STREAM_SHUT_RD, + STREAM_SHUT_WR, + STREAM_SHUT_RDWR +} stream_shutdown_t; + +/* Similar to shutdown() system call; shut down part of a full-duplex + * connection */ +PHPAPI int php_stream_xport_shutdown(php_stream *stream, stream_shutdown_t how TSRMLS_DC); END_EXTERN_C() + /* Structure definition for the set_option interface that the above functions wrap */ typedef struct _php_stream_xport_param { @@ -116,11 +127,13 @@ typedef struct _php_stream_xport_param { STREAM_XPORT_OP_GET_NAME, STREAM_XPORT_OP_GET_PEER_NAME, STREAM_XPORT_OP_RECV, - STREAM_XPORT_OP_SEND + STREAM_XPORT_OP_SEND, + STREAM_XPORT_OP_SHUTDOWN } op; unsigned int want_addr:1; unsigned int want_textaddr:1; unsigned int want_errortext:1; + unsigned int how:2; struct { char *name; diff --git a/main/streams/php_stream_userspace.h b/main/streams/php_stream_userspace.h index f7acf113b..095f06c1b 100644 --- a/main/streams/php_stream_userspace.h +++ b/main/streams/php_stream_userspace.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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: php_stream_userspace.h,v 1.5.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: php_stream_userspace.h,v 1.5.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ /* for user-space streams */ diff --git a/main/streams/php_streams_int.h b/main/streams/php_streams_int.h index 1c037457a..f7e0c7b15 100644 --- a/main/streams/php_streams_int.h +++ b/main/streams/php_streams_int.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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: php_streams_int.h,v 1.7.2.2.2.1 2006/09/14 09:58:27 dmitry Exp $ */ +/* $Id: php_streams_int.h,v 1.7.2.2.2.2 2007/01/01 09:36:12 sebastian Exp $ */ #if ZEND_DEBUG diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 6a62f021f..3ed947e9f 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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: plain_wrapper.c,v 1.52.2.6.2.8 2006/10/19 09:49:44 dmitry Exp $ */ +/* $Id: plain_wrapper.c,v 1.52.2.6.2.21 2007/04/18 14:23:06 dmitry Exp $ */ #include "php.h" #include "php_globals.h" @@ -39,6 +39,11 @@ #include "php_streams_int.h" +#define php_stream_fopen_from_fd_int(fd, mode, persistent_id) _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_CC TSRMLS_CC) +#define php_stream_fopen_from_fd_int_rel(fd, mode, persistent_id) _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_REL_CC TSRMLS_CC) +#define php_stream_fopen_from_file_int(file, mode) _php_stream_fopen_from_file_int((file), (mode) STREAMS_CC TSRMLS_CC) +#define php_stream_fopen_from_file_int_rel(file, mode) _php_stream_fopen_from_file_int((file), (mode) STREAMS_REL_CC TSRMLS_CC) + /* parse standard "fopen" modes into open() flags */ PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags) { @@ -128,12 +133,44 @@ static int do_fstat(php_stdio_stream_data *d, int force) return 0; } +static php_stream *_php_stream_fopen_from_fd_int(int fd, const char *mode, const char *persistent_id STREAMS_DC TSRMLS_DC) +{ + php_stdio_stream_data *self; + + self = pemalloc_rel_orig(sizeof(*self), persistent_id); + memset(self, 0, sizeof(*self)); + self->file = NULL; + self->is_pipe = 0; + self->lock_flag = LOCK_UN; + self->is_process_pipe = 0; + self->temp_file_name = NULL; + self->fd = fd; + + return php_stream_alloc_rel(&php_stream_stdio_ops, self, persistent_id, mode); +} + +static php_stream *_php_stream_fopen_from_file_int(FILE *file, const char *mode STREAMS_DC TSRMLS_DC) +{ + php_stdio_stream_data *self; + + self = emalloc_rel_orig(sizeof(*self)); + memset(self, 0, sizeof(*self)); + self->file = file; + self->is_pipe = 0; + self->lock_flag = LOCK_UN; + self->is_process_pipe = 0; + self->temp_file_name = NULL; + self->fd = fileno(file); + + return php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode); +} + PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path STREAMS_DC TSRMLS_DC) { int fd = php_open_temporary_fd(dir, pfx, opened_path TSRMLS_CC); if (fd != -1) { - php_stream *stream = php_stream_fopen_from_fd_rel(fd, "r+b", NULL); + php_stream *stream = php_stream_fopen_from_fd_int_rel(fd, "r+b", NULL); if (stream) { return stream; } @@ -152,7 +189,7 @@ PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC) int fd = php_open_temporary_fd(NULL, "php", &opened_path TSRMLS_CC); if (fd != -1) { - php_stream *stream = php_stream_fopen_from_fd_rel(fd, "r+b", NULL); + php_stream *stream = php_stream_fopen_from_fd_int_rel(fd, "r+b", NULL); if (stream) { php_stdio_stream_data *self = (php_stdio_stream_data*)stream->abstract; stream->wrapper = &php_plain_files_wrapper; @@ -174,36 +211,26 @@ PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC) PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const char *persistent_id STREAMS_DC TSRMLS_DC) { - php_stdio_stream_data *self; - php_stream *stream; - - self = pemalloc_rel_orig(sizeof(*self), persistent_id); - memset(self, 0, sizeof(*self)); - self->file = NULL; - self->is_pipe = 0; - self->lock_flag = LOCK_UN; - self->is_process_pipe = 0; - self->temp_file_name = NULL; - self->fd = fd; + php_stream *stream = php_stream_fopen_from_fd_int_rel(fd, mode, persistent_id); + + if (stream) { + php_stdio_stream_data *self = (php_stdio_stream_data*)stream->abstract; #ifdef S_ISFIFO - /* detect if this is a pipe */ - if (self->fd >= 0) { - self->is_pipe = (do_fstat(self, 0) == 0 && S_ISFIFO(self->sb.st_mode)) ? 1 : 0; - } + /* detect if this is a pipe */ + if (self->fd >= 0) { + self->is_pipe = (do_fstat(self, 0) == 0 && S_ISFIFO(self->sb.st_mode)) ? 1 : 0; + } #elif defined(PHP_WIN32) - { - long handle = _get_osfhandle(self->fd); + { + zend_uintptr_t handle = _get_osfhandle(self->fd); - if (handle != 0xFFFFFFFF) { - self->is_pipe = GetFileType((HANDLE)handle) == FILE_TYPE_PIPE; + if (handle != (zend_uintptr_t)INVALID_HANDLE_VALUE) { + self->is_pipe = GetFileType((HANDLE)handle) == FILE_TYPE_PIPE; + } } - } #endif - stream = php_stream_alloc_rel(&php_stream_stdio_ops, self, persistent_id, mode); - - if (stream) { if (self->is_pipe) { stream->flags |= PHP_STREAM_FLAG_NO_SEEK; } else { @@ -222,36 +249,26 @@ PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const cha PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC TSRMLS_DC) { - php_stdio_stream_data *self; - php_stream *stream; - - self = emalloc_rel_orig(sizeof(*self)); - memset(self, 0, sizeof(*self)); - self->file = file; - self->is_pipe = 0; - self->lock_flag = LOCK_UN; - self->is_process_pipe = 0; - self->temp_file_name = NULL; - self->fd = fileno(file); + php_stream *stream = php_stream_fopen_from_file_int_rel(file, mode); + + if (stream) { + php_stdio_stream_data *self = (php_stdio_stream_data*)stream->abstract; #ifdef S_ISFIFO - /* detect if this is a pipe */ - if (self->fd >= 0) { - self->is_pipe = (do_fstat(self, 0) == 0 && S_ISFIFO(self->sb.st_mode)) ? 1 : 0; - } + /* detect if this is a pipe */ + if (self->fd >= 0) { + self->is_pipe = (do_fstat(self, 0) == 0 && S_ISFIFO(self->sb.st_mode)) ? 1 : 0; + } #elif defined(PHP_WIN32) - { - long handle = _get_osfhandle(self->fd); + { + zend_uintptr_t handle = _get_osfhandle(self->fd); - if (handle != 0xFFFFFFFF) { - self->is_pipe = GetFileType((HANDLE)handle) == FILE_TYPE_PIPE; + if (handle != (zend_uintptr_t)INVALID_HANDLE_VALUE) { + self->is_pipe = GetFileType((HANDLE)handle) == FILE_TYPE_PIPE; + } } - } #endif - stream = php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode); - - if (stream) { if (self->is_pipe) { stream->flags |= PHP_STREAM_FLAG_NO_SEEK; } else { @@ -312,9 +329,19 @@ static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count TSRMLS assert(data != NULL); if (data->fd >= 0) { + if (stream->eof && !data->is_pipe) { + return 0; + } ret = read(data->fd, buf, count); - - stream->eof = (ret == 0 || (ret == (size_t)-1 && errno != EWOULDBLOCK)); + + if (ret == (size_t)-1 && errno == EINTR) { + /* Read was interrupted, retry once, + If read still fails, giveup with feof==0 + so script can retry if desired */ + ret = read(data->fd, buf, count); + } + + stream->eof = (ret == 0 || (ret == (size_t)-1 && errno != EWOULDBLOCK && errno != EINTR)); } else { #if HAVE_FLUSHIO @@ -372,16 +399,7 @@ static int php_stdiop_close(php_stream *stream, int close_handle TSRMLS_DC) data->file = NULL; } } else if (data->fd != -1) { -#if PHP_DEBUG - if ((data->fd == 1 || data->fd == 2) && 0 == strcmp(sapi_module.name, "cli")) { - /* don't close stdout or stderr in CLI in DEBUG mode, as we want to see any leaks */ - ret = 0; - } else { - ret = close(data->fd); - } -#else ret = close(data->fd); -#endif data->fd = -1; } else { return 0; /* everything should be closed already -> success */ @@ -583,7 +601,7 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void return -1; } - if ((long) ptrparam == PHP_STREAM_LOCK_SUPPORTED) { + if ((zend_uintptr_t) ptrparam == PHP_STREAM_LOCK_SUPPORTED) { return 0; } @@ -607,9 +625,16 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void case PHP_STREAM_MMAP_MAP_RANGE: do_fstat(data, 1); + if (range->length == 0 && range->offset > 0 && range->offset < data->sb.st_size) { + range->length = data->sb.st_size - range->offset; + } if (range->length == 0 || range->length > data->sb.st_size) { range->length = data->sb.st_size; } + if (range->offset >= data->sb.st_size) { + range->offset = data->sb.st_size; + range->length = 0; + } switch (range->mode) { case PHP_STREAM_MAP_MODE_READONLY: prot = PROT_READ; @@ -689,8 +714,16 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void return PHP_STREAM_OPTION_RETURN_ERR; } - if (range->length == 0) { - range->length = GetFileSize(hfile, NULL) - range->offset; + size = GetFileSize(hfile, NULL); + if (range->length == 0 && range->offset > 0 && range->offset < size) { + range->length = size - range->offset; + } + if (range->length == 0 || range->length > size) { + range->length = size; + } + if (range->offset >= size) { + range->offset = size; + range->length = 0; } /* figure out how big a chunk to map to be able to view the part that we need */ @@ -740,8 +773,13 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void case PHP_STREAM_TRUNCATE_SUPPORTED: return fd == -1 ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK; - case PHP_STREAM_TRUNCATE_SET_SIZE: - return ftruncate(fd, *(size_t*)ptrparam) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; + case PHP_STREAM_TRUNCATE_SET_SIZE: { + ptrdiff_t new_size = *(ptrdiff_t*)ptrparam; + if (new_size < 0) { + return PHP_STREAM_OPTION_RETURN_ERR; + } + return ftruncate(fd, new_size) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; + } } default: @@ -862,12 +900,12 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha *opened_path = realpath; realpath = NULL; } - if (realpath) { - efree(realpath); - } /* fall through */ case PHP_STREAM_PERSISTENT_FAILURE: + if (realpath) { + efree(realpath); + } efree(persistent_id);; return ret; } @@ -877,7 +915,11 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha if (fd != -1) { - ret = php_stream_fopen_from_fd_rel(fd, mode, persistent_id); + if (options & STREAM_OPEN_FOR_INCLUDE) { + ret = php_stream_fopen_from_fd_int_rel(fd, mode, persistent_id); + } else { + ret = php_stream_fopen_from_fd_rel(fd, mode, persistent_id); + } if (ret) { if (opened_path) { @@ -891,6 +933,8 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha efree(persistent_id); } + /* WIN32 always set ISREG flag */ +#ifndef PHP_WIN32 /* sanity checks for include/require. * We check these after opening the stream, so that we save * on fstat() syscalls */ @@ -899,15 +943,16 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha int r; r = do_fstat(self, 0); - if ( -#ifndef PHP_WIN32 - (r != 0) || /* it is OK for fstat to fail under win32 */ -#endif - (r == 0 && !S_ISREG(self->sb.st_mode))) { + if ((r == 0 && !S_ISREG(self->sb.st_mode))) { + if (opened_path) { + efree(*opened_path); + *opened_path = NULL; + } php_stream_close(ret); return NULL; } } +#endif return ret; } @@ -1269,7 +1314,7 @@ not_relative_path: #ifdef PHP_WIN32 if (IS_SLASH(filename[0])) { - int cwd_len; + size_t cwd_len; char *cwd; cwd = virtual_getcwd_ex(&cwd_len TSRMLS_CC); /* getcwd() will return always return [DRIVE_LETTER]:/) on windows. */ diff --git a/main/streams/streams.c b/main/streams/streams.c index bd8901388..adc41beaa 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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 | @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.82.2.6.2.8 2006/10/03 19:51:01 iliaa Exp $ */ +/* $Id: streams.c,v 1.82.2.6.2.12 2007/03/03 19:01:34 helly Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -279,6 +279,10 @@ PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /* int preserve_handle = close_options & PHP_STREAM_FREE_PRESERVE_HANDLE ? 1 : 0; int release_cast = 1; + if (stream->flags & PHP_STREAM_FLAG_NO_CLOSE) { + preserve_handle = 1; + } + #if STREAM_DEBUG fprintf(stderr, "stream_free: %s:%p[%s] in_free=%d opts=%08x\n", stream->ops->label, stream, stream->orig_path, stream->in_free, close_options); #endif @@ -1449,12 +1453,12 @@ PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *w return FAILURE; } - return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len, &wrapper, sizeof(wrapper), NULL); + return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL); } PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC) { - return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol)); + return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol) + 1); } static void clone_wrapper_hash(TSRMLS_D) @@ -1479,7 +1483,7 @@ PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_w clone_wrapper_hash(TSRMLS_C); } - return zend_hash_add(FG(stream_wrappers), protocol, protocol_len, &wrapper, sizeof(wrapper), NULL); + return zend_hash_add(FG(stream_wrappers), protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL); } PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC) @@ -1488,7 +1492,7 @@ PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC) clone_wrapper_hash(TSRMLS_C); } - return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol)); + return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol) + 1); } /* }}} */ @@ -1521,11 +1525,11 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char php_error_docref(NULL TSRMLS_CC, E_WARNING, "Use of \"zlib:\" wrapper is deprecated; please use \"compress.zlib://\" instead."); } - if (protocol) { - if (FAILURE == zend_hash_find(wrapper_hash, (char*)protocol, n, (void**)&wrapperpp)) { - char *tmp = estrndup(protocol, n); + if (protocol) { + char *tmp = estrndup(protocol, n); + if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)&wrapperpp)) { php_strtolower(tmp, n); - if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n, (void**)&wrapperpp)) { + if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)&wrapperpp)) { char wrapper_name[32]; if (n >= sizeof(wrapper_name)) { @@ -1538,8 +1542,8 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char wrapperpp = NULL; protocol = NULL; } - efree(tmp); } + efree(tmp); } /* TODO: curl based streams probably support file:// properly */ if (!protocol || !strncasecmp(protocol, "file", n)) { @@ -1588,7 +1592,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char } /* Check again, the original check might have not known the protocol name */ - if (zend_hash_find(wrapper_hash, "file", sizeof("file")-1, (void**)&wrapperpp) == SUCCESS) { + if (zend_hash_find(wrapper_hash, "file", sizeof("file"), (void**)&wrapperpp) == SUCCESS) { return *wrapperpp; } @@ -1765,10 +1769,14 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio } if (wrapper) { - - stream = wrapper->wops->stream_opener(wrapper, + if (!wrapper->wops->stream_opener) { + php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC, + "wrapper does not support stream open"); + } else { + stream = wrapper->wops->stream_opener(wrapper, path_to_open, mode, options ^ REPORT_ERRORS, opened_path, context STREAMS_REL_CC TSRMLS_CC); + } /* if the caller asked for a persistent stream but the wrapper did not * return one, force an error here */ diff --git a/main/streams/transports.c b/main/streams/transports.c index c0ec5ec1d..36cf85a9c 100644 --- a/main/streams/transports.c +++ b/main/streams/transports.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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: transports.c,v 1.16.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: transports.c,v 1.16.2.1.2.4 2007/02/24 15:48:40 iliaa Exp $ */ #include "php.h" #include "php_streams_int.h" @@ -31,12 +31,12 @@ PHPAPI HashTable *php_stream_xport_get_hash(void) PHPAPI int php_stream_xport_register(char *protocol, php_stream_transport_factory factory TSRMLS_DC) { - return zend_hash_update(&xport_hash, protocol, strlen(protocol), &factory, sizeof(factory), NULL); + return zend_hash_update(&xport_hash, protocol, strlen(protocol) + 1, &factory, sizeof(factory), NULL); } PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC) { - return zend_hash_del(&xport_hash, protocol, strlen(protocol)); + return zend_hash_del(&xport_hash, protocol, strlen(protocol) + 1); } #define ERR_REPORT(out_err, fmt, arg) \ @@ -106,7 +106,8 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int } if (protocol) { - if (FAILURE == zend_hash_find(&xport_hash, (char*)protocol, n, (void**)&factory)) { + char *tmp = estrndup(protocol, n); + if (FAILURE == zend_hash_find(&xport_hash, (char*)tmp, n + 1, (void**)&factory)) { char wrapper_name[32]; if (n >= sizeof(wrapper_name)) @@ -116,8 +117,10 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int ERR_REPORT(error_string, "Unable to find the socket transport \"%s\" - did you forget to enable it when you configured PHP?", wrapper_name); + efree(tmp); return NULL; } + efree(tmp); } if (factory == NULL) { @@ -136,7 +139,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int if ((flags & STREAM_XPORT_SERVER) == 0) { /* client */ - if (flags & STREAM_XPORT_CONNECT) { + if (flags & (STREAM_XPORT_CONNECT|STREAM_XPORT_CONNECT_ASYNC)) { if (-1 == php_stream_xport_connect(stream, name, namelen, flags & STREAM_XPORT_CONNECT_ASYNC ? 1 : 0, timeout, &error_text, error_code TSRMLS_CC)) { @@ -486,6 +489,25 @@ PHPAPI int php_stream_xport_sendto(php_stream *stream, const char *buf, size_t b return -1; } +/* Similar to shutdown() system call; shut down part of a full-duplex + * connection */ +PHPAPI int php_stream_xport_shutdown(php_stream *stream, stream_shutdown_t how TSRMLS_DC) +{ + php_stream_xport_param param; + int ret = 0; + + memset(¶m, 0, sizeof(param)); + + param.op = STREAM_XPORT_OP_SHUTDOWN; + param.how = how; + + ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, ¶m); + + if (ret == PHP_STREAM_OPTION_RETURN_OK) { + return param.outputs.returncode; + } + return -1; +} /* * Local variables: diff --git a/main/streams/userspace.c b/main/streams/userspace.c index dc99c5c66..6bf110abc 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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: userspace.c,v 1.31.2.3.2.1 2006/08/14 15:01:29 tony2001 Exp $ */ +/* $Id: userspace.c,v 1.31.2.3.2.4 2007/02/13 19:50:59 tony2001 Exp $ */ #include "php.h" #include "php_globals.h" @@ -455,7 +455,7 @@ PHP_FUNCTION(stream_wrapper_register) RETURN_TRUE; } else { /* We failed. But why? */ - if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol, protocol_len)) { + if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol, protocol_len + 1)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Protocol %s:// is already defined.", protocol); } else { /* Should never happen */ @@ -511,7 +511,7 @@ PHP_FUNCTION(stream_wrapper_restore) RETURN_TRUE; } - if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len, (void**)&wrapperpp) == FAILURE) || !wrapperpp) { + if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len + 1, (void**)&wrapperpp) == FAILURE) || !wrapperpp) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s:// never existed, nothing to restore", protocol); RETURN_FALSE; } @@ -759,6 +759,10 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o retval = NULL; } + if (ret) { + return ret; + } + /* now determine where we are */ ZVAL_STRINGL(&func_name, USERSTREAM_TELL, sizeof(USERSTREAM_TELL)-1, 0); @@ -768,16 +772,20 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_LONG) + if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_LONG) { *newoffs = Z_LVAL_P(retval); - else - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_TELL " is not implemented!", - us->wrapper->classname); + ret = 0; + } else if (call_result == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_TELL " is not implemented!", us->wrapper->classname); + ret = -1; + } else { + ret = -1; + } - if (retval) + if (retval) { zval_ptr_dtor(&retval); - - return 0; + } + return ret; } /* parse the return value from one of the stat functions and store the diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index 60084545d..63d6b3e1b 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 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: xp_socket.c,v 1.33.2.2.2.1 2006/10/11 12:53:56 tony2001 Exp $ */ +/* $Id: xp_socket.c,v 1.33.2.2.2.4 2007/01/01 09:36:12 sebastian Exp $ */ #include "php.h" #include "ext/standard/file.h" @@ -369,6 +369,24 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void return PHP_STREAM_OPTION_RETURN_OK; +#ifdef HAVE_SHUTDOWN +# ifndef SHUT_RD +# define SHUT_RD 0 +# endif +# ifndef SHUT_WR +# define SHUT_WR 1 +# endif +# ifndef SHUT_RDWR +# define SHUT_RDWR 2 +# endif + case STREAM_XPORT_OP_SHUTDOWN: { + static const int shutdown_how[] = {SHUT_RD, SHUT_WR, SHUT_RDWR}; + + xparam->outputs.returncode = shutdown(sock->socket, shutdown_how[xparam->how]); + return PHP_STREAM_OPTION_RETURN_OK; + } +#endif + default: return PHP_STREAM_OPTION_RETURN_NOTIMPL; } @@ -624,6 +642,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_ if (xparam->want_errortext) { spprintf(&xparam->outputs.error_text, 0, "local_addr context option is not a string."); } + efree(host); return -1; } bindto = parse_ip_address_ex(Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval), &bindport, xparam->want_errortext, &xparam->outputs.error_text TSRMLS_CC); |
