xref: /PHP-8.2/ext/zip/php_zip.h (revision e4f23769)
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 #define PHP_ZIP_VERSION "1.21.1"
35 
36 #ifdef HAVE_LIBZIP_VERSION
37 #define LIBZIP_VERSION_STR zip_libzip_version()
38 #else
39 #define LIBZIP_VERSION_STR LIBZIP_VERSION
40 #endif
41 
42 #define ZIP_OPENBASEDIR_CHECKPATH(filename) php_check_open_basedir(filename)
43 
44 typedef struct _ze_zip_rsrc {
45 	struct zip *za;
46 	zip_uint64_t index_current;
47 	zip_int64_t num_files;
48 } zip_rsrc;
49 
50 typedef zip_rsrc * zip_rsrc_ptr;
51 
52 typedef struct _ze_zip_read_rsrc {
53 	struct zip_file *zf;
54 	struct zip_stat sb;
55 } zip_read_rsrc;
56 
57 /* Extends zend object */
58 typedef struct _ze_zip_object {
59 	struct zip *za;
60 	char **buffers;
61 	HashTable *prop_handler;
62 	char *filename;
63 	int filename_len;
64 	int buffers_cnt;
65 	zip_int64_t last_id;
66 	int err_zip;
67 	int err_sys;
68 #ifdef HAVE_PROGRESS_CALLBACK
69 	zval progress_callback;
70 #endif
71 #ifdef HAVE_CANCEL_CALLBACK
72 	zval cancel_callback;
73 #endif
74 	zend_object zo;
75 } ze_zip_object;
76 
php_zip_fetch_object(zend_object * obj)77 static inline ze_zip_object *php_zip_fetch_object(zend_object *obj) {
78 	return (ze_zip_object *)((char*)(obj) - XtOffsetOf(ze_zip_object, zo));
79 }
80 
81 #define Z_ZIP_P(zv) php_zip_fetch_object(Z_OBJ_P((zv)))
82 
83 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);
84 php_stream *php_stream_zip_open(struct zip *arch, struct zip_stat *sb, const char *mode, zip_flags_t flags STREAMS_DC);
85 
86 extern const php_stream_wrapper php_stream_zip_wrapper;
87 
88 #define LIBZIP_ATLEAST(m,n,p) (((m<<16) + (n<<8) + p) <= ((LIBZIP_VERSION_MAJOR<<16) + (LIBZIP_VERSION_MINOR<<8) + LIBZIP_VERSION_MICRO))
89 
90 #endif	/* PHP_ZIP_H */
91