1
0
mirror of https://github.com/php/php-src.git synced 2026-04-29 03:03:26 +02:00
Commit Graph

102 Commits

Author SHA1 Message Date
Wez Furlong 5f7c347f17 Fix a nasty nasty bug:
When not enough data to satisfy a read was found in the buffer, fgets modifies
the buf pointer to point to the position to store the next chunk.  It then
returned the modified buf pointer, instead of a pointer to the start of the
buffer.

Also added some infrastructure for making fgets grow the buffer on-demand to
the correct line-size.  Since streams uses reasonable chunk sizes, the
performance of the realloc's should be pretty good; in the best case, the line
is already found completely in the buffer, so the returned buffer will be
allocated to precisely the correct size.

In the worst case, where the buffer only contains part of the line, we get a
realloc per buffer fill. The reallocs are either the size of the remainder
of the line, or the chunk_size (if the buffer sill does not contain a complete
line).  Each realloc adds an extra byte for a NUL terminator.

I think this will perform quite well using the default chunk size of 8K.
2002-10-13 22:52:33 +00:00
Wez Furlong 4308a399b9 paranoia 2002-10-12 02:56:34 +00:00
Wez Furlong 258aa4d239 Write in blocks of the current chunk_size for a stream.
Should resolve problems with network writes.
2002-10-12 02:31:42 +00:00
Sascha Schumann 88b2d8bb8f stdio buffers data in user land. By calling fflush(3), this
data is sent to the kernel using write(2). fsync'ing a
file descriptor is not required -- writing to a fd has the same
affect as calling fflush after each fwrite.
2002-10-07 03:12:06 +00:00
Wez Furlong 510f3b0305 Try to ensure that we return the number of bytes requested during fread(). 2002-10-06 23:27:53 +00:00
Wez Furlong 9d5bab5a0d EOF related fixes. 2002-10-05 10:59:35 +00:00
Wez Furlong 077fe52d8b This seems to resolve the issues with fgets.
I've moved EOF detection into the streams layer; a stream reader
implementation should set stream->eof when it detects EOF.
Fixed test for user streams - it still fails but that is due to an output
buffering bug.
2002-10-05 10:35:13 +00:00
Sascha Schumann bfd2a857b2 Fix EOF cases
Noticed by: Ilia
2002-10-04 19:48:59 +00:00
Sascha Schumann 1918011c01 Interrupt loop, if the stream op fails. 2002-10-04 19:36:09 +00:00
Sascha Schumann a4ec211e9e Add a few notes 2002-10-04 19:08:43 +00:00
Wez Furlong 9c5883bdf6 replace dont_block with a flag. 2002-10-04 18:59:34 +00:00
Ilia Alshanetsky 08645d53c0 Fixed bug #19746 2002-10-04 18:44:47 +00:00
Sascha Schumann 4f7e6dadd8 Improve the general behaviour of stream_gets and fix its semantics
with regard to sockets. The behaviour should be aligned with PHP 4.2 now.
This has been verified to some degree.

If the underlying stream operations block when no new data is readable,
we need to take extra precautions.

If there is buffered data available, we check for a EOL. If it exists,
we pass the data immediately back to the caller. This saves a call
to the read implementation and will not block where blocking
is not necessary at all.

If the stream buffer contains more data than the caller requested,
we can also avoid that costly step and simply return that data.
2002-10-04 18:21:40 +00:00
Marcus Boerger 3ee8172674 fix position handling 2002-10-03 16:06:41 +00:00
Marcus Boerger 4a1d83aa8c Another missing variable init
#Wez shouldn't "stream->filterhead->fops->flush()" affect return value also?
2002-10-02 13:25:38 +00:00
Marcus Boerger efec24d22d Missing variable init 2002-10-02 13:18:01 +00:00
Wez Furlong 393d57d5be Differentiate between write buffer and streams read buffer sizes.
Add options for timeout and chunk size; previously these were only
set-able for socket streams.
2002-09-28 22:10:47 +00:00
Wez Furlong 84e0df3dfe Allow user streams/wrappers to implement fstat(), opendir() and stat(). 2002-09-28 13:05:47 +00:00
Wez Furlong a95fb6bfd6 Fix for #19580. (Incorrectly warning about lost data when that is not the
case on systems without fopencookie).
2002-09-26 16:22:28 +00:00
Wez Furlong c484eb8c97 Fix segfault in wrapper error log mechanism when errors are logged on
second and subsequent events.
Implement very simple recursion protection for user streams written
like this:
class urlEncodeStream {
    var $fp = NULL;

    function stream_open($path, $mode, $options, &$opened_path)
    {
        $this->fp = fopen($path, $mode); // <-- this recurses infinitely
        return is_resource($this->fp);
    }
}

file_register_wrapper('urlencode', 'urlEncodeStream');
$fp = fopen('urlencode:///tmp/outputfile.txt', 'w');

Noticed by: Yasuo.
2002-09-26 12:12:27 +00:00
Wez Furlong 696e0a2301 Implement persistent streams. (for pfsockopen).
Juggle some includes/definitions.
Tidy up streams use in ext/standard/file.c
2002-09-25 15:25:12 +00:00
Wez Furlong ba2dc46117 Correct a buglet in the newly introduced buffer code.
# Andi: this might have been the cause of that problem you mentioned.
2002-09-23 23:39:46 +00:00
Wez Furlong a2c344fa67 Ensure that the seekable stream returned for include("http://") under win32
is based on a temporary file rather than a memory stream.
2002-09-23 19:10:33 +00:00
Wez Furlong c74b9faca5 Implement a default_socket_timeout and auto_detect_line_endings ini options.
Also move user_agent from BG to FG.
2002-09-23 18:12:39 +00:00
Wez Furlong a3cda3b32d Hopefully fix the other warnings that my last warning-fixing commit caused. 2002-09-23 15:21:16 +00:00
Wez Furlong ad4afdf827 fix some warnings. 2002-09-23 14:50:21 +00:00
Wez Furlong 9e84b3d5b5 Revise buffer/seek code a little.
Tidy up user streams even more.
Make test case quite aggressive.
2002-09-23 13:22:10 +00:00
Wez Furlong 4d8a07d529 Implement read buffering in streams.
Eliminate similar code from network.c.
Implement fgets equivalent at the streams level, which can detect
the mac, dos and unix line endings and handle them appropriately.
The default behaviour is unix (and dos) line endings.
An ini option to control this behaviour will follow.
# Don't forget to make clean!
# I've done some testing but would appreciate feedback from
# people with scripts/extensions that seek around a lot.
2002-09-23 01:47:04 +00:00
Wez Furlong 3df412cf9b Fix a couple of bad pointer indirections (oops).
Lets stick to a single category of "http" for the "user_agent"
context override.
2002-09-07 20:58:30 +00:00
Wez Furlong 95ffc663d9 Fix open_basedir. 2002-08-25 12:10:17 +00:00
Wez Furlong e286b286ae Hopefully really fix #18022 this time. 2002-08-25 11:23:19 +00:00
Wez Furlong 6d2fb45328 Potential fix for Bug#18022:
Streams that are pipes on systems that HAVE_FLUSHIO should not be seeked
as is required for plain files on those systems.
2002-08-25 11:02:05 +00:00
Wez Furlong 509ad5ec0f Unify error messages. 2002-08-25 10:36:08 +00:00
Wez Furlong c7be7b55d1 Add a "closing" parameter for filters to determine if a flush is the last
flush before the stream is closed.  This allows filters to finish a chunk
and write footers etc.
2002-08-25 10:26:58 +00:00
Wez Furlong 3d8b6c2d52 Add a configure check to see if the seeker function in an fopencookie
uses off_t or the newer, more portable "fpos_t *".
The check could perhaps be more refined, as the test program will segfault
on older systems (like mine) that use off_t.
2002-08-22 22:28:19 +00:00
Wez Furlong 5718112088 Fix compile warnings under win32 2002-08-22 17:42:18 +00:00
Marcus Boerger 4c1f3dec65 fix php_error_docref parameters 2002-08-22 10:16:03 +00:00
Wez Furlong 03b8214b9d Fix newly introduced leak in the debug build. 2002-08-20 22:08:55 +00:00
Wez Furlong 9d348ea800 Implement filter API for streams.
Filters can be stacked onto a stream; more details will follow in docs and
on php-dev.

Implement "string.rot13" filter

Allows the following script:

$fp = fopen("file.txt", "r");
stream_filter_prepend($fp, "string.rot13");

// File contents will be subject to a rot13 transformation before
// being output.
fpassthru($fp);
fclose($fp);
2002-08-20 20:47:47 +00:00
Wez Furlong 5f9a5a7c8e Remove php_stream_sock_set_blocking and replace with
php_stream_set_option which can be used in a similar way as ioctl()
to set options for streams.

Current options include buffering and blocking support.

o Buffer control is support for stdio based streams.
o Blocking/non-blocking is supported for stdio and socket based streams.
2002-08-19 22:59:10 +00:00
Wez Furlong 2e4b6ef181 Fix a little leak. 2002-08-16 12:02:42 +00:00
Wez Furlong c2cbae6dd3 Enhance Ilia's recent patch to query the wrapper subsystem to determine
if a filename is a URL and thus if safe-mode checks should be skipped.
2002-08-16 09:50:24 +00:00
Wez Furlong 5a21ab42cb Introduce an error stack for wrappers, to help prevent multiple errors
and warnings (some of which are bogus) when there are problems opening
streams.
Implement sanity check on the mode used to open ftp and http connections.
This fixes Bug 12004.
2002-08-11 10:53:10 +00:00
Wez Furlong 1144bdb04d remove obsolete TSRMLS_FETCH 2002-08-10 20:20:55 +00:00
James Cox 1ae29d455c @Copy() fixed to return 1 on 0 byte files. Patch by Ilia A <ilia@prohost.org>. 2002-08-09 00:33:06 +00:00
Edin Kadribasic 0af2ae718f No need to check for allow_url_fopen here.
#This closes two bugs which I cannot find right now courtesy our buggy bug
#database.
2002-06-19 00:31:30 +00:00
Markus Fischer 17b3ef47f3 - Fix builtin gets() emulation (hopefully). 2002-06-11 21:22:12 +00:00
Markus Fischer 4290da23d0 - Add missing Id tag. 2002-06-11 18:55:48 +00:00
Markus Fischer 709785a90a - Always \0 terminate data returned from _php_stream_copy_to_mem(). 2002-06-11 18:54:57 +00:00
Markus Fischer 0cd40c2808 - Since streams are always enabled, instead of just printing 'enabled' we tell
what streams are currently registered.
2002-06-08 10:25:44 +00:00