pajoye          Sun Aug 13 20:16:48 2006 UTC

  Modified files:              
    /php-src/ext/zip    php_zip.c php_zip.h 
    /php-src/ext/zip/lib        zip.h zip_open.c zip_replace.c 
  Log:
  - add overwrite mode to ZipArchive::open, always starts a new archive
  - fix build with php6
  - remove safemode when built against php6
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/zip/php_zip.c?r1=1.2&r2=1.3&diff_format=u
Index: php-src/ext/zip/php_zip.c
diff -u php-src/ext/zip/php_zip.c:1.2 php-src/ext/zip/php_zip.c:1.3
--- php-src/ext/zip/php_zip.c:1.2       Fri Jul 28 14:00:07 2006
+++ php-src/ext/zip/php_zip.c   Sun Aug 13 20:16:48 2006
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_zip.c,v 1.2 2006/07/28 14:00:07 iliaa Exp $ */
+/* $Id: php_zip.c,v 1.3 2006/08/13 20:16:48 pajoye Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -39,8 +39,14 @@
 /* }}} */
 
 /* {{{ SAFEMODE_CHECKFILE(filename) */
+#if (PHP_MAJOR_VERSION < 6)
 #define SAFEMODE_CHECKFILE(filename) \
-       (PG(safe_mode) && (!php_checkuid(filename, NULL, 
CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(filename TSRMLS_CC)
+       if (PG(safe_mode) && (!php_checkuid(filename, NULL, 
CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(filename TSRMLS_CC) { \
+               RETURN_FALSE; \
+       } 
+#else 
+#define SAFEMODE_CHECKFILE(filename);
+#endif
 /* }}} */
 
 /* {{{ PHP_ZIP_STAT_INDEX(za, index, flags, sb) */
@@ -111,7 +117,7 @@
                len = spprintf(&file_dirname_fullpath, 0, "%s", dest);
        }
 
-       php_basename(file, file_len, NULL, 0, &file_basename, 
&file_basename_len TSRMLS_CC);
+       php_basename(file, file_len, NULL, 0, &file_basename, (int 
*)&file_basename_len TSRMLS_CC);
 
        SAFEMODE_CHECKFILE(file_dirname_fullpath);
 
@@ -152,8 +158,11 @@
                efree(file_basename);
                return 0;
        }
-
+#if (PHP_MAJOR_VERSION < 6)
        stream = php_stream_open_wrapper(fullpath, "w+b", 
REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL);
+#else
+       stream = php_stream_open_wrapper(fullpath, "w+b", REPORT_ERRORS, NULL);
+#endif
        n = 0;
        if (stream) {
                while ((n=zip_fread(zf, b, sizeof(b))) > 0) 
php_stream_write(stream, b, n);
@@ -613,9 +622,8 @@
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, 
&filename_len, &mode) == FAILURE) {
                return;
        }
-       if (SAFEMODE_CHECKFILE(filename)) {
-               RETURN_FALSE;
-       }
+
+       SAFEMODE_CHECKFILE(filename);
 
        rsrc_int = (zip_rsrc *)emalloc(sizeof(zip_rsrc));
 
@@ -956,6 +964,7 @@
        int entry_name_len = 0;
        struct zip_source *zs;
        long offset_start = 0, offset_len = 0;
+       int cur_idx;
 
        if (!this) {
                RETURN_FALSE;
@@ -979,15 +988,29 @@
                entry_name_len = filename_len;
        }
 
-       if (SAFEMODE_CHECKFILE(filename)) {
-               RETURN_FALSE;
-       }
+       SAFEMODE_CHECKFILE(filename);
 
        zs = zip_source_file(intern, filename, 0, 0);
        if (!zs) {
                RETURN_FALSE;
        }
-       if (zip_add(intern, entry_name, zs) < 0) {
+
+       cur_idx = zip_name_locate(intern, (const char *)entry_name, 0);
+       /* TODO: fix  _zip_replace */
+       if (cur_idx<0) {
+               /* reset the error */
+               if (intern->error.str) {
+                       _zip_error_fini(&intern->error);
+               }
+               _zip_error_init(&intern->error);
+
+       } else {
+               if (zip_delete(intern, cur_idx) == -1) {
+                       RETURN_FALSE;
+               }
+       }
+
+       if (zip_add(intern, entry_name, zs) == -1) {
                RETURN_FALSE;
        } else {
                RETURN_TRUE;
@@ -1006,6 +1029,7 @@
        ze_zip_object *ze_obj;
        struct zip_source *zs;
        int pos = 0;
+       int cur_idx;
 
        if (!this) {
                RETURN_FALSE;
@@ -1037,8 +1061,25 @@
                RETURN_FALSE;
        }
 
+       cur_idx = zip_name_locate(intern, (const char *)name, 0);
+       /* TODO: fix  _zip_replace */
+       if (cur_idx<0) {
+               /* reset the error */
+               if (intern->error.str) {
+                       _zip_error_fini(&intern->error);
+               }
+               _zip_error_init(&intern->error);
+
+       } else {
+               if (zip_delete(intern, cur_idx) == -1) {
+                       RETURN_FALSE;
+               }
+       }
+
        if (zip_add(intern, name, zs) == -1) {
                RETURN_FALSE;
+       } else {
+               RETURN_TRUE;
        }
 }
 /* }}} */
@@ -1845,6 +1886,8 @@
        REGISTER_ZIP_CLASS_CONST_LONG("CREATE", ZIP_CREATE);
        REGISTER_ZIP_CLASS_CONST_LONG("EXCL", ZIP_EXCL);
        REGISTER_ZIP_CLASS_CONST_LONG("CHECKCONS", ZIP_CHECKCONS);
+       REGISTER_ZIP_CLASS_CONST_LONG("OVERWRITE", ZIP_OVERWRITE);
+
        REGISTER_ZIP_CLASS_CONST_LONG("FL_NOCASE", ZIP_FL_NOCASE);
        REGISTER_ZIP_CLASS_CONST_LONG("FL_NODIR", ZIP_FL_NODIR);
        REGISTER_ZIP_CLASS_CONST_LONG("FL_COMPRESSED", ZIP_FL_COMPRESSED);
@@ -1916,7 +1959,7 @@
        php_info_print_table_start();
 
        php_info_print_table_row(2, "Zip", "enabled");
-       php_info_print_table_row(2, "Extension Version","$Id: php_zip.c,v 1.2 
2006/07/28 14:00:07 iliaa Exp $");
+       php_info_print_table_row(2, "Extension Version","$Id: php_zip.c,v 1.3 
2006/08/13 20:16:48 pajoye Exp $");
        php_info_print_table_row(2, "Zip version", "1.4.0");
        php_info_print_table_row(2, "Libzip version", "0.7.1");
 
http://cvs.php.net/viewvc.cgi/php-src/ext/zip/php_zip.h?r1=1.10&r2=1.11&diff_format=u
Index: php-src/ext/zip/php_zip.h
diff -u php-src/ext/zip/php_zip.h:1.10 php-src/ext/zip/php_zip.h:1.11
--- php-src/ext/zip/php_zip.h:1.10      Mon Jul 24 16:58:58 2006
+++ php-src/ext/zip/php_zip.h   Sun Aug 13 20:16:48 2006
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_zip.h,v 1.10 2006/07/24 16:58:58 pajoye Exp $ */
+/* $Id: php_zip.h,v 1.11 2006/08/13 20:16:48 pajoye Exp $ */
 
 #ifndef PHP_ZIP_H
 #define PHP_ZIP_H
@@ -37,7 +37,7 @@
 #include "lib/zip.h"
 
 #ifndef ZEND_ENGINE_2_1
-# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0)
+# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) || PHP_MAJOR_VERSION == 
6
 #  define ZEND_ENGINE_2_1
 # endif
 #endif
http://cvs.php.net/viewvc.cgi/php-src/ext/zip/lib/zip.h?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/zip/lib/zip.h
diff -u php-src/ext/zip/lib/zip.h:1.1 php-src/ext/zip/lib/zip.h:1.2
--- php-src/ext/zip/lib/zip.h:1.1       Mon Jul 24 16:58:58 2006
+++ php-src/ext/zip/lib/zip.h   Sun Aug 13 20:16:48 2006
@@ -53,6 +53,7 @@
 #define ZIP_CREATE           1
 #define ZIP_EXCL             2
 #define ZIP_CHECKCONS        4
+#define ZIP_OVERWRITE        8
 
 
 /* flags for zip_name_locate, zip_fopen, zip_stat, ... */
http://cvs.php.net/viewvc.cgi/php-src/ext/zip/lib/zip_open.c?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/zip/lib/zip_open.c
diff -u php-src/ext/zip/lib/zip_open.c:1.1 php-src/ext/zip/lib/zip_open.c:1.2
--- php-src/ext/zip/lib/zip_open.c:1.1  Mon Jul 24 16:58:58 2006
+++ php-src/ext/zip/lib/zip_open.c      Sun Aug 13 20:16:48 2006
@@ -74,9 +74,9 @@
        set_error(zep, NULL, ZIP_ER_INVAL);
        return NULL;
     }
-    
-    if (stat(fn, &st) != 0) {
-       if (flags & ZIP_CREATE) {
+
+    if (flags & ZIP_OVERWRITE || stat(fn, &st) != 0) {
+       if ((flags & ZIP_CREATE) || (flags & ZIP_OVERWRITE)) {
            if ((za=_zip_new(&error)) == NULL) {
                set_error(zep, &error, 0);
                return NULL;
@@ -99,14 +99,15 @@
        set_error(zep, NULL, ZIP_ER_EXISTS);
        return NULL;
     }
+
+
     /* ZIP_CREATE gets ignored if file exists and not ZIP_EXCL,
        just like open() */
-    
-    if ((fp=fopen(fn, "rb")) == NULL) {
-       set_error(zep, NULL, ZIP_ER_OPEN);
-       return NULL;
-    }
-    
+       if ((fp=fopen(fn, "rb")) == NULL) {
+               set_error(zep, NULL, ZIP_ER_OPEN);
+               return NULL;
+       }
+
     clearerr(fp);
     fseek(fp, 0, SEEK_END);
     len = ftell(fp);
http://cvs.php.net/viewvc.cgi/php-src/ext/zip/lib/zip_replace.c?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/zip/lib/zip_replace.c
diff -u php-src/ext/zip/lib/zip_replace.c:1.1 
php-src/ext/zip/lib/zip_replace.c:1.2
--- php-src/ext/zip/lib/zip_replace.c:1.1       Mon Jul 24 16:58:58 2006
+++ php-src/ext/zip/lib/zip_replace.c   Sun Aug 13 20:16:48 2006
@@ -66,11 +66,14 @@
                        return -1;
                idx = za->nentry - 1;
        }
-    
+
+   
     _zip_unchange_data(za->entry+idx);
 
     if (name && _zip_set_name(za, idx, name) != 0)
                return -1;
+ 
+
     za->entry[idx].state = ((za->cdir == NULL || idx >= za->cdir->nentry)
                            ? ZIP_ST_ADDED : ZIP_ST_REPLACED);
     za->entry[idx].source = source;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to