}
/* }}} */
-/* {{{ PHP_ZIP_STAT_PATH(za, path, path_len, flags, sb) */
+/* {{{ PHP_ZIP_STAT_PATH(za, path, path_len, flags, sb)
+ This is always used for the first argument*/
#define PHP_ZIP_STAT_PATH(za, path, path_len, flags, sb) \
- if (path_len < 1) { \
- php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); \
- RETURN_FALSE; \
+ if (path_len == 0) { \
+ zend_argument_value_error(1, "cannot be empty"); \
+ RETURN_THROWS(); \
} \
if (zip_stat(za, path, flags, &sb) != 0) { \
RETURN_FALSE; \
#endif
if ((option = zend_hash_str_find(options, "remove_all_path", sizeof("remove_all_path") - 1)) != NULL) {
+ if (Z_TYPE_P(option) != IS_FALSE && Z_TYPE_P(option) != IS_TRUE) {
+ php_error_docref(NULL, E_WARNING, "Option \"remove_all_path\" must be of type bool, %s given",
+ zend_zval_type_name(option));
+ }
opts->remove_all_path = zval_get_long(option);
}
if ((option = zend_hash_str_find(options, "comp_method", sizeof("comp_method") - 1)) != NULL) {
+ if (Z_TYPE_P(option) != IS_LONG) {
+ php_error_docref(NULL, E_WARNING, "Option \"comp_method\" must be of type int, %s given",
+ zend_zval_type_name(option));
+ }
opts->comp_method = zval_get_long(option);
if ((option = zend_hash_str_find(options, "comp_flags", sizeof("comp_flags") - 1)) != NULL) {
+ if (Z_TYPE_P(option) != IS_LONG) {
+ php_error_docref(NULL, E_WARNING, "Option \"comp_flags\" must be of type int, %s given",
+ zend_zval_type_name(option));
+ }
opts->comp_flags = zval_get_long(option);
}
}
#ifdef HAVE_ENCRYPTION
if ((option = zend_hash_str_find(options, "enc_method", sizeof("enc_method") - 1)) != NULL) {
+ if (Z_TYPE_P(option) != IS_LONG) {
+ php_error_docref(NULL, E_WARNING, "Option \"enc_method\" must be of type int, %s given",
+ zend_zval_type_name(option));
+ }
opts->enc_method = zval_get_long(option);
if ((option = zend_hash_str_find(options, "enc_password", sizeof("enc_password") - 1)) != NULL) {
if (Z_TYPE_P(option) != IS_STRING) {
- php_error_docref(NULL, E_WARNING, "enc_password option expected to be a string");
+ zend_type_error("Option \"enc_password\" must be of type string, %s given",
+ zend_zval_type_name(option));
return -1;
}
opts->enc_password = Z_STRVAL_P(option);
if ((option = zend_hash_str_find(options, "remove_path", sizeof("remove_path") - 1)) != NULL) {
if (Z_TYPE_P(option) != IS_STRING) {
- php_error_docref(NULL, E_WARNING, "remove_path option expected to be a string");
+ zend_type_error("Option \"remove_path\" must be of type string, %s given",
+ zend_zval_type_name(option));
return -1;
}
- if (Z_STRLEN_P(option) < 1) {
- php_error_docref(NULL, E_NOTICE, "Empty string given as remove_path option");
+ if (Z_STRLEN_P(option) == 0) {
+ zend_value_error("Option \"remove_path\" cannot be empty");
return -1;
}
if (Z_STRLEN_P(option) >= MAXPATHLEN) {
- php_error_docref(NULL, E_WARNING, "remove_path string is too long (max: %d, %zd given)",
- MAXPATHLEN - 1, Z_STRLEN_P(option));
+ zend_value_error("Option \"remove_path\" must be less than %d bytes", MAXPATHLEN - 1);
return -1;
}
opts->remove_path_len = Z_STRLEN_P(option);
if ((option = zend_hash_str_find(options, "add_path", sizeof("add_path") - 1)) != NULL) {
if (Z_TYPE_P(option) != IS_STRING) {
- php_error_docref(NULL, E_WARNING, "add_path option expected to be a string");
+ zend_type_error("Option \"add_path\" must be of type string, %s given",
+ zend_zval_type_name(option));
return -1;
}
- if (Z_STRLEN_P(option) < 1) {
- php_error_docref(NULL, E_NOTICE, "Empty string given as the add_path option");
+ if (Z_STRLEN_P(option) == 0) {
+ zend_value_error("Option \"add_path\" cannot be empty");
return -1;
}
if (Z_STRLEN_P(option) >= MAXPATHLEN) {
- php_error_docref(NULL, E_WARNING, "add_path string too long (max: %d, %zd given)",
- MAXPATHLEN - 1, Z_STRLEN_P(option));
+ zend_value_error("Option \"add_path\" must be less than %d bytes", MAXPATHLEN - 1);
return -1;
}
opts->add_path_len = Z_STRLEN_P(option);
if ((option = zend_hash_str_find(options, "flags", sizeof("flags") - 1)) != NULL) {
if (Z_TYPE_P(option) != IS_LONG) {
- php_error_docref(NULL, E_WARNING, "flags option expected to be a integer");
+ zend_type_error("Option \"flags\" must be of type int, %s given",
+ zend_zval_type_name(option));
return -1;
}
opts->flags = Z_LVAL_P(option);
}
if ((GLOB_AVAILABLE_FLAGS & flags) != flags) {
+
php_error_docref(NULL, E_WARNING, "At least one of the passed flags is invalid or not supported on this platform");
return -1;
}
}
if (ZSTR_LEN(filename) == 0) {
- php_error_docref(NULL, E_WARNING, "Empty string as source");
- RETURN_FALSE;
+ zend_argument_value_error(1, "cannot be empty");
+ RETURN_THROWS();
}
if (ZIP_OPENBASEDIR_CHECKPATH(ZSTR_VAL(filename))) {
ze_obj = Z_ZIP_P(self);
if (ZSTR_LEN(filename) == 0) {
- php_error_docref(NULL, E_WARNING, "Empty string as source");
- RETURN_FALSE;
+ zend_argument_value_error(1, "cannot be empty");
+ RETURN_THROWS();
}
if (ZIP_OPENBASEDIR_CHECKPATH(ZSTR_VAL(filename))) {
}
if (ZSTR_LEN(pattern) == 0) {
- php_error_docref(NULL, E_NOTICE, "Empty string as pattern");
- RETURN_FALSE;
+ zend_argument_value_error(1, "cannot be empty");
+ RETURN_THROWS();
}
if (options && zend_hash_num_elements(options) > 0 && (php_zip_parse_options(options, &opts) < 0)) {
- RETURN_FALSE;
+ RETURN_THROWS();
}
if (type == 1) {
}
if (ZSTR_LEN(filename) == 0) {
- php_error_docref(NULL, E_NOTICE, "Empty string as filename");
- RETURN_FALSE;
+ zend_argument_value_error(1, "cannot be empty");
+ RETURN_THROWS();
}
if (entry_name_len == 0) {
}
if (ZSTR_LEN(filename) == 0) {
- php_error_docref(NULL, E_NOTICE, "Empty string as filename");
- RETURN_FALSE;
+ zend_argument_value_error(1, "cannot be empty");
+ RETURN_THROWS();
}
if (index < 0) {
- php_error_docref(NULL, E_NOTICE, "Invalid negative index");
- RETURN_FALSE;
+ zend_argument_value_error(2, "must be greater than or equal to 0");
+ RETURN_THROWS();
}
if (php_zip_add_file(Z_ZIP_P(self), ZSTR_VAL(filename), ZSTR_LEN(filename),
ZIP_FROM_OBJECT(intern, self);
if (comment_len > 0xffff) {
- php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes");
- RETURN_FALSE;
+ zend_argument_value_error(1, "must be less than 65535 bytes");
+ RETURN_THROWS();
}
if (zip_set_archive_comment(intern, (const char *)comment, comment_len)) {
RETURN_THROWS();
}
- if (name_len < 1) {
- php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
+ if (name_len == 0) {
+ zend_argument_value_error(1, "cannot be empty");
+ RETURN_THROWS();
}
ZIP_FROM_OBJECT(intern, self);
if (comment_len > 0xffff) {
- php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes");
- RETURN_FALSE;
+ zend_argument_value_error(2, "must be less than 65535 bytes");
+ RETURN_THROWS();
}
idx = zip_name_locate(intern, name, 0);
ZIP_FROM_OBJECT(intern, self);
if (comment_len > 0xffff) {
- php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes");
- RETURN_FALSE;
+ zend_argument_value_error(2, "must be less than 65535 bytes");
+ RETURN_THROWS();
}
PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
ZIP_FROM_OBJECT(intern, self);
- if (name_len < 1) {
- php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
+ if (name_len == 0) {
+ zend_argument_value_error(1, "cannot be empty");
+ RETURN_THROWS();
}
idx = zip_name_locate(intern, name, 0);
+
if (idx < 0) {
RETURN_FALSE;
}
ZIP_FROM_OBJECT(intern, self);
- if (name_len < 1) {
- php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
+ if (name_len == 0) {
+ zend_argument_value_error(1, "cannot be empty");
+ RETURN_THROWS();
}
idx = zip_name_locate(intern, name, 0);
+
if (idx < 0) {
RETURN_FALSE;
}
ZIP_FROM_OBJECT(intern, self);
- if (name_len < 1) {
- php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
+ if (name_len == 0) {
+ zend_argument_value_error(1, "cannot be empty");
+ RETURN_THROWS();
}
idx = zip_name_locate(intern, name, 0);
+
if (idx < 0) {
RETURN_FALSE;
}
ZIP_FROM_OBJECT(intern, self);
- if (name_len < 1) {
- php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
- RETURN_FALSE;
+ if (name_len == 0) {
+ zend_argument_value_error(1, "cannot be empty");
+ RETURN_THROWS();
}
idx = zip_name_locate(intern, name, 0);
+
if (idx < 0) {
RETURN_FALSE;
}
/* {{{ Set the compression of a file in zip, using its name */
PHP_METHOD(ZipArchive, setCompressionName)
- {
+{
struct zip *intern;
zval *this = ZEND_THIS;
size_t name_len;
ZIP_FROM_OBJECT(intern, this);
- if (name_len < 1) {
- php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
+ if (name_len == 0) {
+ zend_argument_value_error(1, "cannot be empty");
+ RETURN_THROWS();
}
idx = zip_name_locate(intern, name, 0);
+
if (idx < 0) {
RETURN_FALSE;
}
#ifdef HAVE_SET_MTIME
/* {{{ Set the modification time of a file in zip, using its name */
PHP_METHOD(ZipArchive, setMtimeName)
- {
+{
struct zip *intern;
zval *this = ZEND_THIS;
size_t name_len;
ZIP_FROM_OBJECT(intern, this);
- if (name_len < 1) {
- php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
+ if (name_len == 0) {
+ zend_argument_value_error(1, "cannot be empty");
+ RETURN_THROWS();
}
idx = zip_name_locate(intern, name, 0);
+
if (idx < 0) {
RETURN_FALSE;
}
ZIP_FROM_OBJECT(intern, self);
- if (new_name_len < 1) {
- php_error_docref(NULL, E_NOTICE, "Empty string as new entry name");
- RETURN_FALSE;
+ if (new_name_len == 0) {
+ zend_argument_value_error(2, "cannot be empty");
+ RETURN_THROWS();
}
if (zip_file_rename(intern, index, (const char *)new_name, 0) != 0) {
ZIP_FROM_OBJECT(intern, self);
- if (new_name_len < 1) {
- php_error_docref(NULL, E_NOTICE, "Empty string as new entry name");
- RETURN_FALSE;
+ if (new_name_len == 0) {
+ zend_argument_value_error(2, "cannot be empty");
+ RETURN_THROWS();
}
PHP_ZIP_STAT_PATH(intern, name, name_len, 0, sb);
struct zip *intern;
zval *self = ZEND_THIS;
double rate;
- zval *callback;
+ zend_fcall_info fci;
+ zend_fcall_info_cache fcc;
ze_zip_object *obj;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "dz", &rate, &callback) == FAILURE) {
- return;
- }
-
- /* callable? */
- if (!zend_is_callable(callback, 0, NULL)) {
- zend_string *callback_name = zend_get_callable_name(callback);
- php_error_docref(NULL, E_WARNING, "Invalid callback '%s'", ZSTR_VAL(callback_name));
- zend_string_release_ex(callback_name, 0);
- RETURN_FALSE;
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "df", &rate, &fci, &fcc) == FAILURE) {
+ RETURN_THROWS();
}
ZIP_FROM_OBJECT(intern, self);
_php_zip_progress_callback_free(obj);
/* register */
- ZVAL_COPY(&obj->progress_callback, callback);
+ ZVAL_COPY(&obj->progress_callback, &fci.function_name);
if (zip_register_progress_callback_with_state(intern, rate, _php_zip_progress_callback, _php_zip_progress_callback_free, obj)) {
RETURN_FALSE;
}
{
struct zip *intern;
zval *self = ZEND_THIS;
- zval *callback;
+ zend_fcall_info fci;
+ zend_fcall_info_cache fcc;
ze_zip_object *obj;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &callback) == FAILURE) {
- return;
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "f", &fci, &fcc) == FAILURE) {
+ RETURN_THROWS();
}
ZIP_FROM_OBJECT(intern, self);
- /* callable? */
- if (!zend_is_callable(callback, 0, NULL)) {
- zend_string *callback_name = zend_get_callable_name(callback);
- php_error_docref(NULL, E_WARNING, "Invalid callback '%s'", ZSTR_VAL(callback_name));
- zend_string_release_ex(callback_name, 0);
- RETURN_FALSE;
- }
-
obj = Z_ZIP_P(self);
/* free if called twice */
_php_zip_cancel_callback_free(obj);
/* register */
- ZVAL_COPY(&obj->cancel_callback, callback);
+ ZVAL_COPY(&obj->cancel_callback, &fci.function_name);
if (zip_register_cancel_callback_with_state(intern, _php_zip_cancel_callback, _php_zip_cancel_callback_free, obj)) {
RETURN_FALSE;
}