summaryrefslogtreecommitdiff
path: root/main/streams
diff options
context:
space:
mode:
authorMark A. Hershberger <mah@debian.(none)>2009-03-25 00:36:21 -0400
committerMark A. Hershberger <mah@debian.(none)>2009-03-25 00:36:21 -0400
commitd29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (patch)
treeb38e2e5c6974b9a15f103e5cf884cba9fff90ef4 /main/streams
parenta88a88d0986a4a32288c102cdbfebd78d7e91d99 (diff)
downloadphp-upstream/5.2.0.tar.gz
Imported Upstream version 5.2.0upstream/5.2.0
Diffstat (limited to 'main/streams')
-rw-r--r--main/streams/filter.c8
-rw-r--r--main/streams/memory.c320
-rw-r--r--main/streams/php_streams_int.h11
-rw-r--r--main/streams/plain_wrapper.c56
-rwxr-xr-xmain/streams/streams.c47
-rw-r--r--main/streams/userspace.c36
-rw-r--r--main/streams/xp_socket.c11
7 files changed, 374 insertions, 115 deletions
diff --git a/main/streams/filter.c b/main/streams/filter.c
index f601fa8c5..0bb19c202 100644
--- a/main/streams/filter.c
+++ b/main/streams/filter.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: filter.c,v 1.17.2.4 2006/05/19 10:24:19 tony2001 Exp $ */
+/* $Id: filter.c,v 1.17.2.3.2.3 2006/10/11 23:11:26 pollita Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -61,7 +61,7 @@ PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern
php_stream_filter_factory tmpfactory;
ALLOC_HASHTABLE(FG(stream_filters));
- zend_hash_init(FG(stream_filters), 0, NULL, NULL, 1);
+ zend_hash_init(FG(stream_filters), zend_hash_num_elements(&stream_filters_hash), NULL, NULL, 1);
zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL, &tmpfactory, sizeof(php_stream_filter_factory));
}
@@ -224,12 +224,12 @@ PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket TSRMLS_DC)
{
if (bucket->prev) {
bucket->prev->next = bucket->next;
- } else {
+ } else if (bucket->brigade) {
bucket->brigade->head = bucket->next;
}
if (bucket->next) {
bucket->next->prev = bucket->prev;
- } else {
+ } else if (bucket->brigade) {
bucket->brigade->tail = bucket->prev;
}
bucket->brigade = NULL;
diff --git a/main/streams/memory.c b/main/streams/memory.c
index 30b1caad6..818e5a813 100644
--- a/main/streams/memory.c
+++ b/main/streams/memory.c
@@ -16,11 +16,14 @@
+----------------------------------------------------------------------+
*/
-/* $Id: memory.c,v 1.8.2.6 2006/03/18 19:57:00 helly Exp $ */
+/* $Id: memory.c,v 1.8.2.6.2.8 2006/06/29 14:40:49 bjori Exp $ */
#define _GNU_SOURCE
#include "php.h"
+PHPAPI int php_url_decode(char *str, int len);
+PHPAPI unsigned char *php_base64_decode(const unsigned char *str, int length, int *ret_length);
+
/* Memory streams use a dynamic memory buffer to emulate a stream.
* You can use php_stream_memory_open to create a readonly stream
* from an existing memory buffer.
@@ -46,10 +49,7 @@ typedef struct {
/* {{{ */
static size_t php_stream_memory_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
{
- php_stream_memory_data *ms;
-
- assert(stream != NULL);
- ms = stream->abstract;
+ php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
assert(ms != NULL);
if (ms->mode & TEMP_STREAM_READONLY) {
@@ -85,22 +85,18 @@ static size_t php_stream_memory_write(php_stream *stream, const char *buf, size_
/* {{{ */
static size_t php_stream_memory_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
{
- php_stream_memory_data *ms;
-
- assert(stream != NULL);
- ms = stream->abstract;
+ php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
assert(ms != NULL);
- if (ms->fpos + count > ms->fsize) {
+ if (ms->fpos + count >= ms->fsize) {
count = ms->fsize - ms->fpos;
+ stream->eof = 1;
}
if (count) {
assert(ms->data!= NULL);
assert(buf!= NULL);
memcpy(buf, ms->data+ms->fpos, count);
ms->fpos += count;
- } else {
- stream->eof = 1;
}
return count;
}
@@ -110,10 +106,7 @@ static size_t php_stream_memory_read(php_stream *stream, char *buf, size_t count
/* {{{ */
static int php_stream_memory_close(php_stream *stream, int close_handle TSRMLS_DC)
{
- php_stream_memory_data *ms;
-
- assert(stream != NULL);
- ms = stream->abstract;
+ php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
assert(ms != NULL);
if (ms->data && close_handle && ms->mode != TEMP_STREAM_READONLY) {
@@ -140,10 +133,7 @@ static int php_stream_memory_flush(php_stream *stream TSRMLS_DC)
/* {{{ */
static int php_stream_memory_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC)
{
- php_stream_memory_data *ms;
-
- assert(stream != NULL);
- ms = stream->abstract;
+ php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
assert(ms != NULL);
switch(whence) {
@@ -156,6 +146,7 @@ static int php_stream_memory_seek(php_stream *stream, off_t offset, int whence,
} else {
ms->fpos = ms->fpos + offset;
*newoffs = ms->fpos;
+ stream->eof = 0;
return 0;
}
} else {
@@ -166,6 +157,7 @@ static int php_stream_memory_seek(php_stream *stream, off_t offset, int whence,
} else {
ms->fpos = ms->fpos + offset;
*newoffs = ms->fpos;
+ stream->eof = 0;
return 0;
}
}
@@ -177,6 +169,7 @@ static int php_stream_memory_seek(php_stream *stream, off_t offset, int whence,
} else {
ms->fpos = offset;
*newoffs = ms->fpos;
+ stream->eof = 0;
return 0;
}
case SEEK_END:
@@ -191,6 +184,7 @@ static int php_stream_memory_seek(php_stream *stream, off_t offset, int whence,
} else {
ms->fpos = ms->fsize + offset;
*newoffs = ms->fpos;
+ stream->eof = 0;
return 0;
}
default:
@@ -207,6 +201,45 @@ static int php_stream_memory_cast(php_stream *stream, int castas, void **ret TSR
}
/* }}} */
+static int php_stream_memory_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) /* {{{ */
+{
+ time_t timestamp = 0;
+ php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
+ assert(ms != NULL);
+
+ memset(ssb, 0, sizeof(php_stream_statbuf));
+ /* read-only across the board */
+
+ ssb->sb.st_mode = ms->mode & TEMP_STREAM_READONLY ? 0444 : 0666;
+
+ ssb->sb.st_size = ms->fsize;
+ ssb->sb.st_mode |= S_IFREG; /* regular file */
+
+#ifdef NETWARE
+ ssb->sb.st_mtime.tv_sec = timestamp;
+ ssb->sb.st_atime.tv_sec = timestamp;
+ ssb->sb.st_ctime.tv_sec = timestamp;
+#else
+ ssb->sb.st_mtime = timestamp;
+ ssb->sb.st_atime = timestamp;
+ ssb->sb.st_ctime = timestamp;
+#endif
+
+ ssb->sb.st_nlink = 1;
+ ssb->sb.st_rdev = -1;
+ /* this is only for APC, so use /dev/null device - no chance of conflict there! */
+ ssb->sb.st_dev = 0xC;
+ /* generate unique inode number for alias/filename, so no phars will conflict */
+ ssb->sb.st_ino = 0;
+
+#ifndef PHP_WIN32
+ ssb->sb.st_blksize = -1;
+ ssb->sb.st_blocks = -1;
+#endif
+
+ return 0;
+}
+/* }}} */
php_stream_ops php_stream_memory_ops = {
php_stream_memory_write, php_stream_memory_read,
@@ -214,7 +247,7 @@ php_stream_ops php_stream_memory_ops = {
"MEMORY",
php_stream_memory_seek,
php_stream_memory_cast,
- NULL, /* stat */
+ php_stream_memory_stat,
NULL /* set_option */
};
@@ -229,7 +262,7 @@ PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC TSRMLS_DC)
self->data = NULL;
self->fpos = 0;
self->fsize = 0;
- self->smax = -1;
+ self->smax = ~0u;
self->mode = mode;
self->owner_ptr = NULL;
@@ -247,7 +280,7 @@ PHPAPI php_stream *_php_stream_memory_open(int mode, char *buf, size_t length ST
php_stream_memory_data *ms;
if ((stream = php_stream_memory_create_rel(mode)) != NULL) {
- ms = stream->abstract;
+ ms = (php_stream_memory_data*)stream->abstract;
if (mode == TEMP_STREAM_READONLY || mode == TEMP_STREAM_TAKE_BUFFER) {
/* use the buffer directly */
@@ -268,10 +301,8 @@ PHPAPI php_stream *_php_stream_memory_open(int mode, char *buf, size_t length ST
/* {{{ */
PHPAPI char *_php_stream_memory_get_buffer(php_stream *stream, size_t *length STREAMS_DC TSRMLS_DC)
{
- php_stream_memory_data *ms;
+ php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
- assert(stream != NULL);
- ms = stream->abstract;
assert(ms != NULL);
assert(length != 0);
@@ -288,16 +319,14 @@ typedef struct {
php_stream *innerstream;
size_t smax;
int mode;
+ zval* meta;
} php_stream_temp_data;
/* {{{ */
static size_t php_stream_temp_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
{
- php_stream_temp_data *ts;
-
- assert(stream != NULL);
- ts = stream->abstract;
+ php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
assert(ts != NULL);
if (!ts->innerstream) {
@@ -322,11 +351,9 @@ static size_t php_stream_temp_write(php_stream *stream, const char *buf, size_t
/* {{{ */
static size_t php_stream_temp_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
{
- php_stream_temp_data *ts;
+ php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
size_t got;
- assert(stream != NULL);
- ts = stream->abstract;
assert(ts != NULL);
if (!ts->innerstream) {
@@ -335,9 +362,7 @@ static size_t php_stream_temp_read(php_stream *stream, char *buf, size_t count T
got = php_stream_read(ts->innerstream, buf, count);
- if (!got) {
- stream->eof |= ts->innerstream->eof;
- }
+ stream->eof = ts->innerstream->eof;
return got;
}
@@ -347,11 +372,9 @@ static size_t php_stream_temp_read(php_stream *stream, char *buf, size_t count T
/* {{{ */
static int php_stream_temp_close(php_stream *stream, int close_handle TSRMLS_DC)
{
- php_stream_temp_data *ts;
+ php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
int ret;
- assert(stream != NULL);
- ts = stream->abstract;
assert(ts != NULL);
if (ts->innerstream) {
@@ -359,6 +382,10 @@ static int php_stream_temp_close(php_stream *stream, int close_handle TSRMLS_DC)
} else {
ret = 0;
}
+
+ if (ts->meta) {
+ zval_ptr_dtor(&ts->meta);
+ }
efree(ts);
@@ -370,10 +397,7 @@ static int php_stream_temp_close(php_stream *stream, int close_handle TSRMLS_DC)
/* {{{ */
static int php_stream_temp_flush(php_stream *stream TSRMLS_DC)
{
- php_stream_temp_data *ts;
-
- assert(stream != NULL);
- ts = stream->abstract;
+ php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
assert(ts != NULL);
return ts->innerstream ? php_stream_flush(ts->innerstream) : -1;
@@ -384,11 +408,9 @@ static int php_stream_temp_flush(php_stream *stream TSRMLS_DC)
/* {{{ */
static int php_stream_temp_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC)
{
- php_stream_temp_data *ts;
+ php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
int ret;
- assert(stream != NULL);
- ts = stream->abstract;
assert(ts != NULL);
if (!ts->innerstream) {
@@ -397,6 +419,7 @@ static int php_stream_temp_seek(php_stream *stream, off_t offset, int whence, of
}
ret = php_stream_seek(ts->innerstream, offset, whence);
*newoffs = php_stream_tell(ts->innerstream);
+ stream->eof = ts->innerstream->eof;
return ret;
}
@@ -405,14 +428,12 @@ static int php_stream_temp_seek(php_stream *stream, off_t offset, int whence, of
/* {{{ */
static int php_stream_temp_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
{
- php_stream_temp_data *ts;
+ php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
php_stream *file;
size_t memsize;
char *membuf;
off_t pos;
- assert(stream != NULL);
- ts = stream->abstract;
assert(ts != NULL);
if (!ts->innerstream) {
@@ -450,14 +471,41 @@ static int php_stream_temp_cast(php_stream *stream, int castas, void **ret TSRML
}
/* }}} */
+static int php_stream_temp_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) /* {{{ */
+{
+ php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
+
+ if (!ts || !ts->innerstream) {
+ return -1;
+ }
+ return php_stream_stat(ts->innerstream, ssb);
+}
+/* }}} */
+
+static int php_stream_temp_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) /* {{{ */
+{
+ php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
+
+ switch(option) {
+ case PHP_STREAM_OPTION_META_DATA_API:
+ if (ts->meta) {
+ zend_hash_copy(Z_ARRVAL_P((zval*)ptrparam), Z_ARRVAL_P(ts->meta), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*));
+ }
+ return PHP_STREAM_OPTION_RETURN_OK;
+ default:
+ return PHP_STREAM_OPTION_RETURN_NOTIMPL;
+ }
+}
+/* }}} */
+
php_stream_ops php_stream_temp_ops = {
php_stream_temp_write, php_stream_temp_read,
php_stream_temp_close, php_stream_temp_flush,
"TEMP",
php_stream_temp_seek,
php_stream_temp_cast,
- NULL, /* stat */
- NULL /* set_option */
+ php_stream_temp_stat,
+ php_stream_temp_set_option
};
/* }}} */
@@ -471,6 +519,7 @@ PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STR
self = ecalloc(1, sizeof(*self));
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->flags |= PHP_STREAM_FLAG_NO_BUFFER;
self->innerstream = php_stream_memory_create(mode);
@@ -485,21 +534,182 @@ PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STR
PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char *buf, size_t length STREAMS_DC TSRMLS_DC)
{
php_stream *stream;
- php_stream_temp_data *ms;
+ php_stream_temp_data *ts;
+ off_t newoffs;
if ((stream = php_stream_temp_create_rel(mode, max_memory_usage)) != NULL) {
if (length) {
assert(buf != NULL);
php_stream_temp_write(stream, buf, length TSRMLS_CC);
+ php_stream_temp_seek(stream, 0, SEEK_SET, &newoffs TSRMLS_CC);
}
- ms = stream->abstract;
- assert(ms != NULL);
- ms->mode = mode;
+ ts = (php_stream_temp_data*)stream->abstract;
+ assert(ts != NULL);
+ ts->mode = mode;
}
return stream;
}
/* }}} */
+php_stream_ops php_stream_rfc2397_ops = {
+ php_stream_temp_write, php_stream_temp_read,
+ php_stream_temp_close, php_stream_temp_flush,
+ "RFC2397",
+ php_stream_temp_seek,
+ php_stream_temp_cast,
+ php_stream_temp_stat,
+ php_stream_temp_set_option
+};
+
+static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) /* {{{ */
+{
+ php_stream *stream;
+ php_stream_temp_data *ts;
+ char *comma, *semi, *sep, *key;
+ size_t mlen, dlen, plen, vlen;
+ off_t newoffs;
+ zval *meta = NULL;
+ int base64 = 0, ilen;
+
+ if (memcmp(path, "data:", 5)) {
+ return NULL;
+ }
+
+ path += 5;
+ dlen = strlen(path);
+
+ if (dlen >= 2 && path[0] == '/' && path[1] == '/') {
+ dlen -= 2;
+ path += 2;
+ }
+
+ if ((comma = memchr(path, ',', dlen)) == NULL) {
+ php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "rfc2397: no comma in URL");
+ return NULL;
+ }
+
+ if (comma != path) {
+ /* meta info */
+ mlen = comma - path;
+ dlen -= mlen;
+ semi = memchr(path, ';', mlen);
+ sep = memchr(path, '/', mlen);
+
+ if (!semi && !sep) {
+ php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "rfc2397: illegal media type");
+ return NULL;
+ }
+
+ MAKE_STD_ZVAL(meta);
+ array_init(meta);
+ if (!semi) { /* there is only a mime type */
+ add_assoc_stringl(meta, "mediatype", path, mlen, 1);
+ mlen = 0;
+ } else if (sep && sep < semi) { /* there is a mime type */
+ plen = semi - path;
+ add_assoc_stringl(meta, "mediatype", path, plen, 1);
+ mlen -= plen;
+ path += plen;
+ } else if (semi != path || mlen != sizeof(";base64")-1 || memcmp(path, ";base64", sizeof(";base64")-1)) { /* must be error since parameters are only allowed after mediatype */
+ zval_ptr_dtor(&meta);
+ php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "rfc2397: illegal media type");
+ return NULL;
+ }
+ /* get parameters and potentially ';base64' */
+ while(semi && (semi == path)) {
+ path++;
+ mlen--;
+ sep = memchr(path, '=', mlen);
+ semi = memchr(path, ';', mlen);
+ if (!sep || (semi && semi < sep)) { /* must be ';base64' or failure */
+ if (mlen != sizeof("base64")-1 || memcmp(path, "base64", sizeof("base64")-1)) {
+ /* must be error since parameters are only allowed after mediatype and we have no '=' sign */
+ zval_ptr_dtor(&meta);
+ php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "rfc2397: illegal parameter");
+ return NULL;
+ }
+ base64 = 1;
+ mlen -= sizeof("base64") - 1;
+ path += sizeof("base64") - 1;
+ break;
+ }
+ /* found parameter ... the heart of cs ppl lies in +1/-1 or was it +2 this time? */
+ plen = sep - path;
+ vlen = (semi ? semi - sep : mlen - plen) - 1 /* '=' */;
+ key = estrndup(path, plen);
+ add_assoc_stringl_ex(meta, key, plen + 1, sep + 1, vlen, 1);
+ efree(key);
+ plen += vlen + 1;
+ mlen -= plen;
+ path += plen;
+ }
+ if (mlen) {
+ zval_ptr_dtor(&meta);
+ php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "rfc2397: illegal URL");
+ return NULL;
+ }
+ } else {
+ MAKE_STD_ZVAL(meta);
+ array_init(meta);
+ }
+ add_assoc_bool(meta, "base64", base64);
+
+ /* skip ',' */
+ comma++;
+ dlen--;
+
+ if (base64) {
+ comma = (char*)php_base64_decode((const unsigned char *)comma, dlen, &ilen);
+ if (!comma) {
+ zval_ptr_dtor(&meta);
+ php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "rfc2397: unable to decode");
+ return NULL;
+ }
+ } else {
+ comma = estrndup(comma, dlen);
+ ilen = dlen = php_url_decode(comma, dlen);
+ }
+
+ 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);
+ if (vlen >= sizeof(stream->mode)) {
+ vlen = sizeof(stream->mode) - 1;
+ }
+ memcpy(stream->mode, mode, vlen);
+ stream->mode[vlen] = '\0';
+ 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->meta = meta;
+ }
+
+ return stream;
+}
+
+static php_stream_wrapper_ops php_stream_rfc2397_wops = {
+ php_stream_url_wrap_rfc2397,
+ NULL, /* close */
+ NULL, /* fstat */
+ NULL, /* stat */
+ NULL, /* opendir */
+ "RFC2397",
+ NULL, /* unlink */
+ NULL, /* rename */
+ NULL, /* mkdir */
+ NULL /* rmdir */
+};
+
+php_stream_wrapper php_stream_rfc2397_wrapper = {
+ &php_stream_rfc2397_wops,
+ NULL,
+ 0, /* is_url */
+};
/*
* Local variables:
diff --git a/main/streams/php_streams_int.h b/main/streams/php_streams_int.h
index 4091235a3..1c037457a 100644
--- a/main/streams/php_streams_int.h
+++ b/main/streams/php_streams_int.h
@@ -16,25 +16,20 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_streams_int.h,v 1.7.2.2 2006/04/22 17:17:40 wez Exp $ */
+/* $Id: php_streams_int.h,v 1.7.2.2.2.1 2006/09/14 09:58:27 dmitry Exp $ */
#if ZEND_DEBUG
-#if USE_ZEND_ALLOC
-# define emalloc_rel_orig(size) \
+#define emalloc_rel_orig(size) \
( __php_stream_call_depth == 0 \
? _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_RELAY_CC) \
: _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC) )
-# define erealloc_rel_orig(ptr, size) \
+#define erealloc_rel_orig(ptr, size) \
( __php_stream_call_depth == 0 \
? _erealloc((ptr), (size), 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_RELAY_CC) \
: _erealloc((ptr), (size), 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC) )
-#else
-# define emalloc_rel_orig(size) emalloc(size)
-# define erealloc_rel_orig(ptr, size) erealloc(ptr, size)
-#endif
#define pemalloc_rel_orig(size, persistent) ((persistent) ? malloc((size)) : emalloc_rel_orig((size)))
#define perealloc_rel_orig(ptr, size, persistent) ((persistent) ? realloc((ptr), (size)) : erealloc_rel_orig((ptr), (size)))
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index 98a7bd636..6a62f021f 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: plain_wrapper.c,v 1.52.2.7 2006/08/22 06:16:19 dmitry Exp $ */
+/* $Id: plain_wrapper.c,v 1.52.2.6.2.8 2006/10/19 09:49:44 dmitry Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -242,10 +242,9 @@ PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STRE
#elif defined(PHP_WIN32)
{
long handle = _get_osfhandle(self->fd);
- DWORD in_buf_size, out_buf_size;
if (handle != 0xFFFFFFFF) {
- self->is_pipe = GetNamedPipeInfo((HANDLE)handle, NULL, &out_buf_size, &in_buf_size, NULL);
+ self->is_pipe = GetFileType((HANDLE)handle) == FILE_TYPE_PIPE;
}
}
#endif
@@ -373,7 +372,7 @@ static int php_stdiop_close(php_stream *stream, int close_handle TSRMLS_DC)
data->file = NULL;
}
} else if (data->fd != -1) {
-#ifdef PHP_DEBUG
+#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;
@@ -705,7 +704,7 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
delta = range->offset - loffs;
}
- data->last_mapped_addr = MapViewOfFile(data->file_mapping, acc, 0, loffs, range->length);
+ data->last_mapped_addr = MapViewOfFile(data->file_mapping, acc, 0, loffs, range->length + delta);
if (data->last_mapped_addr) {
/* give them back the address of the start offset they requested */
@@ -1088,7 +1087,18 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod
int offset = 0;
buf = estrndup(dir, dir_len);
+
+#ifdef PHP_WIN32
+ e = buf;
+ while (*e) {
+ if (*e == '/') {
+ *e = DEFAULT_SLASH;
+ }
+ e++;
+ }
+#else
e = buf + dir_len;
+#endif
if ((p = memchr(buf, DEFAULT_SLASH, dir_len))) {
offset = p - buf + 1;
@@ -1099,10 +1109,22 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod
}
else {
/* find a top level directory we need to create */
- while ( (p = strrchr(buf + offset, DEFAULT_SLASH)) || (p = strrchr(buf, DEFAULT_SLASH)) ) {
+ while ( (p = strrchr(buf + offset, DEFAULT_SLASH)) || ( offset !=1 && (p = strrchr(buf, DEFAULT_SLASH))) ) {
+ int n = 0;
+
*p = '\0';
+ while (p > buf && *(p-1) == DEFAULT_SLASH) {
+ ++n;
+ --p;
+ *p = '\0';
+ }
if (VCWD_STAT(buf, &sb) == 0) {
- *p = DEFAULT_SLASH;
+ while (1) {
+ *p = DEFAULT_SLASH;
+ if (!n) break;
+ --n;
+ ++p;
+ }
break;
}
}
@@ -1116,9 +1138,10 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod
}
/* create any needed directories if the creation of the 1st directory worked */
while (++p != e) {
- if (*p == '\0' && *(p + 1) != '\0') {
+ if (*p == '\0') {
*p = DEFAULT_SLASH;
- if ((ret = VCWD_MKDIR(buf, (mode_t)mode)) < 0) {
+ if ((*(p+1) != '\0') &&
+ (ret = VCWD_MKDIR(buf, (mode_t)mode)) < 0) {
if (options & REPORT_ERRORS) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
}
@@ -1271,11 +1294,6 @@ not_relative_path:
#endif
if (!path || (path && !*path)) {
-
- if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) {
- return NULL;
- }
-
if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) {
return NULL;
}
@@ -1315,11 +1333,13 @@ not_relative_path:
*end = '\0';
end++;
}
+ if (*ptr == '\0') {
+ goto stream_skip;
+ }
snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename);
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir_ex(trypath, 0 TSRMLS_CC)) {
- ptr = end;
- continue;
+ goto stream_skip;
}
if (PG(safe_mode)) {
@@ -1332,8 +1352,7 @@ not_relative_path:
goto stream_done;
}
}
- ptr = end;
- continue;
+ goto stream_skip;
}
stream = php_stream_fopen_rel(trypath, mode, opened_path, options);
if (stream) {
@@ -1341,6 +1360,7 @@ stream_done:
efree(pathbuf);
return stream;
}
+stream_skip:
ptr = end;
} /* end provided path */
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 745b4c0aa..bd8901388 100755
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streams.c,v 1.82.2.6 2006/04/22 17:17:40 wez Exp $ */
+/* $Id: streams.c,v 1.82.2.6.2.8 2006/10/03 19:51:01 iliaa Exp $ */
#define _GNU_SOURCE
#include "php.h"
@@ -1198,10 +1198,6 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen
int min_room = CHUNK_SIZE / 4;
php_stream_statbuf ssbuf;
- if (buf) {
- *buf = NULL;
- }
-
if (maxlen == 0) {
return 0;
}
@@ -1216,7 +1212,7 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen
p = php_stream_mmap_range(src, php_stream_tell(src), maxlen, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped);
- if (p) {
+ if (p && mapped) {
*buf = pemalloc_rel_orig(mapped + 1, persistent);
if (*buf) {
@@ -1348,11 +1344,7 @@ PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size
writeptr += didwrite;
}
} else {
- if (maxlen == 0) {
- return haveread;
- } else {
- return 0; /* error */
- }
+ return haveread;
}
if (maxlen - haveread == 0) {
@@ -1470,7 +1462,7 @@ static void clone_wrapper_hash(TSRMLS_D)
php_stream_wrapper *tmp;
ALLOC_HASHTABLE(FG(stream_wrappers));
- zend_hash_init(FG(stream_wrappers), 0, NULL, NULL, 1);
+ zend_hash_init(FG(stream_wrappers), zend_hash_num_elements(&url_stream_wrappers_hash), NULL, NULL, 1);
zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL, &tmp, sizeof(tmp));
}
@@ -1520,9 +1512,9 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
n++;
}
- if ((*p == ':') && (n > 1) && !strncmp("://", p, 3)) {
+ if ((*p == ':') && (n > 1) && (!strncmp("//", p+1, 2) || !memcmp("data", path, 4))) {
protocol = path;
- } else if (strncasecmp(path, "zlib:", 5) == 0) {
+ } else if (n == 5 && strncasecmp(path, "zlib:", 5) == 0) {
/* BC with older php scripts and zlib wrapper */
protocol = "compress.zlib";
n = 13;
@@ -1530,18 +1522,23 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
}
if (protocol) {
- if (FAILURE == zend_hash_find(wrapper_hash, (char*)protocol, n, (void**)&wrapperpp)) {
- char wrapper_name[32];
-
- if (n >= sizeof(wrapper_name))
- n = sizeof(wrapper_name) - 1;
- PHP_STRLCPY(wrapper_name, protocol, sizeof(wrapper_name), n);
+ if (FAILURE == zend_hash_find(wrapper_hash, (char*)protocol, n, (void**)&wrapperpp)) {
+ char *tmp = estrndup(protocol, n);
+ php_strtolower(tmp, n);
+ if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n, (void**)&wrapperpp)) {
+ char wrapper_name[32];
+
+ if (n >= sizeof(wrapper_name)) {
+ n = sizeof(wrapper_name) - 1;
+ }
+ PHP_STRLCPY(wrapper_name, protocol, sizeof(wrapper_name), n);
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unable to find the wrapper \"%s\" - did you forget to enable it when you configured PHP?",
- wrapper_name);
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unable to find the wrapper \"%s\" - did you forget to enable it when you configured PHP?", wrapper_name);
- wrapperpp = NULL;
- protocol = NULL;
+ wrapperpp = NULL;
+ protocol = NULL;
+ }
+ efree(tmp);
}
}
/* TODO: curl based streams probably support file:// properly */
@@ -1605,7 +1602,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
return &php_plain_files_wrapper;
}
- if (wrapperpp && (*wrapperpp)->is_url && !PG(allow_url_fopen)) {
+ if ((wrapperpp && (*wrapperpp)->is_url) && (!PG(allow_url_fopen) || ((options & STREAM_OPEN_FOR_INCLUDE) && !PG(allow_url_include))) ) {
if (options & REPORT_ERRORS) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "URL file-access is disabled in the server configuration");
}
diff --git a/main/streams/userspace.c b/main/streams/userspace.c
index e9447a05a..dc99c5c66 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: userspace.c,v 1.31.2.3 2006/04/22 17:17:40 wez Exp $ */
+/* $Id: userspace.c,v 1.31.2.3.2.1 2006/08/14 15:01:29 tony2001 Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -231,6 +231,40 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena
object_init_ex(us->object, uwrap->ce);
ZVAL_REFCOUNT(us->object) = 1;
PZVAL_IS_REF(us->object) = 1;
+
+ if (uwrap->ce->constructor) {
+ zend_fcall_info fci;
+ zend_fcall_info_cache fcc;
+ zval *retval_ptr;
+
+ fci.size = sizeof(fci);
+ fci.function_table = &uwrap->ce->function_table;
+ fci.function_name = NULL;
+ fci.symbol_table = NULL;
+ fci.object_pp = &us->object;
+ fci.retval_ptr_ptr = &retval_ptr;
+ fci.param_count = 0;
+ fci.params = NULL;
+ fci.no_separation = 1;
+
+ fcc.initialized = 1;
+ fcc.function_handler = uwrap->ce->constructor;
+ fcc.calling_scope = EG(scope);
+ fcc.object_pp = &us->object;
+
+ if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute %s::%s()", uwrap->ce->name, uwrap->ce->constructor->common.function_name);
+ zval_dtor(us->object);
+ FREE_ZVAL(us->object);
+ efree(us);
+ FG(user_stream_current_filename) = NULL;
+ return NULL;
+ } else {
+ if (retval_ptr) {
+ zval_ptr_dtor(&retval_ptr);
+ }
+ }
+ }
if (context) {
MAKE_STD_ZVAL(zcontext);
diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c
index 5b7e32917..60084545d 100644
--- a/main/streams/xp_socket.c
+++ b/main/streams/xp_socket.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: xp_socket.c,v 1.33.2.2 2006/02/02 18:16:43 pollita Exp $ */
+/* $Id: xp_socket.c,v 1.33.2.2.2.1 2006/10/11 12:53:56 tony2001 Exp $ */
#include "php.h"
#include "ext/standard/file.h"
@@ -495,7 +495,7 @@ static inline char *parse_ip_address_ex(const char *str, int str_len, int *portn
#ifdef HAVE_IPV6
char *p;
- if (*(str) == '[') {
+ if (*(str) == '[' && str_len > 1) {
/* IPV6 notation to specify raw address with port (i.e. [fe80::1]:80) */
p = memchr(str + 1, ']', str_len - 2);
if (!p || *(p + 1) != ':') {
@@ -508,8 +508,11 @@ static inline char *parse_ip_address_ex(const char *str, int str_len, int *portn
return estrndup(str + 1, p - str - 1);
}
#endif
-
- colon = memchr(str, ':', str_len - 1);
+ if (str_len) {
+ colon = memchr(str, ':', str_len - 1);
+ } else {
+ colon = NULL;
+ }
if (colon) {
*portno = atoi(colon + 1);
host = estrndup(str, colon - str);