summaryrefslogtreecommitdiff
path: root/ext/zip
diff options
context:
space:
mode:
authorRemi Collet <remi@remirepo.net>2020-04-02 14:40:05 +0200
committerRemi Collet <remi@php.net>2020-04-02 14:52:05 +0200
commit2dc8d39bae47fc2cb44125514a8a4e81e9a8dd24 (patch)
tree9f877f81ed444db748ec6e41aaac441ecb0e99f6 /ext/zip
parent6983ae751cd301886c966b84367fc7aaa1273b2d (diff)
downloadphp-git-2dc8d39bae47fc2cb44125514a8a4e81e9a8dd24.tar.gz
- 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
Diffstat (limited to 'ext/zip')
-rw-r--r--ext/zip/config.m48
-rw-r--r--ext/zip/php_zip.c58
-rw-r--r--ext/zip/php_zip.stub.php8
-rw-r--r--ext/zip/php_zip_arginfo.h11
-rw-r--r--ext/zip/tests/oo_supported.phpt65
5 files changed, 141 insertions, 9 deletions
diff --git a/ext/zip/config.m4 b/ext/zip/config.m4
index abd84ff51d..308020af63 100644
--- a/ext/zip/config.m4
+++ b/ext/zip/config.m4
@@ -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"
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c
index 02e64f64ae..3b9b07097e 100644
--- a/ext/zip/php_zip.c
+++ b/ext/zip/php_zip.c
@@ -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();
}
diff --git a/ext/zip/php_zip.stub.php b/ext/zip/php_zip.stub.php
index 1e3ceb6d07..101afcbe8e 100644
--- a/ext/zip/php_zip.stub.php
+++ b/ext/zip/php_zip.stub.php
@@ -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
}
diff --git a/ext/zip/php_zip_arginfo.h b/ext/zip/php_zip_arginfo.h
index a90b768171..ffb3983527 100644
--- a/ext/zip/php_zip_arginfo.h
+++ b/ext/zip/php_zip_arginfo.h
@@ -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
diff --git a/ext/zip/tests/oo_supported.phpt b/ext/zip/tests/oo_supported.phpt
new file mode 100644
index 0000000000..02b169bff7
--- /dev/null
+++ b/ext/zip/tests/oo_supported.phpt
@@ -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