mirror of
https://github.com/php/php-src.git
synced 2026-04-29 03:03:26 +02:00
- add ZipArchive::EM_UNKNOWN constant - add ZipArchive::EM_TRAD_PKWARE constant - cleanup hack for libzip 1.3.1 (have only exist for a few days) - add ZipArchive::isCompressionMethodSupported() method (libzip 1.7.0) - add ZipArchive::isEncryptionMethodSupported() method (libzip 1.7.0) - bump version to 1.19.0-dev
This commit is contained in:
@@ -51,6 +51,14 @@ if test "$PHP_ZIP" != "no"; then
|
||||
$LIBZIP_LIBS
|
||||
])
|
||||
|
||||
PHP_CHECK_LIBRARY(zip, zip_compression_method_supported,
|
||||
[
|
||||
AC_DEFINE(HAVE_METHOD_SUPPORTED, 1, [Libzip >= 1.7.0 with zip_*_method_supported functions])
|
||||
], [
|
||||
], [
|
||||
$LIBZIP_LIBS
|
||||
])
|
||||
|
||||
AC_DEFINE(HAVE_ZIP,1,[ ])
|
||||
|
||||
PHP_ZIP_SOURCES="php_zip.c zip_stream.c"
|
||||
|
||||
+49
-9
@@ -1039,12 +1039,8 @@ static void php_zip_object_free_storage(zend_object *object) /* {{{ */
|
||||
}
|
||||
if (intern->za) {
|
||||
if (zip_close(intern->za) != 0) {
|
||||
#if LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR == 3 && LIBZIP_VERSION_MICRO == 1
|
||||
php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: zip_close have failed");
|
||||
#else
|
||||
php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: %s", zip_strerror(intern->za));
|
||||
zip_discard(intern->za);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1561,9 +1557,6 @@ static ZIPARCHIVE_METHOD(close)
|
||||
|
||||
err = zip_close(intern);
|
||||
if (err) {
|
||||
#if LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR == 3 && LIBZIP_VERSION_MICRO == 1
|
||||
php_error_docref(NULL, E_WARNING, "zip_close have failed");
|
||||
#else
|
||||
php_error_docref(NULL, E_WARNING, "%s", zip_strerror(intern));
|
||||
/* Save error for property reader */
|
||||
#if LIBZIP_VERSION_MAJOR < 1
|
||||
@@ -1579,7 +1572,6 @@ static ZIPARCHIVE_METHOD(close)
|
||||
}
|
||||
#endif
|
||||
zip_discard(intern);
|
||||
#endif
|
||||
} else {
|
||||
ze_obj->err_zip = 0;
|
||||
ze_obj->err_sys = 0;
|
||||
@@ -3064,6 +3056,36 @@ static ZIPARCHIVE_METHOD(registerCancelCallback)
|
||||
/* }}} */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_METHOD_SUPPORTED
|
||||
/* {{{ proto bool ZipArchive::isCompressionMethodSupported(int method, bool enc)
|
||||
check if a compression method is available in used libzip */
|
||||
static ZIPARCHIVE_METHOD(isCompressionMethodSupported)
|
||||
{
|
||||
zend_long method;
|
||||
zend_bool enc = 1;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|b", &method, &enc) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
RETVAL_BOOL(zip_compression_method_supported((zip_int32_t)method, enc));
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool ZipArchive::isEncryptionMethodSupported(int method, bool enc)
|
||||
check if a encryption method is available in used libzip */
|
||||
static ZIPARCHIVE_METHOD(isEncryptionMethodSupported)
|
||||
{
|
||||
zend_long method;
|
||||
zend_bool enc = 1;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|b", &method, &enc) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
RETVAL_BOOL(zip_encryption_method_supported((zip_uint16_t)method, enc));
|
||||
}
|
||||
/* }}} */
|
||||
#endif
|
||||
|
||||
/* {{{ ze_zip_object_class_functions */
|
||||
static const zend_function_entry zip_class_functions[] = {
|
||||
ZIPARCHIVE_ME(open, arginfo_class_ZipArchive_open, ZEND_ACC_PUBLIC)
|
||||
@@ -3121,6 +3143,10 @@ static const zend_function_entry zip_class_functions[] = {
|
||||
#ifdef HAVE_CANCEL_CALLBACK
|
||||
ZIPARCHIVE_ME(registerCancelCallback, arginfo_class_ZipArchive_registerCancelCallback, ZEND_ACC_PUBLIC)
|
||||
#endif
|
||||
#ifdef HAVE_METHOD_SUPPORTED
|
||||
ZIPARCHIVE_ME(isCompressionMethodSupported, arginfo_class_ZipArchive_isCompressionMethodSupported, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
|
||||
ZIPARCHIVE_ME(isEncryptionMethodSupported, arginfo_class_ZipArchive_isEncryptionMethodSupported, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
|
||||
#endif
|
||||
|
||||
PHP_FE_END
|
||||
};
|
||||
@@ -3280,12 +3306,14 @@ static PHP_MINIT_FUNCTION(zip)
|
||||
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_DEFAULT", ZIP_OPSYS_DEFAULT);
|
||||
#endif /* ifdef ZIP_OPSYS_DEFAULT */
|
||||
|
||||
#ifdef HAVE_ENCRYPTION
|
||||
REGISTER_ZIP_CLASS_CONST_LONG("EM_NONE", ZIP_EM_NONE);
|
||||
REGISTER_ZIP_CLASS_CONST_LONG("EM_TRAD_PKWARE", ZIP_EM_TRAD_PKWARE);
|
||||
#ifdef HAVE_ENCRYPTION
|
||||
REGISTER_ZIP_CLASS_CONST_LONG("EM_AES_128", ZIP_EM_AES_128);
|
||||
REGISTER_ZIP_CLASS_CONST_LONG("EM_AES_192", ZIP_EM_AES_192);
|
||||
REGISTER_ZIP_CLASS_CONST_LONG("EM_AES_256", ZIP_EM_AES_256);
|
||||
#endif
|
||||
REGISTER_ZIP_CLASS_CONST_LONG("EM_UNKNOWN", ZIP_EM_UNKNOWN);
|
||||
|
||||
#if HAVE_LIBZIP_VERSION
|
||||
zend_declare_class_constant_string(zip_class_entry, "LIBZIP_VERSION", sizeof("LIBZIP_VERSION")-1, zip_libzip_version());
|
||||
@@ -3326,6 +3354,18 @@ static PHP_MINFO_FUNCTION(zip)
|
||||
#else
|
||||
php_info_print_table_row(2, "Libzip version", LIBZIP_VERSION);
|
||||
#endif
|
||||
#ifdef HAVE_METHOD_SUPPORTED
|
||||
php_info_print_table_row(2, "BZIP2 compression",
|
||||
zip_compression_method_supported(ZIP_CM_BZIP2, 1) ? "Yes" : "No");
|
||||
php_info_print_table_row(2, "XZ compression",
|
||||
zip_compression_method_supported(ZIP_CM_XZ, 1) ? "Yes" : "No");
|
||||
php_info_print_table_row(2, "AES-128 encryption",
|
||||
zip_encryption_method_supported(ZIP_EM_AES_128, 1) ? "Yes" : "No");
|
||||
php_info_print_table_row(2, "AES-192 encryption",
|
||||
zip_encryption_method_supported(ZIP_EM_AES_128, 1) ? "Yes" : "No");
|
||||
php_info_print_table_row(2, "AES-256 encryption",
|
||||
zip_encryption_method_supported(ZIP_EM_AES_128, 1) ? "Yes" : "No");
|
||||
#endif
|
||||
|
||||
php_info_print_table_end();
|
||||
}
|
||||
|
||||
@@ -186,4 +186,12 @@ class ZipArchive
|
||||
/** @return bool */
|
||||
public function registerCancelCallback(callable $callback) {}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_METHOD_SUPPORTED
|
||||
/** @return bool */
|
||||
public static function isCompressionMethodSupported(int $method, bool $enc): bool {}
|
||||
|
||||
/** @return bool */
|
||||
public static function isEncryptionMethodSupported(int $method, bool $enc): bool {}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -269,3 +269,14 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_registerCancelCallback, 0, 0, 1)
|
||||
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_METHOD_SUPPORTED)
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ZipArchive_isCompressionMethodSupported, 0, 2, _IS_BOOL, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, method, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, enc, _IS_BOOL, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_METHOD_SUPPORTED)
|
||||
#define arginfo_class_ZipArchive_isEncryptionMethodSupported arginfo_class_ZipArchive_isCompressionMethodSupported
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
--TEST--
|
||||
ziparchive::properties isset()/empty() checks
|
||||
--SKIPIF--
|
||||
<?php
|
||||
/* $Id$ */
|
||||
if(!extension_loaded('zip')) die('skip');
|
||||
if (!method_exists('ZipArchive', 'isCompressionMethodSupported')) die('skip needs libzip >= 1.7');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
$methods = [
|
||||
ZipArchive::CM_STORE => "STORE",
|
||||
ZipArchive::CM_DEFLATE => "DEFLATE",
|
||||
ZipArchive::CM_BZIP2 => "BZIP2",
|
||||
ZipArchive::CM_XZ => "XZ",
|
||||
];
|
||||
foreach($methods as $method => $name) {
|
||||
echo "Compression $name\n";
|
||||
var_dump(ZipArchive::isCompressionMethodSupported($method));
|
||||
var_dump(ZipArchive::isCompressionMethodSupported($method, false));
|
||||
}
|
||||
|
||||
$methods = [
|
||||
ZipArchive::EM_NONE => "NONE",
|
||||
ZipArchive::EM_TRAD_PKWARE => "TRAD_PKWARE",
|
||||
ZipArchive::EM_AES_128 => "AES-128",
|
||||
ZipArchive::EM_AES_192 => "AES-192",
|
||||
ZipArchive::EM_AES_256 => "AES-256",
|
||||
];
|
||||
foreach($methods as $method => $name) {
|
||||
echo "Encryption $name\n";
|
||||
var_dump(ZipArchive::isEncryptionMethodSupported($method));
|
||||
var_dump(ZipArchive::isEncryptionMethodSupported($method, false));
|
||||
}
|
||||
?>
|
||||
Done
|
||||
--EXPECTF--
|
||||
Compression STORE
|
||||
bool(true)
|
||||
bool(true)
|
||||
Compression DEFLATE
|
||||
bool(true)
|
||||
bool(true)
|
||||
Compression BZIP2
|
||||
bool(%s)
|
||||
bool(%s)
|
||||
Compression XZ
|
||||
bool(%s)
|
||||
bool(%s)
|
||||
Encryption NONE
|
||||
bool(true)
|
||||
bool(true)
|
||||
Encryption TRAD_PKWARE
|
||||
bool(true)
|
||||
bool(true)
|
||||
Encryption AES-128
|
||||
bool(%s)
|
||||
bool(%s)
|
||||
Encryption AES-192
|
||||
bool(%s)
|
||||
bool(%s)
|
||||
Encryption AES-256
|
||||
bool(%s)
|
||||
bool(%s)
|
||||
Done
|
||||
Reference in New Issue
Block a user