├── .gitignore ├── jni ├── Application.mk ├── zipconf.h ├── zip_err_str.c ├── zip_source_error.c ├── zip_strerror.c ├── zip_error_clear.c ├── zip_file_strerror.c ├── zip_source_is_deleted.c ├── zip_file_error_clear.c ├── zip_file_error_get.c ├── zip_replace.c ├── zip_rename.c ├── zip_error_get_sys_type.c ├── zip_add_dir.c ├── zip_get_encryption_implementation.c ├── zip_get_archive_flag.c ├── zip_get_compression_implementation.c ├── zip_stat.c ├── zip_fopen_index.c ├── zip_fopen.c ├── zip_source_tell_write.c ├── zip_unchange_all.c ├── zip_entry.c ├── zip_fclose.c ├── zip_get_num_files.c ├── zip_source_rollback_write.c ├── zip_unchange_archive.c ├── zip_fopen_encrypted.c ├── zip_source_tell.c ├── zip_get_file_comment.c ├── zip_source_write.c ├── zip_error_get.c ├── zip_get_num_entries.c ├── zip_memdup.c ├── zip_set_file_comment.c ├── zip_source_read.c ├── zip_source_begin_write.c ├── zip_add.c ├── zip_file_get_external_attributes.c ├── zip_unchange_data.c ├── zip_source_close.c ├── zip_delete.c ├── zip_set_default_password.c ├── zip_source_seek_write.c ├── zip_fread.c ├── zip_source_remove.c ├── zip_file_get_comment.c ├── zip_get_archive_comment.c ├── zip_file_add.c ├── zip_get_name.c ├── zip_source_zip.c ├── zip_source_stat.c ├── zip_source_supports.c ├── zip_source_file.c ├── zip_set_archive_flag.c ├── zip_source_commit_write.c ├── zip_error_to_str.c ├── zip_new.c ├── zip_source_free.c ├── zip_source_layered.c ├── zip_discard.c ├── zip_file_rename.c ├── zip_unchange.c ├── zip_add_entry.c ├── zip_source_open.c ├── zip_source_call.c ├── zip_filerange_crc.c ├── zip_file_get_offset.c ├── zip_file_set_mtime.c ├── zip_error_strerror.c ├── zip_fopen_index_encrypted.c ├── zip_name_locate.c ├── zip_set_archive_comment.c ├── zip_fdopen.c ├── zip_dir_add.c ├── zip_stat_init.c ├── zip_stat_index.c ├── zip_set_file_compression.c ├── zip_source_function.c ├── zip_source_seek.c ├── zip_file_set_external_attributes.c ├── Android.mk ├── zip_file_set_comment.c ├── zip_file_replace.c ├── zip_set_name.c ├── mkstemp.c ├── zip_io_util.c └── zip_error.c ├── README.rst └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | obj/ 2 | -------------------------------------------------------------------------------- /jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_OPTIM := release 2 | APP_MODULES := libzip 3 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | libzip for Android 2 | ================== 3 | This is a repackaging of libzip for the Android NDK. 4 | 5 | The only changed files are config.h and the android .mk files. 6 | 7 | libzip has been written by Dieter Baron and Thomas Klausner. 8 | 9 | Assuming 'ndk-build' is in your path, you can use the build.sh script to build a static lib. 10 | 11 | The 'master' branch of this repository contains version 1.0.1 of libzip. I 12 | haven't had much time to test it on Android. 13 | 14 | The 'stable' branch of this repository contains the older 0.9.3 version which 15 | works fine on Android. 16 | -------------------------------------------------------------------------------- /jni/zipconf.h: -------------------------------------------------------------------------------- 1 | #ifndef _HAD_ZIPCONF_H 2 | #define _HAD_ZIPCONF_H 3 | 4 | /* 5 | zipconf.h -- platform specific include file 6 | 7 | This file was generated automatically by ./make_zipconf.sh 8 | based on ../config.h. 9 | */ 10 | 11 | #define LIBZIP_VERSION "1.0.1" 12 | #define LIBZIP_VERSION_MAJOR 1 13 | #define LIBZIP_VERSION_MINOR 0 14 | #define LIBZIP_VERSION_MICRO 1 15 | 16 | #include 17 | 18 | typedef int8_t zip_int8_t; 19 | #define ZIP_INT8_MIN INT8_MIN 20 | #define ZIP_INT8_MAX INT8_MAX 21 | 22 | typedef uint8_t zip_uint8_t; 23 | #define ZIP_UINT8_MAX UINT8_MAX 24 | 25 | typedef int16_t zip_int16_t; 26 | #define ZIP_INT16_MIN INT16_MIN 27 | #define ZIP_INT16_MAX INT16_MAX 28 | 29 | typedef uint16_t zip_uint16_t; 30 | #define ZIP_UINT16_MAX UINT16_MAX 31 | 32 | typedef int32_t zip_int32_t; 33 | #define ZIP_INT32_MIN INT32_MIN 34 | #define ZIP_INT32_MAX INT32_MAX 35 | 36 | typedef uint32_t zip_uint32_t; 37 | #define ZIP_UINT32_MAX UINT32_MAX 38 | 39 | typedef int64_t zip_int64_t; 40 | #define ZIP_INT64_MIN INT64_MIN 41 | #define ZIP_INT64_MAX INT64_MAX 42 | 43 | typedef uint64_t zip_uint64_t; 44 | #define ZIP_UINT64_MAX UINT64_MAX 45 | 46 | 47 | #endif /* zipconf.h */ 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner 2 | The authors can be contacted at 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in 11 | the documentation and/or other materials provided with the 12 | distribution. 13 | 3. The names of the authors may not be used to endorse or promote 14 | products derived from this software without specific prior 15 | written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 18 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /jni/zip_err_str.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file was generated automatically by ./make_zip_err_str.sh 3 | from ./zip.h; make changes there. 4 | */ 5 | 6 | #include "zipint.h" 7 | 8 | const char * const _zip_err_str[] = { 9 | "No error", 10 | "Multi-disk zip archives not supported", 11 | "Renaming temporary file failed", 12 | "Closing zip archive failed", 13 | "Seek error", 14 | "Read error", 15 | "Write error", 16 | "CRC error", 17 | "Containing zip archive was closed", 18 | "No such file", 19 | "File already exists", 20 | "Can't open file", 21 | "Failure to create temporary file", 22 | "Zlib error", 23 | "Malloc failure", 24 | "Entry has been changed", 25 | "Compression method not supported", 26 | "Premature end of file", 27 | "Invalid argument", 28 | "Not a zip archive", 29 | "Internal error", 30 | "Zip archive inconsistent", 31 | "Can't remove file", 32 | "Entry has been deleted", 33 | "Encryption method not supported", 34 | "Read-only archive", 35 | "No password provided", 36 | "Wrong password provided", 37 | "Operation not supported", 38 | "Resource still in use", 39 | "Tell error", 40 | }; 41 | 42 | const int _zip_nerr_str = sizeof(_zip_err_str)/sizeof(_zip_err_str[0]); 43 | 44 | #define N ZIP_ET_NONE 45 | #define S ZIP_ET_SYS 46 | #define Z ZIP_ET_ZLIB 47 | 48 | const int _zip_err_type[] = { 49 | N, 50 | N, 51 | S, 52 | S, 53 | S, 54 | S, 55 | S, 56 | N, 57 | N, 58 | N, 59 | N, 60 | S, 61 | S, 62 | Z, 63 | N, 64 | N, 65 | N, 66 | N, 67 | N, 68 | N, 69 | N, 70 | N, 71 | S, 72 | N, 73 | N, 74 | N, 75 | N, 76 | N, 77 | N, 78 | N, 79 | S, 80 | }; 81 | -------------------------------------------------------------------------------- /jni/zip_source_error.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_error.c -- get last error from zip_source 3 | Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | zip_error_t * 39 | zip_source_error(zip_source_t *src) 40 | { 41 | return &src->error; 42 | } 43 | -------------------------------------------------------------------------------- /jni/zip_strerror.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_sterror.c -- get string representation of zip error 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN const char * 39 | zip_strerror(zip_t *za) 40 | { 41 | return zip_error_strerror(&za->error); 42 | } 43 | -------------------------------------------------------------------------------- /jni/zip_error_clear.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_error_clear.c -- clear zip error 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN void 39 | zip_error_clear(zip_t *za) 40 | { 41 | if (za == NULL) 42 | return; 43 | 44 | _zip_error_clear(&za->error); 45 | } 46 | -------------------------------------------------------------------------------- /jni/zip_file_strerror.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_file_sterror.c -- get string representation of zip file error 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN const char * 39 | zip_file_strerror(zip_file_t *zf) 40 | { 41 | return zip_error_strerror(&zf->error); 42 | } 43 | -------------------------------------------------------------------------------- /jni/zip_source_is_deleted.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_is_deleted.c -- was archive was removed? 3 | Copyright (C) 2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN int 39 | zip_source_is_deleted(zip_source_t *src) 40 | { 41 | return src->write_state == ZIP_SOURCE_WRITE_REMOVED; 42 | } 43 | -------------------------------------------------------------------------------- /jni/zip_file_error_clear.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_file_error_clear.c -- clear zip file error 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN void 39 | zip_file_error_clear(zip_file_t *zf) 40 | { 41 | if (zf == NULL) 42 | return; 43 | 44 | _zip_error_clear(&zf->error); 45 | } 46 | -------------------------------------------------------------------------------- /jni/zip_file_error_get.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_file_error_get.c -- get zip file error 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #define _ZIP_COMPILING_DEPRECATED 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN void 39 | zip_file_error_get(zip_file_t *zf, int *zep, int *sep) 40 | { 41 | _zip_error_get(&zf->error, zep, sep); 42 | } 43 | -------------------------------------------------------------------------------- /jni/zip_replace.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_replace.c -- replace file via callback function 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #define _ZIP_COMPILING_DEPRECATED 36 | #include "zipint.h" 37 | 38 | 39 | ZIP_EXTERN int 40 | zip_replace(zip_t *za, zip_uint64_t idx, zip_source_t *source) 41 | { 42 | return zip_file_replace(za, idx, source, 0); 43 | } 44 | -------------------------------------------------------------------------------- /jni/zip_rename.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_rename.c -- rename file in zip archive 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #define _ZIP_COMPILING_DEPRECATED 38 | #include "zipint.h" 39 | 40 | 41 | ZIP_EXTERN int 42 | zip_rename(zip_t *za, zip_uint64_t idx, const char *name) 43 | { 44 | return zip_file_rename(za, idx, name, 0); 45 | } 46 | -------------------------------------------------------------------------------- /jni/zip_error_get_sys_type.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_error_get_sys_type.c -- return type of system error code 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #define _ZIP_COMPILING_DEPRECATED 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN int 39 | zip_error_get_sys_type(int ze) 40 | { 41 | if (ze < 0 || ze >= _zip_nerr_str) 42 | return 0; 43 | 44 | return _zip_err_type[ze]; 45 | } 46 | -------------------------------------------------------------------------------- /jni/zip_add_dir.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_add_dir.c -- add directory 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #define _ZIP_COMPILING_DEPRECATED 36 | #include "zipint.h" 37 | 38 | 39 | /* NOTE: Signed due to -1 on error. See zip_add.c for more details. */ 40 | 41 | ZIP_EXTERN zip_int64_t 42 | zip_add_dir(zip_t *za, const char *name) 43 | { 44 | return zip_dir_add(za, name, 0); 45 | } 46 | -------------------------------------------------------------------------------- /jni/zip_get_encryption_implementation.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_get_encryption_implementation.c -- get encryption implementation 3 | Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | zip_encryption_implementation 39 | _zip_get_encryption_implementation(zip_uint16_t em) 40 | { 41 | if (em == ZIP_EM_TRAD_PKWARE) 42 | return zip_source_pkware; 43 | return NULL; 44 | } 45 | -------------------------------------------------------------------------------- /jni/zip_get_archive_flag.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_get_archive_flag.c -- get archive global flag 3 | Copyright (C) 2008-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN int 39 | zip_get_archive_flag(zip_t *za, zip_flags_t flag, zip_flags_t flags) 40 | { 41 | unsigned int fl; 42 | 43 | fl = (flags & ZIP_FL_UNCHANGED) ? za->flags : za->ch_flags; 44 | 45 | return (fl & flag) ? 1 : 0; 46 | } 47 | -------------------------------------------------------------------------------- /jni/zip_get_compression_implementation.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_get_compression_implementation.c -- get compression implementation 3 | Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | zip_compression_implementation 39 | _zip_get_compression_implementation(zip_int32_t cm) 40 | { 41 | if (cm == ZIP_CM_DEFLATE || ZIP_CM_IS_DEFAULT(cm)) 42 | return zip_source_deflate; 43 | return NULL; 44 | } 45 | -------------------------------------------------------------------------------- /jni/zip_stat.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_stat.c -- get information about file by name 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN int 39 | zip_stat(zip_t *za, const char *fname, zip_flags_t flags, zip_stat_t *st) 40 | { 41 | zip_int64_t idx; 42 | 43 | if ((idx=zip_name_locate(za, fname, flags)) < 0) 44 | return -1; 45 | 46 | return zip_stat_index(za, (zip_uint64_t)idx, flags, st); 47 | } 48 | -------------------------------------------------------------------------------- /jni/zip_fopen_index.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_fopen_index.c -- open file in zip archive for reading by index 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "zipint.h" 40 | 41 | 42 | ZIP_EXTERN zip_file_t * 43 | zip_fopen_index(zip_t *za, zip_uint64_t index, zip_flags_t flags) 44 | { 45 | return zip_fopen_index_encrypted(za, index, flags, za->default_password); 46 | } 47 | -------------------------------------------------------------------------------- /jni/zip_fopen.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_fopen.c -- open file in zip archive for reading 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN zip_file_t * 39 | zip_fopen(zip_t *za, const char *fname, zip_flags_t flags) 40 | { 41 | zip_int64_t idx; 42 | 43 | if ((idx=zip_name_locate(za, fname, flags)) < 0) 44 | return NULL; 45 | 46 | return zip_fopen_index_encrypted(za, (zip_uint64_t)idx, flags, za->default_password); 47 | } 48 | -------------------------------------------------------------------------------- /jni/zip_source_tell_write.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_tell_write.c -- report current offset for writing 3 | Copyright (C) 2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN zip_int64_t 39 | zip_source_tell_write(zip_source_t *src) 40 | { 41 | if (!ZIP_SOURCE_IS_OPEN_WRITING(src)) { 42 | zip_error_set(&src->error, ZIP_ER_INVAL, 0); 43 | return -1; 44 | } 45 | 46 | return _zip_source_call(src, NULL, 0, ZIP_SOURCE_TELL_WRITE); 47 | } 48 | -------------------------------------------------------------------------------- /jni/zip_unchange_all.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_unchange.c -- undo changes to all files in zip archive 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | ZIP_EXTERN int 41 | zip_unchange_all(zip_t *za) 42 | { 43 | int ret; 44 | zip_uint64_t i; 45 | 46 | ret = 0; 47 | for (i=0; inentry; i++) 48 | ret |= _zip_unchange(za, i, 1); 49 | 50 | ret |= zip_unchange_archive(za); 51 | 52 | return ret; 53 | } 54 | -------------------------------------------------------------------------------- /jni/zip_entry.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_entry.c -- struct zip_entry helper functions 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | void 38 | _zip_entry_finalize(zip_entry_t *e) 39 | { 40 | _zip_unchange_data(e); 41 | _zip_dirent_free(e->orig); 42 | _zip_dirent_free(e->changes); 43 | } 44 | 45 | 46 | void 47 | _zip_entry_init(zip_entry_t *e) 48 | { 49 | e->orig = NULL; 50 | e->changes = NULL; 51 | e->source = NULL; 52 | e->deleted = 0; 53 | } 54 | -------------------------------------------------------------------------------- /jni/zip_fclose.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_fclose.c -- close file in zip archive 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | ZIP_EXTERN int 41 | zip_fclose(zip_file_t *zf) 42 | { 43 | int ret; 44 | 45 | if (zf->src) 46 | zip_source_free(zf->src); 47 | 48 | ret = 0; 49 | if (zf->error.zip_err) 50 | ret = zf->error.zip_err; 51 | 52 | zip_error_fini(&zf->error); 53 | free(zf); 54 | return ret; 55 | } 56 | -------------------------------------------------------------------------------- /jni/zip_get_num_files.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_get_num_files.c -- get number of files in archive 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #define _ZIP_COMPILING_DEPRECATED 36 | #include "zipint.h" 37 | #include 38 | 39 | 40 | ZIP_EXTERN int 41 | zip_get_num_files(zip_t *za) 42 | { 43 | if (za == NULL) 44 | return -1; 45 | 46 | if (za->nentry > INT_MAX) { 47 | zip_error_set(&za->error, ZIP_ER_OPNOTSUPP, 0); 48 | return -1; 49 | } 50 | 51 | return (int)za->nentry; 52 | } 53 | -------------------------------------------------------------------------------- /jni/zip_source_rollback_write.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_rollback_write.c -- discard changes 3 | Copyright (C) 2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN void 39 | zip_source_rollback_write(zip_source_t *src) 40 | { 41 | if (src->write_state != ZIP_SOURCE_WRITE_OPEN && src->write_state != ZIP_SOURCE_WRITE_FAILED) { 42 | return; 43 | } 44 | 45 | _zip_source_call(src, NULL, 0, ZIP_SOURCE_ROLLBACK_WRITE); 46 | src->write_state = ZIP_SOURCE_WRITE_CLOSED; 47 | } 48 | -------------------------------------------------------------------------------- /jni/zip_unchange_archive.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_unchange_archive.c -- undo global changes to ZIP archive 3 | Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | ZIP_EXTERN int 41 | zip_unchange_archive(zip_t *za) 42 | { 43 | if (za->comment_changed) { 44 | _zip_string_free(za->comment_changes); 45 | za->comment_changes = NULL; 46 | za->comment_changed = 0; 47 | } 48 | 49 | za->ch_flags = za->flags; 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /jni/zip_fopen_encrypted.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_fopen_encrypted.c -- open file for reading with password 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN zip_file_t * 39 | zip_fopen_encrypted(zip_t *za, const char *fname, zip_flags_t flags, const char *password) 40 | { 41 | zip_int64_t idx; 42 | 43 | if ((idx=zip_name_locate(za, fname, flags)) < 0) 44 | return NULL; 45 | 46 | return zip_fopen_index_encrypted(za, (zip_uint64_t)idx, flags, password); 47 | } 48 | -------------------------------------------------------------------------------- /jni/zip_source_tell.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_tell.c -- report current offset 3 | Copyright (C) 2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN zip_int64_t 39 | zip_source_tell(zip_source_t *src) 40 | { 41 | if (src->source_closed) { 42 | return -1; 43 | } 44 | if (!ZIP_SOURCE_IS_OPEN_READING(src)) { 45 | zip_error_set(&src->error, ZIP_ER_INVAL, 0); 46 | return -1; 47 | } 48 | 49 | return _zip_source_call(src, NULL, 0, ZIP_SOURCE_TELL); 50 | } 51 | -------------------------------------------------------------------------------- /jni/zip_get_file_comment.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_get_file_comment.c -- get file comment 3 | Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #define _ZIP_COMPILING_DEPRECATED 36 | #include "zipint.h" 37 | 38 | 39 | ZIP_EXTERN const char * 40 | zip_get_file_comment(zip_t *za, zip_uint64_t idx, int *lenp, int flags) 41 | { 42 | zip_uint32_t len; 43 | const char *s; 44 | 45 | if ((s=zip_file_get_comment(za, idx, &len, (zip_flags_t)flags)) != NULL) { 46 | if (lenp) 47 | *lenp = (int)len; 48 | } 49 | 50 | return s; 51 | } 52 | -------------------------------------------------------------------------------- /jni/zip_source_write.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_write.c -- start a new file for writing 3 | Copyright (C) 2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN zip_int64_t 39 | zip_source_write(zip_source_t *src, const void *data, zip_uint64_t length) 40 | { 41 | if (!ZIP_SOURCE_IS_OPEN_WRITING(src) || length > ZIP_INT64_MAX) { 42 | zip_error_set(&src->error, ZIP_ER_INVAL, 0); 43 | return -1; 44 | } 45 | 46 | return _zip_source_call(src, (void *)data, length, ZIP_SOURCE_WRITE); 47 | } 48 | -------------------------------------------------------------------------------- /jni/zip_error_get.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_error_get.c -- get zip error 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #define _ZIP_COMPILING_DEPRECATED 36 | #include "zipint.h" 37 | 38 | 39 | ZIP_EXTERN void 40 | zip_error_get(zip_t *za, int *zep, int *sep) 41 | { 42 | _zip_error_get(&za->error, zep, sep); 43 | } 44 | 45 | 46 | ZIP_EXTERN zip_error_t * 47 | zip_get_error(zip_t *za) 48 | { 49 | return &za->error; 50 | } 51 | 52 | 53 | ZIP_EXTERN zip_error_t * 54 | zip_file_get_error(zip_file_t *f) 55 | { 56 | return &f->error; 57 | } 58 | -------------------------------------------------------------------------------- /jni/zip_get_num_entries.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_get_num_entries.c -- get number of entries in archive 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN zip_int64_t 39 | zip_get_num_entries(zip_t *za, zip_flags_t flags) 40 | { 41 | zip_uint64_t n; 42 | 43 | if (za == NULL) 44 | return -1; 45 | 46 | if (flags & ZIP_FL_UNCHANGED) { 47 | n = za->nentry; 48 | while (n>0 && za->entry[n-1].orig == NULL) 49 | --n; 50 | return (zip_int64_t)n; 51 | } 52 | return (zip_int64_t)za->nentry; 53 | } 54 | -------------------------------------------------------------------------------- /jni/zip_memdup.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_memdup.c -- internal zip function, "strdup" with len 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | void * 41 | _zip_memdup(const void *mem, size_t len, zip_error_t *error) 42 | { 43 | void *ret; 44 | 45 | if (len == 0) 46 | return NULL; 47 | 48 | ret = malloc(len); 49 | if (!ret) { 50 | zip_error_set(error, ZIP_ER_MEMORY, 0); 51 | return NULL; 52 | } 53 | 54 | memcpy(ret, mem, len); 55 | 56 | return ret; 57 | } 58 | -------------------------------------------------------------------------------- /jni/zip_set_file_comment.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_set_file_comment.c -- set comment for file in archive 3 | Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #define _ZIP_COMPILING_DEPRECATED 38 | #include "zipint.h" 39 | 40 | 41 | ZIP_EXTERN int 42 | zip_set_file_comment(zip_t *za, zip_uint64_t idx, const char *comment, int len) 43 | { 44 | if (len < 0 || len > ZIP_UINT16_MAX) { 45 | zip_error_set(&za->error, ZIP_ER_INVAL, 0); 46 | return -1; 47 | } 48 | return zip_file_set_comment(za, idx, comment, (zip_uint16_t)len, 0); 49 | } 50 | -------------------------------------------------------------------------------- /jni/zip_source_read.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_read.c -- read data from zip_source 3 | Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | zip_int64_t 39 | zip_source_read(zip_source_t *src, void *data, zip_uint64_t len) 40 | { 41 | if (src->source_closed) { 42 | return -1; 43 | } 44 | if (!ZIP_SOURCE_IS_OPEN_READING(src) || len > ZIP_INT64_MAX || (len > 0 && data == NULL)) { 45 | zip_error_set(&src->error, ZIP_ER_INVAL, 0); 46 | return -1; 47 | } 48 | 49 | return _zip_source_call(src, data, len, ZIP_SOURCE_READ); 50 | } 51 | -------------------------------------------------------------------------------- /jni/zip_source_begin_write.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_begin_write.c -- start a new file for writing 3 | Copyright (C) 2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN int 39 | zip_source_begin_write(zip_source_t *src) 40 | { 41 | if (ZIP_SOURCE_IS_OPEN_WRITING(src)) { 42 | zip_error_set(&src->error, ZIP_ER_INVAL, 0); 43 | return -1; 44 | } 45 | 46 | if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_BEGIN_WRITE) < 0) { 47 | return -1; 48 | } 49 | 50 | src->write_state = ZIP_SOURCE_WRITE_OPEN; 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /jni/zip_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_add.c -- add file via callback function 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #define _ZIP_COMPILING_DEPRECATED 36 | #include "zipint.h" 37 | 38 | 39 | /* 40 | NOTE: Return type is signed so we can return -1 on error. 41 | The index can not be larger than ZIP_INT64_MAX since the size 42 | of the central directory cannot be larger than 43 | ZIP_UINT64_MAX, and each entry is larger than 2 bytes. 44 | */ 45 | 46 | ZIP_EXTERN zip_int64_t 47 | zip_add(zip_t *za, const char *name, zip_source_t *source) 48 | { 49 | return zip_file_add(za, name, source, 0); 50 | } 51 | -------------------------------------------------------------------------------- /jni/zip_file_get_external_attributes.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_file_get_external_attributes.c -- get opsys/external attributes 3 | Copyright (C) 2013-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "zipint.h" 35 | 36 | int 37 | zip_file_get_external_attributes(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_uint8_t *opsys, zip_uint32_t *attributes) 38 | { 39 | zip_dirent_t *de; 40 | 41 | if ((de=_zip_get_dirent(za, idx, flags, NULL)) == NULL) 42 | return -1; 43 | 44 | if (opsys) 45 | *opsys = (zip_uint8_t)((de->version_madeby >> 8) & 0xff); 46 | 47 | if (attributes) 48 | *attributes = de->ext_attrib; 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /jni/zip_unchange_data.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_unchange_data.c -- undo helper function 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | void 38 | _zip_unchange_data(zip_entry_t *ze) 39 | { 40 | if (ze->source) { 41 | zip_source_free(ze->source); 42 | ze->source = NULL; 43 | } 44 | 45 | if (ze->changes != NULL && (ze->changes->changed & ZIP_DIRENT_COMP_METHOD) && ze->changes->comp_method == ZIP_CM_REPLACED_DEFAULT) { 46 | ze->changes->changed &= ~ZIP_DIRENT_COMP_METHOD; 47 | if (ze->changes->changed == 0) { 48 | _zip_dirent_free(ze->changes); 49 | ze->changes = NULL; 50 | } 51 | } 52 | 53 | ze->deleted = 0; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /jni/zip_source_close.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_close.c -- close zip_source (stop reading) 3 | Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | int 39 | zip_source_close(zip_source_t *src) 40 | { 41 | if (!ZIP_SOURCE_IS_OPEN_READING(src)) { 42 | zip_error_set(&src->error, ZIP_ER_INVAL, 0); 43 | return -1; 44 | } 45 | 46 | src->open_count--; 47 | if (src->open_count == 0) { 48 | _zip_source_call(src, NULL, 0, ZIP_SOURCE_CLOSE); 49 | 50 | if (ZIP_SOURCE_IS_LAYERED(src)) { 51 | if (zip_source_close(src->src) < 0) { 52 | zip_error_set(&src->error, ZIP_ER_INTERNAL, 0); 53 | } 54 | } 55 | } 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /jni/zip_delete.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_delete.c -- delete file from zip archive 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN int 39 | zip_delete(zip_t *za, zip_uint64_t idx) 40 | { 41 | if (idx >= za->nentry) { 42 | zip_error_set(&za->error, ZIP_ER_INVAL, 0); 43 | return -1; 44 | } 45 | 46 | if (ZIP_IS_RDONLY(za)) { 47 | zip_error_set(&za->error, ZIP_ER_RDONLY, 0); 48 | return -1; 49 | } 50 | 51 | /* allow duplicate file names, because the file will 52 | * be removed directly afterwards */ 53 | if (_zip_unchange(za, idx, 1) != 0) 54 | return -1; 55 | 56 | za->entry[idx].deleted = 1; 57 | 58 | return 0; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /jni/zip_set_default_password.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_set_default_password.c -- set default password for decryption 3 | Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | #include 37 | 38 | #include "zipint.h" 39 | 40 | 41 | ZIP_EXTERN int 42 | zip_set_default_password(zip_t *za, const char *passwd) 43 | { 44 | if (za == NULL) 45 | return -1; 46 | 47 | if (za->default_password) 48 | free(za->default_password); 49 | 50 | if (passwd) { 51 | if ((za->default_password=strdup(passwd)) == NULL) { 52 | zip_error_set(&za->error, ZIP_ER_MEMORY, 0); 53 | return -1; 54 | } 55 | } 56 | else 57 | za->default_password = NULL; 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /jni/zip_source_seek_write.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_seek_write.c -- seek to offset for writing 3 | Copyright (C) 2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN int 39 | zip_source_seek_write(zip_source_t *src, zip_int64_t offset, int whence) 40 | { 41 | zip_source_args_seek_t args; 42 | 43 | if (!ZIP_SOURCE_IS_OPEN_WRITING(src) || (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END)) { 44 | zip_error_set(&src->error, ZIP_ER_INVAL, 0); 45 | return -1; 46 | } 47 | 48 | args.offset = offset; 49 | args.whence = whence; 50 | 51 | return (_zip_source_call(src, &args, sizeof(args), ZIP_SOURCE_SEEK_WRITE) < 0 ? -1 : 0); 52 | } 53 | -------------------------------------------------------------------------------- /jni/zip_fread.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_fread.c -- read from file 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN zip_int64_t 39 | zip_fread(zip_file_t *zf, void *outbuf, zip_uint64_t toread) 40 | { 41 | zip_int64_t n; 42 | 43 | if (!zf) 44 | return -1; 45 | 46 | if (zf->error.zip_err != 0) 47 | return -1; 48 | 49 | if (toread > ZIP_INT64_MAX) { 50 | zip_error_set(&zf->error, ZIP_ER_INVAL, 0); 51 | return -1; 52 | } 53 | 54 | if ((zf->eof) || (toread == 0)) 55 | return 0; 56 | 57 | if ((n=zip_source_read(zf->src, outbuf, toread)) < 0) { 58 | _zip_error_set_from_source(&zf->error, zf->src); 59 | return -1; 60 | } 61 | 62 | return n; 63 | } 64 | -------------------------------------------------------------------------------- /jni/zip_source_remove.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_remove.c -- remove empty archive 3 | Copyright (C) 2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | int 39 | zip_source_remove(zip_source_t *src) 40 | { 41 | if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) { 42 | return 0; 43 | } 44 | 45 | if (ZIP_SOURCE_IS_OPEN_READING(src)) { 46 | if (zip_source_close(src) < 0) { 47 | return -1; 48 | } 49 | } 50 | if (src->write_state != ZIP_SOURCE_WRITE_CLOSED) { 51 | zip_source_rollback_write(src); 52 | } 53 | 54 | if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_REMOVE) < 0) { 55 | return -1; 56 | } 57 | 58 | src->write_state = ZIP_SOURCE_WRITE_REMOVED; 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /jni/zip_file_get_comment.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_file_get_comment.c -- get file comment 3 | Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | /* lenp is 32 bit because converted comment can be longer than ZIP_UINT16_MAX */ 38 | 39 | ZIP_EXTERN const char * 40 | zip_file_get_comment(zip_t *za, zip_uint64_t idx, zip_uint32_t *lenp, zip_flags_t flags) 41 | { 42 | zip_dirent_t *de; 43 | zip_uint32_t len; 44 | const zip_uint8_t *str; 45 | 46 | if ((de=_zip_get_dirent(za, idx, flags, NULL)) == NULL) 47 | return NULL; 48 | 49 | if ((str=_zip_string_get(de->comment, &len, flags, &za->error)) == NULL) 50 | return NULL; 51 | 52 | if (lenp) 53 | *lenp = len; 54 | 55 | return (const char *)str; 56 | } 57 | -------------------------------------------------------------------------------- /jni/zip_get_archive_comment.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_get_archive_comment.c -- get archive comment 3 | Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | ZIP_EXTERN const char * 41 | zip_get_archive_comment(zip_t *za, int *lenp, zip_flags_t flags) 42 | { 43 | zip_string_t *comment; 44 | zip_uint32_t len; 45 | const zip_uint8_t *str; 46 | 47 | if ((flags & ZIP_FL_UNCHANGED) || (za->comment_changes == NULL)) 48 | comment = za->comment_orig; 49 | else 50 | comment = za->comment_changes; 51 | 52 | if ((str=_zip_string_get(comment, &len, flags, &za->error)) == NULL) 53 | return NULL; 54 | 55 | if (lenp) 56 | *lenp = (int)len; 57 | 58 | return (const char *)str; 59 | } 60 | -------------------------------------------------------------------------------- /jni/zip_file_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_file_add.c -- add file via callback function 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | /* 38 | NOTE: Return type is signed so we can return -1 on error. 39 | The index can not be larger than ZIP_INT64_MAX since the size 40 | of the central directory cannot be larger than 41 | ZIP_UINT64_MAX, and each entry is larger than 2 bytes. 42 | */ 43 | 44 | ZIP_EXTERN zip_int64_t 45 | zip_file_add(zip_t *za, const char *name, zip_source_t *source, zip_flags_t flags) 46 | { 47 | if (name == NULL || source == NULL) { 48 | zip_error_set(&za->error, ZIP_ER_INVAL, 0); 49 | return -1; 50 | } 51 | 52 | return _zip_file_replace(za, ZIP_UINT64_MAX, name, source, flags); 53 | } 54 | -------------------------------------------------------------------------------- /jni/zip_get_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_get_name.c -- get filename for a file in zip file 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | ZIP_EXTERN const char * 41 | zip_get_name(zip_t *za, zip_uint64_t idx, zip_flags_t flags) 42 | { 43 | return _zip_get_name(za, idx, flags, &za->error); 44 | } 45 | 46 | 47 | const char * 48 | _zip_get_name(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error) 49 | { 50 | zip_dirent_t *de; 51 | const zip_uint8_t *str; 52 | 53 | if ((de=_zip_get_dirent(za, idx, flags, error)) == NULL) 54 | return NULL; 55 | 56 | if ((str=_zip_string_get(de->filename, NULL, flags, error)) == NULL) 57 | return NULL; 58 | 59 | return (const char *)str; 60 | } 61 | -------------------------------------------------------------------------------- /jni/zip_source_zip.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_zip.c -- create data source from zip file 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | #include 37 | 38 | #include "zipint.h" 39 | 40 | 41 | ZIP_EXTERN zip_source_t * 42 | zip_source_zip(zip_t *za, zip_t *srcza, zip_uint64_t srcidx, 43 | zip_flags_t flags, zip_uint64_t start, zip_int64_t len) 44 | { 45 | if (len < -1) { 46 | zip_error_set(&za->error, ZIP_ER_INVAL, 0); 47 | return NULL; 48 | } 49 | 50 | if (len == -1) 51 | len = 0; 52 | 53 | if (start == 0 && len == 0) 54 | flags |= ZIP_FL_COMPRESSED; 55 | else 56 | flags &= ~ZIP_FL_COMPRESSED; 57 | 58 | return _zip_source_zip_new(za, srcza, srcidx, flags, start, (zip_uint64_t)len, NULL); 59 | } 60 | -------------------------------------------------------------------------------- /jni/zip_source_stat.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_stat.c -- get meta information from zip_source 3 | Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | int 39 | zip_source_stat(zip_source_t *src, zip_stat_t *st) 40 | { 41 | if (src->source_closed) { 42 | return -1; 43 | } 44 | if (st == NULL) { 45 | zip_error_set(&src->error, ZIP_ER_INVAL, 0); 46 | return -1; 47 | } 48 | 49 | zip_stat_init(st); 50 | 51 | if (ZIP_SOURCE_IS_LAYERED(src)) { 52 | if (zip_source_stat(src->src, st) < 0) { 53 | _zip_error_set_from_source(&src->error, src->src); 54 | return -1; 55 | } 56 | } 57 | 58 | if (_zip_source_call(src, st, sizeof(*st), ZIP_SOURCE_STAT) < 0) { 59 | return -1; 60 | } 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /jni/zip_source_supports.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_supports.c -- check for supported functions 3 | Copyright (C) 2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | zip_int64_t 41 | zip_source_supports(zip_source_t *src) 42 | { 43 | return src->supports; 44 | } 45 | 46 | 47 | zip_int64_t 48 | zip_source_make_command_bitmap(zip_source_cmd_t cmd0, ...) 49 | { 50 | zip_int64_t bitmap; 51 | va_list ap; 52 | 53 | bitmap = ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd0); 54 | 55 | 56 | 57 | va_start(ap, cmd0); 58 | for (;;) { 59 | int cmd = va_arg(ap, int); 60 | if (cmd < 0) { 61 | break; 62 | } 63 | bitmap |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd); 64 | } 65 | va_end(ap); 66 | 67 | return bitmap; 68 | } 69 | -------------------------------------------------------------------------------- /jni/zip_source_file.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_file.c -- create data source from file 3 | Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | #include 37 | 38 | #include "zipint.h" 39 | 40 | 41 | ZIP_EXTERN zip_source_t * 42 | zip_source_file(zip_t *za, const char *fname, zip_uint64_t start, zip_int64_t len) 43 | { 44 | if (za == NULL) 45 | return NULL; 46 | 47 | return zip_source_file_create(fname, start, len, &za->error); 48 | } 49 | 50 | 51 | ZIP_EXTERN zip_source_t * 52 | zip_source_file_create(const char *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error) 53 | { 54 | if (fname == NULL || length < -1) { 55 | zip_error_set(error, ZIP_ER_INVAL, 0); 56 | return NULL; 57 | } 58 | 59 | return _zip_source_file_or_p(fname, NULL, start, length, NULL, error); 60 | } 61 | -------------------------------------------------------------------------------- /jni/zip_set_archive_flag.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_get_archive_flag.c -- set archive global flag 3 | Copyright (C) 2008-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN int 39 | zip_set_archive_flag(zip_t *za, zip_flags_t flag, int value) 40 | { 41 | unsigned int new_flags; 42 | 43 | if (value) 44 | new_flags = za->ch_flags | flag; 45 | else 46 | new_flags = za->ch_flags & ~flag; 47 | 48 | if (new_flags == za->ch_flags) 49 | return 0; 50 | 51 | if (ZIP_IS_RDONLY(za)) { 52 | zip_error_set(&za->error, ZIP_ER_RDONLY, 0); 53 | return -1; 54 | } 55 | 56 | if ((flag & ZIP_AFL_RDONLY) && value 57 | && (za->ch_flags & ZIP_AFL_RDONLY) == 0) { 58 | if (_zip_changed(za, NULL)) { 59 | zip_error_set(&za->error, ZIP_ER_CHANGED, 0); 60 | return -1; 61 | } 62 | } 63 | 64 | za->ch_flags = new_flags; 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /jni/zip_source_commit_write.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_commit_write.c -- commit changes to file 3 | Copyright (C) 2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN int 39 | zip_source_commit_write(zip_source_t *src) 40 | { 41 | if (!ZIP_SOURCE_IS_OPEN_WRITING(src)) { 42 | zip_error_set(&src->error, ZIP_ER_INVAL, 0); 43 | return -1; 44 | } 45 | 46 | if (src->open_count > 1) { 47 | zip_error_set(&src->error, ZIP_ER_INUSE, 0); 48 | return -1; 49 | } 50 | else if (ZIP_SOURCE_IS_OPEN_READING(src)) { 51 | if (zip_source_close(src) < 0) { 52 | return -1; 53 | } 54 | } 55 | 56 | if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_COMMIT_WRITE) < 0) { 57 | src->write_state = ZIP_SOURCE_WRITE_FAILED; 58 | return -1; 59 | } 60 | 61 | src->write_state = ZIP_SOURCE_WRITE_CLOSED; 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /jni/zip_error_to_str.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_error_to_str.c -- get string representation of zip error code 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #define _ZIP_COMPILING_DEPRECATED 41 | #include "zipint.h" 42 | 43 | 44 | ZIP_EXTERN int 45 | zip_error_to_str(char *buf, zip_uint64_t len, int ze, int se) 46 | { 47 | const char *zs, *ss; 48 | 49 | if (ze < 0 || ze >= _zip_nerr_str) 50 | return snprintf(buf, len, "Unknown error %d", ze); 51 | 52 | zs = _zip_err_str[ze]; 53 | 54 | switch (_zip_err_type[ze]) { 55 | case ZIP_ET_SYS: 56 | ss = strerror(se); 57 | break; 58 | 59 | case ZIP_ET_ZLIB: 60 | ss = zError(se); 61 | break; 62 | 63 | default: 64 | ss = NULL; 65 | } 66 | 67 | return snprintf(buf, len, "%s%s%s", 68 | zs, (ss ? ": " : ""), (ss ? ss : "")); 69 | } 70 | -------------------------------------------------------------------------------- /jni/zip_new.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_new.c -- create and init struct zip 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | /* _zip_new: 41 | creates a new zipfile struct, and sets the contents to zero; returns 42 | the new struct. */ 43 | 44 | zip_t * 45 | _zip_new(zip_error_t *error) 46 | { 47 | zip_t *za; 48 | 49 | za = (zip_t *)malloc(sizeof(struct zip)); 50 | if (!za) { 51 | zip_error_set(error, ZIP_ER_MEMORY, 0); 52 | return NULL; 53 | } 54 | 55 | za->src = NULL; 56 | za->open_flags = 0; 57 | zip_error_init(&za->error); 58 | za->flags = za->ch_flags = 0; 59 | za->default_password = NULL; 60 | za->comment_orig = za->comment_changes = NULL; 61 | za->comment_changed = 0; 62 | za->nentry = za->nentry_alloc = 0; 63 | za->entry = NULL; 64 | za->nopen_source = za->nopen_source_alloc = 0; 65 | za->open_source = NULL; 66 | za->tempdir = NULL; 67 | 68 | return za; 69 | } 70 | -------------------------------------------------------------------------------- /jni/zip_source_free.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_free.c -- free zip data source 3 | Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | ZIP_EXTERN void 41 | zip_source_free(zip_source_t *src) 42 | { 43 | if (src == NULL) 44 | return; 45 | 46 | if (src->refcount > 0) { 47 | src->refcount--; 48 | } 49 | if (src->refcount > 0) { 50 | return; 51 | } 52 | 53 | if (ZIP_SOURCE_IS_OPEN_READING(src)) { 54 | src->open_count = 1; /* force close */ 55 | zip_source_close(src); 56 | } 57 | if (ZIP_SOURCE_IS_OPEN_WRITING(src)) { 58 | zip_source_rollback_write(src); 59 | } 60 | 61 | if (src->source_archive && !src->source_closed) { 62 | _zip_deregister_source(src->source_archive, src); 63 | } 64 | 65 | (void)_zip_source_call(src, NULL, 0, ZIP_SOURCE_FREE); 66 | 67 | if (src->src) { 68 | zip_source_free(src->src); 69 | } 70 | 71 | free(src); 72 | } 73 | -------------------------------------------------------------------------------- /jni/zip_source_layered.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_layered.c -- create layered source 3 | Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | zip_source_t * 41 | zip_source_layered(zip_t *za, zip_source_t *src, zip_source_layered_callback cb, void *ud) 42 | { 43 | if (za == NULL) 44 | return NULL; 45 | 46 | return zip_source_layered_create(src, cb, ud, &za->error); 47 | } 48 | 49 | 50 | zip_source_t * 51 | zip_source_layered_create(zip_source_t *src, zip_source_layered_callback cb, void *ud, zip_error_t *error) 52 | { 53 | zip_source_t *zs; 54 | 55 | if ((zs=_zip_source_new(error)) == NULL) 56 | return NULL; 57 | 58 | zip_source_keep(src); 59 | zs->src = src; 60 | zs->cb.l = cb; 61 | zs->ud = ud; 62 | 63 | zs->supports = cb(src, ud, NULL, 0, ZIP_SOURCE_SUPPORTS); 64 | if (zs->supports < 0) { 65 | zs->supports = ZIP_SOURCE_SUPPORTS_READABLE; 66 | } 67 | 68 | return zs; 69 | } 70 | -------------------------------------------------------------------------------- /jni/zip_discard.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_discard.c -- discard and free struct zip 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | /* zip_discard: 41 | frees the space allocated to a zipfile struct, and closes the 42 | corresponding file. */ 43 | 44 | void 45 | zip_discard(zip_t *za) 46 | { 47 | zip_uint64_t i; 48 | 49 | if (za == NULL) 50 | return; 51 | 52 | if (za->src) { 53 | zip_source_close(za->src); 54 | zip_source_free(za->src); 55 | } 56 | 57 | free(za->default_password); 58 | _zip_string_free(za->comment_orig); 59 | _zip_string_free(za->comment_changes); 60 | 61 | if (za->entry) { 62 | for (i=0; inentry; i++) 63 | _zip_entry_finalize(za->entry+i); 64 | free(za->entry); 65 | } 66 | 67 | for (i=0; inopen_source; i++) { 68 | _zip_source_invalidate(za->open_source[i]); 69 | } 70 | free(za->open_source); 71 | 72 | zip_error_fini(&za->error); 73 | 74 | free(za); 75 | 76 | return; 77 | } 78 | -------------------------------------------------------------------------------- /jni/zip_file_rename.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_file_rename.c -- rename file in zip archive 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | ZIP_EXTERN int 41 | zip_file_rename(zip_t *za, zip_uint64_t idx, const char *name, zip_flags_t flags) 42 | { 43 | const char *old_name; 44 | int old_is_dir, new_is_dir; 45 | 46 | if (idx >= za->nentry || (name != NULL && strlen(name) > ZIP_UINT16_MAX)) { 47 | zip_error_set(&za->error, ZIP_ER_INVAL, 0); 48 | return -1; 49 | } 50 | 51 | if (ZIP_IS_RDONLY(za)) { 52 | zip_error_set(&za->error, ZIP_ER_RDONLY, 0); 53 | return -1; 54 | } 55 | 56 | if ((old_name=zip_get_name(za, idx, 0)) == NULL) 57 | return -1; 58 | 59 | new_is_dir = (name != NULL && name[strlen(name)-1] == '/'); 60 | old_is_dir = (old_name[strlen(old_name)-1] == '/'); 61 | 62 | if (new_is_dir != old_is_dir) { 63 | zip_error_set(&za->error, ZIP_ER_INVAL, 0); 64 | return -1; 65 | } 66 | 67 | return _zip_set_name(za, idx, name, flags); 68 | } 69 | -------------------------------------------------------------------------------- /jni/zip_unchange.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_unchange.c -- undo changes to file in zip archive 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | ZIP_EXTERN int 41 | zip_unchange(zip_t *za, zip_uint64_t idx) 42 | { 43 | return _zip_unchange(za, idx, 0); 44 | } 45 | 46 | 47 | int 48 | _zip_unchange(zip_t *za, zip_uint64_t idx, int allow_duplicates) 49 | { 50 | zip_int64_t i; 51 | 52 | if (idx >= za->nentry) { 53 | zip_error_set(&za->error, ZIP_ER_INVAL, 0); 54 | return -1; 55 | } 56 | 57 | if (!allow_duplicates && za->entry[idx].changes && (za->entry[idx].changes->changed & ZIP_DIRENT_FILENAME)) { 58 | i = _zip_name_locate(za, _zip_get_name(za, idx, ZIP_FL_UNCHANGED, NULL), 0, NULL); 59 | if (i >= 0 && (zip_uint64_t)i != idx) { 60 | zip_error_set(&za->error, ZIP_ER_EXISTS, 0); 61 | return -1; 62 | } 63 | } 64 | 65 | _zip_dirent_free(za->entry[idx].changes); 66 | za->entry[idx].changes = NULL; 67 | 68 | _zip_unchange_data(za->entry+idx); 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /jni/zip_add_entry.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_add_entry.c -- create and init struct zip_entry 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | /* NOTE: Signed due to -1 on error. See zip_add.c for more details. */ 41 | 42 | zip_int64_t 43 | _zip_add_entry(zip_t *za) 44 | { 45 | zip_uint64_t idx; 46 | 47 | if (za->nentry+1 >= za->nentry_alloc) { 48 | zip_entry_t *rentries; 49 | zip_uint64_t nalloc = za->nentry_alloc + 16; 50 | zip_uint64_t realloc_size = sizeof(struct zip_entry) * (size_t)nalloc; 51 | 52 | if (sizeof(struct zip_entry) * (size_t)za->nentry_alloc > realloc_size) { 53 | zip_error_set(&za->error, ZIP_ER_MEMORY, 0); 54 | return -1; 55 | } 56 | rentries = (zip_entry_t *)realloc(za->entry, sizeof(struct zip_entry) * (size_t)nalloc); 57 | if (!rentries) { 58 | zip_error_set(&za->error, ZIP_ER_MEMORY, 0); 59 | return -1; 60 | } 61 | za->entry = rentries; 62 | za->nentry_alloc = nalloc; 63 | } 64 | 65 | idx = za->nentry++; 66 | 67 | _zip_entry_init(za->entry+idx); 68 | 69 | return (zip_int64_t)idx; 70 | } 71 | -------------------------------------------------------------------------------- /jni/zip_source_open.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_open.c -- open zip_source (prepare for reading) 3 | Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | ZIP_EXTERN int 38 | zip_source_open(zip_source_t *src) 39 | { 40 | if (src->source_closed) { 41 | return -1; 42 | } 43 | if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) { 44 | zip_error_set(&src->error, ZIP_ER_DELETED, 0); 45 | return -1; 46 | } 47 | 48 | if (ZIP_SOURCE_IS_OPEN_READING(src)) { 49 | if ((zip_source_supports(src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK)) == 0) { 50 | zip_error_set(&src->error, ZIP_ER_INUSE, 0); 51 | return -1; 52 | } 53 | } 54 | else { 55 | if (ZIP_SOURCE_IS_LAYERED(src)) { 56 | if (zip_source_open(src->src) < 0) { 57 | _zip_error_set_from_source(&src->error, src->src); 58 | return -1; 59 | } 60 | } 61 | 62 | if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_OPEN) < 0) { 63 | if (ZIP_SOURCE_IS_LAYERED(src)) { 64 | zip_source_close(src->src); 65 | } 66 | return -1; 67 | } 68 | } 69 | 70 | src->open_count++; 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /jni/zip_source_call.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_call.c -- invoke callback command on zip_source 3 | Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | zip_int64_t 39 | _zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command) 40 | { 41 | zip_int64_t ret; 42 | 43 | if ((src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(command)) == 0) { 44 | zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0); 45 | return -1; 46 | } 47 | 48 | if (src->src == NULL) { 49 | ret = src->cb.f(src->ud, data, length, command); 50 | } 51 | else { 52 | ret = src->cb.l(src->src, src->ud, data, length, command); 53 | } 54 | 55 | if (ret < 0) { 56 | if (command != ZIP_SOURCE_ERROR && command != ZIP_SOURCE_SUPPORTS) { 57 | int e[2]; 58 | 59 | if (_zip_source_call(src, e, sizeof(e), ZIP_SOURCE_ERROR) < 0) { 60 | zip_error_set(&src->error, ZIP_ER_INTERNAL, 0); 61 | } 62 | else { 63 | zip_error_set(&src->error, e[0], e[1]); 64 | } 65 | } 66 | } 67 | 68 | return ret; 69 | } 70 | -------------------------------------------------------------------------------- /jni/zip_filerange_crc.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_filerange_crc.c -- compute CRC32 for a range of a file 3 | Copyright (C) 2008-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | #include 37 | 38 | #include "zipint.h" 39 | 40 | 41 | 42 | int 43 | _zip_filerange_crc(zip_source_t *src, zip_uint64_t start, zip_uint64_t len, uLong *crcp, zip_error_t *error) 44 | { 45 | Bytef buf[BUFSIZE]; 46 | zip_int64_t n; 47 | 48 | *crcp = crc32(0L, Z_NULL, 0); 49 | 50 | if (start > ZIP_INT64_MAX) { 51 | zip_error_set(error, ZIP_ER_SEEK, EFBIG); 52 | return -1; 53 | } 54 | 55 | if (zip_source_seek(src, (zip_int64_t)start, SEEK_SET) != 0) { 56 | _zip_error_set_from_source(error, src); 57 | return -1; 58 | } 59 | 60 | while (len > 0) { 61 | n = (zip_int64_t)(len > BUFSIZE ? BUFSIZE : len); 62 | if ((n = zip_source_read(src, buf, (zip_uint64_t)n)) < 0) { 63 | _zip_error_set_from_source(error, src); 64 | return -1; 65 | } 66 | if (n == 0) { 67 | zip_error_set(error, ZIP_ER_EOF, 0); 68 | return -1; 69 | } 70 | 71 | *crcp = crc32(*crcp, buf, (uInt)n); 72 | 73 | len -= (zip_uint64_t)n; 74 | } 75 | 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /jni/zip_file_get_offset.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_file_get_offset.c -- get offset of file data in archive. 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "zipint.h" 43 | 44 | 45 | /* _zip_file_get_offset(za, ze): 46 | Returns the offset of the file data for entry ze. 47 | 48 | On error, fills in za->error and returns 0. 49 | */ 50 | 51 | zip_uint64_t 52 | _zip_file_get_offset(const zip_t *za, zip_uint64_t idx, zip_error_t *error) 53 | { 54 | zip_uint64_t offset; 55 | zip_int32_t size; 56 | 57 | offset = za->entry[idx].orig->offset; 58 | 59 | if (zip_source_seek(za->src, (zip_int64_t)offset, SEEK_SET) < 0) { 60 | _zip_error_set_from_source(error, za->src); 61 | return 0; 62 | } 63 | 64 | /* TODO: cache? */ 65 | if ((size=_zip_dirent_size(za->src, ZIP_EF_LOCAL, error)) < 0) 66 | return 0; 67 | 68 | if (offset+(zip_uint32_t)size > ZIP_INT64_MAX) { 69 | zip_error_set(error, ZIP_ER_SEEK, EFBIG); 70 | return 0; 71 | } 72 | 73 | return offset + (zip_uint32_t)size; 74 | } 75 | -------------------------------------------------------------------------------- /jni/zip_file_set_mtime.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_file_set_mtime.c -- set modification time of entry. 3 | Copyright (C) 2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "zipint.h" 35 | 36 | ZIP_EXTERN int zip_file_set_mtime(zip_t *za, zip_uint64_t idx, time_t mtime, zip_flags_t flags) 37 | { 38 | zip_entry_t *e; 39 | int changed; 40 | 41 | if (_zip_get_dirent(za, idx, 0, NULL) == NULL) 42 | return -1; 43 | 44 | if (ZIP_IS_RDONLY(za)) { 45 | zip_error_set(&za->error, ZIP_ER_RDONLY, 0); 46 | return -1; 47 | } 48 | 49 | e = za->entry+idx; 50 | 51 | changed = e->orig == NULL || mtime != e->orig->last_mod; 52 | 53 | if (changed) { 54 | if (e->changes == NULL) { 55 | if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) { 56 | zip_error_set(&za->error, ZIP_ER_MEMORY, 0); 57 | return -1; 58 | } 59 | } 60 | e->changes->last_mod = mtime; 61 | e->changes->changed |= ZIP_DIRENT_LAST_MOD; 62 | } 63 | else { 64 | if (e->changes) { 65 | e->changes->changed &= ~ZIP_DIRENT_LAST_MOD; 66 | if (e->changes->changed == 0) { 67 | _zip_dirent_free(e->changes); 68 | e->changes = NULL; 69 | } 70 | } 71 | } 72 | 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /jni/zip_error_strerror.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_error_sterror.c -- get string representation of struct zip_error 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "zipint.h" 41 | 42 | 43 | ZIP_EXTERN const char * 44 | zip_error_strerror(zip_error_t *err) 45 | { 46 | const char *zs, *ss; 47 | char buf[128], *s; 48 | 49 | zip_error_fini(err); 50 | 51 | if (err->zip_err < 0 || err->zip_err >= _zip_nerr_str) { 52 | sprintf(buf, "Unknown error %d", err->zip_err); 53 | zs = NULL; 54 | ss = buf; 55 | } 56 | else { 57 | zs = _zip_err_str[err->zip_err]; 58 | 59 | switch (_zip_err_type[err->zip_err]) { 60 | case ZIP_ET_SYS: 61 | ss = strerror(err->sys_err); 62 | break; 63 | 64 | case ZIP_ET_ZLIB: 65 | ss = zError(err->sys_err); 66 | break; 67 | 68 | default: 69 | ss = NULL; 70 | } 71 | } 72 | 73 | if (ss == NULL) 74 | return zs; 75 | else { 76 | if ((s=(char *)malloc(strlen(ss) 77 | + (zs ? strlen(zs)+2 : 0) + 1)) == NULL) 78 | return _zip_err_str[ZIP_ER_MEMORY]; 79 | 80 | sprintf(s, "%s%s%s", 81 | (zs ? zs : ""), 82 | (zs ? ": " : ""), 83 | ss); 84 | err->str = s; 85 | 86 | return s; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /jni/zip_fopen_index_encrypted.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_fopen_index_encrypted.c -- open file for reading by index w/ password 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "zipint.h" 40 | 41 | static zip_file_t *_zip_file_new(zip_t *za); 42 | 43 | 44 | ZIP_EXTERN zip_file_t * 45 | zip_fopen_index_encrypted(zip_t *za, zip_uint64_t index, zip_flags_t flags, 46 | const char *password) 47 | { 48 | zip_file_t *zf; 49 | zip_source_t *src; 50 | 51 | if ((src=_zip_source_zip_new(za, za, index, flags, 0, 0, password)) == NULL) 52 | return NULL; 53 | 54 | if (zip_source_open(src) < 0) { 55 | _zip_error_set_from_source(&za->error, src); 56 | zip_source_free(src); 57 | return NULL; 58 | } 59 | 60 | if ((zf=_zip_file_new(za)) == NULL) { 61 | zip_source_free(src); 62 | return NULL; 63 | } 64 | 65 | zf->src = src; 66 | 67 | return zf; 68 | } 69 | 70 | 71 | static zip_file_t * 72 | _zip_file_new(zip_t *za) 73 | { 74 | zip_file_t *zf; 75 | 76 | if ((zf=(zip_file_t *)malloc(sizeof(struct zip_file))) == NULL) { 77 | zip_error_set(&za->error, ZIP_ER_MEMORY, 0); 78 | return NULL; 79 | } 80 | 81 | zf->za = za; 82 | zip_error_init(&zf->error); 83 | zf->eof = 0; 84 | zf->src = NULL; 85 | 86 | return zf; 87 | } 88 | -------------------------------------------------------------------------------- /jni/zip_name_locate.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_name_locate.c -- get index by name 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | #ifdef HAVE_STRINGS_H 37 | #include 38 | #endif 39 | 40 | #include "zipint.h" 41 | 42 | 43 | ZIP_EXTERN zip_int64_t 44 | zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags) 45 | { 46 | return _zip_name_locate(za, fname, flags, &za->error); 47 | } 48 | 49 | 50 | zip_int64_t 51 | _zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags, zip_error_t *error) 52 | { 53 | int (*cmp)(const char *, const char *); 54 | const char *fn, *p; 55 | zip_uint64_t i; 56 | 57 | if (za == NULL) 58 | return -1; 59 | 60 | if (fname == NULL) { 61 | zip_error_set(error, ZIP_ER_INVAL, 0); 62 | return -1; 63 | } 64 | 65 | cmp = (flags & ZIP_FL_NOCASE) ? strcasecmp : strcmp; 66 | 67 | for (i=0; inentry; i++) { 68 | fn = _zip_get_name(za, i, flags, error); 69 | 70 | /* newly added (partially filled) entry or error */ 71 | if (fn == NULL) 72 | continue; 73 | 74 | if (flags & ZIP_FL_NODIR) { 75 | p = strrchr(fn, '/'); 76 | if (p) 77 | fn = p+1; 78 | } 79 | 80 | if (cmp(fname, fn) == 0) { 81 | _zip_error_clear(error); 82 | return (zip_int64_t)i; 83 | } 84 | } 85 | 86 | zip_error_set(error, ZIP_ER_NOENT, 0); 87 | return -1; 88 | } 89 | -------------------------------------------------------------------------------- /jni/zip_set_archive_comment.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_set_archive_comment.c -- set archive comment 3 | Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | ZIP_EXTERN int 41 | zip_set_archive_comment(zip_t *za, const char *comment, zip_uint16_t len) 42 | { 43 | zip_string_t *cstr; 44 | 45 | if (ZIP_IS_RDONLY(za)) { 46 | zip_error_set(&za->error, ZIP_ER_RDONLY, 0); 47 | return -1; 48 | } 49 | 50 | if (len > 0 && comment == NULL) { 51 | zip_error_set(&za->error, ZIP_ER_INVAL, 0); 52 | return -1; 53 | } 54 | 55 | if (len > 0) { 56 | if ((cstr=_zip_string_new((const zip_uint8_t *)comment, len, ZIP_FL_ENC_GUESS, &za->error)) == NULL) 57 | return -1; 58 | 59 | if (_zip_guess_encoding(cstr, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_CP437) { 60 | _zip_string_free(cstr); 61 | zip_error_set(&za->error, ZIP_ER_INVAL, 0); 62 | return -1; 63 | } 64 | } 65 | else 66 | cstr = NULL; 67 | 68 | _zip_string_free(za->comment_changes); 69 | za->comment_changes = NULL; 70 | 71 | if (((za->comment_orig && _zip_string_equal(za->comment_orig, cstr)) 72 | || (za->comment_orig == NULL && cstr == NULL))) { 73 | _zip_string_free(cstr); 74 | za->comment_changed = 0; 75 | } 76 | else { 77 | za->comment_changes = cstr; 78 | za->comment_changed = 1; 79 | } 80 | 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /jni/zip_fdopen.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_fdopen.c -- open read-only archive from file descriptor 3 | Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN zip_t * 39 | zip_fdopen(int fd_orig, int _flags, int *zep) 40 | { 41 | int fd; 42 | FILE *fp; 43 | zip_t *za; 44 | zip_source_t *src; 45 | struct zip_error error; 46 | 47 | if (_flags < 0 || (_flags & ZIP_TRUNCATE)) { 48 | _zip_set_open_error(zep, NULL, ZIP_ER_INVAL); 49 | return NULL; 50 | } 51 | 52 | /* We dup() here to avoid messing with the passed in fd. 53 | We could not restore it to the original state in case of error. */ 54 | 55 | if ((fd=dup(fd_orig)) < 0) { 56 | _zip_set_open_error(zep, NULL, ZIP_ER_OPEN); 57 | return NULL; 58 | } 59 | 60 | if ((fp=fdopen(fd, "rb")) == NULL) { 61 | close(fd); 62 | _zip_set_open_error(zep, NULL, ZIP_ER_OPEN); 63 | return NULL; 64 | } 65 | 66 | zip_error_init(&error); 67 | if ((src = zip_source_filep_create(fp, 0, -1, &error)) == NULL) { 68 | _zip_set_open_error(zep, &error, 0); 69 | zip_error_fini(&error); 70 | return NULL; 71 | } 72 | 73 | if ((za = zip_open_from_source(src, _flags, &error)) == NULL) { 74 | _zip_set_open_error(zep, &error, 0); 75 | zip_error_fini(&error); 76 | return NULL; 77 | } 78 | 79 | zip_error_fini(&error); 80 | close(fd_orig); 81 | return za; 82 | } 83 | -------------------------------------------------------------------------------- /jni/zip_dir_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_dir_add.c -- add directory 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | #include 37 | 38 | #include "zipint.h" 39 | 40 | 41 | /* NOTE: Signed due to -1 on error. See zip_add.c for more details. */ 42 | 43 | ZIP_EXTERN zip_int64_t 44 | zip_dir_add(zip_t *za, const char *name, zip_flags_t flags) 45 | { 46 | size_t len; 47 | zip_int64_t idx; 48 | char *s; 49 | zip_source_t *source; 50 | 51 | if (ZIP_IS_RDONLY(za)) { 52 | zip_error_set(&za->error, ZIP_ER_RDONLY, 0); 53 | return -1; 54 | } 55 | 56 | if (name == NULL) { 57 | zip_error_set(&za->error, ZIP_ER_INVAL, 0); 58 | return -1; 59 | } 60 | 61 | s = NULL; 62 | len = strlen(name); 63 | 64 | if (name[len-1] != '/') { 65 | if ((s=(char *)malloc(len+2)) == NULL) { 66 | zip_error_set(&za->error, ZIP_ER_MEMORY, 0); 67 | return -1; 68 | } 69 | strcpy(s, name); 70 | s[len] = '/'; 71 | s[len+1] = '\0'; 72 | } 73 | 74 | if ((source=zip_source_buffer(za, NULL, 0, 0)) == NULL) { 75 | free(s); 76 | return -1; 77 | } 78 | 79 | idx = _zip_file_replace(za, ZIP_UINT64_MAX, s ? s : name, source, flags); 80 | 81 | free(s); 82 | 83 | if (idx < 0) 84 | zip_source_free(source); 85 | else { 86 | if (zip_file_set_external_attributes(za, (zip_uint64_t)idx, 0, ZIP_OPSYS_DEFAULT, ZIP_EXT_ATTRIB_DEFAULT_DIR) < 0) { 87 | zip_delete(za, (zip_uint64_t)idx); 88 | return -1; 89 | } 90 | } 91 | 92 | return idx; 93 | } 94 | -------------------------------------------------------------------------------- /jni/zip_stat_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_stat_init.c -- initialize struct zip_stat. 3 | Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include 35 | 36 | #include "zipint.h" 37 | 38 | 39 | ZIP_EXTERN void 40 | zip_stat_init(zip_stat_t *st) 41 | { 42 | st->valid = 0; 43 | st->name = NULL; 44 | st->index = ZIP_UINT64_MAX; 45 | st->crc = 0; 46 | st->mtime = (time_t)-1; 47 | st->size = 0; 48 | st->comp_size = 0; 49 | st->comp_method = ZIP_CM_STORE; 50 | st->encryption_method = ZIP_EM_NONE; 51 | } 52 | 53 | 54 | int 55 | _zip_stat_merge(zip_stat_t *dst, const zip_stat_t *src, zip_error_t *error) 56 | { 57 | /* name is not merged, since zip_stat_t doesn't own it, and src may not be valid as long as dst */ 58 | if (src->valid & ZIP_STAT_INDEX) { 59 | dst->index = src->index; 60 | } 61 | if (src->valid & ZIP_STAT_SIZE) { 62 | dst->size = src->size; 63 | } 64 | if (src->valid & ZIP_STAT_COMP_SIZE) { 65 | dst->comp_size = src->comp_size; 66 | } 67 | if (src->valid & ZIP_STAT_MTIME) { 68 | dst->mtime = src->mtime; 69 | } 70 | if (src->valid & ZIP_STAT_CRC) { 71 | dst->crc = src->crc; 72 | } 73 | if (src->valid & ZIP_STAT_COMP_METHOD) { 74 | dst->comp_method = src->comp_method; 75 | } 76 | if (src->valid & ZIP_STAT_ENCRYPTION_METHOD) { 77 | dst->encryption_method = src->encryption_method; 78 | } 79 | if (src->valid & ZIP_STAT_FLAGS) { 80 | dst->flags = src->flags; 81 | } 82 | dst->valid |= src->valid; 83 | 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /jni/zip_stat_index.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_stat_index.c -- get information about file by index 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN int 39 | zip_stat_index(zip_t *za, zip_uint64_t index, zip_flags_t flags, 40 | zip_stat_t *st) 41 | { 42 | const char *name; 43 | zip_dirent_t *de; 44 | 45 | if ((de=_zip_get_dirent(za, index, flags, NULL)) == NULL) 46 | return -1; 47 | 48 | if ((name=zip_get_name(za, index, flags)) == NULL) 49 | return -1; 50 | 51 | 52 | if ((flags & ZIP_FL_UNCHANGED) == 0 53 | && ZIP_ENTRY_DATA_CHANGED(za->entry+index)) { 54 | if (zip_source_stat(za->entry[index].source, st) < 0) { 55 | zip_error_set(&za->error, ZIP_ER_CHANGED, 0); 56 | return -1; 57 | } 58 | } 59 | else { 60 | zip_stat_init(st); 61 | 62 | st->crc = de->crc; 63 | st->size = de->uncomp_size; 64 | st->mtime = de->last_mod; 65 | st->comp_size = de->comp_size; 66 | st->comp_method = (zip_uint16_t)de->comp_method; 67 | if (de->bitflags & ZIP_GPBF_ENCRYPTED) { 68 | if (de->bitflags & ZIP_GPBF_STRONG_ENCRYPTION) { 69 | /* TODO */ 70 | st->encryption_method = ZIP_EM_UNKNOWN; 71 | } 72 | else 73 | st->encryption_method = ZIP_EM_TRAD_PKWARE; 74 | } 75 | else 76 | st->encryption_method = ZIP_EM_NONE; 77 | st->valid = ZIP_STAT_CRC|ZIP_STAT_SIZE|ZIP_STAT_MTIME 78 | |ZIP_STAT_COMP_SIZE|ZIP_STAT_COMP_METHOD|ZIP_STAT_ENCRYPTION_METHOD; 79 | } 80 | 81 | st->index = index; 82 | st->name = name; 83 | st->valid |= ZIP_STAT_INDEX|ZIP_STAT_NAME; 84 | 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /jni/zip_set_file_compression.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_set_file_compression.c -- set compression for file in archive 3 | Copyright (C) 2012-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN int 39 | zip_set_file_compression(zip_t *za, zip_uint64_t idx, zip_int32_t method, zip_uint32_t flags) 40 | { 41 | zip_entry_t *e; 42 | zip_int32_t old_method; 43 | 44 | if (idx >= za->nentry) { 45 | zip_error_set(&za->error, ZIP_ER_INVAL, 0); 46 | return -1; 47 | } 48 | 49 | if (ZIP_IS_RDONLY(za)) { 50 | zip_error_set(&za->error, ZIP_ER_RDONLY, 0); 51 | return -1; 52 | } 53 | 54 | if (method != ZIP_CM_DEFAULT && method != ZIP_CM_STORE && method != ZIP_CM_DEFLATE) { 55 | zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0); 56 | return -1; 57 | } 58 | 59 | e = za->entry+idx; 60 | 61 | old_method = (e->orig == NULL ? ZIP_CM_DEFAULT : e->orig->comp_method); 62 | 63 | /* TODO: revisit this when flags are supported, since they may require a recompression */ 64 | 65 | if (method == old_method) { 66 | if (e->changes) { 67 | e->changes->changed &= ~ZIP_DIRENT_COMP_METHOD; 68 | if (e->changes->changed == 0) { 69 | _zip_dirent_free(e->changes); 70 | e->changes = NULL; 71 | } 72 | } 73 | } 74 | else { 75 | if (e->changes == NULL) { 76 | if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) { 77 | zip_error_set(&za->error, ZIP_ER_MEMORY, 0); 78 | return -1; 79 | } 80 | } 81 | 82 | e->changes->comp_method = method; 83 | e->changes->changed |= ZIP_DIRENT_COMP_METHOD; 84 | } 85 | 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /jni/zip_source_function.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_function.c -- create zip data source from callback function 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | ZIP_EXTERN zip_source_t * 41 | zip_source_function(zip_t *za, zip_source_callback zcb, void *ud) 42 | { 43 | if (za == NULL) { 44 | return NULL; 45 | } 46 | 47 | return zip_source_function_create(zcb, ud, &za->error); 48 | } 49 | 50 | 51 | ZIP_EXTERN zip_source_t * 52 | zip_source_function_create(zip_source_callback zcb, void *ud, zip_error_t *error) 53 | { 54 | zip_source_t *zs; 55 | 56 | if ((zs=_zip_source_new(error)) == NULL) 57 | return NULL; 58 | 59 | zs->cb.f = zcb; 60 | zs->ud = ud; 61 | 62 | zs->supports = zcb(ud, NULL, 0, ZIP_SOURCE_SUPPORTS); 63 | if (zs->supports < 0) { 64 | zs->supports = ZIP_SOURCE_SUPPORTS_READABLE; 65 | } 66 | 67 | return zs; 68 | } 69 | 70 | 71 | ZIP_EXTERN void 72 | zip_source_keep(zip_source_t *src) 73 | { 74 | src->refcount++; 75 | } 76 | 77 | 78 | zip_source_t * 79 | _zip_source_new(zip_error_t *error) 80 | { 81 | zip_source_t *src; 82 | 83 | if ((src=(zip_source_t *)malloc(sizeof(*src))) == NULL) { 84 | zip_error_set(error, ZIP_ER_MEMORY, 0); 85 | return NULL; 86 | } 87 | 88 | src->src = NULL; 89 | src->cb.f = NULL; 90 | src->ud = NULL; 91 | src->open_count = 0; 92 | src->write_state = ZIP_SOURCE_WRITE_CLOSED; 93 | src->source_closed = false; 94 | src->source_archive = NULL; 95 | src->refcount = 1; 96 | zip_error_init(&src->error); 97 | 98 | return src; 99 | } 100 | -------------------------------------------------------------------------------- /jni/zip_source_seek.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_source_seek.c -- seek to offset 3 | Copyright (C) 2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN int 39 | zip_source_seek(zip_source_t *src, zip_int64_t offset, int whence) 40 | { 41 | zip_source_args_seek_t args; 42 | 43 | if (src->source_closed) { 44 | return -1; 45 | } 46 | if (!ZIP_SOURCE_IS_OPEN_READING(src) || (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END)) { 47 | zip_error_set(&src->error, ZIP_ER_INVAL, 0); 48 | return -1; 49 | } 50 | 51 | args.offset = offset; 52 | args.whence = whence; 53 | 54 | return (_zip_source_call(src, &args, sizeof(args), ZIP_SOURCE_SEEK) < 0 ? -1 : 0); 55 | } 56 | 57 | 58 | zip_int64_t 59 | zip_source_seek_compute_offset(zip_uint64_t offset, zip_uint64_t length, void *data, zip_uint64_t data_length, zip_error_t *error) 60 | { 61 | zip_int64_t new_offset; 62 | zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, data_length, error); 63 | 64 | if (args == NULL) { 65 | return -1; 66 | } 67 | 68 | switch (args->whence) { 69 | case SEEK_CUR: 70 | new_offset = (zip_int64_t)offset + args->offset; 71 | break; 72 | 73 | case SEEK_END: 74 | new_offset = (zip_int64_t)length + args->offset; 75 | break; 76 | 77 | case SEEK_SET: 78 | new_offset = args->offset; 79 | break; 80 | 81 | default: 82 | zip_error_set(error, ZIP_ER_INVAL, 0); 83 | return -1; 84 | } 85 | 86 | if (new_offset < 0 || (zip_uint64_t)new_offset > length) { 87 | zip_error_set(error, ZIP_ER_INVAL, 0); 88 | return -1; 89 | } 90 | 91 | return new_offset; 92 | } 93 | -------------------------------------------------------------------------------- /jni/zip_file_set_external_attributes.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_file_set_external_attributes.c -- set external attributes for entry 3 | Copyright (C) 2013-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "zipint.h" 35 | 36 | ZIP_EXTERN int 37 | zip_file_set_external_attributes(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_uint8_t opsys, zip_uint32_t attributes) 38 | { 39 | zip_entry_t *e; 40 | int changed; 41 | zip_uint8_t unchanged_opsys; 42 | zip_uint32_t unchanged_attributes; 43 | 44 | if (_zip_get_dirent(za, idx, 0, NULL) == NULL) 45 | return -1; 46 | 47 | if (ZIP_IS_RDONLY(za)) { 48 | zip_error_set(&za->error, ZIP_ER_RDONLY, 0); 49 | return -1; 50 | } 51 | 52 | e = za->entry+idx; 53 | 54 | unchanged_opsys = (e->orig ? (zip_uint8_t)(e->orig->version_madeby>>8) : (zip_uint8_t)ZIP_OPSYS_DEFAULT); 55 | unchanged_attributes = e->orig ? e->orig->ext_attrib : ZIP_EXT_ATTRIB_DEFAULT; 56 | 57 | changed = (opsys != unchanged_opsys || attributes != unchanged_attributes); 58 | 59 | if (changed) { 60 | if (e->changes == NULL) { 61 | if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) { 62 | zip_error_set(&za->error, ZIP_ER_MEMORY, 0); 63 | return -1; 64 | } 65 | } 66 | e->changes->version_madeby = (zip_uint16_t)((opsys << 8) | (e->changes->version_madeby & 0xff)); 67 | e->changes->ext_attrib = attributes; 68 | e->changes->changed |= ZIP_DIRENT_ATTRIBUTES; 69 | } 70 | else if (e->changes) { 71 | e->changes->changed &= ~ZIP_DIRENT_ATTRIBUTES; 72 | if (e->changes->changed == 0) { 73 | _zip_dirent_free(e->changes); 74 | e->changes = NULL; 75 | } 76 | else { 77 | e->changes->version_madeby = (zip_uint16_t)((unchanged_opsys << 8) | (e->changes->version_madeby & 0xff)); 78 | e->changes->ext_attrib = unchanged_attributes; 79 | } 80 | } 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2009 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := libzip 20 | LOCAL_SRC_FILES :=\ 21 | mkstemp.c \ 22 | zip_add.c \ 23 | zip_add_dir.c \ 24 | zip_add_entry.c \ 25 | zip_buffer.c \ 26 | zip_close.c \ 27 | zip_delete.c \ 28 | zip_dir_add.c \ 29 | zip_dirent.c \ 30 | zip_discard.c \ 31 | zip_entry.c \ 32 | zip_err_str.c \ 33 | zip_error.c \ 34 | zip_error_clear.c \ 35 | zip_error_get.c \ 36 | zip_error_get_sys_type.c \ 37 | zip_error_strerror.c \ 38 | zip_error_to_str.c \ 39 | zip_extra_field.c \ 40 | zip_extra_field_api.c \ 41 | zip_fclose.c \ 42 | zip_fdopen.c \ 43 | zip_file_add.c \ 44 | zip_file_error_clear.c \ 45 | zip_file_error_get.c \ 46 | zip_file_get_comment.c \ 47 | zip_file_get_external_attributes.c \ 48 | zip_file_get_offset.c \ 49 | zip_file_rename.c \ 50 | zip_file_replace.c \ 51 | zip_file_set_comment.c \ 52 | zip_file_set_external_attributes.c \ 53 | zip_file_set_mtime.c \ 54 | zip_file_strerror.c \ 55 | zip_filerange_crc.c \ 56 | zip_fopen.c \ 57 | zip_fopen_encrypted.c \ 58 | zip_fopen_index.c \ 59 | zip_fopen_index_encrypted.c \ 60 | zip_fread.c \ 61 | zip_get_archive_comment.c \ 62 | zip_get_archive_flag.c \ 63 | zip_get_compression_implementation.c \ 64 | zip_get_encryption_implementation.c \ 65 | zip_get_file_comment.c \ 66 | zip_get_name.c \ 67 | zip_get_num_entries.c \ 68 | zip_get_num_files.c \ 69 | zip_io_util.c \ 70 | zip_memdup.c \ 71 | zip_name_locate.c \ 72 | zip_new.c \ 73 | zip_open.c \ 74 | zip_rename.c \ 75 | zip_replace.c \ 76 | zip_set_archive_comment.c \ 77 | zip_set_archive_flag.c \ 78 | zip_set_default_password.c \ 79 | zip_set_file_comment.c \ 80 | zip_set_file_compression.c \ 81 | zip_set_name.c \ 82 | zip_source_begin_write.c \ 83 | zip_source_buffer.c \ 84 | zip_source_call.c \ 85 | zip_source_close.c \ 86 | zip_source_commit_write.c \ 87 | zip_source_crc.c \ 88 | zip_source_deflate.c \ 89 | zip_source_error.c \ 90 | zip_source_file.c \ 91 | zip_source_filep.c \ 92 | zip_source_free.c \ 93 | zip_source_function.c \ 94 | zip_source_is_deleted.c \ 95 | zip_source_layered.c \ 96 | zip_source_open.c \ 97 | zip_source_pkware.c \ 98 | zip_source_read.c \ 99 | zip_source_remove.c \ 100 | zip_source_rollback_write.c \ 101 | zip_source_seek.c \ 102 | zip_source_seek_write.c \ 103 | zip_source_stat.c \ 104 | zip_source_supports.c \ 105 | zip_source_tell.c \ 106 | zip_source_tell_write.c \ 107 | zip_source_window.c \ 108 | zip_source_write.c \ 109 | zip_source_zip.c \ 110 | zip_source_zip_new.c \ 111 | zip_stat.c \ 112 | zip_stat_index.c \ 113 | zip_stat_init.c \ 114 | zip_strerror.c \ 115 | zip_string.c \ 116 | zip_unchange.c \ 117 | zip_unchange_all.c \ 118 | zip_unchange_archive.c \ 119 | zip_unchange_data.c \ 120 | zip_utf-8.c 121 | 122 | LOCAL_LDLIBS := -lz 123 | 124 | #include $(BUILD_SHARED_LIBRARY) 125 | include $(BUILD_STATIC_LIBRARY) 126 | -------------------------------------------------------------------------------- /jni/zip_file_set_comment.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_file_set_comment.c -- set comment for file in archive 3 | Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | ZIP_EXTERN int 41 | zip_file_set_comment(zip_t *za, zip_uint64_t idx, 42 | const char *comment, zip_uint16_t len, zip_flags_t flags) 43 | { 44 | zip_entry_t *e; 45 | zip_string_t *cstr; 46 | int changed; 47 | 48 | if (_zip_get_dirent(za, idx, 0, NULL) == NULL) 49 | return -1; 50 | 51 | if (ZIP_IS_RDONLY(za)) { 52 | zip_error_set(&za->error, ZIP_ER_RDONLY, 0); 53 | return -1; 54 | } 55 | 56 | if (len > 0 && comment == NULL) { 57 | zip_error_set(&za->error, ZIP_ER_INVAL, 0); 58 | return -1; 59 | } 60 | 61 | if (len > 0) { 62 | if ((cstr=_zip_string_new((const zip_uint8_t *)comment, len, flags, &za->error)) == NULL) 63 | return -1; 64 | if ((flags & ZIP_FL_ENCODING_ALL) == ZIP_FL_ENC_GUESS && _zip_guess_encoding(cstr, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_UTF8_GUESSED) 65 | cstr->encoding = ZIP_ENCODING_UTF8_KNOWN; 66 | } 67 | else 68 | cstr = NULL; 69 | 70 | e = za->entry+idx; 71 | 72 | if (e->changes) { 73 | _zip_string_free(e->changes->comment); 74 | e->changes->comment = NULL; 75 | e->changes->changed &= ~ZIP_DIRENT_COMMENT; 76 | } 77 | 78 | if (e->orig && e->orig->comment) 79 | changed = !_zip_string_equal(e->orig->comment, cstr); 80 | else 81 | changed = (cstr != NULL); 82 | 83 | if (changed) { 84 | if (e->changes == NULL) { 85 | if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) { 86 | zip_error_set(&za->error, ZIP_ER_MEMORY, 0); 87 | _zip_string_free(cstr); 88 | return -1; 89 | } 90 | } 91 | e->changes->comment = cstr; 92 | e->changes->changed |= ZIP_DIRENT_COMMENT; 93 | } 94 | else { 95 | _zip_string_free(cstr); 96 | if (e->changes && e->changes->changed == 0) { 97 | _zip_dirent_free(e->changes); 98 | e->changes = NULL; 99 | } 100 | } 101 | 102 | return 0; 103 | } 104 | -------------------------------------------------------------------------------- /jni/zip_file_replace.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_file_replace.c -- replace file via callback function 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include "zipint.h" 36 | 37 | 38 | ZIP_EXTERN int 39 | zip_file_replace(zip_t *za, zip_uint64_t idx, zip_source_t *source, zip_flags_t flags) 40 | { 41 | if (idx >= za->nentry || source == NULL) { 42 | zip_error_set(&za->error, ZIP_ER_INVAL, 0); 43 | return -1; 44 | } 45 | 46 | if (_zip_file_replace(za, idx, NULL, source, flags) == -1) 47 | return -1; 48 | 49 | return 0; 50 | } 51 | 52 | 53 | 54 | /* NOTE: Signed due to -1 on error. See zip_add.c for more details. */ 55 | 56 | zip_int64_t 57 | _zip_file_replace(zip_t *za, zip_uint64_t idx, const char *name, zip_source_t *source, zip_flags_t flags) 58 | { 59 | zip_uint64_t za_nentry_prev; 60 | 61 | if (ZIP_IS_RDONLY(za)) { 62 | zip_error_set(&za->error, ZIP_ER_RDONLY, 0); 63 | return -1; 64 | } 65 | 66 | za_nentry_prev = za->nentry; 67 | if (idx == ZIP_UINT64_MAX) { 68 | zip_int64_t i = -1; 69 | 70 | if (flags & ZIP_FL_OVERWRITE) 71 | i = _zip_name_locate(za, name, flags, NULL); 72 | 73 | if (i == -1) { 74 | /* create and use new entry, used by zip_add */ 75 | if ((i=_zip_add_entry(za)) < 0) 76 | return -1; 77 | } 78 | idx = (zip_uint64_t)i; 79 | } 80 | 81 | if (name && _zip_set_name(za, idx, name, flags) != 0) { 82 | if (za->nentry != za_nentry_prev) { 83 | _zip_entry_finalize(za->entry+idx); 84 | za->nentry = za_nentry_prev; 85 | } 86 | return -1; 87 | } 88 | 89 | /* does not change any name related data, so we can do it here; 90 | * needed for a double add of the same file name */ 91 | _zip_unchange_data(za->entry+idx); 92 | 93 | if (za->entry[idx].orig != NULL && (za->entry[idx].changes == NULL || (za->entry[idx].changes->changed & ZIP_DIRENT_COMP_METHOD) == 0)) { 94 | if (za->entry[idx].changes == NULL) { 95 | if ((za->entry[idx].changes=_zip_dirent_clone(za->entry[idx].orig)) == NULL) { 96 | zip_error_set(&za->error, ZIP_ER_MEMORY, 0); 97 | return -1; 98 | } 99 | } 100 | 101 | za->entry[idx].changes->comp_method = ZIP_CM_REPLACED_DEFAULT; 102 | za->entry[idx].changes->changed |= ZIP_DIRENT_COMP_METHOD; 103 | } 104 | 105 | za->entry[idx].source = source; 106 | 107 | return (zip_int64_t)idx; 108 | } 109 | -------------------------------------------------------------------------------- /jni/zip_set_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_set_name.c -- rename helper function 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #include 36 | #include 37 | 38 | #include "zipint.h" 39 | 40 | 41 | int 42 | _zip_set_name(zip_t *za, zip_uint64_t idx, const char *name, zip_flags_t flags) 43 | { 44 | zip_entry_t *e; 45 | zip_string_t *str; 46 | int changed; 47 | zip_int64_t i; 48 | 49 | if (idx >= za->nentry) { 50 | zip_error_set(&za->error, ZIP_ER_INVAL, 0); 51 | return -1; 52 | } 53 | 54 | if (ZIP_IS_RDONLY(za)) { 55 | zip_error_set(&za->error, ZIP_ER_RDONLY, 0); 56 | return -1; 57 | } 58 | 59 | if (name && strlen(name) > 0) { 60 | /* TODO: check for string too long */ 61 | if ((str=_zip_string_new((const zip_uint8_t *)name, (zip_uint16_t)strlen(name), flags, &za->error)) == NULL) 62 | return -1; 63 | if ((flags & ZIP_FL_ENCODING_ALL) == ZIP_FL_ENC_GUESS && _zip_guess_encoding(str, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_UTF8_GUESSED) 64 | str->encoding = ZIP_ENCODING_UTF8_KNOWN; 65 | } 66 | else 67 | str = NULL; 68 | 69 | /* TODO: encoding flags needed for CP437? */ 70 | if ((i=_zip_name_locate(za, name, 0, NULL)) >= 0 && (zip_uint64_t)i != idx) { 71 | _zip_string_free(str); 72 | zip_error_set(&za->error, ZIP_ER_EXISTS, 0); 73 | return -1; 74 | } 75 | 76 | /* no effective name change */ 77 | if (i>=0 && (zip_uint64_t)i == idx) { 78 | _zip_string_free(str); 79 | return 0; 80 | } 81 | 82 | e = za->entry+idx; 83 | 84 | if (e->changes) { 85 | _zip_string_free(e->changes->filename); 86 | e->changes->filename = NULL; 87 | e->changes->changed &= ~ZIP_DIRENT_FILENAME; 88 | } 89 | 90 | if (e->orig) 91 | changed = !_zip_string_equal(e->orig->filename, str); 92 | else 93 | changed = 1; 94 | 95 | if (changed) { 96 | if (e->changes == NULL) { 97 | if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) { 98 | zip_error_set(&za->error, ZIP_ER_MEMORY, 0); 99 | _zip_string_free(str); 100 | return -1; 101 | } 102 | } 103 | e->changes->filename = str; 104 | e->changes->changed |= ZIP_DIRENT_FILENAME; 105 | } 106 | else { 107 | _zip_string_free(str); 108 | if (e->changes && e->changes->changed == 0) { 109 | _zip_dirent_free(e->changes); 110 | e->changes = NULL; 111 | } 112 | } 113 | 114 | return 0; 115 | } 116 | -------------------------------------------------------------------------------- /jni/mkstemp.c: -------------------------------------------------------------------------------- 1 | /* $NiH: mkstemp.c,v 1.3 2006/04/23 14:51:45 wiz Exp $ */ 2 | 3 | /* Adapted from NetBSB libc by Dieter Baron */ 4 | 5 | /* NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp */ 6 | 7 | /* 8 | * Copyright (c) 1987, 1993 9 | * The Regents of the University of California. All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #ifndef O_BINARY 47 | #define O_BINARY 0 48 | #endif 49 | 50 | 51 | 52 | int 53 | _zip_mkstemp(char *path) 54 | { 55 | int fd; 56 | char *start, *trv; 57 | struct stat sbuf; 58 | pid_t pid; 59 | 60 | /* To guarantee multiple calls generate unique names even if 61 | the file is not created. 676 different possibilities with 7 62 | or more X's, 26 with 6 or less. */ 63 | static char xtra[2] = "aa"; 64 | int xcnt = 0; 65 | 66 | pid = getpid(); 67 | 68 | /* Move to end of path and count trailing X's. */ 69 | for (trv = path; *trv; ++trv) 70 | if (*trv == 'X') 71 | xcnt++; 72 | else 73 | xcnt = 0; 74 | 75 | /* Use at least one from xtra. Use 2 if more than 6 X's. */ 76 | if (*(trv - 1) == 'X') 77 | *--trv = xtra[0]; 78 | if (xcnt > 6 && *(trv - 1) == 'X') 79 | *--trv = xtra[1]; 80 | 81 | /* Set remaining X's to pid digits with 0's to the left. */ 82 | while (*--trv == 'X') { 83 | *trv = (pid % 10) + '0'; 84 | pid /= 10; 85 | } 86 | 87 | /* update xtra for next call. */ 88 | if (xtra[0] != 'z') 89 | xtra[0]++; 90 | else { 91 | xtra[0] = 'a'; 92 | if (xtra[1] != 'z') 93 | xtra[1]++; 94 | else 95 | xtra[1] = 'a'; 96 | } 97 | 98 | /* 99 | * check the target directory; if you have six X's and it 100 | * doesn't exist this runs for a *very* long time. 101 | */ 102 | for (start = trv + 1;; --trv) { 103 | if (trv <= path) 104 | break; 105 | if (*trv == '/') { 106 | *trv = '\0'; 107 | if (stat(path, &sbuf)) 108 | return (0); 109 | if (!S_ISDIR(sbuf.st_mode)) { 110 | errno = ENOTDIR; 111 | return (0); 112 | } 113 | *trv = '/'; 114 | break; 115 | } 116 | } 117 | 118 | for (;;) { 119 | if ((fd=open(path, O_CREAT|O_EXCL|O_RDWR|O_BINARY, 0600)) >= 0) 120 | return (fd); 121 | if (errno != EEXIST) 122 | return (0); 123 | 124 | /* tricky little algorithm for backward compatibility */ 125 | for (trv = start;;) { 126 | if (!*trv) 127 | return (0); 128 | if (*trv == 'z') 129 | *trv++ = 'a'; 130 | else { 131 | if (isdigit((unsigned char)*trv)) 132 | *trv = 'a'; 133 | else 134 | ++*trv; 135 | break; 136 | } 137 | } 138 | } 139 | /*NOTREACHED*/ 140 | } 141 | -------------------------------------------------------------------------------- /jni/zip_io_util.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_io_util.c -- I/O helper functions 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include "zipint.h" 39 | 40 | int 41 | _zip_read(zip_source_t *src, zip_uint8_t *b, zip_uint64_t length, zip_error_t *error) 42 | { 43 | zip_int64_t n; 44 | 45 | if (length > ZIP_INT64_MAX) { 46 | zip_error_set(error, ZIP_ER_INTERNAL, 0); 47 | return -1; 48 | } 49 | 50 | if ((n = zip_source_read(src, b, length)) < 0) { 51 | _zip_error_set_from_source(error, src); 52 | return -1; 53 | } 54 | 55 | if (n < (zip_int64_t)length) { 56 | zip_error_set(error, ZIP_ER_EOF, 0); 57 | return -1; 58 | } 59 | 60 | return 0; 61 | } 62 | 63 | 64 | zip_uint8_t * 65 | _zip_read_data(zip_buffer_t *buffer, zip_source_t *src, size_t length, bool nulp, zip_error_t *error) 66 | { 67 | zip_uint8_t *r; 68 | 69 | if (length == 0 && !nulp) { 70 | return NULL; 71 | } 72 | 73 | r = (zip_uint8_t *)malloc(length + (nulp ? 1 : 0)); 74 | if (!r) { 75 | zip_error_set(error, ZIP_ER_MEMORY, 0); 76 | return NULL; 77 | } 78 | 79 | if (buffer) { 80 | zip_uint8_t *data = _zip_buffer_get(buffer, length); 81 | 82 | if (data == NULL) { 83 | zip_error_set(error, ZIP_ER_MEMORY, 0); 84 | free(r); 85 | return NULL; 86 | } 87 | memcpy(r, data, length); 88 | } 89 | else { 90 | if (_zip_read(src, r, length, error) < 0) { 91 | free(r); 92 | return NULL; 93 | } 94 | } 95 | 96 | if (nulp) { 97 | zip_uint8_t *o; 98 | /* replace any in-string NUL characters with spaces */ 99 | r[length] = 0; 100 | for (o=r; osrc, data, length)) < 0) { 130 | _zip_error_set_from_source(&za->error, za->src); 131 | return -1; 132 | } 133 | if ((zip_uint64_t)n != length) { 134 | zip_error_set(&za->error, ZIP_ER_WRITE, EINTR); 135 | return -1; 136 | } 137 | 138 | return 0; 139 | } 140 | -------------------------------------------------------------------------------- /jni/zip_error.c: -------------------------------------------------------------------------------- 1 | /* 2 | zip_error.c -- zip_error_t helper functions 3 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner 4 | 5 | This file is part of libzip, a library to manipulate ZIP archives. 6 | The authors can be contacted at 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 3. The names of the authors may not be used to endorse or promote 18 | products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 22 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include 35 | #include 36 | 37 | #include "zipint.h" 38 | 39 | 40 | ZIP_EXTERN int 41 | zip_error_code_system(const zip_error_t *error) { 42 | return error->sys_err; 43 | } 44 | 45 | 46 | ZIP_EXTERN int 47 | zip_error_code_zip(const zip_error_t *error) { 48 | return error->zip_err; 49 | } 50 | 51 | 52 | ZIP_EXTERN void 53 | zip_error_fini(zip_error_t *err) 54 | { 55 | free(err->str); 56 | err->str = NULL; 57 | } 58 | 59 | 60 | ZIP_EXTERN void 61 | zip_error_init(zip_error_t *err) 62 | { 63 | err->zip_err = ZIP_ER_OK; 64 | err->sys_err = 0; 65 | err->str = NULL; 66 | } 67 | 68 | ZIP_EXTERN void 69 | zip_error_init_with_code(zip_error_t *error, int ze) 70 | { 71 | zip_error_init(error); 72 | error->zip_err = ze; 73 | switch (zip_error_system_type(error)) { 74 | case ZIP_ET_SYS: 75 | error->sys_err = errno; 76 | break; 77 | 78 | default: 79 | error->sys_err = 0; 80 | break; 81 | } 82 | } 83 | 84 | 85 | ZIP_EXTERN int 86 | zip_error_system_type(const zip_error_t *error) { 87 | if (error->zip_err < 0 || error->zip_err >= _zip_nerr_str) 88 | return ZIP_ET_NONE; 89 | 90 | return _zip_err_type[error->zip_err]; 91 | } 92 | 93 | 94 | void 95 | _zip_error_clear(zip_error_t *err) 96 | { 97 | if (err == NULL) 98 | return; 99 | 100 | err->zip_err = ZIP_ER_OK; 101 | err->sys_err = 0; 102 | } 103 | 104 | 105 | void 106 | _zip_error_copy(zip_error_t *dst, const zip_error_t *src) 107 | { 108 | dst->zip_err = src->zip_err; 109 | dst->sys_err = src->sys_err; 110 | } 111 | 112 | 113 | void 114 | _zip_error_get(const zip_error_t *err, int *zep, int *sep) 115 | { 116 | if (zep) 117 | *zep = err->zip_err; 118 | if (sep) { 119 | if (zip_error_system_type(err) != ZIP_ET_NONE) 120 | *sep = err->sys_err; 121 | else 122 | *sep = 0; 123 | } 124 | } 125 | 126 | 127 | void 128 | zip_error_set(zip_error_t *err, int ze, int se) 129 | { 130 | if (err) { 131 | err->zip_err = ze; 132 | err->sys_err = se; 133 | } 134 | } 135 | 136 | 137 | void 138 | _zip_error_set_from_source(zip_error_t *err, zip_source_t *src) 139 | { 140 | _zip_error_copy(err, zip_source_error(src)); 141 | } 142 | 143 | 144 | zip_int64_t 145 | zip_error_to_data(const zip_error_t *error, void *data, zip_uint64_t length) 146 | { 147 | int *e = (int *)data; 148 | 149 | if (length < sizeof(int)*2) { 150 | return -1; 151 | } 152 | 153 | e[0] = zip_error_code_zip(error); 154 | e[1] = zip_error_code_system(error); 155 | return sizeof(int)*2; 156 | } 157 | --------------------------------------------------------------------------------