summaryrefslogtreecommitdiff
path: root/ext/zip/php_zip.c
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/php_zip.c
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/php_zip.c')
-rw-r--r--ext/zip/php_zip.c58
1 files changed, 49 insertions, 9 deletions
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();
}