Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions | Variables
php_streams.h File Reference
#include <sys/types.h>
#include <sys/stat.h>
#include "streams/php_stream_context.h"
#include "streams/php_stream_filter_api.h"
#include "streams/php_stream_transport.h"
#include "streams/php_stream_plain_wrapper.h"
#include "streams/php_stream_glob_wrapper.h"
#include "streams/php_stream_userspace.h"
#include "streams/php_stream_mmap.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _php_stream_statbuf
struct  _php_stream_dirent
struct  _php_stream_ops
struct  _php_stream_wrapper_ops
struct  _php_stream_wrapper
struct  _php_stream

Defines

#define STREAMS_D
#define STREAMS_C
#define STREAMS_REL_C
#define STREAMS_DC
#define STREAMS_CC
#define STREAMS_REL_CC
#define php_stream_alloc_rel(ops, thisptr, persistent, mode)   _php_stream_alloc((ops), (thisptr), (persistent), (mode) STREAMS_REL_CC TSRMLS_CC)
#define php_stream_copy_to_mem_rel(src, buf, maxlen, persistent)   _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_REL_CC TSRMLS_CC)
#define php_stream_fopen_rel(filename, mode, opened, options)   _php_stream_fopen((filename), (mode), (opened), (options) STREAMS_REL_CC TSRMLS_CC)
#define php_stream_fopen_with_path_rel(filename, mode, path, opened, options)   _php_stream_fopen_with_path((filename), (mode), (path), (opened), (options) STREAMS_REL_CC TSRMLS_CC)
#define php_stream_fopen_from_fd_rel(fd, mode, persistent_id)   _php_stream_fopen_from_fd((fd), (mode), (persistent_id) STREAMS_REL_CC TSRMLS_CC)
#define php_stream_fopen_from_file_rel(file, mode)   _php_stream_fopen_from_file((file), (mode) STREAMS_REL_CC TSRMLS_CC)
#define php_stream_fopen_from_pipe_rel(file, mode)   _php_stream_fopen_from_pipe((file), (mode) STREAMS_REL_CC TSRMLS_CC)
#define php_stream_fopen_tmpfile_rel()   _php_stream_fopen_tmpfile(0 STREAMS_REL_CC TSRMLS_CC)
#define php_stream_fopen_temporary_file_rel(dir, pfx, opened_path)   _php_stream_fopen_temporary_file((dir), (pfx), (opened_path) STREAMS_REL_CC TSRMLS_CC)
#define php_stream_open_wrapper_rel(path, mode, options, opened)   _php_stream_open_wrapper_ex((path), (mode), (options), (opened), NULL STREAMS_REL_CC TSRMLS_CC)
#define php_stream_open_wrapper_ex_rel(path, mode, options, opened, context)   _php_stream_open_wrapper_ex((path), (mode), (options), (opened), (context) STREAMS_REL_CC TSRMLS_CC)
#define php_stream_make_seekable_rel(origstream, newstream, flags)   _php_stream_make_seekable((origstream), (newstream), (flags) STREAMS_REL_CC TSRMLS_CC)
#define PHP_STREAM_FLAG_NO_SEEK   1
#define PHP_STREAM_FLAG_NO_BUFFER   2
#define PHP_STREAM_FLAG_EOL_UNIX   0 /* also includes DOS */
#define PHP_STREAM_FLAG_DETECT_EOL   4
#define PHP_STREAM_FLAG_EOL_MAC   8
#define PHP_STREAM_FLAG_AVOID_BLOCKING   16
#define PHP_STREAM_FLAG_NO_CLOSE   32
#define PHP_STREAM_FLAG_IS_DIR   64
#define PHP_STREAM_FLAG_NO_FCLOSE   128
#define PHP_STREAM_FCLOSE_NONE   0
#define PHP_STREAM_FCLOSE_FDOPEN   1
#define PHP_STREAM_FCLOSE_FOPENCOOKIE   2
#define php_stream_alloc(ops, thisptr, persistent_id, mode)   _php_stream_alloc((ops), (thisptr), (persistent_id), (mode) STREAMS_CC TSRMLS_CC)
#define php_stream_get_resource_id(stream)   (stream)->rsrc_id
#define php_stream_auto_cleanup(stream)   /* nothing */
#define php_stream_to_zval(stream, zval)   { ZVAL_RESOURCE(zval, (stream)->rsrc_id); }
#define php_stream_from_zval(xstr, ppzval)   ZEND_FETCH_RESOURCE2((xstr), php_stream *, (ppzval), -1, "stream", php_file_le_stream(), php_file_le_pstream())
#define php_stream_from_zval_no_verify(xstr, ppzval)   (xstr) = (php_stream*)zend_fetch_resource((ppzval) TSRMLS_CC, -1, "stream", NULL, 2, php_file_le_stream(), php_file_le_pstream())
#define PHP_STREAM_PERSISTENT_SUCCESS   0 /* id exists */
#define PHP_STREAM_PERSISTENT_FAILURE   1 /* id exists but is not a stream! */
#define PHP_STREAM_PERSISTENT_NOT_EXIST   2 /* id does not exist */
#define PHP_STREAM_FREE_CALL_DTOR   1 /* call ops->close */
#define PHP_STREAM_FREE_RELEASE_STREAM   2 /* pefree(stream) */
#define PHP_STREAM_FREE_PRESERVE_HANDLE   4 /* tell ops->close to not close it's underlying handle */
#define PHP_STREAM_FREE_RSRC_DTOR   8 /* called from the resource list dtor */
#define PHP_STREAM_FREE_PERSISTENT   16 /* manually freeing a persistent connection */
#define PHP_STREAM_FREE_CLOSE   (PHP_STREAM_FREE_CALL_DTOR | PHP_STREAM_FREE_RELEASE_STREAM)
#define PHP_STREAM_FREE_CLOSE_CASTED   (PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_PRESERVE_HANDLE)
#define PHP_STREAM_FREE_CLOSE_PERSISTENT   (PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_PERSISTENT)
#define php_stream_free(stream, close_options)   _php_stream_free((stream), (close_options) TSRMLS_CC)
#define php_stream_close(stream)   _php_stream_free((stream), PHP_STREAM_FREE_CLOSE TSRMLS_CC)
#define php_stream_pclose(stream)   _php_stream_free((stream), PHP_STREAM_FREE_CLOSE_PERSISTENT TSRMLS_CC)
#define php_stream_rewind(stream)   _php_stream_seek((stream), 0L, SEEK_SET TSRMLS_CC)
#define php_stream_seek(stream, offset, whence)   _php_stream_seek((stream), (offset), (whence) TSRMLS_CC)
#define php_stream_tell(stream)   _php_stream_tell((stream) TSRMLS_CC)
#define php_stream_read(stream, buf, count)   _php_stream_read((stream), (buf), (count) TSRMLS_CC)
#define php_stream_write_string(stream, str)   _php_stream_write(stream, str, strlen(str) TSRMLS_CC)
#define php_stream_write(stream, buf, count)   _php_stream_write(stream, (buf), (count) TSRMLS_CC)
#define php_stream_printf   _php_stream_printf
#define php_stream_eof(stream)   _php_stream_eof((stream) TSRMLS_CC)
#define php_stream_getc(stream)   _php_stream_getc((stream) TSRMLS_CC)
#define php_stream_putc(stream, c)   _php_stream_putc((stream), (c) TSRMLS_CC)
#define php_stream_flush(stream)   _php_stream_flush((stream), 0 TSRMLS_CC)
#define php_stream_gets(stream, buf, maxlen)   _php_stream_get_line((stream), (buf), (maxlen), NULL TSRMLS_CC)
#define php_stream_get_line(stream, buf, maxlen, retlen)   _php_stream_get_line((stream), (buf), (maxlen), (retlen) TSRMLS_CC)
#define php_stream_puts(stream, buf)   _php_stream_puts((stream), (buf) TSRMLS_CC)
#define php_stream_stat(stream, ssb)   _php_stream_stat((stream), (ssb) TSRMLS_CC)
#define php_stream_stat_path(path, ssb)   _php_stream_stat_path((path), 0, (ssb), NULL TSRMLS_CC)
#define php_stream_stat_path_ex(path, flags, ssb, context)   _php_stream_stat_path((path), (flags), (ssb), (context) TSRMLS_CC)
#define php_stream_mkdir(path, mode, options, context)   _php_stream_mkdir(path, mode, options, context TSRMLS_CC)
#define php_stream_rmdir(path, options, context)   _php_stream_rmdir(path, options, context TSRMLS_CC)
#define php_stream_opendir(path, options, context)   _php_stream_opendir((path), (options), (context) STREAMS_CC TSRMLS_CC)
#define php_stream_readdir(dirstream, dirent)   _php_stream_readdir((dirstream), (dirent) TSRMLS_CC)
#define php_stream_closedir(dirstream)   php_stream_close((dirstream))
#define php_stream_rewinddir(dirstream)   php_stream_rewind((dirstream))
#define php_stream_scandir(dirname, namelist, context, compare)   _php_stream_scandir((dirname), (namelist), 0, (context), (compare) TSRMLS_CC)
#define php_stream_set_option(stream, option, value, ptrvalue)   _php_stream_set_option((stream), (option), (value), (ptrvalue) TSRMLS_CC)
#define php_stream_set_chunk_size(stream, size)   _php_stream_set_option((stream), PHP_STREAM_OPTION_SET_CHUNK_SIZE, (size), NULL TSRMLS_CC)
#define PHP_STREAM_MKDIR_RECURSIVE   1
#define PHP_STREAM_URL_STAT_LINK   1
#define PHP_STREAM_URL_STAT_QUIET   2
#define PHP_STREAM_OPTION_BLOCKING   1
#define PHP_STREAM_OPTION_READ_BUFFER   2
#define PHP_STREAM_OPTION_WRITE_BUFFER   3
#define PHP_STREAM_BUFFER_NONE   0 /* unbuffered */
#define PHP_STREAM_BUFFER_LINE   1 /* line buffered */
#define PHP_STREAM_BUFFER_FULL   2 /* fully buffered */
#define PHP_STREAM_OPTION_READ_TIMEOUT   4
#define PHP_STREAM_OPTION_SET_CHUNK_SIZE   5
#define PHP_STREAM_OPTION_LOCKING   6
#define PHP_STREAM_LOCK_SUPPORTED   1
#define php_stream_supports_lock(stream)   _php_stream_set_option((stream), PHP_STREAM_OPTION_LOCKING, 0, (void *) PHP_STREAM_LOCK_SUPPORTED TSRMLS_CC) == 0 ? 1 : 0
#define php_stream_lock(stream, mode)   _php_stream_set_option((stream), PHP_STREAM_OPTION_LOCKING, (mode), (void *) NULL TSRMLS_CC)
#define PHP_STREAM_OPTION_XPORT_API   7 /* see php_stream_transport.h */
#define PHP_STREAM_OPTION_CRYPTO_API   8 /* see php_stream_transport.h */
#define PHP_STREAM_OPTION_MMAP_API   9 /* see php_stream_mmap.h */
#define PHP_STREAM_OPTION_TRUNCATE_API   10
#define PHP_STREAM_TRUNCATE_SUPPORTED   0
#define PHP_STREAM_TRUNCATE_SET_SIZE   1 /* ptrparam is a pointer to a size_t */
#define php_stream_truncate_supported(stream)   (_php_stream_set_option((stream), PHP_STREAM_OPTION_TRUNCATE_API, PHP_STREAM_TRUNCATE_SUPPORTED, NULL TSRMLS_CC) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0)
#define php_stream_truncate_set_size(stream, size)   _php_stream_truncate_set_size((stream), (size) TSRMLS_CC)
#define PHP_STREAM_OPTION_META_DATA_API   11 /* ptrparam is a zval* to which to add meta data information */
#define php_stream_populate_meta_data(stream, zv)   (_php_stream_set_option((stream), PHP_STREAM_OPTION_META_DATA_API, 0, zv TSRMLS_CC) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0)
#define PHP_STREAM_OPTION_CHECK_LIVENESS   12 /* no parameters */
#define PHP_STREAM_OPTION_RETURN_OK   0 /* option set OK */
#define PHP_STREAM_OPTION_RETURN_ERR   -1 /* problem setting option */
#define PHP_STREAM_OPTION_RETURN_NOTIMPL   -2 /* underlying stream does not implement; streams can handle it instead */
#define PHP_STREAM_COPY_ALL   ((size_t)-1)
#define php_stream_copy_to_stream(src, dest, maxlen)   _php_stream_copy_to_stream((src), (dest), (maxlen) STREAMS_CC TSRMLS_CC)
#define php_stream_copy_to_stream_ex(src, dest, maxlen, len)   _php_stream_copy_to_stream_ex((src), (dest), (maxlen), (len) STREAMS_CC TSRMLS_CC)
#define php_stream_copy_to_mem(src, buf, maxlen, persistent)   _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_CC TSRMLS_CC)
#define php_stream_passthru(stream)   _php_stream_passthru((stream) STREAMS_CC TSRMLS_CC)
#define PHP_STREAM_AS_STDIO   0
#define PHP_STREAM_AS_FD   1
#define PHP_STREAM_AS_SOCKETD   2
#define PHP_STREAM_AS_FD_FOR_SELECT   3
#define PHP_STREAM_CAST_TRY_HARD   0x80000000
#define PHP_STREAM_CAST_RELEASE   0x40000000 /* stream becomes invalid on success */
#define PHP_STREAM_CAST_INTERNAL   0x20000000 /* stream cast for internal use */
#define PHP_STREAM_CAST_MASK   (PHP_STREAM_CAST_TRY_HARD | PHP_STREAM_CAST_RELEASE | PHP_STREAM_CAST_INTERNAL)
#define php_stream_can_cast(stream, as)   _php_stream_cast((stream), (as), NULL, 0 TSRMLS_CC)
#define php_stream_cast(stream, as, ret, show_err)   _php_stream_cast((stream), (as), (ret), (show_err) TSRMLS_CC)
#define php_stream_is(stream, anops)   ((stream)->ops == anops)
#define PHP_STREAM_IS_STDIO   &php_stream_stdio_ops
#define php_stream_is_persistent(stream)   (stream)->is_persistent
#define IGNORE_PATH   0x00000000
#define USE_PATH   0x00000001
#define IGNORE_URL   0x00000002
#define ENFORCE_SAFE_MODE   0x00000004
#define REPORT_ERRORS   0x00000008
#define STREAM_MUST_SEEK   0x00000010
#define STREAM_WILL_CAST   0x00000020
#define STREAM_LOCATE_WRAPPERS_ONLY   0x00000040
#define STREAM_OPEN_FOR_INCLUDE   0x00000080
#define STREAM_USE_URL   0x00000100
#define STREAM_ONLY_GET_HEADERS   0x00000200
#define STREAM_DISABLE_OPEN_BASEDIR   0x00000400
#define STREAM_OPEN_PERSISTENT   0x00000800
#define STREAM_USE_GLOB_DIR_OPEN   0x00001000
#define STREAM_DISABLE_URL_PROTECTION   0x00002000
#define STREAM_ASSUME_REALPATH   0x00004000
#define IGNORE_URL_WIN   0
#define php_stream_open_wrapper(path, mode, options, opened)   _php_stream_open_wrapper_ex((path), (mode), (options), (opened), NULL STREAMS_CC TSRMLS_CC)
#define php_stream_open_wrapper_ex(path, mode, options, opened, context)   _php_stream_open_wrapper_ex((path), (mode), (options), (opened), (context) STREAMS_CC TSRMLS_CC)
#define php_stream_get_from_zval(stream, zstream, mode, options, opened, context)
#define PHP_STREAM_UNCHANGED   0 /* orig stream was seekable anyway */
#define PHP_STREAM_RELEASED   1 /* newstream should be used; origstream is no longer valid */
#define PHP_STREAM_FAILED   2 /* an error occurred while attempting conversion */
#define PHP_STREAM_CRITICAL   3 /* an error occurred; origstream is in an unknown state; you should close origstream */
#define PHP_STREAM_NO_PREFERENCE   0
#define PHP_STREAM_PREFER_STDIO   1
#define PHP_STREAM_FORCE_CONVERSION   2
#define php_stream_make_seekable(origstream, newstream, flags)   _php_stream_make_seekable((origstream), (newstream), (flags) STREAMS_CC TSRMLS_CC)
#define php_stream_get_url_stream_wrappers_hash()   _php_stream_get_url_stream_wrappers_hash(TSRMLS_C)
#define php_get_stream_filters_hash()   _php_get_stream_filters_hash(TSRMLS_C)
#define PHP_STREAM_IS_URL   1

Typedefs

typedef struct _php_stream
typedef struct _php_stream_wrapper
typedef struct _php_stream_context
typedef struct _php_stream_filter
typedef struct _php_stream_statbuf php_stream_statbuf
typedef struct _php_stream_dirent php_stream_dirent
typedef struct _php_stream_ops php_stream_ops
typedef struct
_php_stream_wrapper_ops 
php_stream_wrapper_ops

Functions

PHPAPI int php_file_le_stream (void)
PHPAPI int php_file_le_pstream (void)
PHPAPI int php_file_le_stream_filter (void)
PHPAPI php_stream * _php_stream_alloc (php_stream_ops *ops, void *abstract, const char *persistent_id, const char *mode STREAMS_DC TSRMLS_DC)
PHPAPI int php_stream_from_persistent_id (const char *persistent_id, php_stream **stream TSRMLS_DC)
PHPAPI int _php_stream_free (php_stream *stream, int close_options TSRMLS_DC)
PHPAPI int _php_stream_seek (php_stream *stream, off_t offset, int whence TSRMLS_DC)
PHPAPI off_t _php_stream_tell (php_stream *stream TSRMLS_DC)
PHPAPI size_t _php_stream_read (php_stream *stream, char *buf, size_t count TSRMLS_DC)
PHPAPI size_t _php_stream_write (php_stream *stream, const char *buf, size_t count TSRMLS_DC)
PHPAPI size_t _php_stream_printf (php_stream *stream TSRMLS_DC, const char *fmt,...) PHP_ATTRIBUTE_FORMAT(printf
PHPAPI int _php_stream_eof (php_stream *stream TSRMLS_DC)
PHPAPI int _php_stream_getc (php_stream *stream TSRMLS_DC)
PHPAPI int _php_stream_putc (php_stream *stream, int c TSRMLS_DC)
PHPAPI int _php_stream_flush (php_stream *stream, int closing TSRMLS_DC)
PHPAPI char * _php_stream_get_line (php_stream *stream, char *buf, size_t maxlen, size_t *returned_len TSRMLS_DC)
PHPAPI char * php_stream_get_record (php_stream *stream, size_t maxlen, size_t *returned_len, char *delim, size_t delim_len TSRMLS_DC)
PHPAPI int _php_stream_puts (php_stream *stream, char *buf TSRMLS_DC)
PHPAPI int _php_stream_stat (php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC)
PHPAPI int _php_stream_stat_path (char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
PHPAPI int _php_stream_mkdir (char *path, int mode, int options, php_stream_context *context TSRMLS_DC)
PHPAPI int _php_stream_rmdir (char *path, int options, php_stream_context *context TSRMLS_DC)
PHPAPI php_stream * _php_stream_opendir (char *path, int options, php_stream_context *context STREAMS_DC TSRMLS_DC)
PHPAPI php_stream_dirent_php_stream_readdir (php_stream *dirstream, php_stream_dirent *ent TSRMLS_DC)
PHPAPI int php_stream_dirent_alphasort (const char **a, const char **b)
PHPAPI int php_stream_dirent_alphasortr (const char **a, const char **b)
PHPAPI int _php_stream_scandir (char *dirname, char **namelist[], int flags, php_stream_context *context, int(*compare)(const char **a, const char **b) TSRMLS_DC)
PHPAPI int _php_stream_set_option (php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC)
PHPAPI int _php_stream_truncate_set_size (php_stream *stream, size_t newsize TSRMLS_DC)
ZEND_ATTRIBUTE_DEPRECATED
PHPAPI size_t 
_php_stream_copy_to_stream (php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC TSRMLS_DC)
PHPAPI size_t _php_stream_copy_to_stream_ex (php_stream *src, php_stream *dest, size_t maxlen, size_t *len STREAMS_DC TSRMLS_DC)
PHPAPI size_t _php_stream_copy_to_mem (php_stream *src, char **buf, size_t maxlen, int persistent STREAMS_DC TSRMLS_DC)
PHPAPI size_t _php_stream_passthru (php_stream *src STREAMS_DC TSRMLS_DC)
PHPAPI int _php_stream_cast (php_stream *stream, int castas, void **ret, int show_err TSRMLS_DC)
int php_init_stream_wrappers (int module_number TSRMLS_DC)
int php_shutdown_stream_wrappers (int module_number TSRMLS_DC)
void php_shutdown_stream_hashes (TSRMLS_D)
 PHP_RSHUTDOWN_FUNCTION (streams)
PHPAPI int php_register_url_stream_wrapper (char *protocol, php_stream_wrapper *wrapper TSRMLS_DC)
PHPAPI int php_unregister_url_stream_wrapper (char *protocol TSRMLS_DC)
PHPAPI int php_register_url_stream_wrapper_volatile (char *protocol, php_stream_wrapper *wrapper TSRMLS_DC)
PHPAPI int php_unregister_url_stream_wrapper_volatile (char *protocol TSRMLS_DC)
PHPAPI php_stream * _php_stream_open_wrapper_ex (char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
PHPAPI php_stream_wrapper * php_stream_locate_url_wrapper (const char *path, char **path_for_open, int options TSRMLS_DC)
PHPAPI char * php_stream_locate_eol (php_stream *stream, char *buf, size_t buf_len TSRMLS_DC)
PHPAPI void php_stream_wrapper_log_error (php_stream_wrapper *wrapper, int options TSRMLS_DC, const char *fmt,...) PHP_ATTRIBUTE_FORMAT(printf
PHPAPI int _php_stream_make_seekable (php_stream *origstream, php_stream **newstream, int flags STREAMS_DC TSRMLS_DC)
PHPAPI HashTable_php_stream_get_url_stream_wrappers_hash (TSRMLS_D)
PHPAPI HashTablephp_stream_get_url_stream_wrappers_hash_global (void)
PHPAPI HashTable_php_get_stream_filters_hash (TSRMLS_D)
PHPAPI HashTablephp_get_stream_filters_hash_global (void)

Variables

php_stream_wrapper_opsphp_stream_user_wrapper_ops

Class Documentation

struct _php_stream_statbuf

Definition at line 106 of file php_streams.h.

struct _php_stream_dirent

Definition at line 111 of file php_streams.h.

Class Members
char d_name
struct _php_stream_wrapper

Definition at line 159 of file php_streams.h.

Collaboration diagram for _php_stream_wrapper:
Class Members
void * abstract
int err_count
char ** err_stack
int is_url
php_stream_wrapper_ops * wops
struct _php_stream

Definition at line 188 of file php_streams.h.

Collaboration diagram for _php_stream:
Class Members
void * abstract
size_t chunk_size
php_stream_context * context
int eof
int fclose_stdiocast
int fgetss_state
int flags
int in_free
int is_persistent
char mode
php_stream_ops * ops
char * orig_path
off_t position
unsigned char * readbuf
size_t readbuflen
php_stream_filter_chain readfilters
off_t readpos
int rsrc_id
FILE * stdiocast
php_stream_wrapper * wrapper
zval * wrapperdata
void * wrapperthis
php_stream_filter_chain writefilters
off_t writepos

Define Documentation

#define ENFORCE_SAFE_MODE   0x00000004

Definition at line 487 of file php_streams.h.

#define IGNORE_PATH   0x00000000

Definition at line 484 of file php_streams.h.

#define IGNORE_URL   0x00000002

Definition at line 486 of file php_streams.h.

#define IGNORE_URL_WIN   0

Definition at line 530 of file php_streams.h.

Definition at line 578 of file php_streams.h.

#define php_stream_alloc (   ops,
  thisptr,
  persistent_id,
  mode 
)    _php_stream_alloc((ops), (thisptr), (persistent_id), (mode) STREAMS_CC TSRMLS_CC)

Definition at line 243 of file php_streams.h.

#define php_stream_alloc_rel (   ops,
  thisptr,
  persistent,
  mode 
)    _php_stream_alloc((ops), (thisptr), (persistent), (mode) STREAMS_REL_CC TSRMLS_CC)

Definition at line 62 of file php_streams.h.

#define PHP_STREAM_AS_FD   1

Definition at line 457 of file php_streams.h.

Definition at line 461 of file php_streams.h.

#define PHP_STREAM_AS_SOCKETD   2

Definition at line 459 of file php_streams.h.

#define PHP_STREAM_AS_STDIO   0

Definition at line 455 of file php_streams.h.

#define php_stream_auto_cleanup (   stream)    /* nothing */

Definition at line 254 of file php_streams.h.

#define PHP_STREAM_BUFFER_FULL   2 /* fully buffered */

Definition at line 382 of file php_streams.h.

#define PHP_STREAM_BUFFER_LINE   1 /* line buffered */

Definition at line 381 of file php_streams.h.

#define PHP_STREAM_BUFFER_NONE   0 /* unbuffered */

Definition at line 380 of file php_streams.h.

#define php_stream_can_cast (   stream,
  as 
)    _php_stream_cast((stream), (as), NULL, 0 TSRMLS_CC)

Definition at line 472 of file php_streams.h.

#define php_stream_cast (   stream,
  as,
  ret,
  show_err 
)    _php_stream_cast((stream), (as), (ret), (show_err) TSRMLS_CC)

Definition at line 473 of file php_streams.h.

#define PHP_STREAM_CAST_INTERNAL   0x20000000 /* stream cast for internal use */

Definition at line 466 of file php_streams.h.

Definition at line 467 of file php_streams.h.

#define PHP_STREAM_CAST_RELEASE   0x40000000 /* stream becomes invalid on success */

Definition at line 465 of file php_streams.h.

#define PHP_STREAM_CAST_TRY_HARD   0x80000000

Definition at line 464 of file php_streams.h.

Definition at line 278 of file php_streams.h.

#define php_stream_closedir (   dirstream)    php_stream_close((dirstream))

Definition at line 343 of file php_streams.h.

#define PHP_STREAM_COPY_ALL   ((size_t)-1)

Definition at line 426 of file php_streams.h.

#define php_stream_copy_to_mem (   src,
  buf,
  maxlen,
  persistent 
)    _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_CC TSRMLS_CC)

Definition at line 440 of file php_streams.h.

#define php_stream_copy_to_mem_rel (   src,
  buf,
  maxlen,
  persistent 
)    _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_REL_CC TSRMLS_CC)

Definition at line 64 of file php_streams.h.

#define php_stream_copy_to_stream (   src,
  dest,
  maxlen 
)    _php_stream_copy_to_stream((src), (dest), (maxlen) STREAMS_CC TSRMLS_CC)

Definition at line 431 of file php_streams.h.

#define php_stream_copy_to_stream_ex (   src,
  dest,
  maxlen,
  len 
)    _php_stream_copy_to_stream_ex((src), (dest), (maxlen), (len) STREAMS_CC TSRMLS_CC)

Definition at line 433 of file php_streams.h.

#define PHP_STREAM_CRITICAL   3 /* an error occurred; origstream is in an unknown state; you should close origstream */

Definition at line 565 of file php_streams.h.

Definition at line 305 of file php_streams.h.

#define PHP_STREAM_FAILED   2 /* an error occurred while attempting conversion */

Definition at line 564 of file php_streams.h.

#define PHP_STREAM_FCLOSE_FDOPEN   1

Definition at line 235 of file php_streams.h.

Definition at line 236 of file php_streams.h.

#define PHP_STREAM_FCLOSE_NONE   0

Definition at line 234 of file php_streams.h.

Definition at line 180 of file php_streams.h.

Definition at line 173 of file php_streams.h.

#define PHP_STREAM_FLAG_EOL_MAC   8

Definition at line 174 of file php_streams.h.

#define PHP_STREAM_FLAG_EOL_UNIX   0 /* also includes DOS */

Definition at line 172 of file php_streams.h.

#define PHP_STREAM_FLAG_IS_DIR   64

Definition at line 184 of file php_streams.h.

#define PHP_STREAM_FLAG_NO_BUFFER   2

Definition at line 170 of file php_streams.h.

#define PHP_STREAM_FLAG_NO_CLOSE   32

Definition at line 182 of file php_streams.h.

#define PHP_STREAM_FLAG_NO_FCLOSE   128

Definition at line 186 of file php_streams.h.

#define PHP_STREAM_FLAG_NO_SEEK   1

Definition at line 169 of file php_streams.h.

Definition at line 314 of file php_streams.h.

#define php_stream_fopen_from_fd_rel (   fd,
  mode,
  persistent_id 
)    _php_stream_fopen_from_fd((fd), (mode), (persistent_id) STREAMS_REL_CC TSRMLS_CC)

Definition at line 70 of file php_streams.h.

#define php_stream_fopen_from_file_rel (   file,
  mode 
)    _php_stream_fopen_from_file((file), (mode) STREAMS_REL_CC TSRMLS_CC)

Definition at line 71 of file php_streams.h.

#define php_stream_fopen_from_pipe_rel (   file,
  mode 
)    _php_stream_fopen_from_pipe((file), (mode) STREAMS_REL_CC TSRMLS_CC)

Definition at line 73 of file php_streams.h.

#define php_stream_fopen_rel (   filename,
  mode,
  opened,
  options 
)    _php_stream_fopen((filename), (mode), (opened), (options) STREAMS_REL_CC TSRMLS_CC)

Definition at line 66 of file php_streams.h.

#define php_stream_fopen_temporary_file_rel (   dir,
  pfx,
  opened_path 
)    _php_stream_fopen_temporary_file((dir), (pfx), (opened_path) STREAMS_REL_CC TSRMLS_CC)

Definition at line 77 of file php_streams.h.

Definition at line 75 of file php_streams.h.

#define php_stream_fopen_with_path_rel (   filename,
  mode,
  path,
  opened,
  options 
)    _php_stream_fopen_with_path((filename), (mode), (path), (opened), (options) STREAMS_REL_CC TSRMLS_CC)

Definition at line 68 of file php_streams.h.

Definition at line 568 of file php_streams.h.

#define php_stream_free (   stream,
  close_options 
)    _php_stream_free((stream), (close_options) TSRMLS_CC)

Definition at line 277 of file php_streams.h.

#define PHP_STREAM_FREE_CALL_DTOR   1 /* call ops->close */

Definition at line 267 of file php_streams.h.

Definition at line 272 of file php_streams.h.

Definition at line 273 of file php_streams.h.

Definition at line 274 of file php_streams.h.

#define PHP_STREAM_FREE_PERSISTENT   16 /* manually freeing a persistent connection */

Definition at line 271 of file php_streams.h.

#define PHP_STREAM_FREE_PRESERVE_HANDLE   4 /* tell ops->close to not close it's underlying handle */

Definition at line 269 of file php_streams.h.

Definition at line 268 of file php_streams.h.

#define PHP_STREAM_FREE_RSRC_DTOR   8 /* called from the resource list dtor */

Definition at line 270 of file php_streams.h.

#define php_stream_from_zval (   xstr,
  ppzval 
)    ZEND_FETCH_RESOURCE2((xstr), php_stream *, (ppzval), -1, "stream", php_file_le_stream(), php_file_le_pstream())

Definition at line 258 of file php_streams.h.

#define php_stream_from_zval_no_verify (   xstr,
  ppzval 
)    (xstr) = (php_stream*)zend_fetch_resource((ppzval) TSRMLS_CC, -1, "stream", NULL, 2, php_file_le_stream(), php_file_le_pstream())

Definition at line 259 of file php_streams.h.

#define php_stream_get_from_zval (   stream,
  zstream,
  mode,
  options,
  opened,
  context 
)
Value:
if (Z_TYPE_PP((zstream)) == IS_RESOURCE) { \
                     php_stream_from_zval((stream), (zstream)); \
              } else (stream) = Z_TYPE_PP((zstream)) == IS_STRING ?  \
                     php_stream_open_wrapper_ex(Z_STRVAL_PP((zstream)), (mode), (options), (opened), (context)) : NULL

Definition at line 549 of file php_streams.h.

#define php_stream_get_line (   stream,
  buf,
  maxlen,
  retlen 
)    _php_stream_get_line((stream), (buf), (maxlen), (retlen) TSRMLS_CC)

Definition at line 319 of file php_streams.h.

#define php_stream_get_resource_id (   stream)    (stream)->rsrc_id

Definition at line 245 of file php_streams.h.

Definition at line 575 of file php_streams.h.

Definition at line 308 of file php_streams.h.

#define php_stream_gets (   stream,
  buf,
  maxlen 
)    _php_stream_get_line((stream), (buf), (maxlen), NULL TSRMLS_CC)

Definition at line 317 of file php_streams.h.

#define php_stream_is (   stream,
  anops 
)    ((stream)->ops == anops)

Definition at line 477 of file php_streams.h.

#define php_stream_is_persistent (   stream)    (stream)->is_persistent

Definition at line 480 of file php_streams.h.

Definition at line 478 of file php_streams.h.

#define PHP_STREAM_IS_URL   1

Definition at line 585 of file php_streams.h.

#define php_stream_lock (   stream,
  mode 
)    _php_stream_set_option((stream), PHP_STREAM_OPTION_LOCKING, (mode), (void *) NULL TSRMLS_CC)

Definition at line 395 of file php_streams.h.

#define PHP_STREAM_LOCK_SUPPORTED   1

Definition at line 392 of file php_streams.h.

#define php_stream_make_seekable (   origstream,
  newstream,
  flags 
)    _php_stream_make_seekable((origstream), (newstream), (flags) STREAMS_CC TSRMLS_CC)

Definition at line 571 of file php_streams.h.

#define php_stream_make_seekable_rel (   origstream,
  newstream,
  flags 
)    _php_stream_make_seekable((origstream), (newstream), (flags) STREAMS_REL_CC TSRMLS_CC)

Definition at line 82 of file php_streams.h.

#define php_stream_mkdir (   path,
  mode,
  options,
  context 
)    _php_stream_mkdir(path, mode, options, context TSRMLS_CC)

Definition at line 334 of file php_streams.h.

Definition at line 362 of file php_streams.h.

#define PHP_STREAM_NO_PREFERENCE   0

Definition at line 566 of file php_streams.h.

#define php_stream_open_wrapper (   path,
  mode,
  options,
  opened 
)    _php_stream_open_wrapper_ex((path), (mode), (options), (opened), NULL STREAMS_CC TSRMLS_CC)

Definition at line 546 of file php_streams.h.

#define php_stream_open_wrapper_ex (   path,
  mode,
  options,
  opened,
  context 
)    _php_stream_open_wrapper_ex((path), (mode), (options), (opened), (context) STREAMS_CC TSRMLS_CC)

Definition at line 547 of file php_streams.h.

#define php_stream_open_wrapper_ex_rel (   path,
  mode,
  options,
  opened,
  context 
)    _php_stream_open_wrapper_ex((path), (mode), (options), (opened), (context) STREAMS_REL_CC TSRMLS_CC)

Definition at line 80 of file php_streams.h.

#define php_stream_open_wrapper_rel (   path,
  mode,
  options,
  opened 
)    _php_stream_open_wrapper_ex((path), (mode), (options), (opened), NULL STREAMS_REL_CC TSRMLS_CC)

Definition at line 79 of file php_streams.h.

#define php_stream_opendir (   path,
  options,
  context 
)    _php_stream_opendir((path), (options), (context) STREAMS_CC TSRMLS_CC)

Definition at line 340 of file php_streams.h.

Definition at line 373 of file php_streams.h.

#define PHP_STREAM_OPTION_CHECK_LIVENESS   12 /* no parameters */

Definition at line 418 of file php_streams.h.

#define PHP_STREAM_OPTION_CRYPTO_API   8 /* see php_stream_transport.h */

Definition at line 399 of file php_streams.h.

#define PHP_STREAM_OPTION_LOCKING   6

Definition at line 389 of file php_streams.h.

#define PHP_STREAM_OPTION_META_DATA_API   11 /* ptrparam is a zval* to which to add meta data information */

Definition at line 413 of file php_streams.h.

#define PHP_STREAM_OPTION_MMAP_API   9 /* see php_stream_mmap.h */

Definition at line 400 of file php_streams.h.

Definition at line 377 of file php_streams.h.

Definition at line 385 of file php_streams.h.

#define PHP_STREAM_OPTION_RETURN_ERR   -1 /* problem setting option */

Definition at line 421 of file php_streams.h.

#define PHP_STREAM_OPTION_RETURN_NOTIMPL   -2 /* underlying stream does not implement; streams can handle it instead */

Definition at line 422 of file php_streams.h.

#define PHP_STREAM_OPTION_RETURN_OK   0 /* option set OK */

Definition at line 420 of file php_streams.h.

Definition at line 386 of file php_streams.h.

Definition at line 401 of file php_streams.h.

Definition at line 378 of file php_streams.h.

#define PHP_STREAM_OPTION_XPORT_API   7 /* see php_stream_transport.h */

Definition at line 398 of file php_streams.h.

Definition at line 444 of file php_streams.h.

Definition at line 279 of file php_streams.h.

#define PHP_STREAM_PERSISTENT_FAILURE   1 /* id exists but is not a stream! */

Definition at line 264 of file php_streams.h.

#define PHP_STREAM_PERSISTENT_NOT_EXIST   2 /* id does not exist */

Definition at line 265 of file php_streams.h.

#define PHP_STREAM_PERSISTENT_SUCCESS   0 /* id exists */

Definition at line 263 of file php_streams.h.

Definition at line 414 of file php_streams.h.

#define PHP_STREAM_PREFER_STDIO   1

Definition at line 567 of file php_streams.h.

Definition at line 302 of file php_streams.h.

#define php_stream_putc (   stream,
 
)    _php_stream_putc((stream), (c) TSRMLS_CC)

Definition at line 311 of file php_streams.h.

#define php_stream_puts (   stream,
  buf 
)    _php_stream_puts((stream), (buf) TSRMLS_CC)

Definition at line 324 of file php_streams.h.

#define php_stream_read (   stream,
  buf,
  count 
)    _php_stream_read((stream), (buf), (count) TSRMLS_CC)

Definition at line 289 of file php_streams.h.

#define php_stream_readdir (   dirstream,
  dirent 
)    _php_stream_readdir((dirstream), (dirent) TSRMLS_CC)

Definition at line 342 of file php_streams.h.

#define PHP_STREAM_RELEASED   1 /* newstream should be used; origstream is no longer valid */

Definition at line 563 of file php_streams.h.

#define php_stream_rewind (   stream)    _php_stream_seek((stream), 0L, SEEK_SET TSRMLS_CC)

Definition at line 282 of file php_streams.h.

#define php_stream_rewinddir (   dirstream)    php_stream_rewind((dirstream))

Definition at line 344 of file php_streams.h.

#define php_stream_rmdir (   path,
  options,
  context 
)    _php_stream_rmdir(path, options, context TSRMLS_CC)

Definition at line 337 of file php_streams.h.

#define php_stream_scandir (   dirname,
  namelist,
  context,
  compare 
)    _php_stream_scandir((dirname), (namelist), 0, (context), (compare) TSRMLS_CC)

Definition at line 351 of file php_streams.h.

#define php_stream_seek (   stream,
  offset,
  whence 
)    _php_stream_seek((stream), (offset), (whence) TSRMLS_CC)

Definition at line 283 of file php_streams.h.

Definition at line 356 of file php_streams.h.

#define php_stream_set_option (   stream,
  option,
  value,
  ptrvalue 
)    _php_stream_set_option((stream), (option), (value), (ptrvalue) TSRMLS_CC)

Definition at line 354 of file php_streams.h.

#define php_stream_stat (   stream,
  ssb 
)    _php_stream_stat((stream), (ssb) TSRMLS_CC)

Definition at line 327 of file php_streams.h.

#define php_stream_stat_path (   path,
  ssb 
)    _php_stream_stat_path((path), 0, (ssb), NULL TSRMLS_CC)

Definition at line 330 of file php_streams.h.

#define php_stream_stat_path_ex (   path,
  flags,
  ssb,
  context 
)    _php_stream_stat_path((path), (flags), (ssb), (context) TSRMLS_CC)

Definition at line 331 of file php_streams.h.

Definition at line 394 of file php_streams.h.

Definition at line 286 of file php_streams.h.

#define php_stream_to_zval (   stream,
  zval 
)    { ZVAL_RESOURCE(zval, (stream)->rsrc_id); }

Definition at line 255 of file php_streams.h.

#define PHP_STREAM_TRUNCATE_SET_SIZE   1 /* ptrparam is a pointer to a size_t */

Definition at line 404 of file php_streams.h.

Definition at line 410 of file php_streams.h.

Definition at line 403 of file php_streams.h.

Definition at line 406 of file php_streams.h.

#define PHP_STREAM_UNCHANGED   0 /* orig stream was seekable anyway */

Definition at line 562 of file php_streams.h.

#define PHP_STREAM_URL_STAT_LINK   1

Definition at line 369 of file php_streams.h.

#define PHP_STREAM_URL_STAT_QUIET   2

Definition at line 370 of file php_streams.h.

#define php_stream_write (   stream,
  buf,
  count 
)    _php_stream_write(stream, (buf), (count) TSRMLS_CC)

Definition at line 293 of file php_streams.h.

#define php_stream_write_string (   stream,
  str 
)    _php_stream_write(stream, str, strlen(str) TSRMLS_CC)

Definition at line 292 of file php_streams.h.

#define REPORT_ERRORS   0x00000008

Definition at line 488 of file php_streams.h.

#define STREAM_ASSUME_REALPATH   0x00004000

Definition at line 527 of file php_streams.h.

#define STREAM_DISABLE_OPEN_BASEDIR   0x00000400

Definition at line 515 of file php_streams.h.

#define STREAM_DISABLE_URL_PROTECTION   0x00002000

Definition at line 524 of file php_streams.h.

#define STREAM_LOCATE_WRAPPERS_ONLY   0x00000040

Definition at line 503 of file php_streams.h.

#define STREAM_MUST_SEEK   0x00000010

Definition at line 492 of file php_streams.h.

#define STREAM_ONLY_GET_HEADERS   0x00000200

Definition at line 512 of file php_streams.h.

#define STREAM_OPEN_FOR_INCLUDE   0x00000080

Definition at line 506 of file php_streams.h.

#define STREAM_OPEN_PERSISTENT   0x00000800

Definition at line 518 of file php_streams.h.

#define STREAM_USE_GLOB_DIR_OPEN   0x00001000

Definition at line 521 of file php_streams.h.

#define STREAM_USE_URL   0x00000100

Definition at line 509 of file php_streams.h.

#define STREAM_WILL_CAST   0x00000020

Definition at line 500 of file php_streams.h.

#define STREAMS_C

Definition at line 53 of file php_streams.h.

#define STREAMS_CC

Definition at line 56 of file php_streams.h.

#define STREAMS_D

Definition at line 52 of file php_streams.h.

#define STREAMS_DC

Definition at line 55 of file php_streams.h.

#define STREAMS_REL_C

Definition at line 54 of file php_streams.h.

#define STREAMS_REL_CC

Definition at line 57 of file php_streams.h.

#define USE_PATH   0x00000001

Definition at line 485 of file php_streams.h.


Typedef Documentation

typedef struct _php_stream

Definition at line 98 of file php_streams.h.

typedef struct _php_stream_context

Definition at line 100 of file php_streams.h.

typedef struct _php_stream_filter

Definition at line 101 of file php_streams.h.

typedef struct _php_stream_wrapper

Definition at line 99 of file php_streams.h.


Function Documentation

Definition at line 41 of file filter.c.

{
       return (FG(stream_filters) ? FG(stream_filters) : &stream_filters_hash);
}
PHPAPI php_stream* _php_stream_alloc ( php_stream_ops ops,
void *  abstract,
const char *  persistent_id,
const char *mode STREAMS_DC  TSRMLS_DC 
)

Definition at line 260 of file streams.c.

{
       php_stream *ret;

       ret = (php_stream*) pemalloc_rel_orig(sizeof(php_stream), persistent_id ? 1 : 0);

       memset(ret, 0, sizeof(php_stream));

       ret->readfilters.stream = ret;
       ret->writefilters.stream = ret;

#if STREAM_DEBUG
fprintf(stderr, "stream_alloc: %s:%p persistent=%s\n", ops->label, ret, persistent_id);
#endif

       ret->ops = ops;
       ret->abstract = abstract;
       ret->is_persistent = persistent_id ? 1 : 0;
       ret->chunk_size = FG(def_chunk_size);

#if ZEND_DEBUG
       ret->open_filename = __zend_orig_filename ? __zend_orig_filename : __zend_filename;
       ret->open_lineno = __zend_orig_lineno ? __zend_orig_lineno : __zend_lineno;
#endif

       if (FG(auto_detect_line_endings)) {
              ret->flags |= PHP_STREAM_FLAG_DETECT_EOL;
       }

       if (persistent_id) {
              zend_rsrc_list_entry le;

              Z_TYPE(le) = le_pstream;
              le.ptr = ret;
              le.refcount = 0;

              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;
              }
       }

       ret->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ret, persistent_id ? le_pstream : le_stream);
       strlcpy(ret->mode, mode, sizeof(ret->mode));

       return ret;
}

Here is the call graph for this function:

PHPAPI int _php_stream_cast ( php_stream *  stream,
int  castas,
void **  ret,
int show_err  TSRMLS_DC 
)

Definition at line 192 of file cast.c.

{
       int flags = castas & PHP_STREAM_CAST_MASK;
       castas &= ~PHP_STREAM_CAST_MASK;

       /* synchronize our buffer (if possible) */
       if (ret && castas != PHP_STREAM_AS_FD_FOR_SELECT) {
              php_stream_flush(stream);
              if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
                     off_t dummy;

                     stream->ops->seek(stream, stream->position, SEEK_SET, &dummy TSRMLS_CC);
                     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) {
                            *(FILE**)ret = stream->stdiocast;
                     }
                     goto exit_success;
              }

              /* 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
              ) {
                     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) {
                     goto exit_success;
              }

              {
                     char fixed_mode[5];
                     php_stream_mode_sanitize_fdopen_fopencookie(stream, fixed_mode);
                     *(FILE**)ret = fopencookie(stream, fixed_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) {
                            fseek(*ret, pos, SEEK_SET);
                     }

                     goto exit_success;
              }

              /* must be either:
                     a) programmer error
                     b) no memory
                     -> lets bail
              */
              php_error_docref(NULL TSRMLS_CC, E_ERROR, "fopencookie failed");
              return FAILURE;
#endif

              if (!php_stream_is_filtered(stream) && stream->ops->cast && stream->ops->cast(stream, castas, NULL TSRMLS_CC) == SUCCESS) {
                     if (FAILURE == stream->ops->cast(stream, castas, ret TSRMLS_CC)) {
                            return FAILURE;
                     }
                     goto exit_success;
              } else if (flags & PHP_STREAM_CAST_TRY_HARD) {
                     php_stream *newstream;

                     newstream = php_stream_fopen_tmpfile();
                     if (newstream) {
                            size_t retcopy = php_stream_copy_to_stream_ex(stream, newstream, PHP_STREAM_COPY_ALL, NULL);

                            if (retcopy != SUCCESS) {
                                   php_stream_close(newstream);
                            } else {
                                   int retcast = php_stream_cast(newstream, castas | flags, (void **)ret, show_err);

                                   if (retcast == SUCCESS) {
                                          rewind(*(FILE**)ret);
                                   }

                                   /* do some specialized cleanup */
                                   if ((flags & PHP_STREAM_CAST_RELEASE)) {
                                          php_stream_free(stream, PHP_STREAM_FREE_CLOSE_CASTED);
                                   }

                                   /* TODO: we probably should be setting .stdiocast and .fclose_stdiocast or
                                    * we may be leaking the FILE*. Needs investigation, though. */
                                   return retcast;
                            }
                     }
              }
       }

       if (php_stream_is_filtered(stream)) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot cast a filtered stream on this system");
              return FAILURE;
       } else if (stream->ops->cast && stream->ops->cast(stream, castas, ret TSRMLS_CC) == SUCCESS) {
              goto exit_success;
       }

       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"
              };

              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;

exit_success:

       if ((stream->writepos - stream->readpos) > 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));
       }

       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);
       }

       return SUCCESS;

}

Here is the call graph for this function:

PHPAPI size_t _php_stream_copy_to_mem ( php_stream *  src,
char **  buf,
size_t  maxlen,
int persistent STREAMS_DC  TSRMLS_DC 
)

Definition at line 1282 of file streams.c.

{
       size_t ret = 0;
       char *ptr;
       size_t len = 0, max_len;
       int step = CHUNK_SIZE;
       int min_room = CHUNK_SIZE / 4;
       php_stream_statbuf ssbuf;

       if (maxlen == 0) {
              return 0;
       }

       if (maxlen == PHP_STREAM_COPY_ALL) {
              maxlen = 0;
       }

       if (maxlen > 0) {
              ptr = *buf = pemalloc_rel_orig(maxlen + 1, persistent);
              while ((len < maxlen) && !php_stream_eof(src)) {
                     ret = php_stream_read(src, ptr, maxlen - len);
                     if (!ret) {
                            break;
                     }
                     len += ret;
                     ptr += ret;
              }
              *ptr = '\0';
              return len;
       }

       /* avoid many reallocs by allocating a good sized chunk to begin with, if
        * we can.  Note that the stream may be filtered, in which case the stat
        * result may be inaccurate, as the filter may inflate or deflate the
        * number of bytes that we can read.  In order to avoid an upsize followed
        * by a downsize of the buffer, overestimate by the step size (which is
        * 2K).  */
       if (php_stream_stat(src, &ssbuf) == 0 && ssbuf.sb.st_size > 0) {
              max_len = ssbuf.sb.st_size + step;
       } else {
              max_len = step;
       }

       ptr = *buf = pemalloc_rel_orig(max_len, persistent);

       while((ret = php_stream_read(src, ptr, max_len - len))) {
              len += ret;
              if (len + min_room >= max_len) {
                     *buf = perealloc_rel_orig(*buf, max_len + step, persistent);
                     max_len += step;
                     ptr = *buf + len;
              } else {
                     ptr += ret;
              }
       }
       if (len) {
              *buf = perealloc_rel_orig(*buf, len + 1, persistent);
              (*buf)[len] = '\0';
       } else {
              pefree(*buf, persistent);
              *buf = NULL;
       }
       return len;
}

Here is the call graph for this function:

ZEND_ATTRIBUTE_DEPRECATED PHPAPI size_t _php_stream_copy_to_stream ( php_stream *  src,
php_stream *  dest,
size_t maxlen STREAMS_DC  TSRMLS_DC 
)

Definition at line 1456 of file streams.c.

{
       size_t len;
       int ret = _php_stream_copy_to_stream_ex(src, dest, maxlen, &len STREAMS_REL_CC TSRMLS_CC);
       if (ret == SUCCESS && len == 0 && maxlen != 0) {
              return 1;
       }
       return len;
}

Here is the call graph for this function:

PHPAPI size_t _php_stream_copy_to_stream_ex ( php_stream *  src,
php_stream *  dest,
size_t  maxlen,
size_t *len STREAMS_DC  TSRMLS_DC 
)

Definition at line 1348 of file streams.c.

{
       char buf[CHUNK_SIZE];
       size_t readchunk;
       size_t haveread = 0;
       size_t didread;
       size_t dummy;
       php_stream_statbuf ssbuf;

       if (!len) {
              len = &dummy;
       }

       if (maxlen == 0) {
              *len = 0;
              return SUCCESS;
       }

       if (maxlen == PHP_STREAM_COPY_ALL) {
              maxlen = 0;
       }

       if (php_stream_stat(src, &ssbuf) == 0) {
              if (ssbuf.sb.st_size == 0
#ifdef S_ISREG
                     && S_ISREG(ssbuf.sb.st_mode)
#endif
              ) {
                     *len = 0;
                     return SUCCESS;
              }
       }

       if (php_stream_mmap_possible(src)) {
              char *p;
              size_t mapped;

              p = php_stream_mmap_range(src, php_stream_tell(src), maxlen, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped);

              if (p) {
                     mapped = php_stream_write(dest, p, mapped);

                     php_stream_mmap_unmap_ex(src, mapped);

                     *len = mapped;

                     /* we've got at least 1 byte to read.
                      * less than 1 is an error */

                     if (mapped > 0) {
                            return SUCCESS;
                     }
                     return FAILURE;
              }
       }

       while(1) {
              readchunk = sizeof(buf);

              if (maxlen && (maxlen - haveread) < readchunk) {
                     readchunk = maxlen - haveread;
              }

              didread = php_stream_read(src, buf, readchunk);

              if (didread) {
                     /* extra paranoid */
                     size_t didwrite, towrite;
                     char *writeptr;

                     towrite = didread;
                     writeptr = buf;
                     haveread += didread;

                     while(towrite) {
                            didwrite = php_stream_write(dest, writeptr, towrite);
                            if (didwrite == 0) {
                                   *len = haveread - (didread - towrite);
                                   return FAILURE;
                            }

                            towrite -= didwrite;
                            writeptr += didwrite;
                     }
              } else {
                     break;
              }

              if (maxlen - haveread == 0) {
                     break;
              }
       }

       *len = haveread;

       /* we've got at least 1 byte to read.
        * less than 1 is an error */

       if (haveread > 0 || src->eof) {
              return SUCCESS;
       }
       return FAILURE;
}

Here is the caller graph for this function:

PHPAPI int _php_stream_eof ( php_stream *stream  TSRMLS_DC)

Definition at line 677 of file streams.c.

{
       /* if there is data in the buffer, it's not EOF */
       if (stream->writepos - stream->readpos > 0) {
              return 0;
       }

       /* use the configured timeout when checking eof */
       if (!stream->eof && PHP_STREAM_OPTION_RETURN_ERR ==
                     php_stream_set_option(stream, PHP_STREAM_OPTION_CHECK_LIVENESS,
                     0, NULL)) {
              stream->eof = 1;
       }

       return stream->eof;
}
PHPAPI int _php_stream_flush ( php_stream *  stream,
int closing  TSRMLS_DC 
)

Definition at line 1082 of file streams.c.

{
       int ret = 0;

       if (stream->writefilters.head) {
              _php_stream_write_filtered(stream, NULL, 0, closing ? PSFS_FLAG_FLUSH_CLOSE : PSFS_FLAG_FLUSH_INC  TSRMLS_CC);
       }

       if (stream->ops->flush) {
              ret = stream->ops->flush(stream TSRMLS_CC);
       }

       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI int _php_stream_free ( php_stream *  stream,
int close_options  TSRMLS_DC 
)

Definition at line 317 of file streams.c.

{
       int ret = 1;
       int remove_rsrc = 1;
       int preserve_handle = close_options & PHP_STREAM_FREE_PRESERVE_HANDLE ? 1 : 0;
       int release_cast = 1;
       php_stream_context *context = stream->context;

       if (stream->flags & PHP_STREAM_FLAG_NO_CLOSE) {
              preserve_handle = 1;
       }

#if STREAM_DEBUG
fprintf(stderr, "stream_free: %s:%p[%s] in_free=%d opts=%08x\n", stream->ops->label, stream, stream->orig_path, stream->in_free, close_options);
#endif

       /* recursion protection */
       if (stream->in_free) {
              return 1;
       }

       stream->in_free++;

       /* if we are releasing the stream only (and preserving the underlying handle),
        * we need to do things a little differently.
        * We are only ever called like this when the stream is cast to a FILE*
        * for include (or other similar) purposes.
        * */
       if (preserve_handle) {
              if (stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FOPENCOOKIE) {
                     /* If the stream was fopencookied, we must NOT touch anything
                      * here, as the cookied stream relies on it all.
                      * Instead, mark the stream as OK to auto-clean */
                     php_stream_auto_cleanup(stream);
                     stream->in_free--;
                     return 0;
              }
              /* otherwise, make sure that we don't close the FILE* from a cast */
              release_cast = 0;
       }

#if STREAM_DEBUG
fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remove_rsrc=%d\n",
              stream->ops->label, stream, stream->orig_path, preserve_handle, release_cast, remove_rsrc);
#endif

       /* 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 actually only decreases the refcount; if we're
               * releasing the stream, we want to actually delete the resource from
               * the resource list, otherwise the resource will point to invalid memory.
               * In any case, let's always completely delete it from the resource list,
               * not only when PHP_STREAM_FREE_RELEASE_STREAM is set */
              while (zend_list_delete(stream->rsrc_id) == SUCCESS) {}
       }

       /* Remove stream from any context link list */
       if (stream->context && stream->context->links) {
              php_stream_context_del_link(stream->context, stream);
       }

       if (close_options & PHP_STREAM_FREE_CALL_DTOR) {
              if (release_cast && stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FOPENCOOKIE) {
                     /* calling fclose on an fopencookied stream will ultimately
                            call this very same function.  If we were called via fclose,
                            the cookie_closer unsets the fclose_stdiocast flags, so
                            we can be sure that we only reach here when PHP code calls
                            php_stream_free.
                            Lets let the cookie code clean it all up.
                      */
                     stream->in_free = 0;
                     return fclose(stream->stdiocast);
              }

              ret = stream->ops->close(stream, preserve_handle ? 0 : 1 TSRMLS_CC);
              stream->abstract = NULL;

              /* tidy up any FILE* that might have been fdopened */
              if (release_cast && stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FDOPEN && stream->stdiocast) {
                     fclose(stream->stdiocast);
                     stream->stdiocast = NULL;
                     stream->fclose_stdiocast = PHP_STREAM_FCLOSE_NONE;
              }
       }

       if (close_options & PHP_STREAM_FREE_RELEASE_STREAM) {
              while (stream->readfilters.head) {
                     php_stream_filter_remove(stream->readfilters.head, 1 TSRMLS_CC);
              }
              while (stream->writefilters.head) {
                     php_stream_filter_remove(stream->writefilters.head, 1 TSRMLS_CC);
              }

              if (stream->wrapper && stream->wrapper->wops && stream->wrapper->wops->stream_closer) {
                     stream->wrapper->wops->stream_closer(stream->wrapper, stream TSRMLS_CC);
                     stream->wrapper = NULL;
              }

              if (stream->wrapperdata) {
                     zval_ptr_dtor(&stream->wrapperdata);
                     stream->wrapperdata = NULL;
              }

              if (stream->readbuf) {
                     pefree(stream->readbuf, stream->is_persistent);
                     stream->readbuf = NULL;
              }

              if (stream->is_persistent && (close_options & PHP_STREAM_FREE_PERSISTENT)) {
                     /* we don't work with *stream but need its value for comparison */
                     zend_hash_apply_with_argument(&EG(persistent_list), (apply_func_arg_t) _php_stream_free_persistent, stream TSRMLS_CC);
              }
#if ZEND_DEBUG
              if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) && (stream->__exposed == 0) && (EG(error_reporting) & E_WARNING)) {
                     /* it leaked: Lets deliberately NOT pefree it so that the memory manager shows it
                      * as leaked; it will log a warning, but lets help it out and display what kind
                      * of stream it was. */
                     char *leakinfo;
                     spprintf(&leakinfo, 0, __FILE__ "(%d) : Stream of type '%s' %p (path:%s) was not closed\n", __LINE__, stream->ops->label, stream, stream->orig_path);

                     if (stream->orig_path) {
                            pefree(stream->orig_path, stream->is_persistent);
                            stream->orig_path = NULL;
                     }

# if defined(PHP_WIN32)
                     OutputDebugString(leakinfo);
# else
                     fprintf(stderr, "%s", leakinfo);
# endif
                     efree(leakinfo);
              } else {
                     if (stream->orig_path) {
                            pefree(stream->orig_path, stream->is_persistent);
                            stream->orig_path = NULL;
                     }

                     pefree(stream, stream->is_persistent);
              }
#else
              if (stream->orig_path) {
                     pefree(stream->orig_path, stream->is_persistent);
                     stream->orig_path = NULL;
              }

              pefree(stream, stream->is_persistent);
#endif
       }

       if (context) {
              zend_list_delete(context->rsrc_id);
       }

       return ret;
}

Here is the call graph for this function:

PHPAPI char* _php_stream_get_line ( php_stream *  stream,
char *  buf,
size_t  maxlen,
size_t *returned_len  TSRMLS_DC 
)

Definition at line 788 of file streams.c.

{
       size_t avail = 0;
       size_t current_buf_size = 0;
       size_t total_copied = 0;
       int grow_mode = 0;
       char *bufstart = buf;

       if (buf == NULL) {
              grow_mode = 1;
       } else if (maxlen == 0) {
              return NULL;
       }

       /*
        * 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.
        */

       for (;;) {
              avail = stream->writepos - stream->readpos;

              if (avail > 0) {
                     size_t cpysz = 0;
                     char *readptr;
                     char *eol;
                     int done = 0;

                     readptr = stream->readbuf + stream->readpos;
                     eol = php_stream_locate_eol(stream, NULL, 0 TSRMLS_CC);

                     if (eol) {
                            cpysz = eol - readptr + 1;
                            done = 1;
                     } else {
                            cpysz = avail;
                     }

                     if (grow_mode) {
                            /* allow room for a NUL. If this realloc is really a realloc
                             * (ie: second time around), we get an extra byte. In most
                             * cases, with the default chunk size of 8K, we will only
                             * incur that overhead once.  When people have lines longer
                             * than 8K, we waste 1 byte per additional 8K or so.
                             * That seems acceptable to me, to avoid making this code
                             * hard to follow */
                            bufstart = erealloc(bufstart, current_buf_size + cpysz + 1);
                            current_buf_size += cpysz + 1;
                            buf = bufstart + total_copied;
                     } else {
                            if (cpysz >= maxlen - 1) {
                                   cpysz = maxlen - 1;
                                   done = 1;
                            }
                     }

                     memcpy(buf, readptr, cpysz);

                     stream->position += cpysz;
                     stream->readpos += cpysz;
                     buf += cpysz;
                     maxlen -= cpysz;
                     total_copied += cpysz;

                     if (done) {
                            break;
                     }
              } else if (stream->eof) {
                     break;
              } else {
                     /* XXX: Should be fine to always read chunk_size */
                     size_t toread;

                     if (grow_mode) {
                            toread = stream->chunk_size;
                     } else {
                            toread = maxlen - 1;
                            if (toread > stream->chunk_size) {
                                   toread = stream->chunk_size;
                            }
                     }

                     php_stream_fill_read_buffer(stream, toread TSRMLS_CC);

                     if (stream->writepos - stream->readpos == 0) {
                            break;
                     }
              }
       }

       if (total_copied == 0) {
              if (grow_mode) {
                     assert(bufstart == NULL);
              }
              return NULL;
       }

       buf[0] = '\0';
       if (returned_len) {
              *returned_len = total_copied;
       }

       return bufstart;
}

Here is the call graph for this function:

Definition at line 58 of file streams.c.

{
       return (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash);
}
PHPAPI int _php_stream_getc ( php_stream *stream  TSRMLS_DC)

Definition at line 704 of file streams.c.

{
       char buf;

       if (php_stream_read(stream, &buf, 1) > 0) {
              return buf & 0xff;
       }
       return EOF;
}
PHPAPI int _php_stream_make_seekable ( php_stream *  origstream,
php_stream **  newstream,
int flags STREAMS_DC  TSRMLS_DC 
)

Definition at line 369 of file cast.c.

{
       if (newstream == NULL) {
              return PHP_STREAM_FAILED;
       }
       *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) {
              *newstream = php_stream_fopen_tmpfile();
       } else {
              *newstream = php_stream_temp_new();
       }

       if (*newstream == NULL) {
              return PHP_STREAM_FAILED;
       }

#if ZEND_DEBUG
       (*newstream)->open_filename = origstream->open_filename;
       (*newstream)->open_lineno = origstream->open_lineno;
#endif

       if (php_stream_copy_to_stream_ex(origstream, *newstream, PHP_STREAM_COPY_ALL, NULL) != SUCCESS) {
              php_stream_close(*newstream);
              *newstream = NULL;
              return PHP_STREAM_CRITICAL;
       }

       php_stream_close(origstream);
       php_stream_seek(*newstream, 0, SEEK_SET);

       return PHP_STREAM_RELEASED;
}
PHPAPI int _php_stream_mkdir ( char *  path,
int  mode,
int  options,
php_stream_context *context  TSRMLS_DC 
)

Definition at line 1739 of file streams.c.

{
       php_stream_wrapper *wrapper = NULL;

       wrapper = php_stream_locate_url_wrapper(path, NULL, ENFORCE_SAFE_MODE TSRMLS_CC);
       if (!wrapper || !wrapper->wops || !wrapper->wops->stream_mkdir) {
              return 0;
       }

       return wrapper->wops->stream_mkdir(wrapper, path, mode, options, context TSRMLS_CC);
}

Here is the call graph for this function:

PHPAPI php_stream* _php_stream_open_wrapper_ex ( char *  path,
char *  mode,
int  options,
char **  opened_path,
php_stream_context *context STREAMS_DC  TSRMLS_DC 
)

Definition at line 1862 of file streams.c.

{
       php_stream *stream = NULL;
       php_stream_wrapper *wrapper = NULL;
       char *path_to_open;
       int persistent = options & STREAM_OPEN_PERSISTENT;
       char *resolved_path = NULL;
       char *copy_of_path = NULL;


       if (opened_path) {
              *opened_path = NULL;
       }

       if (!path || !*path) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Filename cannot be empty");
              return NULL;
       }

       if (options & USE_PATH) {
              resolved_path = zend_resolve_path(path, strlen(path) TSRMLS_CC);
              if (resolved_path) {
                     path = resolved_path;
                     /* we've found this file, don't re-check include_path or run realpath */
                     options |= STREAM_ASSUME_REALPATH;
                     options &= ~USE_PATH;
              }
       }

       path_to_open = path;

       wrapper = php_stream_locate_url_wrapper(path, &path_to_open, options TSRMLS_CC);
       if (options & STREAM_USE_URL && (!wrapper || !wrapper->is_url)) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function may only be used against URLs");
              if (resolved_path) {
                     efree(resolved_path);
              }
              return NULL;
       }

       if (wrapper) {
              if (!wrapper->wops->stream_opener) {
                     php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC,
                                   "wrapper does not support stream open");
              } else {
                     stream = wrapper->wops->stream_opener(wrapper,
                            path_to_open, mode, options ^ REPORT_ERRORS,
                            opened_path, context STREAMS_REL_CC TSRMLS_CC);
              }

              /* if the caller asked for a persistent stream but the wrapper did not
               * return one, force an error here */
              if (stream && (options & STREAM_OPEN_PERSISTENT) && !stream->is_persistent) {
                     php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC,
                                   "wrapper does not support persistent streams");
                     php_stream_close(stream);
                     stream = NULL;
              }

              if (stream) {
                     stream->wrapper = wrapper;
              }
       }

       if (stream) {
              if (opened_path && !*opened_path && resolved_path) {
                     *opened_path = resolved_path;
                     resolved_path = NULL;
              }
              if (stream->orig_path) {
                     pefree(stream->orig_path, persistent);
              }
              copy_of_path = pestrdup(path, persistent);
              stream->orig_path = copy_of_path;
#if ZEND_DEBUG
              stream->open_filename = __zend_orig_filename ? __zend_orig_filename : __zend_filename;
              stream->open_lineno = __zend_orig_lineno ? __zend_orig_lineno : __zend_lineno;
#endif
       }

       if (stream != NULL && (options & STREAM_MUST_SEEK)) {
              php_stream *newstream;

              switch(php_stream_make_seekable_rel(stream, &newstream,
                                   (options & STREAM_WILL_CAST)
                                          ? PHP_STREAM_PREFER_STDIO : PHP_STREAM_NO_PREFERENCE)) {
                     case PHP_STREAM_UNCHANGED:
                            if (resolved_path) {
                                   efree(resolved_path);
                            }
                            return stream;
                     case PHP_STREAM_RELEASED:
                            if (newstream->orig_path) {
                                   pefree(newstream->orig_path, persistent);
                            }
                            newstream->orig_path = pestrdup(path, persistent);
                            if (resolved_path) {
                                   efree(resolved_path);
                            }
                            return newstream;
                     default:
                            php_stream_close(stream);
                            stream = NULL;
                            if (options & REPORT_ERRORS) {
                                   char *tmp = estrdup(path);
                                   php_strip_url_passwd(tmp);
                                   php_error_docref1(NULL TSRMLS_CC, tmp, E_WARNING, "could not make seekable - %s",
                                                 tmp);
                                   efree(tmp);

                                   options ^= REPORT_ERRORS;
                            }
              }
       }

       if (stream && stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0 && strchr(mode, 'a') && stream->position == 0) {
              off_t newpos = 0;

              /* if opened for append, we need to revise our idea of the initial file position */
              if (0 == stream->ops->seek(stream, 0, SEEK_CUR, &newpos TSRMLS_CC)) {
                     stream->position = newpos;
              }
       }

       if (stream == NULL && (options & REPORT_ERRORS)) {
              php_stream_display_wrapper_errors(wrapper, path, "failed to open stream" TSRMLS_CC);
              if (opened_path && *opened_path) {
                     efree(*opened_path);
                     *opened_path = NULL;
              }
       }
       php_stream_tidy_wrapper_error_log(wrapper TSRMLS_CC);
#if ZEND_DEBUG
       if (stream == NULL && copy_of_path != NULL) {
              pefree(copy_of_path, persistent);
       }
#endif
       if (resolved_path) {
              efree(resolved_path);
       }
       return stream;
}

Here is the call graph for this function:

PHPAPI php_stream* _php_stream_opendir ( char *  path,
int  options,
php_stream_context *context STREAMS_DC  TSRMLS_DC 
)

Definition at line 1813 of file streams.c.

{
       php_stream *stream = NULL;
       php_stream_wrapper *wrapper = NULL;
       char *path_to_open;

       if (!path || !*path) {
              return NULL;
       }

       path_to_open = path;

       wrapper = php_stream_locate_url_wrapper(path, &path_to_open, options TSRMLS_CC);

       if (wrapper && wrapper->wops->dir_opener) {
              stream = wrapper->wops->dir_opener(wrapper,
                            path_to_open, "r", options ^ REPORT_ERRORS, NULL,
                            context STREAMS_REL_CC TSRMLS_CC);

              if (stream) {
                     stream->wrapper = wrapper;
                     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");
       }
       if (stream == NULL && (options & REPORT_ERRORS)) {
              php_stream_display_wrapper_errors(wrapper, path, "failed to open dir" TSRMLS_CC);
       }
       php_stream_tidy_wrapper_error_log(wrapper TSRMLS_CC);

       return stream;
}

Here is the call graph for this function:

PHPAPI size_t _php_stream_passthru ( php_stream *src STREAMS_DC  TSRMLS_DC)
PHPAPI size_t _php_stream_printf ( php_stream *stream  TSRMLS_DC,
const char *  fmt,
  ... 
)
PHPAPI int _php_stream_putc ( php_stream *  stream,
int TSRMLS_DC 
)

Definition at line 694 of file streams.c.

{
       unsigned char buf = c;

       if (php_stream_write(stream, &buf, 1) > 0) {
              return 1;
       }
       return EOF;
}
PHPAPI int _php_stream_puts ( php_stream *  stream,
char *buf  TSRMLS_DC 
)

Definition at line 714 of file streams.c.

{
       int len;
       char newline[2] = "\n"; /* is this OK for Win? */
       len = strlen(buf);

       if (len > 0 && php_stream_write(stream, buf, len) && php_stream_write(stream, newline, 1)) {
              return 1;
       }
       return 0;
}
PHPAPI size_t _php_stream_read ( php_stream *  stream,
char *  buf,
size_t count  TSRMLS_DC 
)

Here is the caller graph for this function:

PHPAPI php_stream_dirent* _php_stream_readdir ( php_stream *  dirstream,
php_stream_dirent *ent  TSRMLS_DC 
)

Definition at line 1850 of file streams.c.

{

       if (sizeof(php_stream_dirent) == php_stream_read(dirstream, (char*)ent, sizeof(php_stream_dirent))) {
              return ent;
       }

       return NULL;
}
PHPAPI int _php_stream_rmdir ( char *  path,
int  options,
php_stream_context *context  TSRMLS_DC 
)

Definition at line 1754 of file streams.c.

{
       php_stream_wrapper *wrapper = NULL;

       wrapper = php_stream_locate_url_wrapper(path, NULL, ENFORCE_SAFE_MODE TSRMLS_CC);
       if (!wrapper || !wrapper->wops || !wrapper->wops->stream_rmdir) {
              return 0;
       }

       return wrapper->wops->stream_rmdir(wrapper, path, options, context TSRMLS_CC);
}

Here is the call graph for this function:

PHPAPI int _php_stream_scandir ( char *  dirname,
char **  namelist[],
int  flags,
php_stream_context *  context,
int(*)(const char **a, const char **b) TSRMLS_DC  compare 
)

Definition at line 2188 of file streams.c.

{
       php_stream *stream;
       php_stream_dirent sdp;
       char **vector = NULL;
       int vector_size = 0;
       int nfiles = 0;

       if (!namelist) {
              return FAILURE;
       }

       stream = php_stream_opendir(dirname, ENFORCE_SAFE_MODE | REPORT_ERRORS, context);
       if (!stream) {
              return FAILURE;
       }

       while (php_stream_readdir(stream, &sdp)) {
              if (nfiles == vector_size) {
                     if (vector_size == 0) {
                            vector_size = 10;
                     } else {
                            vector_size *= 2;
                     }
                     vector = (char **) erealloc(vector, vector_size * sizeof(char *));
              }

              vector[nfiles] = estrdup(sdp.d_name);

              nfiles++;
       }
       php_stream_closedir(stream);

       *namelist = vector;

       if (compare) {
              qsort(*namelist, nfiles, sizeof(char *), (int(*)(const void *, const void *))compare);
       }
       return nfiles;
}

Here is the call graph for this function:

PHPAPI int _php_stream_seek ( php_stream *  stream,
off_t  offset,
int whence  TSRMLS_DC 
)

Definition at line 1135 of file streams.c.

{
       if (stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FOPENCOOKIE) {
              /* flush to commit data written to the fopencookie FILE* */
              fflush(stream->stdiocast);
       }

       /* handle the case where we are in the buffer */
       if ((stream->flags & PHP_STREAM_FLAG_NO_BUFFER) == 0) {
              switch(whence) {
                     case SEEK_CUR:
                            if (offset > 0 && offset <= stream->writepos - stream->readpos) {
                                   stream->readpos += offset; /* if offset = ..., then readpos = writepos */
                                   stream->position += offset;
                                   stream->eof = 0;
                                   return 0;
                            }
                            break;
                     case SEEK_SET:
                            if (offset > stream->position &&
                                          offset <= stream->position + stream->writepos - stream->readpos) {
                                   stream->readpos += offset - stream->position;
                                   stream->position = offset;
                                   stream->eof = 0;
                                   return 0;
                            }
                            break;
              }
       }


       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;
                            whence = SEEK_SET;
                            break;
              }
              ret = stream->ops->seek(stream, offset, whence, &stream->position TSRMLS_CC);

              if (((stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) || ret == 0) {
                     if (ret == 0) {
                            stream->eof = 0;
                     }

                     /* invalidate the buffer contents */
                     stream->readpos = stream->writepos = 0;

                     return ret;
              }
              /* else the stream has decided that it can't support seeking after all;
               * fall through to attempt emulation */
       }

       /* emulate forward moving seeks with reads */
       if (whence == SEEK_CUR && offset >= 0) {
              char tmp[1024];
              size_t didread;
              while(offset > 0) {
                     if ((didread = php_stream_read(stream, tmp, MIN(offset, sizeof(tmp)))) == 0) {
                            return -1;
                     }
                     offset -= didread;
              }
              stream->eof = 0;
              return 0;
       }

       php_error_docref(NULL TSRMLS_CC, E_WARNING, "stream does not support seeking");

       return -1;
}

Here is the call graph for this function:

PHPAPI int _php_stream_set_option ( php_stream *  stream,
int  option,
int  value,
void *ptrparam  TSRMLS_DC 
)

Definition at line 1214 of file streams.c.

{
       int ret = PHP_STREAM_OPTION_RETURN_NOTIMPL;

       if (stream->ops->set_option) {
              ret = stream->ops->set_option(stream, option, value, ptrparam TSRMLS_CC);
       }

       if (ret == PHP_STREAM_OPTION_RETURN_NOTIMPL) {
              switch(option) {
                     case PHP_STREAM_OPTION_SET_CHUNK_SIZE:
                            ret = stream->chunk_size;
                            stream->chunk_size = value;
                            return ret;

                     case PHP_STREAM_OPTION_READ_BUFFER:
                            /* try to match the buffer mode as best we can */
                            if (value == PHP_STREAM_BUFFER_NONE) {
                                   stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
                            } else if (stream->flags & PHP_STREAM_FLAG_NO_BUFFER) {
                                   stream->flags ^= PHP_STREAM_FLAG_NO_BUFFER;
                            }
                            ret = PHP_STREAM_OPTION_RETURN_OK;
                            break;

                     default:
                            ;
              }
       }

       return ret;
}
PHPAPI int _php_stream_stat ( php_stream *  stream,
php_stream_statbuf *ssb  TSRMLS_DC 
)

Definition at line 726 of file streams.c.

{
       memset(ssb, 0, sizeof(*ssb));

       /* if the stream was wrapped, allow the wrapper to stat it */
       if (stream->wrapper && stream->wrapper->wops->stream_stat != NULL) {
              return stream->wrapper->wops->stream_stat(stream->wrapper, stream, ssb TSRMLS_CC);
       }

       /* if the stream doesn't directly support stat-ing, return with failure.
        * We could try and emulate this by casting to a FD and fstat-ing it,
        * but since the fd might not represent the actual underlying content
        * this would give bogus results. */
       if (stream->ops->stat == NULL) {
              return -1;
       }

       return (stream->ops->stat)(stream, ssb TSRMLS_CC);
}
PHPAPI int _php_stream_stat_path ( char *  path,
int  flags,
php_stream_statbuf ssb,
php_stream_context *context  TSRMLS_DC 
)

Definition at line 1768 of file streams.c.

{
       php_stream_wrapper *wrapper = NULL;
       char *path_to_open = path;
       int ret;

       /* Try to hit the cache first */
       if (flags & PHP_STREAM_URL_STAT_LINK) {
              if (BG(CurrentLStatFile) && strcmp(path, BG(CurrentLStatFile)) == 0) {
                     memcpy(ssb, &BG(lssb), sizeof(php_stream_statbuf));
                     return 0;
              }
       } else {
              if (BG(CurrentStatFile) && strcmp(path, BG(CurrentStatFile)) == 0) {
                     memcpy(ssb, &BG(ssb), sizeof(php_stream_statbuf));
                     return 0;
              }
       }

       wrapper = php_stream_locate_url_wrapper(path, &path_to_open, ENFORCE_SAFE_MODE TSRMLS_CC);
       if (wrapper && wrapper->wops->url_stat) {
              ret = wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context TSRMLS_CC);
              if (ret == 0) {
                     /* Drop into cache */
                     if (flags & PHP_STREAM_URL_STAT_LINK) {
                            if (BG(CurrentLStatFile)) {
                                   efree(BG(CurrentLStatFile));
                            }
                            BG(CurrentLStatFile) = estrdup(path);
                            memcpy(&BG(lssb), ssb, sizeof(php_stream_statbuf));
                     } else {
                            if (BG(CurrentStatFile)) {
                                   efree(BG(CurrentStatFile));
                            }
                            BG(CurrentStatFile) = estrdup(path);
                            memcpy(&BG(ssb), ssb, sizeof(php_stream_statbuf));
                     }
              }
              return ret;
       }
       return -1;
}

Here is the call graph for this function:

PHPAPI off_t _php_stream_tell ( php_stream *stream  TSRMLS_DC)

Definition at line 1130 of file streams.c.

{
       return stream->position;
}
PHPAPI int _php_stream_truncate_set_size ( php_stream *  stream,
size_t newsize  TSRMLS_DC 
)
PHPAPI size_t _php_stream_write ( php_stream *  stream,
const char *  buf,
size_t count  TSRMLS_DC 
)

Definition at line 1097 of file streams.c.

{
       if (buf == NULL || count == 0 || stream->ops->write == NULL) {
              return 0;
       }

       if (stream->writefilters.head) {
              return _php_stream_write_filtered(stream, buf, count, PSFS_FLAG_NORMAL TSRMLS_CC);
       } else {
              return _php_stream_write_buffer(stream, buf, count TSRMLS_CC);
       }
}

Here is the call graph for this function:

Definition at line 48 of file streams.c.

{
       return le_pstream;
}

Here is the caller graph for this function:

Definition at line 43 of file streams.c.

{
       return le_stream;
}

Here is the caller graph for this function:

Definition at line 53 of file streams.c.

{
       return le_stream_filter;
}

Here is the caller graph for this function:

Definition at line 35 of file filter.c.

{
       return &stream_filters_hash;
}

Here is the caller graph for this function:

int php_init_stream_wrappers ( int module_number  TSRMLS_DC)

Definition at line 1497 of file streams.c.

{
       le_stream = zend_register_list_destructors_ex(stream_resource_regular_dtor, NULL, "stream", module_number);
       le_pstream = zend_register_list_destructors_ex(NULL, stream_resource_persistent_dtor, "persistent stream", module_number);

       /* Filters are cleaned up by the streams they're attached to */
       le_stream_filter = zend_register_list_destructors_ex(NULL, NULL, "stream filter", module_number);

       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
                     &&
                     php_stream_xport_register("tcp", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS
                     &&
                     php_stream_xport_register("udp", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS
#if defined(AF_UNIX) && !(defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE))
                     &&
                     php_stream_xport_register("unix", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS
                     &&
                     php_stream_xport_register("udg", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS
#endif
              ) ? SUCCESS : FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI int php_register_url_stream_wrapper ( char *  protocol,
php_stream_wrapper *wrapper  TSRMLS_DC 
)

Definition at line 1552 of file streams.c.

{
       int protocol_len = strlen(protocol);

       if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) {
              return FAILURE;
       }

       return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI int php_register_url_stream_wrapper_volatile ( char *  protocol,
php_stream_wrapper *wrapper  TSRMLS_DC 
)

Definition at line 1578 of file streams.c.

{
       int protocol_len = strlen(protocol);

       if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) {
              return FAILURE;
       }

       if (!FG(stream_wrappers)) {
              clone_wrapper_hash(TSRMLS_C);
       }

       return zend_hash_add(FG(stream_wrappers), protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHP_RSHUTDOWN_FUNCTION ( streams  )

Definition at line 102 of file streams.c.

Here is the call graph for this function:

Definition at line 1482 of file streams.c.

{
       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;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int php_shutdown_stream_wrappers ( int module_number  TSRMLS_DC)

Definition at line 1524 of file streams.c.

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI int php_stream_dirent_alphasort ( const char **  a,
const char **  b 
)

Definition at line 2172 of file streams.c.

{
       return strcoll(*a, *b);
}

Here is the caller graph for this function:

PHPAPI int php_stream_dirent_alphasortr ( const char **  a,
const char **  b 
)

Definition at line 2180 of file streams.c.

{
       return strcoll(*b, *a);
}

Here is the caller graph for this function:

PHPAPI int php_stream_from_persistent_id ( const char *  persistent_id,
php_stream **stream  TSRMLS_DC 
)

Definition at line 108 of file streams.c.

{
       zend_rsrc_list_entry *le;

       if (zend_hash_find(&EG(persistent_list), (char*)persistent_id, strlen(persistent_id)+1, (void*) &le) == SUCCESS) {
              if (Z_TYPE_P(le) == le_pstream) {
                     if (stream) {
                            HashPosition pos;
                            zend_rsrc_list_entry *regentry;
                            ulong index = -1; /* intentional */

                            /* see if this persistent resource already has been loaded to the
                             * regular list; allowing the same resource in several entries in the
                             * regular list causes trouble (see bug #54623) */
                            zend_hash_internal_pointer_reset_ex(&EG(regular_list), &pos);
                            while (zend_hash_get_current_data_ex(&EG(regular_list),
                                          (void **)&regentry, &pos) == SUCCESS) {
                                   if (regentry->ptr == le->ptr) {
                                          zend_hash_get_current_key_ex(&EG(regular_list), NULL, NULL,
                                                 &index, 0, &pos);
                                          break;
                                   }
                                   zend_hash_move_forward_ex(&EG(regular_list), &pos);
                            }
                            
                            *stream = (php_stream*)le->ptr;
                            if (index == -1) { /* not found in regular list */
                                   le->refcount++;
                                   (*stream)->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, *stream, le_pstream);
                            } else {
                                   regentry->refcount++;
                                   (*stream)->rsrc_id = index;
                            }
                     }
                     return PHP_STREAM_PERSISTENT_SUCCESS;
              }
              return PHP_STREAM_PERSISTENT_FAILURE;
       }
       return PHP_STREAM_PERSISTENT_NOT_EXIST;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI char* php_stream_get_record ( php_stream *  stream,
size_t  maxlen,
size_t returned_len,
char *  delim,
size_t delim_len  TSRMLS_DC 
)

Definition at line 902 of file streams.c.

{
       char *e, *buf;
       size_t toread, len;
       int skip = 0;

       len = stream->writepos - stream->readpos;

       /* make sure the stream read buffer has maxlen bytes */
       while (len < maxlen) {

              size_t just_read;
              toread = MIN(maxlen - len, stream->chunk_size);

              php_stream_fill_read_buffer(stream, len + toread TSRMLS_CC);

              just_read = (stream->writepos - stream->readpos) - len;
              len += just_read;

              /* Assume the stream is temporarily or permanently out of data */
              if (just_read == 0) {
                     break;
              }
       }

       if (delim_len == 0 || !delim) {
              toread = maxlen;
       } else {
              size_t seek_len;

              /* set the maximum number of bytes we're allowed to read from buffer */
              seek_len = stream->writepos - stream->readpos;
              if (seek_len > maxlen) {
                     seek_len = maxlen;
              }

              if (delim_len == 1) {
                     e = memchr(stream->readbuf + stream->readpos, *delim, seek_len);
              } else {
                     e = php_memnstr(stream->readbuf + stream->readpos, delim, delim_len, (stream->readbuf + stream->readpos + seek_len));
              }

              if (!e) {
                     /* return with error if the delimiter string was not found, we
                      * could not completely fill the read buffer with maxlen bytes
                      * and we don't know we've reached end of file. Added with
                      * non-blocking streams in mind, where this situation is frequent */
                     if (seek_len < maxlen && !stream->eof) {
                            return NULL;
                     }
                     toread = maxlen;
              } else {
                     toread = e - (char *) stream->readbuf - stream->readpos;
                     /* we found the delimiter, so advance the read pointer past it */
                     skip = 1;
              }
       }

       if (toread > maxlen && maxlen > 0) {
              toread = maxlen;
       }

       buf = emalloc(toread + 1);
       *returned_len = php_stream_read(stream, buf, toread);

       if (skip) {
              stream->readpos += delim_len;
              stream->position += delim_len;
       }
       buf[*returned_len] = '\0';
       return buf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 63 of file streams.c.

Here is the caller graph for this function:

PHPAPI char* php_stream_locate_eol ( php_stream *  stream,
char *  buf,
size_t buf_len  TSRMLS_DC 
)

Definition at line 746 of file streams.c.

{
       size_t avail;
       char *cr, *lf, *eol = NULL;
       char *readptr;

       if (!buf) {
              readptr = stream->readbuf + stream->readpos;
              avail = stream->writepos - stream->readpos;
       } else {
              readptr = buf;
              avail = buf_len;
       }

       /* Look for EOL */
       if (stream->flags & PHP_STREAM_FLAG_DETECT_EOL) {
              cr = memchr(readptr, '\r', avail);
              lf = memchr(readptr, '\n', avail);

              if (cr && lf != cr + 1 && !(lf && lf < cr)) {
                     /* mac */
                     stream->flags ^= PHP_STREAM_FLAG_DETECT_EOL;
                     stream->flags |= PHP_STREAM_FLAG_EOL_MAC;
                     eol = cr;
              } else if ((cr && lf && cr == lf - 1) || (lf)) {
                     /* dos or unix endings */
                     stream->flags ^= PHP_STREAM_FLAG_DETECT_EOL;
                     eol = lf;
              }
       } else if (stream->flags & PHP_STREAM_FLAG_EOL_MAC) {
              eol = memchr(readptr, '\r', avail);
       } else {
              /* unix (and dos) line endings */
              eol = memchr(readptr, '\n', avail);
       }

       return eol;
}

Here is the caller graph for this function:

PHPAPI php_stream_wrapper* php_stream_locate_url_wrapper ( const char *  path,
char **  path_for_open,
int options  TSRMLS_DC 
)

Definition at line 1604 of file streams.c.

{
       HashTable *wrapper_hash = (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash);
       php_stream_wrapper **wrapperpp = NULL;
       const char *p, *protocol = NULL;
       int n = 0;

       if (path_for_open) {
              *path_for_open = (char*)path;
       }

       if (options & IGNORE_URL) {
              return (options & STREAM_LOCATE_WRAPPERS_ONLY) ? NULL : &php_plain_files_wrapper;
       }

       for (p = path; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++) {
              n++;
       }

       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 */
              protocol = "compress.zlib";
              n = 13;
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Use of \"zlib:\" wrapper is deprecated; please use \"compress.zlib://\" instead");
       }

       if (protocol) {
              char *tmp = estrndup(protocol, n);
              if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)&wrapperpp)) {
                     php_strtolower(tmp, n);
                     if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (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_WARNING, "Unable to find the wrapper \"%s\" - did you forget to enable it when you configured PHP?", wrapper_name);

                            wrapperpp = NULL;
                            protocol = NULL;
                     }
              }
              efree(tmp);
       }
       /* TODO: curl based streams probably support file:// properly */
       if (!protocol || !strncasecmp(protocol, "file", n))     {
              /* fall back on regular file access */
              php_stream_wrapper *plain_files_wrapper = &php_plain_files_wrapper;

              if (protocol) {
                     int localhost = 0;

                     if (!strncasecmp(path, "file://localhost/", 17)) {
                            localhost = 1;
                     }

#ifdef PHP_WIN32
                     if (localhost == 0 && path[n+3] != '\0' && path[n+3] != '/' && path[n+4] != ':')    {
#else
                     if (localhost == 0 && path[n+3] != '\0' && path[n+3] != '/') {
#endif
                            if (options & REPORT_ERRORS) {
                                   php_error_docref(NULL TSRMLS_CC, E_WARNING, "remote host file access not supported, %s", path);
                            }
                            return NULL;
                     }

                     if (path_for_open) {
                            /* skip past protocol and :/, but handle windows correctly */
                            *path_for_open = (char*)path + n + 1;
                            if (localhost == 1) {
                                   (*path_for_open) += 11;
                            }
                            while (*(++*path_for_open)=='/');
#ifdef PHP_WIN32
                            if (*(*path_for_open + 1) != ':')
#endif
                                   (*path_for_open)--;
                     }
              }

              if (options & STREAM_LOCATE_WRAPPERS_ONLY) {
                     return NULL;
              }

              if (FG(stream_wrappers)) {
              /* The file:// wrapper may have been disabled/overridden */

                     if (wrapperpp) {
                            /* It was found so go ahead and provide it */
                            return *wrapperpp;
                     }

                     /* Check again, the original check might have not known the protocol name */
                     if (zend_hash_find(wrapper_hash, "file", sizeof("file"), (void**)&wrapperpp) == SUCCESS) {
                            return *wrapperpp;
                     }

                     if (options & REPORT_ERRORS) {
                            php_error_docref(NULL TSRMLS_CC, E_WARNING, "file:// wrapper is disabled in the server configuration");
                     }
                     return NULL;
              }

              return plain_files_wrapper;
       }

       if (wrapperpp && (*wrapperpp)->is_url &&
        (options & STREAM_DISABLE_URL_PROTECTION) == 0 &&
           (!PG(allow_url_fopen) ||
            (((options & STREAM_OPEN_FOR_INCLUDE) ||
              PG(in_user_include)) && !PG(allow_url_include)))) {
              if (options & REPORT_ERRORS) {
                     /* protocol[n] probably isn't '\0' */
                     char *protocol_dup = estrndup(protocol, n);
                     if (!PG(allow_url_fopen)) {
                            php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s:// wrapper is disabled in the server configuration by allow_url_fopen=0", protocol_dup);
                     } else {
                            php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s:// wrapper is disabled in the server configuration by allow_url_include=0", protocol_dup);
                     }
                     efree(protocol_dup);
              }
              return NULL;
       }

       return *wrapperpp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI void php_stream_wrapper_log_error ( php_stream_wrapper *  wrapper,
int options  TSRMLS_DC,
const char *  fmt,
  ... 
)

Here is the caller graph for this function:

PHPAPI int php_unregister_url_stream_wrapper ( char *protocol  TSRMLS_DC)

Definition at line 1563 of file streams.c.

{
       return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol) + 1);
}

Here is the caller graph for this function:

PHPAPI int php_unregister_url_stream_wrapper_volatile ( char *protocol  TSRMLS_DC)

Definition at line 1593 of file streams.c.

{
       if (!FG(stream_wrappers)) {
              clone_wrapper_hash(TSRMLS_C);
       }

       return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol) + 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation