2002-03-19 03:51:01 +00:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2014-09-19 16:33:14 +00:00
| PHP Version 7 |
2002-03-19 03:51:01 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2015-01-15 15:27:30 +00:00
| Copyright ( c ) 1997 - 2015 The PHP Group |
2002-03-19 03:51:01 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 12:51:34 +00:00
| This source file is subject to version 3.01 of the PHP license , |
2002-03-19 03:51:01 +00:00
| that is bundled with this package in the file LICENSE , and is |
2003-06-10 20:04:29 +00:00
| available through the world - wide - web at the following url : |
2006-01-01 12:51:34 +00:00
| http : //www.php.net/license/3_01.txt |
2002-03-19 03:51:01 +00:00
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ php . net so we can mail you a copy immediately . |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2003-02-19 08:40:19 +00:00
| Authors : Wez Furlong < wez @ thebrainroom . com > |
2003-12-13 04:07:18 +00:00
| Sara Golemon < pollita @ php . net > |
2002-03-19 03:51:01 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2002-05-04 17:41:03 +00:00
*/
2002-03-19 03:51:01 +00:00
2002-05-04 17:42:58 +00:00
/* $Id$ */
2002-05-04 17:39:05 +00:00
2002-03-19 03:51:01 +00:00
# include "php.h"
# include "php_globals.h"
2002-09-26 12:12:27 +00:00
# include "ext/standard/file.h"
2008-11-26 04:19:20 +00:00
# include "ext/standard/flock_compat.h"
# ifdef HAVE_SYS_FILE_H
# include <sys/file.h>
# endif
2011-02-17 00:25:32 +00:00
# include <stddef.h>
2002-03-19 03:51:01 +00:00
2011-05-25 21:03:55 +00:00
# if HAVE_UTIME
# ifdef PHP_WIN32
# include <sys / utime.h>
# else
# include <utime.h>
# endif
# endif
2002-03-19 03:51:01 +00:00
static int le_protocols ;
struct php_user_stream_wrapper {
char * protoname ;
char * classname ;
zend_class_entry * ce ;
php_stream_wrapper wrapper ;
} ;
2015-03-03 23:05:28 +00:00
static php_stream * user_wrapper_opener ( php_stream_wrapper * wrapper , const char * filename , const char * mode , int options , zend_string * * opened_path , php_stream_context * context STREAMS_DC ) ;
2014-12-13 22:06:14 +00:00
static int user_wrapper_stat_url ( php_stream_wrapper * wrapper , const char * url , int flags , php_stream_statbuf * ssb , php_stream_context * context ) ;
static int user_wrapper_unlink ( php_stream_wrapper * wrapper , const char * url , int options , php_stream_context * context ) ;
static int user_wrapper_rename ( php_stream_wrapper * wrapper , const char * url_from , const char * url_to , int options , php_stream_context * context ) ;
static int user_wrapper_mkdir ( php_stream_wrapper * wrapper , const char * url , int mode , int options , php_stream_context * context ) ;
static int user_wrapper_rmdir ( php_stream_wrapper * wrapper , const char * url , int options , php_stream_context * context ) ;
static int user_wrapper_metadata ( php_stream_wrapper * wrapper , const char * url , int option , void * value , php_stream_context * context ) ;
2013-07-30 10:49:36 +00:00
static php_stream * user_wrapper_opendir ( php_stream_wrapper * wrapper , const char * filename , const char * mode ,
2015-03-03 23:05:28 +00:00
int options , zend_string * * opened_path , php_stream_context * context STREAMS_DC ) ;
2002-03-24 18:05:49 +00:00
static php_stream_wrapper_ops user_stream_wops = {
user_wrapper_opener ,
2002-09-28 13:05:47 +00:00
NULL , /* close - the streams themselves know how */
NULL , /* stat - the streams themselves know how */
user_wrapper_stat_url ,
user_wrapper_opendir ,
2003-05-14 06:10:04 +00:00
" user-space " ,
2003-12-12 23:06:42 +00:00
user_wrapper_unlink ,
2003-12-13 04:07:18 +00:00
user_wrapper_rename ,
user_wrapper_mkdir ,
2011-05-25 21:03:55 +00:00
user_wrapper_rmdir ,
user_wrapper_metadata
2002-03-24 18:05:49 +00:00
} ;
2002-03-19 03:51:01 +00:00
2014-12-13 22:06:14 +00:00
static void stream_wrapper_dtor ( zend_resource * rsrc )
2002-03-19 03:51:01 +00:00
{
struct php_user_stream_wrapper * uwrap = ( struct php_user_stream_wrapper * ) rsrc - > ptr ;
efree ( uwrap - > protoname ) ;
efree ( uwrap - > classname ) ;
efree ( uwrap ) ;
}
2002-03-19 14:35:55 +00:00
PHP_MINIT_FUNCTION ( user_streams )
2002-03-19 03:51:01 +00:00
{
le_protocols = zend_register_list_destructors_ex ( stream_wrapper_dtor , NULL , " stream factory " , 0 ) ;
2002-03-19 14:35:55 +00:00
if ( le_protocols = = FAILURE )
return FAILURE ;
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " STREAM_USE_PATH " , USE_PATH , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_IGNORE_URL " , IGNORE_URL , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_REPORT_ERRORS " , REPORT_ERRORS , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_MUST_SEEK " , STREAM_MUST_SEEK , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_URL_STAT_LINK " , PHP_STREAM_URL_STAT_LINK , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_URL_STAT_QUIET " , PHP_STREAM_URL_STAT_QUIET , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_MKDIR_RECURSIVE " , PHP_STREAM_MKDIR_RECURSIVE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_IS_URL " , PHP_STREAM_IS_URL , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_OPTION_BLOCKING " , PHP_STREAM_OPTION_BLOCKING , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_OPTION_READ_TIMEOUT " , PHP_STREAM_OPTION_READ_TIMEOUT , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_OPTION_READ_BUFFER " , PHP_STREAM_OPTION_READ_BUFFER , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_OPTION_WRITE_BUFFER " , PHP_STREAM_OPTION_WRITE_BUFFER , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_BUFFER_NONE " , PHP_STREAM_BUFFER_NONE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_BUFFER_LINE " , PHP_STREAM_BUFFER_LINE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_BUFFER_FULL " , PHP_STREAM_BUFFER_FULL , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_CAST_AS_STREAM " , PHP_STREAM_AS_STDIO , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_CAST_FOR_SELECT " , PHP_STREAM_AS_FD_FOR_SELECT , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_META_TOUCH " , PHP_STREAM_META_TOUCH , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_META_OWNER " , PHP_STREAM_META_OWNER , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_META_OWNER_NAME " , PHP_STREAM_META_OWNER_NAME , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_META_GROUP " , PHP_STREAM_META_GROUP , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_META_GROUP_NAME " , PHP_STREAM_META_GROUP_NAME , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " STREAM_META_ACCESS " , PHP_STREAM_META_ACCESS , CONST_CS | CONST_PERSISTENT ) ;
2002-03-19 14:35:55 +00:00
return SUCCESS ;
2002-03-19 03:51:01 +00:00
}
struct _php_userstream_data {
struct php_user_stream_wrapper * wrapper ;
2014-02-25 21:00:39 +00:00
zval object ;
2002-03-19 03:51:01 +00:00
} ;
typedef struct _php_userstream_data php_userstream_data_t ;
/* names of methods */
# define USERSTREAM_OPEN "stream_open"
# define USERSTREAM_CLOSE "stream_close"
# define USERSTREAM_READ "stream_read"
# define USERSTREAM_WRITE "stream_write"
# define USERSTREAM_FLUSH "stream_flush"
# define USERSTREAM_SEEK "stream_seek"
# define USERSTREAM_TELL "stream_tell"
# define USERSTREAM_EOF "stream_eof"
2002-09-28 13:05:47 +00:00
# define USERSTREAM_STAT "stream_stat"
# define USERSTREAM_STATURL "url_stat"
2003-05-14 18:30:49 +00:00
# define USERSTREAM_UNLINK "unlink"
2003-12-12 23:06:42 +00:00
# define USERSTREAM_RENAME "rename"
2003-12-13 04:07:18 +00:00
# define USERSTREAM_MKDIR "mkdir"
# define USERSTREAM_RMDIR "rmdir"
2002-09-28 13:05:47 +00:00
# define USERSTREAM_DIR_OPEN "dir_opendir"
# define USERSTREAM_DIR_READ "dir_readdir"
# define USERSTREAM_DIR_REWIND "dir_rewinddir"
# define USERSTREAM_DIR_CLOSE "dir_closedir"
2004-01-21 10:17:12 +00:00
# define USERSTREAM_LOCK "stream_lock"
2008-11-15 12:52:13 +00:00
# define USERSTREAM_CAST "stream_cast"
# define USERSTREAM_SET_OPTION "stream_set_option"
2011-02-17 00:25:32 +00:00
# define USERSTREAM_TRUNCATE "stream_truncate"
2011-05-25 21:03:55 +00:00
# define USERSTREAM_METADATA "stream_metadata"
2002-09-28 13:05:47 +00:00
/* {{{ class should have methods like these:
2011-05-25 21:03:55 +00:00
2002-09-23 13:22:10 +00:00
function stream_open ( $ path , $ mode , $ options , & $ opened_path )
{
return true / false ;
}
2011-05-25 21:03:55 +00:00
2002-09-23 13:22:10 +00:00
function stream_read ( $ count )
{
return false on error ;
else return string ;
}
2011-05-25 21:03:55 +00:00
2002-09-23 13:22:10 +00:00
function stream_write ( $ data )
{
return false on error ;
else return count written ;
}
2011-05-25 21:03:55 +00:00
2002-09-23 13:22:10 +00:00
function stream_close ( )
{
}
2011-05-25 21:03:55 +00:00
2002-09-23 13:22:10 +00:00
function stream_flush ( )
{
return true / false ;
}
2011-05-25 21:03:55 +00:00
2002-09-23 13:22:10 +00:00
function stream_seek ( $ offset , $ whence )
{
return true / false ;
}
function stream_tell ( )
{
return ( int ) $ position ;
}
function stream_eof ( )
{
return true / false ;
}
2002-09-28 13:05:47 +00:00
function stream_stat ( )
{
return array ( just like that returned by fstat ( ) ) ;
}
2008-11-15 12:52:13 +00:00
function stream_cast ( $ castas )
{
if ( $ castas = = STREAM_CAST_FOR_SELECT ) {
return $ this - > underlying_stream ;
}
return false ;
}
function stream_set_option ( $ option , $ arg1 , $ arg2 )
{
switch ( $ option ) {
case STREAM_OPTION_BLOCKING :
$ blocking = $ arg1 ;
. . .
case STREAM_OPTION_READ_TIMEOUT :
$ sec = $ arg1 ;
$ usec = $ arg2 ;
. . .
case STREAM_OPTION_WRITE_BUFFER :
$ mode = $ arg1 ;
$ size = $ arg2 ;
. . .
default :
return false ;
}
}
2003-12-02 18:52:58 +00:00
function url_stat ( string $ url , int $ flags )
2002-09-28 13:05:47 +00:00
{
return array ( just like that returned by stat ( ) ) ;
}
2003-05-14 18:30:49 +00:00
function unlink ( string $ url )
{
return true / false ;
}
2003-12-12 23:06:42 +00:00
function rename ( string $ from , string $ to )
{
return true / false ;
}
2003-12-13 04:07:18 +00:00
function mkdir ( $ dir , $ mode , $ options )
{
return true / false ;
}
function rmdir ( $ dir , $ options )
{
return true / false ;
}
2002-09-28 13:05:47 +00:00
function dir_opendir ( string $ url , int $ options )
{
return true / false ;
}
function dir_readdir ( )
{
return string next filename in dir ;
}
function dir_closedir ( )
{
release dir related resources ;
}
function dir_rewinddir ( )
{
reset to start of dir list ;
}
2009-03-25 19:55:59 +00:00
function stream_lock ( $ operation )
{
return true / false ;
}
2011-02-17 00:25:32 +00:00
function stream_truncate ( $ new_size )
{
return true / false ;
}
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
} } } * */
2002-03-19 03:51:01 +00:00
2014-12-13 22:06:14 +00:00
static void user_stream_create_object ( struct php_user_stream_wrapper * uwrap , php_stream_context * context , zval * object )
2002-03-19 03:51:01 +00:00
{
2012-08-08 05:59:12 +00:00
/* create an instance of our class */
object_init_ex ( object , uwrap - > ce ) ;
2011-05-25 21:03:55 +00:00
2012-08-08 05:59:12 +00:00
if ( context ) {
2014-02-10 06:04:30 +00:00
add_property_resource ( object , " context " , context - > res ) ;
2014-04-02 10:34:44 +00:00
GC_REFCOUNT ( context - > res ) + + ;
2012-08-08 05:59:12 +00:00
} else {
add_property_null ( object , " context " ) ;
2007-07-09 17:27:24 +00:00
}
2006-08-14 15:01:29 +00:00
if ( uwrap - > ce - > constructor ) {
zend_fcall_info fci ;
zend_fcall_info_cache fcc ;
2014-02-10 06:04:30 +00:00
zval retval ;
2011-05-25 21:03:55 +00:00
2006-08-14 15:01:29 +00:00
fci . size = sizeof ( fci ) ;
fci . function_table = & uwrap - > ce - > function_table ;
2014-02-10 06:04:30 +00:00
ZVAL_UNDEF ( & fci . function_name ) ;
2006-08-14 15:01:29 +00:00
fci . symbol_table = NULL ;
2014-03-27 22:11:22 +00:00
fci . object = Z_OBJ_P ( object ) ;
2014-02-10 06:04:30 +00:00
fci . retval = & retval ;
2006-08-14 15:01:29 +00:00
fci . param_count = 0 ;
fci . params = NULL ;
fci . no_separation = 1 ;
2011-05-25 21:03:55 +00:00
2006-08-14 15:01:29 +00:00
fcc . initialized = 1 ;
fcc . function_handler = uwrap - > ce - > constructor ;
fcc . calling_scope = EG ( scope ) ;
2012-08-08 05:59:12 +00:00
fcc . called_scope = Z_OBJCE_P ( object ) ;
2014-03-27 22:11:22 +00:00
fcc . object = Z_OBJ_P ( object ) ;
2006-08-14 15:01:29 +00:00
2014-12-13 22:06:14 +00:00
if ( zend_call_function ( & fci , & fcc ) = = FAILURE ) {
php_error_docref ( NULL , E_WARNING , " Could not execute %s::%s() " , uwrap - > ce - > name - > val , uwrap - > ce - > constructor - > common . function_name - > val ) ;
2012-08-08 05:59:12 +00:00
zval_dtor ( object ) ;
2014-02-10 06:04:30 +00:00
ZVAL_UNDEF ( object ) ;
2006-08-14 15:01:29 +00:00
} else {
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & retval ) ;
2006-08-14 15:01:29 +00:00
}
}
2012-08-08 05:59:12 +00:00
}
2003-06-16 19:13:39 +00:00
2013-07-30 10:49:36 +00:00
static php_stream * user_wrapper_opener ( php_stream_wrapper * wrapper , const char * filename , const char * mode ,
2015-03-03 23:05:28 +00:00
int options , zend_string * * opened_path , php_stream_context * context STREAMS_DC )
2012-08-08 05:59:12 +00:00
{
struct php_user_stream_wrapper * uwrap = ( struct php_user_stream_wrapper * ) wrapper - > abstract ;
php_userstream_data_t * us ;
2014-02-10 06:04:30 +00:00
zval zretval , zfuncname ;
zval args [ 4 ] ;
2012-08-08 05:59:12 +00:00
int call_result ;
php_stream * stream = NULL ;
zend_bool old_in_user_include ;
/* Try to catch bad usage without preventing flexibility */
if ( FG ( user_stream_current_filename ) ! = NULL & & strcmp ( filename , FG ( user_stream_current_filename ) ) = = 0 ) {
2014-12-13 22:06:14 +00:00
php_stream_wrapper_log_error ( wrapper , options , " infinite recursion prevented " ) ;
2012-08-08 05:59:12 +00:00
return NULL ;
}
FG ( user_stream_current_filename ) = filename ;
/* if the user stream was registered as local and we are in include context,
we add allow_url_include restrictions to allow_url_fopen ones */
/* we need only is_url == 0 here since if is_url == 1 and remote wrappers
were restricted we wouldn ' t get here */
old_in_user_include = PG ( in_user_include ) ;
if ( uwrap - > wrapper . is_url = = 0 & &
( options & STREAM_OPEN_FOR_INCLUDE ) & &
! PG ( allow_url_include ) ) {
PG ( in_user_include ) = 1 ;
}
us = emalloc ( sizeof ( * us ) ) ;
us - > wrapper = uwrap ;
2014-12-13 22:06:14 +00:00
user_stream_create_object ( uwrap , context , & us - > object ) ;
2014-02-25 21:00:39 +00:00
if ( Z_TYPE ( us - > object ) = = IS_UNDEF ) {
2012-08-08 05:59:12 +00:00
FG ( user_stream_current_filename ) = NULL ;
PG ( in_user_include ) = old_in_user_include ;
efree ( us ) ;
return NULL ;
2003-06-16 19:13:39 +00:00
}
2011-05-25 21:03:55 +00:00
2002-03-19 03:51:01 +00:00
/* call it's stream_open method - set up params first */
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & args [ 0 ] , filename ) ;
ZVAL_STRING ( & args [ 1 ] , mode ) ;
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 2 ] , options ) ;
2014-02-10 06:04:30 +00:00
ZVAL_NEW_REF ( & args [ 3 ] , & EG ( uninitialized_zval ) ) ;
2002-03-19 03:51:01 +00:00
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & zfuncname , USERSTREAM_OPEN ) ;
2011-05-25 21:03:55 +00:00
2002-03-19 03:51:01 +00:00
call_result = call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2014-02-10 06:04:30 +00:00
& zfuncname ,
2002-03-19 03:51:01 +00:00
& zretval ,
4 , args ,
2014-12-14 13:07:59 +00:00
0 , NULL ) ;
2011-05-25 21:03:55 +00:00
2014-02-10 06:04:30 +00:00
if ( call_result = = SUCCESS & & Z_TYPE ( zretval ) ! = IS_UNDEF & & zval_is_true ( & zretval ) ) {
2002-03-19 03:51:01 +00:00
/* the stream is now open! */
stream = php_stream_alloc_rel ( & php_stream_userspace_ops , us , 0 , mode ) ;
/* if the opened path is set, copy it out */
2014-08-05 16:55:15 +00:00
if ( Z_ISREF ( args [ 3 ] ) & & Z_TYPE_P ( Z_REFVAL ( args [ 3 ] ) ) = = IS_STRING & & opened_path ) {
2015-03-03 23:05:28 +00:00
* opened_path = zend_string_copy ( Z_STR_P ( Z_REFVAL ( args [ 3 ] ) ) ) ;
2002-03-19 03:51:01 +00:00
}
2002-03-19 13:42:25 +00:00
/* set wrapper data to be a reference to our object */
2014-02-25 21:00:39 +00:00
ZVAL_COPY ( & stream - > wrapperdata , & us - > object ) ;
2002-03-19 03:51:01 +00:00
} else {
2014-12-13 22:06:14 +00:00
php_stream_wrapper_log_error ( wrapper , options , " \" %s:: " USERSTREAM_OPEN " \" call failed " ,
2002-09-18 10:15:40 +00:00
us - > wrapper - > classname ) ;
2002-03-19 03:51:01 +00:00
}
2011-05-25 21:03:55 +00:00
2002-03-19 03:51:01 +00:00
/* destroy everything else */
2002-09-18 10:15:40 +00:00
if ( stream = = NULL ) {
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & us - > object ) ;
2014-03-04 11:12:43 +00:00
ZVAL_UNDEF ( & us - > object ) ;
2002-09-18 10:15:40 +00:00
efree ( us ) ;
}
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & zretval ) ;
2002-03-19 03:51:01 +00:00
zval_ptr_dtor ( & zfuncname ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & args [ 3 ] ) ;
zval_ptr_dtor ( & args [ 2 ] ) ;
zval_ptr_dtor ( & args [ 1 ] ) ;
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & args [ 0 ] ) ;
2002-03-19 03:51:01 +00:00
2002-09-26 12:12:27 +00:00
FG ( user_stream_current_filename ) = NULL ;
2011-05-25 21:03:55 +00:00
2007-07-09 17:27:24 +00:00
PG ( in_user_include ) = old_in_user_include ;
2002-03-19 03:51:01 +00:00
return stream ;
}
2013-07-30 10:49:36 +00:00
static php_stream * user_wrapper_opendir ( php_stream_wrapper * wrapper , const char * filename , const char * mode ,
2015-03-03 23:05:28 +00:00
int options , zend_string * * opened_path , php_stream_context * context STREAMS_DC )
2002-09-28 13:05:47 +00:00
{
struct php_user_stream_wrapper * uwrap = ( struct php_user_stream_wrapper * ) wrapper - > abstract ;
php_userstream_data_t * us ;
2014-02-10 06:04:30 +00:00
zval zretval , zfuncname ;
zval args [ 2 ] ;
2002-09-28 13:05:47 +00:00
int call_result ;
php_stream * stream = NULL ;
/* Try to catch bad usage without preventing flexibility */
if ( FG ( user_stream_current_filename ) ! = NULL & & strcmp ( filename , FG ( user_stream_current_filename ) ) = = 0 ) {
2014-12-13 22:06:14 +00:00
php_stream_wrapper_log_error ( wrapper , options , " infinite recursion prevented " ) ;
2002-09-28 13:05:47 +00:00
return NULL ;
}
FG ( user_stream_current_filename ) = filename ;
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
us = emalloc ( sizeof ( * us ) ) ;
2011-05-25 21:03:55 +00:00
us - > wrapper = uwrap ;
2002-09-28 13:05:47 +00:00
2014-12-13 22:06:14 +00:00
user_stream_create_object ( uwrap , context , & us - > object ) ;
2014-02-25 21:00:39 +00:00
if ( Z_TYPE ( us - > object ) = = IS_UNDEF ) {
2012-08-08 05:59:12 +00:00
FG ( user_stream_current_filename ) = NULL ;
efree ( us ) ;
return NULL ;
2003-12-02 19:14:31 +00:00
}
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
/* call it's dir_open method - set up params first */
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & args [ 0 ] , filename ) ;
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 1 ] , options ) ;
2002-09-28 13:05:47 +00:00
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & zfuncname , USERSTREAM_DIR_OPEN ) ;
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
call_result = call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2014-02-10 06:04:30 +00:00
& zfuncname ,
2002-09-28 13:05:47 +00:00
& zretval ,
2 , args ,
2014-12-14 13:07:59 +00:00
0 , NULL ) ;
2011-05-25 21:03:55 +00:00
2014-02-10 06:04:30 +00:00
if ( call_result = = SUCCESS & & Z_TYPE ( zretval ) ! = IS_UNDEF & & zval_is_true ( & zretval ) ) {
2002-09-28 13:05:47 +00:00
/* the stream is now open! */
stream = php_stream_alloc_rel ( & php_stream_userspace_dir_ops , us , 0 , mode ) ;
/* set wrapper data to be a reference to our object */
2014-02-25 21:00:39 +00:00
ZVAL_COPY ( & stream - > wrapperdata , & us - > object ) ;
2002-09-28 13:05:47 +00:00
} else {
2014-12-13 22:06:14 +00:00
php_stream_wrapper_log_error ( wrapper , options , " \" %s:: " USERSTREAM_DIR_OPEN " \" call failed " ,
2002-09-28 13:05:47 +00:00
us - > wrapper - > classname ) ;
}
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
/* destroy everything else */
if ( stream = = NULL ) {
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & us - > object ) ;
2014-03-04 11:12:43 +00:00
ZVAL_UNDEF ( & us - > object ) ;
2002-09-28 13:05:47 +00:00
efree ( us ) ;
}
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & zretval ) ;
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
zval_ptr_dtor ( & zfuncname ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & args [ 1 ] ) ;
zval_ptr_dtor ( & args [ 0 ] ) ;
2002-09-28 13:05:47 +00:00
FG ( user_stream_current_filename ) = NULL ;
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
return stream ;
}
2007-08-16 23:54:24 +00:00
/* {{{ proto bool stream_wrapper_register(string protocol, string classname[, integer flags])
2002-03-19 03:51:01 +00:00
Registers a custom URL protocol handler class */
2003-05-19 15:35:06 +00:00
PHP_FUNCTION ( stream_wrapper_register )
2002-03-19 03:51:01 +00:00
{
2014-02-10 06:04:30 +00:00
zend_string * protocol , * classname ;
2002-03-19 03:51:01 +00:00
struct php_user_stream_wrapper * uwrap ;
2014-02-10 06:04:30 +00:00
zend_resource * rsrc ;
2014-08-25 17:24:55 +00:00
zend_long flags = 0 ;
2011-05-25 21:03:55 +00:00
2014-12-13 22:06:14 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " SS|l " , & protocol , & classname , & flags ) = = FAILURE ) {
2002-03-19 03:51:01 +00:00
RETURN_FALSE ;
}
2011-05-25 21:03:55 +00:00
2002-03-19 03:51:01 +00:00
uwrap = ( struct php_user_stream_wrapper * ) ecalloc ( 1 , sizeof ( * uwrap ) ) ;
2014-02-10 06:04:30 +00:00
uwrap - > protoname = estrndup ( protocol - > val , protocol - > len ) ;
uwrap - > classname = estrndup ( classname - > val , classname - > len ) ;
2002-03-24 18:05:49 +00:00
uwrap - > wrapper . wops = & user_stream_wops ;
uwrap - > wrapper . abstract = uwrap ;
2007-07-09 17:27:24 +00:00
uwrap - > wrapper . is_url = ( ( flags & PHP_STREAM_IS_URL ) ! = 0 ) ;
2002-03-19 03:51:01 +00:00
2015-02-02 05:23:16 +00:00
rsrc = zend_register_resource ( uwrap , le_protocols ) ;
2004-06-21 18:58:55 +00:00
2014-12-13 22:06:14 +00:00
if ( ( uwrap - > ce = zend_lookup_class ( classname ) ) ! = NULL ) {
if ( php_register_url_stream_wrapper_volatile ( protocol - > val , & uwrap - > wrapper ) = = SUCCESS ) {
2002-03-19 03:51:01 +00:00
RETURN_TRUE ;
2004-03-17 00:08:22 +00:00
} else {
/* We failed. But why? */
2014-02-10 06:04:30 +00:00
if ( zend_hash_exists ( php_stream_get_url_stream_wrappers_hash ( ) , protocol ) ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Protocol %s:// is already defined. " , protocol - > val ) ;
2004-03-17 00:08:22 +00:00
} else {
2007-05-15 13:04:43 +00:00
/* Hash doesn't exist so it must have been an invalid protocol scheme */
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Invalid protocol scheme specified. Unable to register wrapper class %s to %s:// " , classname - > val , protocol - > val ) ;
2004-03-17 00:08:22 +00:00
}
2002-03-19 03:51:01 +00:00
}
} else {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " class '%s' is undefined " , classname - > val ) ;
2002-03-19 03:51:01 +00:00
}
2014-02-10 06:04:30 +00:00
zend_list_delete ( rsrc ) ;
2002-03-19 03:51:01 +00:00
RETURN_FALSE ;
}
/* }}} */
2005-12-18 15:38:08 +00:00
/* {{{ proto bool stream_wrapper_unregister(string protocol)
2004-09-10 20:45:35 +00:00
Unregister a wrapper for the life of the current request . */
PHP_FUNCTION ( stream_wrapper_unregister )
{
char * protocol ;
2014-08-27 13:31:48 +00:00
size_t protocol_len ;
2004-09-10 20:45:35 +00:00
2014-12-13 22:06:14 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " s " , & protocol , & protocol_len ) = = FAILURE ) {
2004-09-10 20:45:35 +00:00
RETURN_FALSE ;
}
2014-12-13 22:06:14 +00:00
if ( php_unregister_url_stream_wrapper_volatile ( protocol ) = = FAILURE ) {
2004-09-10 20:45:35 +00:00
/* We failed */
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Unable to unregister protocol %s:// " , protocol ) ;
2004-09-10 20:45:35 +00:00
RETURN_FALSE ;
}
RETURN_TRUE ;
}
/* }}} */
2005-12-18 15:38:08 +00:00
/* {{{ proto bool stream_wrapper_restore(string protocol)
2004-09-10 20:45:35 +00:00
Restore the original protocol handler , overriding if necessary */
PHP_FUNCTION ( stream_wrapper_restore )
{
2014-02-10 06:04:30 +00:00
zend_string * protocol ;
php_stream_wrapper * wrapper ;
2004-09-10 20:45:35 +00:00
HashTable * global_wrapper_hash ;
2014-12-13 22:06:14 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " S " , & protocol ) = = FAILURE ) {
2004-09-10 20:45:35 +00:00
RETURN_FALSE ;
}
global_wrapper_hash = php_stream_get_url_stream_wrappers_hash_global ( ) ;
if ( php_stream_get_url_stream_wrappers_hash ( ) = = global_wrapper_hash ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_NOTICE , " %s:// was never changed, nothing to restore " , protocol - > val ) ;
2004-09-10 20:45:35 +00:00
RETURN_TRUE ;
}
2014-02-10 06:04:30 +00:00
if ( ( wrapper = zend_hash_find_ptr ( global_wrapper_hash , protocol ) ) = = NULL ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:// never existed, nothing to restore " , protocol - > val ) ;
2004-09-10 20:45:35 +00:00
RETURN_FALSE ;
}
/* A failure here could be okay given that the protocol might have been merely unregistered */
2014-12-13 22:06:14 +00:00
php_unregister_url_stream_wrapper_volatile ( protocol - > val ) ;
2004-09-10 20:45:35 +00:00
2014-12-13 22:06:14 +00:00
if ( php_register_url_stream_wrapper_volatile ( protocol - > val , wrapper ) = = FAILURE ) {
php_error_docref ( NULL , E_WARNING , " Unable to restore original %s:// wrapper " , protocol - > val ) ;
2004-09-10 20:45:35 +00:00
RETURN_FALSE ;
2011-05-25 21:03:55 +00:00
}
2004-09-10 20:45:35 +00:00
RETURN_TRUE ;
}
/* }}} */
2002-03-19 03:51:01 +00:00
2014-12-13 22:06:14 +00:00
static size_t php_userstreamop_write ( php_stream * stream , const char * buf , size_t count )
2002-03-19 03:51:01 +00:00
{
zval func_name ;
2014-02-10 06:04:30 +00:00
zval retval ;
2002-03-19 03:51:01 +00:00
int call_result ;
php_userstream_data_t * us = ( php_userstream_data_t * ) stream - > abstract ;
2014-02-10 06:04:30 +00:00
zval args [ 1 ] ;
2002-03-19 03:51:01 +00:00
size_t didwrite = 0 ;
assert ( us ! = NULL ) ;
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_WRITE , sizeof ( USERSTREAM_WRITE ) - 1 ) ;
2002-03-19 03:51:01 +00:00
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & args [ 0 ] , ( char * ) buf , count ) ;
2002-03-19 03:51:01 +00:00
call_result = call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2002-03-19 03:51:01 +00:00
& func_name ,
& retval ,
1 , args ,
2014-12-13 22:06:14 +00:00
0 , NULL ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & args [ 0 ] ) ;
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & func_name ) ;
2002-03-19 03:51:01 +00:00
2002-09-18 10:15:40 +00:00
didwrite = 0 ;
2014-07-15 15:18:56 +00:00
if ( EG ( exception ) ) {
return 0 ;
}
2014-02-10 06:04:30 +00:00
if ( call_result = = SUCCESS & & Z_TYPE ( retval ) ! = IS_UNDEF ) {
2014-08-25 19:51:49 +00:00
convert_to_long ( & retval ) ;
2014-08-25 17:24:55 +00:00
didwrite = Z_LVAL ( retval ) ;
2002-09-23 13:22:10 +00:00
} else if ( call_result = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_WRITE " is not implemented! " ,
2002-09-23 13:22:10 +00:00
us - > wrapper - > classname ) ;
2002-09-18 10:15:40 +00:00
}
2002-03-19 13:44:38 +00:00
/* don't allow strange buffer overruns due to bogus return */
if ( didwrite > count ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_WRITE " wrote " ZEND_LONG_FMT " bytes more data than requested ( " ZEND_LONG_FMT " written, " ZEND_LONG_FMT " max) " ,
2002-03-19 16:56:53 +00:00
us - > wrapper - > classname ,
2014-08-25 17:24:55 +00:00
( zend_long ) ( didwrite - count ) , ( zend_long ) didwrite , ( zend_long ) count ) ;
2002-03-19 13:44:38 +00:00
didwrite = count ;
}
2011-05-25 21:03:55 +00:00
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & retval ) ;
2011-05-25 21:03:55 +00:00
2002-03-19 03:51:01 +00:00
return didwrite ;
}
2014-12-13 22:06:14 +00:00
static size_t php_userstreamop_read ( php_stream * stream , char * buf , size_t count )
2002-03-19 03:51:01 +00:00
{
zval func_name ;
2014-02-10 06:04:30 +00:00
zval retval ;
zval args [ 1 ] ;
2002-03-19 03:51:01 +00:00
int call_result ;
size_t didread = 0 ;
php_userstream_data_t * us = ( php_userstream_data_t * ) stream - > abstract ;
assert ( us ! = NULL ) ;
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_READ , sizeof ( USERSTREAM_READ ) - 1 ) ;
2002-03-19 03:51:01 +00:00
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 0 ] , count ) ;
2002-10-05 10:35:13 +00:00
call_result = call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2002-03-19 03:51:01 +00:00
& func_name ,
& retval ,
2002-10-05 10:35:13 +00:00
1 , args ,
2014-12-13 22:06:14 +00:00
0 , NULL ) ;
2002-09-23 13:22:10 +00:00
2015-03-09 07:21:08 +00:00
zval_ptr_dtor ( & args [ 0 ] ) ;
2014-07-15 15:18:56 +00:00
zval_ptr_dtor ( & func_name ) ;
if ( EG ( exception ) ) {
return - 1 ;
}
2014-02-10 06:04:30 +00:00
if ( call_result = = SUCCESS & & Z_TYPE ( retval ) ! = IS_UNDEF ) {
convert_to_string ( & retval ) ;
2014-08-25 17:24:55 +00:00
didread = Z_STRLEN ( retval ) ;
2002-10-05 10:35:13 +00:00
if ( didread > count ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_READ " - read " ZEND_LONG_FMT " bytes more data than requested ( " ZEND_LONG_FMT " read, " ZEND_LONG_FMT " max) - excess data will be lost " ,
2014-08-25 17:24:55 +00:00
us - > wrapper - > classname , ( zend_long ) ( didread - count ) , ( zend_long ) didread , ( zend_long ) count ) ;
2002-10-05 10:35:13 +00:00
didread = count ;
2002-09-23 13:22:10 +00:00
}
2002-10-05 10:35:13 +00:00
if ( didread > 0 )
2014-02-10 06:04:30 +00:00
memcpy ( buf , Z_STRVAL ( retval ) , didread ) ;
2002-10-05 10:35:13 +00:00
} else if ( call_result = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_READ " is not implemented! " ,
2002-10-05 10:35:13 +00:00
us - > wrapper - > classname ) ;
}
2002-03-19 03:51:01 +00:00
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & retval ) ;
ZVAL_UNDEF ( & retval ) ;
2002-10-05 10:35:13 +00:00
/* since the user stream has no way of setting the eof flag directly, we need to ask it if we hit eof */
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_EOF , sizeof ( USERSTREAM_EOF ) - 1 ) ;
2002-10-05 10:35:13 +00:00
call_result = call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2002-10-05 10:35:13 +00:00
& func_name ,
& retval ,
2014-12-13 22:06:14 +00:00
0 , NULL , 0 , NULL ) ;
2002-10-05 10:35:13 +00:00
2014-02-10 06:04:30 +00:00
if ( call_result = = SUCCESS & & Z_TYPE ( retval ) ! = IS_UNDEF & & zval_is_true ( & retval ) ) {
2002-10-14 00:16:02 +00:00
stream - > eof = 1 ;
} else if ( call_result = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING ,
2002-10-14 00:16:02 +00:00
" %s:: " USERSTREAM_EOF " is not implemented! Assuming EOF " ,
us - > wrapper - > classname ) ;
2002-10-05 10:35:13 +00:00
stream - > eof = 1 ;
2002-03-19 03:51:01 +00:00
}
2002-10-05 10:35:13 +00:00
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & retval ) ;
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & func_name ) ;
2002-10-15 01:57:19 +00:00
2002-03-19 03:51:01 +00:00
return didread ;
}
2014-12-13 22:06:14 +00:00
static int php_userstreamop_close ( php_stream * stream , int close_handle )
2002-03-19 03:51:01 +00:00
{
zval func_name ;
2014-02-10 06:04:30 +00:00
zval retval ;
2002-03-19 03:51:01 +00:00
php_userstream_data_t * us = ( php_userstream_data_t * ) stream - > abstract ;
assert ( us ! = NULL ) ;
2011-05-25 21:03:55 +00:00
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_CLOSE , sizeof ( USERSTREAM_CLOSE ) - 1 ) ;
2011-05-25 21:03:55 +00:00
2002-05-04 17:32:01 +00:00
call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2002-03-19 03:51:01 +00:00
& func_name ,
& retval ,
2014-12-13 22:06:14 +00:00
0 , NULL , 0 , NULL ) ;
2002-03-19 03:51:01 +00:00
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & retval ) ;
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & func_name ) ;
2011-05-25 21:03:55 +00:00
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & us - > object ) ;
2014-03-04 11:12:43 +00:00
ZVAL_UNDEF ( & us - > object ) ;
2002-03-19 03:51:01 +00:00
efree ( us ) ;
2011-05-25 21:03:55 +00:00
2002-03-19 03:51:01 +00:00
return 0 ;
}
2014-12-13 22:06:14 +00:00
static int php_userstreamop_flush ( php_stream * stream )
2002-03-19 03:51:01 +00:00
{
zval func_name ;
2014-02-10 06:04:30 +00:00
zval retval ;
2002-03-19 03:51:01 +00:00
int call_result ;
php_userstream_data_t * us = ( php_userstream_data_t * ) stream - > abstract ;
assert ( us ! = NULL ) ;
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_FLUSH , sizeof ( USERSTREAM_FLUSH ) - 1 ) ;
2011-05-25 21:03:55 +00:00
2002-03-19 03:51:01 +00:00
call_result = call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2002-03-19 03:51:01 +00:00
& func_name ,
& retval ,
2014-12-13 22:06:14 +00:00
0 , NULL , 0 , NULL ) ;
2002-03-19 03:51:01 +00:00
2014-02-10 06:04:30 +00:00
if ( call_result = = SUCCESS & & Z_TYPE ( retval ) ! = IS_UNDEF & & zval_is_true ( & retval ) )
2002-03-19 03:51:01 +00:00
call_result = 0 ;
else
call_result = - 1 ;
2011-05-25 21:03:55 +00:00
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & retval ) ;
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & func_name ) ;
2011-05-25 21:03:55 +00:00
2002-03-19 03:51:01 +00:00
return call_result ;
}
2014-12-13 22:06:14 +00:00
static int php_userstreamop_seek ( php_stream * stream , zend_off_t offset , int whence , zend_off_t * newoffs )
2002-03-19 03:51:01 +00:00
{
zval func_name ;
2014-02-10 06:04:30 +00:00
zval retval ;
2002-09-23 01:47:04 +00:00
int call_result , ret ;
2002-03-19 03:51:01 +00:00
php_userstream_data_t * us = ( php_userstream_data_t * ) stream - > abstract ;
2014-02-10 06:04:30 +00:00
zval args [ 2 ] ;
2002-03-19 03:51:01 +00:00
assert ( us ! = NULL ) ;
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_SEEK , sizeof ( USERSTREAM_SEEK ) - 1 ) ;
2002-03-19 03:51:01 +00:00
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 0 ] , offset ) ;
ZVAL_LONG ( & args [ 1 ] , whence ) ;
2002-09-23 01:47:04 +00:00
call_result = call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2002-03-19 03:51:01 +00:00
& func_name ,
& retval ,
2002-09-23 01:47:04 +00:00
2 , args ,
2014-12-13 22:06:14 +00:00
0 , NULL ) ;
2002-03-19 03:51:01 +00:00
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & args [ 0 ] ) ;
zval_ptr_dtor ( & args [ 1 ] ) ;
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & func_name ) ;
2002-03-19 03:51:01 +00:00
2002-09-23 13:22:10 +00:00
if ( call_result = = FAILURE ) {
/* stream_seek is not implemented, so disable seeks for this stream */
stream - > flags | = PHP_STREAM_FLAG_NO_SEEK ;
/* there should be no retval to clean up */
2011-05-25 21:03:55 +00:00
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & retval ) ;
2011-05-25 21:03:55 +00:00
2002-09-23 13:22:10 +00:00
return - 1 ;
2014-02-10 06:04:30 +00:00
} else if ( call_result = = SUCCESS & & Z_TYPE ( retval ) ! = IS_UNDEF & & zval_is_true ( & retval ) ) {
2002-09-23 13:22:10 +00:00
ret = 0 ;
} else {
2002-09-23 01:47:04 +00:00
ret = - 1 ;
2002-09-23 13:22:10 +00:00
}
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & retval ) ;
ZVAL_UNDEF ( & retval ) ;
2002-03-19 03:51:01 +00:00
2007-02-13 19:50:59 +00:00
if ( ret ) {
return ret ;
}
2002-09-23 01:47:04 +00:00
/* now determine where we are */
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_TELL , sizeof ( USERSTREAM_TELL ) - 1 ) ;
2002-03-19 03:51:01 +00:00
2002-09-18 10:15:40 +00:00
call_result = call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2002-09-23 01:47:04 +00:00
& func_name ,
& retval ,
2014-12-13 22:06:14 +00:00
0 , NULL , 0 , NULL ) ;
2002-03-19 03:51:01 +00:00
2014-08-25 17:24:55 +00:00
if ( call_result = = SUCCESS & & Z_TYPE ( retval ) = = IS_LONG ) {
* newoffs = Z_LVAL ( retval ) ;
2007-02-13 19:50:59 +00:00
ret = 0 ;
} else if ( call_result = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_TELL " is not implemented! " , us - > wrapper - > classname ) ;
2007-02-13 19:50:59 +00:00
ret = - 1 ;
} else {
ret = - 1 ;
}
2002-10-15 01:57:19 +00:00
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & retval ) ;
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & func_name ) ;
2007-02-13 19:50:59 +00:00
return ret ;
2002-09-28 13:05:47 +00:00
}
/* parse the return value from one of the stat functions and store the
* relevant fields into the statbuf provided */
2014-12-13 22:06:14 +00:00
static int statbuf_from_array ( zval * array , php_stream_statbuf * ssb )
2002-09-28 13:05:47 +00:00
{
2014-02-10 06:04:30 +00:00
zval * elem ;
2002-09-28 13:05:47 +00:00
2003-05-20 13:09:11 +00:00
# define STAT_PROP_ENTRY_EX(name, name2) \
2014-02-10 06:04:30 +00:00
if ( NULL ! = ( elem = zend_hash_str_find ( Z_ARRVAL_P ( array ) , # name , sizeof ( # name ) - 1 ) ) ) { \
2011-02-01 22:55:17 +00:00
SEPARATE_ZVAL ( elem ) ; \
2014-08-25 19:51:49 +00:00
convert_to_long ( elem ) ; \
2014-08-25 17:24:55 +00:00
ssb - > sb . st_ # # name2 = Z_LVAL_P ( elem ) ; \
2002-09-28 13:05:47 +00:00
}
2003-05-20 13:09:11 +00:00
# define STAT_PROP_ENTRY(name) STAT_PROP_ENTRY_EX(name,name)
2011-12-22 15:33:48 +00:00
memset ( ssb , 0 , sizeof ( php_stream_statbuf ) ) ;
2002-09-28 13:05:47 +00:00
STAT_PROP_ENTRY ( dev ) ;
STAT_PROP_ENTRY ( ino ) ;
STAT_PROP_ENTRY ( mode ) ;
STAT_PROP_ENTRY ( nlink ) ;
STAT_PROP_ENTRY ( uid ) ;
STAT_PROP_ENTRY ( gid ) ;
# if HAVE_ST_RDEV
STAT_PROP_ENTRY ( rdev ) ;
# endif
STAT_PROP_ENTRY ( size ) ;
2004-09-23 13:07:43 +00:00
# ifdef NETWARE
2003-05-20 13:09:11 +00:00
STAT_PROP_ENTRY_EX ( atime , atime . tv_sec ) ;
STAT_PROP_ENTRY_EX ( mtime , mtime . tv_sec ) ;
STAT_PROP_ENTRY_EX ( ctime , ctime . tv_sec ) ;
2003-01-03 12:48:14 +00:00
# else
2002-09-28 13:05:47 +00:00
STAT_PROP_ENTRY ( atime ) ;
STAT_PROP_ENTRY ( mtime ) ;
STAT_PROP_ENTRY ( ctime ) ;
2003-01-03 12:48:14 +00:00
# endif
2002-09-28 13:05:47 +00:00
# ifdef HAVE_ST_BLKSIZE
STAT_PROP_ENTRY ( blksize ) ;
# endif
# ifdef HAVE_ST_BLOCKS
STAT_PROP_ENTRY ( blocks ) ;
# endif
2011-05-25 21:03:55 +00:00
# undef STAT_PROP_ENTRY
# undef STAT_PROP_ENTRY_EX
2002-09-28 13:05:47 +00:00
return SUCCESS ;
}
2014-12-13 22:06:14 +00:00
static int php_userstreamop_stat ( php_stream * stream , php_stream_statbuf * ssb )
2002-09-28 13:05:47 +00:00
{
zval func_name ;
2014-02-10 06:04:30 +00:00
zval retval ;
2002-09-28 13:05:47 +00:00
int call_result ;
php_userstream_data_t * us = ( php_userstream_data_t * ) stream - > abstract ;
int ret = - 1 ;
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_STAT , sizeof ( USERSTREAM_STAT ) - 1 ) ;
2002-09-28 13:05:47 +00:00
call_result = call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2002-09-28 13:05:47 +00:00
& func_name ,
& retval ,
2014-12-13 22:06:14 +00:00
0 , NULL , 0 , NULL ) ;
2002-09-28 13:05:47 +00:00
2014-02-10 06:04:30 +00:00
if ( call_result = = SUCCESS & & Z_TYPE ( retval ) = = IS_ARRAY ) {
2014-12-13 22:06:14 +00:00
if ( SUCCESS = = statbuf_from_array ( & retval , ssb ) )
2002-09-28 13:05:47 +00:00
ret = 0 ;
} else {
if ( call_result = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_STAT " is not implemented! " ,
2002-09-28 13:05:47 +00:00
us - > wrapper - > classname ) ;
}
}
2003-05-29 20:19:03 +00:00
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & retval ) ;
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & func_name ) ;
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
return ret ;
}
2004-01-21 10:17:12 +00:00
2014-12-13 22:06:14 +00:00
static int php_userstreamop_set_option ( php_stream * stream , int option , int value , void * ptrparam ) {
2004-01-21 10:17:12 +00:00
zval func_name ;
2014-02-10 06:04:30 +00:00
zval retval ;
2004-01-21 10:17:12 +00:00
int call_result ;
php_userstream_data_t * us = ( php_userstream_data_t * ) stream - > abstract ;
2011-02-18 17:53:26 +00:00
int ret = PHP_STREAM_OPTION_RETURN_NOTIMPL ;
2014-02-10 06:04:30 +00:00
zval args [ 3 ] ;
2004-01-21 10:17:12 +00:00
switch ( option ) {
2004-03-07 22:05:21 +00:00
case PHP_STREAM_OPTION_CHECK_LIVENESS :
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_EOF , sizeof ( USERSTREAM_EOF ) - 1 ) ;
2014-12-13 22:06:14 +00:00
call_result = call_user_function_ex ( NULL , Z_ISUNDEF ( us - > object ) ? NULL : & us - > object , & func_name , & retval , 0 , NULL , 0 , NULL ) ;
2014-04-30 14:32:42 +00:00
if ( call_result = = SUCCESS & & ( Z_TYPE ( retval ) = = IS_FALSE | | Z_TYPE ( retval ) = = IS_TRUE ) ) {
2014-02-10 06:04:30 +00:00
ret = zval_is_true ( & retval ) ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK ;
2004-03-07 22:05:21 +00:00
} else {
ret = PHP_STREAM_OPTION_RETURN_ERR ;
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING ,
2004-03-07 22:05:21 +00:00
" %s:: " USERSTREAM_EOF " is not implemented! Assuming EOF " ,
us - > wrapper - > classname ) ;
}
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & retval ) ;
zval_ptr_dtor ( & func_name ) ;
2004-03-07 22:05:21 +00:00
break ;
2004-01-21 10:17:12 +00:00
case PHP_STREAM_OPTION_LOCKING :
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 0 ] , 0 ) ;
2008-11-26 04:19:20 +00:00
if ( value & LOCK_NB ) {
2014-08-25 17:24:55 +00:00
Z_LVAL_P ( & args [ 0 ] ) | = PHP_LOCK_NB ;
2008-11-26 04:19:20 +00:00
}
switch ( value & ~ LOCK_NB ) {
case LOCK_SH :
2014-08-25 17:24:55 +00:00
Z_LVAL_P ( & args [ 0 ] ) | = PHP_LOCK_SH ;
2008-11-26 04:19:20 +00:00
break ;
case LOCK_EX :
2014-08-25 17:24:55 +00:00
Z_LVAL_P ( & args [ 0 ] ) | = PHP_LOCK_EX ;
2008-11-26 04:19:20 +00:00
break ;
case LOCK_UN :
2014-08-25 17:24:55 +00:00
Z_LVAL_P ( & args [ 0 ] ) | = PHP_LOCK_UN ;
2008-11-26 04:19:20 +00:00
break ;
}
2004-03-07 22:05:21 +00:00
/* TODO wouldblock */
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_LOCK , sizeof ( USERSTREAM_LOCK ) - 1 ) ;
2011-05-25 21:03:55 +00:00
2004-01-21 10:17:12 +00:00
call_result = call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2014-03-04 11:12:43 +00:00
& func_name ,
& retval ,
2014-12-13 22:06:14 +00:00
1 , args , 0 , NULL ) ;
2011-05-25 21:03:55 +00:00
2014-04-30 14:32:42 +00:00
if ( call_result = = SUCCESS & & ( Z_TYPE ( retval ) = = IS_FALSE | | Z_TYPE ( retval ) = = IS_TRUE ) ) {
ret = ( Z_TYPE ( retval ) = = IS_FALSE ) ;
2004-01-21 10:17:12 +00:00
} else if ( call_result = = FAILURE ) {
2011-05-25 21:03:55 +00:00
if ( value = = 0 ) {
2004-03-07 22:05:21 +00:00
/* lock support test (TODO: more check) */
2011-02-18 17:53:26 +00:00
ret = PHP_STREAM_OPTION_RETURN_OK ;
2004-01-21 10:17:12 +00:00
} else {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_LOCK " is not implemented! " ,
2004-01-21 10:17:12 +00:00
us - > wrapper - > classname ) ;
2011-02-18 17:53:26 +00:00
ret = PHP_STREAM_OPTION_RETURN_ERR ;
2004-01-21 10:17:12 +00:00
}
}
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & retval ) ;
zval_ptr_dtor ( & func_name ) ;
zval_ptr_dtor ( & args [ 0 ] ) ;
2004-01-21 10:17:12 +00:00
break ;
2011-05-25 21:03:55 +00:00
2011-02-17 00:25:32 +00:00
case PHP_STREAM_OPTION_TRUNCATE_API :
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_TRUNCATE , sizeof ( USERSTREAM_TRUNCATE ) - 1 ) ;
2011-05-25 21:03:55 +00:00
2011-02-17 00:25:32 +00:00
switch ( value ) {
case PHP_STREAM_TRUNCATE_SUPPORTED :
2014-03-04 11:12:43 +00:00
if ( zend_is_callable_ex ( & func_name ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : Z_OBJ ( us - > object ) ,
2014-12-13 22:06:14 +00:00
IS_CALLABLE_CHECK_SILENT , NULL , NULL , NULL ) )
2011-02-17 00:25:32 +00:00
ret = PHP_STREAM_OPTION_RETURN_OK ;
else
ret = PHP_STREAM_OPTION_RETURN_ERR ;
break ;
2011-05-25 21:03:55 +00:00
2011-02-17 00:25:32 +00:00
case PHP_STREAM_TRUNCATE_SET_SIZE : {
ptrdiff_t new_size = * ( ptrdiff_t * ) ptrparam ;
if ( new_size > = 0 & & new_size < = ( ptrdiff_t ) LONG_MAX ) {
2014-08-26 09:23:25 +00:00
ZVAL_LONG ( & args [ 0 ] , ( zend_long ) new_size ) ;
2011-02-17 00:25:32 +00:00
call_result = call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2014-03-04 11:12:43 +00:00
& func_name ,
& retval ,
2014-12-13 22:06:14 +00:00
1 , args , 0 , NULL ) ;
2014-02-10 06:04:30 +00:00
if ( call_result = = SUCCESS & & Z_TYPE ( retval ) ! = IS_UNDEF ) {
2014-04-30 14:32:42 +00:00
if ( Z_TYPE ( retval ) = = IS_FALSE | | Z_TYPE ( retval ) = = IS_TRUE ) {
ret = ( Z_TYPE ( retval ) = = IS_TRUE ) ? PHP_STREAM_OPTION_RETURN_OK :
2014-02-10 06:04:30 +00:00
PHP_STREAM_OPTION_RETURN_ERR ;
2011-02-17 00:25:32 +00:00
} else {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING ,
2011-02-17 00:25:32 +00:00
" %s:: " USERSTREAM_TRUNCATE " did not return a boolean! " ,
us - > wrapper - > classname ) ;
}
} else {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING ,
2011-02-17 00:25:32 +00:00
" %s:: " USERSTREAM_TRUNCATE " is not implemented! " ,
us - > wrapper - > classname ) ;
}
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & retval ) ;
zval_ptr_dtor ( & args [ 0 ] ) ;
2011-02-17 00:25:32 +00:00
} else { /* bad new size */
ret = PHP_STREAM_OPTION_RETURN_ERR ;
}
break ;
}
}
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & func_name ) ;
2011-02-17 00:25:32 +00:00
break ;
2011-05-25 21:03:55 +00:00
2008-11-15 12:52:13 +00:00
case PHP_STREAM_OPTION_READ_BUFFER :
case PHP_STREAM_OPTION_WRITE_BUFFER :
case PHP_STREAM_OPTION_READ_TIMEOUT :
case PHP_STREAM_OPTION_BLOCKING : {
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_SET_OPTION , sizeof ( USERSTREAM_SET_OPTION ) - 1 ) ;
2008-11-15 12:52:13 +00:00
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 0 ] , option ) ;
2014-02-10 06:04:30 +00:00
ZVAL_NULL ( & args [ 1 ] ) ;
ZVAL_NULL ( & args [ 2 ] ) ;
2008-11-15 12:52:13 +00:00
switch ( option ) {
case PHP_STREAM_OPTION_READ_BUFFER :
case PHP_STREAM_OPTION_WRITE_BUFFER :
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 1 ] , value ) ;
2008-11-15 12:52:13 +00:00
if ( ptrparam ) {
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 2 ] , * ( long * ) ptrparam ) ;
2008-11-15 12:52:13 +00:00
} else {
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 2 ] , BUFSIZ ) ;
2008-11-15 12:52:13 +00:00
}
break ;
case PHP_STREAM_OPTION_READ_TIMEOUT : {
struct timeval tv = * ( struct timeval * ) ptrparam ;
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 1 ] , tv . tv_sec ) ;
ZVAL_LONG ( & args [ 2 ] , tv . tv_usec ) ;
2008-11-15 12:52:13 +00:00
break ;
}
case PHP_STREAM_OPTION_BLOCKING :
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 1 ] , value ) ;
2008-11-15 12:52:13 +00:00
break ;
default :
break ;
}
call_result = call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2008-11-15 12:52:13 +00:00
& func_name ,
& retval ,
2014-12-13 22:06:14 +00:00
3 , args , 0 , NULL ) ;
2011-05-25 21:03:55 +00:00
2011-02-18 17:53:26 +00:00
if ( call_result = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_SET_OPTION " is not implemented! " ,
2011-02-18 17:53:26 +00:00
us - > wrapper - > classname ) ;
ret = PHP_STREAM_OPTION_RETURN_ERR ;
2014-12-13 22:06:14 +00:00
} else if ( Z_TYPE ( retval ) ! = IS_UNDEF & & zend_is_true ( & retval ) ) {
2011-02-18 17:53:26 +00:00
ret = PHP_STREAM_OPTION_RETURN_OK ;
} else {
ret = PHP_STREAM_OPTION_RETURN_ERR ;
}
2008-11-15 12:52:13 +00:00
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & retval ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & args [ 2 ] ) ;
zval_ptr_dtor ( & args [ 1 ] ) ;
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & args [ 0 ] ) ;
zval_ptr_dtor ( & func_name ) ;
2008-11-15 12:52:13 +00:00
break ;
}
2004-01-21 10:17:12 +00:00
}
return ret ;
}
2014-12-13 22:06:14 +00:00
static int user_wrapper_unlink ( php_stream_wrapper * wrapper , const char * url , int options , php_stream_context * context )
2003-05-14 18:30:49 +00:00
{
struct php_user_stream_wrapper * uwrap = ( struct php_user_stream_wrapper * ) wrapper - > abstract ;
2014-02-10 06:04:30 +00:00
zval zfuncname , zretval ;
zval args [ 1 ] ;
2003-05-14 18:30:49 +00:00
int call_result ;
2014-02-25 21:00:39 +00:00
zval object ;
2003-05-14 18:30:49 +00:00
int ret = 0 ;
/* create an instance of our class */
2014-12-13 22:06:14 +00:00
user_stream_create_object ( uwrap , context , & object ) ;
2014-02-25 21:00:39 +00:00
if ( Z_TYPE ( object ) = = IS_UNDEF ) {
2012-08-08 05:59:12 +00:00
return ret ;
2003-12-02 19:14:31 +00:00
}
2003-05-14 18:30:49 +00:00
/* call the unlink method */
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & args [ 0 ] , url ) ;
2003-05-14 18:30:49 +00:00
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & zfuncname , USERSTREAM_UNLINK ) ;
2011-05-25 21:03:55 +00:00
2003-05-14 18:30:49 +00:00
call_result = call_user_function_ex ( NULL ,
2014-02-25 21:00:39 +00:00
& object ,
2014-02-10 06:04:30 +00:00
& zfuncname ,
2003-05-14 18:30:49 +00:00
& zretval ,
1 , args ,
2014-12-14 13:07:59 +00:00
0 , NULL ) ;
2003-05-14 18:30:49 +00:00
2014-04-30 14:32:42 +00:00
if ( call_result = = SUCCESS & & ( Z_TYPE ( zretval ) = = IS_FALSE | | Z_TYPE ( zretval ) = = IS_TRUE ) ) {
ret = ( Z_TYPE ( zretval ) = = IS_TRUE ) ;
2003-05-14 18:30:49 +00:00
} else if ( call_result = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_UNLINK " is not implemented! " , uwrap - > classname ) ;
2003-05-14 18:30:49 +00:00
}
/* clean up */
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & object ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & zretval ) ;
2014-02-26 08:22:03 +00:00
zval_ptr_dtor ( & zfuncname ) ;
2011-05-25 21:03:55 +00:00
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & args [ 0 ] ) ;
2003-05-14 18:30:49 +00:00
return ret ;
}
2013-07-30 10:49:36 +00:00
static int user_wrapper_rename ( php_stream_wrapper * wrapper , const char * url_from , const char * url_to ,
2014-12-13 22:06:14 +00:00
int options , php_stream_context * context )
2003-12-12 23:06:42 +00:00
{
struct php_user_stream_wrapper * uwrap = ( struct php_user_stream_wrapper * ) wrapper - > abstract ;
2014-02-10 06:04:30 +00:00
zval zfuncname , zretval ;
zval args [ 2 ] ;
2003-12-12 23:06:42 +00:00
int call_result ;
2014-02-25 21:00:39 +00:00
zval object ;
2003-12-12 23:06:42 +00:00
int ret = 0 ;
/* create an instance of our class */
2015-01-03 09:22:58 +00:00
user_stream_create_object ( uwrap , context , & object ) ;
2014-02-25 21:00:39 +00:00
if ( Z_TYPE ( object ) = = IS_UNDEF ) {
2012-08-08 05:59:12 +00:00
return ret ;
2003-12-12 23:06:42 +00:00
}
/* call the rename method */
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & args [ 0 ] , url_from ) ;
ZVAL_STRING ( & args [ 1 ] , url_to ) ;
2003-12-12 23:06:42 +00:00
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & zfuncname , USERSTREAM_RENAME ) ;
2011-05-25 21:03:55 +00:00
2003-12-12 23:06:42 +00:00
call_result = call_user_function_ex ( NULL ,
2014-02-25 21:00:39 +00:00
& object ,
2014-02-10 06:04:30 +00:00
& zfuncname ,
2003-12-12 23:06:42 +00:00
& zretval ,
2 , args ,
2014-12-14 13:07:59 +00:00
0 , NULL ) ;
2003-12-12 23:06:42 +00:00
2014-04-30 14:32:42 +00:00
if ( call_result = = SUCCESS & & ( Z_TYPE ( zretval ) = = IS_FALSE | | Z_TYPE ( zretval ) = = IS_TRUE ) ) {
ret = ( Z_TYPE ( zretval ) = = IS_TRUE ) ;
2003-12-12 23:06:42 +00:00
} else if ( call_result = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_RENAME " is not implemented! " , uwrap - > classname ) ;
2003-12-12 23:06:42 +00:00
}
/* clean up */
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & object ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & zretval ) ;
2011-05-25 21:03:55 +00:00
2003-12-12 23:06:42 +00:00
zval_ptr_dtor ( & zfuncname ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & args [ 1 ] ) ;
zval_ptr_dtor ( & args [ 0 ] ) ;
2003-12-12 23:06:42 +00:00
return ret ;
}
2013-07-30 10:49:36 +00:00
static int user_wrapper_mkdir ( php_stream_wrapper * wrapper , const char * url , int mode ,
2014-12-13 22:06:14 +00:00
int options , php_stream_context * context )
2003-12-13 04:07:18 +00:00
{
struct php_user_stream_wrapper * uwrap = ( struct php_user_stream_wrapper * ) wrapper - > abstract ;
2014-02-10 06:04:30 +00:00
zval zfuncname , zretval ;
zval args [ 3 ] ;
2003-12-13 04:07:18 +00:00
int call_result ;
2014-02-25 21:00:39 +00:00
zval object ;
2003-12-13 04:07:18 +00:00
int ret = 0 ;
/* create an instance of our class */
2015-01-03 09:22:58 +00:00
user_stream_create_object ( uwrap , context , & object ) ;
2014-02-25 21:00:39 +00:00
if ( Z_TYPE ( object ) = = IS_UNDEF ) {
2012-08-08 05:59:12 +00:00
return ret ;
2003-12-13 04:07:18 +00:00
}
2009-05-08 11:35:12 +00:00
/* call the mkdir method */
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & args [ 0 ] , url ) ;
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 1 ] , mode ) ;
ZVAL_LONG ( & args [ 2 ] , options ) ;
2003-12-13 04:07:18 +00:00
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & zfuncname , USERSTREAM_MKDIR ) ;
2011-05-25 21:03:55 +00:00
2003-12-13 04:07:18 +00:00
call_result = call_user_function_ex ( NULL ,
2014-02-25 21:00:39 +00:00
& object ,
2014-02-10 06:04:30 +00:00
& zfuncname ,
2003-12-13 04:07:18 +00:00
& zretval ,
3 , args ,
2014-12-14 13:07:59 +00:00
0 , NULL ) ;
2003-12-13 04:07:18 +00:00
2014-04-30 14:32:42 +00:00
if ( call_result = = SUCCESS & & ( Z_TYPE ( zretval ) = = IS_FALSE | | Z_TYPE ( zretval ) = = IS_TRUE ) ) {
ret = ( Z_TYPE ( zretval ) = = IS_TRUE ) ;
2003-12-13 04:07:18 +00:00
} else if ( call_result = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_MKDIR " is not implemented! " , uwrap - > classname ) ;
2003-12-13 04:07:18 +00:00
}
/* clean up */
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & object ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & zretval ) ;
2011-05-25 21:03:55 +00:00
2003-12-13 04:07:18 +00:00
zval_ptr_dtor ( & zfuncname ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & args [ 2 ] ) ;
zval_ptr_dtor ( & args [ 1 ] ) ;
zval_ptr_dtor ( & args [ 0 ] ) ;
2003-12-13 04:07:18 +00:00
return ret ;
}
2013-07-30 10:49:36 +00:00
static int user_wrapper_rmdir ( php_stream_wrapper * wrapper , const char * url ,
2014-12-13 22:06:14 +00:00
int options , php_stream_context * context )
2003-12-13 04:07:18 +00:00
{
struct php_user_stream_wrapper * uwrap = ( struct php_user_stream_wrapper * ) wrapper - > abstract ;
2014-02-10 06:04:30 +00:00
zval zfuncname , zretval ;
zval args [ 2 ] ;
2003-12-13 04:07:18 +00:00
int call_result ;
2014-02-25 21:00:39 +00:00
zval object ;
2003-12-13 04:07:18 +00:00
int ret = 0 ;
/* create an instance of our class */
2015-01-03 09:22:58 +00:00
user_stream_create_object ( uwrap , context , & object ) ;
2014-02-25 21:00:39 +00:00
if ( Z_TYPE ( object ) = = IS_UNDEF ) {
2012-08-08 05:59:12 +00:00
return ret ;
2003-12-13 04:07:18 +00:00
}
2009-05-08 11:35:12 +00:00
/* call the rmdir method */
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & args [ 0 ] , url ) ;
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 1 ] , options ) ;
2003-12-13 04:07:18 +00:00
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & zfuncname , USERSTREAM_RMDIR ) ;
2011-05-25 21:03:55 +00:00
2003-12-13 04:07:18 +00:00
call_result = call_user_function_ex ( NULL ,
2014-02-25 21:00:39 +00:00
& object ,
2014-02-10 06:04:30 +00:00
& zfuncname ,
2003-12-13 04:07:18 +00:00
& zretval ,
2 , args ,
2014-12-14 13:07:59 +00:00
0 , NULL ) ;
2003-12-13 04:07:18 +00:00
2014-04-30 14:32:42 +00:00
if ( call_result = = SUCCESS & & ( Z_TYPE ( zretval ) = = IS_FALSE | | Z_TYPE ( zretval ) = = IS_TRUE ) ) {
ret = ( Z_TYPE ( zretval ) = = IS_TRUE ) ;
2003-12-13 04:07:18 +00:00
} else if ( call_result = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_RMDIR " is not implemented! " , uwrap - > classname ) ;
2003-12-13 04:07:18 +00:00
}
/* clean up */
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & object ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & zretval ) ;
2011-05-25 21:03:55 +00:00
2003-12-13 04:07:18 +00:00
zval_ptr_dtor ( & zfuncname ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & args [ 1 ] ) ;
zval_ptr_dtor ( & args [ 0 ] ) ;
2003-12-13 04:07:18 +00:00
return ret ;
}
2013-07-30 10:49:36 +00:00
static int user_wrapper_metadata ( php_stream_wrapper * wrapper , const char * url , int option ,
2014-12-13 22:06:14 +00:00
void * value , php_stream_context * context )
2011-05-25 21:03:55 +00:00
{
struct php_user_stream_wrapper * uwrap = ( struct php_user_stream_wrapper * ) wrapper - > abstract ;
2014-02-10 06:04:30 +00:00
zval zfuncname , zretval ;
zval args [ 3 ] ;
2011-05-25 21:03:55 +00:00
int call_result ;
2014-02-25 21:00:39 +00:00
zval object ;
2011-05-25 21:03:55 +00:00
int ret = 0 ;
switch ( option ) {
case PHP_STREAM_META_TOUCH :
2014-02-10 06:04:30 +00:00
array_init ( & args [ 2 ] ) ;
2011-05-25 21:03:55 +00:00
if ( value ) {
struct utimbuf * newtime = ( struct utimbuf * ) value ;
2014-08-25 17:24:55 +00:00
add_index_long ( & args [ 2 ] , 0 , newtime - > modtime ) ;
add_index_long ( & args [ 2 ] , 1 , newtime - > actime ) ;
2011-05-25 21:03:55 +00:00
}
break ;
case PHP_STREAM_META_GROUP :
case PHP_STREAM_META_OWNER :
case PHP_STREAM_META_ACCESS :
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 2 ] , * ( long * ) value ) ;
2011-05-25 21:03:55 +00:00
break ;
case PHP_STREAM_META_GROUP_NAME :
case PHP_STREAM_META_OWNER_NAME :
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & args [ 2 ] , value ) ;
2011-05-25 21:03:55 +00:00
break ;
default :
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Unknown option %d for " USERSTREAM_METADATA , option ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & args [ 2 ] ) ;
2011-05-25 21:03:55 +00:00
return ret ;
}
/* create an instance of our class */
2015-01-03 09:22:58 +00:00
user_stream_create_object ( uwrap , context , & object ) ;
2014-02-25 21:00:39 +00:00
if ( Z_TYPE ( object ) = = IS_UNDEF ) {
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & args [ 2 ] ) ;
2012-08-08 05:59:12 +00:00
return ret ;
2011-05-25 21:03:55 +00:00
}
/* call the mkdir method */
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & args [ 0 ] , url ) ;
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 1 ] , option ) ;
2011-05-25 21:03:55 +00:00
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & zfuncname , USERSTREAM_METADATA ) ;
2011-05-25 21:03:55 +00:00
call_result = call_user_function_ex ( NULL ,
2014-02-25 21:00:39 +00:00
& object ,
2014-02-10 06:04:30 +00:00
& zfuncname ,
2011-05-25 21:03:55 +00:00
& zretval ,
3 , args ,
2014-12-14 13:07:59 +00:00
0 , NULL ) ;
2011-05-25 21:03:55 +00:00
2014-04-30 14:32:42 +00:00
if ( call_result = = SUCCESS & & ( Z_TYPE ( zretval ) = = IS_FALSE | | Z_TYPE ( zretval ) = = IS_TRUE ) ) {
ret = Z_TYPE ( zretval ) = = IS_TRUE ;
2011-05-25 21:03:55 +00:00
} else if ( call_result = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_METADATA " is not implemented! " , uwrap - > classname ) ;
2011-05-25 21:03:55 +00:00
}
/* clean up */
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & object ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & zretval ) ;
2011-05-25 21:03:55 +00:00
zval_ptr_dtor ( & zfuncname ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & args [ 0 ] ) ;
zval_ptr_dtor ( & args [ 1 ] ) ;
zval_ptr_dtor ( & args [ 2 ] ) ;
2011-05-25 21:03:55 +00:00
return ret ;
}
2013-07-30 10:49:36 +00:00
static int user_wrapper_stat_url ( php_stream_wrapper * wrapper , const char * url , int flags ,
2014-12-13 22:06:14 +00:00
php_stream_statbuf * ssb , php_stream_context * context )
2002-09-28 13:05:47 +00:00
{
struct php_user_stream_wrapper * uwrap = ( struct php_user_stream_wrapper * ) wrapper - > abstract ;
2014-02-10 06:04:30 +00:00
zval zfuncname , zretval ;
zval args [ 2 ] ;
2002-09-28 13:05:47 +00:00
int call_result ;
2014-02-25 21:00:39 +00:00
zval object ;
2002-09-28 13:05:47 +00:00
int ret = - 1 ;
/* create an instance of our class */
2014-12-13 22:06:14 +00:00
user_stream_create_object ( uwrap , context , & object ) ;
2014-02-25 21:00:39 +00:00
if ( Z_TYPE ( object ) = = IS_UNDEF ) {
2012-08-08 05:59:12 +00:00
return ret ;
2003-12-02 19:14:31 +00:00
}
2009-05-08 11:35:12 +00:00
/* call it's stat_url method - set up params first */
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & args [ 0 ] , url ) ;
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 1 ] , flags ) ;
2003-12-02 18:52:58 +00:00
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & zfuncname , USERSTREAM_STATURL ) ;
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
call_result = call_user_function_ex ( NULL ,
2014-02-25 21:00:39 +00:00
& object ,
2014-02-10 06:04:30 +00:00
& zfuncname ,
2002-09-28 13:05:47 +00:00
& zretval ,
2003-12-02 18:52:58 +00:00
2 , args ,
2014-12-14 13:07:59 +00:00
0 , NULL ) ;
2011-05-25 21:03:55 +00:00
2014-02-10 06:04:30 +00:00
if ( call_result = = SUCCESS & & Z_TYPE ( zretval ) = = IS_ARRAY ) {
2002-09-28 13:05:47 +00:00
/* We got the info we needed */
2014-12-13 22:06:14 +00:00
if ( SUCCESS = = statbuf_from_array ( & zretval , ssb ) )
2002-09-28 13:05:47 +00:00
ret = 0 ;
} else {
if ( call_result = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_STATURL " is not implemented! " ,
2002-09-28 13:05:47 +00:00
uwrap - > classname ) ;
}
}
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
/* clean up */
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & object ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & zretval ) ;
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
zval_ptr_dtor ( & zfuncname ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & args [ 1 ] ) ;
zval_ptr_dtor ( & args [ 0 ] ) ;
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
return ret ;
}
2014-12-13 22:06:14 +00:00
static size_t php_userstreamop_readdir ( php_stream * stream , char * buf , size_t count )
2002-09-28 13:05:47 +00:00
{
zval func_name ;
2014-02-10 06:04:30 +00:00
zval retval ;
2002-09-28 13:05:47 +00:00
int call_result ;
size_t didread = 0 ;
php_userstream_data_t * us = ( php_userstream_data_t * ) stream - > abstract ;
php_stream_dirent * ent = ( php_stream_dirent * ) buf ;
/* avoid problems if someone mis-uses the stream */
if ( count ! = sizeof ( php_stream_dirent ) )
return 0 ;
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_DIR_READ , sizeof ( USERSTREAM_DIR_READ ) - 1 ) ;
2002-09-28 13:05:47 +00:00
call_result = call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2002-09-28 13:05:47 +00:00
& func_name ,
& retval ,
0 , NULL ,
2014-12-13 22:06:14 +00:00
0 , NULL ) ;
2002-09-28 13:05:47 +00:00
2014-04-30 14:32:42 +00:00
if ( call_result = = SUCCESS & & Z_TYPE ( retval ) ! = IS_FALSE & & Z_TYPE ( retval ) ! = IS_TRUE ) {
2014-02-10 06:04:30 +00:00
convert_to_string ( & retval ) ;
2014-08-25 17:24:55 +00:00
PHP_STRLCPY ( ent - > d_name , Z_STRVAL ( retval ) , sizeof ( ent - > d_name ) , Z_STRLEN ( retval ) ) ;
2002-09-28 13:05:47 +00:00
didread = sizeof ( php_stream_dirent ) ;
} else if ( call_result = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_DIR_READ " is not implemented! " ,
2002-09-23 13:22:10 +00:00
us - > wrapper - > classname ) ;
2002-09-28 13:05:47 +00:00
}
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & retval ) ;
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & func_name ) ;
2002-09-28 13:05:47 +00:00
return didread ;
}
2014-12-13 22:06:14 +00:00
static int php_userstreamop_closedir ( php_stream * stream , int close_handle )
2002-09-28 13:05:47 +00:00
{
zval func_name ;
2014-02-10 06:04:30 +00:00
zval retval ;
2002-09-28 13:05:47 +00:00
php_userstream_data_t * us = ( php_userstream_data_t * ) stream - > abstract ;
assert ( us ! = NULL ) ;
2011-05-25 21:03:55 +00:00
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_DIR_CLOSE , sizeof ( USERSTREAM_DIR_CLOSE ) - 1 ) ;
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2002-09-28 13:05:47 +00:00
& func_name ,
& retval ,
2014-12-13 22:06:14 +00:00
0 , NULL , 0 , NULL ) ;
2002-09-28 13:05:47 +00:00
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & retval ) ;
zval_ptr_dtor ( & func_name ) ;
zval_ptr_dtor ( & us - > object ) ;
2014-03-04 11:12:43 +00:00
ZVAL_UNDEF ( & us - > object ) ;
2002-03-19 03:51:01 +00:00
2002-09-28 13:05:47 +00:00
efree ( us ) ;
2011-05-25 21:03:55 +00:00
2002-03-19 03:51:01 +00:00
return 0 ;
}
2014-12-13 22:06:14 +00:00
static int php_userstreamop_rewinddir ( php_stream * stream , zend_off_t offset , int whence , zend_off_t * newoffs )
2002-09-28 13:05:47 +00:00
{
zval func_name ;
2014-02-10 06:04:30 +00:00
zval retval ;
2002-09-28 13:05:47 +00:00
php_userstream_data_t * us = ( php_userstream_data_t * ) stream - > abstract ;
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_DIR_REWIND , sizeof ( USERSTREAM_DIR_REWIND ) - 1 ) ;
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2002-09-28 13:05:47 +00:00
& func_name ,
& retval ,
2014-12-13 22:06:14 +00:00
0 , NULL , 0 , NULL ) ;
2002-09-28 13:05:47 +00:00
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & retval ) ;
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & func_name ) ;
2011-05-25 21:03:55 +00:00
2002-09-28 13:05:47 +00:00
return 0 ;
}
2014-12-13 22:06:14 +00:00
static int php_userstreamop_cast ( php_stream * stream , int castas , void * * retptr )
2008-11-15 12:52:13 +00:00
{
php_userstream_data_t * us = ( php_userstream_data_t * ) stream - > abstract ;
zval func_name ;
2014-02-10 06:04:30 +00:00
zval retval ;
zval args [ 1 ] ;
2008-11-15 12:52:13 +00:00
php_stream * intstream = NULL ;
int call_result ;
int ret = FAILURE ;
2014-02-10 06:04:30 +00:00
ZVAL_STRINGL ( & func_name , USERSTREAM_CAST , sizeof ( USERSTREAM_CAST ) - 1 ) ;
2008-11-15 12:52:13 +00:00
switch ( castas ) {
case PHP_STREAM_AS_FD_FOR_SELECT :
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 0 ] , PHP_STREAM_AS_FD_FOR_SELECT ) ;
2008-11-15 12:52:13 +00:00
break ;
default :
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & args [ 0 ] , PHP_STREAM_AS_STDIO ) ;
2008-11-15 12:52:13 +00:00
break ;
}
call_result = call_user_function_ex ( NULL ,
2014-05-03 08:06:27 +00:00
Z_ISUNDEF ( us - > object ) ? NULL : & us - > object ,
2008-11-15 12:52:13 +00:00
& func_name ,
& retval ,
2014-12-13 22:06:14 +00:00
1 , args , 0 , NULL ) ;
2008-11-15 12:52:13 +00:00
do {
if ( call_result = = FAILURE ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_CAST " is not implemented! " ,
2008-11-15 12:52:13 +00:00
us - > wrapper - > classname ) ;
break ;
}
2014-12-13 22:06:14 +00:00
if ( Z_ISUNDEF ( retval ) | | ! zend_is_true ( & retval ) ) {
2008-11-15 12:52:13 +00:00
break ;
}
php_stream_from_zval_no_verify ( intstream , & retval ) ;
if ( ! intstream ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_CAST " must return a stream resource " ,
2008-11-15 12:52:13 +00:00
us - > wrapper - > classname ) ;
break ;
}
if ( intstream = = stream ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s:: " USERSTREAM_CAST " must not return itself " ,
2008-11-15 12:52:13 +00:00
us - > wrapper - > classname ) ;
intstream = NULL ;
break ;
}
ret = php_stream_cast ( intstream , castas , retptr , 1 ) ;
} while ( 0 ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & retval ) ;
2014-02-25 21:00:39 +00:00
zval_ptr_dtor ( & func_name ) ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & args [ 0 ] ) ;
2008-11-15 12:52:13 +00:00
return ret ;
}
2002-03-19 03:51:01 +00:00
php_stream_ops php_stream_userspace_ops = {
php_userstreamop_write , php_userstreamop_read ,
php_userstreamop_close , php_userstreamop_flush ,
2002-03-28 00:49:00 +00:00
" user-space " ,
2002-09-23 01:47:04 +00:00
php_userstreamop_seek ,
2008-11-15 12:52:13 +00:00
php_userstreamop_cast ,
2011-05-25 21:03:55 +00:00
php_userstreamop_stat ,
2004-01-21 10:17:12 +00:00
php_userstreamop_set_option ,
2002-09-28 13:05:47 +00:00
} ;
php_stream_ops php_stream_userspace_dir_ops = {
NULL , /* write */
php_userstreamop_readdir ,
php_userstreamop_closedir ,
NULL , /* flush */
" user-space-dir " ,
php_userstreamop_rewinddir ,
NULL , /* cast */
2002-09-23 01:47:04 +00:00
NULL , /* stat */
NULL /* set_option */
2002-03-19 03:51:01 +00:00
} ;