struct php_user_stream_wrapper {
char * protoname;
- char * classname;
zend_class_entry *ce;
php_stream_wrapper wrapper;
};
struct php_user_stream_wrapper * uwrap = (struct php_user_stream_wrapper*)rsrc->ptr;
efree(uwrap->protoname);
- efree(uwrap->classname);
efree(uwrap);
}
ZVAL_COPY(&stream->wrapperdata, &us->object);
} else {
php_stream_wrapper_log_error(wrapper, options, "\"%s::" USERSTREAM_OPEN "\" call failed",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
}
/* destroy everything else */
ZVAL_COPY(&stream->wrapperdata, &us->object);
} else {
php_stream_wrapper_log_error(wrapper, options, "\"%s::" USERSTREAM_DIR_OPEN "\" call failed",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
}
/* destroy everything else */
/* {{{ Registers a custom URL protocol handler class */
PHP_FUNCTION(stream_wrapper_register)
{
- zend_string *protocol, *classname;
- struct php_user_stream_wrapper * uwrap;
+ zend_string *protocol;
+ struct php_user_stream_wrapper *uwrap;
+ zend_class_entry *ce = NULL;
zend_resource *rsrc;
zend_long flags = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|l", &protocol, &classname, &flags) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "SC|l", &protocol, &ce, &flags) == FAILURE) {
RETURN_THROWS();
}
uwrap = (struct php_user_stream_wrapper *)ecalloc(1, sizeof(*uwrap));
+ uwrap->ce = ce;
uwrap->protoname = estrndup(ZSTR_VAL(protocol), ZSTR_LEN(protocol));
- uwrap->classname = estrndup(ZSTR_VAL(classname), ZSTR_LEN(classname));
uwrap->wrapper.wops = &user_stream_wops;
uwrap->wrapper.abstract = uwrap;
uwrap->wrapper.is_url = ((flags & PHP_STREAM_IS_URL) != 0);
rsrc = zend_register_resource(uwrap, le_protocols);
- if ((uwrap->ce = zend_lookup_class(classname)) != NULL) {
- if (php_register_url_stream_wrapper_volatile(protocol, &uwrap->wrapper) == SUCCESS) {
- RETURN_TRUE;
- } else {
- /* We failed. But why? */
- if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol)) {
- php_error_docref(NULL, E_WARNING, "Protocol %s:// is already defined.", ZSTR_VAL(protocol));
- } else {
- /* Hash doesn't exist so it must have been an invalid protocol scheme */
- php_error_docref(NULL, E_WARNING, "Invalid protocol scheme specified. Unable to register wrapper class %s to %s://", ZSTR_VAL(classname), ZSTR_VAL(protocol));
- }
- }
+ if (php_register_url_stream_wrapper_volatile(protocol, &uwrap->wrapper) == SUCCESS) {
+ RETURN_TRUE;
+ }
+
+ /* We failed. But why? */
+ if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol)) {
+ php_error_docref(NULL, E_WARNING, "Protocol %s:// is already defined.", ZSTR_VAL(protocol));
} else {
- php_error_docref(NULL, E_WARNING, "Class '%s' is undefined", ZSTR_VAL(classname));
+ /* Hash doesn't exist so it must have been an invalid protocol scheme */
+ php_error_docref(NULL, E_WARNING, "Invalid protocol scheme specified. Unable to register wrapper class %s to %s://", ZSTR_VAL(uwrap->ce->name), ZSTR_VAL(protocol));
}
zend_list_delete(rsrc);
}
} else {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_WRITE " is not implemented!",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
didwrite = -1;
}
/* don't allow strange buffer overruns due to bogus return */
if (didwrite > 0 && didwrite > count) {
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)",
- us->wrapper->classname,
+ ZSTR_VAL(us->wrapper->ce->name),
(zend_long)(didwrite - count), (zend_long)didwrite, (zend_long)count);
didwrite = count;
}
if (call_result == FAILURE) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " is not implemented!",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
return -1;
}
if (didread > 0) {
if (didread > count) {
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",
- us->wrapper->classname, (zend_long)(didread - count), (zend_long)didread, (zend_long)count);
+ ZSTR_VAL(us->wrapper->ce->name), (zend_long)(didread - count), (zend_long)didread, (zend_long)count);
didread = count;
}
memcpy(buf, Z_STRVAL(retval), didread);
} else if (call_result == FAILURE) {
php_error_docref(NULL, E_WARNING,
"%s::" USERSTREAM_EOF " is not implemented! Assuming EOF",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
stream->eof = 1;
}
*newoffs = Z_LVAL(retval);
ret = 0;
} else if (call_result == FAILURE) {
- php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_TELL " is not implemented!", us->wrapper->classname);
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_TELL " is not implemented!", ZSTR_VAL(us->wrapper->ce->name));
ret = -1;
} else {
ret = -1;
} else {
if (call_result == FAILURE) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_STAT " is not implemented!",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
}
}
ret = PHP_STREAM_OPTION_RETURN_ERR;
php_error_docref(NULL, E_WARNING,
"%s::" USERSTREAM_EOF " is not implemented! Assuming EOF",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
}
zval_ptr_dtor(&retval);
zval_ptr_dtor(&func_name);
ret = PHP_STREAM_OPTION_RETURN_OK;
} else {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_LOCK " is not implemented!",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
ret = PHP_STREAM_OPTION_RETURN_ERR;
}
}
} else {
php_error_docref(NULL, E_WARNING,
"%s::" USERSTREAM_TRUNCATE " did not return a boolean!",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
}
} else {
php_error_docref(NULL, E_WARNING,
"%s::" USERSTREAM_TRUNCATE " is not implemented!",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
}
zval_ptr_dtor(&retval);
zval_ptr_dtor(&args[0]);
if (call_result == FAILURE) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_SET_OPTION " is not implemented!",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
ret = PHP_STREAM_OPTION_RETURN_ERR;
} else if (zend_is_true(&retval)) {
ret = PHP_STREAM_OPTION_RETURN_OK;
if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) {
ret = (Z_TYPE(zretval) == IS_TRUE);
} else if (call_result == FAILURE) {
- php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_UNLINK " is not implemented!", uwrap->classname);
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_UNLINK " is not implemented!", ZSTR_VAL(uwrap->ce->name));
}
/* clean up */
if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) {
ret = (Z_TYPE(zretval) == IS_TRUE);
} else if (call_result == FAILURE) {
- php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_RENAME " is not implemented!", uwrap->classname);
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_RENAME " is not implemented!", ZSTR_VAL(uwrap->ce->name));
}
/* clean up */
if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) {
ret = (Z_TYPE(zretval) == IS_TRUE);
} else if (call_result == FAILURE) {
- php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_MKDIR " is not implemented!", uwrap->classname);
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_MKDIR " is not implemented!", ZSTR_VAL(uwrap->ce->name));
}
/* clean up */
if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) {
ret = (Z_TYPE(zretval) == IS_TRUE);
} else if (call_result == FAILURE) {
- php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_RMDIR " is not implemented!", uwrap->classname);
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_RMDIR " is not implemented!", ZSTR_VAL(uwrap->ce->name));
}
/* clean up */
if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) {
ret = Z_TYPE(zretval) == IS_TRUE;
} else if (call_result == FAILURE) {
- php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_METADATA " is not implemented!", uwrap->classname);
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_METADATA " is not implemented!", ZSTR_VAL(uwrap->ce->name));
}
/* clean up */
} else {
if (call_result == FAILURE) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_STATURL " is not implemented!",
- uwrap->classname);
+ ZSTR_VAL(uwrap->ce->name));
}
}
didread = sizeof(php_stream_dirent);
} else if (call_result == FAILURE) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_DIR_READ " is not implemented!",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
}
zval_ptr_dtor(&retval);
do {
if (call_result == FAILURE) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " is not implemented!",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
break;
}
if (!zend_is_true(&retval)) {
php_stream_from_zval_no_verify(intstream, &retval);
if (!intstream) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must return a stream resource",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
break;
}
if (intstream == stream) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must not return itself",
- us->wrapper->classname);
+ ZSTR_VAL(us->wrapper->ce->name));
intstream = NULL;
break;
}