xref: /PHP-7.0/ext/zip/php_zip.h (revision 478f119a)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2017 The PHP Group                                |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 3.01 of the PHP license,      |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available through the world-wide-web at the following url:           |
10   | http://www.php.net/license/3_01.txt.                                 |
11   | If you did not receive a copy of the PHP license and are unable to   |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Author: Pierre-Alain Joye <pajoye@php.net>                           |
16   +----------------------------------------------------------------------+
17 */
18 
19 
20 #ifndef PHP_ZIP_H
21 #define PHP_ZIP_H
22 
23 extern zend_module_entry zip_module_entry;
24 #define phpext_zip_ptr &zip_module_entry
25 
26 #ifdef ZTS
27 #include "TSRM.h"
28 #endif
29 
30 #if defined(HAVE_LIBZIP)
31 #include <zip.h>
32 #else
33 #include "lib/zip.h"
34 #endif
35 
36 #ifndef ZIP_OVERWRITE
37 #define ZIP_OVERWRITE ZIP_TRUNCATE
38 #endif
39 
40 #define PHP_ZIP_VERSION "1.13.5"
41 
42 #ifndef  Z_SET_REFCOUNT_P
43 # if PHP_MAJOR_VERSION < 6 && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3)
44 #  define Z_SET_REFCOUNT_P(pz, rc)  pz->refcount = rc
45 #  define Z_UNSET_ISREF_P(pz) pz->is_ref = 0
46 # endif
47 #endif
48 
49 /* {{{ ZIP_OPENBASEDIR_CHECKPATH(filename) */
50 #if PHP_API_VERSION < 20100412
51 # define ZIP_OPENBASEDIR_CHECKPATH(filename) \
52 	(PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(filename)
53 #else
54 #define ZIP_OPENBASEDIR_CHECKPATH(filename) \
55 	php_check_open_basedir(filename)
56 #endif
57 /* }}} */
58 
59 typedef struct _ze_zip_rsrc {
60 	struct zip *za;
61 	int index_current;
62 	int num_files;
63 } zip_rsrc;
64 
65 typedef zip_rsrc * zip_rsrc_ptr;
66 
67 typedef struct _ze_zip_read_rsrc {
68 	struct zip_file *zf;
69 	struct zip_stat sb;
70 } zip_read_rsrc;
71 
72 #define ZIPARCHIVE_ME(name, arg_info, flags) {#name, c_ziparchive_ ##name, arg_info,(uint32_t) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
73 #define ZIPARCHIVE_METHOD(name)	ZEND_NAMED_FUNCTION(c_ziparchive_ ##name)
74 
75 /* Extends zend object */
76 typedef struct _ze_zip_object {
77 	struct zip *za;
78 	char **buffers;
79 	HashTable *prop_handler;
80 	char *filename;
81 	int filename_len;
82 	int buffers_cnt;
83 	zend_object zo;
84 } ze_zip_object;
85 
php_zip_fetch_object(zend_object * obj)86 static inline ze_zip_object *php_zip_fetch_object(zend_object *obj) {
87 	return (ze_zip_object *)((char*)(obj) - XtOffsetOf(ze_zip_object, zo));
88 }
89 
90 #define Z_ZIP_P(zv) php_zip_fetch_object(Z_OBJ_P((zv)))
91 
92 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);
93 php_stream *php_stream_zip_open(const char *filename, const char *path, const char *mode STREAMS_DC);
94 
95 extern php_stream_wrapper php_stream_zip_wrapper;
96 
97 #endif	/* PHP_ZIP_H */
98 
99 /*
100  * Local variables:
101  * tab-width: 4
102  * c-basic-offset: 4
103  * End:
104  * vim600: noet sw=4 ts=4 fdm=marker
105  * vim<600: noet sw=4 ts=4
106  */
107