]> granicus.if.org Git - php/commitdiff
- sync with PECL HEAD
authorPierre Joye <pajoye@php.net>
Wed, 21 May 2008 09:27:41 +0000 (09:27 +0000)
committerPierre Joye <pajoye@php.net>
Wed, 21 May 2008 09:27:41 +0000 (09:27 +0000)
68 files changed:
ext/zip/config.m4
ext/zip/config.w32
ext/zip/examples/create.php
ext/zip/examples/dir.php
ext/zip/examples/extract.php
ext/zip/examples/fopen.php
ext/zip/examples/test.zip
ext/zip/lib/mkstemp.c [deleted file]
ext/zip/lib/unistd.h [deleted file]
ext/zip/lib/zip.h
ext/zip/lib/zip_add.c
ext/zip/lib/zip_add_dir.c
ext/zip/lib/zip_alias.h [deleted file]
ext/zip/lib/zip_close.c
ext/zip/lib/zip_delete.c
ext/zip/lib/zip_dirent.c
ext/zip/lib/zip_entry_free.c
ext/zip/lib/zip_entry_new.c
ext/zip/lib/zip_err_str.c
ext/zip/lib/zip_error.c
ext/zip/lib/zip_error_clear.c
ext/zip/lib/zip_error_get.c
ext/zip/lib/zip_error_get_sys_type.c
ext/zip/lib/zip_error_strerror.c
ext/zip/lib/zip_error_to_str.c
ext/zip/lib/zip_fclose.c
ext/zip/lib/zip_file_error_clear.c
ext/zip/lib/zip_file_error_get.c
ext/zip/lib/zip_file_get_offset.c
ext/zip/lib/zip_file_strerror.c
ext/zip/lib/zip_fopen.c
ext/zip/lib/zip_fopen_index.c
ext/zip/lib/zip_fread.c
ext/zip/lib/zip_free.c
ext/zip/lib/zip_get_archive_comment.c
ext/zip/lib/zip_get_file_comment.c
ext/zip/lib/zip_get_name.c
ext/zip/lib/zip_get_num_files.c
ext/zip/lib/zip_memdup.c
ext/zip/lib/zip_name_locate.c
ext/zip/lib/zip_new.c
ext/zip/lib/zip_open.c
ext/zip/lib/zip_rename.c
ext/zip/lib/zip_replace.c
ext/zip/lib/zip_set_archive_comment.c
ext/zip/lib/zip_set_file_comment.c
ext/zip/lib/zip_set_name.c
ext/zip/lib/zip_source_buffer.c
ext/zip/lib/zip_source_file.c
ext/zip/lib/zip_source_filep.c
ext/zip/lib/zip_source_free.c
ext/zip/lib/zip_source_function.c
ext/zip/lib/zip_source_zip.c
ext/zip/lib/zip_stat.c
ext/zip/lib/zip_stat_index.c
ext/zip/lib/zip_stat_init.c
ext/zip/lib/zip_strerror.c
ext/zip/lib/zip_unchange.c
ext/zip/lib/zip_unchange_all.c
ext/zip/lib/zip_unchange_archive.c
ext/zip/lib/zip_unchange_data.c
ext/zip/lib/zip_win32.h
ext/zip/lib/zipint.h
ext/zip/lib/zipint_alias.h [deleted file]
ext/zip/php_zip.c
ext/zip/php_zip.h
ext/zip/tests/bug38943.phpt
ext/zip/tests/bug7658.phpt

index 271bd2faa056ceea4d21e956255b97722503b2ee..8b635d1a1a9fed062893be521508e5e8dc1a5262 100644 (file)
@@ -3,13 +3,16 @@ dnl $Id$
 dnl
 
 PHP_ARG_ENABLE(zip, for zip archive read/writesupport,
-[  --enable-zip            Include Zip read/write support])
+[  --enable-zip        Include Zip read/write support.])
 
 if test -z "$PHP_ZLIB_DIR"; then
 PHP_ARG_WITH(zlib-dir, for the location of libz,
-[  --with-zlib-dir[=DIR]     ZIP: Set the path to libz install prefix], no, no)
+[  --with-zlib-dir[=DIR]   zip: Set the path to libz install prefix.], no, no)
 fi
 
+PHP_ARG_WITH(pcre-dir, pcre install prefix,
+[  --with-pcre-dir           FILTER: pcre install prefix], no, no)
+
 if test "$PHP_ZIP" != "no"; then
 
        if test "$PHP_ZLIB_DIR" != "no" && test "$PHP_ZLIB_DIR" != "yes"; then
@@ -44,6 +47,32 @@ if test "$PHP_ZIP" != "no"; then
                PHP_ADD_INCLUDE($PHP_ZLIB_INCDIR)
        fi
 
+
+       dnl This is PECL build, check if bundled PCRE library is used
+       old_CPPFLAGS=$CPPFLAGS
+       CPPFLAGS=$INCLUDES
+       AC_EGREP_CPP(yes,[
+#include <main/php_config.h>
+#if defined(HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE)
+yes
+#endif
+    ],[
+      PHP_PCRE_REGEX=yes
+    ],[
+      AC_EGREP_CPP(yes,[
+#include <main/php_config.h>
+#if defined(HAVE_PCRE) && !defined(COMPILE_DL_PCRE)
+yes
+#endif
+      ],[
+        PHP_PCRE_REGEX=pecl
+      ],[
+        PHP_PCRE_REGEX=no
+      ])
+    ])
+       CPPFLAGS=$old_CPPFLAGS
+
+
        PHP_ZIP_SOURCES="$PHP_ZIP_SOURCES lib/zip_add.c lib/zip_error.c lib/zip_fclose.c \
                          lib/zip_fread.c lib/zip_open.c lib/zip_source_filep.c  \
                          lib/zip_strerror.c lib/zip_close.c lib/zip_error_get.c \
index a8ae4f1223e1fffa71daccbd1ea12b916cce5b04..62e8140974878d830a6c2593285b704d16a5ff38 100644 (file)
@@ -1,10 +1,9 @@
 // $Id$
 // vim:ft=javascript
 
-ARG_ENABLE("zip", "ZIP support", "no");
+ARG_ENABLE("zip", "ZIP support", "yes");
 
 if (PHP_ZIP != "no") {
-
        if (CHECK_HEADER_ADD_INCLUDE("zlib.h", "CFLAGS_ZIP", "..\\zlib;" + php_usual_include_suspects + ";" + PHP_ZIP)) {
                if (PHP_ZLIB_SHARED) {
                        CHECK_LIB("zlib.lib", "zip", PHP_ZIP);
index cffacee93b713f83fdbcf3bec6ca0d62832362a6..a41c8e6d0bcab7c66e7a5ef0c0afe5790e84f45f 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 error_reporting(E_ALL);
+if (!extension_loaded('zip')) {
+    dl('zip.so');
+}
 $thisdir = dirname(__FILE__);
 unlink("./test112.zip");
 $zip = new ZipArchive();
index 00e4b405852980ae63f55a0a47ee10b41f2132e0..c362a72ba36f803654cf6b0ea5755887d1fc5271 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+if (!extension_loaded('zip')) {
+    dl('zip.so');
+}
+
 $za = new ZipArchive();
 
 $za->open('test_with_comment.zip');
index 696502ba1225f6074444a406a77324b8e2543455..5276b0dca5f6582a4ada803d87514769ebb0c447 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+if (!extension_loaded('zip')) {
+    dl('zip.so');
+}
+
 $zip = new ZipArchive();
 
 echo $zip->filename . "\n";
index 5af37b1ab33734c378a8d26dde7c5759324ed201..32357f3c08f6ea94393472a9f1c79eafdb2af231 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+if (!extension_loaded('zip')) {
+    dl('zip.so');
+}
+
 
 $fp = fopen('zip://' . dirname(__FILE__) . '/test.zip#test', 'r');
 if (!$fp) {
index 6b986948031d904753e54b3739462aa99b8932c9..a6a2e62f65883666631ccc030978204b2aad9555 100644 (file)
Binary files a/ext/zip/examples/test.zip and b/ext/zip/examples/test.zip differ
diff --git a/ext/zip/lib/mkstemp.c b/ext/zip/lib/mkstemp.c
deleted file mode 100644 (file)
index 3ac587e..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/* $NiH: mkstemp.c,v 1.3 2006/04/23 14:51:45 wiz Exp $ */
-
-/* Adapted from NetBSB libc by Dieter Baron */
-
-/*     NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp       */
-
-/*
- * Copyright (c) 1987, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-
-int
-_zip_mkstemp(char *path)
-{
-       int fd;   
-       char *start, *trv;
-       struct stat sbuf;
-       pid_t pid;
-
-       /* To guarantee multiple calls generate unique names even if
-          the file is not created. 676 different possibilities with 7
-          or more X's, 26 with 6 or less. */
-       static char xtra[2] = "aa";
-       int xcnt = 0;
-
-       pid = getpid();
-
-       /* Move to end of path and count trailing X's. */
-       for (trv = path; *trv; ++trv)
-               if (*trv == 'X')
-                       xcnt++;
-               else
-                       xcnt = 0;       
-
-       /* Use at least one from xtra.  Use 2 if more than 6 X's. */
-       if (*(trv - 1) == 'X')
-               *--trv = xtra[0];
-       if (xcnt > 6 && *(trv - 1) == 'X')
-               *--trv = xtra[1];
-
-       /* Set remaining X's to pid digits with 0's to the left. */
-       while (*--trv == 'X') {
-               *trv = (pid % 10) + '0';
-               pid /= 10;
-       }
-
-       /* update xtra for next call. */
-       if (xtra[0] != 'z')
-               xtra[0]++;
-       else {
-               xtra[0] = 'a';
-               if (xtra[1] != 'z')
-                       xtra[1]++;
-               else
-                       xtra[1] = 'a';
-       }
-
-       /*
-        * check the target directory; if you have six X's and it
-        * doesn't exist this runs for a *very* long time.
-        */
-       for (start = trv + 1;; --trv) {
-               if (trv <= path)
-                       break;
-               if (*trv == '/') {
-                       *trv = '\0';
-                       if (stat(path, &sbuf))
-                               return (0);
-                       if (!S_ISDIR(sbuf.st_mode)) {
-                               errno = ENOTDIR;
-                               return (0);
-                       }
-                       *trv = '/';
-                       break;
-               }
-       }
-
-       for (;;) {
-               if ((fd = open(path, O_CREAT | O_EXCL | O_RDWR, 0600)) >= 0)
-                       return (1);
-               if (errno != EEXIST)
-                       return (0);
-
-               /* tricky little algorithm for backward compatibility */
-               for (trv = start;;) {
-                       if (!*trv)
-                               return (0);
-                       if (*trv == 'z')
-                               *trv++ = 'a';
-                       else {
-                               if (isdigit((unsigned char)*trv))
-                                       *trv = 'a';
-                               else
-                                       ++*trv;
-                               break;
-                       }
-               }
-       }
-       /*NOTREACHED*/
-}
diff --git a/ext/zip/lib/unistd.h b/ext/zip/lib/unistd.h
deleted file mode 100644 (file)
index 2ef435c..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#ifndef _MSC_VER
-#include <unistd.h>
-#endif
index 87151174b0fa2512d2aa737edad778da6719b907..5c8460bf272f249980c26b8a2fc5dff08434547a 100644 (file)
@@ -2,13 +2,11 @@
 #define _HAD_ZIP_H
 
 /*
-  $NiH: zip.h,v 1.57 2006/04/24 14:04:19 dillo Exp $
-
   zip.h -- exported declarations.
   Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
@@ -22,7 +20,7 @@
   3. The names of the authors may not be used to endorse or promote
      products derived from this software without specific prior
      written permission.
+
   THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
 \f
 #include "main/php.h"
-/* #defines that rename all zip_ functions and structs */
-#include "zip_alias.h"
+
 #ifdef PHP_WIN32
 #      include "zip_win32.h"
 #      ifdef PHP_ZIP_EXPORTS
-#              define PHPZIPAPI __declspec(dllexport)
+#              define ZIP_EXTERN(rt) __declspec(dllexport)rt _stdcall
 #      else
-#              define PHPZIPAPI
+#              define ZIP_EXTERN(rt) rt
 #      endif
 #elif defined(__GNUC__) && __GNUC__ >= 4
-#      define PHPZIPAPI __attribute__ ((visibility("default")))
+#      define ZIP_EXTERN(rt) __attribute__ ((visibility("default"))) rt
 #else
-#      define PHPZIPAPI
+#      define ZIP_EXTERN(rt) rt
 #endif
+
 BEGIN_EXTERN_C()
+
 #include <sys/types.h>
 #include <stdio.h>
 #include <time.h>
 
-
 /* flags for zip_open */
 
 #define ZIP_CREATE           1
@@ -73,6 +71,10 @@ BEGIN_EXTERN_C()
 #define ZIP_FL_COMPRESSED      4 /* read compressed data */
 #define ZIP_FL_UNCHANGED       8 /* use original data, ignoring changes */
 
+/* archive global flags flags */
+
+#define ZIP_AFL_TORRENT                1 /* torrent zipped */
+
 /* libzip error codes */
 
 #define ZIP_ER_OK             0  /* N No error */
@@ -123,6 +125,13 @@ BEGIN_EXTERN_C()
 #define ZIP_CM_PKWARE_IMPLODE 10  /* PKWARE imploding */
 /* 11 - Reserved by PKWARE */
 #define ZIP_CM_BZIP2          12  /* compressed using BZIP2 algorithm */
+/* 13 - Reserved by PKWARE */
+#define ZIP_CM_LZMA          14  /* LZMA (EFS) */
+/* 15-17 - Reserved by PKWARE */
+#define ZIP_CM_TERSE         18  /* compressed using IBM TERSE (new) */
+#define ZIP_CM_LZ77           19  /* IBM LZ77 z Architecture (PFS) */
+#define ZIP_CM_WAVPACK       97  /* WavPack compressed data */
+#define ZIP_CM_PPMD          98  /* PPMd version I, Rev 1 */
 
 /* encryption methods */
 
@@ -152,6 +161,8 @@ enum zip_source_cmd {
     ZIP_SOURCE_FREE    /* cleanup and free resources */
 };
 
+
+
 typedef ssize_t (*zip_source_callback)(void *state, void *data,
                                       size_t len, enum zip_source_cmd cmd);
 
@@ -172,46 +183,51 @@ struct zip_source;
 
 \f
 
-PHPZIPAPI int zip_add(struct zip *, const char *, struct zip_source *);
-PHPZIPAPI int zip_add_dir(struct zip *, const char *);
-PHPZIPAPI int zip_close(struct zip *);
-PHPZIPAPI int zip_delete(struct zip *, int);
-PHPZIPAPI void zip_error_clear(struct zip *);
-PHPZIPAPI void zip_error_get(struct zip *, int *, int *);
-PHPZIPAPI int zip_error_get_sys_type(int);
-PHPZIPAPI int zip_error_to_str(char *, size_t, int, int);
-PHPZIPAPI int zip_fclose(struct zip_file *);
-PHPZIPAPI void zip_file_error_clear(struct zip_file *);
-PHPZIPAPI void zip_file_error_get(struct zip_file *, int *, int *);
-PHPZIPAPI const char *zip_file_strerror(struct zip_file *);
-PHPZIPAPI struct zip_file *zip_fopen(struct zip *, const char *, int);
-PHPZIPAPI struct zip_file *zip_fopen_index(struct zip *, int, int);
-PHPZIPAPI ssize_t zip_fread(struct zip_file *, void *, size_t);
-PHPZIPAPI const char *zip_get_archive_comment(struct zip *, int *, int);
-PHPZIPAPI const char *zip_get_file_comment(struct zip *, int, int *, int);
-PHPZIPAPI const char *zip_get_name(struct zip *, int, int);
-PHPZIPAPI int zip_get_num_files(struct zip *);
-PHPZIPAPI int zip_name_locate(struct zip *, const char *, int);
-PHPZIPAPI struct zip *zip_open(const char *, int, int *);
-PHPZIPAPI int zip_rename(struct zip *, int, const char *);
-PHPZIPAPI int zip_replace(struct zip *, int, struct zip_source *);
-PHPZIPAPI int zip_set_archive_comment(struct zip *, const char *, int);
-PHPZIPAPI int zip_set_file_comment(struct zip *, int, const char *, int);
-PHPZIPAPI struct zip_source *zip_source_buffer(struct zip *, const void *, off_t, int);
-PHPZIPAPI struct zip_source *zip_source_file(struct zip *, const char *, off_t, off_t);
-PHPZIPAPI struct zip_source *zip_source_filep(struct zip *, FILE *, off_t, off_t);
-PHPZIPAPI void zip_source_free(struct zip_source *);
-PHPZIPAPI struct zip_source *zip_source_function(struct zip *,
-                                      zip_source_callback, void *);
-PHPZIPAPI struct zip_source *zip_source_zip(struct zip *, struct zip *, int, int,
-                                 off_t, off_t);
-PHPZIPAPI int zip_stat(struct zip *, const char *, int, struct zip_stat *);
-PHPZIPAPI int zip_stat_index(struct zip *, int, int, struct zip_stat *);
-PHPZIPAPI void zip_stat_init(struct zip_stat *);
-PHPZIPAPI const char *zip_strerror(struct zip *);
-PHPZIPAPI int zip_unchange(struct zip *, int);
-PHPZIPAPI int zip_unchange_all(struct zip *);
-PHPZIPAPI int zip_unchange_archive(struct zip *);
+ZIP_EXTERN(int) zip_add(struct zip *, const char *, struct zip_source *);
+ZIP_EXTERN(int) zip_add_dir(struct zip *, const char *);
+ZIP_EXTERN(int) zip_close(struct zip *);
+ZIP_EXTERN(int) zip_delete(struct zip *, int);
+ZIP_EXTERN(void) zip_error_clear(struct zip *);
+ZIP_EXTERN(void) zip_error_get(struct zip *, int *, int *);
+ZIP_EXTERN(int) zip_error_get_sys_type(int);
+ZIP_EXTERN(int) zip_error_to_str(char *, size_t, int, int);
+ZIP_EXTERN(int) zip_fclose(struct zip_file *);
+ZIP_EXTERN(void) zip_file_error_clear(struct zip_file *);
+ZIP_EXTERN(void) zip_file_error_get(struct zip_file *, int *, int *);
+ZIP_EXTERN(const char *)zip_file_strerror(struct zip_file *);
+ZIP_EXTERN(struct zip_file *)zip_fopen(struct zip *, const char *, int);
+ZIP_EXTERN(struct zip_file *)zip_fopen_index(struct zip *, int, int);
+ZIP_EXTERN(ssize_t) zip_fread(struct zip_file *, void *, size_t);
+ZIP_EXTERN(const char *)zip_get_archive_comment(struct zip *, int *, int);
+ZIP_EXTERN(int) zip_get_archive_flag(struct zip *, int, int);
+ZIP_EXTERN(const char *)zip_get_file_comment(struct zip *, int, int *, int);
+ZIP_EXTERN(const char *)zip_get_name(struct zip *, int, int);
+ZIP_EXTERN(int) zip_get_num_files(struct zip *);
+ZIP_EXTERN(int) zip_name_locate(struct zip *, const char *, int);
+ZIP_EXTERN(struct zip *)zip_open(const char *, int, int *);
+ZIP_EXTERN(int) zip_rename(struct zip *, int, const char *);
+ZIP_EXTERN(int) zip_replace(struct zip *, int, struct zip_source *);
+ZIP_EXTERN(int) zip_set_archive_comment(struct zip *, const char *, int);
+ZIP_EXTERN(int) zip_set_archive_flag(struct zip *, int, int);
+ZIP_EXTERN(int) zip_set_file_comment(struct zip *, int, const char *, int);
+ZIP_EXTERN(struct zip_source *)zip_source_buffer(struct zip *, const void *,
+                                               off_t, int);
+ZIP_EXTERN(struct zip_source *)zip_source_file(struct zip *, const char *,
+                                             off_t, off_t);
+ZIP_EXTERN(struct zip_source *)zip_source_filep(struct zip *, FILE *,
+                                              off_t, off_t);
+ZIP_EXTERN(void) zip_source_free(struct zip_source *);
+ZIP_EXTERN(struct zip_source *)zip_source_function(struct zip *,
+                                                 zip_source_callback, void *);
+ZIP_EXTERN(struct zip_source *)zip_source_zip(struct zip *, struct zip *,
+                                            int, int, off_t, off_t);
+ZIP_EXTERN(int) zip_stat(struct zip *, const char *, int, struct zip_stat *);
+ZIP_EXTERN(int) zip_stat_index(struct zip *, int, int, struct zip_stat *);
+ZIP_EXTERN(void) zip_stat_init(struct zip_stat *);
+ZIP_EXTERN(const char *)zip_strerror(struct zip *);
+ZIP_EXTERN(int) zip_unchange(struct zip *, int);
+ZIP_EXTERN(int) zip_unchange_all(struct zip *);
+ZIP_EXTERN(int) zip_unchange_archive(struct zip *);
 
 END_EXTERN_C();
 #endif /* _HAD_ZIP_H */
index 70d1162f7fd23bc186696e1fddd6f0d22eca2522..85d5997911b9420557dbb28cda3362ce99e7a1b7 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_add.c,v 1.14 2004/11/18 15:04:04 wiz Exp $
-
   zip_add.c -- add file via callback function
-  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
@@ -19,7 +17,7 @@
   3. The names of the authors may not be used to endorse or promote
      products derived from this software without specific prior
      written permission.
+
   THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_add(struct zip *za, const char *name, struct zip_source *source)
 {
     if (name == NULL || source == NULL) {
        _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
        return -1;
     }
+
     return _zip_replace(za, -1, name, source);
 }
index d4da559ecd7d36a15fcbc80f21293838ebf9e9d9..9b23425194298bac1da4369f46d517829091a4e3 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_add_dir.c,v 1.1 2006/10/03 12:23:13 dillo Exp $
-
   zip_add_dir.c -- add directory
-  Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 #include <stdlib.h>
 #include <string.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_add_dir(struct zip *za, const char *name)
 {
     int len, ret;
diff --git a/ext/zip/lib/zip_alias.h b/ext/zip/lib/zip_alias.h
deleted file mode 100644 (file)
index 27a7b45..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-
-#define zip_source_cmd php_ziplib__zip_source_cmd
-#define zip_source_callback php_ziplib__zip_source_callback
-#define zip_stat php_ziplib__zip_stat
-#define zip php_ziplib__zip
-#define zip_file php_ziplib__zip_file
-#define zip_source php_ziplib__zip_source
-#define zip_add php_ziplib__zip_add
-#define zip_add_dir php_ziplib__zip_add_dir
-#define zip_close php_ziplib__zip_close
-#define zip_delete php_ziplib__zip_delete
-#define zip_error_clear php_ziplib__zip_error_clear
-#define zip_error_get php_ziplib__zip_error_get
-#define zip_error_get_sys_type php_ziplib__zip_error_get_sys_type
-#define zip_error_to_str php_ziplib__zip_error_to_str
-#define zip_fclose php_ziplib__zip_fclose
-#define zip_file_error_clear php_ziplib__zip_fille_error_clear
-#define zip_file_error_get php_ziplib__zip_file_error_get
-#define zip_file_strerror php_ziplib__zip_file_strerror
-#define zip_fopen php_ziplib__zip_fopen
-#define zip_fopen_index php_ziplib__zip_fopen_index
-#define zip_fread php_ziplib__zip_fread
-#define zip_get_archive_comment php_ziplib__zip_get_archive_comment
-#define zip_get_file_comment php_ziplib__zip_get_file_comment
-#define zip_get_name php_ziplib__zip_get_name
-#define zip_get_num_files php_ziplib__zip_get_num_files
-#define zip_name_locate php_ziplib__zip_name_locate
-#define zip_open php_ziplib__zip_open
-#define zip_rename php_ziplib__zip_rename
-#define zip_replace php_ziplib__zip_replace
-#define zip_set_archive_comment php_ziplib__zip_set_archive_comment
-#define zip_set_file_comment php_ziplib__zip_set_file_comment
-#define zip_source_buffer php_ziplib__zip_source_buffer
-#define zip_source_file php_ziplib__zip_source_file
-#define zip_source_filep php_ziplib__zip_source_filep
-#define zip_source_free php_ziplib__zip_source_free
-#define zip_source_function php_ziplib__zip_source_function
-#define zip_source_zip php_ziplib__zip_source_zip
-#define zip_stat php_ziplib__zip_stat
-#define zip_stat_index php_ziplib__zip_stat_index
-#define zip_stat_init php_ziplib__zip_stat_init
-#define zip_strerror php_ziplib__zip_strerror
-#define zip_unchange php_ziplib__zip_unchange
-#define zip_unchange_all php_ziplib__zip_unchange_all
-#define zip_unchange_archive php_ziplib__zip_unchange_archive
index 11ba8e223106e695f3c61bc83633d8d7c5feaaf1..c928b0671af534a148cd169e19dc7f71f7366d33 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_close.c,v 1.60 2006/05/09 17:21:47 wiz Exp $
-
   zip_close.c -- close zip archive and update changes
-  Copyright (C) 1999, 2004, 2005 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
+
+\f
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#ifndef _MSC_VER
-#include <unistd.h>
-#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 static int add_data(struct zip *, int, struct zip_dirent *, FILE *);
@@ -56,7 +53,9 @@ static int _zip_cdir_set_comment(struct zip_cdir *, struct zip *);
 static int _zip_changed(struct zip *, int *);
 static char *_zip_create_temp_output(struct zip *, FILE **);
 
-PHPZIPAPI int
+\f
+
+ZIP_EXTERN(int)
 zip_close(struct zip *za)
 {
     int survivors;
@@ -66,7 +65,12 @@ zip_close(struct zip *za)
     mode_t mask;
     struct zip_cdir *cd;
     struct zip_dirent de;
-               int rename_error = 0;
+    int reopen_on_error;
+
+    reopen_on_error = 0;
+
+    if (za == NULL)
+       return -1;
 
     if (!_zip_changed(za, &survivors)) {
        _zip_free(za);
@@ -130,7 +134,7 @@ zip_close(struct zip *za)
        }
        else {
            /* copy existing directory entries */
-           if (fseek(za->zp, za->cdir->entry[i].offset, SEEK_SET) != 0) {
+           if (fseeko(za->zp, za->cdir->entry[i].offset, SEEK_SET) != 0) {
                _zip_error_set(&za->error, ZIP_ER_SEEK, errno);
                error = 1;
                break;
@@ -139,12 +143,12 @@ zip_close(struct zip *za)
                error = 1;
                break;
            }
-
-               if (de.bitflags & ZIP_GPBF_USE_DATA_DESCRIPTOR) {
-                       de.crc = (za->cdir->entry+i)->crc;
-                       de.comp_size = (za->cdir->entry+i)->comp_size;
-                       de.uncomp_size = (za->cdir->entry+i)->uncomp_size;
-               }
+           if (de.bitflags & ZIP_GPBF_DATA_DESCRIPTOR) {
+               de.crc = za->cdir->entry[i].crc;
+               de.comp_size = za->cdir->entry[i].comp_size;
+               de.uncomp_size = za->cdir->entry[i].uncomp_size;
+               //de.bitflags &= ~ZIP_GPBF_DATA_DESCRIPTOR;
+           }
            memcpy(cd->entry+j, za->cdir->entry+i, sizeof(cd->entry[j]));
        }
 
@@ -165,14 +169,13 @@ zip_close(struct zip *za)
            cd->entry[j].comment_len = za->entry[i].ch_comment_len;
        }
 
-       cd->entry[j].offset = ftell(out);
+       cd->entry[j].offset = ftello(out);
 
        if (ZIP_ENTRY_DATA_CHANGED(za->entry+i)) {
            if (add_data(za, i, &de, out) < 0) {
                error = 1;
                break;
            }
-
            cd->entry[j].last_mod = de.last_mod;
            cd->entry[j].comp_method = de.comp_method;
            cd->entry[j].comp_size = de.comp_size;
@@ -185,7 +188,8 @@ zip_close(struct zip *za)
                break;
            }
            /* we just read the local dirent, file is at correct position */
-           if (copy_data(za->zp, de.comp_size, out, &za->error) < 0) {
+           if (copy_data(za->zp, cd->entry[j].comp_size, out,
+                         &za->error) < 0) {
                error = 1;
                break;
            }
@@ -220,34 +224,28 @@ zip_close(struct zip *za)
        return -1;
     }
 
-   if (za->zp) {
+    if (za->zp) {
        fclose(za->zp);
        za->zp = NULL;
+       reopen_on_error = 1;
     }
-
-#ifdef PHP_WIN32 
-       if (!MoveFileEx(temp, za->zn, MOVEFILE_REPLACE_EXISTING)) {
-               rename_error = -1;
-       }
-#else
-       if (rename(temp, za->zn) != 0) {
-               rename_error = -1;
-       }
-#endif
-
-       if (rename_error < 0) {
-               _zip_error_set(&za->error, ZIP_ER_RENAME, errno);
-               remove(temp);
-               free(temp);
-               return -1;
+    if (_zip_rename(temp, za->zn) != 0) {
+       _zip_error_set(&za->error, ZIP_ER_RENAME, errno);
+       remove(temp);
+       free(temp);
+       if (reopen_on_error) {
+           /* ignore errors, since we're already in an error case */
+           za->zp = fopen(za->zn, "rb");
        }
-
+       return -1;
+    }
     mask = umask(0);
     umask(mask);
     chmod(za->zn, 0666&~mask);
 
     _zip_free(za);
-       free(temp);
+    free(temp);
+
     return 0;
 }
 
@@ -274,7 +272,7 @@ add_data(struct zip *za, int idx, struct zip_dirent *de, FILE *ft)
        return -1;
     }
 
-    offstart = ftell(ft);
+    offstart = ftello(ft);
 
     if (_zip_dirent_write(de, ft, 1, &za->error) < 0)
        return -1;
@@ -293,9 +291,9 @@ add_data(struct zip *za, int idx, struct zip_dirent *de, FILE *ft)
        return -1;
     }
 
-    offend = ftell(ft);
+    offend = ftello(ft);
 
-    if (fseek(ft, offstart, SEEK_SET) < 0) {
+    if (fseeko(ft, offstart, SEEK_SET) < 0) {
        _zip_error_set(&za->error, ZIP_ER_SEEK, errno);
        return -1;
     }
@@ -309,7 +307,7 @@ add_data(struct zip *za, int idx, struct zip_dirent *de, FILE *ft)
     if (_zip_dirent_write(de, ft, 1, &za->error) < 0)
        return -1;
 
-    if (fseek(ft, offend, SEEK_SET) < 0) {
+    if (fseeko(ft, offend, SEEK_SET) < 0) {
        _zip_error_set(&za->error, ZIP_ER_SEEK, errno);
        return -1;
     }
@@ -527,14 +525,13 @@ _zip_create_temp_output(struct zip *za, FILE **outp)
     char *temp;
     int tfd;
     FILE *tfp;
-    int len = strlen(za->zn) + 8;
 
-    if ((temp=(char *)malloc(len)) == NULL) {
+    if ((temp=(char *)malloc(strlen(za->zn)+8)) == NULL) {
        _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
        return NULL;
     }
 
-    snprintf(temp, len, "%s.XXXXXX", za->zn);
+    sprintf(temp, "%s.XXXXXX", za->zn);
 
     if ((tfd=mkstemp(temp)) == -1) {
        _zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno);
@@ -549,9 +546,6 @@ _zip_create_temp_output(struct zip *za, FILE **outp)
        free(temp);
        return NULL;
     }
-#ifdef PHP_WIN32
-       _setmode(_fileno(tfp), _O_BINARY );
-#endif
 
     *outp = tfp;
     return temp;
index eb5055b687d5e34b2c634c22b39d5bb71ebf8dbb..4591ff7f86a0fea58328db361c46fba840f7b64a 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_delete.c,v 1.17 2005/06/09 19:57:09 dillo Exp $
-
   zip_delete.c -- delete file from zip archive
-  Copyright (C) 1999, 2004, 2005 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_delete(struct zip *za, int idx)
 {
     if (idx < 0 || idx >= za->nentry) {
index f796f8d669003cff4692c095192897ac6880a3b3..7b953596ad4fdc3ab544f4ec687605d8d5b34ee2 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_dirent.c,v 1.9 2006/04/23 14:51:45 wiz Exp $
-
   zip_dirent.c -- read directory entry (local or central), clean dirent
-  Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-#include "main/php_reentrancy.h"
+\f
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#ifndef _MSC_VER
-#include <unistd.h>
-#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 static time_t _zip_d2u_time(int, int);
@@ -56,7 +51,7 @@ static void _zip_write4(unsigned int, FILE *);
 
 \f
 
-PHPZIPAPI void
+void
 _zip_cdir_free(struct zip_cdir *cd)
 {
     int i;
@@ -73,7 +68,7 @@ _zip_cdir_free(struct zip_cdir *cd)
 
 \f
 
-PHPZIPAPI struct zip_cdir *
+struct zip_cdir *
 _zip_cdir_new(int nentry, struct zip_error *error)
 {
     struct zip_cdir *cd;
@@ -102,19 +97,19 @@ _zip_cdir_new(int nentry, struct zip_error *error)
 
 \f
 
-PHPZIPAPI int
+int
 _zip_cdir_write(struct zip_cdir *cd, FILE *fp, struct zip_error *error)
 {
     int i;
 
-    cd->offset = ftell(fp);
+    cd->offset = ftello(fp);
 
     for (i=0; i<cd->nentry; i++) {
        if (_zip_dirent_write(cd->entry+i, fp, 0, error) != 0)
            return -1;
     }
 
-    cd->size = ftell(fp) - cd->offset;
+    cd->size = ftello(fp) - cd->offset;
     
     /* clearerr(fp); */
     fwrite(EOCD_MAGIC, 1, 4, fp);
@@ -136,7 +131,7 @@ _zip_cdir_write(struct zip_cdir *cd, FILE *fp, struct zip_error *error)
 
 \f
 
-PHPZIPAPI void
+void
 _zip_dirent_finalize(struct zip_dirent *zde)
 {
     free(zde->filename);
@@ -149,7 +144,7 @@ _zip_dirent_finalize(struct zip_dirent *zde)
 
 \f
 
-PHPZIPAPI void
+void
 _zip_dirent_init(struct zip_dirent *de)
 {
     de->version_madeby = 0;
@@ -188,7 +183,7 @@ _zip_dirent_init(struct zip_dirent *de)
    returned.
 */
 
-PHPZIPAPI int
+int
 _zip_dirent_read(struct zip_dirent *zde, FILE *fp,
                 unsigned char **bufp, unsigned int left, int localp,
                 struct zip_error *error)
@@ -333,7 +328,7 @@ _zip_dirent_read(struct zip_dirent *zde, FILE *fp,
    returned.
 */
 
-PHPZIPAPI int
+int
 _zip_dirent_write(struct zip_dirent *zde, FILE *fp, int localp,
                  struct zip_error *error)
 {
@@ -390,11 +385,13 @@ _zip_dirent_write(struct zip_dirent *zde, FILE *fp, int localp,
 static time_t
 _zip_d2u_time(int dtime, int ddate)
 {
-    struct tm *tm, tmbuf;
+    struct tm *tm;
     time_t now;
 
     now = time(NULL);
-    tm = php_localtime_r(&now, &tmbuf);
+    tm = localtime(&now);
+    /* let mktime decide if DST is in effect */
+    tm->tm_isdst = -1;
     
     tm->tm_year = ((ddate>>9)&127) + 1980 - 1900;
     tm->tm_mon = ((ddate>>5)&15) - 1;
@@ -409,7 +406,7 @@ _zip_d2u_time(int dtime, int ddate)
 
 \f
 
-PHPZIPAPI unsigned short
+unsigned short
 _zip_read2(unsigned char **a)
 {
     unsigned short ret;
@@ -422,7 +419,7 @@ _zip_read2(unsigned char **a)
 
 \f
 
-PHPZIPAPI unsigned int
+unsigned int
 _zip_read4(unsigned char **a)
 {
     unsigned int ret;
@@ -519,9 +516,9 @@ _zip_write4(unsigned int i, FILE *fp)
 static void
 _zip_u2d_time(time_t time, unsigned short *dtime, unsigned short *ddate)
 {
-    struct tm *tm, tmbuf;
+    struct tm *tm;
 
-    tm = php_localtime_r(&time, &tmbuf);
+    tm = localtime(&time);
     *ddate = ((tm->tm_year+1900-1980)<<9) + ((tm->tm_mon+1)<<5)
        + tm->tm_mday;
     *dtime = ((tm->tm_hour)<<11) + ((tm->tm_min)<<5)
index 1bab313ed5e612d1efdcc063a67297a9c72a88c2..c50c9434bdd93a138f02bf6bf917bc68fdda64ae 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_entry_free.c,v 1.2 2006/04/09 19:05:47 wiz Exp $
-
   zip_entry_free.c -- free struct zip_entry
-  Copyright (C) 1999, 2003, 2004, 2006 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 #include <stdlib.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI void
+void
 _zip_entry_free(struct zip_entry *ze)
 {
     free(ze->ch_filename);
index 67e13fd84ab6ef078ddefd6a7872cdfc596d08b4..7059b1b060749d93cacfb7f499b1b072a25eee54 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_entry_new.c,v 1.2 2006/04/09 19:05:47 wiz Exp $
-
   zip_entry_new.c -- create and init struct zip_entry
-  Copyright (C) 1999, 2003, 2004, 2006 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 #include <stdlib.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI struct zip_entry *
+struct zip_entry *
 _zip_entry_new(struct zip *za)
 {
     struct zip_entry *ze;
index c74538d64a22766e7996db30786417d52219026f..ce1652a701291ac7d79d49cef9968f9b6adca2ba 100644 (file)
@@ -1,12 +1,8 @@
 /*
-   This file was generated automatically by ./make_zip_err_str.sh
-   from ./zip.h; make changes there.
-
-       NiH: make_zip_err_str.sh,v 1.8 2004/11/17 21:55:09 wiz Exp 
-       NiH: zip.h,v 1.57 2006/04/24 14:04:19 dillo Exp
+   This file was generated automatically by make_zip_err_str.sh
+   from zip.h; make changes there.
  */
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
index 4816b73aea08825589acb99d9a345e36326497dd..aab70794566c0d2e248e88dada5c08827e70bcc4 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_error.c,v 1.7 2005/06/09 19:57:09 dillo Exp $
-
   zip_error.c -- struct zip_error helper functions
-  Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 #include <stdlib.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI void
+void
 _zip_error_clear(struct zip_error *err)
 {
     err->zip_err = ZIP_ER_OK;
@@ -51,7 +48,7 @@ _zip_error_clear(struct zip_error *err)
 
 \f
 
-PHPZIPAPI void
+void
 _zip_error_copy(struct zip_error *dst, struct zip_error *src)
 {
     dst->zip_err = src->zip_err;
@@ -60,7 +57,7 @@ _zip_error_copy(struct zip_error *dst, struct zip_error *src)
 
 \f
 
-PHPZIPAPI void
+void
 _zip_error_fini(struct zip_error *err)
 {
     free(err->str);
@@ -69,7 +66,7 @@ _zip_error_fini(struct zip_error *err)
 
 \f
 
-PHPZIPAPI void
+void
 _zip_error_get(struct zip_error *err, int *zep, int *sep)
 {
     if (zep)
@@ -84,7 +81,7 @@ _zip_error_get(struct zip_error *err, int *zep, int *sep)
 
 \f
 
-PHPZIPAPI void
+void
 _zip_error_init(struct zip_error *err)
 {
     err->zip_err = ZIP_ER_OK;
@@ -94,7 +91,7 @@ _zip_error_init(struct zip_error *err)
 
 \f
 
-PHPZIPAPI void
+void
 _zip_error_set(struct zip_error *err, int ze, int se)
 {
     if (err) {
index 8a76f444001f7d39d986f85ada3be5505f466761..34e7dea48ebbaaa0719c8d7e6a07ad19f9bf09e3 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_error_clear.c,v 1.1 2006/10/04 15:21:09 dillo Exp $
-
   zip_error_clear.c -- clear zip error
-  Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI void
+ZIP_EXTERN(void)
 zip_error_clear(struct zip *za)
 {
     _zip_error_clear(&za->error);
index 888b5456935234ce923161594bb94b153f6350fe..c15705e32fccdd75ec6e7fa1a4894c87f0505f6c 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_error_get.c,v 1.1 2004/11/18 15:06:20 wiz Exp $
-
   zip_error_get.c -- get zip error
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI void
+ZIP_EXTERN(void)
 zip_error_get(struct zip *za, int *zep, int *sep)
 {
     _zip_error_get(&za->error, zep, sep);
index bfe6423836639e763ec85d7e2d14423cdca5a012..47aa93e69b927c44f416c2a6d8fb918914c4fe8c 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_error_get_sys_type.c,v 1.1 2004/12/22 15:49:18 wiz Exp $
-
   zip_error_get_sys_type.c -- return type of system error code
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_error_get_sys_type(int ze)
 {
     if (ze < 0 || ze >= _zip_nerr_str)
index 06e98c76d805bc8412de1b2b0126732deaac9833..3d0951cfb1f6b8697ac0e4db626787e62e2dfcfe 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_error_strerror.c,v 1.4 2006/02/21 09:41:00 dillo Exp $
-
   zip_error_sterror.c -- get string representation of struct zip_error
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 #include <stdlib.h>
 #include <string.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI const char *
+const char *
 _zip_error_strerror(struct zip_error *err)
 {
     const char *zs, *ss;
@@ -54,7 +51,7 @@ _zip_error_strerror(struct zip_error *err)
     _zip_error_fini(err);
 
     if (err->zip_err < 0 || err->zip_err >= _zip_nerr_str) {
-       snprintf(buf, sizeof(buf), "Unknown error %d", err->zip_err);
+       sprintf(buf, "Unknown error %d", err->zip_err);
        zs = NULL;
        ss = buf;
     }
@@ -78,16 +75,16 @@ _zip_error_strerror(struct zip_error *err)
     if (ss == NULL)
        return zs;
     else {
-    int l = strlen(ss) + (zs ? strlen(zs)+2 : 0) + 1;
-       if ((s=(char *)malloc(l)) == NULL)
+       if ((s=(char *)malloc(strlen(ss)
+                             + (zs ? strlen(zs)+2 : 0) + 1)) == NULL)
            return _zip_err_str[ZIP_ER_MEMORY];
        
-       snprintf(s, l, "%s%s%s",
+       sprintf(s, "%s%s%s",
                (zs ? zs : ""),
                (zs ? ": " : ""),
                ss);
        err->str = s;
 
-       return ss;
+       return s;
     }
 }
index 665803472e3a9cf729655329defd7156d6851ebd..4dea4d667a5ee28976564edd130fa9894e3339c7 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_error_to_str.c,v 1.1 2004/11/18 15:06:20 wiz Exp $
-
   zip_error_to_str.c -- get string representation of zip error code
-  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 #include <stdlib.h>
 #include <string.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_error_to_str(char *buf, size_t len, int ze, int se)
 {
     const char *zs, *ss;
index 91f30b7bb9bf8363dba2c5da9f3427f2f1e90286..6bf697301ae827709321948bb296c91f0aa4b427 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_fclose.c,v 1.14 2005/06/09 19:57:09 dillo Exp $
-
   zip_fclose.c -- close file in zip archive
-  Copyright (C) 1999, 2004, 2005 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 #include <stdlib.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_fclose(struct zip_file *zf)
 {
     int i, ret;
@@ -51,15 +48,14 @@ zip_fclose(struct zip_file *zf)
        inflateEnd(zf->zstr);
     free(zf->buffer);
     free(zf->zstr);
-
        if (zf->za) {
-               for (i=0; i<zf->za->nfile; i++) {
-                       if (zf->za->file[i] == zf) {
-                               zf->za->file[i] = zf->za->file[zf->za->nfile-1];
-                               zf->za->nfile--;
-                               break;
-                       }
-               }
+    for (i=0; i<zf->za->nfile; i++) {
+       if (zf->za->file[i] == zf) {
+           zf->za->file[i] = zf->za->file[zf->za->nfile-1];
+           zf->za->nfile--;
+           break;
+       }
+    }
        }
 
     ret = 0;
index dca33b35f70d25ba7e3c8ae0b79e39aba08cc3a3..6c9c2a02b3f0f54528efe829624c654cf0f7b7fd 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_file_error_clear.c,v 1.4 2006/10/04 18:37:54 wiz Exp $
-
   zip_file_error_clear.c -- clear zip file error
-  Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI void
+ZIP_EXTERN(void)
 zip_file_error_clear(struct zip_file *zf)
 {
     _zip_error_clear(&zf->error);
index 05516703c689b4da57d13f0763dbde6de67aef6f..a53fa7e0033243c236fea130160980d8e28739ad 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_file_error_get.c,v 1.1 2004/11/18 15:06:21 wiz Exp $
-
   zip_file_error_get.c -- get zip file error
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI void
+ZIP_EXTERN(void)
 zip_file_error_get(struct zip_file *zf, int *zep, int *sep)
 {
     _zip_error_get(&zf->error, zep, sep);
index 4930040235a360cf0bc614d84247447e93a6a978..68f92f1fe61b70489361a088f275b866e280b6a9 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_file_get_offset.c,v 1.4 2006/04/23 14:51:45 wiz Exp $
-
   zip_file_get_offset.c -- get offset of file data in archive.
-  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#ifndef _MSC_VER
-#include <unistd.h>
-#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
@@ -56,7 +50,7 @@
    On error, fills in za->error and returns 0.
 */
 
-PHPZIPAPI unsigned int
+unsigned int
 _zip_file_get_offset(struct zip *za, int idx)
 {
     struct zip_dirent de;
@@ -64,7 +58,7 @@ _zip_file_get_offset(struct zip *za, int idx)
 
     offset = za->cdir->entry[idx].offset;
 
-    if (fseek(za->zp, offset, SEEK_SET) != 0) {
+    if (fseeko(za->zp, offset, SEEK_SET) != 0) {
        _zip_error_set(&za->error, ZIP_ER_SEEK, errno);
        return 0;
     }
index 2cc79c13338369aa1cfec37e55e160875ac30f4e..c2864f2ba1aafeb42bb2816e2e3ae17ae016dfeb 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_file_strerror.c,v 1.1 2003/10/05 16:05:22 dillo Exp $
-
   zip_file_sterror.c -- get string representation of zip file error
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI const char *
+ZIP_EXTERN(const char *)
 zip_file_strerror(struct zip_file *zf)
 {
     return _zip_error_strerror(&zf->error);
index c05ad45bd67921ba1db9ecff6957c8d948e82d5b..b4b76049f4430e625d456537d349ba14b9880d18 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_fopen.c,v 1.12 2005/06/09 19:57:09 dillo Exp $
-
   zip_fopen.c -- open file in zip archive for reading
-  Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI struct zip_file *
+ZIP_EXTERN(struct zip_file *)
 zip_fopen(struct zip *za, const char *fname, int flags)
 {
     int idx;
index 105cefe738bb3950ba881e36f5382c311be6d8a9..1e7e4198970aa073fe662f711d24329abad4f8d6 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_fopen_index.c,v 1.24 2005/05/20 21:54:53 wiz Exp $
-
   zip_fopen_index.c -- open file in zip archive for reading by index
-  Copyright (C) 1999, 2004, 2005 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 static struct zip_file *_zip_file_new(struct zip *za);
 
 \f
 
-PHPZIPAPI struct zip_file *
+ZIP_EXTERN(struct zip_file *)
 zip_fopen_index(struct zip *za, int fileno, int flags)
 {
     int len, ret;
@@ -141,7 +138,7 @@ zip_fopen_index(struct zip *za, int fileno, int flags)
 
 \f
 
-PHPZIPAPI int
+int
 _zip_file_fillbuf(void *buf, size_t buflen, struct zip_file *zf)
 {
     int i, j;
@@ -152,7 +149,7 @@ _zip_file_fillbuf(void *buf, size_t buflen, struct zip_file *zf)
     if ((zf->flags & ZIP_ZF_EOF) || zf->cbytes_left <= 0 || buflen <= 0)
        return 0;
     
-    if (fseek(zf->za->zp, zf->fpos, SEEK_SET) < 0) {
+    if (fseeko(zf->za->zp, zf->fpos, SEEK_SET) < 0) {
        _zip_error_set(&zf->error, ZIP_ER_SEEK, errno);
        return -1;
     }
index 064d2b97fb6cd467cff2797d04ce90ad5d3aa7c5..1c0c8ac631c55579d314d25483602bb2c0c70b40 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_fread.c,v 1.21 2006/04/23 14:49:50 wiz Exp $
-
   zip_fread.c -- read from file
-  Copyright (C) 1999, 2004, 2005 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI ssize_t
+ZIP_EXTERN(ssize_t)
 zip_fread(struct zip_file *zf, void *outbuf, size_t toread)
 {
     int ret;
-       size_t out_before, len;
+    size_t out_before, len;
     int i;
 
     if (!zf)
index 534c58eb07a3836ba17ed50a575e0b68689ede69..76c3a9673ff539433d4515d40cbecebfd4521dc7 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_free.c,v 1.17 2005/06/09 19:57:10 dillo Exp $
-
   zip_free.c -- free struct zip
-  Copyright (C) 1999, 2004, 2005 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
@@ -36,7 +34,7 @@
 \f
 
 #include <stdlib.h>
-#include "zip.h"
+
 #include "zipint.h"
 
 \f
@@ -45,7 +43,7 @@
    frees the space allocated to a zipfile struct, and closes the
    corresponding file. */
 
-PHPZIPAPI void
+void
 _zip_free(struct zip *za)
 {
     int i;
@@ -59,9 +57,6 @@ _zip_free(struct zip *za)
     if (za->zp)
        fclose(za->zp);
 
-    if (za->ch_comment)
-       free(za->ch_comment);
-
     _zip_cdir_free(za->cdir);
 
     if (za->entry) {
index c23597c09687a5455119375710d2128407e24c9b..fe97e6e8c18a1fd8dc6945ee3b58e91c4ed33be9 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_get_archive_comment.c,v 1.4 2006/04/23 16:11:33 wiz Exp $
-
   zip_get_archive_comment.c -- get archive comment
-  Copyright (C) 2006 Dieter Baron and Thomas Klausner
+  Copyright (C) 2006-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI const char *
+ZIP_EXTERN(const char *)
 zip_get_archive_comment(struct zip *za, int *lenp, int flags)
 {
     if ((flags & ZIP_FL_UNCHANGED)
        || (za->ch_comment_len == -1)) {
-               if (za->cdir) {
-                       if (lenp != NULL)
-                               *lenp = za->cdir->comment_len;
-                       return za->cdir->comment;
-               }
+       if (za->cdir) {
+           if (lenp != NULL)
+               *lenp = za->cdir->comment_len;
+           return za->cdir->comment;
+       }
+       else {
+           if (lenp != NULL)
+               *lenp = -1;
+           return NULL;
+       }
     }
     
     if (lenp != NULL)
index 476ac7da0b2ca3110124f62772248c65fb34f724..57dd9028bc1387b7a5f8fa616382aa79b183454a 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_get_file_comment.c,v 1.2 2006/04/23 13:06:28 wiz Exp $
-
   zip_get_file_comment.c -- get file comment
-  Copyright (C) 2006 Dieter Baron and Thomas Klausner
+  Copyright (C) 2006-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI const char *
+ZIP_EXTERN(const char *)
 zip_get_file_comment(struct zip *za, int idx, int *lenp, int flags)
 {
     if (idx < 0 || idx >= za->nentry) {
index c2cae2518eeaba737191bfa6b614c9772a9f1efe..b58d972058897e4f9c218f2d8043f33ce61d8a58 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_get_name.c,v 1.13 2005/01/20 21:00:54 dillo Exp $
-
   zip_get_name.c -- get filename for a file in zip file
-  Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI const char *
+ZIP_EXTERN(const char *)
 zip_get_name(struct zip *za, int idx, int flags)
 {
     return _zip_get_name(za, idx, flags, &za->error);
@@ -48,7 +45,7 @@ zip_get_name(struct zip *za, int idx, int flags)
 
 \f
 
-PHPZIPAPI const char *
+const char *
 _zip_get_name(struct zip *za, int idx, int flags, struct zip_error *error)
 {
     if (idx < 0 || idx >= za->nentry) {
index 05a54fcb6c4eaab2eb744ba3ea67f0005cf27a80..a442f293ec350a18a512c75d62c4815bd92f6799 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_get_num_files.c,v 1.2 2003/12/27 22:53:15 wiz Exp $
-
   zip_get_num_files.c -- get number of files in archive
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_get_num_files(struct zip *za)
 {
     if (za == NULL)
index ebb7426dd2498252f1f0b2c8ceda9c08969e77ef..641125ed2d1b21488e825e22743d25d2c8101294 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_memdup.c,v 1.2 2006/04/24 10:34:39 dillo Exp $
-
   zip_memdup.c -- internal zip function, "strdup" with len
-  Copyright (C) 1999, 2003, 2004, 2005, 2006 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 #include <stdlib.h>
 #include <string.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI void *
+void *
 _zip_memdup(const void *mem, size_t len, struct zip_error *error)
 {
     void *ret;
index 108db4f60913608cb35289346cb0a0ed2c405239..e8b35ff936ecd04a85eb7da86e8e27613d468c12 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_name_locate.c,v 1.19 2005/06/09 19:57:10 dillo Exp $
-
   zip_name_locate.c -- get index by name
-  Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
@@ -19,7 +17,7 @@
   3. The names of the authors may not be used to endorse or promote
      products derived from this software without specific prior
      written permission.
+
   THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
 #include <string.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_name_locate(struct zip *za, const char *fname, int flags)
 {
     return _zip_name_locate(za, fname, flags, &za->error);
@@ -50,7 +47,7 @@ zip_name_locate(struct zip *za, const char *fname, int flags)
 
 \f
 
-PHPZIPAPI int
+int
 _zip_name_locate(struct zip *za, const char *fname, int flags,
                 struct zip_error *error)
 {
@@ -62,11 +59,8 @@ _zip_name_locate(struct zip *za, const char *fname, int flags,
        _zip_error_set(error, ZIP_ER_INVAL, 0);
        return -1;
     }
-#ifdef PHP_WIN32
-       cmp = (flags & ZIP_FL_NOCASE) ? stricmp : strcmp;
-#else
-       cmp = (flags & ZIP_FL_NOCASE) ? strcasecmp : strcmp;
-#endif
+
+    cmp = (flags & ZIP_FL_NOCASE) ? strcmpi : strcmp;
 
     n = (flags & ZIP_FL_UNCHANGED) ? za->cdir->nentry : za->nentry;
     for (i=0; i<n; i++) {
@@ -78,7 +72,7 @@ _zip_name_locate(struct zip *za, const char *fname, int flags,
        /* newly added (partially filled) entry */
        if (fn == NULL)
            continue;
-       
+
        if (flags & ZIP_FL_NODIR) {
            p = strrchr(fn, '/');
            if (p)
@@ -89,6 +83,7 @@ _zip_name_locate(struct zip *za, const char *fname, int flags,
            return i;
     }
 
-    _zip_error_set(error, ZIP_ER_NOENT, 0);
+/* Look for an entry should not raise an error  */
+/*    _zip_error_set(error, ZIP_ER_NOENT, 0);*/
     return -1;
 }
index 378513b6cfbf7fb8bca1e1573ada33556de105a5..3e8ccee644bc2e091a3d0c89a204abf95c7f4723 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_new.c,v 1.12 2006/04/23 00:40:47 wiz Exp $
-
   zip_new.c -- create and init struct zip
-  Copyright (C) 1999, 2004, 2005 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
@@ -36,7 +34,7 @@
 \f
 
 #include <stdlib.h>
-#include "zip.h"
+
 #include "zipint.h"
 
 \f
@@ -45,7 +43,7 @@
    creates a new zipfile struct, and sets the contents to zero; returns
    the new struct. */
 
-PHPZIPAPI struct zip *
+struct zip *
 _zip_new(struct zip_error *error)
 {
     struct zip *za;
@@ -66,6 +64,7 @@ _zip_new(struct zip_error *error)
     za->entry = NULL;
     za->nfile = za->nfile_alloc = 0;
     za->file = NULL;
+    za->flags = za->ch_flags = 0;
     
     return za;
 }
index 711dcb1cac4e619448558cd58420f63d7b0407fb..7247b7b8d699c37b15a40e01e35682cbe14c5bfe 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_open.c,v 1.38 2006/05/04 00:01:26 dillo Exp $
-
   zip_open.c -- open zip archive
   Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 #include <sys/stat.h>
 #include <errno.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifndef _MSC_VER
-#include <unistd.h>
-#endif
-#include <sys/types.h>
-#include "zip.h"
+
 #include "zipint.h"
 
 static void set_error(int *, struct zip_error *, int);
+static struct zip *_zip_allocate_new(const char *, int *);
 static int _zip_checkcons(FILE *, struct zip_cdir *, struct zip_error *);
+static void _zip_check_torrentzip(struct zip *);
+static struct zip_cdir *_zip_find_central_dir(FILE *, int, int *, off_t);
+static int _zip_file_exists(const char *, int, int *);
 static int _zip_headercomp(struct zip_dirent *, int,
                           struct zip_dirent *, int);
 static unsigned char *_zip_memmem(const unsigned char *, int,
@@ -58,154 +57,55 @@ static struct zip_cdir *_zip_readcdir(FILE *, unsigned char *, unsigned char *,
 
 \f
 
-PHPZIPAPI struct zip *
+ZIP_EXTERN(struct zip *)
 zip_open(const char *fn, int flags, int *zep)
 {
     FILE *fp;
-    unsigned char *buf, *match;
-    int a, i, buflen, best;
     struct zip *za;
-    struct zip_cdir *cdir, *cdirnew;
-    long len;
-    struct stat st;
-    struct zip_error error, err2;
-
-    if (fn == NULL) {
-       set_error(zep, NULL, ZIP_ER_INVAL);
+    struct zip_cdir *cdir;
+    int i;
+    off_t len;
+    
+    switch (_zip_file_exists(fn, flags, zep)) {
+    case -1:
        return NULL;
+    case 0:
+       return _zip_allocate_new(fn, zep);
+    default:
+       break;
     }
 
-    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;
-           }
-           
-           za->zn = strdup(fn);
-           if (!za->zn) {
-               _zip_free(za);
-               set_error(zep, NULL, ZIP_ER_MEMORY);
-               return NULL;
-           }
-           return za;
-       }
-       else {
-           set_error(zep, NULL, ZIP_ER_OPEN);
-           return NULL;
-       }
-    }
-    else if ((flags & ZIP_EXCL)) {
-       set_error(zep, NULL, ZIP_ER_EXISTS);
+    if ((fp=fopen(fn, "rb")) == NULL) {
+       set_error(zep, NULL, ZIP_ER_OPEN);
        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;
-       }
-
-#ifdef PHP_WIN32
-       _setmode(_fileno(fp), _O_BINARY );
-#endif
-
-    clearerr(fp);
-    fseek(fp, 0, SEEK_END);
-    len = ftell(fp);
-    i = fseek(fp, -(len < CDBUFSIZE ? len : CDBUFSIZE), SEEK_END);
-    if (i == -1 && errno != EFBIG) {
-       /* seek before start of file on my machine */
-       set_error(zep, NULL, ZIP_ER_SEEK);
-       fclose(fp);
-       return NULL;
-    }
+    fseeko(fp, 0, SEEK_END);
+    len = ftello(fp);
 
-    /* 64k is too much for stack */
-    if ((buf=(unsigned char *)malloc(CDBUFSIZE)) == NULL) {
-       set_error(zep, NULL, ZIP_ER_MEMORY);
-       fclose(fp);
-       return NULL;
+    /* treat empty files as empty archives */
+    if (len == 0) {
+       if ((za=_zip_allocate_new(fn, zep)) == NULL)
+           fclose(fp);
+       else
+           za->zp = fp;
+       return za;
     }
 
-    clearerr(fp);
-    buflen = fread(buf, 1, CDBUFSIZE, fp);
-
-    if (ferror(fp)) {
-       set_error(zep, NULL, ZIP_ER_READ);
-       free(buf);
+    cdir = _zip_find_central_dir(fp, flags, zep, len);
+    if (cdir == NULL) {
        fclose(fp);
        return NULL;
     }
-    
-    best = -2;
-    cdir = NULL;
-    match = buf;
-    while ((match=_zip_memmem(match, buflen-(match-buf)-18,
-                             (const unsigned char *)EOCD_MAGIC, 4))!=NULL) {
-       /* found match -- check, if good */
-       /* to avoid finding the same match all over again */
-       match++;
-       if ((cdirnew=_zip_readcdir(fp, buf, match-1, buflen, flags,
-                                  &err2)) == NULL) {
-           if (best == -2) {
-               set_error(zep, &err2, 0);
-               best = -1;
-           }
-           continue;
-       }
 
-       if (cdir) {
-           if (best <= 0)
-               best = _zip_checkcons(fp, cdir, &err2);
-           a = _zip_checkcons(fp, cdirnew, &err2);
-           if (best < a) {
-               _zip_cdir_free(cdir);
-               cdir = cdirnew;
-               best = a;
-           }
-           else
-               _zip_cdir_free(cdirnew);
-       }
-       else {
-           cdir = cdirnew;
-           if (flags & ZIP_CHECKCONS)
-               best = _zip_checkcons(fp, cdir, &err2);
-           else
-               best = 0;
-       }
-       cdirnew = NULL;
-    }
-
-    free(buf);
-    
-    if (best < 0) {
-       /* no consistent eocd found */
-       if (best == -2) {
-           /* no eocd found at all */
-           set_error(zep, NULL, ZIP_ER_NOZIP);
-       }
-       _zip_cdir_free(cdir);
-       fclose(fp);
-       return NULL;
-    }
-
-    if ((za=_zip_new(&error)) == NULL) {
-       set_error(zep, &error, 0);
+    if ((za=_zip_allocate_new(fn, zep)) == NULL) {
        _zip_cdir_free(cdir);
        fclose(fp);
        return NULL;
     }
 
-    za->zp = fp;
     za->cdir = cdir;
-    
-    if ((za->zn=strdup(fn)) == NULL) {
-       set_error(zep, NULL, ZIP_ER_MEMORY);
-       _zip_free(za);
-       return NULL;
-    }
+    za->zp = fp;
 
     if ((za->entry=(struct zip_entry *)malloc(sizeof(*(za->entry))
                                              * cdir->nentry)) == NULL) {
@@ -216,6 +116,9 @@ zip_open(const char *fn, int flags, int *zep)
     for (i=0; i<cdir->nentry; i++)
        _zip_entry_new(za);
 
+    _zip_check_torrentzip(za);
+    za->ch_flags = za->flags;
+
     return za;
 }
 
@@ -295,13 +198,14 @@ _zip_readcdir(FILE *fp, unsigned char *buf, unsigned char *eocd, int buflen,
        return NULL;
     }
 
-    if (cd->comment_len)
+    if (cd->comment_len) {
        if ((cd->comment=(char *)_zip_memdup(eocd+EOCDLEN,
                                             cd->comment_len, error))
            == NULL) {
            free(cd);
            return NULL;
        }
+    }
 
     cdp = eocd;
     if (cd->size < (unsigned int)(eocd-buf)) {
@@ -313,8 +217,10 @@ _zip_readcdir(FILE *fp, unsigned char *buf, unsigned char *eocd, int buflen,
        /* go to start of cdir and read it entry by entry */
        bufp = NULL;
        clearerr(fp);
-       fseek(fp, -(cd->size+cd->comment_len+EOCDLEN), SEEK_END);
-       if (ferror(fp) || ((unsigned int)ftell(fp) != cd->offset)) {
+       fseeko(fp, cd->offset, SEEK_SET);
+       /* possible consistency check: cd->offset =
+          len-(cd->size+cd->comment_len+EOCDLEN) ? */
+       if (ferror(fp) || ((unsigned long)ftello(fp) != cd->offset)) {
            /* seek error or offset of cdir wrong */
            if (ferror(fp))
                _zip_error_set(error, ZIP_ER_SEEK, errno);
@@ -376,7 +282,7 @@ _zip_checkcons(FILE *fp, struct zip_cdir *cd, struct zip_error *error)
            return -1;
        }
        
-       if (fseek(fp, cd->entry[i].offset, SEEK_SET) != 0) {
+       if (fseeko(fp, cd->entry[i].offset, SEEK_SET) != 0) {
            _zip_error_set(error, ZIP_ER_SEEK, 0);
            return -1;
        }
@@ -385,7 +291,7 @@ _zip_checkcons(FILE *fp, struct zip_cdir *cd, struct zip_error *error)
            return -1;
        
        if (_zip_headercomp(cd->entry+i, 0, &temp, 1) != 0) {
-           _zip_error_set(error, ZIP_ER_NOZIP, 0);
+           _zip_error_set(error, ZIP_ER_INCONS, 0);
            _zip_dirent_finalize(&temp);
            return -1;
        }
@@ -395,6 +301,52 @@ _zip_checkcons(FILE *fp, struct zip_cdir *cd, struct zip_error *error)
     return max - min;
 }
 
+\f
+
+/* _zip_check_torrentzip:
+   check wether ZA has a valid TORRENTZIP comment, i.e. is torrentzipped */
+
+static void
+_zip_check_torrentzip(struct zip *za)
+{
+    uLong crc_got, crc_should;
+    char *end;
+    Bytef buf[BUFSIZE];
+    unsigned int n, remain;
+
+    if (za->zp == NULL || za->cdir == NULL)
+       return;
+
+    if (za->cdir->comment_len != TORRENT_SIG_LEN+8
+       || strncmp(za->cdir->comment, TORRENT_SIG, TORRENT_SIG_LEN) != 0)
+       return;
+    
+    errno = 0;
+    crc_should = strtoul(za->cdir->comment+TORRENT_SIG_LEN, &end, 16);
+    if ((crc_should == UINT_MAX && errno != 0) || (end && *end))
+       return;
+    
+    crc_got = crc32(0L, Z_NULL, 0);
+
+    if (fseek(za->zp, za->cdir->offset, SEEK_SET) != 0)
+       return;
+    remain = za->cdir->size;
+
+    while (remain > 0) {
+       n = remain > BUFSIZE ? BUFSIZE : remain;
+       if ((n=fread(buf, 1, n, za->zp)) <= 0)
+           return;
+
+       crc_got = crc32(crc_got, buf, n);
+
+       remain -= n;
+    }
+
+    if (crc_got == crc_should)
+       za->flags |= ZIP_AFL_TORRENT;
+}
+
+
 \f
 
 /* _zip_headercomp:
@@ -414,14 +366,32 @@ _zip_headercomp(struct zip_dirent *h1, int local1p, struct zip_dirent *h2,
 #endif
        || (h1->comp_method != h2->comp_method)
        || (h1->last_mod != h2->last_mod)
-       || (h1->crc != h2->crc)
-       || (h1->comp_size != h2->comp_size)
-       || (h1->uncomp_size != h2->uncomp_size)
        || (h1->filename_len != h2->filename_len)
        || !h1->filename || !h2->filename
        || strcmp(h1->filename, h2->filename))
        return -1;
 
+    /* check that CRC and sizes are zero if data descriptor is used */
+    if ((h1->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) && local1p
+       && (h1->crc != 0
+           || h1->comp_size != 0
+           || h1->uncomp_size != 0))
+       return -1;
+    if ((h2->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) && local2p
+       && (h2->crc != 0
+           || h2->comp_size != 0
+           || h2->uncomp_size != 0))
+       return -1;
+    
+    /* check that CRC and sizes are equal if no data descriptor is used */
+    if (((h1->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) == 0 || local1p == 0)
+       && ((h2->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) == 0 || local2p == 0)) {
+       if ((h1->crc != h2->crc)
+           || (h1->comp_size != h2->comp_size)
+           || (h1->uncomp_size != h2->uncomp_size))
+           return -1;
+    }
+    
     if ((local1p == local2p)
        && ((h1->extrafield_len != h2->extrafield_len)
            || (h1->extrafield_len && h2->extrafield
@@ -448,6 +418,137 @@ _zip_headercomp(struct zip_dirent *h1, int local1p, struct zip_dirent *h2,
 
 \f
 
+static struct zip *
+_zip_allocate_new(const char *fn, int *zep)
+{
+    struct zip *za;
+    struct zip_error error;
+
+    if ((za=_zip_new(&error)) == NULL) {
+       set_error(zep, &error, 0);
+       return NULL;
+    }
+       
+    za->zn = strdup(fn);
+    if (!za->zn) {
+       _zip_free(za);
+       set_error(zep, NULL, ZIP_ER_MEMORY);
+       return NULL;
+    }
+    return za;
+}
+
+\f
+
+static int
+_zip_file_exists(const char *fn, int flags, int *zep)
+{
+    struct stat st;
+
+    if (fn == NULL) {
+       set_error(zep, NULL, ZIP_ER_INVAL);
+       return -1;
+    }
+    
+    if (stat(fn, &st) != 0) {
+       if (flags & ZIP_CREATE)
+           return 0;
+       else {
+           set_error(zep, NULL, ZIP_ER_OPEN);
+           return -1;
+       }
+    }
+    else if ((flags & ZIP_EXCL)) {
+       set_error(zep, NULL, ZIP_ER_EXISTS);
+       return -1;
+    }
+    /* ZIP_CREATE gets ignored if file exists and not ZIP_EXCL,
+       just like open() */
+
+    return 1;
+}
+
+\f
+
+static struct zip_cdir *
+_zip_find_central_dir(FILE *fp, int flags, int *zep, off_t len)
+{
+    struct zip_cdir *cdir, *cdirnew;
+    unsigned char *buf, *match;
+    int a, best, buflen, i;
+    struct zip_error zerr;
+
+    i = fseeko(fp, -(len < CDBUFSIZE ? len : CDBUFSIZE), SEEK_END);
+    if (i == -1 && errno != EFBIG) {
+       /* seek before start of file on my machine */
+       set_error(zep, NULL, ZIP_ER_SEEK);
+       return NULL;
+    }
+
+    /* 64k is too much for stack */
+    if ((buf=(unsigned char *)malloc(CDBUFSIZE)) == NULL) {
+       set_error(zep, NULL, ZIP_ER_MEMORY);
+       return NULL;
+    }
+
+    clearerr(fp);
+    buflen = fread(buf, 1, CDBUFSIZE, fp);
+
+    if (ferror(fp)) {
+       set_error(zep, NULL, ZIP_ER_READ);
+       free(buf);
+       return NULL;
+    }
+    
+    best = -1;
+    cdir = NULL;
+    match = buf;
+    _zip_error_set(&zerr, ZIP_ER_NOZIP, 0);
+
+    while ((match=_zip_memmem(match, buflen-(match-buf)-18,
+                             (const unsigned char *)EOCD_MAGIC, 4))!=NULL) {
+       /* found match -- check, if good */
+       /* to avoid finding the same match all over again */
+       match++;
+       if ((cdirnew=_zip_readcdir(fp, buf, match-1, buflen, flags,
+                                  &zerr)) == NULL)
+           continue;
+
+       if (cdir) {
+           if (best <= 0)
+               best = _zip_checkcons(fp, cdir, &zerr);
+           a = _zip_checkcons(fp, cdirnew, &zerr);
+           if (best < a) {
+               _zip_cdir_free(cdir);
+               cdir = cdirnew;
+               best = a;
+           }
+           else
+               _zip_cdir_free(cdirnew);
+       }
+       else {
+           cdir = cdirnew;
+           if (flags & ZIP_CHECKCONS)
+               best = _zip_checkcons(fp, cdir, &zerr);
+           else
+               best = 0;
+       }
+       cdirnew = NULL;
+    }
+
+    free(buf);
+    
+    if (best < 0) {
+       set_error(zep, &zerr, 0);
+       _zip_cdir_free(cdir);
+       return NULL;
+    }
+
+    return cdir;
+}
+
+\f
+
 static unsigned char *
 _zip_memmem(const unsigned char *big, int biglen, const unsigned char *little, 
        int littlelen)
index 8141dc46a6f332e9d64fb1475c403490ce27feae..a0055fdc47affffa4b5be6ccef80d7854c787f07 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_rename.c,v 1.15 2004/11/30 22:19:38 wiz Exp $
-
   zip_rename.c -- rename file in zip archive
-  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_rename(struct zip *za, int idx, const char *name)
 {
     if (idx >= za->nentry || idx < 0) {
index 12db005f2804480c20aa90de8e932f02642e129f..ae69a86f632f1441b83f44e5c435e68090c0a74b 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_replace.c,v 1.20 2006/04/09 14:52:02 wiz Exp $
-
   zip_replace.c -- replace file via callback function
-  Copyright (C) 1999, 2003, 2004, 2006 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_replace(struct zip *za, int idx, struct zip_source *source)
 {
     if (idx < 0 || idx >= za->nentry || source == NULL) {
@@ -57,23 +54,22 @@ zip_replace(struct zip *za, int idx, struct zip_source *source)
 
 \f
 
-PHPZIPAPI int
+int
 _zip_replace(struct zip *za, int idx, const char *name,
             struct zip_source *source)
 {
-       if (idx == -1) {
-               if (_zip_entry_new(za) == NULL)
-                       return -1;
-               idx = za->nentry - 1;
-       }
+    if (idx == -1) {
+       if (_zip_entry_new(za) == NULL)
+           return -1;
 
-   
+       idx = za->nentry - 1;
+    }
+    
     _zip_unchange_data(za->entry+idx);
 
     if (name && _zip_set_name(za, idx, name) != 0)
-               return -1;
-
+       return -1;
+    
     za->entry[idx].state = ((za->cdir == NULL || idx >= za->cdir->nentry)
                            ? ZIP_ST_ADDED : ZIP_ST_REPLACED);
     za->entry[idx].source = source;
index 7649a80de9f3b5a4f906cc84e19235e5b6df6ac3..c4bd070ddcde340078a93a2caaf4423506672750 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_set_archive_comment.c,v 1.3 2006/04/24 10:34:39 dillo Exp $
-
   zip_set_archive_comment.c -- set archive comment
-  Copyright (C) 2006 Dieter Baron and Thomas Klausner
+  Copyright (C) 2006-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 #include <stdlib.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_set_archive_comment(struct zip *za, const char *comment, int len)
 {
     char *tmpcom;
@@ -60,7 +57,7 @@ zip_set_archive_comment(struct zip *za, const char *comment, int len)
     else
        tmpcom = NULL;
 
-    if (za->ch_comment) free(za->ch_comment);
+    free(za->ch_comment);
     za->ch_comment = tmpcom;
     za->ch_comment_len = len;
     
index 5454aa21da64410f24348b571a639bdcbefcf163..3d5dd6b5e3e68b82380c7e7a12656e7003699d32 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_set_file_comment.c,v 1.4 2006/04/24 10:34:39 dillo Exp $
-
   zip_set_file_comment.c -- set comment for file in archive
-  Copyright (C) 2006 Dieter Baron and Thomas Klausner
+  Copyright (C) 2006-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 #include <stdlib.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_set_file_comment(struct zip *za, int idx, const char *comment, int len)
 {
     char *tmpcom;
index 8a401faacae5b8ce6977d1661f46aafae9c13b3b..5c7da3d7c51ff10d37517bbf47f4d3e4c962ffc4 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_set_name.c,v 1.16 2004/11/30 23:02:47 wiz Exp $
-
   zip_set_name.c -- rename helper function
-  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 #include <stdlib.h>
 #include <string.h>
-#include "zip.h"
+
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+int
 _zip_set_name(struct zip *za, int idx, const char *name)
 {
     char *s;
index 95875b74c18109e354c2b5d015bd64466e1d3779..867d3dfa3ed695d253d0293534b77d11fa2df20a 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_source_buffer.c,v 1.8 2006/04/23 14:50:49 wiz Exp $
-
   zip_source_buffer.c -- create zip data source from buffer
-  Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
@@ -38,7 +36,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 struct read_data {
@@ -52,7 +49,7 @@ static ssize_t read_data(void *state, void *data, size_t len,
 
 \f
 
-PHPZIPAPI struct zip_source *
+ZIP_EXTERN(struct zip_source *)
 zip_source_buffer(struct zip *za, const void *data, off_t len, int freep)
 {
     struct read_data *f;
@@ -84,6 +81,8 @@ zip_source_buffer(struct zip *za, const void *data, off_t len, int freep)
     return zs;
 }
 
+\f
+
 static ssize_t
 read_data(void *state, void *data, size_t len, enum zip_source_cmd cmd)
 {
@@ -103,8 +102,6 @@ read_data(void *state, void *data, size_t len, enum zip_source_cmd cmd)
        n = z->end - z->buf;
        if (n > len)
            n = len;
-       if (n < 0)
-           n = 0;
 
        if (n) {
            memcpy(buf, z->buf, n);
index 486e1900d97103086a7c54e1504a5400cd5f4152..204fa1d5a317c7cbf1069ad141bbcd8e82340913 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_source_file.c,v 1.2 2004/11/18 16:28:13 wiz Exp $
-
   zip_source_file.c -- create data source from file
-  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 #include <errno.h>
 #include <stdio.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI struct zip_source *
+ZIP_EXTERN(struct zip_source *)
 zip_source_file(struct zip *za, const char *fname, off_t start, off_t len)
 {
     struct zip_source *zs;
@@ -62,10 +59,6 @@ zip_source_file(struct zip *za, const char *fname, off_t start, off_t len)
        return NULL;
     }
 
-#ifdef PHP_WIN32
-       _setmode(_fileno(fp), _O_BINARY );
-#endif
-
     if ((zs=zip_source_filep(za, fp, start, len)) == NULL) {
        fclose(fp);
        return NULL;
index 8a33042655871394cf363cdde5d7ae442443dae9..48a122d4bd1943f91b2783a60eebb548ac31a309 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_source_filep.c,v 1.6 2005/06/09 19:57:10 dillo Exp $
-
   zip_source_filep.c -- create data source from FILE *
-  Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
@@ -41,7 +39,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 struct read_file {
@@ -57,7 +54,7 @@ static ssize_t read_file(void *state, void *data, size_t len,
 
 \f
 
-PHPZIPAPI struct zip_source *
+ZIP_EXTERN(struct zip_source *)
 zip_source_filep(struct zip *za, FILE *file, off_t start, off_t len)
 {
     struct read_file *f;
index 707309c913ba3c35f373cf7456cec99a32ff6eb8..293e7f7e114cdc77b2ae0e937a07273382835656 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_source_free.c,v 1.2 2004/12/22 16:32:00 dillo Exp $
-
   zip_source_free.c -- free zip data source
-  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 #include <stdlib.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI void
+ZIP_EXTERN(void)
 zip_source_free(struct zip_source *source)
 {
     if (source == NULL)
index 4ab11092445c999c0fa4039a9bd6271327b48239..fe3e82aa5ba29d80317c739bf944388f98480429 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_source_function.c,v 1.4 2006/02/21 09:41:00 dillo Exp $
-
   zip_source_function.c -- create zip data source from callback function
-  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 #include <stdlib.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI struct zip_source *
+ZIP_EXTERN(struct zip_source *)
 zip_source_function(struct zip *za, zip_source_callback zcb, void *ud)
 {
     struct zip_source *zs;
index 75e656402116ecb527ce3dc99017071105394b47..bf166b35196bc1b1e4d42a94c4d551baeb0e12fb 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_source_zip.c,v 1.7 2006/02/21 09:41:00 dillo Exp $
-
   zip_source_zip.c -- create data source from zip file
-  Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
@@ -38,7 +36,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "zip.h"
 #include "zipint.h"
 
 struct read_zip {
@@ -52,7 +49,7 @@ static ssize_t read_zip(void *st, void *data, size_t len,
 
 \f
 
-PHPZIPAPI struct zip_source *
+ZIP_EXTERN(struct zip_source *)
 zip_source_zip(struct zip *za, struct zip *srcza, int srcidx, int flags,
               off_t start, off_t len)
 {
index 7c6cbf00d227f12e00a6fbbece173f5a94ac8244..c8a25e1d84ac377cc130d02ae0109d456c0418af 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_stat.c,v 1.3 2004/04/16 09:40:30 dillo Exp $
-
   zip_stat.c -- get information about file by name
-  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_stat(struct zip *za, const char *fname, int flags, struct zip_stat *st)
 {
     int idx;
index cf55565ef553ec7330b248b696c77fba6e031478..26425206ca3323b1d3b5a07d974e454c30a02b12 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_stat_index.c,v 1.10 2006/04/24 14:04:19 dillo Exp $
-
   zip_stat_index.c -- get information about file by index
-  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_stat_index(struct zip *za, int index, int flags, struct zip_stat *st)
 {
     const char *name;
@@ -67,7 +64,7 @@ zip_stat_index(struct zip *za, int index, int flags, struct zip_stat *st)
            _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
            return -1;
        }
-
+       
        st->crc = za->cdir->entry[index].crc;
        st->size = za->cdir->entry[index].uncomp_size;
        st->mtime = za->cdir->entry[index].last_mod;
index e9c056dfc5b9e1dbaa72c5ae912cd5dd84d65a2a..cb451dc3bcaad35d25cafa4729077cf6accb7b7d 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_stat_init.c,v 1.1 2006/10/31 12:03:04 dillo Exp $
-
   zip_stat_init.c -- initialize struct zip_stat.
-  Copyright (C) 2006 Dieter Baron and Thomas Klausner
+  Copyright (C) 2006-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
@@ -39,7 +37,7 @@
 
 \f
 
-PHPZIPAPI void
+ZIP_EXTERN(void)
 zip_stat_init(struct zip_stat *st)
 {
     st->name = NULL;
index f3e5aa9fe8914090b63243011abe45f067a53980..ad23bafed6c629dca6427e39d9f00b76280321e0 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_strerror.c,v 1.1 2003/10/05 16:05:22 dillo Exp $
-
   zip_sterror.c -- get string representation of zip error
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 
 \f
 
-#include "zip.h"
 #include "zipint.h"
 
 \f
-
-PHPZIPAPI const char *
+ZIP_EXTERN(const char *)
 zip_strerror(struct zip *za)
 {
     return _zip_error_strerror(&za->error);
index 80070e7a3b3797e0cef9189e8d9fa87a5a42a71d..7366c9cc7164e0bcf1e38424ca8a93f0f9241fb6 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_unchange.c,v 1.19 2006/04/23 13:21:18 wiz Exp $
-
   zip_unchange.c -- undo changes to file in zip archive
-  Copyright (C) 1999, 2004, 2006 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 \f
 
 #include <stdlib.h>
-#include "zip.h"
+
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_unchange(struct zip *za, int idx)
 {
     return _zip_unchange(za, idx, 0);
@@ -49,7 +47,7 @@ zip_unchange(struct zip *za, int idx)
 
 \f
 
-PHPZIPAPI int
+int
 _zip_unchange(struct zip *za, int idx, int allow_duplicates)
 {
     int i;
index 2d4459c8238d3ae1a4f5690cf002a1ca826a18b1..01282f89dbbafa05fe67aba83eb4c762ba014e98 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_unchange_all.c,v 1.10 2006/04/23 13:14:46 wiz Exp $
-
   zip_unchange.c -- undo changes to all files in zip archive
-  Copyright (C) 1999, 2006 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
 \f
 
 #include <stdlib.h>
-#include "zip.h"
+
 #include "zipint.h"
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_unchange_all(struct zip *za)
 {
     int ret, i;
@@ -49,7 +47,7 @@ zip_unchange_all(struct zip *za)
     ret = 0;
     for (i=0; i<za->nentry; i++)
        ret |= _zip_unchange(za, i, 1);
-        
+
     ret |= zip_unchange_archive(za);
 
     return ret;
index 6c2bc6dcb3bc1c1dcb218aafb5692002ef8c191e..b8a85fc9ac4eee81039aa7d30c786586e295aca2 100644 (file)
@@ -1,11 +1,9 @@
 /*
-  $NiH: zip_unchange_archive.c,v 1.1 2006/04/23 13:14:46 wiz Exp $
-
   zip_unchange_archive.c -- undo global changes to ZIP archive
-  Copyright (C) 2006 Dieter Baron and Thomas Klausner
+  Copyright (C) 2006-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
@@ -41,7 +39,7 @@
 
 \f
 
-PHPZIPAPI int
+ZIP_EXTERN(int)
 zip_unchange_archive(struct zip *za)
 {
     free(za->ch_comment);
index dfa2ea545fc168463514dff3d0183087a92ef94a..6fe89f4fb2b785958198834bee3da9320531e65e 100644 (file)
@@ -1,11 +1,11 @@
 /*
-  $NiH: zip_unchange_data.c,v 1.15 2004/12/22 16:32:00 dillo Exp $
+  $NiH: zip_unchange_data.c,v 1.14 2004/11/30 23:02:47 wiz Exp $
 
   zip_unchange_data.c -- undo helper function
   Copyright (C) 1999, 2004 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
@@ -39,7 +39,7 @@
 
 #include "zipint.h"
 
-PHPZIPAPI void
+void
 _zip_unchange_data(struct zip_entry *ze)
 {
     if (ze->source) {
index ea3860d6022f312a0db90a5678376a5e6337dfa7..ff28d2878c4b6e8986400956c13250e1081faec2 100644 (file)
@@ -2,16 +2,25 @@
 #include <windows.h>
 #include <io.h>
 #include <fcntl.h>
+#include <string.h>
+#include <zconf.h>
+
+#ifndef strcasecmp
+# define strcmpi _strcmpi
+#endif
 
 #ifndef ssize_t
 #      define ssize_t SSIZE_T
 #endif
+
 #ifndef mode_t
 #      define mode_t int
 #endif
+
 #ifndef snprintf
 #      define snprintf _snprintf
 #endif
+
 #ifndef mkstemp
 #      define mkstemp(t) _creat(_mktemp(t), _S_IREAD|_S_IWRITE)
 #endif
index 33632aca4ec3096560f06de1cdb711064813806c..165f68dc65d4dccc0d8a4bf0d439c777a8356592 100644 (file)
@@ -2,13 +2,11 @@
 #define _HAD_ZIPINT_H
 
 /*
-  $NiH: zipint.h,v 1.48 2006/04/24 14:04:19 dillo Exp $
-
   zipint.h -- internal declarations.
-  Copyright (C) 1999, 2003, 2004, 2005, 2006 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
+  The authors can be contacted at <libzip@nih.at>
 
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
@@ -22,7 +20,7 @@
   3. The names of the authors may not be used to endorse or promote
      products derived from this software without specific prior
      written permission.
+
   THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 #include <zlib.h>
 
 #include "zip.h"
-/* #defines that rename all zip_ functions and structs */
-#include "zipint_alias.h"
 
-BEGIN_EXTERN_C()
+#ifdef PHP_WIN32
+#include <windows.h>
+#include <wchar.h>
+#define _zip_rename(s, t)                                              \
+       (!MoveFileExA((s), (t),                                         \
+                    MOVEFILE_COPY_ALLOWED|MOVEFILE_REPLACE_EXISTING))
+#else
+#define _zip_rename    rename
+#endif
+
+#ifndef strcasecmp
+# define strcmpi strcasecmp 
+#endif
+
 #ifndef HAVE_FSEEKO
 #define fseeko(s, o, w)        (fseek((s), (long int)(o), (w)))
 #endif
+#ifndef HAVE_FTELLO
+#define ftello(s)      ((long)ftell((s)))
+#endif
+
+\f
 
 #define CENTRAL_MAGIC "PK\1\2"
 #define LOCAL_MAGIC   "PK\3\4"
 #define EOCD_MAGIC    "PK\5\6"
 #define DATADES_MAGIC "PK\7\8"
+#define TORRENT_SIG    "TORRENTZIPPED-"
+#define TORRENT_SIG_LEN        14
 #define CDENTRYSIZE         46u
 #define LENTRYSIZE          30
 #define MAXCOMLEN        65536
@@ -74,8 +90,8 @@ enum zip_state { ZIP_ST_UNCHANGED, ZIP_ST_DELETED, ZIP_ST_REPLACED,
 /* directory entry: general purpose bit flags */
 
 #define ZIP_GPBF_ENCRYPTED             0x0001  /* is encrypted */
+#define ZIP_GPBF_DATA_DESCRIPTOR       0x0008  /* crc/size after file data */
 #define ZIP_GPBF_STRONG_ENCRYPTION     0x0040  /* uses strong encryption */
-#define ZIP_GPBF_USE_DATA_DESCRIPTOR    0x0008  /* uses crc and size from data header */
 
 /* error information */
 
@@ -92,6 +108,9 @@ struct zip {
     FILE *zp;                  /* file */
     struct zip_error error;    /* error information */
 
+    unsigned int flags;                /* archive global flags */
+    unsigned int ch_flags;     /* changed archive global flags */
+
     struct zip_cdir *cdir;     /* central directory */
     char *ch_comment;          /* changed archive comment */
     int ch_comment_len;                /* length of changed zip archive
@@ -112,13 +131,13 @@ struct zip_file {
     int flags;                 /* -1: eof, >0: error */
 
     int method;                        /* compression method */
-    long fpos;                 /* position within zip file (fread/fwrite) */
+    off_t fpos;                        /* position within zip file (fread/fwrite) */
     unsigned long bytes_left;  /* number of bytes left to read */
     unsigned long cbytes_left;  /* number of bytes of compressed data left */
-    
+
     unsigned long crc;         /* CRC so far */
     unsigned long crc_orig;    /* CRC recorded in archive */
-    
+
     char *buffer;
     z_stream *zstr;
 };
@@ -189,43 +208,42 @@ extern const int _zip_err_type[];
 
 \f
 
-PHPZIPAPI void _zip_cdir_free(struct zip_cdir *);
-PHPZIPAPI struct zip_cdir *_zip_cdir_new(int, struct zip_error *);
-PHPZIPAPI int _zip_cdir_write(struct zip_cdir *, FILE *, struct zip_error *);
+void _zip_cdir_free(struct zip_cdir *);
+struct zip_cdir *_zip_cdir_new(int, struct zip_error *);
+int _zip_cdir_write(struct zip_cdir *, FILE *, struct zip_error *);
 
-PHPZIPAPI void _zip_dirent_finalize(struct zip_dirent *);
-PHPZIPAPI void _zip_dirent_init(struct zip_dirent *);
-PHPZIPAPI int _zip_dirent_read(struct zip_dirent *, FILE *,
+void _zip_dirent_finalize(struct zip_dirent *);
+void _zip_dirent_init(struct zip_dirent *);
+int _zip_dirent_read(struct zip_dirent *, FILE *,
                     unsigned char **, unsigned int, int, struct zip_error *);
-PHPZIPAPI int _zip_dirent_write(struct zip_dirent *, FILE *, int, struct zip_error *);
-
-PHPZIPAPI void _zip_entry_free(struct zip_entry *);
-PHPZIPAPI void _zip_entry_init(struct zip *, int);
-PHPZIPAPI struct zip_entry *_zip_entry_new(struct zip *);
-
-PHPZIPAPI void _zip_error_clear(struct zip_error *);
-PHPZIPAPI void _zip_error_copy(struct zip_error *, struct zip_error *);
-PHPZIPAPI void _zip_error_fini(struct zip_error *);
-PHPZIPAPI void _zip_error_get(struct zip_error *, int *, int *);
-PHPZIPAPI void _zip_error_init(struct zip_error *);
-PHPZIPAPI void _zip_error_set(struct zip_error *, int, int);
-PHPZIPAPI const char *_zip_error_strerror(struct zip_error *);
-
-PHPZIPAPI int _zip_file_fillbuf(void *, size_t, struct zip_file *);
-PHPZIPAPI unsigned int _zip_file_get_offset(struct zip *, int);
-
-PHPZIPAPI void _zip_free(struct zip *);
-PHPZIPAPI const char *_zip_get_name(struct zip *, int, int, struct zip_error *);
-PHPZIPAPI int _zip_local_header_read(struct zip *, int);
-PHPZIPAPI void *_zip_memdup(const void *, size_t, struct zip_error *);
-PHPZIPAPI int _zip_name_locate(struct zip *, const char *, int, struct zip_error *);
-PHPZIPAPI struct zip *_zip_new(struct zip_error *);
-PHPZIPAPI unsigned short _zip_read2(unsigned char **);
-PHPZIPAPI unsigned int _zip_read4(unsigned char **);
-PHPZIPAPI int _zip_replace(struct zip *, int, const char *, struct zip_source *);
-PHPZIPAPI int _zip_set_name(struct zip *, int, const char *);
-PHPZIPAPI int _zip_unchange(struct zip *, int, int);
-PHPZIPAPI void _zip_unchange_data(struct zip_entry *);
-
-END_EXTERN_C();
+int _zip_dirent_write(struct zip_dirent *, FILE *, int, struct zip_error *);
+
+void _zip_entry_free(struct zip_entry *);
+void _zip_entry_init(struct zip *, int);
+struct zip_entry *_zip_entry_new(struct zip *);
+
+void _zip_error_clear(struct zip_error *);
+void _zip_error_copy(struct zip_error *, struct zip_error *);
+void _zip_error_fini(struct zip_error *);
+void _zip_error_get(struct zip_error *, int *, int *);
+void _zip_error_init(struct zip_error *);
+void _zip_error_set(struct zip_error *, int, int);
+const char *_zip_error_strerror(struct zip_error *);
+
+int _zip_file_fillbuf(void *, size_t, struct zip_file *);
+unsigned int _zip_file_get_offset(struct zip *, int);
+
+void _zip_free(struct zip *);
+const char *_zip_get_name(struct zip *, int, int, struct zip_error *);
+int _zip_local_header_read(struct zip *, int);
+void *_zip_memdup(const void *, size_t, struct zip_error *);
+int _zip_name_locate(struct zip *, const char *, int, struct zip_error *);
+struct zip *_zip_new(struct zip_error *);
+unsigned short _zip_read2(unsigned char **);
+unsigned int _zip_read4(unsigned char **);
+int _zip_replace(struct zip *, int, const char *, struct zip_source *);
+int _zip_set_name(struct zip *, int, const char *);
+int _zip_unchange(struct zip *, int, int);
+void _zip_unchange_data(struct zip_entry *);
+
 #endif /* zipint.h */
diff --git a/ext/zip/lib/zipint_alias.h b/ext/zip/lib/zipint_alias.h
deleted file mode 100644 (file)
index e8541b3..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-
-/* state of change of a file in zip archive */
-#define zip_state php_ziplib__zip_state
-#define zip_error php_ziplib__zip_error
-#define zip_dirent php_ziplib__zip_dirent
-#define zip_cdir php_ziplib__zip_cdir
-#define zip_source php_ziplib__zip_source
-#define zip_entry php_ziplib__zip_entry
-
-#define _zip_err_str php_ziplib___zip_err_str
-#define _zip_nerr_str php_ziplib___zip_nerr_str
-#define _zip_err_type php_ziplib___zip_err_type
-\f
-#define _zip_cdir_free php_ziplib___zip_cdir_free
-#define _zip_cdir_new php_ziplib___zip_cdir_new
-#define _zip_cdir_write php_ziplib___zip_cdir_write
-
-#define _zip_dirent_finalize php_ziplib___zip_dirent_finalize
-#define _zip_dirent_init php_ziplib___zip_dirent_init
-#define _zip_dirent_read php_ziplib___zip_dirent_read
-#define _zip_dirent_write php_ziplib___zip_dirent_write
-
-#define _zip_entry_free php_ziplib___zip_entry_free
-#define _zip_entry_init php_ziplib___zip_entry_init
-#define _zip_entry_new php_ziplib___zip_entry_new
-
-#define _zip_error_clear php_ziplib___zip_error_clear
-#define _zip_error_copy php_ziplib___zip_error_copy
-#define _zip_error_fini php_ziplib___zip_error_fini
-#define _zip_error_get php_ziplib___zip_error_get
-#define _zip_error_init php_ziplib___zip_error_init
-#define _zip_error_set php_ziplib___zip_error_set
-#define _zip_error_strerror php_ziplib___zip_error_strerror
-
-#define _zip_file_fillbuf php_ziplib___zip_file_fillbuf
-#define _zip_file_get_offset php_ziplib___zip_file_get_offset
-
-#define _zip_free php_ziplib___zip_free
-#define _zip_get_name php_ziplib___zip_get_name
-#define _zip_local_header_read php_ziplib___zip_local_header_read
-#define _zip_memdup php_ziplib___zip_memdup
-#define _zip_name_locate php_ziplib___zip_name_locate
-#define _zip_new php_ziplib___zip_new
-#define _zip_read2 php_ziplib___zip_read2
-#define _zip_read4 php_ziplib___zip_read4
-#define _zip_replace php_ziplib___zip_replace
-#define _zip_set_name php_ziplib___zip_set_name
-#define _zip_unchange php_ziplib___zip_unchange
-#define _zip_unchange_data php_ziplib___zip_unchange_data
index bf73300ebc611348239283f4fafcf1a9a9cc2a60..4e5db1a232b6d33dc40e5e98f197d36cefb56016 100644 (file)
@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2008 The PHP Group                                |
+  | Copyright (c) 1997-2007 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
 #include "ext/standard/info.h"
 #include "ext/standard/file.h"
 #include "ext/standard/php_string.h"
+#include "ext/pcre/php_pcre.h"
 #include "php_zip.h"
 #include "lib/zip.h"
 #include "lib/zipint.h"
 
-/* zip_open is a macro for renaming libzip zipopen, so we need to use PHP_NAMED_FUNCTION */
-static PHP_NAMED_FUNCTION(zif_zip_open);
-static PHP_NAMED_FUNCTION(zif_zip_read);
-static PHP_NAMED_FUNCTION(zif_zip_close);
-static PHP_NAMED_FUNCTION(zif_zip_entry_read);
-static PHP_NAMED_FUNCTION(zif_zip_entry_filesize);
-static PHP_NAMED_FUNCTION(zif_zip_entry_name);
-static PHP_NAMED_FUNCTION(zif_zip_entry_compressedsize);
-static PHP_NAMED_FUNCTION(zif_zip_entry_compressionmethod);
-static PHP_NAMED_FUNCTION(zif_zip_entry_open);
-static PHP_NAMED_FUNCTION(zif_zip_entry_close);
+#ifdef HAVE_GLOB
+#ifndef PHP_WIN32
+#include <glob.h>
+#else
+#include "win32/glob.h"
+#endif
+#endif
 
 /* {{{ Resource le */
 static int le_zip_dir;
@@ -50,6 +47,15 @@ static int le_zip_entry;
 #define le_zip_entry_name "Zip Entry"
 /* }}} */
 
+/* {{{ 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)
+#else 
+#define SAFEMODE_CHECKFILE(filename) (0)
+#endif
+/* }}} */
+
 /* {{{ PHP_ZIP_STAT_INDEX(za, index, flags, sb) */
 #define PHP_ZIP_STAT_INDEX(za, index, flags, sb) \
        if (zip_stat_index(za, index, flags, &sb) != 0) { \
@@ -82,6 +88,7 @@ static int le_zip_entry;
 
 /* }}} */
 
+#ifdef ZEND_ENGINE_2_1
 /* {{{ php_zip_extract_file */
 /* TODO: Simplify it */
 static int php_zip_extract_file(struct zip * za, char *dest, char *file, int file_len TSRMLS_DC)
@@ -107,7 +114,7 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int fil
        if (file_len >= MAXPATHLEN || zip_stat(za, file, 0, &sb) != 0) {
                return 0;
        }
-
+       /* it is a directory only, see #40228 */
        if (file_len > 1 && file[file_len - 1] == '/') {
                len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file);
                is_dir_only = 1;
@@ -121,9 +128,9 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int fil
                        len = spprintf(&file_dirname_fullpath, 0, "%s", dest);
                }
 
-               php_basename(file, file_len, NULL, 0, &file_basename, (size_t *)&file_basename_len TSRMLS_CC);
+               php_basename(file, file_len, NULL, 0, &file_basename, (unsigned int *)&file_basename_len TSRMLS_CC);
 
-               if (OPENBASEDIR_CHECKPATH(file_dirname_fullpath)) {
+               if (SAFEMODE_CHECKFILE(file_dirname_fullpath)) {
                        efree(file_dirname_fullpath);
                        efree(file_basename);
                        return 0;
@@ -132,6 +139,18 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int fil
 
        /* let see if the path already exists */
        if (php_stream_stat_path(file_dirname_fullpath, &ssb) < 0) {
+
+#if defined(PHP_WIN32) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 1)
+               char *e;
+               e = file_dirname_fullpath;
+               while (*e) {
+                          if (*e == '/') {
+                                          *e = DEFAULT_SLASH;
+                          }
+                          e++;
+               }
+#endif
+
                ret = php_stream_mkdir(file_dirname_fullpath, 0777,  PHP_STREAM_MKDIR_RECURSIVE, NULL);
                if (!ret) {
                        efree(file_dirname_fullpath);
@@ -160,8 +179,7 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int fil
         * is required, does a file can have a different
         * safemode status as its parent folder?
         */
-       if (OPENBASEDIR_CHECKPATH(fullpath)) {
-               efree(fullpath);
+       if (SAFEMODE_CHECKFILE(fullpath)) {
                efree(file_dirname_fullpath);
                efree(file_basename);
                return 0;
@@ -174,8 +192,11 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int fil
                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);
@@ -195,6 +216,111 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int fil
 }
 /* }}} */
 
+static int php_zip_add_file(struct zip *za, const char *filename, int filename_len, 
+       char *entry_name, int entry_name_len, long offset_start, long offset_len TSRMLS_DC) /* {{{ */
+{
+       struct zip_source *zs;
+       int cur_idx;
+       char resolved_path[MAXPATHLEN];
+
+
+       if (SAFEMODE_CHECKFILE(filename)) {
+               return -1;
+       }
+
+       if (!expand_filepath(filename, resolved_path TSRMLS_CC)) {
+               return -1;
+       }
+
+       zs = zip_source_file(za, resolved_path, offset_start, offset_len);
+       if (!zs) {
+               return -1;
+       }
+
+       cur_idx = zip_name_locate(za, (const char *)entry_name, 0);
+       /* TODO: fix  _zip_replace */
+       if (cur_idx<0) {
+               /* reset the error */
+               if (za->error.str) {
+                       _zip_error_fini(&za->error);
+               }
+               _zip_error_init(&za->error);
+       } else {
+               if (zip_delete(za, cur_idx) == -1) {
+                       zip_source_free(zs);
+                       return -1;
+               }
+       }
+
+       if (zip_add(za, entry_name, zs) == -1) {
+               return -1;
+       } else {
+               return 1;
+       }
+}
+/* }}} */
+
+static int php_zip_parse_options(zval *options, long *remove_all_path, 
+       char **remove_path, int *remove_path_len, char **add_path, int *add_path_len TSRMLS_DC) /* {{{ */
+{
+       zval **option;
+       if (zend_hash_find(HASH_OF(options), "remove_all_path", sizeof("remove_all_path"), (void **)&option) == SUCCESS) {
+               long opt;
+               if (Z_TYPE_PP(option) != IS_LONG) {
+                       zval tmp = **option;
+                       zval_copy_ctor(&tmp);
+                       convert_to_long(&tmp);
+                       opt = Z_LVAL(tmp);
+               } else {
+                       opt = Z_LVAL_PP(option);
+               }
+               *remove_all_path = opt;
+       }
+
+       /* If I add more options, it would make sense to create a nice static struct and loop over it. */
+       if (zend_hash_find(HASH_OF(options), "remove_path", sizeof("remove_path"), (void **)&option) == SUCCESS) {
+               if (Z_TYPE_PP(option) != IS_STRING) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "remove_path option expected to be a string");
+                       return -1;
+               }
+
+               if (Z_STRLEN_PP(option) < 1) {
+                       php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Empty string given as remove_path option");
+                       return -1;
+               }
+
+               if (Z_STRLEN_PP(option) >= MAXPATHLEN) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "remove_path string is too long (max: %i, %i given)", 
+                                               MAXPATHLEN - 1, Z_STRLEN_PP(option));
+                       return -1;
+               }
+               *remove_path_len = Z_STRLEN_PP(option); 
+               *remove_path = Z_STRVAL_PP(option);
+       }
+
+       if (zend_hash_find(HASH_OF(options), "add_path", sizeof("add_path"), (void **)&option) == SUCCESS) {
+               if (Z_TYPE_PP(option) != IS_STRING) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "add_path option expected to be a string");
+                       return -1;
+               }
+
+               if (Z_STRLEN_PP(option) < 1) {
+                       php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Empty string given as the add_path option");
+                       return -1;
+               }
+
+               if (Z_STRLEN_PP(option) >= MAXPATHLEN) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "add_path string too long (max: %i, %i given)", 
+                                               MAXPATHLEN - 1, Z_STRLEN_PP(option));
+                       return -1;
+               }
+               *add_path_len = Z_STRLEN_PP(option); 
+               *add_path = Z_STRVAL_PP(option);
+       }
+       return 1;
+}
+/* }}} */
+
 /* {{{ REGISTER_ZIP_CLASS_CONST_LONG */
 #define REGISTER_ZIP_CLASS_CONST_LONG(const_name, value) \
            zend_declare_class_constant_long(zip_class_entry, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC);
@@ -272,8 +398,217 @@ static char * php_zipobj_get_zip_comment(struct zip *za, int *len TSRMLS_DC) /*
 }
 /* }}} */
 
+#ifdef HAVE_GLOB /* {{{ */
+#ifndef GLOB_ONLYDIR
+#define GLOB_ONLYDIR (1<<30)
+#define GLOB_EMULATE_ONLYDIR
+#define GLOB_FLAGMASK (~GLOB_ONLYDIR)
+#else
+#define GLOB_FLAGMASK (~0)
+#endif /* }}} */
+
+int php_zip_glob(char *pattern, int pattern_len, long flags, zval *return_value TSRMLS_DC) /* {{{ */
+{
+       char cwd[MAXPATHLEN];
+       int cwd_skip = 0;
+#ifdef ZTS
+       char work_pattern[MAXPATHLEN];
+       char *result;
+#endif
+       glob_t globbuf;
+       int n;
+       int ret;
+
+#ifdef ZTS 
+       if (!IS_ABSOLUTE_PATH(pattern, pattern_len)) {
+               result = VCWD_GETCWD(cwd, MAXPATHLEN);  
+               if (!result) {
+                       cwd[0] = '\0';
+               }
+#ifdef PHP_WIN32
+               if (IS_SLASH(*pattern)) {
+                       cwd[2] = '\0';
+               }
+#endif
+               cwd_skip = strlen(cwd)+1;
+
+               snprintf(work_pattern, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, pattern);
+               pattern = work_pattern;
+       } 
+#endif
+
+       globbuf.gl_offs = 0;
+       if (0 != (ret = glob(pattern, flags & GLOB_FLAGMASK, NULL, &globbuf))) {
+#ifdef GLOB_NOMATCH
+               if (GLOB_NOMATCH == ret) {
+                       /* Some glob implementation simply return no data if no matches
+                          were found, others return the GLOB_NOMATCH error code.
+                          We don't want to treat GLOB_NOMATCH as an error condition
+                          so that PHP glob() behaves the same on both types of 
+                          implementations and so that 'foreach (glob() as ...'
+                          can be used for simple glob() calls without further error
+                          checking.
+                       */
+                       array_init(return_value);
+                       return 0;
+               }
+#endif
+               return 0;
+       }
+
+       /* now catch the FreeBSD style of "no matches" */
+       if (!globbuf.gl_pathc || !globbuf.gl_pathv) {
+               array_init(return_value);
+               return 0;
+       }
+
+       /* we assume that any glob pattern will match files from one directory only
+          so checking the dirname of the first match should be sufficient */
+       strncpy(cwd, globbuf.gl_pathv[0], MAXPATHLEN);
+       if (PG(safe_mode) && (!php_checkuid(cwd, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
+               return -1;
+       }
+       if (php_check_open_basedir(cwd TSRMLS_CC)) {
+               return -1;
+       }
+
+       array_init(return_value);
+       for (n = 0; n < globbuf.gl_pathc; n++) {
+               /* we need to do this everytime since GLOB_ONLYDIR does not guarantee that
+                * all directories will be filtered. GNU libc documentation states the
+                * following: 
+                * If the information about the type of the file is easily available 
+                * non-directories will be rejected but no extra work will be done to 
+                * determine the information for each file. I.e., the caller must still be 
+                * able to filter directories out. 
+                */
+               if (flags & GLOB_ONLYDIR) {
+                       struct stat s;
+
+                       if (0 != VCWD_STAT(globbuf.gl_pathv[n], &s)) {
+                               continue;
+                       }
+
+                       if (S_IFDIR != (s.st_mode & S_IFMT)) {
+                               continue;
+                       }
+               }
+               add_next_index_string(return_value, globbuf.gl_pathv[n]+cwd_skip, 1);
+       }
+
+       globfree(&globbuf);
+       return globbuf.gl_pathc;
+}
+/* }}} */
+
+int php_zip_pcre(char *regexp, int regexp_len, char *path, int path_len, zval *return_value TSRMLS_DC) /* {{{ */
+{
+       char cwd[MAXPATHLEN];
+       int cwd_skip = 0;
+#ifdef ZTS
+       char work_path[MAXPATHLEN];
+       char *result;
+#endif
+       int files_cnt;
+       char **namelist;
+
+#ifdef ZTS 
+       if (!IS_ABSOLUTE_PATH(path, path_len)) {
+               result = VCWD_GETCWD(cwd, MAXPATHLEN);  
+               if (!result) {
+                       cwd[0] = '\0';
+               }
+#ifdef PHP_WIN32
+               if (IS_SLASH(*path)) {
+                       cwd[2] = '\0';
+               }
+#endif
+               cwd_skip = strlen(cwd)+1;
+
+               snprintf(work_path, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, path);
+               path = work_path;
+       } 
+#endif
+
+       /* we assume that any glob pattern will match files from one directory only
+          so checking the dirname of the first match should be sufficient */
+       if (PG(safe_mode) && (!php_checkuid(path, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
+               return -1;
+       }
+       if (php_check_open_basedir(path TSRMLS_CC)) {
+               return -1;
+       }
+       files_cnt = php_stream_scandir(path, &namelist, NULL, (void *) php_stream_dirent_alphasort);
+
+       if (files_cnt > 0) {
+               pcre       *re = NULL;
+               pcre_extra *pcre_extra = NULL;
+               int preg_options = 0, i;
+
+               re = pcre_get_compiled_regex(regexp, &pcre_extra, &preg_options TSRMLS_CC);
+               if (!re) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid expression");
+                       return -1;      
+               }
+
+               array_init(return_value);
+
+               /* only the files, directories are ignored */
+               for (i = 0; i < files_cnt; i++) {
+                       struct stat s;
+                       char   fullpath[MAXPATHLEN];
+                       int    ovector[3];
+                       int    matches;
+                       int    namelist_len = strlen(namelist[i]);
+
+                       
+                       if ((namelist_len == 1 && namelist[i][0] == '.') ||
+                               (namelist_len == 2 && namelist[i][0] == '.' && namelist[i][1] == '.')) {
+                               efree(namelist[i]);
+                               continue;
+                       }
+
+                       if ((path_len + namelist_len + 1) >= MAXPATHLEN) {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "add_path string too long (max: %i, %i given)", 
+                                               MAXPATHLEN - 1, (path_len + namelist_len + 1));
+                               efree(namelist[i]);
+                               break;
+                       }
+
+                       snprintf(fullpath, MAXPATHLEN, "%s%c%s", path, DEFAULT_SLASH, namelist[i]);
+
+                       if (0 != VCWD_STAT(fullpath, &s)) {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot read <%s>", fullpath);
+                               efree(namelist[i]);
+                               continue;
+                       }
+
+                       if (S_IFDIR == (s.st_mode & S_IFMT)) {
+                               efree(namelist[i]);
+                               continue;
+                       }
+
+                       matches = pcre_exec(re, NULL, namelist[i], strlen(namelist[i]), 0, 0, ovector, 3);
+                       /* 0 means that the vector is too small to hold all the captured substring offsets */
+                       if (matches < 0) {
+                               efree(namelist[i]);
+                               continue;       
+                       }
+
+                       add_next_index_string(return_value, fullpath, 1);
+                       efree(namelist[i]);
+               }
+               efree(namelist);
+       }
+       return files_cnt;
+}
+/* }}} */
+#endif 
+
+#endif
+
 /* {{{ zend_function_entry */
-static const zend_function_entry zip_functions[] = {
+static zend_function_entry zip_functions[] = {
        ZEND_RAW_FENTRY("zip_open", zif_zip_open, NULL, 0)
        ZEND_RAW_FENTRY("zip_close", zif_zip_close, NULL, 0)
        ZEND_RAW_FENTRY("zip_read", zif_zip_read, NULL, 0)
@@ -290,6 +625,7 @@ static const zend_function_entry zip_functions[] = {
 /* }}} */
 
 /* {{{ ZE2 OO definitions */
+#ifdef ZEND_ENGINE_2_1
 static zend_class_entry *zip_class_entry;
 static zend_object_handlers zip_object_handlers;
 
@@ -306,8 +642,10 @@ typedef struct _zip_prop_handler {
 
        int type;
 } zip_prop_handler;
+#endif
 /* }}} */
 
+#ifdef ZEND_ENGINE_2_1
 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 TSRMLS_DC) /* {{{ */
 {
        zip_prop_handler hnd;
@@ -556,7 +894,20 @@ static void php_zip_object_free_storage(void *object TSRMLS_DC) /* {{{ */
        }
 
        intern->za = NULL;
+
+#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 1 && PHP_RELEASE_VERSION > 2) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 1) || (PHP_MAJOR_VERSION > 5)
        zend_object_std_dtor(&intern->zo TSRMLS_CC);
+#else
+       if (intern->zo.guards) {
+               zend_hash_destroy(intern->zo.guards);
+               FREE_HASHTABLE(intern->zo.guards);
+       }
+
+       if (intern->zo.properties) {
+               zend_hash_destroy(intern->zo.properties);
+               FREE_HASHTABLE(intern->zo.properties);
+       }
+#endif
 
        if (intern->filename) {
                efree(intern->filename);
@@ -580,7 +931,14 @@ static zend_object_value php_zip_object_new(zend_class_entry *class_type TSRMLS_
        intern->buffers_cnt = 0;
        intern->prop_handler = &zip_prop_handlers;
 
+#if ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 1) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 1 && PHP_RELEASE_VERSION > 2))
        zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
+#else
+       ALLOC_HASHTABLE(intern->zo.properties);
+       zend_hash_init(intern->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
+       intern->zo.ce = class_type;
+#endif
+
        zend_hash_copy(intern->zo.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref,
                                        (void *) &tmp, sizeof(zval *));
 
@@ -594,6 +952,7 @@ static zend_object_value php_zip_object_new(zend_class_entry *class_type TSRMLS_
        return retval;
 }
 /* }}} */
+#endif
 
 /* {{{ Resource dtors */
 
@@ -636,7 +995,7 @@ static void php_zip_free_entry(zend_rsrc_list_entry *rsrc TSRMLS_DC)
 /* }}}*/
 
 /* reset macro */
-#undef zip
+
 /* {{{ function prototypes */
 static PHP_MINIT_FUNCTION(zip);
 static PHP_MSHUTDOWN_FUNCTION(zip);
@@ -654,7 +1013,7 @@ zend_module_entry zip_module_entry = {
        NULL,
        NULL,
        PHP_MINFO(zip),
-       "2.0.0",
+       "@PACKAGE_VERSION@",
        STANDARD_MODULE_PROPERTIES
 };
 /* }}} */
@@ -663,7 +1022,6 @@ zend_module_entry zip_module_entry = {
 ZEND_GET_MODULE(zip)
 #endif
 /* set macro */
-#define zip php_ziplib__zip
 
 /* {{{ proto resource zip_open(string filename)
 Create new zip using source uri for output */
@@ -671,7 +1029,6 @@ static PHP_NAMED_FUNCTION(zif_zip_open)
 {
        char     *filename;
        int       filename_len;
-       char resolved_path[MAXPATHLEN + 1];
        zip_rsrc *rsrc_int;
        int err = 0;
 
@@ -679,16 +1036,7 @@ static PHP_NAMED_FUNCTION(zif_zip_open)
                return;
        }
 
-       if (filename_len == 0) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string as source");
-               RETURN_FALSE;
-       }
-
-       if (OPENBASEDIR_CHECKPATH(filename)) {
-               RETURN_FALSE;
-       }
-
-       if(!expand_filepath(filename, resolved_path TSRMLS_CC)) {
+       if (SAFEMODE_CHECKFILE(filename)) {
                RETURN_FALSE;
        }
 
@@ -757,7 +1105,6 @@ static PHP_NAMED_FUNCTION(zif_zip_read)
                        rsrc_int->index_current++;
                        ZEND_REGISTER_RESOURCE(return_value, zr_rsrc, le_zip_entry);
                } else {
-                       efree(zr_rsrc);
                        RETURN_FALSE;
                }
 
@@ -839,7 +1186,6 @@ static PHP_NAMED_FUNCTION(zif_zip_entry_read)
                        buffer[n] = 0;
                        RETURN_STRINGL(buffer, n, 0);
                } else {
-                       efree(buffer);
                        RETURN_EMPTY_STRING()
                }
        } else {
@@ -944,6 +1290,7 @@ static PHP_NAMED_FUNCTION(zif_zip_entry_compressionmethod)
 }
 /* }}} */
 
+#ifdef ZEND_ENGINE_2_1
 /* {{{ proto mixed ZipArchive::open(string source [, int flags])
 Create new zip using source uri for output, return TRUE on success or the error code */
 static ZIPARCHIVE_METHOD(open)
@@ -972,10 +1319,6 @@ static ZIPARCHIVE_METHOD(open)
                RETURN_FALSE;
        }
 
-       if (OPENBASEDIR_CHECKPATH(filename)) {
-               RETURN_FALSE;
-       }
-
        if (!expand_filepath(filename, resolved_path TSRMLS_CC)) {
                RETURN_FALSE;
        }
@@ -1031,6 +1374,28 @@ static ZIPARCHIVE_METHOD(close)
 }
 /* }}} */
 
+/* {{{ proto string ZipArchive::getStatusString()
+ * Returns the status error message, system and/or zip messages */
+static ZIPARCHIVE_METHOD(getStatusString)
+{
+       struct zip *intern;
+       zval *this = getThis();
+       int zep, syp, len;
+       char error_string[128];
+
+       if (!this) {
+               RETURN_FALSE;
+       }
+
+       ZIP_FROM_OBJECT(intern, this);
+
+       zip_error_get(intern, &zep, &syp);
+
+       len = zip_error_to_str(error_string, 128, zep, syp);
+       RETVAL_STRINGL(error_string, len, 1); 
+}
+/* }}} */
+
 /* {{{ proto bool ZipArchive::createEmptyDir(string dirname)
 Returns the index of the entry named filename in the archive */
 static ZIPARCHIVE_METHOD(addEmptyDir)
@@ -1050,14 +1415,14 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
        ZIP_FROM_OBJECT(intern, this);
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
-                       &dirname, &dirname_len) == FAILURE) {
+                               &dirname, &dirname_len) == FAILURE) {
                return;
        }
-
        if (dirname_len<1) {
                RETURN_FALSE;
        }
 
+
        if (dirname[dirname_len-1] != '/') {
                s=(char *)emalloc(dirname_len+2);
                strcpy(s, dirname);
@@ -1071,17 +1436,10 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
        if (idx >= 0) {
                RETVAL_FALSE;
        } else {
-               /* reset the error */
-               if (intern->error.str) {
-                       _zip_error_fini(&intern->error);
-               }
-               _zip_error_init(&intern->error);
-
                if (zip_add_dir(intern, (const char *)s) == -1) {
                        RETVAL_FALSE;
-               } else {
-                       RETVAL_TRUE;
                }
+               RETVAL_TRUE;
        }
 
        if (s != dirname) {
@@ -1090,6 +1448,128 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
 }
 /* }}} */
 
+static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
+{
+       struct zip *intern;
+       zval *this = getThis();
+       char *pattern;
+       char *path;
+       char *remove_path = NULL;
+       char *add_path = NULL;
+       int pattern_len, add_path_len, remove_path_len, path_len;
+       long remove_all_path = 0;
+       long flags = 0;
+       zval *options = NULL;
+       int found;
+
+       if (!this) {
+               RETURN_FALSE;
+       }
+
+       ZIP_FROM_OBJECT(intern, this);
+       /* 1 == glob, 2==pcre */
+       if (type == 1) {
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|la", 
+                                       &pattern, &pattern_len, &flags, &options) == FAILURE) {
+                       return;
+               }
+       } else {
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sa", 
+                                       &pattern, &pattern_len, &path, &path_len, &options) == FAILURE) {
+                       return;
+               }
+       }
+
+       if (pattern_len == 0) {
+               php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Empty string as pattern");
+               RETURN_FALSE;
+       }
+       if (options && (php_zip_parse_options(options, &remove_all_path, &remove_path, &remove_path_len,
+                       &add_path, &add_path_len TSRMLS_CC) < 0)) {
+               RETURN_FALSE;
+       }
+
+       if (remove_path && remove_path_len > 1 && (remove_path[strlen(remove_path) - 1] == '/' ||
+               remove_path[strlen(remove_path) - 1] == '\\')) {
+               remove_path[strlen(remove_path) - 1] = '\0';
+       }
+
+       if (type == 1) {
+               found = php_zip_glob(pattern, pattern_len, flags, return_value TSRMLS_CC);
+       } else {
+               found = php_zip_pcre(pattern, pattern_len, path, path_len, return_value TSRMLS_CC);
+       }
+
+       if (found > 0) {
+               int i;
+               zval **zval_file = NULL;
+
+               for (i = 0; i < found; i++) {
+                       char *file, *file_stripped, *entry_name;
+                       int entry_name_len,file_stripped_len;
+                       char entry_name_buf[MAXPATHLEN];
+                       char *basename = NULL;
+
+                       if (zend_hash_index_find(Z_ARRVAL_P(return_value), i, (void **) &zval_file) == SUCCESS) {
+                               file = Z_STRVAL_PP(zval_file);
+                               if (remove_all_path) {
+                                       php_basename(Z_STRVAL_PP(zval_file), Z_STRLEN_PP(zval_file), NULL, 0,
+                                                                       &basename, (unsigned int *)&file_stripped_len TSRMLS_CC);
+                                       file_stripped = basename;
+                               } else if (remove_path && strstr(Z_STRVAL_PP(zval_file), remove_path) != NULL) {
+                                       file_stripped = Z_STRVAL_PP(zval_file) + remove_path_len + 1;
+                                       file_stripped_len = Z_STRLEN_PP(zval_file) - remove_path_len - 1;
+                               } else {
+                                       file_stripped = Z_STRVAL_PP(zval_file);
+                                       file_stripped_len = Z_STRLEN_PP(zval_file);
+                               }
+
+                               if (add_path) {
+                                       if ((add_path_len + file_stripped_len) > MAXPATHLEN) {
+                                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Entry name too long (max: %i, %i given)", 
+                                               MAXPATHLEN - 1, (add_path_len + file_stripped_len));
+                                               zval_dtor(return_value);
+                                               RETURN_FALSE;
+                                       }
+
+                                       snprintf(entry_name_buf, MAXPATHLEN, "%s%s", add_path, file_stripped);
+                                       entry_name = entry_name_buf; 
+                                       entry_name_len = strlen(entry_name);
+                               } else {
+                                       entry_name = Z_STRVAL_PP(zval_file);
+                                       entry_name_len = Z_STRLEN_PP(zval_file);
+                               }
+                               if (basename) {
+                                       efree(basename);
+                                       basename = NULL;
+                               }
+                               if (php_zip_add_file(intern, Z_STRVAL_PP(zval_file), Z_STRLEN_PP(zval_file), 
+                                       entry_name, entry_name_len, 0, 0 TSRMLS_CC) < 0) {
+                                       zval_dtor(return_value);
+                                       RETURN_FALSE;
+                               }
+                       }
+               }
+       }
+}
+/* }}} */
+
+/* {{{ proto bool addGlob(string pattern[,int flags [, array options]])
+Add files matching the glob pattern. See php's glob for the pattern syntax. */
+static ZIPARCHIVE_METHOD(addGlob)
+{
+       php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
+}
+/* }}} */
+
+/* {{{ proto bool addPattern(string pattern[, string path [, array options]])
+Add files matching the pcre pattern. See php's pcre for the pattern syntax. */
+static ZIPARCHIVE_METHOD(addPattern)
+{
+       php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2);
+}
+/* }}} */
+
 /* {{{ proto bool ZipArchive::addFile(string filepath[, string entryname[, int start [, int length]]])
 Add a file in a Zip archive using its path and the name to use. */
 static ZIPARCHIVE_METHOD(addFile)
@@ -1100,10 +1580,7 @@ static ZIPARCHIVE_METHOD(addFile)
        int filename_len;
        char *entry_name = NULL;
        int entry_name_len = 0;
-       struct zip_source *zs;
        long offset_start = 0, offset_len = 0;
-       int cur_idx;
-       char resolved_path[MAXPATHLEN];
 
        if (!this) {
                RETURN_FALSE;
@@ -1126,35 +1603,8 @@ static ZIPARCHIVE_METHOD(addFile)
                entry_name_len = filename_len;
        }
 
-       if (OPENBASEDIR_CHECKPATH(filename)) {
-               RETURN_FALSE;
-       }
-
-       if (!expand_filepath(filename, resolved_path TSRMLS_CC)) {
-               RETURN_FALSE;
-       }
-
-       zs = zip_source_file(intern, resolved_path, 0, 0);
-       if (!zs) {
-               RETURN_FALSE;
-       }
-
-       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) {
+       if (php_zip_add_file(intern, filename, filename_len, 
+               entry_name, entry_name_len, 0, 0 TSRMLS_CC) < 0) {
                RETURN_FALSE;
        } else {
                RETURN_TRUE;
@@ -1206,14 +1656,7 @@ static ZIPARCHIVE_METHOD(addFromString)
 
        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 (cur_idx >= 0) {
                if (zip_delete(intern, cur_idx) == -1) {
                        RETURN_FALSE;
                }
@@ -1310,15 +1753,10 @@ static ZIPARCHIVE_METHOD(locateName)
 
        idx = (long)zip_name_locate(intern, (const char *)name, flags);
 
-       if (idx<0) {
-               /* reset the error */
-               if (intern->error.str) {
-                       _zip_error_fini(&intern->error);
-               }
-               _zip_error_init(&intern->error);
-               RETURN_FALSE;
-       } else {
+       if (idx >= 0) {
                RETURN_LONG(idx);
+       } else {
+               RETURN_FALSE;
        }
 }
 /* }}} */
@@ -1799,12 +2237,12 @@ static ZIPARCHIVE_METHOD(extractTo)
                RETURN_FALSE;
        }
 
-       if (php_stream_stat_path(pathto, &ssb) < 0) {
-               ret = php_stream_mkdir(pathto, 0777,  PHP_STREAM_MKDIR_RECURSIVE, NULL);
-               if (!ret) {
-                       RETURN_FALSE;
-               }
-       }
+    if (php_stream_stat_path(pathto, &ssb) < 0) {
+        ret = php_stream_mkdir(pathto, 0777,  PHP_STREAM_MKDIR_RECURSIVE, NULL);
+        if (!ret) {
+            RETURN_FALSE;
+        }
+    }
 
        ZIP_FROM_OBJECT(intern, this);
        if (zval_files) {
@@ -1839,21 +2277,22 @@ static ZIPARCHIVE_METHOD(extractTo)
                                break;
                }
        } else {
-               /* Extract all files */
-               int filecount = zip_get_num_files(intern);
+        /* Extract all files */
+        int filecount = zip_get_num_files(intern);
 
-               if (filecount == -1) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal archive");
-                       RETURN_FALSE;
-               }
+        if (filecount == -1) {
+            php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal archive");
+            RETURN_FALSE;
+        }
 
-               for (i = 0; i < filecount; i++) {
+        for (i = 0; i < filecount; i++) {
                        char *file = (char*)zip_get_name(intern, i, ZIP_FL_UNCHANGED);
-                       if (!php_zip_extract_file(intern, pathto, file, strlen(file) TSRMLS_CC)) {
-                               RETURN_FALSE;
-                       }
-               }
-       }
+            if (!php_zip_extract_file(intern, pathto, file, strlen(file) TSRMLS_CC)) {
+                RETURN_FALSE;
+            }
+        }
+    }
+
        RETURN_TRUE;
 }
 /* }}} */
@@ -1913,7 +2352,6 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
        buffer = safe_emalloc(len, 1, 2);
        n = zip_fread(zf, buffer, len);
        if (n < 1) {
-               efree(buffer);
                RETURN_EMPTY_STRING();
        }
 
@@ -1976,12 +2414,15 @@ static ZIPARCHIVE_METHOD(getStream)
 /* }}} */
 
 /* {{{ ze_zip_object_class_functions */
-static const zend_function_entry zip_class_functions[] = {
+static zend_function_entry zip_class_functions[] = {
        ZIPARCHIVE_ME(open,                             NULL, ZEND_ACC_PUBLIC)
        ZIPARCHIVE_ME(close,                            NULL, ZEND_ACC_PUBLIC)
+       ZIPARCHIVE_ME(getStatusString,          NULL, ZEND_ACC_PUBLIC)
        ZIPARCHIVE_ME(addEmptyDir,                      NULL, ZEND_ACC_PUBLIC)
        ZIPARCHIVE_ME(addFromString,            NULL, ZEND_ACC_PUBLIC)
        ZIPARCHIVE_ME(addFile,                  NULL, ZEND_ACC_PUBLIC)
+       ZIPARCHIVE_ME(addGlob,                  NULL, ZEND_ACC_PUBLIC)
+       ZIPARCHIVE_ME(addPattern,               NULL, ZEND_ACC_PUBLIC)
        ZIPARCHIVE_ME(renameIndex,              NULL, ZEND_ACC_PUBLIC)
        ZIPARCHIVE_ME(renameName,                       NULL, ZEND_ACC_PUBLIC)
        ZIPARCHIVE_ME(setArchiveComment,        NULL, ZEND_ACC_PUBLIC)
@@ -2007,12 +2448,12 @@ static const zend_function_entry zip_class_functions[] = {
        {NULL, NULL, NULL}
 };
 /* }}} */
+#endif
 
 /* {{{ PHP_MINIT_FUNCTION */
-#undef zip
 static PHP_MINIT_FUNCTION(zip)
-#define zip php_ziplib__zip
 {
+#ifdef ZEND_ENGINE_2_1
        zend_class_entry ce;
 
        memcpy(&zip_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
@@ -2082,6 +2523,7 @@ static PHP_MINIT_FUNCTION(zip)
        REGISTER_ZIP_CLASS_CONST_LONG("ER_DELETED",     ZIP_ER_DELETED);        /* N Entry has been deleted */
 
        php_register_url_stream_wrapper("zip", &php_stream_zip_wrapper TSRMLS_CC);
+#endif
 
        le_zip_dir   = zend_register_list_destructors_ex(php_zip_free_dir,   NULL, le_zip_dir_name,   module_number);
        le_zip_entry = zend_register_list_destructors_ex(php_zip_free_entry, NULL, le_zip_entry_name, module_number);
@@ -2092,28 +2534,26 @@ static PHP_MINIT_FUNCTION(zip)
 
 /* {{{ PHP_MSHUTDOWN_FUNCTION
  */
-#undef zip
 static PHP_MSHUTDOWN_FUNCTION(zip)
-#define zip php_ziplib__zip
 {
+#ifdef ZEND_ENGINE_2_1
        zend_hash_destroy(&zip_prop_handlers);
        php_unregister_url_stream_wrapper("zip" TSRMLS_CC);
-
+#endif
        return SUCCESS;
 }
 /* }}} */
 
 /* {{{ PHP_MINFO_FUNCTION
  */
-#undef zip
 static PHP_MINFO_FUNCTION(zip)
 {
        php_info_print_table_start();
 
        php_info_print_table_row(2, "Zip", "enabled");
        php_info_print_table_row(2, "Extension Version","$Id$");
-       php_info_print_table_row(2, "Zip version", PHP_ZIP_VERSION_STRING);
-       php_info_print_table_row(2, "Libzip version", "0.8.0");
+       php_info_print_table_row(2, "Zip version", "@PACKAGE_VERSION@");
+       php_info_print_table_row(2, "Libzip version", "0.7.1");
 
        php_info_print_table_end();
 }
index dfcf8cc3988d78960226fb1315b511c12a012dbf..542af4b18bff0a65056ae1964c364b70d23029b2 100644 (file)
@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2008 The PHP Group                                |
+  | Copyright (c) 1997-2007 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
 extern zend_module_entry zip_module_entry;
 #define phpext_zip_ptr &zip_module_entry
 
+#ifdef PHP_WIN32
+#define PHP_ZIP_API __declspec(dllexport)
+#else
+#define PHP_ZIP_API
+#endif
+
 #ifdef ZTS
 #include "TSRM.h"
 #endif
 
 #include "lib/zip.h"
 
-#define PHP_ZIP_VERSION_STRING "1.8.11"
+#ifndef ZEND_ENGINE_2_1
+# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) || PHP_MAJOR_VERSION == 6
+#  define ZEND_ENGINE_2_1
+# endif
+#endif
+
+#ifndef  Z_SET_REFCOUNT_P
+# if PHP_MAJOR_VERSION < 6 && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3)
+#  define Z_SET_REFCOUNT_P(pz, rc)  pz->refcount = rc 
+#  define Z_UNSET_ISREF_P(pz) pz->is_ref = 0 
+# endif
+#endif
 
 /* {{{ OPENBASEDIR_CHECKPATH(filename) */
 #if (PHP_MAJOR_VERSION < 6)
@@ -55,6 +72,7 @@ typedef struct _ze_zip_read_rsrc {
        struct zip_stat sb;
 } zip_read_rsrc;
 
+#ifdef ZEND_ENGINE_2_1
 #define ZIPARCHIVE_ME(name, arg_info, flags)   ZEND_FENTRY(name, c_ziparchive_ ##name, arg_info, flags)
 #define ZIPARCHIVE_METHOD(name)        ZEND_NAMED_FUNCTION(c_ziparchive_##name)
 
@@ -73,6 +91,19 @@ php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper, char *path, char
 php_stream *php_stream_zip_open(char *filename, char *path, char *mode STREAMS_DC TSRMLS_DC);
 
 extern php_stream_wrapper php_stream_zip_wrapper;
+#endif
+
+/* zip_open is a macro for renaming libzip zipopen, so we need to use PHP_NAMED_FUNCTION */
+static PHP_NAMED_FUNCTION(zif_zip_open);
+static PHP_NAMED_FUNCTION(zif_zip_read);
+static PHP_NAMED_FUNCTION(zif_zip_close);
+static PHP_NAMED_FUNCTION(zif_zip_entry_read);
+static PHP_NAMED_FUNCTION(zif_zip_entry_filesize);
+static PHP_NAMED_FUNCTION(zif_zip_entry_name);
+static PHP_NAMED_FUNCTION(zif_zip_entry_compressedsize);
+static PHP_NAMED_FUNCTION(zif_zip_entry_compressionmethod);
+static PHP_NAMED_FUNCTION(zif_zip_entry_open);
+static PHP_NAMED_FUNCTION(zif_zip_entry_close);
 
 #endif /* PHP_ZIP_H */
 
index f4896df99bc7d40d464a96c7a7f6f351f6d314b1..02985848dc2e32521500abc602b2101c9b619c81 100644 (file)
@@ -1,26 +1,14 @@
 --TEST--
-#38943, properties in extended class cannot be set
+#38943, properties in extended class cannot be set (< 5.3)
 --SKIPIF--
 <?php
 /* $Id$ */
 if(!extension_loaded('zip')) die('skip');
+if (!defined('PHP_VERSION_MAJOR')) die('skip');
 ?>
 --FILE--
 <?php
-class myZip extends ZipArchive {
-       private $test = 0;
-       public $testp = 1;
-       private $testarray = array();
-
-       public function __construct() {
-               $this->testarray[] = 1;
-               var_dump($this->testarray);
-       }
-}
-
-$z = new myZip;
-$z->testp = "foobar";
-var_dump($z);
+include dirname(__FILE__) . '/bug38943.inc';
 ?>
 --EXPECTF--
 array(1) {
@@ -28,11 +16,11 @@ array(1) {
   int(1)
 }
 object(myZip)#1 (%d) {
-  ["test":"myZip":private]=>
+  ["test:private"]=>
   int(0)
   ["testp"]=>
   string(6) "foobar"
-  ["testarray":"myZip":private]=>
+  ["testarray:private"]=>
   array(1) {
     [0]=>
     int(1)
index 450c357239db7bda561b441972a71ba50b1c6db1..6e4331552078b8d52534c15546a09f959d4900e0 100644 (file)
@@ -7,6 +7,23 @@ if(!extension_loaded('zip')) die('skip');
 ?>
 --FILE--
 <?php
+$expect = array(
+       "mimetype",
+       "Configurations2/statusbar/",
+       "Configurations2/accelerator/current.xml",
+       "Configurations2/floater/",
+       "Configurations2/popupmenu/",
+       "Configurations2/progressbar/",
+       "Configurations2/menubar/",
+       "Configurations2/toolbar/",
+       "Configurations2/images/Bitmaps/",
+       "content.xml",
+       "styles.xml",
+       "meta.xml",
+       "Thumbnails/thumbnail.png",
+       "settings.xml",
+       "META-INF/manifest.xml",
+);
 $dirname = dirname(__FILE__) . '/';
 include $dirname . 'utils.inc';
 $file = $dirname . '__tmp_bug7658.odt';
@@ -16,45 +33,22 @@ if(!$zip->open($file)) {
        echo 'failed';
 }
 
-dump_entries_name($zip);
 
 $zip->deleteName('content.xml');
 $zip->addFile($dirname . "bug7658.xml","content.xml");
 $zip->close();
 echo "\n";
 $zip->open($file);
-dump_entries_name($zip);
+
+for($i=0; $i < $zip->numFiles; $i++) {
+       $sb = $zip->statIndex($i);
+       $found[] = $sb['name'];
+}
+$ar = array_diff($found, $expect);
+
+var_dump($ar);
 @unlink($file);
 ?>
---EXPECT--
-0 mimetype
-1 Configurations2/statusbar/
-2 Configurations2/accelerator/current.xml
-3 Configurations2/floater/
-4 Configurations2/popupmenu/
-5 Configurations2/progressbar/
-6 Configurations2/menubar/
-7 Configurations2/toolbar/
-8 Configurations2/images/Bitmaps/
-9 content.xml
-10 styles.xml
-11 meta.xml
-12 Thumbnails/thumbnail.png
-13 settings.xml
-14 META-INF/manifest.xml
-
-0 mimetype
-1 Configurations2/statusbar/
-2 Configurations2/accelerator/current.xml
-3 Configurations2/floater/
-4 Configurations2/popupmenu/
-5 Configurations2/progressbar/
-6 Configurations2/menubar/
-7 Configurations2/toolbar/
-8 Configurations2/images/Bitmaps/
-9 styles.xml
-10 meta.xml
-11 Thumbnails/thumbnail.png
-12 settings.xml
-13 META-INF/manifest.xml
-14 content.xml
+--EXPECTF--
+array(0) {
+}
\ No newline at end of file