cvs: php4 /main/streams userspace.c

From: Date: Wed, 14 May 2003 18:30:49 +0000
Subject: cvs: php4 /main/streams userspace.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-20912@lists.php.net to get a copy of this message
pollita Wed May 14 14:30:49 2003 EDT Modified files: /php4/main/streams userspace.c Log: Implement userspace wrapper support for unlink method Index: php4/main/streams/userspace.c diff -u php4/main/streams/userspace.c:1.3 php4/main/streams/userspace.c:1.4 --- php4/main/streams/userspace.c:1.3 Wed May 14 02:10:04 2003 +++ php4/main/streams/userspace.c Wed May 14 14:30:49 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: userspace.c,v 1.3 2003/05/14 06:10:04 pollita Exp $ */ +/* $Id: userspace.c,v 1.4 2003/05/14 18:30:49 pollita Exp $ */ #include "php.h" #include "php_globals.h" @@ -33,6 +33,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, php_stream_statbuf *ssb TSRMLS_DC); +static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC); static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); @@ -43,7 +44,7 @@ user_wrapper_stat_url, user_wrapper_opendir, "user-space", - NULL /* unlink */ + user_wrapper_unlink }; @@ -90,6 +91,7 @@ #define USERSTREAM_EOF "stream_eof" #define USERSTREAM_STAT "stream_stat" #define USERSTREAM_STATURL "url_stat" +#define USERSTREAM_UNLINK "unlink" #define USERSTREAM_DIR_OPEN "dir_opendir" #define USERSTREAM_DIR_READ "dir_readdir" #define USERSTREAM_DIR_REWIND "dir_rewinddir" @@ -148,6 +150,11 @@ return array( just like that returned by stat() ); } + function unlink(string $url) + { + return true / false; + } + function dir_opendir(string $url, int $options) { return true / false; @@ -695,6 +702,53 @@ if (retval) zval_ptr_dtor(&retval); + return ret; +} + +static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) +{ + struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; + zval *zfilename, *zfuncname, *zretval; + zval **args[1]; + int call_result; + zval *object; + int ret = 0; + + /* create an instance of our class */ + ALLOC_ZVAL(object); + object_init_ex(object, uwrap->ce); + ZVAL_REFCOUNT(object) = 1; + PZVAL_IS_REF(object) = 1; + + /* call the unlink method */ + MAKE_STD_ZVAL(zfilename); + ZVAL_STRING(zfilename, url, 1); + args[0] = &zfilename; + + MAKE_STD_ZVAL(zfuncname); + ZVAL_STRING(zfuncname, USERSTREAM_UNLINK, 1); + + call_result = call_user_function_ex(NULL, + &object, + zfuncname, + &zretval, + 1, args, + 0, NULL TSRMLS_CC); + + if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { + ret = Z_LVAL_P(zretval); + } else if (call_result == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_UNLINK " is not implemented!", uwrap->classname); + } + + /* clean up */ + zval_ptr_dtor(&object); + if (zretval) + zval_ptr_dtor(&zretval); + + zval_ptr_dtor(&zfuncname); + zval_ptr_dtor(&zfilename); + return ret; }

« previous php.cvs (#20912) next »