xref: /PHP-8.0/ext/zip/php_zip.h (revision 6d0d5227)
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   | http://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.19.5"
35 
36 #define ZIP_OPENBASEDIR_CHECKPATH(filename) php_check_open_basedir(filename)
37 
38 typedef struct _ze_zip_rsrc {
39 	struct zip *za;
40 	zip_uint64_t index_current;
41 	zip_int64_t num_files;
42 } zip_rsrc;
43 
44 typedef zip_rsrc * zip_rsrc_ptr;
45 
46 typedef struct _ze_zip_read_rsrc {
47 	struct zip_file *zf;
48 	struct zip_stat sb;
49 } zip_read_rsrc;
50 
51 /* Extends zend object */
52 typedef struct _ze_zip_object {
53 	struct zip *za;
54 	char **buffers;
55 	HashTable *prop_handler;
56 	char *filename;
57 	int filename_len;
58 	int buffers_cnt;
59 	zip_int64_t last_id;
60 	int err_zip;
61 	int err_sys;
62 #ifdef HAVE_PROGRESS_CALLBACK
63 	zval progress_callback;
64 #endif
65 #ifdef HAVE_CANCEL_CALLBACK
66 	zval cancel_callback;
67 #endif
68 	zend_object zo;
69 } ze_zip_object;
70 
php_zip_fetch_object(zend_object * obj)71 static inline ze_zip_object *php_zip_fetch_object(zend_object *obj) {
72 	return (ze_zip_object *)((char*)(obj) - XtOffsetOf(ze_zip_object, zo));
73 }
74 
75 #define Z_ZIP_P(zv) php_zip_fetch_object(Z_OBJ_P((zv)))
76 
77 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);
78 php_stream *php_stream_zip_open(struct zip *arch, const char *path, const char *mode STREAMS_DC);
79 
80 extern const php_stream_wrapper php_stream_zip_wrapper;
81 
82 #endif	/* PHP_ZIP_H */
83