xref: /php-src/ext/zip/php_zip.h (revision 3d5723e2)
1 /*
2   +----------------------------------------------------------------------+
3   | Copyright (c) The PHP Group                                          |
4   +----------------------------------------------------------------------+
5   | This source file is subject to version 3.01 of the PHP license,      |
6   | that is bundled with this package in the file LICENSE, and is        |
7   | available through the world-wide-web at the following url:           |
8   | https://www.php.net/license/3_01.txt                                 |
9   | If you did not receive a copy of the PHP license and are unable to   |
10   | obtain it through the world-wide-web, please send a note to          |
11   | license@php.net so we can mail you a copy immediately.               |
12   +----------------------------------------------------------------------+
13   | Author: Pierre-Alain Joye <pajoye@php.net>                           |
14   +----------------------------------------------------------------------+
15 */
16 
17 
18 #ifndef PHP_ZIP_H
19 #define PHP_ZIP_H
20 
21 extern zend_module_entry zip_module_entry;
22 #define phpext_zip_ptr &zip_module_entry
23 
24 #ifdef ZTS
25 #include "TSRM.h"
26 #endif
27 
28 #include <zip.h>
29 
30 #ifndef ZIP_OVERWRITE
31 #define ZIP_OVERWRITE ZIP_TRUNCATE
32 #endif
33 
34 /* since 1.10.1 */
35 #ifndef ZIP_LENGTH_TO_END
36 #define ZIP_LENGTH_TO_END 0
37 #endif
38 
39 /* Additionnal flags not from libzip */
40 #define ZIP_FL_OPEN_FILE_NOW (1u<<30)
41 
42 #define PHP_ZIP_VERSION "1.22.3"
43 
44 #ifdef HAVE_LIBZIP_VERSION
45 #define LIBZIP_VERSION_STR zip_libzip_version()
46 #else
47 #define LIBZIP_VERSION_STR LIBZIP_VERSION
48 #endif
49 
50 #define ZIP_OPENBASEDIR_CHECKPATH(filename) php_check_open_basedir(filename)
51 
52 typedef struct _ze_zip_rsrc {
53 	struct zip *za;
54 	zip_uint64_t index_current;
55 	zip_int64_t num_files;
56 } zip_rsrc;
57 
58 typedef zip_rsrc * zip_rsrc_ptr;
59 
60 typedef struct _ze_zip_read_rsrc {
61 	struct zip_file *zf;
62 	struct zip_stat sb;
63 } zip_read_rsrc;
64 
65 /* Extends zend object */
66 typedef struct _ze_zip_object {
67 	struct zip *za;
68 	char **buffers;
69 	HashTable *prop_handler;
70 	char *filename;
71 	int filename_len;
72 	int buffers_cnt;
73 	zip_int64_t last_id;
74 	int err_zip;
75 	int err_sys;
76 #ifdef HAVE_PROGRESS_CALLBACK
77 	zval progress_callback;
78 #endif
79 #ifdef HAVE_CANCEL_CALLBACK
80 	zval cancel_callback;
81 #endif
82 	zend_object zo;
83 } ze_zip_object;
84 
php_zip_fetch_object(zend_object * obj)85 static inline ze_zip_object *php_zip_fetch_object(zend_object *obj) {
86 	return (ze_zip_object *)((char*)(obj) - XtOffsetOf(ze_zip_object, zo));
87 }
88 
89 #define Z_ZIP_P(zv) php_zip_fetch_object(Z_OBJ_P((zv)))
90 
91 php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
92 php_stream *php_stream_zip_open(struct zip *arch, struct zip_stat *sb, const char *mode, zip_flags_t flags STREAMS_DC);
93 
94 extern const php_stream_wrapper php_stream_zip_wrapper;
95 
96 #define LIBZIP_ATLEAST(m,n,p) (((m<<16) + (n<<8) + p) <= ((LIBZIP_VERSION_MAJOR<<16) + (LIBZIP_VERSION_MINOR<<8) + LIBZIP_VERSION_MICRO))
97 
98 #endif	/* PHP_ZIP_H */
99