Browse Source

Implement userspace wrapper support for unlink method

migration/unlabaled-1.3.2
Sara Golemon 23 years ago
parent
commit
44743cf9ec
  1. 56
      main/streams/userspace.c

56
main/streams/userspace.c

@ -33,6 +33,7 @@ struct php_user_stream_wrapper {
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 @@ static php_stream_wrapper_ops user_stream_wops = {
user_wrapper_stat_url,
user_wrapper_opendir,
"user-space",
NULL /* unlink */
user_wrapper_unlink
};
@ -90,6 +91,7 @@ typedef struct _php_userstream_data php_userstream_data_t;
#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 @@ typedef struct _php_userstream_data php_userstream_data_t;
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;
@ -698,6 +705,53 @@ static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb TSR
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;
}
static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, php_stream_statbuf *ssb TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;

Loading…
Cancel
Save