@@ -1039,12 +1039,8 @@ static void php_zip_object_free_storage(zend_object *object) /* {{{ */
1039
1039
}
1040
1040
if (intern -> za ) {
1041
1041
if (zip_close (intern -> za ) != 0 ) {
1042
- #if LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR == 3 && LIBZIP_VERSION_MICRO == 1
1043
- php_error_docref (NULL , E_WARNING , "Cannot destroy the zip context: zip_close have failed" );
1044
- #else
1045
1042
php_error_docref (NULL , E_WARNING , "Cannot destroy the zip context: %s" , zip_strerror (intern -> za ));
1046
1043
zip_discard (intern -> za );
1047
- #endif
1048
1044
}
1049
1045
}
1050
1046
@@ -1561,9 +1557,6 @@ static ZIPARCHIVE_METHOD(close)
1561
1557
1562
1558
err = zip_close (intern );
1563
1559
if (err ) {
1564
- #if LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR == 3 && LIBZIP_VERSION_MICRO == 1
1565
- php_error_docref (NULL , E_WARNING , "zip_close have failed" );
1566
- #else
1567
1560
php_error_docref (NULL , E_WARNING , "%s" , zip_strerror (intern ));
1568
1561
/* Save error for property reader */
1569
1562
#if LIBZIP_VERSION_MAJOR < 1
@@ -1579,7 +1572,6 @@ static ZIPARCHIVE_METHOD(close)
1579
1572
}
1580
1573
#endif
1581
1574
zip_discard (intern );
1582
- #endif
1583
1575
} else {
1584
1576
ze_obj -> err_zip = 0 ;
1585
1577
ze_obj -> err_sys = 0 ;
@@ -3064,6 +3056,36 @@ static ZIPARCHIVE_METHOD(registerCancelCallback)
3064
3056
/* }}} */
3065
3057
#endif
3066
3058
3059
+ #ifdef HAVE_METHOD_SUPPORTED
3060
+ /* {{{ proto bool ZipArchive::isCompressionMethodSupported(int method, bool enc)
3061
+ check if a compression method is available in used libzip */
3062
+ static ZIPARCHIVE_METHOD (isCompressionMethodSupported )
3063
+ {
3064
+ zend_long method ;
3065
+ zend_bool enc = 1 ;
3066
+
3067
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "l|b" , & method , & enc ) == FAILURE ) {
3068
+ return ;
3069
+ }
3070
+ RETVAL_BOOL (zip_compression_method_supported ((zip_int32_t )method , enc ));
3071
+ }
3072
+ /* }}} */
3073
+
3074
+ /* {{{ proto bool ZipArchive::isEncryptionMethodSupported(int method, bool enc)
3075
+ check if a encryption method is available in used libzip */
3076
+ static ZIPARCHIVE_METHOD (isEncryptionMethodSupported )
3077
+ {
3078
+ zend_long method ;
3079
+ zend_bool enc = 1 ;
3080
+
3081
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "l|b" , & method , & enc ) == FAILURE ) {
3082
+ return ;
3083
+ }
3084
+ RETVAL_BOOL (zip_encryption_method_supported ((zip_uint16_t )method , enc ));
3085
+ }
3086
+ /* }}} */
3087
+ #endif
3088
+
3067
3089
/* {{{ ze_zip_object_class_functions */
3068
3090
static const zend_function_entry zip_class_functions [] = {
3069
3091
ZIPARCHIVE_ME (open , arginfo_class_ZipArchive_open , ZEND_ACC_PUBLIC )
@@ -3121,6 +3143,10 @@ static const zend_function_entry zip_class_functions[] = {
3121
3143
#ifdef HAVE_CANCEL_CALLBACK
3122
3144
ZIPARCHIVE_ME (registerCancelCallback , arginfo_class_ZipArchive_registerCancelCallback , ZEND_ACC_PUBLIC )
3123
3145
#endif
3146
+ #ifdef HAVE_METHOD_SUPPORTED
3147
+ ZIPARCHIVE_ME (isCompressionMethodSupported , arginfo_class_ZipArchive_isCompressionMethodSupported , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC )
3148
+ ZIPARCHIVE_ME (isEncryptionMethodSupported , arginfo_class_ZipArchive_isEncryptionMethodSupported , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC )
3149
+ #endif
3124
3150
3125
3151
PHP_FE_END
3126
3152
};
@@ -3280,12 +3306,14 @@ static PHP_MINIT_FUNCTION(zip)
3280
3306
REGISTER_ZIP_CLASS_CONST_LONG ("OPSYS_DEFAULT" , ZIP_OPSYS_DEFAULT );
3281
3307
#endif /* ifdef ZIP_OPSYS_DEFAULT */
3282
3308
3283
- #ifdef HAVE_ENCRYPTION
3284
3309
REGISTER_ZIP_CLASS_CONST_LONG ("EM_NONE" , ZIP_EM_NONE );
3310
+ REGISTER_ZIP_CLASS_CONST_LONG ("EM_TRAD_PKWARE" , ZIP_EM_TRAD_PKWARE );
3311
+ #ifdef HAVE_ENCRYPTION
3285
3312
REGISTER_ZIP_CLASS_CONST_LONG ("EM_AES_128" , ZIP_EM_AES_128 );
3286
3313
REGISTER_ZIP_CLASS_CONST_LONG ("EM_AES_192" , ZIP_EM_AES_192 );
3287
3314
REGISTER_ZIP_CLASS_CONST_LONG ("EM_AES_256" , ZIP_EM_AES_256 );
3288
3315
#endif
3316
+ REGISTER_ZIP_CLASS_CONST_LONG ("EM_UNKNOWN" , ZIP_EM_UNKNOWN );
3289
3317
3290
3318
#if HAVE_LIBZIP_VERSION
3291
3319
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)
3326
3354
#else
3327
3355
php_info_print_table_row (2 , "Libzip version" , LIBZIP_VERSION );
3328
3356
#endif
3357
+ #ifdef HAVE_METHOD_SUPPORTED
3358
+ php_info_print_table_row (2 , "BZIP2 compression" ,
3359
+ zip_compression_method_supported (ZIP_CM_BZIP2 , 1 ) ? "Yes" : "No" );
3360
+ php_info_print_table_row (2 , "XZ compression" ,
3361
+ zip_compression_method_supported (ZIP_CM_XZ , 1 ) ? "Yes" : "No" );
3362
+ php_info_print_table_row (2 , "AES-128 encryption" ,
3363
+ zip_encryption_method_supported (ZIP_EM_AES_128 , 1 ) ? "Yes" : "No" );
3364
+ php_info_print_table_row (2 , "AES-192 encryption" ,
3365
+ zip_encryption_method_supported (ZIP_EM_AES_128 , 1 ) ? "Yes" : "No" );
3366
+ php_info_print_table_row (2 , "AES-256 encryption" ,
3367
+ zip_encryption_method_supported (ZIP_EM_AES_128 , 1 ) ? "Yes" : "No" );
3368
+ #endif
3329
3369
3330
3370
php_info_print_table_end ();
3331
3371
}
0 commit comments