php-src/ext/zip/php_zip.c

3030 lines
76 KiB
C
Raw Normal View History

/*
+----------------------------------------------------------------------+
2014-09-19 16:33:14 +00:00
| PHP Version 7 |
+----------------------------------------------------------------------+
2015-01-15 15:27:30 +00:00
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
2008-07-03 12:53:12 +00:00
| Author: Piere-Alain Joye <pierre@php.net> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "ext/standard/file.h"
#include "ext/standard/php_string.h"
2008-05-21 09:27:41 +00:00
#include "ext/pcre/php_pcre.h"
#include "ext/standard/php_filestat.h"
#include "php_zip.h"
/* zip_open is a macro for renaming libzip zipopen, so we need to use PHP_NAMED_FUNCTION */
static PHP_NAMED_FUNCTION(zif_zip_open);
static PHP_NAMED_FUNCTION(zif_zip_read);
static PHP_NAMED_FUNCTION(zif_zip_close);
static PHP_NAMED_FUNCTION(zif_zip_entry_read);
static PHP_NAMED_FUNCTION(zif_zip_entry_filesize);
static PHP_NAMED_FUNCTION(zif_zip_entry_name);
static PHP_NAMED_FUNCTION(zif_zip_entry_compressedsize);
static PHP_NAMED_FUNCTION(zif_zip_entry_compressionmethod);
static PHP_NAMED_FUNCTION(zif_zip_entry_open);
static PHP_NAMED_FUNCTION(zif_zip_entry_close);
2008-05-21 09:27:41 +00:00
#ifdef HAVE_GLOB
#ifndef PHP_WIN32
#include <glob.h>
#else
#include "win32/glob.h"
#endif
#endif
/* {{{ Resource le */
static int le_zip_dir;
#define le_zip_dir_name "Zip Directory"
static int le_zip_entry;
#define le_zip_entry_name "Zip Entry"
/* }}} */
/* {{{ PHP_ZIP_STAT_INDEX(za, index, flags, sb) */
#define PHP_ZIP_STAT_INDEX(za, index, flags, sb) \
if (zip_stat_index(za, index, flags, &sb) != 0) { \
RETURN_FALSE; \
}
/* }}} */
/* {{{ PHP_ZIP_STAT_PATH(za, path, path_len, flags, sb) */
#define PHP_ZIP_STAT_PATH(za, path, path_len, flags, sb) \
if (path_len < 1) { \
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); \
RETURN_FALSE; \
} \
2007-05-19 22:25:11 +00:00
if (zip_stat(za, path, flags, &sb) != 0) { \
RETURN_FALSE; \
}
/* }}} */
/* {{{ PHP_ZIP_SET_FILE_COMMENT(za, index, comment, comment_len) */
#define PHP_ZIP_SET_FILE_COMMENT(za, index, comment, comment_len) \
if (comment_len == 0) { \
/* Passing NULL remove the existing comment */ \
if (zip_set_file_comment(intern, index, NULL, 0) < 0) { \
RETURN_FALSE; \
} \
} else if (zip_set_file_comment(intern, index, comment, comment_len) < 0) { \
RETURN_FALSE; \
} \
RETURN_TRUE;
/* }}} */
# define add_ascii_assoc_string add_assoc_string
2014-08-25 17:24:55 +00:00
# define add_ascii_assoc_long add_assoc_long
2013-12-30 07:47:16 +00:00
/* Flatten a path by making a relative path (to .)*/
static char * php_zip_make_relative_path(char *path, size_t path_len) /* {{{ */
{
char *path_begin = path;
size_t i;
if (path_len < 1 || path == NULL) {
return NULL;
}
if (IS_SLASH(path[0])) {
return path + 1;
}
i = path_len;
while (1) {
while (i > 0 && !IS_SLASH(path[i])) {
i--;
}
if (!i) {
return path;
}
if (i >= 2 && (path[i -1] == '.' || path[i -1] == ':')) {
/* i is the position of . or :, add 1 for / */
path_begin = path + i + 1;
break;
}
i--;
}
return path_begin;
}
/* }}} */
2013-12-30 07:47:16 +00:00
# define CWD_STATE_ALLOC(l) emalloc(l)
# define CWD_STATE_FREE(s) efree(s)
/* {{{ php_zip_extract_file */
2014-12-13 22:06:14 +00:00
static int php_zip_extract_file(struct zip * za, char *dest, char *file, int file_len)
{
php_stream_statbuf ssb;
struct zip_file *zf;
struct zip_stat sb;
char b[8192];
2006-12-23 23:28:39 +00:00
int n, len, ret;
php_stream *stream;
char *fullpath;
char *file_dirname_fullpath;
2006-12-23 23:28:39 +00:00
char file_dirname[MAXPATHLEN];
size_t dir_len;
int is_dir_only = 0;
char *path_cleaned;
size_t path_cleaned_len;
cwd_state new_state;
2014-02-23 10:08:35 +00:00
zend_string *file_basename;
2013-12-30 07:47:16 +00:00
new_state.cwd = CWD_STATE_ALLOC(1);
new_state.cwd[0] = '\0';
new_state.cwd_length = 0;
/* Clean/normlize the path and then transform any path (absolute or relative)
to a path relative to cwd (../../mydir/foo.txt > mydir/foo.txt)
*/
2014-12-13 22:06:14 +00:00
virtual_file_ex(&new_state, file, NULL, CWD_EXPAND);
path_cleaned = php_zip_make_relative_path(new_state.cwd, new_state.cwd_length);
if(!path_cleaned) {
return 0;
}
path_cleaned_len = strlen(path_cleaned);
if (path_cleaned_len >= MAXPATHLEN || zip_stat(za, file, 0, &sb) != 0) {
return 0;
}
2008-05-21 09:27:41 +00:00
/* it is a directory only, see #40228 */
if (path_cleaned_len > 1 && IS_SLASH(path_cleaned[path_cleaned_len - 1])) {
len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file);
is_dir_only = 1;
} else {
memcpy(file_dirname, path_cleaned, path_cleaned_len);
dir_len = php_dirname(file_dirname, path_cleaned_len);
if (dir_len <= 0 || (dir_len == 1 && file_dirname[0] == '.')) {
len = spprintf(&file_dirname_fullpath, 0, "%s", dest);
} else {
len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file_dirname);
}
2014-12-13 22:06:14 +00:00
file_basename = php_basename(path_cleaned, path_cleaned_len, NULL, 0);
if (ZIP_OPENBASEDIR_CHECKPATH(file_dirname_fullpath)) {
efree(file_dirname_fullpath);
2014-08-25 17:24:55 +00:00
zend_string_release(file_basename);
2013-12-30 07:47:16 +00:00
CWD_STATE_FREE(new_state.cwd);
return 0;
}
}
/* let see if the path already exists */
if (php_stream_stat_path_ex(file_dirname_fullpath, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL) < 0) {
ret = php_stream_mkdir(file_dirname_fullpath, 0777, PHP_STREAM_MKDIR_RECURSIVE|REPORT_ERRORS, NULL);
if (!ret) {
efree(file_dirname_fullpath);
if (!is_dir_only) {
2014-08-25 17:24:55 +00:00
zend_string_release(file_basename);
2013-12-30 07:47:16 +00:00
CWD_STATE_FREE(new_state.cwd);
}
return 0;
}
}
/* it is a standalone directory, job done */
if (is_dir_only) {
efree(file_dirname_fullpath);
2013-12-30 07:47:16 +00:00
CWD_STATE_FREE(new_state.cwd);
return 1;
}
2014-02-23 10:08:35 +00:00
len = spprintf(&fullpath, 0, "%s/%s", file_dirname_fullpath, file_basename->val);
if (!len) {
efree(file_dirname_fullpath);
2014-08-25 17:24:55 +00:00
zend_string_release(file_basename);
2013-12-30 07:47:16 +00:00
CWD_STATE_FREE(new_state.cwd);
return 0;
} else if (len > MAXPATHLEN) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Full extraction path exceed MAXPATHLEN (%i)", MAXPATHLEN);
efree(file_dirname_fullpath);
2014-08-25 17:24:55 +00:00
zend_string_release(file_basename);
2013-12-30 07:47:16 +00:00
CWD_STATE_FREE(new_state.cwd);
return 0;
}
/* check again the full path, not sure if it
* is required, does a file can have a different
* safemode status as its parent folder?
*/
if (ZIP_OPENBASEDIR_CHECKPATH(fullpath)) {
efree(fullpath);
efree(file_dirname_fullpath);
2014-08-25 17:24:55 +00:00
zend_string_release(file_basename);
2013-12-30 07:47:16 +00:00
CWD_STATE_FREE(new_state.cwd);
return 0;
}
stream = php_stream_open_wrapper(fullpath, "w+b", REPORT_ERRORS, NULL);
if (stream == NULL) {
n = -1;
goto done;
}
zf = zip_fopen(za, file, 0);
if (zf == NULL) {
n = -1;
php_stream_close(stream);
goto done;
}
n = 0;
while ((n=zip_fread(zf, b, sizeof(b))) > 0) {
php_stream_write(stream, b, n);
}
php_stream_close(stream);
n = zip_fclose(zf);
done:
efree(fullpath);
2014-08-25 17:24:55 +00:00
zend_string_release(file_basename);
efree(file_dirname_fullpath);
2013-12-30 07:47:16 +00:00
CWD_STATE_FREE(new_state.cwd);
if (n<0) {
return 0;
} else {
return 1;
}
}
/* }}} */
static int php_zip_add_file(struct zip *za, const char *filename, size_t filename_len,
2014-12-13 22:06:14 +00:00
char *entry_name, size_t entry_name_len, long offset_start, long offset_len) /* {{{ */
2008-05-21 09:27:41 +00:00
{
struct zip_source *zs;
char resolved_path[MAXPATHLEN];
zval exists_flag;
2008-05-21 09:27:41 +00:00
if (ZIP_OPENBASEDIR_CHECKPATH(filename)) {
2008-05-21 09:27:41 +00:00
return -1;
}
2014-12-13 22:06:14 +00:00
if (!expand_filepath(filename, resolved_path)) {
2008-05-21 09:27:41 +00:00
return -1;
}
2014-12-13 22:06:14 +00:00
php_stat(resolved_path, strlen(resolved_path), FS_EXISTS, &exists_flag);
2014-05-05 02:49:27 +00:00
if (Z_TYPE(exists_flag) == IS_FALSE) {
return -1;
2008-05-21 09:27:41 +00:00
}
zs = zip_source_file(za, resolved_path, offset_start, offset_len);
if (!zs) {
return -1;
}
if (zip_file_add(za, entry_name, zs, ZIP_FL_OVERWRITE) < 0) {
zip_source_free(zs);
2008-05-21 09:27:41 +00:00
return -1;
} else {
zip_error_clear(za);
2008-05-21 09:27:41 +00:00
return 1;
}
}
/* }}} */
2014-12-13 22:06:14 +00:00
static int php_zip_parse_options(zval *options, zend_long *remove_all_path, char **remove_path, size_t *remove_path_len, char **add_path, size_t *add_path_len) /* {{{ */
2008-05-21 09:27:41 +00:00
{
2014-05-05 02:49:27 +00:00
zval *option;
if ((option = zend_hash_str_find(HASH_OF(options), "remove_all_path", sizeof("remove_all_path") - 1)) != NULL) {
2014-08-25 17:24:55 +00:00
zend_long opt;
if (Z_TYPE_P(option) != IS_LONG) {
2014-05-05 02:49:27 +00:00
zval tmp;
ZVAL_DUP(&tmp, option);
2014-08-25 19:51:49 +00:00
convert_to_long(&tmp);
2014-08-25 17:24:55 +00:00
opt = Z_LVAL(tmp);
2008-05-21 09:27:41 +00:00
} else {
2014-08-25 17:24:55 +00:00
opt = Z_LVAL_P(option);
2008-05-21 09:27:41 +00:00
}
*remove_all_path = opt;
}
/* If I add more options, it would make sense to create a nice static struct and loop over it. */
if ((option = zend_hash_str_find(HASH_OF(options), "remove_path", sizeof("remove_path") - 1)) != NULL) {
2014-05-05 02:49:27 +00:00
if (Z_TYPE_P(option) != IS_STRING) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "remove_path option expected to be a string");
2008-05-21 09:27:41 +00:00
return -1;
}
2014-08-25 17:24:55 +00:00
if (Z_STRLEN_P(option) < 1) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_NOTICE, "Empty string given as remove_path option");
2008-05-21 09:27:41 +00:00
return -1;
}
2014-08-25 17:24:55 +00:00
if (Z_STRLEN_P(option) >= MAXPATHLEN) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "remove_path string is too long (max: %i, %i given)",
2014-08-25 17:24:55 +00:00
MAXPATHLEN - 1, Z_STRLEN_P(option));
2008-05-21 09:27:41 +00:00
return -1;
}
2014-08-25 17:24:55 +00:00
*remove_path_len = Z_STRLEN_P(option);
2014-05-05 02:49:27 +00:00
*remove_path = Z_STRVAL_P(option);
2008-05-21 09:27:41 +00:00
}
2014-05-05 02:49:27 +00:00
if ((option = zend_hash_str_find(HASH_OF(options), "add_path", sizeof("add_path") - 1)) != NULL) {
if (Z_TYPE_P(option) != IS_STRING) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "add_path option expected to be a string");
2008-05-21 09:27:41 +00:00
return -1;
}
2014-08-25 17:24:55 +00:00
if (Z_STRLEN_P(option) < 1) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_NOTICE, "Empty string given as the add_path option");
2008-05-21 09:27:41 +00:00
return -1;
}
2014-08-25 17:24:55 +00:00
if (Z_STRLEN_P(option) >= MAXPATHLEN) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "add_path string too long (max: %i, %i given)",
2014-08-25 17:24:55 +00:00
MAXPATHLEN - 1, Z_STRLEN_P(option));
2008-05-21 09:27:41 +00:00
return -1;
}
2014-08-25 17:24:55 +00:00
*add_path_len = Z_STRLEN_P(option);
2014-05-05 02:49:27 +00:00
*add_path = Z_STRVAL_P(option);
2008-05-21 09:27:41 +00:00
}
return 1;
}
/* }}} */
2014-08-25 17:24:55 +00:00
/* {{{ REGISTER_ZIP_CLASS_CONST_LONG */
#define REGISTER_ZIP_CLASS_CONST_LONG(const_name, value) \
2014-12-13 22:06:14 +00:00
zend_declare_class_constant_long(zip_class_entry, const_name, sizeof(const_name)-1, (zend_long)value);
/* }}} */
/* {{{ ZIP_FROM_OBJECT */
#define ZIP_FROM_OBJECT(intern, object) \
{ \
2014-05-05 02:49:27 +00:00
ze_zip_object *obj = Z_ZIP_P(object); \
intern = obj->za; \
if (!intern) { \
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Invalid or uninitialized Zip object"); \
RETURN_FALSE; \
} \
}
/* }}} */
/* {{{ RETURN_SB(sb) */
#define RETURN_SB(sb) \
{ \
array_init(return_value); \
2014-04-15 11:40:40 +00:00
add_ascii_assoc_string(return_value, "name", (char *)(sb)->name); \
2014-08-26 09:23:25 +00:00
add_ascii_assoc_long(return_value, "index", (zend_long) (sb)->index); \
add_ascii_assoc_long(return_value, "crc", (zend_long) (sb)->crc); \
add_ascii_assoc_long(return_value, "size", (zend_long) (sb)->size); \
add_ascii_assoc_long(return_value, "mtime", (zend_long) (sb)->mtime); \
add_ascii_assoc_long(return_value, "comp_size", (zend_long) (sb)->comp_size); \
add_ascii_assoc_long(return_value, "comp_method", (zend_long) (sb)->comp_method); \
}
/* }}} */
2014-12-13 22:06:14 +00:00
static int php_zip_status(struct zip *za) /* {{{ */
{
int zep, syp;
zip_error_get(za, &zep, &syp);
return zep;
}
/* }}} */
2014-12-13 22:06:14 +00:00
static int php_zip_status_sys(struct zip *za) /* {{{ */
{
int zep, syp;
zip_error_get(za, &zep, &syp);
return syp;
}
/* }}} */
2014-12-13 22:06:14 +00:00
static int php_zip_get_num_files(struct zip *za) /* {{{ */
{
return zip_get_num_files(za);
}
/* }}} */
2014-12-13 22:06:14 +00:00
static char * php_zipobj_get_filename(ze_zip_object *obj) /* {{{ */
{
2009-01-02 00:10:20 +00:00
if (!obj) {
return NULL;
}
if (obj->filename) {
return obj->filename;
}
return NULL;
}
/* }}} */
2014-12-13 22:06:14 +00:00
static char * php_zipobj_get_zip_comment(struct zip *za, int *len) /* {{{ */
{
if (za) {
return (char *)zip_get_archive_comment(za, len, 0);
}
return NULL;
}
/* }}} */
2008-05-21 09:27:41 +00:00
#ifdef HAVE_GLOB /* {{{ */
#ifndef GLOB_ONLYDIR
#define GLOB_ONLYDIR (1<<30)
#define GLOB_EMULATE_ONLYDIR
#define GLOB_FLAGMASK (~GLOB_ONLYDIR)
#else
#define GLOB_FLAGMASK (~0)
#endif
#ifndef GLOB_BRACE
# define GLOB_BRACE 0
#endif
#ifndef GLOB_MARK
# define GLOB_MARK 0
#endif
#ifndef GLOB_NOSORT
# define GLOB_NOSORT 0
#endif
#ifndef GLOB_NOCHECK
# define GLOB_NOCHECK 0
#endif
#ifndef GLOB_NOESCAPE
# define GLOB_NOESCAPE 0
#endif
#ifndef GLOB_ERR
# define GLOB_ERR 0
#endif
/* This is used for checking validity of passed flags (passing invalid flags causes segfault in glob()!! */
#define GLOB_AVAILABLE_FLAGS (0 | GLOB_BRACE | GLOB_MARK | GLOB_NOSORT | GLOB_NOCHECK | GLOB_NOESCAPE | GLOB_ERR | GLOB_ONLYDIR)
2008-05-21 09:27:41 +00:00
#endif /* }}} */
2014-12-13 22:06:14 +00:00
int php_zip_glob(char *pattern, int pattern_len, zend_long flags, zval *return_value) /* {{{ */
2008-05-21 09:27:41 +00:00
{
#ifdef HAVE_GLOB
2008-05-21 09:27:41 +00:00
char cwd[MAXPATHLEN];
int cwd_skip = 0;
#ifdef ZTS
char work_pattern[MAXPATHLEN];
char *result;
#endif
glob_t globbuf;
int n;
int ret;
if (pattern_len >= MAXPATHLEN) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Pattern exceeds the maximum allowed length of %d characters", MAXPATHLEN);
return -1;
}
if ((GLOB_AVAILABLE_FLAGS & flags) != flags) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "At least one of the passed flags is invalid or not supported on this platform");
return -1;
}
2008-05-21 09:27:41 +00:00
#ifdef ZTS
2008-05-21 09:27:41 +00:00
if (!IS_ABSOLUTE_PATH(pattern, pattern_len)) {
result = VCWD_GETCWD(cwd, MAXPATHLEN);
2008-05-21 09:27:41 +00:00
if (!result) {
cwd[0] = '\0';
}
#ifdef PHP_WIN32
if (IS_SLASH(*pattern)) {
cwd[2] = '\0';
}
#endif
cwd_skip = strlen(cwd)+1;
snprintf(work_pattern, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, pattern);
pattern = work_pattern;
}
2008-05-21 09:27:41 +00:00
#endif
globbuf.gl_offs = 0;
if (0 != (ret = glob(pattern, flags & GLOB_FLAGMASK, NULL, &globbuf))) {
#ifdef GLOB_NOMATCH
if (GLOB_NOMATCH == ret) {
/* Some glob implementation simply return no data if no matches
were found, others return the GLOB_NOMATCH error code.
We don't want to treat GLOB_NOMATCH as an error condition
so that PHP glob() behaves the same on both types of
2008-05-21 09:27:41 +00:00
implementations and so that 'foreach (glob() as ...'
can be used for simple glob() calls without further error
checking.
*/
array_init(return_value);
return 0;
}
#endif
return 0;
}
/* now catch the FreeBSD style of "no matches" */
if (!globbuf.gl_pathc || !globbuf.gl_pathv) {
array_init(return_value);
return 0;
}
/* we assume that any glob pattern will match files from one directory only
so checking the dirname of the first match should be sufficient */
strncpy(cwd, globbuf.gl_pathv[0], MAXPATHLEN);
if (ZIP_OPENBASEDIR_CHECKPATH(cwd)) {
2008-05-21 09:27:41 +00:00
return -1;
}
array_init(return_value);
for (n = 0; n < globbuf.gl_pathc; n++) {
/* we need to do this every time since GLOB_ONLYDIR does not guarantee that
2008-05-21 09:27:41 +00:00
* all directories will be filtered. GNU libc documentation states the
* following:
* If the information about the type of the file is easily available
* non-directories will be rejected but no extra work will be done to
* determine the information for each file. I.e., the caller must still be
* able to filter directories out.
2008-05-21 09:27:41 +00:00
*/
if (flags & GLOB_ONLYDIR) {
2014-08-19 09:47:21 +00:00
zend_stat_t s;
2008-05-21 09:27:41 +00:00
if (0 != VCWD_STAT(globbuf.gl_pathv[n], &s)) {
continue;
}
if (S_IFDIR != (s.st_mode & S_IFMT)) {
continue;
}
}
2014-04-15 11:40:40 +00:00
add_next_index_string(return_value, globbuf.gl_pathv[n]+cwd_skip);
2008-05-21 09:27:41 +00:00
}
globfree(&globbuf);
return globbuf.gl_pathc;
#else
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_ERROR, "Glob support is not available");
return 0;
#endif /* HAVE_GLOB */
2008-05-21 09:27:41 +00:00
}
/* }}} */
2014-12-13 22:06:14 +00:00
int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_value) /* {{{ */
2008-05-21 09:27:41 +00:00
{
2008-08-08 10:12:27 +00:00
#ifdef ZTS
2008-05-21 09:27:41 +00:00
char cwd[MAXPATHLEN];
int cwd_skip = 0;
char work_path[MAXPATHLEN];
char *result;
#endif
int files_cnt;
2014-05-05 02:49:27 +00:00
zend_string **namelist;
2008-05-21 09:27:41 +00:00
#ifdef ZTS
2008-05-21 09:27:41 +00:00
if (!IS_ABSOLUTE_PATH(path, path_len)) {
result = VCWD_GETCWD(cwd, MAXPATHLEN);
2008-05-21 09:27:41 +00:00
if (!result) {
cwd[0] = '\0';
}
#ifdef PHP_WIN32
if (IS_SLASH(*path)) {
cwd[2] = '\0';
}
#endif
cwd_skip = strlen(cwd)+1;
snprintf(work_path, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, path);
path = work_path;
}
2008-05-21 09:27:41 +00:00
#endif
if (ZIP_OPENBASEDIR_CHECKPATH(path)) {
2008-05-21 09:27:41 +00:00
return -1;
}
2008-05-21 09:27:41 +00:00
files_cnt = php_stream_scandir(path, &namelist, NULL, (void *) php_stream_dirent_alphasort);
if (files_cnt > 0) {
2014-05-05 02:49:27 +00:00
pcre *re = NULL;
2008-05-21 09:27:41 +00:00
pcre_extra *pcre_extra = NULL;
int preg_options = 0, i;
2014-12-13 22:06:14 +00:00
re = pcre_get_compiled_regex(regexp, &pcre_extra, &preg_options);
2008-05-21 09:27:41 +00:00
if (!re) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Invalid expression");
return -1;
2008-05-21 09:27:41 +00:00
}
array_init(return_value);
/* only the files, directories are ignored */
for (i = 0; i < files_cnt; i++) {
2014-08-19 09:47:21 +00:00
zend_stat_t s;
2008-05-21 09:27:41 +00:00
char fullpath[MAXPATHLEN];
int ovector[3];
int matches;
2014-05-05 02:49:27 +00:00
int namelist_len = namelist[i]->len;
2008-05-21 09:27:41 +00:00
2014-05-05 02:49:27 +00:00
if ((namelist_len == 1 && namelist[i]->val[0] == '.') ||
(namelist_len == 2 && namelist[i]->val[0] == '.' && namelist[i]->val[1] == '.')) {
2014-08-25 17:24:55 +00:00
zend_string_release(namelist[i]);
2008-05-21 09:27:41 +00:00
continue;
}
if ((path_len + namelist_len + 1) >= MAXPATHLEN) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "add_path string too long (max: %i, %i given)",
2008-05-21 09:27:41 +00:00
MAXPATHLEN - 1, (path_len + namelist_len + 1));
2014-08-25 17:24:55 +00:00
zend_string_release(namelist[i]);
2008-05-21 09:27:41 +00:00
break;
}
2014-05-05 02:49:27 +00:00
snprintf(fullpath, MAXPATHLEN, "%s%c%s", path, DEFAULT_SLASH, namelist[i]->val);
2008-05-21 09:27:41 +00:00
if (0 != VCWD_STAT(fullpath, &s)) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Cannot read <%s>", fullpath);
2014-08-25 17:24:55 +00:00
zend_string_release(namelist[i]);
2008-05-21 09:27:41 +00:00
continue;
}
if (S_IFDIR == (s.st_mode & S_IFMT)) {
2014-08-25 17:24:55 +00:00
zend_string_release(namelist[i]);
2008-05-21 09:27:41 +00:00
continue;
}
2014-05-05 02:49:27 +00:00
matches = pcre_exec(re, NULL, namelist[i]->val, namelist[i]->len, 0, 0, ovector, 3);
2008-05-21 09:27:41 +00:00
/* 0 means that the vector is too small to hold all the captured substring offsets */
if (matches < 0) {
2014-08-25 17:24:55 +00:00
zend_string_release(namelist[i]);
continue;
2008-05-21 09:27:41 +00:00
}
2014-04-15 11:40:40 +00:00
add_next_index_string(return_value, fullpath);
2014-08-25 17:24:55 +00:00
zend_string_release(namelist[i]);
2008-05-21 09:27:41 +00:00
}
efree(namelist);
}
return files_cnt;
}
/* }}} */
2008-07-03 01:55:48 +00:00
/* {{{ arginfo */
ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_open, 0, 0, 1)
ZEND_ARG_INFO(0, filename)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_close, 0, 0, 1)
ZEND_ARG_INFO(0, zip)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_read, 0, 0, 1)
ZEND_ARG_INFO(0, zip)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_open, 0, 0, 2)
ZEND_ARG_INFO(0, zip_dp)
ZEND_ARG_INFO(0, zip_entry)
ZEND_ARG_INFO(0, mode)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_close, 0, 0, 1)
ZEND_ARG_INFO(0, zip_ent)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_read, 0, 0, 1)
ZEND_ARG_INFO(0, zip_entry)
ZEND_ARG_INFO(0, len)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_name, 0, 0, 1)
ZEND_ARG_INFO(0, zip_entry)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_compressedsize, 0, 0, 1)
ZEND_ARG_INFO(0, zip_entry)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_filesize, 0, 0, 1)
ZEND_ARG_INFO(0, zip_entry)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_compressionmethod, 0, 0, 1)
ZEND_ARG_INFO(0, zip_entry)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ zend_function_entry */
static const zend_function_entry zip_functions[] = {
2008-07-03 01:55:48 +00:00
ZEND_RAW_FENTRY("zip_open", zif_zip_open, arginfo_zip_open, 0)
ZEND_RAW_FENTRY("zip_close", zif_zip_close, arginfo_zip_close, 0)
ZEND_RAW_FENTRY("zip_read", zif_zip_read, arginfo_zip_read, 0)
PHP_FE(zip_entry_open, arginfo_zip_entry_open)
PHP_FE(zip_entry_close, arginfo_zip_entry_close)
PHP_FE(zip_entry_read, arginfo_zip_entry_read)
PHP_FE(zip_entry_filesize, arginfo_zip_entry_filesize)
PHP_FE(zip_entry_name, arginfo_zip_entry_name)
PHP_FE(zip_entry_compressedsize, arginfo_zip_entry_compressedsize)
PHP_FE(zip_entry_compressionmethod, arginfo_zip_entry_compressionmethod)
#ifdef PHP_FE_END
2011-07-25 11:35:02 +00:00
PHP_FE_END
#else
{NULL,NULL,NULL}
#endif
};
/* }}} */
/* {{{ ZE2 OO definitions */
static zend_class_entry *zip_class_entry;
static zend_object_handlers zip_object_handlers;
static HashTable zip_prop_handlers;
2014-12-13 22:06:14 +00:00
typedef int (*zip_read_int_t)(struct zip *za);
typedef char *(*zip_read_const_char_t)(struct zip *za, int *len);
typedef char *(*zip_read_const_char_from_ze_t)(ze_zip_object *obj);
typedef struct _zip_prop_handler {
zip_read_int_t read_int_func;
zip_read_const_char_t read_const_char_func;
zip_read_const_char_from_ze_t read_const_char_from_obj_func;
int type;
} zip_prop_handler;
/* }}} */
2014-12-13 22:06:14 +00:00
static void php_zip_register_prop_handler(HashTable *prop_handler, char *name, zip_read_int_t read_int_func, zip_read_const_char_t read_char_func, zip_read_const_char_from_ze_t read_char_from_obj_func, int rettype) /* {{{ */
{
zip_prop_handler hnd;
hnd.read_const_char_func = read_char_func;
hnd.read_int_func = read_int_func;
hnd.read_const_char_from_obj_func = read_char_from_obj_func;
hnd.type = rettype;
2014-05-05 02:49:27 +00:00
zend_hash_str_add_mem(prop_handler, name, strlen(name), &hnd, sizeof(zip_prop_handler));
}
/* }}} */
2014-12-13 22:06:14 +00:00
static zval *php_zip_property_reader(ze_zip_object *obj, zip_prop_handler *hnd, zval *rv) /* {{{ */
{
const char *retchar = NULL;
int retint = 0;
int len = 0;
if (obj && obj->za != NULL) {
if (hnd->read_const_char_func) {
2014-12-13 22:06:14 +00:00
retchar = hnd->read_const_char_func(obj->za, &len);
} else {
if (hnd->read_int_func) {
2014-12-13 22:06:14 +00:00
retint = hnd->read_int_func(obj->za);
if (retint == -1) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Internal zip error returned");
2014-05-05 02:49:27 +00:00
return NULL;
}
} else {
if (hnd->read_const_char_from_obj_func) {
2014-12-13 22:06:14 +00:00
retchar = hnd->read_const_char_from_obj_func(obj);
2009-02-24 23:55:14 +00:00
len = strlen(retchar);
}
}
}
}
switch (hnd->type) {
case IS_STRING:
if (retchar) {
2014-05-05 02:49:27 +00:00
ZVAL_STRINGL(rv, (char *) retchar, len);
} else {
2014-05-05 02:49:27 +00:00
ZVAL_EMPTY_STRING(rv);
}
break;
2014-05-05 02:49:27 +00:00
/* case IS_TRUE */
case IS_FALSE:
ZVAL_BOOL(rv, (long)retint);
break;
2014-08-25 17:24:55 +00:00
case IS_LONG:
ZVAL_LONG(rv, (long)retint);
break;
default:
2014-05-05 02:49:27 +00:00
ZVAL_NULL(rv);
}
2014-05-05 02:49:27 +00:00
return rv;
}
/* }}} */
2014-12-13 22:06:14 +00:00
static zval *php_zip_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot) /* {{{ */
{
ze_zip_object *obj;
zval tmp_member;
2014-05-05 02:49:27 +00:00
zval *retval = NULL;
zip_prop_handler *hnd = NULL;
zend_object_handlers *std_hnd;
2014-05-05 02:49:27 +00:00
if (Z_TYPE_P(member) != IS_STRING) {
ZVAL_DUP(&tmp_member, member);
convert_to_string(&tmp_member);
member = &tmp_member;
cache_slot = NULL;
}
2014-05-05 02:49:27 +00:00
obj = Z_ZIP_P(object);
if (obj->prop_handler != NULL) {
2014-05-05 02:49:27 +00:00
hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member));
}
2014-05-05 02:49:27 +00:00
if (hnd == NULL) {
std_hnd = zend_get_std_object_handlers();
2014-12-13 22:06:14 +00:00
retval = std_hnd->get_property_ptr_ptr(object, member, type, cache_slot);
}
if (member == &tmp_member) {
zval_dtor(member);
}
2014-05-05 02:49:27 +00:00
return retval;
}
/* }}} */
2014-12-13 22:06:14 +00:00
static zval *php_zip_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv) /* {{{ */
{
ze_zip_object *obj;
zval tmp_member;
2014-05-05 02:49:27 +00:00
zval *retval = NULL;
zip_prop_handler *hnd = NULL;
zend_object_handlers *std_hnd;
2014-05-05 02:49:27 +00:00
if (Z_TYPE_P(member) != IS_STRING) {
ZVAL_DUP(&tmp_member, member);
convert_to_string(&tmp_member);
member = &tmp_member;
cache_slot = NULL;
}
2014-05-05 02:49:27 +00:00
obj = Z_ZIP_P(object);
if (obj->prop_handler != NULL) {
2014-05-05 02:49:27 +00:00
hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member));
}
2014-05-05 02:49:27 +00:00
if (hnd != NULL) {
2014-12-13 22:06:14 +00:00
retval = php_zip_property_reader(obj, hnd, rv);
2014-05-05 02:49:27 +00:00
if (retval == NULL) {
retval = &EG(uninitialized_zval);
}
} else {
std_hnd = zend_get_std_object_handlers();
2014-12-13 22:06:14 +00:00
retval = std_hnd->read_property(object, member, type, cache_slot, rv);
}
if (member == &tmp_member) {
zval_dtor(member);
}
2014-05-05 02:49:27 +00:00
return retval;
}
/* }}} */
2014-12-13 22:06:14 +00:00
static int php_zip_has_property(zval *object, zval *member, int type, void **cache_slot) /* {{{ */
{
ze_zip_object *obj;
zval tmp_member;
2014-05-05 02:49:27 +00:00
zip_prop_handler *hnd = NULL;
zend_object_handlers *std_hnd;
2014-05-05 02:49:27 +00:00
int retval = 0;
2014-05-05 02:49:27 +00:00
if (Z_TYPE_P(member) != IS_STRING) {
ZVAL_DUP(&tmp_member, member);
convert_to_string(&tmp_member);
member = &tmp_member;
cache_slot = NULL;
}
2014-05-05 02:49:27 +00:00
obj = Z_ZIP_P(object);
if (obj->prop_handler != NULL) {
2014-05-05 02:49:27 +00:00
hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member));
}
2014-05-05 02:49:27 +00:00
if (hnd != NULL) {
zval tmp, *prop;
if (type == 2) {
retval = 1;
2014-12-13 22:06:14 +00:00
} else if ((prop = php_zip_property_reader(obj, hnd, &tmp)) != NULL) {
if (type == 1) {
2014-12-13 22:06:14 +00:00
retval = zend_is_true(&tmp);
} else if (type == 0) {
2014-05-05 02:49:27 +00:00
retval = (Z_TYPE(tmp) != IS_NULL);
}
}
zval_ptr_dtor(&tmp);
} else {
std_hnd = zend_get_std_object_handlers();
2014-12-13 22:06:14 +00:00
retval = std_hnd->has_property(object, member, type, cache_slot);
}
if (member == &tmp_member) {
zval_dtor(member);
}
2014-05-05 02:49:27 +00:00
return retval;
}
/* }}} */
2014-12-13 22:06:14 +00:00
static HashTable *php_zip_get_properties(zval *object)/* {{{ */
{
ze_zip_object *obj;
HashTable *props;
2014-05-05 02:49:27 +00:00
zip_prop_handler *hnd;
zend_string *key;
2014-09-12 14:22:42 +00:00
zend_ulong num_key;
2014-05-05 02:49:27 +00:00
obj = Z_ZIP_P(object);
2014-12-13 22:06:14 +00:00
props = zend_std_get_properties(object);
if (obj->prop_handler == NULL) {
return NULL;
}
2014-05-05 02:49:27 +00:00
ZEND_HASH_FOREACH_KEY_PTR(obj->prop_handler, num_key, key, hnd) {
zval *ret, val;
2014-12-13 22:06:14 +00:00
ret = php_zip_property_reader(obj, hnd, &val);
2014-05-05 02:49:27 +00:00
if (ret == NULL) {
ret = &EG(uninitialized_zval);
}
2014-05-05 02:49:27 +00:00
zend_hash_update(props, key, ret);
} ZEND_HASH_FOREACH_END();
return props;
}
/* }}} */
2014-12-13 22:06:14 +00:00
static void php_zip_object_free_storage(zend_object *object) /* {{{ */
{
2014-05-05 02:49:27 +00:00
ze_zip_object * intern = php_zip_fetch_object(object);
int i;
if (!intern) {
return;
}
if (intern->za) {
if (zip_close(intern->za) != 0) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context");
return;
}
intern->za = NULL;
}
if (intern->buffers_cnt>0) {
for (i=0; i<intern->buffers_cnt; i++) {
efree(intern->buffers[i]);
}
efree(intern->buffers);
}
intern->za = NULL;
2014-12-13 22:06:14 +00:00
zend_object_std_dtor(&intern->zo);
if (intern->filename) {
efree(intern->filename);
}
}
/* }}} */
2014-12-13 22:06:14 +00:00
static zend_object *php_zip_object_new(zend_class_entry *class_type) /* {{{ */
{
ze_zip_object *intern;
2014-05-05 02:49:27 +00:00
intern = ecalloc(1, sizeof(ze_zip_object) + sizeof(zval) * (class_type->default_properties_count - 1));
intern->prop_handler = &zip_prop_handlers;
2014-12-13 22:06:14 +00:00
zend_object_std_init(&intern->zo, class_type);
object_properties_init(&intern->zo, class_type);
2014-05-05 02:49:27 +00:00
intern->zo.handlers = &zip_object_handlers;
2014-05-05 02:49:27 +00:00
return &intern->zo;
}
/* }}} */
/* {{{ Resource dtors */
/* {{{ php_zip_free_dir */
2014-12-13 22:06:14 +00:00
static void php_zip_free_dir(zend_resource *rsrc)
{
zip_rsrc * zip_int = (zip_rsrc *) rsrc->ptr;
if (zip_int) {
if (zip_int->za) {
if (zip_close(zip_int->za) != 0) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context");
}
zip_int->za = NULL;
}
efree(rsrc->ptr);
rsrc->ptr = NULL;
}
}
/* }}} */
/* {{{ php_zip_free_entry */
2014-12-13 22:06:14 +00:00
static void php_zip_free_entry(zend_resource *rsrc)
{
zip_read_rsrc *zr_rsrc = (zip_read_rsrc *) rsrc->ptr;
if (zr_rsrc) {
if (zr_rsrc->zf) {
zip_fclose(zr_rsrc->zf);
zr_rsrc->zf = NULL;
}
efree(zr_rsrc);
rsrc->ptr = NULL;
}
}
/* }}} */
/* }}}*/
/* reset macro */
2008-05-21 09:27:41 +00:00
/* {{{ function prototypes */
static PHP_MINIT_FUNCTION(zip);
static PHP_MSHUTDOWN_FUNCTION(zip);
static PHP_MINFO_FUNCTION(zip);
/* }}} */
/* {{{ zip_module_entry
*/
zend_module_entry zip_module_entry = {
STANDARD_MODULE_HEADER,
"zip",
zip_functions,
PHP_MINIT(zip),
PHP_MSHUTDOWN(zip),
NULL,
NULL,
PHP_MINFO(zip),
PHP_ZIP_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_ZIP
ZEND_GET_MODULE(zip)
#endif
/* set macro */
/* {{{ proto resource zip_open(string filename)
Create new zip using source uri for output */
static PHP_NAMED_FUNCTION(zif_zip_open)
{
char resolved_path[MAXPATHLEN + 1];
zip_rsrc *rsrc_int;
int err = 0;
2014-05-05 02:49:27 +00:00
zend_string *filename;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &filename) == FAILURE) {
return;
}
2014-05-05 02:49:27 +00:00
if (filename->len == 0) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Empty string as source");
RETURN_FALSE;
}
2014-05-05 02:49:27 +00:00
if (ZIP_OPENBASEDIR_CHECKPATH(filename->val)) {
RETURN_FALSE;
}
2014-12-13 22:06:14 +00:00
if(!expand_filepath(filename->val, resolved_path)) {
RETURN_FALSE;
}
rsrc_int = (zip_rsrc *)emalloc(sizeof(zip_rsrc));
rsrc_int->za = zip_open(resolved_path, 0, &err);
if (rsrc_int->za == NULL) {
efree(rsrc_int);
2014-08-26 09:23:25 +00:00
RETURN_LONG((zend_long)err);
}
rsrc_int->index_current = 0;
rsrc_int->num_files = zip_get_num_files(rsrc_int->za);
ZEND_REGISTER_RESOURCE(return_value, rsrc_int, le_zip_dir);
}
/* }}} */
/* {{{ proto void zip_close(resource zip)
Close a Zip archive */
static PHP_NAMED_FUNCTION(zif_zip_close)
{
zval * zip;
zip_rsrc *z_rsrc = NULL;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zip) == FAILURE) {
return;
}
2014-05-05 02:49:27 +00:00
ZEND_FETCH_RESOURCE(z_rsrc, zip_rsrc *, zip, -1, le_zip_dir_name, le_zip_dir);
/* really close the zip will break BC :-D */
2014-05-05 02:49:27 +00:00
zend_list_close(Z_RES_P(zip));
}
/* }}} */
/* {{{ proto resource zip_read(resource zip)
Returns the next file in the archive */
static PHP_NAMED_FUNCTION(zif_zip_read)
{
zval *zip_dp;
zip_read_rsrc *zr_rsrc;
int ret;
zip_rsrc *rsrc_int;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zip_dp) == FAILURE) {
return;
}
2014-05-05 02:49:27 +00:00
ZEND_FETCH_RESOURCE(rsrc_int, zip_rsrc *, zip_dp, -1, le_zip_dir_name, le_zip_dir);
if (rsrc_int && rsrc_int->za) {
if (rsrc_int->index_current >= rsrc_int->num_files) {
RETURN_FALSE;
}
zr_rsrc = emalloc(sizeof(zip_read_rsrc));
ret = zip_stat_index(rsrc_int->za, rsrc_int->index_current, 0, &zr_rsrc->sb);
if (ret != 0) {
efree(zr_rsrc);
RETURN_FALSE;
}
zr_rsrc->zf = zip_fopen_index(rsrc_int->za, rsrc_int->index_current, 0);
if (zr_rsrc->zf) {
rsrc_int->index_current++;
ZEND_REGISTER_RESOURCE(return_value, zr_rsrc, le_zip_entry);
} else {
efree(zr_rsrc);
RETURN_FALSE;
}
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool zip_entry_open(resource zip_dp, resource zip_entry [, string mode])
Open a Zip File, pointed by the resource entry */
/* Dummy function to follow the old API */
static PHP_NAMED_FUNCTION(zif_zip_entry_open)
{
zval * zip;
zval * zip_entry;
2008-10-21 23:39:15 +00:00
char *mode = NULL;
size_t mode_len = 0;
zip_read_rsrc * zr_rsrc;
zip_rsrc *z_rsrc;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rr|s", &zip, &zip_entry, &mode, &mode_len) == FAILURE) {
return;
}
2014-05-05 02:49:27 +00:00
ZEND_FETCH_RESOURCE(zr_rsrc, zip_read_rsrc *, zip_entry, -1, le_zip_entry_name, le_zip_entry);
ZEND_FETCH_RESOURCE(z_rsrc, zip_rsrc *, zip, -1, le_zip_dir_name, le_zip_dir);
if (zr_rsrc->zf != NULL) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
2012-06-05 20:49:31 +00:00
/* {{{ proto bool zip_entry_close(resource zip_ent)
Close a zip entry */
static PHP_NAMED_FUNCTION(zif_zip_entry_close)
{
zval * zip_entry;
zip_read_rsrc * zr_rsrc;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zip_entry) == FAILURE) {
return;
}
2014-05-05 02:49:27 +00:00
ZEND_FETCH_RESOURCE(zr_rsrc, zip_read_rsrc *, zip_entry, -1, le_zip_entry_name, le_zip_entry);
2012-06-05 20:49:31 +00:00
2014-05-05 02:49:27 +00:00
RETURN_BOOL(SUCCESS == zend_list_close(Z_RES_P(zip_entry)));
}
/* }}} */
/* {{{ proto mixed zip_entry_read(resource zip_entry [, int len])
Read from an open directory entry */
static PHP_NAMED_FUNCTION(zif_zip_entry_read)
{
zval * zip_entry;
2014-08-25 17:24:55 +00:00
zend_long len = 0;
zip_read_rsrc * zr_rsrc;
2014-05-05 02:49:27 +00:00
zend_string *buffer;
int n = 0;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &zip_entry, &len) == FAILURE) {
return;
}
2014-05-05 02:49:27 +00:00
ZEND_FETCH_RESOURCE(zr_rsrc, zip_read_rsrc *, zip_entry, -1, le_zip_entry_name, le_zip_entry);
if (len <= 0) {
len = 1024;
}
if (zr_rsrc->zf) {
2014-08-25 17:24:55 +00:00
buffer = zend_string_alloc(len, 0);
2014-05-05 02:49:27 +00:00
n = zip_fread(zr_rsrc->zf, buffer->val, buffer->len);
if (n > 0) {
2014-05-05 02:49:27 +00:00
buffer->val[n] = '\0';
buffer->len = n;
RETURN_STR(buffer);
} else {
2014-08-25 17:24:55 +00:00
zend_string_free(buffer);
RETURN_EMPTY_STRING()
}
} else {
RETURN_FALSE;
}
}
/* }}} */
static void php_zip_entry_get_info(INTERNAL_FUNCTION_PARAMETERS, int opt) /* {{{ */
{
zval * zip_entry;
zip_read_rsrc * zr_rsrc;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zip_entry) == FAILURE) {
return;
}
2014-05-05 02:49:27 +00:00
ZEND_FETCH_RESOURCE(zr_rsrc, zip_read_rsrc *, zip_entry, -1, le_zip_entry_name, le_zip_entry);
if (!zr_rsrc->zf) {
RETURN_FALSE;
}
switch (opt) {
case 0:
2014-05-05 02:49:27 +00:00
RETURN_STRING((char *)zr_rsrc->sb.name);
break;
case 1:
2014-08-25 17:24:55 +00:00
RETURN_LONG((zend_long) (zr_rsrc->sb.comp_size));
break;
case 2:
2014-08-25 17:24:55 +00:00
RETURN_LONG((zend_long) (zr_rsrc->sb.size));
break;
case 3:
switch (zr_rsrc->sb.comp_method) {
case 0:
2014-05-05 02:49:27 +00:00
RETURN_STRING("stored");
break;
case 1:
2014-05-05 02:49:27 +00:00
RETURN_STRING("shrunk");
break;
case 2:
case 3:
case 4:
case 5:
2014-05-05 02:49:27 +00:00
RETURN_STRING("reduced");
break;
case 6:
2014-05-05 02:49:27 +00:00
RETURN_STRING("imploded");
break;
case 7:
2014-05-05 02:49:27 +00:00
RETURN_STRING("tokenized");
break;
case 8:
2014-05-05 02:49:27 +00:00
RETURN_STRING("deflated");
break;
case 9:
2014-05-05 02:49:27 +00:00
RETURN_STRING("deflatedX");
break;
case 10:
2014-05-05 02:49:27 +00:00
RETURN_STRING("implodedX");
break;
default:
RETURN_FALSE;
}
2014-08-25 17:24:55 +00:00
RETURN_LONG((zend_long) (zr_rsrc->sb.comp_method));
break;
}
}
/* }}} */
/* {{{ proto string zip_entry_name(resource zip_entry)
Return the name given a ZZip entry */
static PHP_NAMED_FUNCTION(zif_zip_entry_name)
{
php_zip_entry_get_info(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */
/* {{{ proto int zip_entry_compressedsize(resource zip_entry)
Return the compressed size of a ZZip entry */
static PHP_NAMED_FUNCTION(zif_zip_entry_compressedsize)
{
php_zip_entry_get_info(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
/* }}} */
/* {{{ proto int zip_entry_filesize(resource zip_entry)
Return the actual filesize of a ZZip entry */
static PHP_NAMED_FUNCTION(zif_zip_entry_filesize)
{
php_zip_entry_get_info(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2);
}
/* }}} */
/* {{{ proto string zip_entry_compressionmethod(resource zip_entry)
Return a string containing the compression method used on a particular entry */
static PHP_NAMED_FUNCTION(zif_zip_entry_compressionmethod)
{
php_zip_entry_get_info(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3);
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto mixed ZipArchive::open(string source [, int flags])
Create new zip using source uri for output, return TRUE on success or the error code */
static ZIPARCHIVE_METHOD(open)
{
struct zip *intern;
int err = 0;
2014-08-25 17:24:55 +00:00
zend_long flags = 0;
2013-12-19 09:55:26 +00:00
char *resolved_path;
2014-05-05 02:49:27 +00:00
zend_string *filename;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
ze_zip_object *ze_obj = NULL;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &filename, &flags) == FAILURE) {
return;
}
2014-05-05 02:56:18 +00:00
if (self) {
/* We do not use ZIP_FROM_OBJECT, zip init function here */
2014-05-05 02:56:18 +00:00
ze_obj = Z_ZIP_P(self);
}
2014-05-05 02:49:27 +00:00
if (filename->len == 0) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Empty string as source");
RETURN_FALSE;
}
2014-05-05 02:49:27 +00:00
if (ZIP_OPENBASEDIR_CHECKPATH(filename->val)) {
2008-08-08 15:56:44 +00:00
RETURN_FALSE;
}
2014-12-13 22:06:14 +00:00
if (!(resolved_path = expand_filepath(filename->val, NULL))) {
RETURN_FALSE;
}
if (ze_obj->za) {
/* we already have an opened zip, free it */
if (zip_close(ze_obj->za) != 0) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Empty string as source");
efree(resolved_path);
RETURN_FALSE;
}
ze_obj->za = NULL;
}
if (ze_obj->filename) {
efree(ze_obj->filename);
ze_obj->filename = NULL;
}
intern = zip_open(resolved_path, flags, &err);
if (!intern || err) {
efree(resolved_path);
2014-08-25 17:24:55 +00:00
RETURN_LONG((zend_long)err);
}
2013-12-19 09:55:26 +00:00
ze_obj->filename = resolved_path;
ze_obj->filename_len = strlen(resolved_path);
ze_obj->za = intern;
RETURN_TRUE;
}
/* }}} */
/* {{{ proto resource ZipArchive::setPassword(string password)
Set the password for the active archive */
static ZIPARCHIVE_METHOD(setPassword)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
char *password;
2014-08-27 17:25:28 +00:00
size_t password_len;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &password, &password_len) == FAILURE) {
return;
}
if (password_len < 1) {
RETURN_FALSE;
} else {
int res = zip_set_default_password(intern, (const char *)password);
if (res == 0) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto bool ZipArchive::close()
close the zip archive */
static ZIPARCHIVE_METHOD(close)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
ze_zip_object *ze_obj;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-05-05 02:56:18 +00:00
ze_obj = Z_ZIP_P(self);
if (zip_close(intern)) {
zip_discard(intern);
}
efree(ze_obj->filename);
ze_obj->filename = NULL;
ze_obj->filename_len = 0;
ze_obj->za = NULL;
RETURN_TRUE;
}
/* }}} */
2008-05-21 09:27:41 +00:00
/* {{{ proto string ZipArchive::getStatusString()
* Returns the status error message, system and/or zip messages */
static ZIPARCHIVE_METHOD(getStatusString)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2008-05-21 09:27:41 +00:00
int zep, syp, len;
char error_string[128];
2014-05-05 02:56:18 +00:00
if (!self) {
2008-05-21 09:27:41 +00:00
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2008-05-21 09:27:41 +00:00
zip_error_get(intern, &zep, &syp);
len = zip_error_to_str(error_string, 128, zep, syp);
2014-05-05 02:49:27 +00:00
RETVAL_STRINGL(error_string, len);
2008-05-21 09:27:41 +00:00
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto bool ZipArchive::createEmptyDir(string dirname)
Returns the index of the entry named filename in the archive */
static ZIPARCHIVE_METHOD(addEmptyDir)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
char *dirname;
2014-08-27 17:25:28 +00:00
size_t dirname_len;
int idx;
struct zip_stat sb;
char *s;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
2008-05-21 09:27:41 +00:00
&dirname, &dirname_len) == FAILURE) {
return;
}
if (dirname_len<1) {
RETURN_FALSE;
}
2007-06-04 06:38:22 +00:00
if (dirname[dirname_len-1] != '/') {
s=(char *)emalloc(dirname_len+2);
strcpy(s, dirname);
s[dirname_len] = '/';
s[dirname_len+1] = '\0';
2007-06-04 06:38:22 +00:00
} else {
s = dirname;
}
idx = zip_stat(intern, s, 0, &sb);
if (idx >= 0) {
RETVAL_FALSE;
} else {
if (zip_add_dir(intern, (const char *)s) == -1) {
RETVAL_FALSE;
}
zip_error_clear(intern);
2008-05-21 09:27:41 +00:00
RETVAL_TRUE;
}
if (s != dirname) {
efree(s);
}
}
/* }}} */
2008-05-21 09:27:41 +00:00
static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2008-10-21 23:39:15 +00:00
char *path = NULL;
2008-05-21 09:27:41 +00:00
char *remove_path = NULL;
char *add_path = NULL;
2014-08-27 17:25:28 +00:00
size_t add_path_len, remove_path_len = 0, path_len = 0;
2014-08-25 17:24:55 +00:00
zend_long remove_all_path = 0;
zend_long flags = 0;
2008-05-21 09:27:41 +00:00
zval *options = NULL;
int found;
2014-05-05 02:49:27 +00:00
zend_string *pattern;
2008-05-21 09:27:41 +00:00
2014-05-05 02:56:18 +00:00
if (!self) {
2008-05-21 09:27:41 +00:00
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-05-05 02:49:27 +00:00
/* 1 == glob, 2 == pcre */
2008-05-21 09:27:41 +00:00
if (type == 1) {
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|la",
2014-05-05 02:49:27 +00:00
&pattern, &flags, &options) == FAILURE) {
2008-05-21 09:27:41 +00:00
return;
}
} else {
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|sa",
2014-05-05 02:49:27 +00:00
&pattern, &path, &path_len, &options) == FAILURE) {
2008-05-21 09:27:41 +00:00
return;
}
}
2014-05-05 02:49:27 +00:00
if (pattern->len == 0) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_NOTICE, "Empty string as pattern");
2008-05-21 09:27:41 +00:00
RETURN_FALSE;
}
if (options && (php_zip_parse_options(options, &remove_all_path, &remove_path, &remove_path_len,
2014-12-13 22:06:14 +00:00
&add_path, &add_path_len) < 0)) {
2008-05-21 09:27:41 +00:00
RETURN_FALSE;
}
2014-09-14 10:59:31 +00:00
if (remove_path && remove_path_len > 1) {
2014-09-14 13:03:52 +00:00
size_t real_len = strlen(remove_path);
if (real_len > 1 && remove_path[real_len - 1] == '/' || remove_path[real_len - 1] == '\\') {
remove_path[real_len - 1] = '\0';
2014-09-14 10:59:31 +00:00
}
2008-05-21 09:27:41 +00:00
}
if (type == 1) {
2014-12-13 22:06:14 +00:00
found = php_zip_glob(pattern->val, pattern->len, flags, return_value);
2008-05-21 09:27:41 +00:00
} else {
2014-12-13 22:06:14 +00:00
found = php_zip_pcre(pattern, path, path_len, return_value);
2008-05-21 09:27:41 +00:00
}
if (found > 0) {
int i;
2014-05-05 02:49:27 +00:00
zval *zval_file;
2008-05-21 09:27:41 +00:00
for (i = 0; i < found; i++) {
char *file_stripped, *entry_name;
size_t entry_name_len, file_stripped_len;
2008-05-21 09:27:41 +00:00
char entry_name_buf[MAXPATHLEN];
2014-02-23 10:08:35 +00:00
zend_string *basename = NULL;
2008-05-21 09:27:41 +00:00
2014-05-05 02:49:27 +00:00
if ((zval_file = zend_hash_index_find(Z_ARRVAL_P(return_value), i)) != NULL) {
2008-05-21 09:27:41 +00:00
if (remove_all_path) {
2014-12-13 22:06:14 +00:00
basename = php_basename(Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file), NULL, 0);
2014-02-23 10:08:35 +00:00
file_stripped = basename->val;
file_stripped_len = basename->len;
2014-05-05 02:49:27 +00:00
} else if (remove_path && strstr(Z_STRVAL_P(zval_file), remove_path) != NULL) {
file_stripped = Z_STRVAL_P(zval_file) + remove_path_len + 1;
2014-08-25 17:24:55 +00:00
file_stripped_len = Z_STRLEN_P(zval_file) - remove_path_len - 1;
2008-05-21 09:27:41 +00:00
} else {
2014-05-05 02:49:27 +00:00
file_stripped = Z_STRVAL_P(zval_file);
2014-08-25 17:24:55 +00:00
file_stripped_len = Z_STRLEN_P(zval_file);
2008-05-21 09:27:41 +00:00
}
if (add_path) {
if ((add_path_len + file_stripped_len) > MAXPATHLEN) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Entry name too long (max: %d, %pd given)",
2008-05-21 09:27:41 +00:00
MAXPATHLEN - 1, (add_path_len + file_stripped_len));
2014-05-05 02:49:27 +00:00
zval_ptr_dtor(return_value);
2008-05-21 09:27:41 +00:00
RETURN_FALSE;
}
snprintf(entry_name_buf, MAXPATHLEN, "%s%s", add_path, file_stripped);
entry_name = entry_name_buf;
2008-05-21 09:27:41 +00:00
entry_name_len = strlen(entry_name);
} else {
2014-05-05 02:49:27 +00:00
entry_name = Z_STRVAL_P(zval_file);
2014-08-25 17:24:55 +00:00
entry_name_len = Z_STRLEN_P(zval_file);
2008-05-21 09:27:41 +00:00
}
if (basename) {
2014-08-25 17:24:55 +00:00
zend_string_release(basename);
2008-05-21 09:27:41 +00:00
basename = NULL;
}
2014-08-25 17:24:55 +00:00
if (php_zip_add_file(intern, Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file),
2014-12-13 22:06:14 +00:00
entry_name, entry_name_len, 0, 0) < 0) {
2008-05-21 09:27:41 +00:00
zval_dtor(return_value);
RETURN_FALSE;
}
}
}
}
}
/* }}} */
/* {{{ proto bool ZipArchive::addGlob(string pattern[,int flags [, array options]])
2008-05-21 09:27:41 +00:00
Add files matching the glob pattern. See php's glob for the pattern syntax. */
static ZIPARCHIVE_METHOD(addGlob)
{
php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
/* }}} */
/* {{{ proto bool ZipArchive::addPattern(string pattern[, string path [, array options]])
2008-05-21 09:27:41 +00:00
Add files matching the pcre pattern. See php's pcre for the pattern syntax. */
static ZIPARCHIVE_METHOD(addPattern)
{
php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2);
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto bool ZipArchive::addFile(string filepath[, string entryname[, int start [, int length]]])
Add a file in a Zip archive using its path and the name to use. */
static ZIPARCHIVE_METHOD(addFile)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
char *entry_name = NULL;
size_t entry_name_len = 0;
2014-08-25 17:24:55 +00:00
zend_long offset_start = 0, offset_len = 0;
2014-05-05 02:49:27 +00:00
zend_string *filename;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|sll",
2014-05-05 02:49:27 +00:00
&filename, &entry_name, &entry_name_len, &offset_start, &offset_len) == FAILURE) {
return;
}
2014-05-05 02:49:27 +00:00
if (filename->len == 0) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_NOTICE, "Empty string as filename");
RETURN_FALSE;
}
if (entry_name_len == 0) {
2014-05-05 02:49:27 +00:00
entry_name = filename->val;
entry_name_len = filename->len;
}
2014-12-13 22:06:14 +00:00
if (php_zip_add_file(intern, filename->val, filename->len, entry_name, entry_name_len, 0, 0) < 0) {
RETURN_FALSE;
} else {
RETURN_TRUE;
}
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto bool ZipArchive::addFromString(string name, string content)
Add a file using content and the entry name */
static ZIPARCHIVE_METHOD(addFromString)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-08-19 09:47:21 +00:00
zend_string *buffer;
char *name;
size_t name_len;
ze_zip_object *ze_obj;
struct zip_source *zs;
int pos = 0;
int cur_idx;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sS",
2014-08-19 09:47:21 +00:00
&name, &name_len, &buffer) == FAILURE) {
return;
}
2014-05-05 02:56:18 +00:00
ze_obj = Z_ZIP_P(self);
if (ze_obj->buffers_cnt) {
ze_obj->buffers = (char **)erealloc(ze_obj->buffers, sizeof(char *) * (ze_obj->buffers_cnt+1));
pos = ze_obj->buffers_cnt++;
} else {
ze_obj->buffers = (char **)emalloc(sizeof(char *));
ze_obj->buffers_cnt++;
pos = 0;
}
2014-08-19 09:47:21 +00:00
ze_obj->buffers[pos] = (char *)emalloc(buffer->len + 1);
memcpy(ze_obj->buffers[pos], buffer->val, buffer->len + 1);
2014-08-19 09:47:21 +00:00
zs = zip_source_buffer(intern, ze_obj->buffers[pos], buffer->len, 0);
if (zs == NULL) {
RETURN_FALSE;
}
cur_idx = zip_name_locate(intern, (const char *)name, 0);
/* TODO: fix _zip_replace */
2008-05-21 09:27:41 +00:00
if (cur_idx >= 0) {
if (zip_delete(intern, cur_idx) == -1) {
zip_source_free(zs);
RETURN_FALSE;
}
}
if (zip_add(intern, name, zs) == -1) {
zip_source_free(zs);
RETURN_FALSE;
} else {
zip_error_clear(intern);
RETURN_TRUE;
}
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto array ZipArchive::statName(string filename[, int flags])
Returns the information about a the zip entry filename */
static ZIPARCHIVE_METHOD(statName)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-08-25 17:24:55 +00:00
zend_long flags = 0;
struct zip_stat sb;
2014-05-05 02:49:27 +00:00
zend_string *name;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &name, &flags) == FAILURE) {
return;
}
2014-05-05 02:49:27 +00:00
PHP_ZIP_STAT_PATH(intern, name->val, name->len, flags, sb);
RETURN_SB(&sb);
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto resource ZipArchive::statIndex(int index[, int flags])
Returns the zip entry informations using its index */
static ZIPARCHIVE_METHOD(statIndex)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-08-25 17:24:55 +00:00
zend_long index, flags = 0;
struct zip_stat sb;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l",
&index, &flags) == FAILURE) {
return;
}
if (zip_stat_index(intern, index, flags, &sb) != 0) {
RETURN_FALSE;
}
RETURN_SB(&sb);
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto int ZipArchive::locateName(string filename[, int flags])
Returns the index of the entry named filename in the archive */
static ZIPARCHIVE_METHOD(locateName)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-08-25 17:24:55 +00:00
zend_long flags = 0;
zend_long idx = -1;
2014-05-05 02:49:27 +00:00
zend_string *name;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &name, &flags) == FAILURE) {
return;
}
2014-05-05 02:49:27 +00:00
if (name->len < 1) {
RETURN_FALSE;
}
2014-08-25 17:24:55 +00:00
idx = (zend_long)zip_name_locate(intern, (const char *)name->val, flags);
2008-05-21 09:27:41 +00:00
if (idx >= 0) {
2014-08-25 17:24:55 +00:00
RETURN_LONG(idx);
2008-05-21 09:27:41 +00:00
} else {
RETURN_FALSE;
}
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto string ZipArchive::getNameIndex(int index [, int flags])
Returns the name of the file at position index */
static ZIPARCHIVE_METHOD(getNameIndex)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
const char *name;
2014-08-25 17:24:55 +00:00
zend_long flags = 0, index = 0;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l",
&index, &flags) == FAILURE) {
return;
}
name = zip_get_name(intern, (int) index, flags);
if (name) {
2014-05-05 02:49:27 +00:00
RETVAL_STRING((char *)name);
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool ZipArchive::setArchiveComment(string comment)
Set or remove (NULL/'') the comment of the archive */
static ZIPARCHIVE_METHOD(setArchiveComment)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-08-27 17:25:28 +00:00
size_t comment_len;
char * comment;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &comment, &comment_len) == FAILURE) {
return;
}
if (zip_set_archive_comment(intern, (const char *)comment, (int)comment_len)) {
RETURN_FALSE;
} else {
RETURN_TRUE;
}
}
/* }}} */
/* {{{ proto string ZipArchive::getArchiveComment([int flags])
Returns the comment of an entry using its index */
static ZIPARCHIVE_METHOD(getArchiveComment)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-08-25 17:24:55 +00:00
zend_long flags = 0;
const char * comment;
int comment_len = 0;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) {
return;
}
comment = zip_get_archive_comment(intern, &comment_len, (int)flags);
if(comment==NULL) {
RETURN_FALSE;
}
2014-08-25 17:24:55 +00:00
RETURN_STRINGL((char *)comment, (zend_long)comment_len);
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto bool ZipArchive::setCommentName(string name, string comment)
Set or remove (NULL/'') the comment of an entry using its Name */
static ZIPARCHIVE_METHOD(setCommentName)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-08-27 17:25:28 +00:00
size_t comment_len, name_len;
char * comment, *name;
int idx;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss",
&name, &name_len, &comment, &comment_len) == FAILURE) {
return;
}
if (name_len < 1) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
}
idx = zip_name_locate(intern, name, 0);
if (idx < 0) {
RETURN_FALSE;
}
PHP_ZIP_SET_FILE_COMMENT(intern, idx, comment, comment_len);
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto bool ZipArchive::setCommentIndex(int index, string comment)
Set or remove (NULL/'') the comment of an entry using its index */
static ZIPARCHIVE_METHOD(setCommentIndex)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-08-25 17:24:55 +00:00
zend_long index;
2014-08-27 17:25:28 +00:00
size_t comment_len;
char * comment;
struct zip_stat sb;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls",
&index, &comment, &comment_len) == FAILURE) {
return;
}
PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
PHP_ZIP_SET_FILE_COMMENT(intern, index, comment, comment_len);
}
/* }}} */
/* those constants/functions are only available in libzip since 0.11.2 */
#ifdef ZIP_OPSYS_DEFAULT
/* {{{ proto bool ZipArchive::setExternalAttributesName(string name, int opsys, int attr [, int flags])
Set external attributes for file in zip, using its name */
static ZIPARCHIVE_METHOD(setExternalAttributesName)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
size_t name_len;
char *name;
2014-08-25 17:24:55 +00:00
zend_long flags=0, opsys, attr;
zip_int64_t idx;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|l",
&name, &name_len, &opsys, &attr, &flags) == FAILURE) {
return;
}
if (name_len < 1) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
}
idx = zip_name_locate(intern, name, 0);
if (idx < 0) {
RETURN_FALSE;
}
if (zip_file_set_external_attributes(intern, idx, (zip_flags_t)flags,
(zip_uint8_t)(opsys&0xff), (zip_uint32_t)attr) < 0) {
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool ZipArchive::setExternalAttributesIndex(int index, int opsys, int attr [, int flags])
Set external attributes for file in zip, using its index */
static ZIPARCHIVE_METHOD(setExternalAttributesIndex)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-08-25 17:24:55 +00:00
zend_long index, flags=0, opsys, attr;
struct zip_stat sb;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll|l",
&index, &opsys, &attr, &flags) == FAILURE) {
return;
}
PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
if (zip_file_set_external_attributes(intern, (zip_uint64_t)index,
(zip_flags_t)flags, (zip_uint8_t)(opsys&0xff), (zip_uint32_t)attr) < 0) {
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool ZipArchive::getExternalAttributesName(string name, int &opsys, int &attr [, int flags])
Get external attributes for file in zip, using its name */
static ZIPARCHIVE_METHOD(getExternalAttributesName)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis(), *z_opsys, *z_attr;
size_t name_len;
char *name;
2014-08-25 17:24:55 +00:00
zend_long flags=0;
zip_uint8_t opsys;
zip_uint32_t attr;
zip_int64_t idx;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz/z/|l",
&name, &name_len, &z_opsys, &z_attr, &flags) == FAILURE) {
return;
}
if (name_len < 1) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
}
idx = zip_name_locate(intern, name, 0);
if (idx < 0) {
RETURN_FALSE;
}
if (zip_file_get_external_attributes(intern, idx,
(zip_flags_t)flags, &opsys, &attr) < 0) {
RETURN_FALSE;
}
2014-05-05 09:48:49 +00:00
zval_ptr_dtor(z_opsys);
2014-08-25 17:24:55 +00:00
ZVAL_LONG(z_opsys, opsys);
2014-05-05 09:48:49 +00:00
zval_ptr_dtor(z_attr);
2014-08-25 17:24:55 +00:00
ZVAL_LONG(z_attr, attr);
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool ZipArchive::getExternalAttributesIndex(int index, int &opsys, int &attr [, int flags])
Get external attributes for file in zip, using its index */
static ZIPARCHIVE_METHOD(getExternalAttributesIndex)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis(), *z_opsys, *z_attr;
2014-08-25 17:24:55 +00:00
zend_long index, flags=0;
zip_uint8_t opsys;
zip_uint32_t attr;
struct zip_stat sb;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz/z/|l",
&index, &z_opsys, &z_attr, &flags) == FAILURE) {
return;
}
PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
if (zip_file_get_external_attributes(intern, (zip_uint64_t)index,
(zip_flags_t)flags, &opsys, &attr) < 0) {
RETURN_FALSE;
}
zval_dtor(z_opsys);
2014-08-25 17:24:55 +00:00
ZVAL_LONG(z_opsys, opsys);
zval_dtor(z_attr);
2014-08-25 17:24:55 +00:00
ZVAL_LONG(z_attr, attr);
RETURN_TRUE;
}
/* }}} */
#endif /* ifdef ZIP_OPSYS_DEFAULT */
/* {{{ proto string ZipArchive::getCommentName(string name[, int flags])
Returns the comment of an entry using its name */
static ZIPARCHIVE_METHOD(getCommentName)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-08-27 17:25:28 +00:00
size_t name_len;
int idx;
2014-08-25 17:24:55 +00:00
zend_long flags = 0;
int comment_len = 0;
const char * comment;
char *name;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l",
&name, &name_len, &flags) == FAILURE) {
return;
}
if (name_len < 1) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
RETURN_FALSE;
}
idx = zip_name_locate(intern, name, 0);
if (idx < 0) {
RETURN_FALSE;
}
comment = zip_get_file_comment(intern, idx, &comment_len, (int)flags);
2014-08-25 17:24:55 +00:00
RETURN_STRINGL((char *)comment, (zend_long)comment_len);
}
/* }}} */
/* {{{ proto string ZipArchive::getCommentIndex(int index[, int flags])
Returns the comment of an entry using its index */
static ZIPARCHIVE_METHOD(getCommentIndex)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-08-25 17:24:55 +00:00
zend_long index, flags = 0;
const char * comment;
int comment_len = 0;
struct zip_stat sb;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l",
&index, &flags) == FAILURE) {
return;
}
PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
comment = zip_get_file_comment(intern, index, &comment_len, (int)flags);
2014-08-25 17:24:55 +00:00
RETURN_STRINGL((char *)comment, (zend_long)comment_len);
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto bool ZipArchive::deleteIndex(int index)
Delete a file using its index */
static ZIPARCHIVE_METHOD(deleteIndex)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-08-25 17:24:55 +00:00
zend_long index;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
return;
}
if (index < 0) {
RETURN_FALSE;
}
if (zip_delete(intern, index) < 0) {
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto bool ZipArchive::deleteName(string name)
Delete a file using its index */
static ZIPARCHIVE_METHOD(deleteName)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
size_t name_len;
2006-09-06 15:19:41 +00:00
char *name;
struct zip_stat sb;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
return;
}
if (name_len < 1) {
RETURN_FALSE;
}
PHP_ZIP_STAT_PATH(intern, name, name_len, 0, sb);
if (zip_delete(intern, sb.index)) {
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto bool ZipArchive::renameIndex(int index, string new_name)
Rename an entry selected by its index to new_name */
static ZIPARCHIVE_METHOD(renameIndex)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
char *new_name;
size_t new_name_len;
2014-08-25 17:24:55 +00:00
zend_long index;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &index, &new_name, &new_name_len) == FAILURE) {
return;
}
if (index < 0) {
RETURN_FALSE;
}
if (new_name_len < 1) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_NOTICE, "Empty string as new entry name");
RETURN_FALSE;
}
if (zip_rename(intern, index, (const char *)new_name) != 0) {
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto bool ZipArchive::renameName(string name, string new_name)
Rename an entry selected by its name to new_name */
static ZIPARCHIVE_METHOD(renameName)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
struct zip_stat sb;
char *name, *new_name;
2014-08-27 17:25:28 +00:00
size_t name_len, new_name_len;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &name_len, &new_name, &new_name_len) == FAILURE) {
return;
}
if (new_name_len < 1) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_NOTICE, "Empty string as new entry name");
RETURN_FALSE;
}
PHP_ZIP_STAT_PATH(intern, name, name_len, 0, sb);
if (zip_rename(intern, sb.index, (const char *)new_name)) {
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto bool ZipArchive::unchangeIndex(int index)
Changes to the file at position index are reverted */
static ZIPARCHIVE_METHOD(unchangeIndex)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-08-25 17:24:55 +00:00
zend_long index;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
return;
}
if (index < 0) {
RETURN_FALSE;
}
if (zip_unchange(intern, index) != 0) {
RETURN_FALSE;
} else {
RETURN_TRUE;
}
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto bool ZipArchive::unchangeName(string name)
Changes to the file named 'name' are reverted */
static ZIPARCHIVE_METHOD(unchangeName)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
struct zip_stat sb;
char *name;
size_t name_len;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
return;
}
if (name_len < 1) {
RETURN_FALSE;
}
PHP_ZIP_STAT_PATH(intern, name, name_len, 0, sb);
if (zip_unchange(intern, sb.index) != 0) {
RETURN_FALSE;
} else {
RETURN_TRUE;
}
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto bool ZipArchive::unchangeAll()
All changes to files and global information in archive are reverted */
static ZIPARCHIVE_METHOD(unchangeAll)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
if (zip_unchange_all(intern) != 0) {
RETURN_FALSE;
} else {
RETURN_TRUE;
}
}
/* }}} */
2010-06-03 18:39:21 +00:00
/* {{{ proto bool ZipArchive::unchangeArchive()
Revert all global changes to the archive archive. For now, this only reverts archive comment changes. */
static ZIPARCHIVE_METHOD(unchangeArchive)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
if (zip_unchange_archive(intern) != 0) {
RETURN_FALSE;
} else {
RETURN_TRUE;
}
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto bool ZipArchive::extractTo(string pathto[, mixed files])
Extract one or more file from a zip archive */
/* TODO:
* - allow index or array of indeces
* - replace path
* - patterns
*/
static ZIPARCHIVE_METHOD(extractTo)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
zval *zval_files = NULL;
2014-05-05 02:49:27 +00:00
zval *zval_file = NULL;
php_stream_statbuf ssb;
char *pathto;
size_t pathto_len;
int ret, i;
int nelems;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|z", &pathto, &pathto_len, &zval_files) == FAILURE) {
return;
}
if (pathto_len < 1) {
RETURN_FALSE;
}
2011-02-01 10:57:51 +00:00
if (php_stream_stat_path_ex(pathto, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL) < 0) {
ret = php_stream_mkdir(pathto, 0777, PHP_STREAM_MKDIR_RECURSIVE, NULL);
if (!ret) {
RETURN_FALSE;
}
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
if (zval_files && (Z_TYPE_P(zval_files) != IS_NULL)) {
switch (Z_TYPE_P(zval_files)) {
case IS_STRING:
2014-12-13 22:06:14 +00:00
if (!php_zip_extract_file(intern, pathto, Z_STRVAL_P(zval_files), Z_STRLEN_P(zval_files))) {
RETURN_FALSE;
}
break;
case IS_ARRAY:
nelems = zend_hash_num_elements(Z_ARRVAL_P(zval_files));
if (nelems == 0 ) {
RETURN_FALSE;
}
for (i = 0; i < nelems; i++) {
2014-05-05 02:49:27 +00:00
if ((zval_file = zend_hash_index_find(Z_ARRVAL_P(zval_files), i)) != NULL) {
switch (Z_TYPE_P(zval_file)) {
2014-08-25 17:24:55 +00:00
case IS_LONG:
break;
case IS_STRING:
2014-12-13 22:06:14 +00:00
if (!php_zip_extract_file(intern, pathto, Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file))) {
RETURN_FALSE;
}
break;
}
}
}
break;
2014-08-25 17:24:55 +00:00
case IS_LONG:
default:
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Invalid argument, expect string or array of strings");
break;
}
} else {
2011-02-01 10:57:51 +00:00
/* Extract all files */
int filecount = zip_get_num_files(intern);
2011-02-01 10:57:51 +00:00
if (filecount == -1) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Illegal archive");
2011-02-01 10:57:51 +00:00
RETURN_FALSE;
}
2011-02-01 10:57:51 +00:00
for (i = 0; i < filecount; i++) {
char *file = (char*)zip_get_name(intern, i, ZIP_FL_UNCHANGED);
2014-12-13 22:06:14 +00:00
if (!php_zip_extract_file(intern, pathto, file, strlen(file))) {
2011-02-01 10:57:51 +00:00
RETURN_FALSE;
}
}
}
RETURN_TRUE;
}
/* }}} */
static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
struct zip_stat sb;
struct zip_file *zf;
2014-08-25 17:24:55 +00:00
zend_long index = -1;
zend_long flags = 0;
zend_long len = 0;
2014-05-05 02:49:27 +00:00
zend_string *filename;
zend_string *buffer;
int n = 0;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
if (type == 1) {
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|ll", &filename, &len, &flags) == FAILURE) {
return;
}
2014-05-05 02:49:27 +00:00
PHP_ZIP_STAT_PATH(intern, filename->val, filename->len, flags, sb);
} else {
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|ll", &index, &len, &flags) == FAILURE) {
return;
}
PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
}
if (sb.size < 1) {
RETURN_EMPTY_STRING();
}
if (len < 1) {
len = sb.size;
}
if (index >= 0) {
zf = zip_fopen_index(intern, index, flags);
} else {
2014-05-05 02:49:27 +00:00
zf = zip_fopen(intern, filename->val, flags);
}
if (zf == NULL) {
RETURN_FALSE;
}
2014-08-25 17:24:55 +00:00
buffer = zend_string_alloc(len, 0);
2014-05-05 02:49:27 +00:00
n = zip_fread(zf, buffer->val, buffer->len);
if (n < 1) {
2014-08-25 17:24:55 +00:00
zend_string_free(buffer);
RETURN_EMPTY_STRING();
}
zip_fclose(zf);
2014-05-05 02:49:27 +00:00
buffer->val[n] = '\0';
buffer->len = n;
RETURN_STR(buffer);
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto string ZipArchive::getFromName(string entryname[, int len [, int flags]])
get the contents of an entry using its name */
static ZIPARCHIVE_METHOD(getFromName)
{
php_zip_get_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
/* }}} */
2010-06-03 18:39:21 +00:00
/* {{{ proto string ZipArchive::getFromIndex(int index[, int len [, int flags]])
get the contents of an entry using its index */
static ZIPARCHIVE_METHOD(getFromIndex)
{
php_zip_get_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */
2007-12-15 12:52:55 +00:00
/* {{{ proto resource ZipArchive::getStream(string entryname)
get a stream for an entry using its name */
static ZIPARCHIVE_METHOD(getStream)
{
struct zip *intern;
2014-05-05 02:56:18 +00:00
zval *self = getThis();
struct zip_stat sb;
char *mode = "rb";
2014-05-05 02:49:27 +00:00
zend_string *filename;
php_stream *stream;
ze_zip_object *obj;
2014-05-05 02:56:18 +00:00
if (!self) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
ZIP_FROM_OBJECT(intern, self);
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &filename) == FAILURE) {
return;
}
2014-05-05 02:49:27 +00:00
if (zip_stat(intern, filename->val, 0, &sb) != 0) {
RETURN_FALSE;
}
2014-05-05 02:56:18 +00:00
obj = Z_ZIP_P(self);
2014-12-13 22:06:14 +00:00
stream = php_stream_zip_open(obj->filename, filename->val, mode STREAMS_CC);
if (stream) {
php_stream_to_zval(stream, return_value);
}
}
/* }}} */
2010-06-03 18:23:14 +00:00
/* {{{ arginfo */
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_open, 0, 0, 1)
ZEND_ARG_INFO(0, filename)
2010-06-03 18:23:14 +00:00
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setpassword, 0, 0, 1)
ZEND_ARG_INFO(0, password)
ZEND_END_ARG_INFO()
2010-06-03 18:23:14 +00:00
ZEND_BEGIN_ARG_INFO(arginfo_ziparchive__void, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addemptydir, 0, 0, 1)
ZEND_ARG_INFO(0, dirname)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addglob, 0, 0, 1)
ZEND_ARG_INFO(0, pattern)
ZEND_ARG_INFO(0, flags)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addpattern, 0, 0, 1)
ZEND_ARG_INFO(0, pattern)
ZEND_ARG_INFO(0, path)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addfile, 0, 0, 1)
ZEND_ARG_INFO(0, filepath)
ZEND_ARG_INFO(0, entryname)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, length)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addfromstring, 0, 0, 2)
ZEND_ARG_INFO(0, name)
ZEND_ARG_INFO(0, content)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_statname, 0, 0, 1)
ZEND_ARG_INFO(0, filename)
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_statindex, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setarchivecomment, 0, 0, 1)
2010-06-03 18:23:14 +00:00
ZEND_ARG_INFO(0, comment)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setcommentindex, 0, 0, 2)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, comment)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getcommentname, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_ARG_INFO(0, flags)
2010-06-03 18:23:14 +00:00
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getcommentindex, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, flags)
2010-06-03 18:23:14 +00:00
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_renameindex, 0, 0, 2)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, new_name)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_renamename, 0, 0, 2)
ZEND_ARG_INFO(0, name)
ZEND_ARG_INFO(0, new_name)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_unchangeindex, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_unchangename, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_extractto, 0, 0, 1)
ZEND_ARG_INFO(0, pathto)
ZEND_ARG_INFO(0, files)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getfromname, 0, 0, 1)
ZEND_ARG_INFO(0, entryname)
ZEND_ARG_INFO(0, len)
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getfromindex, 0, 0, 1)
2010-06-03 18:39:21 +00:00
ZEND_ARG_INFO(0, index)
2010-06-03 18:23:14 +00:00
ZEND_ARG_INFO(0, len)
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getarchivecomment, 0, 0, 0)
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setcommentname, 0, 0, 2)
ZEND_ARG_INFO(0, name)
ZEND_ARG_INFO(0, comment)
ZEND_END_ARG_INFO()
2010-06-03 18:23:14 +00:00
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getstream, 0, 0, 1)
ZEND_ARG_INFO(0, entryname)
ZEND_END_ARG_INFO()
#ifdef ZIP_OPSYS_DEFAULT
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setextattrname, 0, 0, 3)
ZEND_ARG_INFO(0, name)
ZEND_ARG_INFO(0, opsys)
ZEND_ARG_INFO(0, attr)
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setextattrindex, 0, 0, 3)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, opsys)
ZEND_ARG_INFO(0, attr)
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getextattrname, 0, 0, 3)
ZEND_ARG_INFO(0, name)
ZEND_ARG_INFO(1, opsys)
ZEND_ARG_INFO(1, attr)
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getextattrindex, 0, 0, 3)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(1, opsys)
ZEND_ARG_INFO(1, attr)
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()
#endif /* ifdef ZIP_OPSYS_DEFAULT */
2010-06-03 18:23:14 +00:00
/* }}} */
/* {{{ ze_zip_object_class_functions */
static const zend_function_entry zip_class_functions[] = {
2010-06-03 18:23:14 +00:00
ZIPARCHIVE_ME(open, arginfo_ziparchive_open, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(setPassword, arginfo_ziparchive_setpassword, ZEND_ACC_PUBLIC)
2010-06-03 18:23:14 +00:00
ZIPARCHIVE_ME(close, arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(getStatusString, arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(addEmptyDir, arginfo_ziparchive_addemptydir, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(addFromString, arginfo_ziparchive_addfromstring, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(addFile, arginfo_ziparchive_addfile, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(addGlob, arginfo_ziparchive_addglob, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(addPattern, arginfo_ziparchive_addpattern, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(renameIndex, arginfo_ziparchive_renameindex, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(renameName, arginfo_ziparchive_renamename, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(setArchiveComment, arginfo_ziparchive_setarchivecomment, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(getArchiveComment, arginfo_ziparchive_getarchivecomment, ZEND_ACC_PUBLIC)
2010-06-03 18:23:14 +00:00
ZIPARCHIVE_ME(setCommentIndex, arginfo_ziparchive_setcommentindex, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(setCommentName, arginfo_ziparchive_setcommentname, ZEND_ACC_PUBLIC)
2010-06-03 18:23:14 +00:00
ZIPARCHIVE_ME(getCommentIndex, arginfo_ziparchive_getcommentindex, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(getCommentName, arginfo_ziparchive_getcommentname, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(deleteIndex, arginfo_ziparchive_unchangeindex, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(deleteName, arginfo_ziparchive_unchangename, ZEND_ACC_PUBLIC)
2010-06-03 18:23:14 +00:00
ZIPARCHIVE_ME(statName, arginfo_ziparchive_statname, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(statIndex, arginfo_ziparchive_statindex, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(locateName, arginfo_ziparchive_statname, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(getNameIndex, arginfo_ziparchive_statindex, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(unchangeArchive, arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(unchangeAll, arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(unchangeIndex, arginfo_ziparchive_unchangeindex, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(unchangeName, arginfo_ziparchive_unchangename, ZEND_ACC_PUBLIC)
2010-06-03 18:23:14 +00:00
ZIPARCHIVE_ME(extractTo, arginfo_ziparchive_extractto, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(getFromName, arginfo_ziparchive_getfromname, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(getFromIndex, arginfo_ziparchive_getfromindex, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(getStream, arginfo_ziparchive_getstream, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(setExternalAttributesName, arginfo_ziparchive_setextattrname, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(setExternalAttributesIndex, arginfo_ziparchive_setextattrindex, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(getExternalAttributesName, arginfo_ziparchive_getextattrname, ZEND_ACC_PUBLIC)
ZIPARCHIVE_ME(getExternalAttributesIndex, arginfo_ziparchive_getextattrindex, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
/* }}} */
static void php_zip_free_prop_handler(zval *el) /* {{{ */ {
pefree(Z_PTR_P(el), 1);
} /* }}} */
/* {{{ PHP_MINIT_FUNCTION */
static PHP_MINIT_FUNCTION(zip)
{
zend_class_entry ce;
memcpy(&zip_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
2014-05-05 02:49:27 +00:00
zip_object_handlers.offset = XtOffsetOf(ze_zip_object, zo);
zip_object_handlers.free_obj = php_zip_object_free_storage;
zip_object_handlers.clone_obj = NULL;
zip_object_handlers.get_property_ptr_ptr = php_zip_get_property_ptr_ptr;
zip_object_handlers.get_properties = php_zip_get_properties;
zip_object_handlers.read_property = php_zip_read_property;
zip_object_handlers.has_property = php_zip_has_property;
INIT_CLASS_ENTRY(ce, "ZipArchive", zip_class_functions);
ce.create_object = php_zip_object_new;
2014-12-13 22:06:14 +00:00
zip_class_entry = zend_register_internal_class(&ce);
zend_hash_init(&zip_prop_handlers, 0, NULL, php_zip_free_prop_handler, 1);
2014-12-13 22:06:14 +00:00
php_zip_register_prop_handler(&zip_prop_handlers, "status", php_zip_status, NULL, NULL, IS_LONG);
php_zip_register_prop_handler(&zip_prop_handlers, "statusSys", php_zip_status_sys, NULL, NULL, IS_LONG);
php_zip_register_prop_handler(&zip_prop_handlers, "numFiles", php_zip_get_num_files, NULL, NULL, IS_LONG);
php_zip_register_prop_handler(&zip_prop_handlers, "filename", NULL, NULL, php_zipobj_get_filename, IS_STRING);
php_zip_register_prop_handler(&zip_prop_handlers, "comment", NULL, php_zipobj_get_zip_comment, NULL, IS_STRING);
2014-08-25 17:24:55 +00:00
REGISTER_ZIP_CLASS_CONST_LONG("CREATE", ZIP_CREATE);
REGISTER_ZIP_CLASS_CONST_LONG("EXCL", ZIP_EXCL);
REGISTER_ZIP_CLASS_CONST_LONG("CHECKCONS", ZIP_CHECKCONS);
REGISTER_ZIP_CLASS_CONST_LONG("OVERWRITE", ZIP_OVERWRITE);
REGISTER_ZIP_CLASS_CONST_LONG("FL_NOCASE", ZIP_FL_NOCASE);
REGISTER_ZIP_CLASS_CONST_LONG("FL_NODIR", ZIP_FL_NODIR);
REGISTER_ZIP_CLASS_CONST_LONG("FL_COMPRESSED", ZIP_FL_COMPRESSED);
REGISTER_ZIP_CLASS_CONST_LONG("FL_UNCHANGED", ZIP_FL_UNCHANGED);
REGISTER_ZIP_CLASS_CONST_LONG("CM_DEFAULT", ZIP_CM_DEFAULT);
REGISTER_ZIP_CLASS_CONST_LONG("CM_STORE", ZIP_CM_STORE);
REGISTER_ZIP_CLASS_CONST_LONG("CM_SHRINK", ZIP_CM_SHRINK);
REGISTER_ZIP_CLASS_CONST_LONG("CM_REDUCE_1", ZIP_CM_REDUCE_1);
REGISTER_ZIP_CLASS_CONST_LONG("CM_REDUCE_2", ZIP_CM_REDUCE_2);
REGISTER_ZIP_CLASS_CONST_LONG("CM_REDUCE_3", ZIP_CM_REDUCE_3);
REGISTER_ZIP_CLASS_CONST_LONG("CM_REDUCE_4", ZIP_CM_REDUCE_4);
REGISTER_ZIP_CLASS_CONST_LONG("CM_IMPLODE", ZIP_CM_IMPLODE);
REGISTER_ZIP_CLASS_CONST_LONG("CM_DEFLATE", ZIP_CM_DEFLATE);
REGISTER_ZIP_CLASS_CONST_LONG("CM_DEFLATE64", ZIP_CM_DEFLATE64);
REGISTER_ZIP_CLASS_CONST_LONG("CM_PKWARE_IMPLODE", ZIP_CM_PKWARE_IMPLODE);
REGISTER_ZIP_CLASS_CONST_LONG("CM_BZIP2", ZIP_CM_BZIP2);
REGISTER_ZIP_CLASS_CONST_LONG("CM_LZMA", ZIP_CM_LZMA);
REGISTER_ZIP_CLASS_CONST_LONG("CM_TERSE", ZIP_CM_TERSE);
REGISTER_ZIP_CLASS_CONST_LONG("CM_LZ77", ZIP_CM_LZ77);
REGISTER_ZIP_CLASS_CONST_LONG("CM_WAVPACK", ZIP_CM_WAVPACK);
REGISTER_ZIP_CLASS_CONST_LONG("CM_PPMD", ZIP_CM_PPMD);
/* Error code */
2014-08-25 17:24:55 +00:00
REGISTER_ZIP_CLASS_CONST_LONG("ER_OK", ZIP_ER_OK); /* N No error */
REGISTER_ZIP_CLASS_CONST_LONG("ER_MULTIDISK", ZIP_ER_MULTIDISK); /* N Multi-disk zip archives not supported */
REGISTER_ZIP_CLASS_CONST_LONG("ER_RENAME", ZIP_ER_RENAME); /* S Renaming temporary file failed */
REGISTER_ZIP_CLASS_CONST_LONG("ER_CLOSE", ZIP_ER_CLOSE); /* S Closing zip archive failed */
REGISTER_ZIP_CLASS_CONST_LONG("ER_SEEK", ZIP_ER_SEEK); /* S Seek error */
REGISTER_ZIP_CLASS_CONST_LONG("ER_READ", ZIP_ER_READ); /* S Read error */
REGISTER_ZIP_CLASS_CONST_LONG("ER_WRITE", ZIP_ER_WRITE); /* S Write error */
REGISTER_ZIP_CLASS_CONST_LONG("ER_CRC", ZIP_ER_CRC); /* N CRC error */
REGISTER_ZIP_CLASS_CONST_LONG("ER_ZIPCLOSED", ZIP_ER_ZIPCLOSED); /* N Containing zip archive was closed */
REGISTER_ZIP_CLASS_CONST_LONG("ER_NOENT", ZIP_ER_NOENT); /* N No such file */
REGISTER_ZIP_CLASS_CONST_LONG("ER_EXISTS", ZIP_ER_EXISTS); /* N File already exists */
REGISTER_ZIP_CLASS_CONST_LONG("ER_OPEN", ZIP_ER_OPEN); /* S Can't open file */
REGISTER_ZIP_CLASS_CONST_LONG("ER_TMPOPEN", ZIP_ER_TMPOPEN); /* S Failure to create temporary file */
REGISTER_ZIP_CLASS_CONST_LONG("ER_ZLIB", ZIP_ER_ZLIB); /* Z Zlib error */
REGISTER_ZIP_CLASS_CONST_LONG("ER_MEMORY", ZIP_ER_MEMORY); /* N Malloc failure */
REGISTER_ZIP_CLASS_CONST_LONG("ER_CHANGED", ZIP_ER_CHANGED); /* N Entry has been changed */
REGISTER_ZIP_CLASS_CONST_LONG("ER_COMPNOTSUPP", ZIP_ER_COMPNOTSUPP);/* N Compression method not supported */
REGISTER_ZIP_CLASS_CONST_LONG("ER_EOF", ZIP_ER_EOF); /* N Premature EOF */
REGISTER_ZIP_CLASS_CONST_LONG("ER_INVAL", ZIP_ER_INVAL); /* N Invalid argument */
REGISTER_ZIP_CLASS_CONST_LONG("ER_NOZIP", ZIP_ER_NOZIP); /* N Not a zip archive */
REGISTER_ZIP_CLASS_CONST_LONG("ER_INTERNAL", ZIP_ER_INTERNAL); /* N Internal error */
REGISTER_ZIP_CLASS_CONST_LONG("ER_INCONS", ZIP_ER_INCONS); /* N Zip archive inconsistent */
REGISTER_ZIP_CLASS_CONST_LONG("ER_REMOVE", ZIP_ER_REMOVE); /* S Can't remove file */
REGISTER_ZIP_CLASS_CONST_LONG("ER_DELETED", ZIP_ER_DELETED); /* N Entry has been deleted */
#ifdef ZIP_OPSYS_DEFAULT
2014-08-25 17:24:55 +00:00
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_DOS", ZIP_OPSYS_DOS);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_AMIGA", ZIP_OPSYS_AMIGA);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_OPENVMS", ZIP_OPSYS_OPENVMS);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_UNIX", ZIP_OPSYS_UNIX);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_VM_CMS", ZIP_OPSYS_VM_CMS);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_ATARI_ST", ZIP_OPSYS_ATARI_ST);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_OS_2", ZIP_OPSYS_OS_2);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_MACINTOSH", ZIP_OPSYS_MACINTOSH);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_Z_SYSTEM", ZIP_OPSYS_Z_SYSTEM);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_Z_CPM", ZIP_OPSYS_CPM);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_WINDOWS_NTFS", ZIP_OPSYS_WINDOWS_NTFS);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_MVS", ZIP_OPSYS_MVS);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_VSE", ZIP_OPSYS_VSE);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_ACORN_RISC", ZIP_OPSYS_ACORN_RISC);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_VFAT", ZIP_OPSYS_VFAT);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_ALTERNATE_MVS", ZIP_OPSYS_ALTERNATE_MVS);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_BEOS", ZIP_OPSYS_BEOS);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_TANDEM", ZIP_OPSYS_TANDEM);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_OS_400", ZIP_OPSYS_OS_400);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_OS_X", ZIP_OPSYS_OS_X);
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_DEFAULT", ZIP_OPSYS_DEFAULT);
#endif /* ifdef ZIP_OPSYS_DEFAULT */
2014-12-13 22:06:14 +00:00
php_register_url_stream_wrapper("zip", &php_stream_zip_wrapper);
le_zip_dir = zend_register_list_destructors_ex(php_zip_free_dir, NULL, le_zip_dir_name, module_number);
le_zip_entry = zend_register_list_destructors_ex(php_zip_free_entry, NULL, le_zip_entry_name, module_number);
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
static PHP_MSHUTDOWN_FUNCTION(zip)
{
zend_hash_destroy(&zip_prop_handlers);
2014-12-13 22:06:14 +00:00
php_unregister_url_stream_wrapper("zip");
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
static PHP_MINFO_FUNCTION(zip)
{
php_info_print_table_start();
2006-07-28 13:59:06 +00:00
php_info_print_table_row(2, "Zip", "enabled");
php_info_print_table_row(2, "Extension Version","$Id$");
php_info_print_table_row(2, "Zip version", PHP_ZIP_VERSION);
php_info_print_table_row(2, "Libzip version", LIBZIP_VERSION);
2006-07-28 13:59:06 +00:00
php_info_print_table_end();
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/