diff options
author | Ondřej Surý <ondrej@sury.org> | 2010-10-21 08:52:46 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2010-10-21 08:52:46 +0200 |
commit | 01fcdff3849c3691d9aaeaab735846ab6d8895ca (patch) | |
tree | 6460876d356113fa7053df36f2aa00baa7db24a9 /main/streams | |
parent | 855a09f4eded707941180c9d90acd17c25e29447 (diff) | |
download | php-upstream/5.3.3.tar.gz |
Imported Upstream version 5.3.3upstream/5.3.3
Diffstat (limited to 'main/streams')
-rw-r--r-- | main/streams/cast.c | 96 | ||||
-rw-r--r-- | main/streams/plain_wrapper.c | 2 | ||||
-rwxr-xr-x | main/streams/streams.c | 56 | ||||
-rw-r--r-- | main/streams/transports.c | 17 | ||||
-rw-r--r-- | main/streams/xp_socket.c | 4 |
5 files changed, 100 insertions, 75 deletions
diff --git a/main/streams/cast.c b/main/streams/cast.c index 2e9ad810c..91174665b 100644 --- a/main/streams/cast.c +++ b/main/streams/cast.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: cast.c 294462 2010-02-03 20:49:03Z pajoye $ */ +/* $Id: cast.c 293732 2010-01-19 13:44:08Z jani $ */ #define _GNU_SOURCE #include "php.h" @@ -56,6 +56,7 @@ static int stream_cookie_reader(void *cookie, char *buffer, int size) { int ret; TSRMLS_FETCH(); + ret = php_stream_read((php_stream*)cookie, buffer, size); return ret; } @@ -63,12 +64,14 @@ static int stream_cookie_reader(void *cookie, char *buffer, int size) static int stream_cookie_writer(void *cookie, const char *buffer, int size) { TSRMLS_FETCH(); + return php_stream_write((php_stream *)cookie, (char *)buffer, size); } static fpos_t stream_cookie_seeker(void *cookie, off_t position, int whence) { TSRMLS_FETCH(); + return (fpos_t)php_stream_seek((php_stream *)cookie, position, whence); } @@ -86,6 +89,7 @@ static ssize_t stream_cookie_reader(void *cookie, char *buffer, size_t size) { ssize_t ret; TSRMLS_FETCH(); + ret = php_stream_read(((php_stream *)cookie), buffer, size); return ret; } @@ -93,6 +97,7 @@ static ssize_t stream_cookie_reader(void *cookie, char *buffer, size_t size) static ssize_t stream_cookie_writer(void *cookie, const char *buffer, size_t size) { TSRMLS_FETCH(); + return php_stream_write(((php_stream *)cookie), (char *)buffer, size); } @@ -103,14 +108,16 @@ static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence) *position = php_stream_seek((php_stream *)cookie, (off_t)*position, whence); - if (*position == -1) + if (*position == -1) { return -1; + } return 0; } # else static int stream_cookie_seeker(void *cookie, off_t position, int whence) { TSRMLS_FETCH(); + return php_stream_seek((php_stream *)cookie, position, whence); } # endif @@ -153,9 +160,9 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show stream->readpos = stream->writepos = 0; } } - + /* filtered streams can only be cast as stdio, and only when fopencookie is present */ - + if (castas == PHP_STREAM_AS_STDIO) { if (stream->stdiocast) { if (ret) { @@ -167,31 +174,33 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show /* if the stream is a stdio stream let's give it a chance to respond * first, to avoid doubling up the layers of stdio with an fopencookie */ if (php_stream_is(stream, PHP_STREAM_IS_STDIO) && - stream->ops->cast && - !php_stream_is_filtered(stream) && - stream->ops->cast(stream, castas, ret TSRMLS_CC) == SUCCESS) - { + stream->ops->cast && + !php_stream_is_filtered(stream) && + stream->ops->cast(stream, castas, ret TSRMLS_CC) == SUCCESS + ) { goto exit_success; } - + #if HAVE_FOPENCOOKIE /* if just checking, say yes we can be a FILE*, but don't actually create it yet */ - if (ret == NULL) + if (ret == NULL) { goto exit_success; + } *(FILE**)ret = fopencookie(stream, stream->mode, PHP_STREAM_COOKIE_FUNCTIONS); if (*ret != NULL) { off_t pos; - + stream->fclose_stdiocast = PHP_STREAM_FCLOSE_FOPENCOOKIE; /* If the stream position is not at the start, we need to force * the stdio layer to believe it's real location. */ pos = php_stream_tell(stream); - if (pos > 0) + if (pos > 0) { fseek(*ret, pos, SEEK_SET); - + } + goto exit_success; } @@ -219,11 +228,12 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show if (ret != SUCCESS) { php_stream_close(newstream); } else { - int retcode = php_stream_cast(newstream, castas | flags, (void**)ret, show_err); + int retcode = php_stream_cast(newstream, castas | flags, (void **)ret, show_err); - if (retcode == SUCCESS) + if (retcode == SUCCESS) { rewind(*(FILE**)ret); - + } + /* do some specialized cleanup */ if ((flags & PHP_STREAM_CAST_RELEASE)) { php_stream_free(stream, PHP_STREAM_FREE_CLOSE_CASTED); @@ -245,13 +255,13 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show if (show_err) { /* these names depend on the values of the PHP_STREAM_AS_XXX defines in php_streams.h */ static const char *cast_names[4] = { - "STDIO FILE*", "File Descriptor", "Socket Descriptor", "select()able descriptor" + "STDIO FILE*", + "File Descriptor", + "Socket Descriptor", + "select()able descriptor" }; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot represent a stream of type %s as a %s", - stream->ops->label, - cast_names[castas] - ); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot represent a stream of type %s as a %s", stream->ops->label, cast_names[castas]); } return FAILURE; @@ -259,20 +269,20 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show exit_success: if ((stream->writepos - stream->readpos) > 0 && - stream->fclose_stdiocast != PHP_STREAM_FCLOSE_FOPENCOOKIE && - (flags & PHP_STREAM_CAST_INTERNAL) == 0) { + stream->fclose_stdiocast != PHP_STREAM_FCLOSE_FOPENCOOKIE && + (flags & PHP_STREAM_CAST_INTERNAL) == 0 + ) { /* the data we have buffered will be lost to the third party library that * will be accessing the stream. Emit a warning so that the end-user will * know that they should try something else */ - - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "%ld bytes of buffered data lost during stream conversion!", - (long)(stream->writepos - stream->readpos)); + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld bytes of buffered data lost during stream conversion!", (long)(stream->writepos - stream->readpos)); } - - if (castas == PHP_STREAM_AS_STDIO && ret) + + if (castas == PHP_STREAM_AS_STDIO && ret) { stream->stdiocast = *(FILE**)ret; - + } + if (flags & PHP_STREAM_CAST_RELEASE) { php_stream_free(stream, PHP_STREAM_FREE_CLOSE_CASTED); } @@ -290,15 +300,15 @@ PHPAPI FILE * _php_stream_open_wrapper_as_file(char *path, char *mode, int optio stream = php_stream_open_wrapper_rel(path, mode, options|STREAM_WILL_CAST, opened_path); - if (stream == NULL) + if (stream == NULL) { return NULL; - - if (php_stream_cast(stream, PHP_STREAM_AS_STDIO|PHP_STREAM_CAST_TRY_HARD|PHP_STREAM_CAST_RELEASE, - (void**)&fp, REPORT_ERRORS) == FAILURE) - { + } + + if (php_stream_cast(stream, PHP_STREAM_AS_STDIO|PHP_STREAM_CAST_TRY_HARD|PHP_STREAM_CAST_RELEASE, (void**)&fp, REPORT_ERRORS) == FAILURE) { php_stream_close(stream); - if (opened_path && *opened_path) + if (opened_path && *opened_path) { efree(*opened_path); + } return NULL; } return fp; @@ -311,21 +321,23 @@ PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstr assert(newstream != NULL); *newstream = NULL; - + if (((flags & PHP_STREAM_FORCE_CONVERSION) == 0) && origstream->ops->seek != NULL) { *newstream = origstream; return PHP_STREAM_UNCHANGED; } - + /* Use a tmpfile and copy the old streams contents into it */ - if (flags & PHP_STREAM_PREFER_STDIO) + if (flags & PHP_STREAM_PREFER_STDIO) { *newstream = php_stream_fopen_tmpfile(); - else + } else { *newstream = php_stream_temp_new(); + } - if (*newstream == NULL) + if (*newstream == NULL) { return PHP_STREAM_FAILED; + } #if ZEND_DEBUG (*newstream)->open_filename = origstream->open_filename; @@ -340,7 +352,7 @@ PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstr php_stream_close(origstream); php_stream_seek(*newstream, 0, SEEK_SET); - + return PHP_STREAM_RELEASED; } /* }}} */ diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index e7642d9d4..2087505ce 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: plain_wrapper.c 295417 2010-02-23 15:04:29Z pajoye $ */ +/* $Id: plain_wrapper.c 295308 2010-02-21 17:44:25Z pajoye $ */ #include "php.h" #include "php_globals.h" diff --git a/main/streams/streams.c b/main/streams/streams.c index 44843d25c..e3f79816a 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c 294550 2010-02-05 00:39:31Z pajoye $ */ +/* $Id: streams.c 299466 2010-05-18 19:39:39Z pajoye $ */ #define _GNU_SOURCE #include "php.h" @@ -95,7 +95,7 @@ fprintf(stderr, "forget_persistent: %s:%p\n", stream->ops->label, stream); stream->context TSRMLS_CC); stream->context = NULL; } - + return 0; } @@ -157,7 +157,7 @@ void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char * msg[0] = '\0'; for (i = 0; i < wrapper->err_count; i++) { strcat(msg, wrapper->err_stack[i]); - if (i < wrapper->err_count - 1) { + if (i < wrapper->err_count - 1) { strcat(msg, br); } } @@ -263,7 +263,7 @@ fprintf(stderr, "stream_alloc: %s:%p persistent=%s\n", ops->label, ret, persiste if (FAILURE == zend_hash_update(&EG(persistent_list), (char *)persistent_id, strlen(persistent_id) + 1, (void *)&le, sizeof(le), NULL)) { - + pefree(ret, 1); return NULL; } @@ -329,7 +329,7 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov /* make sure everything is saved */ _php_stream_flush(stream, 1 TSRMLS_CC); - + /* If not called from the resource dtor, remove the stream from the resource list. */ if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) == 0 && remove_rsrc) { zend_list_delete(stream->rsrc_id); @@ -403,7 +403,7 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov pefree(stream->orig_path, stream->is_persistent); stream->orig_path = NULL; } - + # if defined(PHP_WIN32) OutputDebugString(leakinfo); # else @@ -474,7 +474,7 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D } else { flags = stream->eof ? PSFS_FLAG_FLUSH_CLOSE : PSFS_FLAG_FLUSH_INC; } - + /* wind the handle... */ for (filter = stream->readfilters.head; filter; filter = filter->next) { status = filter->fops->filter(stream, filter, brig_inp, brig_outp, NULL, flags TSRMLS_CC); @@ -482,7 +482,7 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D if (status != PSFS_PASS_ON) { break; } - + /* brig_out becomes brig_in. * brig_in will always be empty here, as the filter MUST attach any un-consumed buckets * to its own brigade */ @@ -491,7 +491,7 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D brig_outp = brig_swap; memset(brig_outp, 0, sizeof(*brig_outp)); } - + switch (status) { case PSFS_PASS_ON: /* we get here when the last filter in the chain has data to pass on. @@ -717,7 +717,7 @@ PHPAPI char *php_stream_locate_eol(php_stream *stream, char *buf, size_t buf_len } else { readptr = buf; avail = buf_len; - } + } /* Look for EOL */ if (stream->flags & PHP_STREAM_FLAG_DETECT_EOL) { @@ -828,7 +828,7 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, } else { /* XXX: Should be fine to always read chunk_size */ size_t toread; - + if (grow_mode) { toread = stream->chunk_size; } else { @@ -945,7 +945,7 @@ static size_t _php_stream_write_buffer(php_stream *stream, const char *buf, size stream->ops->seek(stream, stream->position, SEEK_SET, &stream->position TSRMLS_CC); } - + while (count > 0) { towrite = count; if (towrite > stream->chunk_size) @@ -958,7 +958,7 @@ static size_t _php_stream_write_buffer(php_stream *stream, const char *buf, size buf += justwrote; count -= justwrote; didwrite += justwrote; - + /* Only screw with the buffer if we can seek, otherwise we lose data * buffered from fifos and sockets */ if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) { @@ -1119,11 +1119,11 @@ PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_ if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) { int ret; - + if (stream->writefilters.head) { _php_stream_flush(stream, 0 TSRMLS_CC); } - + switch(whence) { case SEEK_CUR: offset = stream->position + offset; @@ -1186,12 +1186,12 @@ PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, voi /* try to match the buffer mode as best we can */ if (value == PHP_STREAM_BUFFER_NONE) { stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; - } else { + } else if (stream->flags & PHP_STREAM_FLAG_NO_BUFFER) { stream->flags ^= PHP_STREAM_FLAG_NO_BUFFER; } ret = PHP_STREAM_OPTION_RETURN_OK; break; - + default: ; } @@ -1244,7 +1244,7 @@ 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 (maxlen == 0) { + if (maxlen == 0) { return 0; } @@ -1343,8 +1343,8 @@ PHPAPI size_t _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, s php_stream_mmap_unmap_ex(src, mapped); *len = mapped; - - /* we've got at least 1 byte to read. + + /* we've got at least 1 byte to read. * less than 1 is an error */ if (mapped > 0) { @@ -1393,7 +1393,7 @@ PHPAPI size_t _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, s *len = haveread; - /* we've got at least 1 byte to read. + /* we've got at least 1 byte to read. * less than 1 is an error */ if (haveread > 0 || src->eof) { @@ -1403,7 +1403,7 @@ PHPAPI size_t _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, s } /* Returns the number of bytes moved. - * Returns 1 when source len is 0. + * Returns 1 when source len is 0. * Deprecated in favor of php_stream_copy_to_stream_ex() */ ZEND_ATTRIBUTE_DEPRECATED PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC TSRMLS_DC) @@ -1457,7 +1457,7 @@ int php_init_stream_wrappers(int module_number TSRMLS_DC) return ( zend_hash_init(&url_stream_wrappers_hash, 0, NULL, NULL, 1) == SUCCESS - && + && zend_hash_init(php_get_stream_filters_hash_global(), 0, NULL, NULL, 1) == SUCCESS && zend_hash_init(php_stream_xport_get_hash(), 0, NULL, NULL, 1) == SUCCESS @@ -1661,13 +1661,13 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char } return NULL; } - + return plain_files_wrapper; } - if (wrapperpp && (*wrapperpp)->is_url && + if (wrapperpp && (*wrapperpp)->is_url && (options & STREAM_DISABLE_URL_PROTECTION) == 0 && - (!PG(allow_url_fopen) || + (!PG(allow_url_fopen) || (((options & STREAM_OPEN_FOR_INCLUDE) || PG(in_user_include)) && !PG(allow_url_include)))) { if (options & REPORT_ERRORS) { @@ -1822,7 +1822,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio char *resolved_path = NULL; char *copy_of_path = NULL; - + if (opened_path) { *opened_path = NULL; } @@ -1871,7 +1871,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio php_stream_close(stream); stream = NULL; } - + if (stream) { stream->wrapper = wrapper; } diff --git a/main/streams/transports.c b/main/streams/transports.c index a35efb2df..9e9990712 100644 --- a/main/streams/transports.c +++ b/main/streams/transports.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: transports.c 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: transports.c 296079 2010-03-11 16:37:24Z mike $ */ #include "php.h" #include "php_streams_int.h" @@ -157,7 +157,20 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int ERR_RETURN(error_string, error_text, "bind() failed: %s"); failed = 1; } else if (flags & STREAM_XPORT_LISTEN) { - if (0 != php_stream_xport_listen(stream, 5, &error_text TSRMLS_CC)) { + zval **zbacklog = NULL; + int backlog = 32; + + if (stream->context && php_stream_context_get_option(stream->context, "socket", "backlog", &zbacklog) == SUCCESS) { + zval *ztmp = *zbacklog; + + convert_to_long_ex(&ztmp); + backlog = Z_LVAL_P(ztmp); + if (ztmp != *zbacklog) { + zval_ptr_dtor(&ztmp); + } + } + + if (0 != php_stream_xport_listen(stream, backlog, &error_text TSRMLS_CC)) { ERR_RETURN(error_string, error_text, "listen() failed: %s"); failed = 1; } diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index 9b039ca93..21bf0b396 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: xp_socket.c 294453 2010-02-03 20:21:40Z pajoye $ */ +/* $Id: xp_socket.c 296079 2010-03-11 16:37:24Z mike $ */ #include "php.h" #include "ext/standard/file.h" @@ -324,7 +324,7 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void switch (xparam->op) { case STREAM_XPORT_OP_LISTEN: - xparam->outputs.returncode = (listen(sock->socket, 5) == 0) ? 0: -1; + xparam->outputs.returncode = (listen(sock->socket, xparam->inputs.backlog) == 0) ? 0: -1; return PHP_STREAM_OPTION_RETURN_OK; case STREAM_XPORT_OP_GET_NAME: |