Browse files

Initial commit

  • Loading branch information...
0 parents commit 1093938d754b127ce41ce28d7dae5f08afe60cd8 @julienr committed Dec 2, 2010
Showing with 6,411 additions and 0 deletions.
  1. +27 −0 LICENSE
  2. +9 −0 README.rst
  3. +2 −0 build.sh
  4. +78 −0 jni/Android.mk
  5. +2 −0 jni/Application.mk
  6. +97 −0 jni/config.h
  7. +140 −0 jni/mkstemp.c
  8. +230 −0 jni/zip.h
  9. +49 −0 jni/zip_add.c
  10. +80 −0 jni/zip_add_dir.c
  11. +679 −0 jni/zip_close.c
  12. +58 −0 jni/zip_delete.c
  13. +615 −0 jni/zip_dirent.c
  14. +52 −0 jni/zip_entry_free.c
  15. +78 −0 jni/zip_entry_new.c
  16. +68 −0 jni/zip_err_str.c
  17. +101 −0 jni/zip_error.c
  18. +44 −0 jni/zip_error_clear.c
  19. +44 −0 jni/zip_error_get.c
  20. +47 −0 jni/zip_error_get_sys_type.c
  21. +90 −0 jni/zip_error_strerror.c
  22. +70 −0 jni/zip_error_to_str.c
  23. +71 −0 jni/zip_fclose.c
  24. +44 −0 jni/zip_file_error_clear.c
  25. +44 −0 jni/zip_file_error_get.c
  26. +74 −0 jni/zip_file_get_offset.c
  27. +44 −0 jni/zip_file_strerror.c
  28. +71 −0 jni/zip_filerange_crc.c
  29. +49 −0 jni/zip_fopen.c
  30. +216 −0 jni/zip_fopen_index.c
  31. +130 −0 jni/zip_fread.c
  32. +81 −0 jni/zip_free.c
  33. +60 −0 jni/zip_get_archive_comment.c
  34. +48 −0 jni/zip_get_archive_flag.c
  35. +58 −0 jni/zip_get_file_comment.c
  36. +71 −0 jni/zip_get_name.c
  37. +47 −0 jni/zip_get_num_files.c
  38. +55 −0 jni/zip_memdup.c
  39. +88 −0 jni/zip_name_locate.c
  40. +70 −0 jni/zip_new.c
  41. +567 −0 jni/zip_open.c
  42. +65 −0 jni/zip_rename.c
  43. +78 −0 jni/zip_replace.c
  44. +65 −0 jni/zip_set_archive_comment.c
  45. +49 −0 jni/zip_set_archive_flag.c
  46. +66 −0 jni/zip_set_file_comment.c
  47. +75 −0 jni/zip_set_name.c
  48. +157 −0 jni/zip_source_buffer.c
  49. +55 −0 jni/zip_source_file.c
  50. +216 −0 jni/zip_source_filep.c
  51. +51 −0 jni/zip_source_free.c
  52. +59 −0 jni/zip_source_function.c
  53. +188 −0 jni/zip_source_zip.c
  54. +49 −0 jni/zip_stat.c
  55. +90 −0 jni/zip_stat_index.c
  56. +51 −0 jni/zip_stat_init.c
  57. +44 −0 jni/zip_strerror.c
  58. +82 −0 jni/zip_unchange.c
  59. +54 −0 jni/zip_unchange_all.c
  60. +52 −0 jni/zip_unchange_archive.c
  61. +53 −0 jni/zip_unchange_data.c
  62. +264 −0 jni/zipint.h
27 LICENSE
@@ -0,0 +1,27 @@
+Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner
+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
+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. 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
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS 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.
9 README.rst
@@ -0,0 +1,9 @@
+libzip for Android
+==================
+This is a repackaging of libzip for the Android NDK.
+
+The only changed files are config.h and the android .mk files.
+
+libzip has been written by Dieter Baron and Thomas Klausner.
+
+Assuming 'ndk-build' is in your path, you can use the build.sh script to build a static lib.
2 build.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+ndk-build NDK_PROJECT_PATH=./ $@
78 jni/Android.mk
@@ -0,0 +1,78 @@
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libzip
+LOCAL_SRC_FILES :=\
+ zip_add.c \
+ zip_add_dir.c \
+ zip_close.c \
+ zip_delete.c \
+ zip_dirent.c \
+ zip_entry_free.c \
+ zip_entry_new.c \
+ zip_err_str.c \
+ zip_error.c \
+ zip_error_clear.c \
+ zip_error_get.c \
+ zip_error_get_sys_type.c \
+ zip_error_strerror.c \
+ zip_error_to_str.c \
+ zip_fclose.c \
+ zip_file_error_clear.c \
+ zip_file_error_get.c \
+ zip_file_get_offset.c \
+ zip_file_strerror.c \
+ zip_filerange_crc.c \
+ zip_fopen.c \
+ zip_fopen_index.c \
+ zip_fread.c \
+ zip_free.c \
+ zip_get_archive_comment.c \
+ zip_get_archive_flag.c \
+ zip_get_file_comment.c \
+ zip_get_num_files.c \
+ zip_get_name.c \
+ zip_memdup.c \
+ zip_name_locate.c \
+ zip_new.c \
+ zip_open.c \
+ zip_rename.c \
+ zip_replace.c \
+ zip_set_archive_comment.c \
+ zip_set_archive_flag.c \
+ zip_set_file_comment.c \
+ zip_source_buffer.c \
+ zip_source_file.c \
+ zip_source_filep.c \
+ zip_source_free.c \
+ zip_source_function.c \
+ zip_source_zip.c \
+ zip_set_name.c \
+ zip_stat.c \
+ zip_stat_index.c \
+ zip_stat_init.c \
+ zip_strerror.c \
+ zip_unchange.c \
+ zip_unchange_all.c \
+ zip_unchange_archive.c \
+ zip_unchange_data.c
+
+LOCAL_LDLIBS := -lz
+
+#include $(BUILD_SHARED_LIBRARY)
+include $(BUILD_STATIC_LIBRARY)
2 jni/Application.mk
@@ -0,0 +1,2 @@
+APP_OPTIM := release
+APP_MODULES := libzip
97 jni/config.h
@@ -0,0 +1,97 @@
+/* Config header for Android */
+/* Define to 1 if you have the declaration of `tzname', and to 0 if you don't.
+ */
+/* #undef HAVE_DECL_TZNAME */
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 0
+
+/* Define to 1 if you have the `fseeko' function. */
+#define HAVE_FSEEKO 0
+
+/* Define to 1 if you have the `ftello' function. */
+#define HAVE_FTELLO 0
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 0
+
+/* Define to 1 if you have the `z' library (-lz). */
+#define HAVE_LIBZ 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 0
+
+/* Define to 1 if you have the `mkstemp' function. */
+#define HAVE_MKSTEMP 0
+
+/* Define to 1 if you have the `MoveFileExA' function. */
+/* #undef HAVE_MOVEFILEEXA */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if `tm_zone' is a member of `struct tm'. */
+#define HAVE_STRUCT_TM_TM_ZONE 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
+ `HAVE_STRUCT_TM_TM_ZONE' instead. */
+#define HAVE_TM_ZONE 1
+
+/* Define to 1 if you don't have `tm_zone' but do have the external array
+ `tzname'. */
+/* #undef HAVE_TZNAME */
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+ */
+#define LT_OBJDIR ".libs/"
+
+/* Define to 1 if your C compiler doesn't accept -c and -o together. */
+/* #undef NO_MINUS_C_MINUS_O */
+
+/* Name of package */
+#define PACKAGE "libzip"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "libzip@nih.at"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libzip"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libzip 0.9.3"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libzip"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "0.9.3"
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if your <sys/time.h> declares `struct tm'. */
+/* #undef TM_IN_SYS_TIME */
+
+/* Version number of package */
+#define VERSION "0.9.3"
140 jni/mkstemp.c
@@ -0,0 +1,140 @@
+/* $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>
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+
+
+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|O_BINARY, 0600)) >= 0)
+ return (fd);
+ 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*/
+}
230 jni/zip.h
@@ -0,0 +1,230 @@
+#ifndef _HAD_ZIP_H
+#define _HAD_ZIP_H
+
+/*
+ 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 <libzip@nih.at>
+
+ 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. 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
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS 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.
+*/
+
+
+
+#ifndef ZIP_EXTERN
+#ifdef _MSC_VER
+#define ZIP_EXTERN __declspec(dllexport)
+#else
+#define ZIP_EXTERN
+#endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <time.h>
+
+/* flags for zip_open */
+
+#define ZIP_CREATE 1
+#define ZIP_EXCL 2
+#define ZIP_CHECKCONS 4
+
+
+/* flags for zip_name_locate, zip_fopen, zip_stat, ... */
+
+#define ZIP_FL_NOCASE 1 /* ignore case on name lookup */
+#define ZIP_FL_NODIR 2 /* ignore directory component */
+#define ZIP_FL_COMPRESSED 4 /* read compressed data */
+#define ZIP_FL_UNCHANGED 8 /* use original data, ignoring changes */
+#define ZIP_FL_RECOMPRESS 16 /* force recompression of data */
+
+/* archive global flags flags */
+
+#define ZIP_AFL_TORRENT 1 /* torrent zipped */
+
+/* libzip error codes */
+
+#define ZIP_ER_OK 0 /* N No error */
+#define ZIP_ER_MULTIDISK 1 /* N Multi-disk zip archives not supported */
+#define ZIP_ER_RENAME 2 /* S Renaming temporary file failed */
+#define ZIP_ER_CLOSE 3 /* S Closing zip archive failed */
+#define ZIP_ER_SEEK 4 /* S Seek error */
+#define ZIP_ER_READ 5 /* S Read error */
+#define ZIP_ER_WRITE 6 /* S Write error */
+#define ZIP_ER_CRC 7 /* N CRC error */
+#define ZIP_ER_ZIPCLOSED 8 /* N Containing zip archive was closed */
+#define ZIP_ER_NOENT 9 /* N No such file */
+#define ZIP_ER_EXISTS 10 /* N File already exists */
+#define ZIP_ER_OPEN 11 /* S Can't open file */
+#define ZIP_ER_TMPOPEN 12 /* S Failure to create temporary file */
+#define ZIP_ER_ZLIB 13 /* Z Zlib error */
+#define ZIP_ER_MEMORY 14 /* N Malloc failure */
+#define ZIP_ER_CHANGED 15 /* N Entry has been changed */
+#define ZIP_ER_COMPNOTSUPP 16 /* N Compression method not supported */
+#define ZIP_ER_EOF 17 /* N Premature EOF */
+#define ZIP_ER_INVAL 18 /* N Invalid argument */
+#define ZIP_ER_NOZIP 19 /* N Not a zip archive */
+#define ZIP_ER_INTERNAL 20 /* N Internal error */
+#define ZIP_ER_INCONS 21 /* N Zip archive inconsistent */
+#define ZIP_ER_REMOVE 22 /* S Can't remove file */
+#define ZIP_ER_DELETED 23 /* N Entry has been deleted */
+
+
+/* type of system error value */
+
+#define ZIP_ET_NONE 0 /* sys_err unused */
+#define ZIP_ET_SYS 1 /* sys_err is errno */
+#define ZIP_ET_ZLIB 2 /* sys_err is zlib error code */
+
+/* compression methods */
+
+#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
+#define ZIP_CM_STORE 0 /* stored (uncompressed) */
+#define ZIP_CM_SHRINK 1 /* shrunk */
+#define ZIP_CM_REDUCE_1 2 /* reduced with factor 1 */
+#define ZIP_CM_REDUCE_2 3 /* reduced with factor 2 */
+#define ZIP_CM_REDUCE_3 4 /* reduced with factor 3 */
+#define ZIP_CM_REDUCE_4 5 /* reduced with factor 4 */
+#define ZIP_CM_IMPLODE 6 /* imploded */
+/* 7 - Reserved for Tokenizing compression algorithm */
+#define ZIP_CM_DEFLATE 8 /* deflated */
+#define ZIP_CM_DEFLATE64 9 /* deflate64 */
+#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 */
+
+#define ZIP_EM_NONE 0 /* not encrypted */
+#define ZIP_EM_TRAD_PKWARE 1 /* traditional PKWARE encryption */
+#if 0 /* Strong Encryption Header not parsed yet */
+#define ZIP_EM_DES 0x6601 /* strong encryption: DES */
+#define ZIP_EM_RC2_OLD 0x6602 /* strong encryption: RC2, version < 5.2 */
+#define ZIP_EM_3DES_168 0x6603
+#define ZIP_EM_3DES_112 0x6609
+#define ZIP_EM_AES_128 0x660e
+#define ZIP_EM_AES_192 0x660f
+#define ZIP_EM_AES_256 0x6610
+#define ZIP_EM_RC2 0x6702 /* strong encryption: RC2, version >= 5.2 */
+#define ZIP_EM_RC4 0x6801
+#endif
+#define ZIP_EM_UNKNOWN 0xffff /* unknown algorithm */
+
+
+
+enum zip_source_cmd {
+ ZIP_SOURCE_OPEN, /* prepare for reading */
+ ZIP_SOURCE_READ, /* read data */
+ ZIP_SOURCE_CLOSE, /* reading is done */
+ ZIP_SOURCE_STAT, /* get meta information */
+ ZIP_SOURCE_ERROR, /* get error information */
+ 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);
+
+struct zip_stat {
+ const char *name; /* name of the file */
+ int index; /* index within archive */
+ unsigned int crc; /* crc of file data */
+ time_t mtime; /* modification time */
+ off_t size; /* size of file (uncompressed) */
+ off_t comp_size; /* size of file (compressed) */
+ unsigned short comp_method; /* compression method used */
+ unsigned short encryption_method; /* encryption method used */
+};
+
+struct zip;
+struct zip_file;
+struct zip_source;
+
+
+
+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 *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _HAD_ZIP_H */
49 jni/zip_add.c
@@ -0,0 +1,49 @@
+/*
+ zip_add.c -- add file via callback function
+ 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 <libzip@nih.at>
+
+ 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. 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
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS 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 "zipint.h"
+
+
+
+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);
+}
80 jni/zip_add_dir.c
@@ -0,0 +1,80 @@
+/*
+ zip_add_dir.c -- add directory
+ 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 <libzip@nih.at>
+
+ 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. 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
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS 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 <stdlib.h>
+#include <string.h>
+
+#include "zipint.h"
+
+
+
+ZIP_EXTERN int
+zip_add_dir(struct zip *za, const char *name)
+{
+ int len, ret;
+ char *s;
+ struct zip_source *source;
+
+ if (name == NULL) {
+ _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+ return -1;
+ }
+
+ s = NULL;
+ len = strlen(name);
+
+ if (name[len-1] != '/') {
+ if ((s=(char *)malloc(len+2)) == NULL) {
+ _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ return -1;
+ }
+ strcpy(s, name);
+ s[len] = '/';
+ s[len+1] = '\0';
+ }
+
+ if ((source=zip_source_buffer(za, NULL, 0, 0)) == NULL) {
+ free(s);
+ return -1;
+ }
+
+ ret = _zip_replace(za, -1, s ? s : name, source);
+
+ free(s);
+ if (ret < 0)
+ zip_source_free(source);
+
+ return ret;
+}
679 jni/zip_close.c
@@ -0,0 +1,679 @@
+/*
+ zip_close.c -- close zip archive and update changes
+ 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 <libzip@nih.at>
+
+ 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. 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
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "zipint.h"
+
+static int add_data(struct zip *, struct zip_source *, struct zip_dirent *,
+ FILE *);
+static int add_data_comp(zip_source_callback, void *, struct zip_stat *,
+ FILE *, struct zip_error *);
+static int add_data_uncomp(struct zip *, zip_source_callback, void *,
+ struct zip_stat *, FILE *);
+static void ch_set_error(struct zip_error *, zip_source_callback, void *);
+static int copy_data(FILE *, off_t, FILE *, struct zip_error *);
+static int write_cdir(struct zip *, struct zip_cdir *, FILE *);
+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 **);
+static int _zip_torrentzip_cmp(const void *, const void *);
+
+
+
+struct filelist {
+ int idx;
+ const char *name;
+};
+
+
+
+ZIP_EXTERN int
+zip_close(struct zip *za)
+{
+ int survivors;
+ int i, j, error;
+ char *temp;
+ FILE *out;
+ mode_t mask;
+ struct zip_cdir *cd;
+ struct zip_dirent de;
+ struct filelist *filelist;
+ int reopen_on_error;
+ int new_torrentzip;
+
+ reopen_on_error = 0;
+
+ if (za == NULL)
+ return -1;
+
+ if (!_zip_changed(za, &survivors)) {
+ _zip_free(za);
+ return 0;
+ }
+
+ /* don't create zip files with no entries */
+ if (survivors == 0) {
+ if (za->zn && za->zp) {
+ if (remove(za->zn) != 0) {
+ _zip_error_set(&za->error, ZIP_ER_REMOVE, errno);
+ return -1;
+ }
+ }
+ _zip_free(za);
+ return 0;
+ }
+
+ if ((filelist=(struct filelist *)malloc(sizeof(filelist[0])*survivors))
+ == NULL)
+ return -1;
+
+ if ((cd=_zip_cdir_new(survivors, &za->error)) == NULL) {
+ free(filelist);
+ return -1;
+ }
+
+ for (i=0; i<survivors; i++)
+ _zip_dirent_init(&cd->entry[i]);
+
+ /* archive comment is special for torrentzip */
+ if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0)) {
+ cd->comment = _zip_memdup(TORRENT_SIG "XXXXXXXX",
+ TORRENT_SIG_LEN + TORRENT_CRC_LEN,
+ &za->error);
+ if (cd->comment == NULL) {
+ _zip_cdir_free(cd);
+ free(filelist);
+ return -1;
+ }
+ cd->comment_len = TORRENT_SIG_LEN + TORRENT_CRC_LEN;
+ }
+ else if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, ZIP_FL_UNCHANGED) == 0) {
+ if (_zip_cdir_set_comment(cd, za) == -1) {
+ _zip_cdir_free(cd);
+ free(filelist);
+ return -1;
+ }
+ }
+
+ if ((temp=_zip_create_temp_output(za, &out)) == NULL) {
+ _zip_cdir_free(cd);
+ free(filelist);
+ return -1;
+ }
+
+
+ /* create list of files with index into original archive */
+ for (i=j=0; i<za->nentry; i++) {
+ if (za->entry[i].state == ZIP_ST_DELETED)
+ continue;
+
+ filelist[j].idx = i;
+ filelist[j].name = zip_get_name(za, i, 0);
+ j++;
+ }
+ if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0))
+ qsort(filelist, survivors, sizeof(filelist[0]),
+ _zip_torrentzip_cmp);
+
+ new_torrentzip = (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0) == 1
+ && zip_get_archive_flag(za, ZIP_AFL_TORRENT,
+ ZIP_FL_UNCHANGED) == 0);
+ error = 0;
+ for (j=0; j<survivors; j++) {
+ i = filelist[j].idx;
+
+ /* create new local directory entry */
+ if (ZIP_ENTRY_DATA_CHANGED(za->entry+i) || new_torrentzip) {
+ _zip_dirent_init(&de);
+
+ if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0))
+ _zip_dirent_torrent_normalize(&de);
+
+ /* use it as central directory entry */
+ memcpy(cd->entry+j, &de, sizeof(cd->entry[j]));
+
+ /* set/update file name */
+ if (za->entry[i].ch_filename == NULL) {
+ if (za->entry[i].state == ZIP_ST_ADDED) {
+ de.filename = strdup("-");
+ de.filename_len = 1;
+ cd->entry[j].filename = "-";
+ cd->entry[j].filename_len = 1;
+ }
+ else {
+ de.filename = strdup(za->cdir->entry[i].filename);
+ de.filename_len = strlen(de.filename);
+ cd->entry[j].filename = za->cdir->entry[i].filename;
+ cd->entry[j].filename_len = de.filename_len;
+ }
+ }
+ }
+ else {
+ /* copy existing directory entries */
+ if (fseeko(za->zp, za->cdir->entry[i].offset, SEEK_SET) != 0) {
+ _zip_error_set(&za->error, ZIP_ER_SEEK, errno);
+ error = 1;
+ break;
+ }
+ if (_zip_dirent_read(&de, za->zp, NULL, NULL, 1,
+ &za->error) != 0) {
+ error = 1;
+ break;
+ }
+ memcpy(cd->entry+j, za->cdir->entry+i, sizeof(cd->entry[j]));
+ 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;
+ cd->entry[j].bitflags &= ~ZIP_GPBF_DATA_DESCRIPTOR;
+ }
+ }
+
+ if (za->entry[i].ch_filename) {
+ free(de.filename);
+ if ((de.filename=strdup(za->entry[i].ch_filename)) == NULL) {
+ error = 1;
+ break;
+ }
+ de.filename_len = strlen(de.filename);
+ cd->entry[j].filename = za->entry[i].ch_filename;
+ cd->entry[j].filename_len = de.filename_len;
+ }
+
+ if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0) == 0
+ && za->entry[i].ch_comment_len != -1) {
+ /* as the rest of cd entries, its malloc/free is done by za */
+ cd->entry[j].comment = za->entry[i].ch_comment;
+ cd->entry[j].comment_len = za->entry[i].ch_comment_len;
+ }
+
+ cd->entry[j].offset = ftello(out);
+
+ if (ZIP_ENTRY_DATA_CHANGED(za->entry+i) || new_torrentzip) {
+ struct zip_source *zs;
+
+ zs = NULL;
+ if (!ZIP_ENTRY_DATA_CHANGED(za->entry+i)) {
+ if ((zs=zip_source_zip(za, za, i, ZIP_FL_RECOMPRESS, 0, -1))
+ == NULL) {
+ error = 1;
+ break;
+ }
+ }
+
+ if (add_data(za, zs ? zs : za->entry[i].source, &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;
+ cd->entry[j].uncomp_size = de.uncomp_size;
+ cd->entry[j].crc = de.crc;
+ }
+ else {
+ if (_zip_dirent_write(&de, out, 1, &za->error) < 0) {
+ error = 1;
+ break;
+ }
+ /* we just read the local dirent, file is at correct position */
+ if (copy_data(za->zp, cd->entry[j].comp_size, out,
+ &za->error) < 0) {
+ error = 1;
+ break;
+ }
+ }
+
+ _zip_dirent_finalize(&de);
+ }
+
+ free(filelist);
+
+ if (!error) {
+ if (write_cdir(za, cd, out) < 0)
+ error = 1;
+ }
+
+ /* pointers in cd entries are owned by za */
+ cd->nentry = 0;
+ _zip_cdir_free(cd);
+
+ if (error) {
+ _zip_dirent_finalize(&de);
+ fclose(out);
+ remove(temp);
+ free(temp);
+ return -1;
+ }
+
+ if (fclose(out) != 0) {
+ _zip_error_set(&za->error, ZIP_ER_CLOSE, errno);
+ remove(temp);
+ free(temp);
+ return -1;
+ }
+
+ if (za->zp) {
+ fclose(za->zp);
+ za->zp = NULL;
+ reopen_on_error = 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);
+
+ return 0;
+}
+
+
+
+static int
+add_data(struct zip *za, struct zip_source *zs, struct zip_dirent *de, FILE *ft)
+{
+ off_t offstart, offend;
+ zip_source_callback cb;
+ void *ud;
+ struct zip_stat st;
+
+ cb = zs->f;
+ ud = zs->ud;
+
+ if (cb(ud, &st, sizeof(st), ZIP_SOURCE_STAT) < (ssize_t)sizeof(st)) {
+ ch_set_error(&za->error, cb, ud);
+ return -1;
+ }
+
+ if (cb(ud, NULL, 0, ZIP_SOURCE_OPEN) < 0) {
+ ch_set_error(&za->error, cb, ud);
+ return -1;
+ }
+
+ offstart = ftello(ft);
+
+ if (_zip_dirent_write(de, ft, 1, &za->error) < 0)
+ return -1;
+
+ if (st.comp_method != ZIP_CM_STORE) {
+ if (add_data_comp(cb, ud, &st, ft, &za->error) < 0)
+ return -1;
+ }
+ else {
+ if (add_data_uncomp(za, cb, ud, &st, ft) < 0)
+ return -1;
+ }
+
+ if (cb(ud, NULL, 0, ZIP_SOURCE_CLOSE) < 0) {
+ ch_set_error(&za->error, cb, ud);
+ return -1;
+ }
+
+ offend = ftello(ft);
+
+ if (fseeko(ft, offstart, SEEK_SET) < 0) {
+ _zip_error_set(&za->error, ZIP_ER_SEEK, errno);
+ return -1;
+ }
+
+
+ de->last_mod = st.mtime;
+ de->comp_method = st.comp_method;
+ de->crc = st.crc;
+ de->uncomp_size = st.size;
+ de->comp_size = st.comp_size;
+
+ if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0))
+ _zip_dirent_torrent_normalize(de);
+
+ if (_zip_dirent_write(de, ft, 1, &za->error) < 0)
+ return -1;
+
+ if (fseeko(ft, offend, SEEK_SET) < 0) {
+ _zip_error_set(&za->error, ZIP_ER_SEEK, errno);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+
+static int
+add_data_comp(zip_source_callback cb, void *ud, struct zip_stat *st,FILE *ft,
+ struct zip_error *error)
+{
+ char buf[BUFSIZE];
+ ssize_t n;
+
+ st->comp_size = 0;
+ while ((n=cb(ud, buf, sizeof(buf), ZIP_SOURCE_READ)) > 0) {
+ if (fwrite(buf, 1, n, ft) != (size_t)n) {
+ _zip_error_set(error, ZIP_ER_WRITE, errno);
+ return -1;
+ }
+
+ st->comp_size += n;
+ }
+ if (n < 0) {
+ ch_set_error(error, cb, ud);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+
+static int
+add_data_uncomp(struct zip *za, zip_source_callback cb, void *ud,
+ struct zip_stat *st, FILE *ft)
+{
+ char b1[BUFSIZE], b2[BUFSIZE];
+ int end, flush, ret;
+ ssize_t n;
+ size_t n2;
+ z_stream zstr;
+ int mem_level;
+
+ st->comp_method = ZIP_CM_DEFLATE;
+ st->comp_size = st->size = 0;
+ st->crc = crc32(0, NULL, 0);
+
+ zstr.zalloc = Z_NULL;
+ zstr.zfree = Z_NULL;
+ zstr.opaque = NULL;
+ zstr.avail_in = 0;
+ zstr.avail_out = 0;
+
+ if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0))
+ mem_level = TORRENT_MEM_LEVEL;
+ else
+ mem_level = MAX_MEM_LEVEL;
+
+ /* -MAX_WBITS: undocumented feature of zlib to _not_ write a zlib header */
+ deflateInit2(&zstr, Z_BEST_COMPRESSION, Z_DEFLATED, -MAX_WBITS, mem_level,
+ Z_DEFAULT_STRATEGY);
+
+ zstr.next_out = (Bytef *)b2;
+ zstr.avail_out = sizeof(b2);
+ zstr.next_in = NULL;
+ zstr.avail_in = 0;
+
+ flush = 0;
+ end = 0;
+ while (!end) {
+ if (zstr.avail_in == 0 && !flush) {
+ if ((n=cb(ud, b1, sizeof(b1), ZIP_SOURCE_READ)) < 0) {
+ ch_set_error(&za->error, cb, ud);
+ deflateEnd(&zstr);
+ return -1;
+ }
+ if (n > 0) {
+ zstr.avail_in = n;
+ zstr.next_in = (Bytef *)b1;
+ st->size += n;
+ st->crc = crc32(st->crc, (Bytef *)b1, n);
+ }
+ else
+ flush = Z_FINISH;
+ }
+
+ ret = deflate(&zstr, flush);
+ if (ret != Z_OK && ret != Z_STREAM_END) {
+ _zip_error_set(&za->error, ZIP_ER_ZLIB, ret);
+ return -1;
+ }
+
+ if (zstr.avail_out != sizeof(b2)) {
+ n2 = sizeof(b2) - zstr.avail_out;
+
+ if (fwrite(b2, 1, n2, ft) != n2) {
+ _zip_error_set(&za->error, ZIP_ER_WRITE, errno);
+ return -1;
+ }
+
+ zstr.next_out = (Bytef *)b2;
+ zstr.avail_out = sizeof(b2);
+ st->comp_size += n2;
+ }
+
+ if (ret == Z_STREAM_END) {
+ deflateEnd(&zstr);
+ end = 1;
+ }
+ }
+
+ return 0;
+}
+
+
+
+static void
+ch_set_error(struct zip_error *error, zip_source_callback cb, void *ud)
+{
+ int e[2];
+
+ if ((cb(ud, e, sizeof(e), ZIP_SOURCE_ERROR)) < (ssize_t)sizeof(e)) {
+ error->zip_err = ZIP_ER_INTERNAL;
+ error->sys_err = 0;
+ }
+ else {
+ error->zip_err = e[0];
+ error->sys_err = e[1];
+ }
+}
+
+
+
+static int
+copy_data(FILE *fs, off_t len, FILE *ft, struct zip_error *error)
+{
+ char buf[BUFSIZE];
+ int n, nn;
+
+ if (len == 0)
+ return 0;
+
+ while (len > 0) {
+ nn = len > sizeof(buf) ? sizeof(buf) : len;
+ if ((n=fread(buf, 1, nn, fs)) < 0) {
+ _zip_error_set(error, ZIP_ER_READ, errno);
+ return -1;
+ }
+ else if (n == 0) {
+ _zip_error_set(error, ZIP_ER_EOF, 0);
+ return -1;
+ }
+
+ if (fwrite(buf, 1, n, ft) != (size_t)n) {
+ _zip_error_set(error, ZIP_ER_WRITE, errno);
+ return -1;
+ }
+
+ len -= n;
+ }
+
+ return 0;
+}
+
+
+
+static int
+write_cdir(struct zip *za, struct zip_cdir *cd, FILE *out)
+{
+ off_t offset;
+ uLong crc;
+ char buf[TORRENT_CRC_LEN+1];
+
+ if (_zip_cdir_write(cd, out, &za->error) < 0)
+ return -1;
+
+ if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0) == 0)
+ return 0;
+
+
+ /* fix up torrentzip comment */
+
+ offset = ftello(out);
+
+ if (_zip_filerange_crc(out, cd->offset, cd->size, &crc, &za->error) < 0)
+ return -1;
+
+ snprintf(buf, sizeof(buf), "%08lX", (long)crc);
+
+ if (fseeko(out, offset-TORRENT_CRC_LEN, SEEK_SET) < 0) {
+ _zip_error_set(&za->error, ZIP_ER_SEEK, errno);
+ return -1;
+ }
+
+ if (fwrite(buf, TORRENT_CRC_LEN, 1, out) != 1) {
+ _zip_error_set(&za->error, ZIP_ER_WRITE, errno);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+
+static int
+_zip_cdir_set_comment(struct zip_cdir *dest, struct zip *src)
+{
+ if (src->ch_comment_len != -1) {
+ dest->comment = _zip_memdup(src->ch_comment,
+ src->ch_comment_len, &src->error);
+ if (dest->comment == NULL)
+ return -1;
+ dest->comment_len = src->ch_comment_len;
+ } else {
+ if (src->cdir && src->cdir->comment) {
+ dest->comment = _zip_memdup(src->cdir->comment,
+ src->cdir->comment_len, &src->error);
+ if (dest->comment == NULL)
+ return -1;
+ dest->comment_len = src->cdir->comment_len;
+ }
+ }
+
+ return 0;
+}
+
+
+
+static int
+_zip_changed(struct zip *za, int *survivorsp)
+{
+ int changed, i, survivors;
+
+ changed = survivors = 0;
+
+ if (za->ch_comment_len != -1
+ || za->ch_flags != za->flags)
+ changed = 1;
+
+ for (i=0; i<za->nentry; i++) {
+ if ((za->entry[i].state != ZIP_ST_UNCHANGED)
+ || (za->entry[i].ch_comment_len != -1))
+ changed = 1;
+ if (za->entry[i].state != ZIP_ST_DELETED)
+ survivors++;
+ }
+
+ *survivorsp = survivors;
+
+ return changed;
+}
+
+
+
+static char *
+_zip_create_temp_output(struct zip *za, FILE **outp)
+{
+ char *temp;
+ int tfd;
+ FILE *tfp;
+
+ if ((temp=(char *)malloc(strlen(za->zn)+8)) == NULL) {
+ _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ return NULL;
+ }
+
+ sprintf(temp, "%s.XXXXXX", za->zn);
+
+ if ((tfd=mkstemp(temp)) == -1) {
+ _zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno);
+ free(temp);
+ return NULL;
+ }
+
+ if ((tfp=fdopen(tfd, "r+b")) == NULL) {
+ _zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno);
+ close(tfd);
+ remove(temp);
+ free(temp);
+ return NULL;
+ }
+
+ *outp = tfp;
+ return temp;
+}
+
+
+
+static int
+_zip_torrentzip_cmp(const void *a, const void *b)
+{
+ return strcasecmp(((const struct filelist *)a)->name,
+ ((const struct filelist *)b)->name);
+}
58 jni/zip_delete.c
@@ -0,0 +1,58 @@
+/*
+ zip_delete.c -- delete file from zip archive
+ 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 <libzip@nih.at>
+
+ 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. 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
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS 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 "zipint.h"
+
+
+
+ZIP_EXTERN int
+zip_delete(struct zip *za, int idx)
+{
+ if (idx < 0 || idx >= za->nentry) {
+ _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+ return -1;
+ }
+
+ /* allow duplicate file names, because the file will
+ * be removed directly afterwards */
+ if (_zip_unchange(za, idx, 1) != 0)
+ return -1;
+
+ za->entry[idx].state = ZIP_ST_DELETED;
+
+ return 0;
+}
+
+
615 jni/zip_dirent.c
@@ -0,0 +1,615 @@
+/*
+ zip_dirent.c -- read directory entry (local or central), clean dirent
+ 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 <libzip@nih.at>
+
+ 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. 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
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "zipint.h"
+
+static time_t _zip_d2u_time(int, int);
+static char *_zip_readfpstr(FILE *, unsigned int, int, struct zip_error *);
+static char *_zip_readstr(unsigned char **, int, int, struct zip_error *);
+static void _zip_u2d_time(time_t, unsigned short *, unsigned short *);
+static void _zip_write2(unsigned short, FILE *);
+static void _zip_write4(unsigned int, FILE *);
+
+
+
+void
+_zip_cdir_free(struct zip_cdir *cd)
+{
+ int i;
+
+ if (!cd)
+ return;
+
+ for (i=0; i<cd->nentry; i++)
+ _zip_dirent_finalize(cd->entry+i);
+ free(cd->comment);
+ free(cd->entry);
+ free(cd);
+}
+
+
+
+int
+_zip_cdir_grow(struct zip_cdir *cd, int nentry, struct zip_error *error)
+{
+ struct zip_dirent *entry;
+
+ if (nentry < cd->nentry) {
+ _zip_error_set(error, ZIP_ER_INTERNAL, 0);
+ return -1;
+ }
+
+ if ((entry=((struct zip_dirent *)
+ realloc(cd->entry, sizeof(*(cd->entry))*nentry))) == NULL) {
+ _zip_error_set(error, ZIP_ER_MEMORY, 0);
+ return -1;
+ }
+
+ cd->nentry = nentry;
+ cd->entry = entry;
+
+ return 0;
+}
+
+
+
+struct zip_cdir *
+_zip_cdir_new(int nentry, struct zip_error *error)
+{
+ struct zip_cdir *cd;
+
+ if ((cd=(struct zip_cdir *)malloc(sizeof(*cd))) == NULL) {
+ _zip_error_set(error, ZIP_ER_MEMORY, 0);
+ return NULL;
+ }
+
+ if ((cd->entry=(struct zip_dirent *)malloc(sizeof(*(cd->entry))*nentry))
+ == NULL) {
+ _zip_error_set(error, ZIP_ER_MEMORY, 0);
+ free(cd);
+ return NULL;
+ }
+
+ /* entries must be initialized by caller */
+
+ cd->nentry = nentry;
+ cd->size = cd->offset = 0;
+ cd->comment = NULL;
+ cd->comment_len = 0;
+
+ return cd;
+}
+
+
+
+int
+_zip_cdir_write(struct zip_cdir *cd, FILE *fp, struct zip_error *error)
+{
+ int i;
+
+ 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 = ftello(fp) - cd->offset;
+
+ /* clearerr(fp); */
+ fwrite(EOCD_MAGIC, 1, 4, fp);
+ _zip_write4(0, fp);
+ _zip_write2((unsigned short)cd->nentry, fp);
+ _zip_write2((unsigned short)cd->nentry, fp);
+ _zip_write4(cd->size, fp);
+ _zip_write4(cd->offset, fp);
+ _zip_write2(cd->comment_len, fp);
+ fwrite(cd->comment, 1, cd->comment_len, fp);
+
+ if (ferror(fp)) {
+ _zip_error_set(error, ZIP_ER_WRITE, errno);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+
+void
+_zip_dirent_finalize(struct zip_dirent *zde)
+{
+ free(zde->filename);
+ zde->filename = NULL;
+ free(zde->extrafield);
+ zde->extrafield = NULL;
+ free(zde->comment);
+ zde->comment = NULL;
+}
+
+
+
+void
+_zip_dirent_init(struct zip_dirent *de)
+{
+ de->version_madeby = 0;
+ de->version_needed = 20; /* 2.0 */
+ de->bitflags = 0;
+ de->comp_method = 0;
+ de->last_mod = 0;
+ de->crc = 0;
+ de->comp_size = 0;
+ de->uncomp_size = 0;
+ de->filename = NULL;
+ de->filename_len = 0;
+ de->extrafield = NULL;
+ de->extrafield_len = 0;
+ de->comment = NULL;
+ de->comment_len = 0;
+ de->disk_number = 0;
+ de->int_attrib = 0;
+ de->ext_attrib = 0;
+ de->offset = 0;
+}
+
+
+
+/* _zip_dirent_read(zde, fp, bufp, left, localp, error):
+ Fills the zip directory entry zde.
+
+ If bufp is non-NULL, data is taken from there and bufp is advanced
+ by the amount of data used; otherwise data is read from fp as needed.
+
+ if leftp is non-NULL, no more bytes than specified by it are used,
+ and *leftp is reduced by the number of bytes used.
+
+ If local != 0, it reads a local header instead of a central
+ directory entry.
+
+ Returns 0 if successful. On error, error is filled in and -1 is
+ returned.
+
+ XXX: leftp and file position undefined on error.
+*/
+
+int
+_zip_dirent_read(struct zip_dirent *zde, FILE *fp,
+ unsigned char **bufp, unsigned int *leftp, int local,
+ struct zip_error *error)
+{
+ unsigned char buf[CDENTRYSIZE];
+ unsigned char *cur;
+ unsigned short dostime, dosdate;
+ unsigned int size;
+
+ if (local)
+ size = LENTRYSIZE;
+ else
+ size = CDENTRYSIZE;
+
+ if (leftp && (*leftp < size)) {
+ _zip_error_set(error, ZIP_ER_NOZIP, 0);
+ return -1;
+ }
+
+ if (bufp) {
+ /* use data from buffer */
+ cur = *bufp;
+ }
+ else {
+ /* read entry from disk */
+ if ((fread(buf, 1, size, fp)<size)) {
+ _zip_error_set(error, ZIP_ER_READ, errno);
+ return -1;
+ }
+ cur = buf;
+ }
+
+ if (memcmp(cur, (local ? LOCAL_MAGIC : CENTRAL_MAGIC), 4) != 0) {
+ _zip_error_set(error, ZIP_ER_NOZIP, 0);
+ return -1;
+ }
+ cur += 4;
+
+
+ /* convert buffercontents to zip_dirent */
+
+ if (!local)
+ zde->version_madeby = _zip_read2(&cur);
+ else
+ zde->version_madeby = 0;
+ zde->version_needed = _zip_read2(&cur);
+ zde->bitflags = _zip_read2(&cur);
+ zde->comp_method = _zip_read2(&cur);
+
+ /* convert to time_t */
+ dostime = _zip_read2(&cur);
+ dosdate = _zip_read2(&cur);
+ zde->last_mod = _zip_d2u_time(dostime, dosdate);
+
+ zde->crc = _zip_read4(&cur);
+ zde->comp_size = _zip_read4(&cur);
+ zde->uncomp_size = _zip_read4(&cur);
+
+ zde->filename_len = _zip_read2(&cur);
+ zde->extrafield_len = _zip_read2(&cur);
+
+ if (local) {
+ zde->comment_len = 0;
+ zde->disk_number = 0;
+ zde->int_attrib = 0;
+ zde->ext_attrib = 0;
+ zde->offset = 0;
+ } else {
+ zde->comment_len = _zip_read2(&cur);
+ zde->disk_number = _zip_read2(&cur);
+ zde->int_attrib = _zip_read2(&cur);
+ zde->ext_attrib = _zip_read4(&cur);
+ zde->offset = _zip_read4(&cur);
+ }
+
+ zde->filename = NULL;
+ zde->extrafield = NULL;
+ zde->comment = NULL;
+
+ size += zde->filename_len+zde->extrafield_len+zde->comment_len;
+
+ if (leftp && (*leftp < size)) {
+ _zip_error_set(error, ZIP_ER_NOZIP, 0);
+ return -1;
+ }
+
+ if (bufp) {
+ if (zde->filename_len) {
+ zde->filename = _zip_readstr(&cur, zde->filename_len, 1, error);
+ if (!zde->filename)
+ return -1;
+ }
+
+ if (zde->extrafield_len) {
+ zde->extrafield = _zip_readstr(&cur, zde->extrafield_len, 0,
+ error);
+ if (!zde->extrafield)
+ return -1;
+ }
+
+ if (zde->comment_len) {
+ zde->comment = _zip_readstr(&cur, zde->comment_len, 0, error);
+ if (!zde->comment)
+ return -1;
+ }
+ }
+ else {
+ if (zde->filename_len) {
+ zde->filename = _zip_readfpstr(fp, zde->filename_len, 1, error);
+ if (!zde->filename)
+ return -1;
+ }
+
+ if (zde->extrafield_len) {
+ zde->extrafield = _zip_readfpstr(fp, zde->extrafield_len, 0,
+ error);
+ if (!zde->extrafield)
+ return -1;
+ }
+
+ if (zde->comment_len) {
+ zde->comment = _zip_readfpstr(fp, zde->comment_len, 0, error);
+ if (!zde->comment)
+ return -1;
+ }
+ }
+
+ if (bufp)
+ *bufp = cur;
+ if (leftp)
+ *leftp -= size;
+
+ return 0;
+}
+
+
+
+/* _zip_dirent_torrent_normalize(de);
+ Set values suitable for torrentzip.
+*/
+
+void
+_zip_dirent_torrent_normalize(struct zip_dirent *de)
+{
+ static struct tm torrenttime;
+ static time_t last_mod = 0;
+
+ if (last_mod == 0) {
+#ifdef HAVE_STRUCT_TM_TM_ZONE
+ time_t now;
+ struct tm *l;
+#endif
+
+ torrenttime.tm_sec = 0;
+ torrenttime.tm_min = 32;
+ torrenttime.tm_hour = 23;
+ torrenttime.tm_mday = 24;
+ torrenttime.tm_mon = 11;
+ torrenttime.tm_year = 96;
+ torrenttime.tm_wday = 0;
+ torrenttime.tm_yday = 0;
+ torrenttime.tm_isdst = 0;
+
+#ifdef HAVE_STRUCT_TM_TM_ZONE
+ time(&now);
+ l = localtime(&now);
+ torrenttime.tm_gmtoff = l->tm_gmtoff;
+ torrenttime.tm_zone = l->tm_zone;
+#endif
+
+ last_mod = mktime(&torrenttime);
+ }
+
+ de->version_madeby = 0;
+ de->version_needed = 20; /* 2.0 */
+ de->bitflags = 2; /* maximum compression */
+ de->comp_method = ZIP_CM_DEFLATE;
+ de->last_mod = last_mod;
+
+ de->disk_number = 0;
+ de->int_attrib = 0;
+ de->ext_attrib = 0;
+ de->offset = 0;
+
+ free(de->extrafield);
+ de->extrafield = NULL;
+ de->extrafield_len = 0;
+ free(de->comment);
+ de->comment = NULL;
+ de->comment_len = 0;
+}
+
+
+
+/* _zip_dirent_write(zde, fp, localp, error):
+ Writes zip directory entry zde to file fp.
+
+ If localp != 0, it writes a local header instead of a central
+ directory entry.
+
+ Returns 0 if successful. On error, error is filled in and -1 is
+ returned.
+*/
+
+int
+_zip_dirent_write(struct zip_dirent *zde, FILE *fp, int localp,
+ struct zip_error *error)
+{
+ unsigned short dostime, dosdate;
+
+ fwrite(localp ? LOCAL_MAGIC : CENTRAL_MAGIC, 1, 4, fp);
+
+ if (!localp)
+ _zip_write2(zde->version_madeby, fp);
+ _zip_write2(zde->version_needed, fp);
+ _zip_write2(zde->bitflags, fp);
+ _zip_write2(zde->comp_method, fp);
+
+ _zip_u2d_time(zde->last_mod, &dostime, &dosdate);
+ _zip_write2(dostime, fp);
+ _zip_write2(dosdate, fp);
+
+ _zip_write4(zde->crc, fp);
+ _zip_write4(zde->comp_size, fp);
+ _zip_write4(zde->uncomp_size, fp);
+
+ _zip_write2(zde->filename_len, fp);
+ _zip_write2(zde->extrafield_len, fp);
+
+ if (!localp) {
+ _zip_write2(zde->comment_len, fp);
+ _zip_write2(zde->disk_number, fp);
+ _zip_write2(zde->int_attrib, fp);
+ _zip_write4(zde->ext_attrib, fp);
+ _zip_write4(zde->offset, fp);
+ }
+
+ if (zde->filename_len)
+ fwrite(zde->filename, 1, zde->filename_len, fp);
+
+ if (zde->extrafield_len)
+ fwrite(zde->extrafield, 1, zde->extrafield_len, fp);
+
+ if (!localp) {
+ if (zde->comment_len)
+ fwrite(zde->comment, 1, zde->comment_len, fp);
+ }
+
+ if (ferror(fp)) {
+ _zip_error_set(error, ZIP_ER_WRITE, errno);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+
+static time_t
+_zip_d2u_time(int dtime, int ddate)
+{
+ struct tm tm;
+
+ memset(&tm, sizeof(tm), 0);
+
+ /* 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;
+ tm.tm_mday = ddate&31;
+
+ tm.tm_hour = (dtime>>11)&31;
+ tm.tm_min = (dtime>>5)&63;
+ tm.tm_sec = (dtime<<1)&62;
+
+ return mktime(&tm);
+}
+
+
+
+unsigned short
+_zip_read2(unsigned char **a)
+{
+ unsigned short ret;
+
+ ret = (*a)[0]+((*a)[1]<<8);
+ *a += 2;
+
+ return ret;
+}
+
+
+
+unsigned int
+_zip_read4(unsigned char **a)
+{
+ unsigned int ret;
+
+ ret = ((((((*a)[3]<<8)+(*a)[2])<<8)+(*a)[1])<<8)+(*a)[0];
+ *a += 4;
+
+ return ret;
+}
+
+
+
+static char *
+_zip_readfpstr(FILE *fp, unsigned int len, int nulp, struct zip_error *error)
+{
+ char *r, *o;
+
+ r = (char *)malloc(nulp ? len+1 : len);
+ if (!r) {
+ _zip_error_set(error, ZIP_ER_MEMORY, 0);
+ return NULL;
+ }
+
+ if (fread(r, 1, len, fp)<len) {
+ free(r);
+ _zip_error_set(error, ZIP_ER_READ, errno);
+ return NULL;
+ }
+
+ if (nulp) {
+ /* replace any in-string NUL characters with spaces */
+ r[len] = 0;
+ for (o=r; o<r+len; o++)
+ if (*o == '\0')
+ *o = ' ';
+ }
+
+ return r;
+}
+
+
+
+static char *
+_zip_readstr(unsigned char **buf, int len, int nulp, struct zip_error *error)
+{
+ char *r, *o;
+
+ r = (char *)malloc(nulp ? len+1 : len);
+ if (!r) {
+ _zip_error_set(error, ZIP_ER_MEMORY, 0);
+ return NULL;
+ }
+
+ memcpy(r, *buf, len);
+ *buf += len;
+
+ if (nulp) {
+ /* replace any in-string NUL characters with spaces */
+ r[len] = 0;
+ for (o=r; o<r+len; o++)
+ if (*o == '\0')
+ *o = ' ';
+ }
+
+ return r;
+}
+
+
+
+static void
+_zip_write2(unsigned short i, FILE *fp)
+{
+ putc(i&0xff, fp);
+ putc((i>>8)&0xff, fp);
+
+ return;
+}
+
+
+
+static void
+_zip_write4(unsigned int i, FILE *fp)
+{
+ putc(i&0xff, fp);
+ putc((i>>8)&0xff, fp);
+ putc((i>>16)&0xff, fp);
+ putc((i>>24)&0xff, fp);
+
+ return;
+}
+
+
+
+static void
+_zip_u2d_time(time_t time, unsigned short *dtime, unsigned short *ddate)
+{
+ struct tm *tm;
+
+ 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)
+ + ((tm->tm_sec)>>1);
+
+ return;
+}
52 jni/zip_entry_free.c
@@ -0,0 +1,52 @@
+/*
+ zip_entry_free.c -- free struct zip_entry
+ 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 <libzip@nih.at>
+
+ 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. 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
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS 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 <stdlib.h>
+
+#include "zipint.h"
+
+
+
+void
+_zip_entry_free(struct zip_entry *ze)
+{
+ free(ze->ch_filename);
+ ze->ch_filename = NULL;
+ free(ze->ch_comment);
+ ze->ch_comment = NULL;
+ ze->ch_comment_len = -1;
+
+ _zip_unchange_data(ze);
+}
78 jni/zip_entry_new.c
@@ -0,0 +1,78 @@
+/*
+ zip_entry_new.c -- create and init struct zip_entry
+ 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 <libzip@nih.at>
+
+ 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. 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
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS 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 <stdlib.h>
+
+#include "zipint.h"
+
+
+
+struct zip_entry *
+_zip_entry_new(struct zip *za)
+{
+ struct zip_entry *ze;
+ if (!za) {
+ ze = (struct zip_entry *)malloc(sizeof(struct zip_entry));
+ if (!ze) {
+ _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ return NULL;
+ }
+ }
+ else {
+ if (za->nentry >= za->nentry_alloc-1) {
+ za->nentry_alloc += 16;
+ za->entry = (struct zip_entry *)realloc(za->entry,
+ sizeof(struct zip_entry)
+ * za->nentry_alloc);
+ if (!za->entry) {
+ _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ return NULL;
+ }
+ }
+ ze = za->entry+za->nentry;
+ }
+
+ ze->state = ZIP_ST_UNCHANGED;
+
+ ze->ch_filename = NULL;
+ ze->ch_comment = NULL;
+ ze->ch_comment_len = -1;
+ ze->source = NULL;
+
+ if (za)
+ za->nentry++;
+
+ return ze;
+}
68 jni/zip_err_str.c
@@ -0,0 +1,68 @@
+/*
+ This file was generated automatically by ./make_zip_err_str.sh
+ from ./zip.h; make changes there.
+ */
+
+#include "zipint.h"
+
+
+
+const char * const _zip_err_str[] = {
+ "No error",
+ "Multi-disk zip archives not supported",
+ "Renaming temporary file failed",
+ "Closing zip archive failed",
+ "Seek error",
+ "Read error",
+ "Write error",
+ "CRC error",
+ "Containing zip archive was closed",
+ "No such file",
+ "File already exists",
+ "Can't open file",
+ "Failure to create temporary file",
+ "Zlib error",
+ "Malloc failure",
+ "Entry has been changed",
+ "Compression method not supported",
+ "Premature EOF",
+ "Invalid argument",
+ "Not a zip archive",
+ "Internal error",
+ "Zip archive inconsistent",
+ "Can't remove file",
+ "Entry has been deleted",
+};
+
+const int _zip_nerr_str = sizeof(_zip_err_str)/sizeof(_zip_err_str[0]);
+
+#define N ZIP_ET_NONE
+#define S ZIP_ET_SYS
+#define Z ZIP_ET_ZLIB
+
+const int _zip_err_type[] = {
+ N,
+ N,
+ S,
+ S,
+ S,
+ S,
+ S,
+ N,
+ N,
+ N,
+ N,
+ S,
+ S,
+ Z,
+ N,
+ N,
+ N,
+ N,
+ N,
+ N,
+ N,
+ N,
+ S,
+ N,
+};
101 jni/zip_error.c
@@ -0,0 +1,101 @@
+/*
+ zip_error.c -- struct zip_error helper functions
+ 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 <libzip@nih.at>
+
+ 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. 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
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS 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 <stdlib.h>
+
+#include "zipint.h"
+
+
+
+void
+_zip_error_clear(struct zip_error *err)
+{
+ err->zip_err = ZIP_ER_OK;
+ err->sys_err = 0;
+}
+
+
+
+void
+_zip_error_copy(struct zip_error *dst, struct zip_error *src)
+{
+ dst->zip_err = src->zip_err;
+ dst->sys_err = src->sys_err;
+}
+
+
+
+void
+_zip_error_fini(struct zip_error *err)
+{
+ free(err->str);
+ err->str = NULL;
+}
+
+
+
+void
+_zip_error_get(struct zip_error *err, int *zep, int *sep)
+{
+ if (zep)
+ *zep = err->zip_err;
+ if (sep) {
+ if (zip_error_get_sys_type(err->zip_err) != ZIP_ET_NONE)
+ *sep = err->sys_err;
+ else
+ *sep = 0;
+ }
+}
+
+
+
+void
+_zip_error_init(struct zip_error *err)
+{
+ err->zip_err = ZIP_ER_OK;
+ err->sys_err = 0;
+ err->str = NULL;
+}
+
+
+
+void
+_zip_error_set(struct zip_error *err, int ze, int se)
+{
+ if (err) {
+ err->zip_err = ze;
+ err->sys_err = se;
+ }
+}
44 jni/zip_error_clear.c
@@ -0,0 +1,44 @@
+/*
+ zip_error_clear.c -- clear zip error
+ 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 <libzip@nih.at>
+
+ 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. 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
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS 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 "zipint.h"
+
+
+
+ZIP_EXTERN void
+zip_error_clear(struct zip *za)
+{
+ _zip_error_clear(&za->error);
+}
44 jni/zip_error_get.c
@@ -0,0 +1,44 @@
+/*
+ zip_error_get.c -- get zip error
+ 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 <libzip@nih.at>
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met: