diff options
author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:34:37 -0400 |
---|---|---|
committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:34:37 -0400 |
commit | 10f5b47dc7c1cf2b9a00991629f43652710322d3 (patch) | |
tree | 3b727a16f652b8042d573e90f003868ffb3b56c7 /main/streams | |
parent | 0e920280a2e04b110827bb766b9f29e3d581c4ee (diff) | |
download | php-10f5b47dc7c1cf2b9a00991629f43652710322d3.tar.gz |
Imported Upstream version 5.0.5upstream/5.0.5
Diffstat (limited to 'main/streams')
-rw-r--r-- | main/streams/php_streams_int.h | 14 | ||||
-rw-r--r-- | main/streams/plain_wrapper.c | 8 | ||||
-rwxr-xr-x | main/streams/streams.c | 60 |
3 files changed, 68 insertions, 14 deletions
diff --git a/main/streams/php_streams_int.h b/main/streams/php_streams_int.h index e443cdfdb..80f312124 100644 --- a/main/streams/php_streams_int.h +++ b/main/streams/php_streams_int.h @@ -16,19 +16,25 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_streams_int.h,v 1.5 2004/01/08 17:33:06 sniper Exp $ */ +/* $Id: php_streams_int.h,v 1.5.2.1 2005/06/07 08:25:29 derick Exp $ */ + #if ZEND_DEBUG -#define emalloc_rel_orig(size) \ + +#if USE_ZEND_ALLOC +# 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 49566d4bb..74f92d17e 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: plain_wrapper.c,v 1.39.2.3 2004/10/28 05:05:39 tony2001 Exp $ */ +/* $Id: plain_wrapper.c,v 1.39.2.7 2005/05/24 10:14:05 tony2001 Exp $ */ #include "php.h" #include "php_globals.h" @@ -155,6 +155,7 @@ PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC) php_stream *stream = php_stream_fopen_from_fd_rel(fd, "r+b", NULL); if (stream) { php_stdio_stream_data *self = (php_stdio_stream_data*)stream->abstract; + stream->wrapper = &php_plain_files_wrapper; self->temp_file_name = opened_path; self->lock_flag = LOCK_UN; @@ -461,6 +462,9 @@ static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC) /* we were opened as a plain file descriptor, so we * need fdopen now */ data->file = fdopen(data->fd, stream->mode); + if (data->file == NULL) { + return FAILURE; + } } *(FILE**)ret = data->file; @@ -578,7 +582,7 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void return 0; } - if (!flock(fd, value) || (errno == EWOULDBLOCK && value & LOCK_NB)) { + if (!flock(fd, value)) { data->lock_flag = value; return 0; } else { diff --git a/main/streams/streams.c b/main/streams/streams.c index b42dd840a..f3a12ba33 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.61.2.6 2005/02/22 00:24:51 iliaa Exp $ */ +/* $Id: streams.c,v 1.61.2.14 2005/06/01 15:11:15 dmitry Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -592,8 +592,9 @@ PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t size TSRMLS } /* just break anyway, to avoid greedy read */ - if (stream->wrapper != &php_plain_files_wrapper) + if (stream->wrapper != &php_plain_files_wrapper) { break; + } } if (didread > 0) { @@ -832,6 +833,7 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re { char *e, *buf; size_t toread; + int skip = 0; php_stream_fill_read_buffer(stream, maxlen TSRMLS_CC); @@ -839,15 +841,16 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re toread = maxlen; } else { if (delim_len == 1) { - e = memchr(stream->readbuf, *delim, stream->readbuflen); + e = memchr(stream->readbuf + stream->readpos, *delim, stream->writepos - stream->readpos); } else { - e = php_memnstr(stream->readbuf, delim, delim_len, (stream->readbuf + stream->readbuflen)); + e = php_memnstr(stream->readbuf + stream->readpos, delim, delim_len, (stream->readbuf + stream->writepos)); } if (!e) { toread = maxlen; } else { - toread = e - (char *) stream->readbuf; + toread = e - (char *) stream->readbuf - stream->readpos; + skip = 1; } } @@ -857,8 +860,12 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re buf = emalloc(toread + 1); *returned_len = php_stream_read(stream, buf, toread); - + if (*returned_len >= 0) { + if (skip) { + stream->readpos += delim_len; + stream->position += delim_len; + } buf[*returned_len] = '\0'; return buf; } else { @@ -1361,6 +1368,21 @@ static void stream_resource_persistent_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC FG(pclose_ret) = php_stream_free(stream, PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR); } +void php_shutdown_stream_hashes(TSRMLS_D) +{ + if (FG(stream_wrappers)) { + zend_hash_destroy(FG(stream_wrappers)); + efree(FG(stream_wrappers)); + FG(stream_wrappers) = NULL; + } + + if (FG(stream_filters)) { + zend_hash_destroy(FG(stream_filters)); + efree(FG(stream_filters)); + FG(stream_filters) = NULL; + } +} + int php_init_stream_wrappers(int module_number TSRMLS_DC) { le_stream = zend_register_list_destructors_ex(stream_resource_regular_dtor, NULL, "stream", module_number); @@ -1396,7 +1418,18 @@ int php_shutdown_stream_wrappers(int module_number TSRMLS_DC) /* API for registering GLOBAL wrappers */ PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC) { - return zend_hash_add(&url_stream_wrappers_hash, protocol, strlen(protocol), wrapper, sizeof(*wrapper), NULL); + int i, protocol_len = strlen(protocol); + + for(i = 0; i < protocol_len; i++) { + if (!isalnum((int)protocol[i]) && + protocol[i] != '+' && + protocol[i] != '-' && + protocol[i] != '.') { + return FAILURE; + } + } + + return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len, wrapper, sizeof(*wrapper), NULL); } PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC) @@ -1407,6 +1440,17 @@ PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC) /* API for registering VOLATILE wrappers */ PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC) { + int i, protocol_len = strlen(protocol); + + for(i = 0; i < protocol_len; i++) { + if (!isalnum((int)protocol[i]) && + protocol[i] != '+' && + protocol[i] != '-' && + protocol[i] != '.') { + return FAILURE; + } + } + if (!FG(stream_wrappers)) { php_stream_wrapper tmpwrapper; @@ -1415,7 +1459,7 @@ PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_w zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL, &tmpwrapper, sizeof(php_stream_wrapper)); } - return zend_hash_add(FG(stream_wrappers), protocol, strlen(protocol), wrapper, sizeof(*wrapper), NULL); + return zend_hash_add(FG(stream_wrappers), protocol, protocol_len, wrapper, sizeof(*wrapper), NULL); } /* }}} */ |