@@ -379,6 +379,7 @@ static int php_zip_parse_options(zval *options, zend_long *remove_all_path, char
379
379
/* }}} */
380
380
381
381
/* {{{ RETURN_SB(sb) */
382
+ #ifdef HAVE_ENCRYPTION
382
383
#define RETURN_SB (sb ) \
383
384
{ \
384
385
array_init(return_value); \
@@ -389,7 +390,21 @@ static int php_zip_parse_options(zval *options, zend_long *remove_all_path, char
389
390
add_ascii_assoc_long(return_value, "mtime", (zend_long) (sb)->mtime); \
390
391
add_ascii_assoc_long(return_value, "comp_size", (zend_long) (sb)->comp_size); \
391
392
add_ascii_assoc_long(return_value, "comp_method", (zend_long) (sb)->comp_method); \
393
+ add_ascii_assoc_long(return_value, "encryption_method", (zend_long) (sb)->encryption_method); \
392
394
}
395
+ #else
396
+ #define RETURN_SB (sb ) \
397
+ { \
398
+ array_init(return_value); \
399
+ add_ascii_assoc_string(return_value, "name", (char *)(sb)->name); \
400
+ add_ascii_assoc_long(return_value, "index", (zend_long) (sb)->index); \
401
+ add_ascii_assoc_long(return_value, "crc", (zend_long) (sb)->crc); \
402
+ add_ascii_assoc_long(return_value, "size", (zend_long) (sb)->size); \
403
+ add_ascii_assoc_long(return_value, "mtime", (zend_long) (sb)->mtime); \
404
+ add_ascii_assoc_long(return_value, "comp_size", (zend_long) (sb)->comp_size); \
405
+ add_ascii_assoc_long(return_value, "comp_method", (zend_long) (sb)->comp_method); \
406
+ }
407
+ #endif
393
408
/* }}} */
394
409
395
410
static int php_zip_status (struct zip * za ) /* {{{ */
@@ -2222,6 +2237,74 @@ static ZIPARCHIVE_METHOD(getExternalAttributesIndex)
2222
2237
/* }}} */
2223
2238
#endif /* ifdef ZIP_OPSYS_DEFAULT */
2224
2239
2240
+ #ifdef HAVE_ENCRYPTION
2241
+ /* {{{ proto bool ZipArchive::setEncryptionName(string name, int method, [string password])
2242
+ Set encryption method for file in zip, using its name */
2243
+ static ZIPARCHIVE_METHOD (setEncryptionName )
2244
+ {
2245
+ struct zip * intern ;
2246
+ zval * self = getThis ();
2247
+ zend_long method ;
2248
+ zip_int64_t idx ;
2249
+ char * name , * password = NULL ;
2250
+ size_t name_len , password_len ;
2251
+
2252
+ if (!self ) {
2253
+ RETURN_FALSE ;
2254
+ }
2255
+
2256
+ ZIP_FROM_OBJECT (intern , self );
2257
+
2258
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "sl|s" ,
2259
+ & name , & name_len , & method , & password , & password_len ) == FAILURE ) {
2260
+ return ;
2261
+ }
2262
+
2263
+ if (name_len < 1 ) {
2264
+ php_error_docref (NULL , E_NOTICE , "Empty string as entry name" );
2265
+ }
2266
+
2267
+ idx = zip_name_locate (intern , name , 0 );
2268
+ if (idx < 0 ) {
2269
+ RETURN_FALSE ;
2270
+ }
2271
+
2272
+ if (zip_file_set_encryption (intern , idx , (zip_uint16_t )method , password )) {
2273
+ RETURN_FALSE ;
2274
+ }
2275
+ RETURN_TRUE ;
2276
+ }
2277
+ /* }}} */
2278
+
2279
+ /* {{{ proto bool ZipArchive::setEncryptionIndex(int index, int method, [string password])
2280
+ Set encryption method for file in zip, using its index */
2281
+ static ZIPARCHIVE_METHOD (setEncryptionIndex )
2282
+ {
2283
+ struct zip * intern ;
2284
+ zval * self = getThis ();
2285
+ zend_long index , method ;
2286
+ char * password = NULL ;
2287
+ size_t password_len ;
2288
+
2289
+ if (!self ) {
2290
+ RETURN_FALSE ;
2291
+ }
2292
+
2293
+ ZIP_FROM_OBJECT (intern , self );
2294
+
2295
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "ll|s" ,
2296
+ & index , & method , & password , & password_len ) == FAILURE ) {
2297
+ return ;
2298
+ }
2299
+
2300
+ if (zip_file_set_encryption (intern , index , (zip_uint16_t )method , password )) {
2301
+ RETURN_FALSE ;
2302
+ }
2303
+ RETURN_TRUE ;
2304
+ }
2305
+ /* }}} */
2306
+ #endif
2307
+
2225
2308
/* {{{ proto string ZipArchive::getCommentName(string name[, int flags])
2226
2309
Returns the comment of an entry using its name */
2227
2310
static ZIPARCHIVE_METHOD (getCommentName )
@@ -2952,6 +3035,20 @@ ZEND_END_ARG_INFO()
2952
3035
#endif /* ifdef ZIP_OPSYS_DEFAULT */
2953
3036
/* }}} */
2954
3037
3038
+ #ifdef HAVE_ENCRYPTION
3039
+ ZEND_BEGIN_ARG_INFO_EX (arginfo_ziparchive_setencryption_name , 0 , 0 , 2 )
3040
+ ZEND_ARG_INFO (0 , name )
3041
+ ZEND_ARG_INFO (0 , method )
3042
+ ZEND_ARG_INFO (0 , password )
3043
+ ZEND_END_ARG_INFO ()
3044
+
3045
+ ZEND_BEGIN_ARG_INFO_EX (arginfo_ziparchive_setencryption_index , 0 , 0 , 2 )
3046
+ ZEND_ARG_INFO (0 , index )
3047
+ ZEND_ARG_INFO (0 , method )
3048
+ ZEND_ARG_INFO (0 , password )
3049
+ ZEND_END_ARG_INFO ()
3050
+ #endif
3051
+
2955
3052
ZEND_BEGIN_ARG_INFO_EX (arginfo_ziparchive_setcompname , 0 , 0 , 2 )
2956
3053
ZEND_ARG_INFO (0 , name )
2957
3054
ZEND_ARG_INFO (0 , method )
@@ -3003,6 +3100,10 @@ static const zend_function_entry zip_class_functions[] = {
3003
3100
ZIPARCHIVE_ME (getExternalAttributesIndex , arginfo_ziparchive_getextattrindex , ZEND_ACC_PUBLIC )
3004
3101
ZIPARCHIVE_ME (setCompressionName , arginfo_ziparchive_setcompname , ZEND_ACC_PUBLIC )
3005
3102
ZIPARCHIVE_ME (setCompressionIndex , arginfo_ziparchive_setcompindex , ZEND_ACC_PUBLIC )
3103
+ #ifdef HAVE_ENCRYPTION
3104
+ ZIPARCHIVE_ME (setEncryptionName , arginfo_ziparchive_setencryption_name , ZEND_ACC_PUBLIC )
3105
+ ZIPARCHIVE_ME (setEncryptionIndex , arginfo_ziparchive_setencryption_index , ZEND_ACC_PUBLIC )
3106
+ #endif
3006
3107
PHP_FE_END
3007
3108
};
3008
3109
/* }}} */
@@ -3047,6 +3148,7 @@ static PHP_MINIT_FUNCTION(zip)
3047
3148
REGISTER_ZIP_CLASS_CONST_LONG ("FL_NODIR" , ZIP_FL_NODIR );
3048
3149
REGISTER_ZIP_CLASS_CONST_LONG ("FL_COMPRESSED" , ZIP_FL_COMPRESSED );
3049
3150
REGISTER_ZIP_CLASS_CONST_LONG ("FL_UNCHANGED" , ZIP_FL_UNCHANGED );
3151
+
3050
3152
#ifdef ZIP_FL_ENC_GUESS
3051
3153
/* Default filename encoding policy. */
3052
3154
REGISTER_ZIP_CLASS_CONST_LONG ("FL_ENC_GUESS" , ZIP_FL_ENC_GUESS );
@@ -3064,20 +3166,6 @@ static PHP_MINIT_FUNCTION(zip)
3064
3166
REGISTER_ZIP_CLASS_CONST_LONG ("FL_ENC_CP437" , ZIP_FL_ENC_CP437 );
3065
3167
#endif
3066
3168
3067
- /* XXX The below are rather not implemented or to check whether makes sense to expose. */
3068
- /*#ifdef ZIP_FL_RECOMPRESS
3069
- REGISTER_ZIP_CLASS_CONST_LONG("FL_RECOMPRESS", ZIP_FL_RECOMPRESS);
3070
- #endif
3071
- #ifdef ZIP_FL_ENCRYPTED
3072
- REGISTER_ZIP_CLASS_CONST_LONG("FL_ENCRYPTED", ZIP_FL_ENCRYPTED);
3073
- #endif
3074
- #ifdef ZIP_FL_LOCAL
3075
- REGISTER_ZIP_CLASS_CONST_LONG("FL_LOCAL", ZIP_FL_LOCAL);
3076
- #endif
3077
- #ifdef ZIP_FL_CENTRAL
3078
- REGISTER_ZIP_CLASS_CONST_LONG("FL_CENTRAL", ZIP_FL_CENTRAL);
3079
- #endif */
3080
-
3081
3169
REGISTER_ZIP_CLASS_CONST_LONG ("CM_DEFAULT" , ZIP_CM_DEFAULT );
3082
3170
REGISTER_ZIP_CLASS_CONST_LONG ("CM_STORE" , ZIP_CM_STORE );
3083
3171
REGISTER_ZIP_CLASS_CONST_LONG ("CM_SHRINK" , ZIP_CM_SHRINK );
@@ -3147,6 +3235,13 @@ static PHP_MINIT_FUNCTION(zip)
3147
3235
REGISTER_ZIP_CLASS_CONST_LONG ("OPSYS_DEFAULT" , ZIP_OPSYS_DEFAULT );
3148
3236
#endif /* ifdef ZIP_OPSYS_DEFAULT */
3149
3237
3238
+ #ifdef HAVE_ENCRYPTION
3239
+ REGISTER_ZIP_CLASS_CONST_LONG ("EM_NONE" , ZIP_EM_NONE );
3240
+ REGISTER_ZIP_CLASS_CONST_LONG ("EM_AES_128" , ZIP_EM_AES_128 );
3241
+ REGISTER_ZIP_CLASS_CONST_LONG ("EM_AES_192" , ZIP_EM_AES_192 );
3242
+ REGISTER_ZIP_CLASS_CONST_LONG ("EM_AES_256" , ZIP_EM_AES_256 );
3243
+ #endif
3244
+
3150
3245
php_register_url_stream_wrapper ("zip" , & php_stream_zip_wrapper );
3151
3246
3152
3247
le_zip_dir = zend_register_list_destructors_ex (php_zip_free_dir , NULL , le_zip_dir_name , module_number );
0 commit comments