@@ -275,7 +275,7 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, size_t
275
275
}
276
276
/* }}} */
277
277
278
- static int php_zip_add_file (struct zip * za , const char * filename , size_t filename_len ,
278
+ static int php_zip_add_file (ze_zip_object * obj , const char * filename , size_t filename_len ,
279
279
char * entry_name , size_t entry_name_len , /* unused if replace >= 0 */
280
280
zip_uint64_t offset_start , zip_uint64_t offset_len ,
281
281
zend_long replace , /* index to replace, add new file if < 0 */
@@ -300,25 +300,26 @@ static int php_zip_add_file(struct zip *za, const char *filename, size_t filenam
300
300
return -1 ;
301
301
}
302
302
303
- zs = zip_source_file (za , resolved_path , offset_start , offset_len );
303
+ zs = zip_source_file (obj -> za , resolved_path , offset_start , offset_len );
304
304
if (!zs ) {
305
305
return -1 ;
306
306
}
307
307
// Replace
308
308
if (replace >= 0 ) {
309
- if (zip_file_replace (za , replace , zs , flags ) < 0 ) {
309
+ if (zip_file_replace (obj -> za , replace , zs , flags ) < 0 ) {
310
310
zip_source_free (zs );
311
311
return -1 ;
312
312
}
313
- zip_error_clear (za );
313
+ zip_error_clear (obj -> za );
314
314
return 1 ;
315
315
}
316
316
// Add
317
- if (zip_file_add (za , entry_name , zs , flags ) < 0 ) {
317
+ obj -> last_id = zip_file_add (obj -> za , entry_name , zs , flags );
318
+ if (obj -> last_id < 0 ) {
318
319
zip_source_free (zs );
319
320
return -1 ;
320
321
}
321
- zip_error_clear (za );
322
+ zip_error_clear (obj -> za );
322
323
return 1 ;
323
324
}
324
325
/* }}} */
@@ -433,67 +434,69 @@ static int php_zip_parse_options(zval *options, zend_long *remove_all_path,
433
434
#endif
434
435
/* }}} */
435
436
436
- static zend_long php_zip_status (struct zip * za ) /* {{{ */
437
+ static zend_long php_zip_status (ze_zip_object * obj ) /* {{{ */
437
438
{
438
439
#if LIBZIP_VERSION_MAJOR < 1
439
440
int zep , syp ;
440
441
441
- zip_error_get (za , & zep , & syp );
442
+ zip_error_get (obj -> za , & zep , & syp );
442
443
#else
443
444
int zep ;
444
445
zip_error_t * err ;
445
446
446
- err = zip_get_error (za );
447
+ err = zip_get_error (obj -> za );
447
448
zep = zip_error_code_zip (err );
448
449
zip_error_fini (err );
449
450
#endif
450
451
return zep ;
451
452
}
452
453
/* }}} */
453
454
454
- static zend_long php_zip_status_sys (struct zip * za ) /* {{{ */
455
+ static zend_long php_zip_last_id (ze_zip_object * obj ) /* {{{ */
456
+ {
457
+ return obj -> last_id ;
458
+ }
459
+ /* }}} */
460
+
461
+ static zend_long php_zip_status_sys (ze_zip_object * obj ) /* {{{ */
455
462
{
456
463
#if LIBZIP_VERSION_MAJOR < 1
457
464
int zep , syp ;
458
465
459
- zip_error_get (za , & zep , & syp );
466
+ zip_error_get (obj -> za , & zep , & syp );
460
467
#else
461
468
int syp ;
462
469
zip_error_t * err ;
463
470
464
- err = zip_get_error (za );
471
+ err = zip_get_error (obj -> za );
465
472
syp = zip_error_code_system (err );
466
473
zip_error_fini (err );
467
474
#endif
468
475
return syp ;
469
476
}
470
477
/* }}} */
471
478
472
- static zend_long php_zip_get_num_files (struct zip * za ) /* {{{ */
479
+ static zend_long php_zip_get_num_files (ze_zip_object * obj ) /* {{{ */
473
480
{
474
- zip_int64_t num = zip_get_num_entries (za , 0 );
481
+ zip_int64_t num = zip_get_num_entries (obj -> za , 0 );
475
482
return MIN (num , ZEND_LONG_MAX );
476
483
}
477
484
/* }}} */
478
485
479
- static char * php_zipobj_get_filename (ze_zip_object * obj ) /* {{{ */
486
+ static char * php_zipobj_get_filename (ze_zip_object * obj , int * len ) /* {{{ */
480
487
{
481
-
482
- if (!obj ) {
483
- return NULL ;
484
- }
485
-
486
- if (obj -> filename ) {
488
+ if (obj && obj -> filename ) {
489
+ * len = strlen (obj -> filename );
487
490
return obj -> filename ;
488
491
}
489
492
return NULL ;
490
493
}
491
494
/* }}} */
492
495
493
- static char * php_zipobj_get_zip_comment (struct zip * za , int * len ) /* {{{ */
496
+ static char * php_zipobj_get_zip_comment (ze_zip_object * obj , int * len ) /* {{{ */
494
497
{
495
- if (za ) {
496
- return (char * )zip_get_archive_comment (za , len , 0 );
498
+ if (obj -> za ) {
499
+ return (char * )zip_get_archive_comment (obj -> za , len , 0 );
497
500
}
498
501
return NULL ;
499
502
}
@@ -764,28 +767,25 @@ static zend_object_handlers zip_object_handlers;
764
767
765
768
static HashTable zip_prop_handlers ;
766
769
767
- typedef zend_long (* zip_read_int_t )(struct zip * za );
768
- typedef char * (* zip_read_const_char_t )(struct zip * za , int * len );
769
- typedef char * (* zip_read_const_char_from_ze_t )(ze_zip_object * obj );
770
+ typedef zend_long (* zip_read_int_t )(ze_zip_object * obj );
771
+ typedef char * (* zip_read_const_char_t )(ze_zip_object * obj , int * len );
770
772
771
773
typedef struct _zip_prop_handler {
772
774
zip_read_int_t read_int_func ;
773
775
zip_read_const_char_t read_const_char_func ;
774
- zip_read_const_char_from_ze_t read_const_char_from_obj_func ;
775
776
776
777
int type ;
777
778
} zip_prop_handler ;
778
779
/* }}} */
779
780
780
- static void php_zip_register_prop_handler (HashTable * prop_handler , char * name , zip_read_int_t read_int_func , zip_read_const_char_t read_char_func , zip_read_const_char_from_ze_t read_char_from_obj_func , int rettype ) /* {{{ */
781
+ static void php_zip_register_prop_handler (HashTable * prop_handler , char * name , zip_read_int_t read_int_func , zip_read_const_char_t read_char_func , int rettype ) /* {{{ */
781
782
{
782
783
zip_prop_handler hnd ;
783
784
zend_string * str ;
784
785
zval tmp ;
785
786
786
787
hnd .read_const_char_func = read_char_func ;
787
788
hnd .read_int_func = read_int_func ;
788
- hnd .read_const_char_from_obj_func = read_char_from_obj_func ;
789
789
hnd .type = rettype ;
790
790
str = zend_string_init_interned (name , strlen (name ), 1 );
791
791
zend_hash_add_mem (prop_handler , str , & hnd , sizeof (zip_prop_handler ));
@@ -805,20 +805,9 @@ static zval *php_zip_property_reader(ze_zip_object *obj, zip_prop_handler *hnd,
805
805
806
806
if (obj && obj -> za != NULL ) {
807
807
if (hnd -> read_const_char_func ) {
808
- retchar = hnd -> read_const_char_func (obj -> za , & len );
809
- } else {
810
- if (hnd -> read_int_func ) {
811
- retint = hnd -> read_int_func (obj -> za );
812
- if (retint == -1 ) {
813
- php_error_docref (NULL , E_WARNING , "Internal zip error returned" );
814
- return NULL ;
815
- }
816
- } else {
817
- if (hnd -> read_const_char_from_obj_func ) {
818
- retchar = hnd -> read_const_char_from_obj_func (obj );
819
- len = strlen (retchar );
820
- }
821
- }
808
+ retchar = hnd -> read_const_char_func (obj , & len );
809
+ } else if (hnd -> read_int_func ) {
810
+ retint = hnd -> read_int_func (obj );
822
811
}
823
812
}
824
813
@@ -1037,6 +1026,7 @@ static zend_object *php_zip_object_new(zend_class_entry *class_type) /* {{{ */
1037
1026
zend_object_std_init (& intern -> zo , class_type );
1038
1027
object_properties_init (& intern -> zo , class_type );
1039
1028
intern -> zo .handlers = & zip_object_handlers ;
1029
+ intern -> last_id = -1 ;
1040
1030
1041
1031
return & intern -> zo ;
1042
1032
}
@@ -1579,8 +1569,6 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
1579
1569
zval * self = ZEND_THIS ;
1580
1570
char * dirname ;
1581
1571
size_t dirname_len ;
1582
- int idx ;
1583
- struct zip_stat sb ;
1584
1572
char * s ;
1585
1573
zend_long flags = 0 ;
1586
1574
@@ -1604,16 +1592,11 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
1604
1592
s = dirname ;
1605
1593
}
1606
1594
1607
- idx = zip_stat (intern , s , 0 , & sb );
1608
- if (idx >= 0 ) {
1595
+ if ((Z_ZIP_P (self )-> last_id = zip_dir_add (intern , (const char * )s , flags )) == -1 ) {
1609
1596
RETVAL_FALSE ;
1610
1597
} else {
1611
- if (zip_dir_add (intern , (const char * )s , flags ) == -1 ) {
1612
- RETVAL_FALSE ;
1613
- } else {
1614
- zip_error_clear (intern );
1615
- RETVAL_TRUE ;
1616
- }
1598
+ zip_error_clear (intern );
1599
+ RETVAL_TRUE ;
1617
1600
}
1618
1601
1619
1602
if (s != dirname ) {
@@ -1624,7 +1607,6 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
1624
1607
1625
1608
static void php_zip_add_from_pattern (INTERNAL_FUNCTION_PARAMETERS , int type ) /* {{{ */
1626
1609
{
1627
- struct zip * intern ;
1628
1610
zval * self = ZEND_THIS ;
1629
1611
char * path = "." ;
1630
1612
char * remove_path = NULL , * save_remove_path ;
@@ -1637,7 +1619,6 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
1637
1619
int found ;
1638
1620
zend_string * pattern ;
1639
1621
1640
- ZIP_FROM_OBJECT (intern , self );
1641
1622
/* 1 == glob, 2 == pcre */
1642
1623
if (type == 1 ) {
1643
1624
if (zend_parse_parameters (ZEND_NUM_ARGS (), "P|la" ,
@@ -1717,7 +1698,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
1717
1698
basename = NULL ;
1718
1699
}
1719
1700
1720
- if (php_zip_add_file (intern , Z_STRVAL_P (zval_file ), Z_STRLEN_P (zval_file ),
1701
+ if (php_zip_add_file (Z_ZIP_P ( self ) , Z_STRVAL_P (zval_file ), Z_STRLEN_P (zval_file ),
1721
1702
entry_name , entry_name_len , 0 , 0 , -1 , zip_flags ) < 0 ) {
1722
1703
zend_array_destroy (Z_ARR_P (return_value ));
1723
1704
RETURN_FALSE ;
@@ -1751,16 +1732,13 @@ static ZIPARCHIVE_METHOD(addPattern)
1751
1732
Add a file in a Zip archive using its path and the name to use. */
1752
1733
static ZIPARCHIVE_METHOD (addFile )
1753
1734
{
1754
- struct zip * intern ;
1755
1735
zval * self = ZEND_THIS ;
1756
1736
char * entry_name = NULL ;
1757
1737
size_t entry_name_len = 0 ;
1758
1738
zend_long offset_start = 0 , offset_len = 0 ;
1759
1739
zend_string * filename ;
1760
1740
zend_long flags = ZIP_FL_OVERWRITE ;
1761
1741
1762
- ZIP_FROM_OBJECT (intern , self );
1763
-
1764
1742
if (zend_parse_parameters (ZEND_NUM_ARGS (), "P|slll" ,
1765
1743
& filename , & entry_name , & entry_name_len , & offset_start , & offset_len , & flags ) == FAILURE ) {
1766
1744
RETURN_THROWS ();
@@ -1776,7 +1754,7 @@ static ZIPARCHIVE_METHOD(addFile)
1776
1754
entry_name_len = ZSTR_LEN (filename );
1777
1755
}
1778
1756
1779
- if (php_zip_add_file (intern , ZSTR_VAL (filename ), ZSTR_LEN (filename ),
1757
+ if (php_zip_add_file (Z_ZIP_P ( self ) , ZSTR_VAL (filename ), ZSTR_LEN (filename ),
1780
1758
entry_name , entry_name_len , offset_start , offset_len , -1 , flags ) < 0 ) {
1781
1759
RETURN_FALSE ;
1782
1760
} else {
@@ -1789,15 +1767,12 @@ static ZIPARCHIVE_METHOD(addFile)
1789
1767
Add a file in a Zip archive using its path and the name to use. */
1790
1768
static ZIPARCHIVE_METHOD (replaceFile )
1791
1769
{
1792
- struct zip * intern ;
1793
1770
zval * self = ZEND_THIS ;
1794
1771
zend_long index ;
1795
1772
zend_long offset_start = 0 , offset_len = 0 ;
1796
1773
zend_string * filename ;
1797
1774
zend_long flags = 0 ;
1798
1775
1799
- ZIP_FROM_OBJECT (intern , self );
1800
-
1801
1776
if (zend_parse_parameters (ZEND_NUM_ARGS (), "Pl|lll" ,
1802
1777
& filename , & index , & offset_start , & offset_len , & flags ) == FAILURE ) {
1803
1778
RETURN_THROWS ();
@@ -1813,7 +1788,7 @@ static ZIPARCHIVE_METHOD(replaceFile)
1813
1788
RETURN_FALSE ;
1814
1789
}
1815
1790
1816
- if (php_zip_add_file (intern , ZSTR_VAL (filename ), ZSTR_LEN (filename ),
1791
+ if (php_zip_add_file (Z_ZIP_P ( self ) , ZSTR_VAL (filename ), ZSTR_LEN (filename ),
1817
1792
NULL , 0 , offset_start , offset_len , index , flags ) < 0 ) {
1818
1793
RETURN_FALSE ;
1819
1794
} else {
@@ -1861,7 +1836,8 @@ static ZIPARCHIVE_METHOD(addFromString)
1861
1836
RETURN_FALSE ;
1862
1837
}
1863
1838
1864
- if (zip_file_add (intern , name , zs , flags ) == -1 ) {
1839
+ ze_obj -> last_id = zip_file_add (intern , name , zs , flags );
1840
+ if (ze_obj -> last_id == -1 ) {
1865
1841
zip_source_free (zs );
1866
1842
RETURN_FALSE ;
1867
1843
} else {
@@ -3069,11 +3045,12 @@ static PHP_MINIT_FUNCTION(zip)
3069
3045
zip_class_entry = zend_register_internal_class (& ce );
3070
3046
3071
3047
zend_hash_init (& zip_prop_handlers , 0 , NULL , php_zip_free_prop_handler , 1 );
3072
- php_zip_register_prop_handler (& zip_prop_handlers , "status" , php_zip_status , NULL , NULL , IS_LONG );
3073
- php_zip_register_prop_handler (& zip_prop_handlers , "statusSys" , php_zip_status_sys , NULL , NULL , IS_LONG );
3074
- php_zip_register_prop_handler (& zip_prop_handlers , "numFiles" , php_zip_get_num_files , NULL , NULL , IS_LONG );
3075
- php_zip_register_prop_handler (& zip_prop_handlers , "filename" , NULL , NULL , php_zipobj_get_filename , IS_STRING );
3076
- php_zip_register_prop_handler (& zip_prop_handlers , "comment" , NULL , php_zipobj_get_zip_comment , NULL , IS_STRING );
3048
+ php_zip_register_prop_handler (& zip_prop_handlers , "lastId" , php_zip_last_id , NULL , IS_LONG );
3049
+ php_zip_register_prop_handler (& zip_prop_handlers , "status" , php_zip_status , NULL , IS_LONG );
3050
+ php_zip_register_prop_handler (& zip_prop_handlers , "statusSys" , php_zip_status_sys , NULL , IS_LONG );
3051
+ php_zip_register_prop_handler (& zip_prop_handlers , "numFiles" , php_zip_get_num_files , NULL , IS_LONG );
3052
+ php_zip_register_prop_handler (& zip_prop_handlers , "filename" , NULL , php_zipobj_get_filename , IS_STRING );
3053
+ php_zip_register_prop_handler (& zip_prop_handlers , "comment" , NULL , php_zipobj_get_zip_comment , IS_STRING );
3077
3054
zend_class_implements (zip_class_entry , 1 , zend_ce_countable );
3078
3055
3079
3056
REGISTER_ZIP_CLASS_CONST_LONG ("CREATE" , ZIP_CREATE );
0 commit comments