summaryrefslogtreecommitdiff
path: root/main/streams
diff options
context:
space:
mode:
Diffstat (limited to 'main/streams')
-rw-r--r--main/streams/cast.c4
-rw-r--r--main/streams/filter.c69
-rw-r--r--main/streams/memory.c4
-rw-r--r--main/streams/mmap.c4
-rw-r--r--main/streams/php_stream_context.h4
-rw-r--r--main/streams/php_stream_filter_api.h6
-rw-r--r--main/streams/php_stream_mmap.h4
-rw-r--r--main/streams/php_stream_plain_wrapper.h4
-rw-r--r--main/streams/php_stream_transport.h4
-rw-r--r--main/streams/php_stream_userspace.h4
-rw-r--r--main/streams/php_streams_int.h4
-rw-r--r--main/streams/plain_wrapper.c13
-rwxr-xr-xmain/streams/streams.c46
-rw-r--r--main/streams/transports.c4
-rw-r--r--main/streams/userspace.c26
-rw-r--r--main/streams/xp_socket.c8
16 files changed, 134 insertions, 74 deletions
diff --git a/main/streams/cast.c b/main/streams/cast.c
index e2c65d8a0..5694300b4 100644
--- a/main/streams/cast.c
+++ b/main/streams/cast.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.2.2 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: cast.c,v 1.12.2.1.2.3 2008/12/31 11:17:48 sebastian Exp $ */
#define _GNU_SOURCE
#include "php.h"
diff --git a/main/streams/filter.c b/main/streams/filter.c
index 334fd81d8..b74d2def0 100644
--- a/main/streams/filter.c
+++ b/main/streams/filter.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.11 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: filter.c,v 1.17.2.3.2.14 2009/01/08 17:03:42 lbarnaud Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -313,7 +313,7 @@ PHPAPI void php_stream_filter_free(php_stream_filter *filter TSRMLS_DC)
pefree(filter, filter->is_persistent);
}
-PHPAPI void _php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC)
+PHPAPI int php_stream_filter_prepend_ex(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC)
{
filter->next = chain->head;
filter->prev = NULL;
@@ -325,9 +325,16 @@ PHPAPI void _php_stream_filter_prepend(php_stream_filter_chain *chain, php_strea
}
chain->head = filter;
filter->chain = chain;
+
+ return SUCCESS;
}
-PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC)
+PHPAPI void _php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC)
+{
+ php_stream_filter_prepend_ex(chain, filter TSRMLS_CC);
+}
+
+PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC)
{
php_stream *stream = chain->stream;
@@ -349,7 +356,7 @@ PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream
php_stream_bucket *bucket;
size_t consumed = 0;
- bucket = php_stream_bucket_new(stream, stream->readbuf + stream->readpos, stream->writepos - stream->readpos, 0, 0 TSRMLS_CC);
+ bucket = php_stream_bucket_new(stream, (char*) stream->readbuf + stream->readpos, stream->writepos - stream->readpos, 0, 0 TSRMLS_CC);
php_stream_bucket_append(brig_inp, bucket TSRMLS_CC);
status = filter->fops->filter(stream, filter, brig_inp, brig_outp, &consumed, PSFS_FLAG_NORMAL TSRMLS_CC);
@@ -360,19 +367,18 @@ PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream
switch (status) {
case PSFS_ERR_FATAL:
- /* If this first cycle simply fails then there's something wrong with the filter.
- Pull the filter off the chain and leave the read buffer alone. */
- if (chain->head == filter) {
- chain->head = NULL;
- chain->tail = NULL;
- } else {
- filter->prev->next = NULL;
- chain->tail = filter->prev;
+ while (brig_in.head) {
+ bucket = brig_in.head;
+ php_stream_bucket_unlink(bucket TSRMLS_CC);
+ php_stream_bucket_delref(bucket TSRMLS_CC);
}
- php_stream_bucket_unlink(bucket TSRMLS_CC);
- php_stream_bucket_delref(bucket TSRMLS_CC);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Filter failed to process pre-buffered data. Not adding to filterchain.");
- break;
+ while (brig_out.head) {
+ bucket = brig_out.head;
+ php_stream_bucket_unlink(bucket TSRMLS_CC);
+ php_stream_bucket_delref(bucket TSRMLS_CC);
+ }
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Filter failed to process pre-buffered data");
+ return FAILURE;
case PSFS_FEED_ME:
/* We don't actually need data yet,
leave this filter in a feed me state until data is needed.
@@ -381,15 +387,12 @@ PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream
stream->writepos = 0;
break;
case PSFS_PASS_ON:
- /* Put any filtered data onto the readbuffer stack.
- Previously read data has been at least partially consumed. */
- stream->readpos += consumed;
-
- if (stream->writepos == stream->readpos) {
- /* Entirely consumed */
- stream->writepos = 0;
- stream->readpos = 0;
- }
+ /* If any data is consumed, we cannot rely upon the existing read buffer,
+ as the filtered data must replace the existing data, so invalidate the cache */
+ /* note that changes here should be reflected in
+ main/streams/streams.c::php_stream_fill_read_buffer */
+ stream->writepos = 0;
+ stream->readpos = 0;
while (brig_outp->head) {
bucket = brig_outp->head;
@@ -409,6 +412,20 @@ PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream
}
}
+ return SUCCESS;
+}
+
+PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC)
+{
+ if (php_stream_filter_append_ex(chain, filter TSRMLS_CC) != SUCCESS) {
+ if (chain->head == filter) {
+ chain->head = NULL;
+ chain->tail = NULL;
+ } else {
+ filter->prev->next = NULL;
+ chain->tail = filter->prev;
+ }
+ }
}
PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish TSRMLS_DC)
diff --git a/main/streams/memory.c b/main/streams/memory.c
index bbd900734..0c1e34bbf 100644
--- a/main/streams/memory.c
+++ b/main/streams/memory.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.19 2008/03/15 10:28:53 felipe Exp $ */
+/* $Id: memory.c,v 1.8.2.6.2.20 2008/12/31 11:17:48 sebastian Exp $ */
#define _GNU_SOURCE
#include "php.h"
diff --git a/main/streams/mmap.c b/main/streams/mmap.c
index 7f7a88ec4..a70bf5805 100644
--- a/main/streams/mmap.c
+++ b/main/streams/mmap.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.2.2 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: mmap.c,v 1.8.2.1.2.3 2008/12/31 11:17:48 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 f1619a6ae..995d4156c 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-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.2.2 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: php_stream_context.h,v 1.11.2.1.2.3 2008/12/31 11:17:48 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 0870e64c2..d4030d62e 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-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.2.3 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: php_stream_filter_api.h,v 1.13.2.1.2.5 2009/01/08 17:03:42 lbarnaud Exp $ */
/* The filter API works on the principle of "Bucket-Brigades". This is
* partially inspired by the Apache 2 method of doing things, although
@@ -125,7 +125,9 @@ struct _php_stream_filter {
/* stack filter onto a stream */
BEGIN_EXTERN_C()
PHPAPI void _php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC);
+PHPAPI int php_stream_filter_prepend_ex(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC);
PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC);
+PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC);
PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish TSRMLS_DC);
PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, int call_dtor TSRMLS_DC);
PHPAPI void php_stream_filter_free(php_stream_filter *filter TSRMLS_DC);
diff --git a/main/streams/php_stream_mmap.h b/main/streams/php_stream_mmap.h
index 50f3bd815..1b3ad6d6b 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-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.2.2 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: php_stream_mmap.h,v 1.5.2.1.2.3 2008/12/31 11:17:48 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 eb7da457f..262f3f5d0 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-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.2.2 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: php_stream_plain_wrapper.h,v 1.7.2.2.2.3 2008/12/31 11:17:48 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 12300ad72..7bafbbd26 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-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.2.5 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: php_stream_transport.h,v 1.10.2.1.2.6 2008/12/31 11:17:48 sebastian Exp $ */
#if HAVE_SYS_SOCKET_H
# include <sys/socket.h>
diff --git a/main/streams/php_stream_userspace.h b/main/streams/php_stream_userspace.h
index 9277529f5..3016c154d 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-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.2.2 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: php_stream_userspace.h,v 1.5.2.1.2.3 2008/12/31 11:17:48 sebastian Exp $ */
/* for user-space streams */
diff --git a/main/streams/php_streams_int.h b/main/streams/php_streams_int.h
index b24555bb8..4b9826818 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-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.3 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: php_streams_int.h,v 1.7.2.2.2.4 2008/12/31 11:17:48 sebastian Exp $ */
#if ZEND_DEBUG
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index af665b716..d70f5f98b 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.27 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: plain_wrapper.c,v 1.52.2.6.2.32 2009/02/10 16:14:27 iliaa Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -242,6 +242,7 @@ PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const cha
#ifdef ESPIPE
if (stream->position == (off_t)-1 && errno == ESPIPE) {
stream->position = 0;
+ stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
self->is_pipe = 1;
}
#endif
@@ -1323,7 +1324,9 @@ not_relative_path:
/* getcwd() will return always return [DRIVE_LETTER]:/) on windows. */
*(cwd+3) = '\0';
- snprintf(trypath, MAXPATHLEN, "%s%s", cwd, filename);
+ if (snprintf(trypath, MAXPATHLEN, "%s%s", cwd, filename) >= MAXPATHLEN) {
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s/%s path was truncated to %d", cwd, filename, MAXPATHLEN);
+ }
free(cwd);
@@ -1384,7 +1387,9 @@ not_relative_path:
if (*ptr == '\0') {
goto stream_skip;
}
- snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename);
+ if (snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename) >= MAXPATHLEN) {
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s/%s path was truncated to %d", ptr, filename, MAXPATHLEN);
+ }
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir_ex(trypath, 0 TSRMLS_CC)) {
goto stream_skip;
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 2352bfbcc..ddd7a2c7e 100755
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.22 2008/03/24 16:28:56 tony2001 Exp $ */
+/* $Id: streams.c,v 1.82.2.6.2.33 2009/01/08 19:21:25 felipe Exp $ */
#define _GNU_SOURCE
#include "php.h"
@@ -164,7 +164,11 @@ void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char *
free_msg = 1;
} else {
- msg = strerror(errno);
+ if (wrapper == &php_plain_files_wrapper) {
+ msg = strerror(errno);
+ } else {
+ msg = "operation failed";
+ }
}
} else {
msg = "no suitable wrapper could be found";
@@ -434,6 +438,10 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D
php_stream_bucket_brigade brig_in = { NULL, NULL }, brig_out = { NULL, NULL };
php_stream_bucket_brigade *brig_inp = &brig_in, *brig_outp = &brig_out, *brig_swap;
+ /* Invalidate the existing cache, otherwise reads can fail, see note in
+ main/streams/filter.c::_php_stream_filter_append */
+ stream->writepos = stream->readpos = 0;
+
/* allocate a buffer for reading chunks */
chunk_buf = emalloc(stream->chunk_size);
@@ -523,16 +531,16 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D
efree(chunk_buf);
} else {
+ /* reduce buffer memory consumption if possible, to avoid a realloc */
+ if (stream->readbuf && stream->readbuflen - stream->writepos < stream->chunk_size) {
+ memmove(stream->readbuf, stream->readbuf + stream->readpos, stream->readbuflen - stream->readpos);
+ stream->writepos -= stream->readpos;
+ stream->readpos = 0;
+ }
/* is there enough data in the buffer ? */
- if (stream->writepos - stream->readpos < (off_t)size) {
+ while (stream->writepos - stream->readpos < (off_t)size) {
size_t justread = 0;
-
- /* reduce buffer memory consumption if possible, to avoid a realloc */
- if (stream->readbuf && stream->readbuflen - stream->writepos < stream->chunk_size) {
- memmove(stream->readbuf, stream->readbuf + stream->readpos, stream->readbuflen - stream->readpos);
- stream->writepos -= stream->readpos;
- stream->readpos = 0;
- }
+ size_t toread;
/* grow the buffer if required
* TODO: this can fail for persistent streams */
@@ -542,13 +550,17 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D
stream->is_persistent);
}
+ toread = stream->readbuflen - stream->writepos;
justread = stream->ops->read(stream, stream->readbuf + stream->writepos,
- stream->readbuflen - stream->writepos
+ toread
TSRMLS_CC);
if (justread != (size_t)-1) {
stream->writepos += justread;
}
+ if (stream->eof || justread != toread) {
+ break;
+ }
}
}
}
@@ -869,6 +881,9 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
}
if (!e) {
+ if (seek_len < maxlen && !stream->eof) {
+ return NULL;
+ }
toread = maxlen;
} else {
toread = e - (char *) stream->readbuf - stream->readpos;
@@ -1219,7 +1234,7 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen
if (maxlen > 0) {
ptr = *buf = pemalloc_rel_orig(maxlen + 1, persistent);
- while ((len < maxlen) & !php_stream_eof(src)) {
+ while ((len < maxlen) && !php_stream_eof(src)) {
ret = php_stream_read(src, ptr, maxlen - len);
len += ret;
ptr += ret;
@@ -1503,7 +1518,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
n++;
}
- if ((*p == ':') && (n > 1) && (!strncmp("//", p+1, 2) || !memcmp("data", path, 4))) {
+ if ((*p == ':') && (n > 1) && (!strncmp("//", p+1, 2) || (n == 4 && !memcmp("data:", path, 5)))) {
protocol = path;
} else if (n == 5 && strncasecmp(path, "zlib:", 5) == 0) {
/* BC with older php scripts and zlib wrapper */
@@ -1706,7 +1721,7 @@ PHPAPI php_stream *_php_stream_opendir(char *path, int options,
if (stream) {
stream->wrapper = wrapper;
- stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
+ stream->flags |= PHP_STREAM_FLAG_NO_BUFFER | PHP_STREAM_FLAG_IS_DIR;
}
} else if (wrapper) {
php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC, "not implemented");
@@ -1748,6 +1763,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio
}
if (!path || !*path) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Filename cannot be empty");
return NULL;
}
diff --git a/main/streams/transports.c b/main/streams/transports.c
index 9c6aa00d9..fb337a2c5 100644
--- a/main/streams/transports.c
+++ b/main/streams/transports.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.2.5 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: transports.c,v 1.16.2.1.2.6 2008/12/31 11:17:48 sebastian Exp $ */
#include "php.h"
#include "php_streams_int.h"
diff --git a/main/streams/userspace.c b/main/streams/userspace.c
index ae18d05b0..16d433c68 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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,11 +17,15 @@
+----------------------------------------------------------------------+
*/
-/* $Id: userspace.c,v 1.31.2.3.2.8 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: userspace.c,v 1.31.2.3.2.10 2008/12/31 11:17:48 sebastian Exp $ */
#include "php.h"
#include "php_globals.h"
#include "ext/standard/file.h"
+#include "ext/standard/flock_compat.h"
+#ifdef HAVE_SYS_FILE_H
+#include <sys/file.h>
+#endif
static int le_protocols;
@@ -908,7 +912,23 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
case PHP_STREAM_OPTION_LOCKING:
MAKE_STD_ZVAL(zvalue);
- ZVAL_LONG(zvalue, value);
+ ZVAL_LONG(zvalue, 0);
+
+ if (value & LOCK_NB) {
+ Z_LVAL_P(zvalue) |= PHP_LOCK_NB;
+ }
+ switch(value & ~LOCK_NB) {
+ case LOCK_SH:
+ Z_LVAL_P(zvalue) |= PHP_LOCK_SH;
+ break;
+ case LOCK_EX:
+ Z_LVAL_P(zvalue) |= PHP_LOCK_EX;
+ break;
+ case LOCK_UN:
+ Z_LVAL_P(zvalue) |= PHP_LOCK_UN;
+ break;
+ }
+
args[0] = &zvalue;
/* TODO wouldblock */
diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c
index 0f6842aa8..5e7e41ada 100644
--- a/main/streams/xp_socket.c
+++ b/main/streams/xp_socket.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 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.9 2008/03/10 20:09:22 andrey Exp $ */
+/* $Id: xp_socket.c,v 1.33.2.2.2.15 2009/02/08 16:54:43 iliaa Exp $ */
#include "php.h"
#include "ext/standard/file.h"
@@ -281,7 +281,7 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
if (sock->socket == -1) {
alive = 0;
} else if (php_pollfd_for(sock->socket, PHP_POLLREADABLE|POLLPRI, &tv) > 0) {
- if (0 == recv(sock->socket, &buf, sizeof(buf), MSG_PEEK) && php_socket_errno() != EAGAIN) {
+ if (0 >= recv(sock->socket, &buf, sizeof(buf), MSG_PEEK) && php_socket_errno() != EWOULDBLOCK) {
alive = 0;
}
}
@@ -621,7 +621,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
parse_unix_address(xparam, &unix_addr TSRMLS_CC);
ret = php_network_connect_socket(sock->socket,
- (const struct sockaddr *)&unix_addr, (socklen_t)sizeof(unix_addr),
+ (const struct sockaddr *)&unix_addr, (socklen_t) XtOffsetOf(struct sockaddr_un, sun_path) + xparam->inputs.namelen,
xparam->op == STREAM_XPORT_OP_CONNECT_ASYNC, xparam->inputs.timeout,
xparam->want_errortext ? &xparam->outputs.error_text : NULL,
&err);