PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/zip - php_zip.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 862 1173 73.5 %
Date: 2015-03-01 Functions: 68 73 93.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 1997-2015 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: Piere-Alain Joye <pierre@php.net>                            |
      16             :   +----------------------------------------------------------------------+
      17             : */
      18             : 
      19             : /* $Id: e90ee9f9792048f73be3647d4b4da6c2a817f0bd $ */
      20             : 
      21             : #ifdef HAVE_CONFIG_H
      22             : #include "config.h"
      23             : #endif
      24             : 
      25             : #include "php.h"
      26             : #include "php_ini.h"
      27             : #include "ext/standard/info.h"
      28             : #include "ext/standard/file.h"
      29             : #include "ext/standard/php_string.h"
      30             : #include "ext/pcre/php_pcre.h"
      31             : #include "ext/standard/php_filestat.h"
      32             : #include "php_zip.h"
      33             : 
      34             : /* zip_open is a macro for renaming libzip zipopen, so we need to use PHP_NAMED_FUNCTION */
      35             : static PHP_NAMED_FUNCTION(zif_zip_open);
      36             : static PHP_NAMED_FUNCTION(zif_zip_read);
      37             : static PHP_NAMED_FUNCTION(zif_zip_close);
      38             : static PHP_NAMED_FUNCTION(zif_zip_entry_read);
      39             : static PHP_NAMED_FUNCTION(zif_zip_entry_filesize);
      40             : static PHP_NAMED_FUNCTION(zif_zip_entry_name);
      41             : static PHP_NAMED_FUNCTION(zif_zip_entry_compressedsize);
      42             : static PHP_NAMED_FUNCTION(zif_zip_entry_compressionmethod);
      43             : static PHP_NAMED_FUNCTION(zif_zip_entry_open);
      44             : static PHP_NAMED_FUNCTION(zif_zip_entry_close);
      45             : 
      46             : #ifdef HAVE_GLOB
      47             : #ifndef PHP_WIN32
      48             : #include <glob.h>
      49             : #else
      50             : #include "win32/glob.h"
      51             : #endif
      52             : #endif
      53             : 
      54             : /* {{{ Resource le */
      55             : static int le_zip_dir;
      56             : #define le_zip_dir_name "Zip Directory"
      57             : static int le_zip_entry;
      58             : #define le_zip_entry_name "Zip Entry"
      59             : /* }}} */
      60             : 
      61             : /* {{{ PHP_ZIP_STAT_INDEX(za, index, flags, sb) */
      62             : #define PHP_ZIP_STAT_INDEX(za, index, flags, sb) \
      63             :         if (zip_stat_index(za, index, flags, &sb) != 0) { \
      64             :                 RETURN_FALSE; \
      65             :         }
      66             : /* }}} */
      67             : 
      68             : /* {{{  PHP_ZIP_STAT_PATH(za, path, path_len, flags, sb) */
      69             : #define PHP_ZIP_STAT_PATH(za, path, path_len, flags, sb) \
      70             :         if (path_len < 1) { \
      71             :                 php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); \
      72             :                 RETURN_FALSE; \
      73             :         } \
      74             :         if (zip_stat(za, path, flags, &sb) != 0) { \
      75             :                 RETURN_FALSE; \
      76             :         }
      77             : /* }}} */
      78             : 
      79             : /* {{{ PHP_ZIP_SET_FILE_COMMENT(za, index, comment, comment_len) */
      80             : #define PHP_ZIP_SET_FILE_COMMENT(za, index, comment, comment_len) \
      81             :         if (comment_len == 0) { \
      82             :                 /* Passing NULL remove the existing comment */ \
      83             :                 if (zip_set_file_comment(intern, index, NULL, 0) < 0) { \
      84             :                         RETURN_FALSE; \
      85             :                 } \
      86             :         } else if (zip_set_file_comment(intern, index, comment, comment_len) < 0) { \
      87             :                 RETURN_FALSE; \
      88             :         } \
      89             :         RETURN_TRUE;
      90             : /* }}} */
      91             : 
      92             : # define add_ascii_assoc_string add_assoc_string
      93             : # define add_ascii_assoc_long add_assoc_long
      94             : 
      95             : /* Flatten a path by making a relative path (to .)*/
      96          11 : static char * php_zip_make_relative_path(char *path, size_t path_len) /* {{{ */
      97             : {
      98          11 :         char *path_begin = path;
      99             :         size_t i;
     100             : 
     101          11 :         if (path_len < 1 || path == NULL) {
     102           0 :                 return NULL;
     103             :         }
     104             : 
     105          11 :         if (IS_SLASH(path[0])) {
     106           0 :                 return path + 1;
     107             :         }
     108             : 
     109          11 :         i = path_len;
     110             : 
     111             :         while (1) {
     112          92 :                 while (i > 0 && !IS_SLASH(path[i])) {
     113          60 :                         i--;
     114             :                 }
     115             : 
     116          16 :                 if (!i) {
     117          11 :                         return path;
     118             :                 }
     119             : 
     120           5 :                 if (i >= 2 && (path[i -1] == '.' || path[i -1] == ':')) {
     121             :                         /* i is the position of . or :, add 1 for / */
     122           0 :                         path_begin = path + i + 1;
     123           0 :                         break;
     124             :                 }
     125           5 :                 i--;
     126           5 :         }
     127             : 
     128           0 :         return path_begin;
     129             : }
     130             : /* }}} */
     131             : 
     132             : # define CWD_STATE_ALLOC(l) emalloc(l)
     133             : # define CWD_STATE_FREE(s)  efree(s)
     134             : 
     135             : /* {{{ php_zip_extract_file */
     136          11 : static int php_zip_extract_file(struct zip * za, char *dest, char *file, int file_len)
     137             : {
     138             :         php_stream_statbuf ssb;
     139             :         struct zip_file *zf;
     140             :         struct zip_stat sb;
     141             :         char b[8192];
     142             :         int n, len, ret;
     143             :         php_stream *stream;
     144             :         char *fullpath;
     145             :         char *file_dirname_fullpath;
     146             :         char file_dirname[MAXPATHLEN];
     147             :         size_t dir_len;
     148          11 :         int is_dir_only = 0;
     149             :         char *path_cleaned;
     150             :         size_t path_cleaned_len;
     151             :         cwd_state new_state;
     152             :         zend_string *file_basename;
     153             : 
     154          11 :         new_state.cwd = CWD_STATE_ALLOC(1);
     155          11 :         new_state.cwd[0] = '\0';
     156          11 :         new_state.cwd_length = 0;
     157             : 
     158             :         /* Clean/normlize the path and then transform any path (absolute or relative)
     159             :                  to a path relative to cwd (../../mydir/foo.txt > mydir/foo.txt)
     160             :          */
     161          11 :         virtual_file_ex(&new_state, file, NULL, CWD_EXPAND);
     162          11 :         path_cleaned =  php_zip_make_relative_path(new_state.cwd, new_state.cwd_length);
     163          11 :         if(!path_cleaned) {
     164           0 :                 return 0;
     165             :         }
     166          11 :         path_cleaned_len = strlen(path_cleaned);
     167             : 
     168          11 :         if (path_cleaned_len >= MAXPATHLEN || zip_stat(za, file, 0, &sb) != 0) {
     169           0 :                 return 0;
     170             :         }
     171             : 
     172             :         /* it is a directory only, see #40228 */
     173          14 :         if (path_cleaned_len > 1 && IS_SLASH(path_cleaned[path_cleaned_len - 1])) {
     174           3 :                 len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file);
     175           3 :                 is_dir_only = 1;
     176             :         } else {
     177           8 :                 memcpy(file_dirname, path_cleaned, path_cleaned_len);
     178           8 :                 dir_len = php_dirname(file_dirname, path_cleaned_len);
     179             : 
     180          15 :                 if (dir_len <= 0 || (dir_len == 1 && file_dirname[0] == '.')) {
     181           7 :                         len = spprintf(&file_dirname_fullpath, 0, "%s", dest);
     182             :                 } else {
     183           1 :                         len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file_dirname);
     184             :                 }
     185             : 
     186           8 :                 file_basename = php_basename(path_cleaned, path_cleaned_len, NULL, 0);
     187             : 
     188           8 :                 if (ZIP_OPENBASEDIR_CHECKPATH(file_dirname_fullpath)) {
     189           0 :                         efree(file_dirname_fullpath);
     190             :                         zend_string_release(file_basename);
     191           0 :                         CWD_STATE_FREE(new_state.cwd);
     192           0 :                         return 0;
     193             :                 }
     194             :         }
     195             : 
     196             :         /* let see if the path already exists */
     197          11 :         if (php_stream_stat_path_ex(file_dirname_fullpath, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL) < 0) {
     198           3 :                 ret = php_stream_mkdir(file_dirname_fullpath, 0777,  PHP_STREAM_MKDIR_RECURSIVE|REPORT_ERRORS, NULL);
     199           3 :                 if (!ret) {
     200           0 :                         efree(file_dirname_fullpath);
     201           0 :                         if (!is_dir_only) {
     202             :                                 zend_string_release(file_basename);
     203           0 :                                 CWD_STATE_FREE(new_state.cwd);
     204             :                         }
     205           0 :                         return 0;
     206             :                 }
     207             :         }
     208             : 
     209             :         /* it is a standalone directory, job done */
     210          11 :         if (is_dir_only) {
     211           3 :                 efree(file_dirname_fullpath);
     212           3 :                 CWD_STATE_FREE(new_state.cwd);
     213           3 :                 return 1;
     214             :         }
     215             : 
     216           8 :         len = spprintf(&fullpath, 0, "%s/%s", file_dirname_fullpath, file_basename->val);
     217           8 :         if (!len) {
     218           0 :                 efree(file_dirname_fullpath);
     219             :                 zend_string_release(file_basename);
     220           0 :                 CWD_STATE_FREE(new_state.cwd);
     221           0 :                 return 0;
     222           8 :         } else if (len > MAXPATHLEN) {
     223           0 :                 php_error_docref(NULL, E_WARNING, "Full extraction path exceed MAXPATHLEN (%i)", MAXPATHLEN);
     224           0 :                 efree(file_dirname_fullpath);
     225             :                 zend_string_release(file_basename);
     226           0 :                 CWD_STATE_FREE(new_state.cwd);
     227           0 :                 return 0;
     228             :         }
     229             : 
     230             :         /* check again the full path, not sure if it
     231             :          * is required, does a file can have a different
     232             :          * safemode status as its parent folder?
     233             :          */
     234           8 :         if (ZIP_OPENBASEDIR_CHECKPATH(fullpath)) {
     235           0 :                 efree(fullpath);
     236           0 :                 efree(file_dirname_fullpath);
     237             :                 zend_string_release(file_basename);
     238           0 :                 CWD_STATE_FREE(new_state.cwd);
     239           0 :                 return 0;
     240             :         }
     241             : 
     242           8 :         stream = php_stream_open_wrapper(fullpath, "w+b", REPORT_ERRORS, NULL);
     243             : 
     244           8 :         if (stream == NULL) {
     245           1 :                 n = -1;
     246           1 :                 goto done;
     247             :         }
     248             : 
     249           7 :         zf = zip_fopen(za, file, 0);
     250           7 :         if (zf == NULL) {
     251           0 :                 n = -1;
     252           0 :                 php_stream_close(stream);
     253           0 :                 goto done;
     254             :         }
     255             : 
     256           7 :         n = 0;
     257             : 
     258          21 :         while ((n=zip_fread(zf, b, sizeof(b))) > 0) {
     259           7 :                 php_stream_write(stream, b, n);
     260             :         }
     261             : 
     262           7 :         php_stream_close(stream);
     263           7 :         n = zip_fclose(zf);
     264             : 
     265             : done:
     266           8 :         efree(fullpath);
     267             :         zend_string_release(file_basename);
     268           8 :         efree(file_dirname_fullpath);
     269           8 :         CWD_STATE_FREE(new_state.cwd);
     270             : 
     271           8 :         if (n<0) {
     272           1 :                 return 0;
     273             :         } else {
     274           7 :                 return 1;
     275             :         }
     276             : }
     277             : /* }}} */
     278             : 
     279           8 : static int php_zip_add_file(struct zip *za, const char *filename, size_t filename_len,
     280             :         char *entry_name, size_t entry_name_len, long offset_start, long offset_len) /* {{{ */
     281             : {
     282             :         struct zip_source *zs;
     283             :         char resolved_path[MAXPATHLEN];
     284             :         zval exists_flag;
     285             : 
     286             : 
     287           8 :         if (ZIP_OPENBASEDIR_CHECKPATH(filename)) {
     288           0 :                 return -1;
     289             :         }
     290             : 
     291           8 :         if (!expand_filepath(filename, resolved_path)) {
     292           0 :                 return -1;
     293             :         }
     294             : 
     295           8 :         php_stat(resolved_path, strlen(resolved_path), FS_EXISTS, &exists_flag);
     296           8 :         if (Z_TYPE(exists_flag) == IS_FALSE) {
     297           2 :                 return -1;
     298             :         }
     299             : 
     300           6 :         zs = zip_source_file(za, resolved_path, offset_start, offset_len);
     301           6 :         if (!zs) {
     302           0 :                 return -1;
     303             :         }
     304           6 :         if (zip_file_add(za, entry_name, zs, ZIP_FL_OVERWRITE) < 0) {
     305           0 :                 zip_source_free(zs);
     306           0 :                 return -1;
     307             :         } else {
     308           6 :                 zip_error_clear(za);
     309           6 :                 return 1;
     310             :         }
     311             : }
     312             : /* }}} */
     313             : 
     314           2 : 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) /* {{{ */
     315             : {
     316             :         zval *option;
     317           2 :         if ((option = zend_hash_str_find(HASH_OF(options), "remove_all_path", sizeof("remove_all_path") - 1)) != NULL) {
     318             :                 zend_long opt;
     319           1 :                 if (Z_TYPE_P(option) != IS_LONG) {
     320             :                         zval tmp;
     321           1 :                         ZVAL_DUP(&tmp, option);
     322           1 :                         convert_to_long(&tmp);
     323           1 :                         opt = Z_LVAL(tmp);
     324             :                 } else {
     325           0 :                         opt = Z_LVAL_P(option);
     326             :                 }
     327           1 :                 *remove_all_path = opt;
     328             :         }
     329             : 
     330             :         /* If I add more options, it would make sense to create a nice static struct and loop over it. */
     331           2 :         if ((option = zend_hash_str_find(HASH_OF(options), "remove_path", sizeof("remove_path") - 1)) != NULL) {
     332           1 :                 if (Z_TYPE_P(option) != IS_STRING) {
     333           0 :                         php_error_docref(NULL, E_WARNING, "remove_path option expected to be a string");
     334           0 :                         return -1;
     335             :                 }
     336             : 
     337           1 :                 if (Z_STRLEN_P(option) < 1) {
     338           0 :                         php_error_docref(NULL, E_NOTICE, "Empty string given as remove_path option");
     339           0 :                         return -1;
     340             :                 }
     341             : 
     342           1 :                 if (Z_STRLEN_P(option) >= MAXPATHLEN) {
     343           0 :                         php_error_docref(NULL, E_WARNING, "remove_path string is too long (max: %i, %i given)",
     344           0 :                                                 MAXPATHLEN - 1, Z_STRLEN_P(option));
     345           0 :                         return -1;
     346             :                 }
     347           1 :                 *remove_path_len = Z_STRLEN_P(option);
     348           1 :                 *remove_path = Z_STRVAL_P(option);
     349             :         }
     350             : 
     351           2 :         if ((option = zend_hash_str_find(HASH_OF(options), "add_path", sizeof("add_path") - 1)) != NULL) {
     352           2 :                 if (Z_TYPE_P(option) != IS_STRING) {
     353           0 :                         php_error_docref(NULL, E_WARNING, "add_path option expected to be a string");
     354           0 :                         return -1;
     355             :                 }
     356             : 
     357           2 :                 if (Z_STRLEN_P(option) < 1) {
     358           0 :                         php_error_docref(NULL, E_NOTICE, "Empty string given as the add_path option");
     359           0 :                         return -1;
     360             :                 }
     361             : 
     362           2 :                 if (Z_STRLEN_P(option) >= MAXPATHLEN) {
     363           0 :                         php_error_docref(NULL, E_WARNING, "add_path string too long (max: %i, %i given)",
     364           0 :                                                 MAXPATHLEN - 1, Z_STRLEN_P(option));
     365           0 :                         return -1;
     366             :                 }
     367           2 :                 *add_path_len = Z_STRLEN_P(option);
     368           2 :                 *add_path = Z_STRVAL_P(option);
     369             :         }
     370           2 :         return 1;
     371             : }
     372             : /* }}} */
     373             : 
     374             : /* {{{ REGISTER_ZIP_CLASS_CONST_LONG */
     375             : #define REGISTER_ZIP_CLASS_CONST_LONG(const_name, value) \
     376             :             zend_declare_class_constant_long(zip_class_entry, const_name, sizeof(const_name)-1, (zend_long)value);
     377             : /* }}} */
     378             : 
     379             : /* {{{ ZIP_FROM_OBJECT */
     380             : #define ZIP_FROM_OBJECT(intern, object) \
     381             :         { \
     382             :                 ze_zip_object *obj = Z_ZIP_P(object); \
     383             :                 intern = obj->za; \
     384             :                 if (!intern) { \
     385             :                         php_error_docref(NULL, E_WARNING, "Invalid or uninitialized Zip object"); \
     386             :                         RETURN_FALSE; \
     387             :                 } \
     388             :         }
     389             : /* }}} */
     390             : 
     391             : /* {{{ RETURN_SB(sb) */
     392             : #define RETURN_SB(sb) \
     393             :         { \
     394             :                 array_init(return_value); \
     395             :                 add_ascii_assoc_string(return_value, "name", (char *)(sb)->name); \
     396             :                 add_ascii_assoc_long(return_value, "index", (zend_long) (sb)->index); \
     397             :                 add_ascii_assoc_long(return_value, "crc", (zend_long) (sb)->crc); \
     398             :                 add_ascii_assoc_long(return_value, "size", (zend_long) (sb)->size); \
     399             :                 add_ascii_assoc_long(return_value, "mtime", (zend_long) (sb)->mtime); \
     400             :                 add_ascii_assoc_long(return_value, "comp_size", (zend_long) (sb)->comp_size); \
     401             :                 add_ascii_assoc_long(return_value, "comp_method", (zend_long) (sb)->comp_method); \
     402             :         }
     403             : /* }}} */
     404             : 
     405          22 : static int php_zip_status(struct zip *za) /* {{{ */
     406             : {
     407             :         int zep, syp;
     408             : 
     409          22 :         zip_error_get(za, &zep, &syp);
     410          22 :         return zep;
     411             : }
     412             : /* }}} */
     413             : 
     414           3 : static int php_zip_status_sys(struct zip *za) /* {{{ */
     415             : {
     416             :         int zep, syp;
     417             : 
     418           3 :         zip_error_get(za, &zep, &syp);
     419           3 :         return syp;
     420             : }
     421             : /* }}} */
     422             : 
     423          65 : static int php_zip_get_num_files(struct zip *za) /* {{{ */
     424             : {
     425          65 :         return zip_get_num_files(za);
     426             : }
     427             : /* }}} */
     428             : 
     429           6 : static char * php_zipobj_get_filename(ze_zip_object *obj) /* {{{ */
     430             : {
     431             : 
     432           6 :         if (!obj) {
     433           0 :                 return NULL;
     434             :         }
     435             : 
     436           6 :         if (obj->filename) {
     437           6 :                 return obj->filename;
     438             :         }
     439           0 :         return NULL;
     440             : }
     441             : /* }}} */
     442             : 
     443           6 : static char * php_zipobj_get_zip_comment(struct zip *za, int *len) /* {{{ */
     444             : {
     445           6 :         if (za) {
     446           6 :                 return (char *)zip_get_archive_comment(za, len, 0);
     447             :         }
     448           0 :         return NULL;
     449             : }
     450             : /* }}} */
     451             : 
     452             : #ifdef HAVE_GLOB /* {{{ */
     453             : #ifndef GLOB_ONLYDIR
     454             : #define GLOB_ONLYDIR (1<<30)
     455             : #define GLOB_EMULATE_ONLYDIR
     456             : #define GLOB_FLAGMASK (~GLOB_ONLYDIR)
     457             : #else
     458             : #define GLOB_FLAGMASK (~0)
     459             : #endif
     460             : #ifndef GLOB_BRACE
     461             : # define GLOB_BRACE 0
     462             : #endif
     463             : #ifndef GLOB_MARK
     464             : # define GLOB_MARK 0
     465             : #endif
     466             : #ifndef GLOB_NOSORT
     467             : # define GLOB_NOSORT 0
     468             : #endif
     469             : #ifndef GLOB_NOCHECK
     470             : # define GLOB_NOCHECK 0
     471             : #endif
     472             : #ifndef GLOB_NOESCAPE
     473             : # define GLOB_NOESCAPE 0
     474             : #endif
     475             : #ifndef GLOB_ERR
     476             : # define GLOB_ERR 0
     477             : #endif
     478             : 
     479             : /* This is used for checking validity of passed flags (passing invalid flags causes segfault in glob()!! */
     480             : #define GLOB_AVAILABLE_FLAGS (0 | GLOB_BRACE | GLOB_MARK | GLOB_NOSORT | GLOB_NOCHECK | GLOB_NOESCAPE | GLOB_ERR | GLOB_ONLYDIR)
     481             : 
     482             : #endif /* }}} */
     483             : 
     484           1 : int php_zip_glob(char *pattern, int pattern_len, zend_long flags, zval *return_value) /* {{{ */
     485             : {
     486             : #ifdef HAVE_GLOB
     487             :         char cwd[MAXPATHLEN];
     488           1 :         int cwd_skip = 0;
     489             : #ifdef ZTS
     490             :         char work_pattern[MAXPATHLEN];
     491             :         char *result;
     492             : #endif
     493             :         glob_t globbuf;
     494             :         int n;
     495             :         int ret;
     496             : 
     497           1 :         if (pattern_len >= MAXPATHLEN) {
     498           0 :                 php_error_docref(NULL, E_WARNING, "Pattern exceeds the maximum allowed length of %d characters", MAXPATHLEN);
     499           0 :                 return -1;
     500             :         }
     501             : 
     502           1 :         if ((GLOB_AVAILABLE_FLAGS & flags) != flags) {
     503           0 :                 php_error_docref(NULL, E_WARNING, "At least one of the passed flags is invalid or not supported on this platform");
     504           0 :                 return -1;
     505             :         }
     506             : 
     507             : #ifdef ZTS
     508             :         if (!IS_ABSOLUTE_PATH(pattern, pattern_len)) {
     509             :                 result = VCWD_GETCWD(cwd, MAXPATHLEN);
     510             :                 if (!result) {
     511             :                         cwd[0] = '\0';
     512             :                 }
     513             : #ifdef PHP_WIN32
     514             :                 if (IS_SLASH(*pattern)) {
     515             :                         cwd[2] = '\0';
     516             :                 }
     517             : #endif
     518             :                 cwd_skip = strlen(cwd)+1;
     519             : 
     520             :                 snprintf(work_pattern, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, pattern);
     521             :                 pattern = work_pattern;
     522             :         }
     523             : #endif
     524             : 
     525           1 :         globbuf.gl_offs = 0;
     526           1 :         if (0 != (ret = glob(pattern, flags & GLOB_FLAGMASK, NULL, &globbuf))) {
     527             : #ifdef GLOB_NOMATCH
     528           0 :                 if (GLOB_NOMATCH == ret) {
     529             :                         /* Some glob implementation simply return no data if no matches
     530             :                            were found, others return the GLOB_NOMATCH error code.
     531             :                            We don't want to treat GLOB_NOMATCH as an error condition
     532             :                            so that PHP glob() behaves the same on both types of
     533             :                            implementations and so that 'foreach (glob() as ...'
     534             :                            can be used for simple glob() calls without further error
     535             :                            checking.
     536             :                         */
     537           0 :                         array_init(return_value);
     538           0 :                         return 0;
     539             :                 }
     540             : #endif
     541           0 :                 return 0;
     542             :         }
     543             : 
     544             :         /* now catch the FreeBSD style of "no matches" */
     545           1 :         if (!globbuf.gl_pathc || !globbuf.gl_pathv) {
     546           0 :                 array_init(return_value);
     547           0 :                 return 0;
     548             :         }
     549             : 
     550             :         /* we assume that any glob pattern will match files from one directory only
     551             :            so checking the dirname of the first match should be sufficient */
     552           1 :         strncpy(cwd, globbuf.gl_pathv[0], MAXPATHLEN);
     553           1 :         if (ZIP_OPENBASEDIR_CHECKPATH(cwd)) {
     554           0 :                 return -1;
     555             :         }
     556             : 
     557           1 :         array_init(return_value);
     558           3 :         for (n = 0; n < globbuf.gl_pathc; n++) {
     559             :                 /* we need to do this every time since GLOB_ONLYDIR does not guarantee that
     560             :                  * all directories will be filtered. GNU libc documentation states the
     561             :                  * following:
     562             :                  * If the information about the type of the file is easily available
     563             :                  * non-directories will be rejected but no extra work will be done to
     564             :                  * determine the information for each file. I.e., the caller must still be
     565             :                  * able to filter directories out.
     566             :                  */
     567           2 :                 if (flags & GLOB_ONLYDIR) {
     568             :                         zend_stat_t s;
     569             : 
     570           0 :                         if (0 != VCWD_STAT(globbuf.gl_pathv[n], &s)) {
     571           0 :                                 continue;
     572             :                         }
     573             : 
     574           0 :                         if (S_IFDIR != (s.st_mode & S_IFMT)) {
     575           0 :                                 continue;
     576             :                         }
     577             :                 }
     578           2 :                 add_next_index_string(return_value, globbuf.gl_pathv[n]+cwd_skip);
     579             :         }
     580             : 
     581           1 :         globfree(&globbuf);
     582           1 :         return globbuf.gl_pathc;
     583             : #else
     584             :         php_error_docref(NULL, E_ERROR, "Glob support is not available");
     585             :         return 0;
     586             : #endif  /* HAVE_GLOB */
     587             : }
     588             : /* }}} */
     589             : 
     590           1 : int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_value) /* {{{ */
     591             : {
     592             : #ifdef ZTS
     593             :         char cwd[MAXPATHLEN];
     594             :         int cwd_skip = 0;
     595             :         char work_path[MAXPATHLEN];
     596             :         char *result;
     597             : #endif
     598             :         int files_cnt;
     599             :         zend_string **namelist;
     600             : 
     601             : #ifdef ZTS
     602             :         if (!IS_ABSOLUTE_PATH(path, path_len)) {
     603             :                 result = VCWD_GETCWD(cwd, MAXPATHLEN);
     604             :                 if (!result) {
     605             :                         cwd[0] = '\0';
     606             :                 }
     607             : #ifdef PHP_WIN32
     608             :                 if (IS_SLASH(*path)) {
     609             :                         cwd[2] = '\0';
     610             :                 }
     611             : #endif
     612             :                 cwd_skip = strlen(cwd)+1;
     613             : 
     614             :                 snprintf(work_path, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, path);
     615             :                 path = work_path;
     616             :         }
     617             : #endif
     618             : 
     619           1 :         if (ZIP_OPENBASEDIR_CHECKPATH(path)) {
     620           0 :                 return -1;
     621             :         }
     622             : 
     623           1 :         files_cnt = php_stream_scandir(path, &namelist, NULL, (void *) php_stream_dirent_alphasort);
     624             : 
     625           1 :         if (files_cnt > 0) {
     626           1 :                 pcre *re = NULL;
     627           1 :                 pcre_extra *pcre_extra = NULL;
     628           1 :                 int preg_options = 0, i;
     629             : 
     630           1 :                 re = pcre_get_compiled_regex(regexp, &pcre_extra, &preg_options);
     631           1 :                 if (!re) {
     632           0 :                         php_error_docref(NULL, E_WARNING, "Invalid expression");
     633           0 :                         return -1;
     634             :                 }
     635             : 
     636           1 :                 array_init(return_value);
     637             : 
     638             :                 /* only the files, directories are ignored */
     639         123 :                 for (i = 0; i < files_cnt; i++) {
     640             :                         zend_stat_t s;
     641             :                         char   fullpath[MAXPATHLEN];
     642             :                         int    ovector[3];
     643             :                         int    matches;
     644         122 :                         int    namelist_len = namelist[i]->len;
     645             : 
     646         124 :                         if ((namelist_len == 1 && namelist[i]->val[0] == '.') ||
     647           2 :                                 (namelist_len == 2 && namelist[i]->val[0] == '.' && namelist[i]->val[1] == '.')) {
     648           2 :                                 zend_string_release(namelist[i]);
     649           2 :                                 continue;
     650             :                         }
     651             : 
     652         120 :                         if ((path_len + namelist_len + 1) >= MAXPATHLEN) {
     653           0 :                                 php_error_docref(NULL, E_WARNING, "add_path string too long (max: %i, %i given)",
     654           0 :                                                 MAXPATHLEN - 1, (path_len + namelist_len + 1));
     655           0 :                                 zend_string_release(namelist[i]);
     656           0 :                                 break;
     657             :                         }
     658             : 
     659         120 :                         snprintf(fullpath, MAXPATHLEN, "%s%c%s", path, DEFAULT_SLASH, namelist[i]->val);
     660             : 
     661         120 :                         if (0 != VCWD_STAT(fullpath, &s)) {
     662           0 :                                 php_error_docref(NULL, E_WARNING, "Cannot read <%s>", fullpath);
     663           0 :                                 zend_string_release(namelist[i]);
     664           0 :                                 continue;
     665             :                         }
     666             : 
     667         120 :                         if (S_IFDIR == (s.st_mode & S_IFMT)) {
     668           0 :                                 zend_string_release(namelist[i]);
     669           0 :                                 continue;
     670             :                         }
     671             : 
     672         120 :                         matches = pcre_exec(re, NULL, namelist[i]->val, namelist[i]->len, 0, 0, ovector, 3);
     673             :                         /* 0 means that the vector is too small to hold all the captured substring offsets */
     674         120 :                         if (matches < 0) {
     675         118 :                                 zend_string_release(namelist[i]);
     676         118 :                                 continue;
     677             :                         }
     678             : 
     679           2 :                         add_next_index_string(return_value, fullpath);
     680           2 :                         zend_string_release(namelist[i]);
     681             :                 }
     682           1 :                 efree(namelist);
     683             :         }
     684           1 :         return files_cnt;
     685             : }
     686             : /* }}} */
     687             : 
     688             : /* {{{ arginfo */
     689             : ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_open, 0, 0, 1)
     690             :         ZEND_ARG_INFO(0, filename)
     691             : ZEND_END_ARG_INFO()
     692             : 
     693             : ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_close, 0, 0, 1)
     694             :         ZEND_ARG_INFO(0, zip)
     695             : ZEND_END_ARG_INFO()
     696             : 
     697             : ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_read, 0, 0, 1)
     698             :         ZEND_ARG_INFO(0, zip)
     699             : ZEND_END_ARG_INFO()
     700             : 
     701             : ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_open, 0, 0, 2)
     702             :         ZEND_ARG_INFO(0, zip_dp)
     703             :         ZEND_ARG_INFO(0, zip_entry)
     704             :         ZEND_ARG_INFO(0, mode)
     705             : ZEND_END_ARG_INFO()
     706             : 
     707             : ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_close, 0, 0, 1)
     708             :         ZEND_ARG_INFO(0, zip_ent)
     709             : ZEND_END_ARG_INFO()
     710             : 
     711             : ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_read, 0, 0, 1)
     712             :         ZEND_ARG_INFO(0, zip_entry)
     713             :         ZEND_ARG_INFO(0, len)
     714             : ZEND_END_ARG_INFO()
     715             : 
     716             : ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_name, 0, 0, 1)
     717             :         ZEND_ARG_INFO(0, zip_entry)
     718             : ZEND_END_ARG_INFO()
     719             : 
     720             : ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_compressedsize, 0, 0, 1)
     721             :         ZEND_ARG_INFO(0, zip_entry)
     722             : ZEND_END_ARG_INFO()
     723             : 
     724             : ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_filesize, 0, 0, 1)
     725             :         ZEND_ARG_INFO(0, zip_entry)
     726             : ZEND_END_ARG_INFO()
     727             : 
     728             : ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_compressionmethod, 0, 0, 1)
     729             :         ZEND_ARG_INFO(0, zip_entry)
     730             : ZEND_END_ARG_INFO()
     731             : /* }}} */
     732             : 
     733             : /* {{{ zend_function_entry */
     734             : static const zend_function_entry zip_functions[] = {
     735             :         ZEND_RAW_FENTRY("zip_open", zif_zip_open, arginfo_zip_open, 0)
     736             :         ZEND_RAW_FENTRY("zip_close", zif_zip_close, arginfo_zip_close, 0)
     737             :         ZEND_RAW_FENTRY("zip_read", zif_zip_read, arginfo_zip_read, 0)
     738             :         PHP_FE(zip_entry_open,          arginfo_zip_entry_open)
     739             :         PHP_FE(zip_entry_close,         arginfo_zip_entry_close)
     740             :         PHP_FE(zip_entry_read,          arginfo_zip_entry_read)
     741             :         PHP_FE(zip_entry_filesize,      arginfo_zip_entry_filesize)
     742             :         PHP_FE(zip_entry_name,          arginfo_zip_entry_name)
     743             :         PHP_FE(zip_entry_compressedsize,                arginfo_zip_entry_compressedsize)
     744             :         PHP_FE(zip_entry_compressionmethod,             arginfo_zip_entry_compressionmethod)
     745             : #ifdef  PHP_FE_END
     746             :         PHP_FE_END
     747             : #else
     748             :         {NULL,NULL,NULL}
     749             : #endif
     750             : };
     751             : /* }}} */
     752             : 
     753             : /* {{{ ZE2 OO definitions */
     754             : static zend_class_entry *zip_class_entry;
     755             : static zend_object_handlers zip_object_handlers;
     756             : 
     757             : static HashTable zip_prop_handlers;
     758             : 
     759             : typedef int (*zip_read_int_t)(struct zip *za);
     760             : typedef char *(*zip_read_const_char_t)(struct zip *za, int *len);
     761             : typedef char *(*zip_read_const_char_from_ze_t)(ze_zip_object *obj);
     762             : 
     763             : typedef struct _zip_prop_handler {
     764             :         zip_read_int_t read_int_func;
     765             :         zip_read_const_char_t read_const_char_func;
     766             :         zip_read_const_char_from_ze_t read_const_char_from_obj_func;
     767             : 
     768             :         int type;
     769             : } zip_prop_handler;
     770             : /* }}} */
     771             : 
     772      104355 : 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) /* {{{ */
     773             : {
     774             :         zip_prop_handler hnd;
     775             : 
     776      104355 :         hnd.read_const_char_func = read_char_func;
     777      104355 :         hnd.read_int_func = read_int_func;
     778      104355 :         hnd.read_const_char_from_obj_func = read_char_from_obj_func;
     779      104355 :         hnd.type = rettype;
     780      104355 :         zend_hash_str_add_mem(prop_handler, name, strlen(name), &hnd, sizeof(zip_prop_handler));
     781      104355 : }
     782             : /* }}} */
     783             : 
     784         114 : static zval *php_zip_property_reader(ze_zip_object *obj, zip_prop_handler *hnd, zval *rv) /* {{{ */
     785             : {
     786         114 :         const char *retchar = NULL;
     787         114 :         int retint = 0;
     788         114 :         int len = 0;
     789             : 
     790         114 :         if (obj && obj->za != NULL) {
     791         102 :                 if (hnd->read_const_char_func) {
     792           6 :                         retchar = hnd->read_const_char_func(obj->za, &len);
     793             :                 } else {
     794          96 :                         if (hnd->read_int_func) {
     795          90 :                                 retint = hnd->read_int_func(obj->za);
     796          90 :                                 if (retint == -1) {
     797           0 :                                         php_error_docref(NULL, E_WARNING, "Internal zip error returned");
     798           0 :                                         return NULL;
     799             :                                 }
     800             :                         } else {
     801           6 :                                 if (hnd->read_const_char_from_obj_func) {
     802           6 :                                         retchar = hnd->read_const_char_from_obj_func(obj);
     803           6 :                                         len = strlen(retchar);
     804             :                                 }
     805             :                         }
     806             :                 }
     807             :         }
     808             : 
     809         114 :         switch (hnd->type) {
     810             :                 case IS_STRING:
     811          16 :                         if (retchar) {
     812          24 :                                 ZVAL_STRINGL(rv, (char *) retchar, len);
     813             :                         } else {
     814           4 :                                 ZVAL_EMPTY_STRING(rv);
     815             :                         }
     816          16 :                         break;
     817             :                 /* case IS_TRUE */
     818             :                 case IS_FALSE:
     819           0 :                         ZVAL_BOOL(rv, (long)retint);
     820           0 :                         break;
     821             :                 case IS_LONG:
     822          98 :                         ZVAL_LONG(rv, (long)retint);
     823          98 :                         break;
     824             :                 default:
     825           0 :                         ZVAL_NULL(rv);
     826             :         }
     827             : 
     828         114 :         return rv;
     829             : }
     830             : /* }}} */
     831             : 
     832           3 : static zval *php_zip_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot) /* {{{ */
     833             : {
     834             :         ze_zip_object *obj;
     835             :         zval tmp_member;
     836           3 :         zval *retval = NULL;
     837           3 :         zip_prop_handler *hnd = NULL;
     838             :         zend_object_handlers *std_hnd;
     839             : 
     840           3 :         if (Z_TYPE_P(member) != IS_STRING) {
     841           0 :                 ZVAL_DUP(&tmp_member, member);
     842           0 :                 convert_to_string(&tmp_member);
     843           0 :                 member = &tmp_member;
     844           0 :                 cache_slot = NULL;
     845             :         }
     846             : 
     847           3 :         obj = Z_ZIP_P(object);
     848             : 
     849           3 :         if (obj->prop_handler != NULL) {
     850           6 :                 hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member));
     851             :         }
     852             : 
     853           3 :         if (hnd == NULL) {
     854           3 :                 std_hnd = zend_get_std_object_handlers();
     855           3 :                 retval = std_hnd->get_property_ptr_ptr(object, member, type, cache_slot);
     856             :         }
     857             : 
     858           3 :         if (member == &tmp_member) {
     859             :                 zval_dtor(member);
     860             :         }
     861             : 
     862           3 :         return retval;
     863             : }
     864             : /* }}} */
     865             : 
     866          86 : static zval *php_zip_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv) /* {{{ */
     867             : {
     868             :         ze_zip_object *obj;
     869             :         zval tmp_member;
     870          86 :         zval *retval = NULL;
     871          86 :         zip_prop_handler *hnd = NULL;
     872             :         zend_object_handlers *std_hnd;
     873             : 
     874          86 :         if (Z_TYPE_P(member) != IS_STRING) {
     875           0 :                 ZVAL_DUP(&tmp_member, member);
     876           0 :                 convert_to_string(&tmp_member);
     877           0 :                 member = &tmp_member;
     878           0 :                 cache_slot = NULL;
     879             :         }
     880             : 
     881          86 :         obj = Z_ZIP_P(object);
     882             : 
     883          86 :         if (obj->prop_handler != NULL) {
     884         172 :                 hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member));
     885             :         }
     886             : 
     887          86 :         if (hnd != NULL) {
     888          82 :                 retval = php_zip_property_reader(obj, hnd, rv);
     889          82 :                 if (retval == NULL) {
     890           0 :                         retval = &EG(uninitialized_zval);
     891             :                 }
     892             :         } else {
     893           4 :                 std_hnd = zend_get_std_object_handlers();
     894           4 :                 retval = std_hnd->read_property(object, member, type, cache_slot, rv);
     895             :         }
     896             : 
     897          86 :         if (member == &tmp_member) {
     898             :                 zval_dtor(member);
     899             :         }
     900             : 
     901          86 :         return retval;
     902             : }
     903             : /* }}} */
     904             : 
     905          14 : static int php_zip_has_property(zval *object, zval *member, int type, void **cache_slot) /* {{{ */
     906             : {
     907             :         ze_zip_object *obj;
     908             :         zval tmp_member;
     909          14 :         zip_prop_handler *hnd = NULL;
     910             :         zend_object_handlers *std_hnd;
     911          14 :         int retval = 0;
     912             : 
     913          14 :         if (Z_TYPE_P(member) != IS_STRING) {
     914           0 :                 ZVAL_DUP(&tmp_member, member);
     915           0 :                 convert_to_string(&tmp_member);
     916           0 :                 member = &tmp_member;
     917           0 :                 cache_slot = NULL;
     918             :         }
     919             : 
     920          14 :         obj = Z_ZIP_P(object);
     921             : 
     922          14 :         if (obj->prop_handler != NULL) {
     923          28 :                 hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member));
     924             :         }
     925             : 
     926          14 :         if (hnd != NULL) {
     927             :                 zval tmp, *prop;
     928             : 
     929          12 :                 if (type == 2) {
     930           0 :                         retval = 1;
     931          12 :                 } else if ((prop = php_zip_property_reader(obj, hnd, &tmp)) != NULL) {
     932          12 :                         if (type == 1) {
     933           6 :                                 retval = zend_is_true(&tmp);
     934           6 :                         } else if (type == 0) {
     935           6 :                                 retval = (Z_TYPE(tmp) != IS_NULL);
     936             :                         }
     937             :                 }
     938             : 
     939          12 :                 zval_ptr_dtor(&tmp);
     940             :         } else {
     941           2 :                 std_hnd = zend_get_std_object_handlers();
     942           2 :                 retval = std_hnd->has_property(object, member, type, cache_slot);
     943             :         }
     944             : 
     945          14 :         if (member == &tmp_member) {
     946             :                 zval_dtor(member);
     947             :         }
     948             : 
     949          14 :         return retval;
     950             : }
     951             : /* }}} */
     952             : 
     953           4 : static HashTable *php_zip_get_properties(zval *object)/* {{{ */
     954             : {
     955             :         ze_zip_object *obj;
     956             :         HashTable *props;
     957             :         zip_prop_handler *hnd;
     958             :         zend_string *key;
     959             :         zend_ulong num_key;
     960             : 
     961           4 :         obj = Z_ZIP_P(object);
     962           4 :         props = zend_std_get_properties(object);
     963             : 
     964           4 :         if (obj->prop_handler == NULL) {
     965           0 :                 return NULL;
     966             :         }
     967             : 
     968          44 :         ZEND_HASH_FOREACH_KEY_PTR(obj->prop_handler, num_key, key, hnd) {
     969             :                 zval *ret, val;
     970          20 :                 ret = php_zip_property_reader(obj, hnd, &val);
     971          20 :                 if (ret == NULL) {
     972           0 :                         ret = &EG(uninitialized_zval);
     973             :                 }
     974          20 :                 zend_hash_update(props, key, ret);
     975             :         } ZEND_HASH_FOREACH_END();
     976             : 
     977           4 :         return props;
     978             : }
     979             : /* }}} */
     980             : 
     981          50 : static void php_zip_object_free_storage(zend_object *object) /* {{{ */
     982             : {
     983          50 :         ze_zip_object * intern = php_zip_fetch_object(object);
     984             :         int i;
     985             : 
     986          50 :         if (!intern) {
     987           0 :                 return;
     988             :         }
     989          50 :         if (intern->za) {
     990          10 :                 if (zip_close(intern->za) != 0) {
     991           0 :                         php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context");
     992           0 :                         return;
     993             :                 }
     994          10 :                 intern->za = NULL;
     995             :         }
     996             : 
     997          50 :         if (intern->buffers_cnt>0) {
     998          51 :                 for (i=0; i<intern->buffers_cnt; i++) {
     999          32 :                         efree(intern->buffers[i]);
    1000             :                 }
    1001          19 :                 efree(intern->buffers);
    1002             :         }
    1003             : 
    1004          50 :         intern->za = NULL;
    1005          50 :         zend_object_std_dtor(&intern->zo);
    1006             : 
    1007          50 :         if (intern->filename) {
    1008          10 :                 efree(intern->filename);
    1009             :         }
    1010             : }
    1011             : /* }}} */
    1012             : 
    1013          50 : static zend_object *php_zip_object_new(zend_class_entry *class_type) /* {{{ */
    1014             : {
    1015             :         ze_zip_object *intern;
    1016             : 
    1017          50 :         intern = ecalloc(1, sizeof(ze_zip_object) + zend_object_properties_size(class_type));
    1018          50 :         intern->prop_handler = &zip_prop_handlers;
    1019          50 :         zend_object_std_init(&intern->zo, class_type);
    1020          50 :         object_properties_init(&intern->zo, class_type);
    1021          50 :         intern->zo.handlers = &zip_object_handlers;
    1022             : 
    1023          50 :         return &intern->zo;
    1024             : }
    1025             : /* }}} */
    1026             : 
    1027             : /* {{{ Resource dtors */
    1028             : 
    1029             : /* {{{ php_zip_free_dir */
    1030          12 : static void php_zip_free_dir(zend_resource *rsrc)
    1031             : {
    1032          12 :         zip_rsrc * zip_int = (zip_rsrc *) rsrc->ptr;
    1033             : 
    1034          12 :         if (zip_int) {
    1035          12 :                 if (zip_int->za) {
    1036          12 :                         if (zip_close(zip_int->za) != 0) {
    1037           0 :                                 php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context");
    1038             :                         }
    1039          12 :                         zip_int->za = NULL;
    1040             :                 }
    1041             : 
    1042          12 :                 efree(rsrc->ptr);
    1043             : 
    1044          12 :                 rsrc->ptr = NULL;
    1045             :         }
    1046          12 : }
    1047             : /* }}} */
    1048             : 
    1049             : /* {{{ php_zip_free_entry */
    1050          24 : static void php_zip_free_entry(zend_resource *rsrc)
    1051             : {
    1052          24 :         zip_read_rsrc *zr_rsrc = (zip_read_rsrc *) rsrc->ptr;
    1053             : 
    1054          24 :         if (zr_rsrc) {
    1055          24 :                 if (zr_rsrc->zf) {
    1056          24 :                         zip_fclose(zr_rsrc->zf);
    1057          24 :                         zr_rsrc->zf = NULL;
    1058             :                 }
    1059          24 :                 efree(zr_rsrc);
    1060          24 :                 rsrc->ptr = NULL;
    1061             :         }
    1062          24 : }
    1063             : /* }}} */
    1064             : 
    1065             : /* }}}*/
    1066             : 
    1067             : /* reset macro */
    1068             : 
    1069             : /* {{{ function prototypes */
    1070             : static PHP_MINIT_FUNCTION(zip);
    1071             : static PHP_MSHUTDOWN_FUNCTION(zip);
    1072             : static PHP_MINFO_FUNCTION(zip);
    1073             : /* }}} */
    1074             : 
    1075             : /* {{{ zip_module_entry
    1076             :  */
    1077             : zend_module_entry zip_module_entry = {
    1078             :         STANDARD_MODULE_HEADER,
    1079             :         "zip",
    1080             :         zip_functions,
    1081             :         PHP_MINIT(zip),
    1082             :         PHP_MSHUTDOWN(zip),
    1083             :         NULL,
    1084             :         NULL,
    1085             :         PHP_MINFO(zip),
    1086             :         PHP_ZIP_VERSION,
    1087             :         STANDARD_MODULE_PROPERTIES
    1088             : };
    1089             : /* }}} */
    1090             : 
    1091             : #ifdef COMPILE_DL_ZIP
    1092             : ZEND_GET_MODULE(zip)
    1093             : #endif
    1094             : /* set macro */
    1095             : 
    1096             : /* {{{ proto resource zip_open(string filename)
    1097             : Create new zip using source uri for output */
    1098          15 : static PHP_NAMED_FUNCTION(zif_zip_open)
    1099             : {
    1100             :         char resolved_path[MAXPATHLEN + 1];
    1101             :         zip_rsrc *rsrc_int;
    1102          15 :         int err = 0;
    1103             :         zend_string *filename;
    1104             : 
    1105          15 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &filename) == FAILURE) {
    1106           1 :                 return;
    1107             :         }
    1108             : 
    1109          14 :         if (filename->len == 0) {
    1110           1 :                 php_error_docref(NULL, E_WARNING, "Empty string as source");
    1111           1 :                 RETURN_FALSE;
    1112             :         }
    1113             : 
    1114          13 :         if (ZIP_OPENBASEDIR_CHECKPATH(filename->val)) {
    1115           0 :                 RETURN_FALSE;
    1116             :         }
    1117             : 
    1118          13 :         if(!expand_filepath(filename->val, resolved_path)) {
    1119           0 :                 RETURN_FALSE;
    1120             :         }
    1121             : 
    1122          13 :         rsrc_int = (zip_rsrc *)emalloc(sizeof(zip_rsrc));
    1123             : 
    1124          13 :         rsrc_int->za = zip_open(resolved_path, 0, &err);
    1125          13 :         if (rsrc_int->za == NULL) {
    1126           1 :                 efree(rsrc_int);
    1127           1 :                 RETURN_LONG((zend_long)err);
    1128             :         }
    1129             : 
    1130          12 :         rsrc_int->index_current = 0;
    1131          12 :         rsrc_int->num_files = zip_get_num_files(rsrc_int->za);
    1132             : 
    1133          12 :         RETURN_RES(zend_register_resource(rsrc_int, le_zip_dir));
    1134             : }
    1135             : /* }}} */
    1136             : 
    1137             : /* {{{ proto void zip_close(resource zip)
    1138             :    Close a Zip archive */
    1139          11 : static PHP_NAMED_FUNCTION(zif_zip_close)
    1140             : {
    1141             :         zval * zip;
    1142          11 :         zip_rsrc *z_rsrc = NULL;
    1143             : 
    1144          11 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zip) == FAILURE) {
    1145           0 :                 return;
    1146             :         }
    1147             : 
    1148          11 :         if ((z_rsrc = (zip_rsrc *)zend_fetch_resource(Z_RES_P(zip), le_zip_dir_name, le_zip_dir)) == NULL) {
    1149           1 :                 RETURN_FALSE;
    1150             :         }
    1151             : 
    1152             :         /* really close the zip will break BC :-D */
    1153          10 :         zend_list_close(Z_RES_P(zip));
    1154             : }
    1155             : /* }}} */
    1156             : 
    1157             : /* {{{ proto resource zip_read(resource zip)
    1158             :    Returns the next file in the archive */
    1159          29 : static PHP_NAMED_FUNCTION(zif_zip_read)
    1160             : {
    1161             :         zval *zip_dp;
    1162             :         zip_read_rsrc *zr_rsrc;
    1163             :         int ret;
    1164             :         zip_rsrc *rsrc_int;
    1165             : 
    1166          29 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zip_dp) == FAILURE) {
    1167           0 :                 return;
    1168             :         }
    1169             : 
    1170          29 :         if ((rsrc_int = (zip_rsrc *)zend_fetch_resource(Z_RES_P(zip_dp), le_zip_dir_name, le_zip_dir)) == NULL) {
    1171           0 :                 RETURN_FALSE;
    1172             :         }
    1173             : 
    1174          29 :         if (rsrc_int && rsrc_int->za) {
    1175          29 :                 if (rsrc_int->index_current >= rsrc_int->num_files) {
    1176           5 :                         RETURN_FALSE;
    1177             :                 }
    1178             : 
    1179          24 :                 zr_rsrc = emalloc(sizeof(zip_read_rsrc));
    1180             : 
    1181          24 :                 ret = zip_stat_index(rsrc_int->za, rsrc_int->index_current, 0, &zr_rsrc->sb);
    1182             : 
    1183          24 :                 if (ret != 0) {
    1184           0 :                         efree(zr_rsrc);
    1185           0 :                         RETURN_FALSE;
    1186             :                 }
    1187             : 
    1188          24 :                 zr_rsrc->zf = zip_fopen_index(rsrc_int->za, rsrc_int->index_current, 0);
    1189          24 :                 if (zr_rsrc->zf) {
    1190          24 :                         rsrc_int->index_current++;
    1191          24 :                         RETURN_RES(zend_register_resource(zr_rsrc, le_zip_entry));
    1192             :                 } else {
    1193           0 :                         efree(zr_rsrc);
    1194           0 :                         RETURN_FALSE;
    1195             :                 }
    1196             : 
    1197             :         } else {
    1198           0 :                 RETURN_FALSE;
    1199             :         }
    1200             : }
    1201             : /* }}} */
    1202             : 
    1203             : /* {{{ proto bool zip_entry_open(resource zip_dp, resource zip_entry [, string mode])
    1204             :    Open a Zip File, pointed by the resource entry */
    1205             : /* Dummy function to follow the old API */
    1206           3 : static PHP_NAMED_FUNCTION(zif_zip_entry_open)
    1207             : {
    1208             :         zval * zip;
    1209             :         zval * zip_entry;
    1210           3 :         char *mode = NULL;
    1211           3 :         size_t mode_len = 0;
    1212             :         zip_read_rsrc * zr_rsrc;
    1213             :         zip_rsrc *z_rsrc;
    1214             : 
    1215           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rr|s", &zip, &zip_entry, &mode, &mode_len) == FAILURE) {
    1216           0 :                 return;
    1217             :         }
    1218             : 
    1219           3 :         if ((zr_rsrc = (zip_read_rsrc *)zend_fetch_resource(Z_RES_P(zip_entry), le_zip_entry_name, le_zip_entry)) == NULL) {
    1220           0 :                 RETURN_FALSE;
    1221             :         }
    1222             : 
    1223           3 :         if ((z_rsrc = (zip_rsrc *)zend_fetch_resource(Z_RES_P(zip), le_zip_dir_name, le_zip_dir)) == NULL) {
    1224           0 :                 RETURN_FALSE;
    1225             :         }
    1226             : 
    1227           3 :         if (zr_rsrc->zf != NULL) {
    1228           3 :                 RETURN_TRUE;
    1229             :         } else {
    1230           0 :                 RETURN_FALSE;
    1231             :         }
    1232             : }
    1233             : /* }}} */
    1234             : 
    1235             : /* {{{ proto bool zip_entry_close(resource zip_ent)
    1236             :    Close a zip entry */
    1237           4 : static PHP_NAMED_FUNCTION(zif_zip_entry_close)
    1238             : {
    1239             :         zval * zip_entry;
    1240             :         zip_read_rsrc * zr_rsrc;
    1241             : 
    1242           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zip_entry) == FAILURE) {
    1243           0 :                 return;
    1244             :         }
    1245             : 
    1246           4 :         if ((zr_rsrc = (zip_read_rsrc *)zend_fetch_resource(Z_RES_P(zip_entry), le_zip_entry_name, le_zip_entry)) == NULL) {
    1247           1 :                 RETURN_FALSE;
    1248             :         }
    1249             : 
    1250           3 :         RETURN_BOOL(SUCCESS == zend_list_close(Z_RES_P(zip_entry)));
    1251             : }
    1252             : /* }}} */
    1253             : 
    1254             : /* {{{ proto mixed zip_entry_read(resource zip_entry [, int len])
    1255             :    Read from an open directory entry */
    1256           2 : static PHP_NAMED_FUNCTION(zif_zip_entry_read)
    1257             : {
    1258             :         zval * zip_entry;
    1259           2 :         zend_long len = 0;
    1260             :         zip_read_rsrc * zr_rsrc;
    1261             :         zend_string *buffer;
    1262           2 :         int n = 0;
    1263             : 
    1264           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &zip_entry, &len) == FAILURE) {
    1265           0 :                 return;
    1266             :         }
    1267             : 
    1268           2 :         if ((zr_rsrc = (zip_read_rsrc *)zend_fetch_resource(Z_RES_P(zip_entry), le_zip_entry_name, le_zip_entry)) == NULL) {
    1269           0 :                 RETURN_FALSE;
    1270             :         }
    1271             : 
    1272           2 :         if (len <= 0) {
    1273           1 :                 len = 1024;
    1274             :         }
    1275             : 
    1276           2 :         if (zr_rsrc->zf) {
    1277           4 :                 buffer = zend_string_alloc(len, 0);
    1278           2 :                 n = zip_fread(zr_rsrc->zf, buffer->val, buffer->len);
    1279           2 :                 if (n > 0) {
    1280           2 :                         buffer->val[n] = '\0';
    1281           2 :                         buffer->len = n;
    1282           2 :                         RETURN_STR(buffer);
    1283             :                 } else {
    1284             :                         zend_string_free(buffer);
    1285           0 :                         RETURN_EMPTY_STRING()
    1286             :                 }
    1287             :         } else {
    1288           0 :                 RETURN_FALSE;
    1289             :         }
    1290             : }
    1291             : /* }}} */
    1292             : 
    1293          18 : static void php_zip_entry_get_info(INTERNAL_FUNCTION_PARAMETERS, int opt) /* {{{ */
    1294             : {
    1295             :         zval * zip_entry;
    1296             :         zip_read_rsrc * zr_rsrc;
    1297             : 
    1298          18 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zip_entry) == FAILURE) {
    1299           0 :                 return;
    1300             :         }
    1301             : 
    1302          18 :         if ((zr_rsrc = (zip_read_rsrc *)zend_fetch_resource(Z_RES_P(zip_entry), le_zip_entry_name, le_zip_entry)) == NULL) {
    1303           0 :                 RETURN_FALSE;
    1304             :         }
    1305             : 
    1306          18 :         if (!zr_rsrc->zf) {
    1307           0 :                 RETURN_FALSE;
    1308             :         }
    1309             : 
    1310          18 :         switch (opt) {
    1311             :                 case 0:
    1312           8 :                         RETURN_STRING((char *)zr_rsrc->sb.name);
    1313             :                         break;
    1314             :                 case 1:
    1315           4 :                         RETURN_LONG((zend_long) (zr_rsrc->sb.comp_size));
    1316             :                         break;
    1317             :                 case 2:
    1318           6 :                         RETURN_LONG((zend_long) (zr_rsrc->sb.size));
    1319             :                         break;
    1320             :                 case 3:
    1321           4 :                         switch (zr_rsrc->sb.comp_method) {
    1322             :                                 case 0:
    1323           6 :                                         RETURN_STRING("stored");
    1324             :                                         break;
    1325             :                                 case 1:
    1326           0 :                                         RETURN_STRING("shrunk");
    1327             :                                         break;
    1328             :                                 case 2:
    1329             :                                 case 3:
    1330             :                                 case 4:
    1331             :                                 case 5:
    1332           0 :                                         RETURN_STRING("reduced");
    1333             :                                         break;
    1334             :                                 case 6:
    1335           0 :                                         RETURN_STRING("imploded");
    1336             :                                         break;
    1337             :                                 case 7:
    1338           0 :                                         RETURN_STRING("tokenized");
    1339             :                                         break;
    1340             :                                 case 8:
    1341           2 :                                         RETURN_STRING("deflated");
    1342             :                                         break;
    1343             :                                 case 9:
    1344           0 :                                         RETURN_STRING("deflatedX");
    1345             :                                         break;
    1346             :                                 case 10:
    1347           0 :                                         RETURN_STRING("implodedX");
    1348             :                                         break;
    1349             :                                 default:
    1350           0 :                                         RETURN_FALSE;
    1351             :                         }
    1352             :                         RETURN_LONG((zend_long) (zr_rsrc->sb.comp_method));
    1353             :                         break;
    1354             :         }
    1355             : 
    1356             : }
    1357             : /* }}} */
    1358             : 
    1359             : /* {{{ proto string zip_entry_name(resource zip_entry)
    1360             :    Return the name given a ZZip entry */
    1361           4 : static PHP_NAMED_FUNCTION(zif_zip_entry_name)
    1362             : {
    1363           4 :         php_zip_entry_get_info(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
    1364           4 : }
    1365             : /* }}} */
    1366             : 
    1367             : /* {{{ proto int zip_entry_compressedsize(resource zip_entry)
    1368             :    Return the compressed size of a ZZip entry */
    1369           4 : static PHP_NAMED_FUNCTION(zif_zip_entry_compressedsize)
    1370             : {
    1371           4 :         php_zip_entry_get_info(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
    1372           4 : }
    1373             : /* }}} */
    1374             : 
    1375             : /* {{{ proto int zip_entry_filesize(resource zip_entry)
    1376             :    Return the actual filesize of a ZZip entry */
    1377           6 : static PHP_NAMED_FUNCTION(zif_zip_entry_filesize)
    1378             : {
    1379           6 :         php_zip_entry_get_info(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2);
    1380           6 : }
    1381             : /* }}} */
    1382             : 
    1383             : /* {{{ proto string zip_entry_compressionmethod(resource zip_entry)
    1384             :    Return a string containing the compression method used on a particular entry */
    1385           4 : static PHP_NAMED_FUNCTION(zif_zip_entry_compressionmethod)
    1386             : {
    1387           4 :         php_zip_entry_get_info(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3);
    1388           4 : }
    1389             : /* }}} */
    1390             : 
    1391             : /* {{{ proto mixed ZipArchive::open(string source [, int flags])
    1392             : Create new zip using source uri for output, return TRUE on success or the error code */
    1393          56 : static ZIPARCHIVE_METHOD(open)
    1394             : {
    1395             :         struct zip *intern;
    1396          56 :         int err = 0;
    1397          56 :         zend_long flags = 0;
    1398             :         char *resolved_path;
    1399             :         zend_string *filename;
    1400          56 :         zval *self = getThis();
    1401          56 :         ze_zip_object *ze_obj = NULL;
    1402             : 
    1403          56 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &filename, &flags) == FAILURE) {
    1404           0 :                 return;
    1405             :         }
    1406             : 
    1407          56 :         if (self) {
    1408             :                 /* We do not use ZIP_FROM_OBJECT, zip init function here */
    1409          56 :                 ze_obj = Z_ZIP_P(self);
    1410             :         }
    1411             : 
    1412          56 :         if (filename->len == 0) {
    1413           1 :                 php_error_docref(NULL, E_WARNING, "Empty string as source");
    1414           1 :                 RETURN_FALSE;
    1415             :         }
    1416             : 
    1417          55 :         if (ZIP_OPENBASEDIR_CHECKPATH(filename->val)) {
    1418           0 :                 RETURN_FALSE;
    1419             :         }
    1420             : 
    1421          55 :         if (!(resolved_path = expand_filepath(filename->val, NULL))) {
    1422           0 :                 RETURN_FALSE;
    1423             :         }
    1424             : 
    1425          55 :         if (ze_obj->za) {
    1426             :                 /* we already have an opened zip, free it */
    1427           0 :                 if (zip_close(ze_obj->za) != 0) {
    1428           0 :                         php_error_docref(NULL, E_WARNING, "Empty string as source");
    1429           0 :                         efree(resolved_path);
    1430           0 :                         RETURN_FALSE;
    1431             :                 }
    1432           0 :                 ze_obj->za = NULL;
    1433             :         }
    1434          55 :         if (ze_obj->filename) {
    1435           0 :                 efree(ze_obj->filename);
    1436           0 :                 ze_obj->filename = NULL;
    1437             :         }
    1438             : 
    1439          55 :         intern = zip_open(resolved_path, flags, &err);
    1440          55 :         if (!intern || err) {
    1441           2 :                 efree(resolved_path);
    1442           2 :                 RETURN_LONG((zend_long)err);
    1443             :         }
    1444          53 :         ze_obj->filename = resolved_path;
    1445          53 :         ze_obj->filename_len = strlen(resolved_path);
    1446          53 :         ze_obj->za = intern;
    1447          53 :         RETURN_TRUE;
    1448             : }
    1449             : /* }}} */
    1450             : 
    1451             : /* {{{ proto resource ZipArchive::setPassword(string password)
    1452             : Set the password for the active archive */
    1453           0 : static ZIPARCHIVE_METHOD(setPassword)
    1454             : {
    1455             :         struct zip *intern;
    1456           0 :         zval *self = getThis();
    1457             :         char *password;
    1458             :         size_t  password_len;
    1459             : 
    1460           0 :         if (!self) {
    1461           0 :                 RETURN_FALSE;
    1462             :         }
    1463             : 
    1464           0 :         ZIP_FROM_OBJECT(intern, self);
    1465             : 
    1466           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &password, &password_len) == FAILURE) {
    1467           0 :                 return;
    1468             :         }
    1469             : 
    1470           0 :         if (password_len < 1) {
    1471           0 :                 RETURN_FALSE;
    1472             :         } else {
    1473           0 :                 int res = zip_set_default_password(intern, (const char *)password);
    1474           0 :                 if (res == 0) {
    1475           0 :                         RETURN_TRUE;
    1476             :                 } else {
    1477           0 :                         RETURN_FALSE;
    1478             :                 }
    1479             :         }
    1480             : }
    1481             : /* }}} */
    1482             : 
    1483             : /* {{{ proto bool ZipArchive::close()
    1484             : close the zip archive */
    1485          44 : static ZIPARCHIVE_METHOD(close)
    1486             : {
    1487             :         struct zip *intern;
    1488          44 :         zval *self = getThis();
    1489             :         ze_zip_object *ze_obj;
    1490             : 
    1491          44 :         if (!self) {
    1492           0 :                 RETURN_FALSE;
    1493             :         }
    1494             : 
    1495          44 :         ZIP_FROM_OBJECT(intern, self);
    1496             : 
    1497          43 :         ze_obj = Z_ZIP_P(self);
    1498             : 
    1499          43 :         if (zip_close(intern)) {
    1500           0 :                 zip_discard(intern);
    1501             :         }
    1502             : 
    1503          43 :         efree(ze_obj->filename);
    1504          43 :         ze_obj->filename = NULL;
    1505          43 :         ze_obj->filename_len = 0;
    1506          43 :         ze_obj->za = NULL;
    1507             : 
    1508          43 :         RETURN_TRUE;
    1509             : }
    1510             : /* }}} */
    1511             : 
    1512             : /* {{{ proto string ZipArchive::getStatusString()
    1513             :  * Returns the status error message, system and/or zip messages */
    1514           2 : static ZIPARCHIVE_METHOD(getStatusString)
    1515             : {
    1516             :         struct zip *intern;
    1517           2 :         zval *self = getThis();
    1518             :         int zep, syp, len;
    1519             :         char error_string[128];
    1520             : 
    1521           2 :         if (!self) {
    1522           0 :                 RETURN_FALSE;
    1523             :         }
    1524             : 
    1525           2 :         ZIP_FROM_OBJECT(intern, self);
    1526             : 
    1527           2 :         zip_error_get(intern, &zep, &syp);
    1528             : 
    1529           2 :         len = zip_error_to_str(error_string, 128, zep, syp);
    1530           4 :         RETVAL_STRINGL(error_string, len);
    1531             : }
    1532             : /* }}} */
    1533             : 
    1534             : /* {{{ proto bool ZipArchive::createEmptyDir(string dirname)
    1535             : Returns the index of the entry named filename in the archive */
    1536           4 : static ZIPARCHIVE_METHOD(addEmptyDir)
    1537             : {
    1538             :         struct zip *intern;
    1539           4 :         zval *self = getThis();
    1540             :         char *dirname;
    1541             :         size_t   dirname_len;
    1542             :         int idx;
    1543             :         struct zip_stat sb;
    1544             :         char *s;
    1545             : 
    1546           4 :         if (!self) {
    1547           0 :                 RETURN_FALSE;
    1548             :         }
    1549             : 
    1550           4 :         ZIP_FROM_OBJECT(intern, self);
    1551             : 
    1552           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
    1553             :                                 &dirname, &dirname_len) == FAILURE) {
    1554           0 :                 return;
    1555             :         }
    1556             : 
    1557           4 :         if (dirname_len<1) {
    1558           0 :                 RETURN_FALSE;
    1559             :         }
    1560             : 
    1561           4 :         if (dirname[dirname_len-1] != '/') {
    1562           4 :                 s=(char *)emalloc(dirname_len+2);
    1563           4 :                 strcpy(s, dirname);
    1564           4 :                 s[dirname_len] = '/';
    1565           4 :                 s[dirname_len+1] = '\0';
    1566             :         } else {
    1567           0 :                 s = dirname;
    1568             :         }
    1569             : 
    1570           4 :         idx = zip_stat(intern, s, 0, &sb);
    1571           4 :         if (idx >= 0) {
    1572           1 :                 RETVAL_FALSE;
    1573             :         } else {
    1574           3 :                 if (zip_add_dir(intern, (const char *)s) == -1) {
    1575           0 :                         RETVAL_FALSE;
    1576             :                 }
    1577           3 :                 zip_error_clear(intern);
    1578           3 :                 RETVAL_TRUE;
    1579             :         }
    1580             : 
    1581           4 :         if (s != dirname) {
    1582           4 :                 efree(s);
    1583             :         }
    1584             : }
    1585             : /* }}} */
    1586             : 
    1587           2 : static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
    1588             : {
    1589             :         struct zip *intern;
    1590           2 :         zval *self = getThis();
    1591           2 :         char *path = NULL;
    1592           2 :         char *remove_path = NULL;
    1593           2 :         char *add_path = NULL;
    1594           2 :         size_t  add_path_len, remove_path_len = 0, path_len = 0;
    1595           2 :         zend_long remove_all_path = 0;
    1596           2 :         zend_long flags = 0;
    1597           2 :         zval *options = NULL;
    1598             :         int found;
    1599             :         zend_string *pattern;
    1600             : 
    1601           2 :         if (!self) {
    1602           0 :                 RETURN_FALSE;
    1603             :         }
    1604             : 
    1605           2 :         ZIP_FROM_OBJECT(intern, self);
    1606             :         /* 1 == glob, 2 == pcre */
    1607           2 :         if (type == 1) {
    1608           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|la",
    1609             :                                         &pattern, &flags, &options) == FAILURE) {
    1610           0 :                         return;
    1611             :                 }
    1612             :         } else {
    1613           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|sa",
    1614             :                                         &pattern, &path, &path_len, &options) == FAILURE) {
    1615           0 :                         return;
    1616             :                 }
    1617             :         }
    1618             : 
    1619           2 :         if (pattern->len == 0) {
    1620           0 :                 php_error_docref(NULL, E_NOTICE, "Empty string as pattern");
    1621           0 :                 RETURN_FALSE;
    1622             :         }
    1623           2 :         if (options && (php_zip_parse_options(options, &remove_all_path, &remove_path, &remove_path_len,
    1624             :                         &add_path, &add_path_len) < 0)) {
    1625           0 :                 RETURN_FALSE;
    1626             :         }
    1627             : 
    1628           2 :         if (remove_path && remove_path_len > 1) {
    1629           1 :                 size_t real_len = strlen(remove_path);
    1630           1 :                 if (real_len > 1 && remove_path[real_len - 1] == '/' || remove_path[real_len - 1] == '\\') {
    1631           0 :                         remove_path[real_len - 1] = '\0';
    1632             :                 }
    1633             :         }
    1634             : 
    1635           2 :         if (type == 1) {
    1636           1 :                 found = php_zip_glob(pattern->val, pattern->len, flags, return_value);
    1637             :         } else {
    1638           1 :                 found = php_zip_pcre(pattern, path, path_len, return_value);
    1639             :         }
    1640             : 
    1641           2 :         if (found > 0) {
    1642             :                 int i;
    1643             :                 zval *zval_file;
    1644             : 
    1645         126 :                 for (i = 0; i < found; i++) {
    1646             :                         char *file_stripped, *entry_name;
    1647             :                         size_t entry_name_len, file_stripped_len;
    1648             :                         char entry_name_buf[MAXPATHLEN];
    1649         124 :                         zend_string *basename = NULL;
    1650             : 
    1651         124 :                         if ((zval_file = zend_hash_index_find(Z_ARRVAL_P(return_value), i)) != NULL) {
    1652           4 :                                 if (remove_all_path) {
    1653           2 :                                         basename = php_basename(Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file), NULL, 0);
    1654           2 :                                         file_stripped = basename->val;
    1655           2 :                                         file_stripped_len = basename->len;
    1656           4 :                                 } else if (remove_path && strstr(Z_STRVAL_P(zval_file), remove_path) != NULL) {
    1657           2 :                                         file_stripped = Z_STRVAL_P(zval_file) + remove_path_len + 1;
    1658           2 :                                         file_stripped_len = Z_STRLEN_P(zval_file) - remove_path_len - 1;
    1659             :                                 } else {
    1660           0 :                                         file_stripped = Z_STRVAL_P(zval_file);
    1661           0 :                                         file_stripped_len = Z_STRLEN_P(zval_file);
    1662             :                                 }
    1663             : 
    1664           4 :                                 if (add_path) {
    1665           4 :                                         if ((add_path_len + file_stripped_len) > MAXPATHLEN) {
    1666           0 :                                                 php_error_docref(NULL, E_WARNING, "Entry name too long (max: %d, %pd given)",
    1667             :                                                 MAXPATHLEN - 1, (add_path_len + file_stripped_len));
    1668           0 :                                                 zval_ptr_dtor(return_value);
    1669           0 :                                                 RETURN_FALSE;
    1670             :                                         }
    1671             : 
    1672           4 :                                         snprintf(entry_name_buf, MAXPATHLEN, "%s%s", add_path, file_stripped);
    1673           4 :                                         entry_name = entry_name_buf;
    1674           4 :                                         entry_name_len = strlen(entry_name);
    1675             :                                 } else {
    1676           0 :                                         entry_name = Z_STRVAL_P(zval_file);
    1677           0 :                                         entry_name_len = Z_STRLEN_P(zval_file);
    1678             :                                 }
    1679           4 :                                 if (basename) {
    1680             :                                         zend_string_release(basename);
    1681           2 :                                         basename = NULL;
    1682             :                                 }
    1683           4 :                                 if (php_zip_add_file(intern, Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file),
    1684             :                                         entry_name, entry_name_len, 0, 0) < 0) {
    1685             :                                         zval_dtor(return_value);
    1686           0 :                                         RETURN_FALSE;
    1687             :                                 }
    1688             :                         }
    1689             :                 }
    1690             :         }
    1691             : }
    1692             : /* }}} */
    1693             : 
    1694             : /* {{{ proto bool ZipArchive::addGlob(string pattern[,int flags [, array options]])
    1695             : Add files matching the glob pattern. See php's glob for the pattern syntax. */
    1696           1 : static ZIPARCHIVE_METHOD(addGlob)
    1697             : {
    1698           1 :         php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
    1699           1 : }
    1700             : /* }}} */
    1701             : 
    1702             : /* {{{ proto bool ZipArchive::addPattern(string pattern[, string path [, array options]])
    1703             : Add files matching the pcre pattern. See php's pcre for the pattern syntax. */
    1704           1 : static ZIPARCHIVE_METHOD(addPattern)
    1705             : {
    1706           1 :         php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2);
    1707           1 : }
    1708             : /* }}} */
    1709             : 
    1710             : /* {{{ proto bool ZipArchive::addFile(string filepath[, string entryname[, int start [, int length]]])
    1711             : Add a file in a Zip archive using its path and the name to use. */
    1712           4 : static ZIPARCHIVE_METHOD(addFile)
    1713             : {
    1714             :         struct zip *intern;
    1715           4 :         zval *self = getThis();
    1716           4 :         char *entry_name = NULL;
    1717           4 :         size_t entry_name_len = 0;
    1718           4 :         zend_long offset_start = 0, offset_len = 0;
    1719             :         zend_string *filename;
    1720             : 
    1721           4 :         if (!self) {
    1722           0 :                 RETURN_FALSE;
    1723             :         }
    1724             : 
    1725           4 :         ZIP_FROM_OBJECT(intern, self);
    1726             : 
    1727           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|sll",
    1728             :                         &filename, &entry_name, &entry_name_len, &offset_start, &offset_len) == FAILURE) {
    1729           0 :                 return;
    1730             :         }
    1731             : 
    1732           4 :         if (filename->len == 0) {
    1733           0 :                 php_error_docref(NULL, E_NOTICE, "Empty string as filename");
    1734           0 :                 RETURN_FALSE;
    1735             :         }
    1736             : 
    1737           4 :         if (entry_name_len == 0) {
    1738           1 :                 entry_name = filename->val;
    1739           1 :                 entry_name_len = filename->len;
    1740             :         }
    1741             : 
    1742           4 :         if (php_zip_add_file(intern, filename->val, filename->len, entry_name, entry_name_len, 0, 0) < 0) {
    1743           2 :                 RETURN_FALSE;
    1744             :         } else {
    1745           2 :                 RETURN_TRUE;
    1746             :         }
    1747             : }
    1748             : /* }}} */
    1749             : 
    1750             : /* {{{ proto bool ZipArchive::addFromString(string name, string content)
    1751             : Add a file using content and the entry name */
    1752          32 : static ZIPARCHIVE_METHOD(addFromString)
    1753             : {
    1754             :         struct zip *intern;
    1755          32 :         zval *self = getThis();
    1756             :         zend_string *buffer;
    1757             :         char *name;
    1758             :         size_t name_len;
    1759             :         ze_zip_object *ze_obj;
    1760             :         struct zip_source *zs;
    1761          32 :         int pos = 0;
    1762             :         int cur_idx;
    1763             : 
    1764          32 :         if (!self) {
    1765           0 :                 RETURN_FALSE;
    1766             :         }
    1767             : 
    1768          32 :         ZIP_FROM_OBJECT(intern, self);
    1769             : 
    1770          32 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "sS",
    1771             :                         &name, &name_len, &buffer) == FAILURE) {
    1772           0 :                 return;
    1773             :         }
    1774             : 
    1775          32 :         ze_obj = Z_ZIP_P(self);
    1776          32 :         if (ze_obj->buffers_cnt) {
    1777          13 :                 ze_obj->buffers = (char **)erealloc(ze_obj->buffers, sizeof(char *) * (ze_obj->buffers_cnt+1));
    1778          13 :                 pos = ze_obj->buffers_cnt++;
    1779             :         } else {
    1780          19 :                 ze_obj->buffers = (char **)emalloc(sizeof(char *));
    1781          19 :                 ze_obj->buffers_cnt++;
    1782          19 :                 pos = 0;
    1783             :         }
    1784          32 :         ze_obj->buffers[pos] = (char *)emalloc(buffer->len + 1);
    1785          32 :         memcpy(ze_obj->buffers[pos], buffer->val, buffer->len + 1);
    1786             : 
    1787          32 :         zs = zip_source_buffer(intern, ze_obj->buffers[pos], buffer->len, 0);
    1788             : 
    1789          32 :         if (zs == NULL) {
    1790           0 :                 RETURN_FALSE;
    1791             :         }
    1792             : 
    1793          32 :         cur_idx = zip_name_locate(intern, (const char *)name, 0);
    1794             :         /* TODO: fix  _zip_replace */
    1795          32 :         if (cur_idx >= 0) {
    1796           0 :                 if (zip_delete(intern, cur_idx) == -1) {
    1797           0 :                         zip_source_free(zs);
    1798           0 :                         RETURN_FALSE;
    1799             :                 }
    1800             :         }
    1801             : 
    1802          32 :         if (zip_add(intern, name, zs) == -1) {
    1803           0 :                 zip_source_free(zs);
    1804           0 :                 RETURN_FALSE;
    1805             :         } else {
    1806          32 :                 zip_error_clear(intern);
    1807          32 :                 RETURN_TRUE;
    1808             :         }
    1809             : }
    1810             : /* }}} */
    1811             : 
    1812             : /* {{{ proto array ZipArchive::statName(string filename[, int flags])
    1813             : Returns the information about a the zip entry filename */
    1814           1 : static ZIPARCHIVE_METHOD(statName)
    1815             : {
    1816             :         struct zip *intern;
    1817           1 :         zval *self = getThis();
    1818           1 :         zend_long flags = 0;
    1819             :         struct zip_stat sb;
    1820             :         zend_string *name;
    1821             : 
    1822           1 :         if (!self) {
    1823           0 :                 RETURN_FALSE;
    1824             :         }
    1825             : 
    1826           1 :         ZIP_FROM_OBJECT(intern, self);
    1827             : 
    1828           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &name, &flags) == FAILURE) {
    1829           0 :                 return;
    1830             :         }
    1831             : 
    1832           1 :         PHP_ZIP_STAT_PATH(intern, name->val, name->len, flags, sb);
    1833             : 
    1834           0 :         RETURN_SB(&sb);
    1835             : }
    1836             : /* }}} */
    1837             : 
    1838             : /* {{{ proto resource ZipArchive::statIndex(int index[, int flags])
    1839             : Returns the zip entry informations using its index */
    1840          50 : static ZIPARCHIVE_METHOD(statIndex)
    1841             : {
    1842             :         struct zip *intern;
    1843          50 :         zval *self = getThis();
    1844          50 :         zend_long index, flags = 0;
    1845             : 
    1846             :         struct zip_stat sb;
    1847             : 
    1848          50 :         if (!self) {
    1849           0 :                 RETURN_FALSE;
    1850             :         }
    1851             : 
    1852          50 :         ZIP_FROM_OBJECT(intern, self);
    1853             : 
    1854          50 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l",
    1855             :                         &index, &flags) == FAILURE) {
    1856           0 :                 return;
    1857             :         }
    1858             : 
    1859          50 :         if (zip_stat_index(intern, index, flags, &sb) != 0) {
    1860           3 :                 RETURN_FALSE;
    1861             :         }
    1862          47 :         RETURN_SB(&sb);
    1863             : }
    1864             : /* }}} */
    1865             : 
    1866             : /* {{{ proto int ZipArchive::locateName(string filename[, int flags])
    1867             : Returns the index of the entry named filename in the archive */
    1868           8 : static ZIPARCHIVE_METHOD(locateName)
    1869             : {
    1870             :         struct zip *intern;
    1871           8 :         zval *self = getThis();
    1872           8 :         zend_long flags = 0;
    1873           8 :         zend_long idx = -1;
    1874             :         zend_string *name;
    1875             : 
    1876           8 :         if (!self) {
    1877           0 :                 RETURN_FALSE;
    1878             :         }
    1879             : 
    1880           8 :         ZIP_FROM_OBJECT(intern, self);
    1881             : 
    1882           8 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &name, &flags) == FAILURE) {
    1883           0 :                 return;
    1884             :         }
    1885             : 
    1886           8 :         if (name->len < 1) {
    1887           0 :                 RETURN_FALSE;
    1888             :         }
    1889             : 
    1890           8 :         idx = (zend_long)zip_name_locate(intern, (const char *)name->val, flags);
    1891             : 
    1892           8 :         if (idx >= 0) {
    1893           6 :                 RETURN_LONG(idx);
    1894             :         } else {
    1895           2 :                 RETURN_FALSE;
    1896             :         }
    1897             : }
    1898             : /* }}} */
    1899             : 
    1900             : /* {{{ proto string ZipArchive::getNameIndex(int index [, int flags])
    1901             : Returns the name of the file at position index */
    1902           4 : static ZIPARCHIVE_METHOD(getNameIndex)
    1903             : {
    1904             :         struct zip *intern;
    1905           4 :         zval *self = getThis();
    1906             :         const char *name;
    1907           4 :         zend_long flags = 0, index = 0;
    1908             : 
    1909           4 :         if (!self) {
    1910           0 :                 RETURN_FALSE;
    1911             :         }
    1912             : 
    1913           4 :         ZIP_FROM_OBJECT(intern, self);
    1914             : 
    1915           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l",
    1916             :                         &index, &flags) == FAILURE) {
    1917           0 :                 return;
    1918             :         }
    1919             : 
    1920           4 :         name = zip_get_name(intern, (int) index, flags);
    1921             : 
    1922           4 :         if (name) {
    1923           6 :                 RETVAL_STRING((char *)name);
    1924             :         } else {
    1925           1 :                 RETURN_FALSE;
    1926             :         }
    1927             : }
    1928             : /* }}} */
    1929             : 
    1930             : /* {{{ proto bool ZipArchive::setArchiveComment(string comment)
    1931             : Set or remove (NULL/'') the comment of the archive */
    1932           2 : static ZIPARCHIVE_METHOD(setArchiveComment)
    1933             : {
    1934             :         struct zip *intern;
    1935           2 :         zval *self = getThis();
    1936             :         size_t comment_len;
    1937             :         char * comment;
    1938             : 
    1939           2 :         if (!self) {
    1940           0 :                 RETURN_FALSE;
    1941             :         }
    1942             : 
    1943           2 :         ZIP_FROM_OBJECT(intern, self);
    1944             : 
    1945           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &comment, &comment_len) == FAILURE) {
    1946           0 :                 return;
    1947             :         }
    1948           2 :         if (zip_set_archive_comment(intern, (const char *)comment, (int)comment_len)) {
    1949           0 :                 RETURN_FALSE;
    1950             :         } else {
    1951           2 :                 RETURN_TRUE;
    1952             :         }
    1953             : }
    1954             : /* }}} */
    1955             : 
    1956             : /* {{{ proto string ZipArchive::getArchiveComment([int flags])
    1957             : Returns the comment of an entry using its index */
    1958           2 : static ZIPARCHIVE_METHOD(getArchiveComment)
    1959             : {
    1960             :         struct zip *intern;
    1961           2 :         zval *self = getThis();
    1962           2 :         zend_long flags = 0;
    1963             :         const char * comment;
    1964           2 :         int comment_len = 0;
    1965             : 
    1966           2 :         if (!self) {
    1967           0 :                 RETURN_FALSE;
    1968             :         }
    1969             : 
    1970           2 :         ZIP_FROM_OBJECT(intern, self);
    1971             : 
    1972           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) {
    1973           0 :                 return;
    1974             :         }
    1975             : 
    1976           2 :         comment = zip_get_archive_comment(intern, &comment_len, (int)flags);
    1977           2 :         if(comment==NULL) {
    1978           0 :                 RETURN_FALSE;
    1979             :         }
    1980           4 :         RETURN_STRINGL((char *)comment, (zend_long)comment_len);
    1981             : }
    1982             : /* }}} */
    1983             : 
    1984             : /* {{{ proto bool ZipArchive::setCommentName(string name, string comment)
    1985             : Set or remove (NULL/'') the comment of an entry using its Name */
    1986           3 : static ZIPARCHIVE_METHOD(setCommentName)
    1987             : {
    1988             :         struct zip *intern;
    1989           3 :         zval *self = getThis();
    1990             :         size_t comment_len, name_len;
    1991             :         char * comment, *name;
    1992             :         int idx;
    1993             : 
    1994           3 :         if (!self) {
    1995           0 :                 RETURN_FALSE;
    1996             :         }
    1997             : 
    1998           3 :         ZIP_FROM_OBJECT(intern, self);
    1999             : 
    2000           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss",
    2001             :                         &name, &name_len, &comment, &comment_len) == FAILURE) {
    2002           0 :                 return;
    2003             :         }
    2004             : 
    2005           3 :         if (name_len < 1) {
    2006           0 :                 php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
    2007             :         }
    2008             : 
    2009           3 :         idx = zip_name_locate(intern, name, 0);
    2010           3 :         if (idx < 0) {
    2011           0 :                 RETURN_FALSE;
    2012             :         }
    2013           3 :         PHP_ZIP_SET_FILE_COMMENT(intern, idx, comment, comment_len);
    2014             : }
    2015             : /* }}} */
    2016             : 
    2017             : /* {{{ proto bool ZipArchive::setCommentIndex(int index, string comment)
    2018             : Set or remove (NULL/'') the comment of an entry using its index */
    2019           2 : static ZIPARCHIVE_METHOD(setCommentIndex)
    2020             : {
    2021             :         struct zip *intern;
    2022           2 :         zval *self = getThis();
    2023             :         zend_long index;
    2024             :         size_t comment_len;
    2025             :         char * comment;
    2026             :         struct zip_stat sb;
    2027             : 
    2028           2 :         if (!self) {
    2029           0 :                 RETURN_FALSE;
    2030             :         }
    2031             : 
    2032           2 :         ZIP_FROM_OBJECT(intern, self);
    2033             : 
    2034           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls",
    2035             :                         &index, &comment, &comment_len) == FAILURE) {
    2036           0 :                 return;
    2037             :         }
    2038             : 
    2039           2 :         PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
    2040           2 :         PHP_ZIP_SET_FILE_COMMENT(intern, index, comment, comment_len);
    2041             : }
    2042             : /* }}} */
    2043             : 
    2044             : /* those constants/functions are only available in libzip since 0.11.2 */
    2045             : #ifdef ZIP_OPSYS_DEFAULT
    2046             : 
    2047             : /* {{{ proto bool ZipArchive::setExternalAttributesName(string name, int opsys, int attr [, int flags])
    2048             : Set external attributes for file in zip, using its name */
    2049           2 : static ZIPARCHIVE_METHOD(setExternalAttributesName)
    2050             : {
    2051             :         struct zip *intern;
    2052           2 :         zval *self = getThis();
    2053             :         size_t name_len;
    2054             :         char *name;
    2055           2 :         zend_long flags=0, opsys, attr;
    2056             :         zip_int64_t idx;
    2057             : 
    2058           2 :         if (!self) {
    2059           0 :                 RETURN_FALSE;
    2060             :         }
    2061             : 
    2062           2 :         ZIP_FROM_OBJECT(intern, self);
    2063             : 
    2064           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|l",
    2065             :                         &name, &name_len, &opsys, &attr, &flags) == FAILURE) {
    2066           0 :                 return;
    2067             :         }
    2068             : 
    2069           2 :         if (name_len < 1) {
    2070           0 :                 php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
    2071             :         }
    2072             : 
    2073           2 :         idx = zip_name_locate(intern, name, 0);
    2074           2 :         if (idx < 0) {
    2075           0 :                 RETURN_FALSE;
    2076             :         }
    2077           4 :         if (zip_file_set_external_attributes(intern, idx, (zip_flags_t)flags,
    2078           2 :                         (zip_uint8_t)(opsys&0xff), (zip_uint32_t)attr) < 0) {
    2079           0 :                 RETURN_FALSE;
    2080             :         }
    2081           2 :         RETURN_TRUE;
    2082             : }
    2083             : /* }}} */
    2084             : 
    2085             : /* {{{ proto bool ZipArchive::setExternalAttributesIndex(int index, int opsys, int attr [, int flags])
    2086             : Set external attributes for file in zip, using its index */
    2087           2 : static ZIPARCHIVE_METHOD(setExternalAttributesIndex)
    2088             : {
    2089             :         struct zip *intern;
    2090           2 :         zval *self = getThis();
    2091           2 :         zend_long index, flags=0, opsys, attr;
    2092             :         struct zip_stat sb;
    2093             : 
    2094           2 :         if (!self) {
    2095           0 :                 RETURN_FALSE;
    2096             :         }
    2097             : 
    2098           2 :         ZIP_FROM_OBJECT(intern, self);
    2099             : 
    2100           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll|l",
    2101             :                         &index, &opsys, &attr, &flags) == FAILURE) {
    2102           0 :                 return;
    2103             :         }
    2104             : 
    2105           2 :         PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
    2106           4 :         if (zip_file_set_external_attributes(intern, (zip_uint64_t)index,
    2107           2 :                         (zip_flags_t)flags, (zip_uint8_t)(opsys&0xff), (zip_uint32_t)attr) < 0) {
    2108           0 :                 RETURN_FALSE;
    2109             :         }
    2110           2 :         RETURN_TRUE;
    2111             : }
    2112             : /* }}} */
    2113             : 
    2114             : /* {{{ proto bool ZipArchive::getExternalAttributesName(string name, int &opsys, int &attr [, int flags])
    2115             : Get external attributes for file in zip, using its name */
    2116           3 : static ZIPARCHIVE_METHOD(getExternalAttributesName)
    2117             : {
    2118             :         struct zip *intern;
    2119           3 :         zval *self = getThis(), *z_opsys, *z_attr;
    2120             :         size_t name_len;
    2121             :         char *name;
    2122           3 :         zend_long flags=0;
    2123             :         zip_uint8_t opsys;
    2124             :         zip_uint32_t attr;
    2125             :         zip_int64_t idx;
    2126             : 
    2127           3 :         if (!self) {
    2128           0 :                 RETURN_FALSE;
    2129             :         }
    2130             : 
    2131           3 :         ZIP_FROM_OBJECT(intern, self);
    2132             : 
    2133           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz/z/|l",
    2134             :                         &name, &name_len, &z_opsys, &z_attr, &flags) == FAILURE) {
    2135           0 :                 return;
    2136             :         }
    2137             : 
    2138           3 :         if (name_len < 1) {
    2139           0 :                 php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
    2140             :         }
    2141             : 
    2142           3 :         idx = zip_name_locate(intern, name, 0);
    2143           3 :         if (idx < 0) {
    2144           0 :                 RETURN_FALSE;
    2145             :         }
    2146           3 :         if (zip_file_get_external_attributes(intern, idx,
    2147             :                         (zip_flags_t)flags, &opsys, &attr) < 0) {
    2148           0 :                 RETURN_FALSE;
    2149             :         }
    2150           3 :         zval_ptr_dtor(z_opsys);
    2151           3 :         ZVAL_LONG(z_opsys, opsys);
    2152           3 :         zval_ptr_dtor(z_attr);
    2153           3 :         ZVAL_LONG(z_attr, attr);
    2154           3 :         RETURN_TRUE;
    2155             : }
    2156             : /* }}} */
    2157             : 
    2158             : /* {{{ proto bool ZipArchive::getExternalAttributesIndex(int index, int &opsys, int &attr [, int flags])
    2159             : Get external attributes for file in zip, using its index */
    2160           3 : static ZIPARCHIVE_METHOD(getExternalAttributesIndex)
    2161             : {
    2162             :         struct zip *intern;
    2163           3 :         zval *self = getThis(), *z_opsys, *z_attr;
    2164           3 :         zend_long index, flags=0;
    2165             :         zip_uint8_t opsys;
    2166             :         zip_uint32_t attr;
    2167             :         struct zip_stat sb;
    2168             : 
    2169           3 :         if (!self) {
    2170           0 :                 RETURN_FALSE;
    2171             :         }
    2172             : 
    2173           3 :         ZIP_FROM_OBJECT(intern, self);
    2174             : 
    2175           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz/z/|l",
    2176             :                         &index, &z_opsys, &z_attr, &flags) == FAILURE) {
    2177           0 :                 return;
    2178             :         }
    2179             : 
    2180           3 :         PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
    2181           3 :         if (zip_file_get_external_attributes(intern, (zip_uint64_t)index,
    2182             :                         (zip_flags_t)flags, &opsys, &attr) < 0) {
    2183           0 :                 RETURN_FALSE;
    2184             :         }
    2185           3 :         zval_dtor(z_opsys);
    2186           3 :         ZVAL_LONG(z_opsys, opsys);
    2187           3 :         zval_dtor(z_attr);
    2188           3 :         ZVAL_LONG(z_attr, attr);
    2189           3 :         RETURN_TRUE;
    2190             : }
    2191             : /* }}} */
    2192             : #endif /* ifdef ZIP_OPSYS_DEFAULT */
    2193             : 
    2194             : /* {{{ proto string ZipArchive::getCommentName(string name[, int flags])
    2195             : Returns the comment of an entry using its name */
    2196           3 : static ZIPARCHIVE_METHOD(getCommentName)
    2197             : {
    2198             :         struct zip *intern;
    2199           3 :         zval *self = getThis();
    2200             :         size_t name_len;
    2201             :         int idx;
    2202           3 :         zend_long flags = 0;
    2203           3 :         int comment_len = 0;
    2204             :         const char * comment;
    2205             :         char *name;
    2206             : 
    2207           3 :         if (!self) {
    2208           0 :                 RETURN_FALSE;
    2209             :         }
    2210             : 
    2211           3 :         ZIP_FROM_OBJECT(intern, self);
    2212             : 
    2213           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l",
    2214             :                         &name, &name_len, &flags) == FAILURE) {
    2215           1 :                 return;
    2216             :         }
    2217           2 :         if (name_len < 1) {
    2218           1 :                 php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
    2219           1 :                 RETURN_FALSE;
    2220             :         }
    2221             : 
    2222           1 :         idx = zip_name_locate(intern, name, 0);
    2223           1 :         if (idx < 0) {
    2224           0 :                 RETURN_FALSE;
    2225             :         }
    2226             : 
    2227           1 :         comment = zip_get_file_comment(intern, idx, &comment_len, (int)flags);
    2228           2 :         RETURN_STRINGL((char *)comment, (zend_long)comment_len);
    2229             : }
    2230             : /* }}} */
    2231             : 
    2232             : /* {{{ proto string ZipArchive::getCommentIndex(int index[, int flags])
    2233             : Returns the comment of an entry using its index */
    2234           6 : static ZIPARCHIVE_METHOD(getCommentIndex)
    2235             : {
    2236             :         struct zip *intern;
    2237           6 :         zval *self = getThis();
    2238           6 :         zend_long index, flags = 0;
    2239             :         const char * comment;
    2240           6 :         int comment_len = 0;
    2241             :         struct zip_stat sb;
    2242             : 
    2243           6 :         if (!self) {
    2244           0 :                 RETURN_FALSE;
    2245             :         }
    2246             : 
    2247           6 :         ZIP_FROM_OBJECT(intern, self);
    2248             : 
    2249           6 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l",
    2250             :                                 &index, &flags) == FAILURE) {
    2251           0 :                 return;
    2252             :         }
    2253             : 
    2254           6 :         PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
    2255           6 :         comment = zip_get_file_comment(intern, index, &comment_len, (int)flags);
    2256          12 :         RETURN_STRINGL((char *)comment, (zend_long)comment_len);
    2257             : }
    2258             : /* }}} */
    2259             : 
    2260             : /* {{{ proto bool ZipArchive::deleteIndex(int index)
    2261             : Delete a file using its index */
    2262           3 : static ZIPARCHIVE_METHOD(deleteIndex)
    2263             : {
    2264             :         struct zip *intern;
    2265           3 :         zval *self = getThis();
    2266             :         zend_long index;
    2267             : 
    2268           3 :         if (!self) {
    2269           0 :                 RETURN_FALSE;
    2270             :         }
    2271             : 
    2272           3 :         ZIP_FROM_OBJECT(intern, self);
    2273             : 
    2274           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
    2275           0 :                 return;
    2276             :         }
    2277             : 
    2278           3 :         if (index < 0) {
    2279           0 :                 RETURN_FALSE;
    2280             :         }
    2281             : 
    2282           3 :         if (zip_delete(intern, index) < 0) {
    2283           2 :                 RETURN_FALSE;
    2284             :         }
    2285             : 
    2286           1 :         RETURN_TRUE;
    2287             : }
    2288             : /* }}} */
    2289             : 
    2290             : /* {{{ proto bool ZipArchive::deleteName(string name)
    2291             : Delete a file using its index */
    2292           3 : static ZIPARCHIVE_METHOD(deleteName)
    2293             : {
    2294             :         struct zip *intern;
    2295           3 :         zval *self = getThis();
    2296             :         size_t name_len;
    2297             :         char *name;
    2298             :         struct zip_stat sb;
    2299             : 
    2300           3 :         if (!self) {
    2301           0 :                 RETURN_FALSE;
    2302             :         }
    2303             : 
    2304           3 :         ZIP_FROM_OBJECT(intern, self);
    2305             : 
    2306           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
    2307           0 :                 return;
    2308             :         }
    2309           3 :         if (name_len < 1) {
    2310           0 :                 RETURN_FALSE;
    2311             :         }
    2312             : 
    2313           3 :         PHP_ZIP_STAT_PATH(intern, name, name_len, 0, sb);
    2314           3 :         if (zip_delete(intern, sb.index)) {
    2315           0 :                 RETURN_FALSE;
    2316             :         }
    2317           3 :         RETURN_TRUE;
    2318             : }
    2319             : /* }}} */
    2320             : 
    2321             : /* {{{ proto bool ZipArchive::renameIndex(int index, string new_name)
    2322             : Rename an entry selected by its index to new_name */
    2323           1 : static ZIPARCHIVE_METHOD(renameIndex)
    2324             : {
    2325             :         struct zip *intern;
    2326           1 :         zval *self = getThis();
    2327             : 
    2328             :         char *new_name;
    2329             :         size_t new_name_len;
    2330             :         zend_long index;
    2331             : 
    2332           1 :         if (!self) {
    2333           0 :                 RETURN_FALSE;
    2334             :         }
    2335             : 
    2336           1 :         ZIP_FROM_OBJECT(intern, self);
    2337             : 
    2338           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &index, &new_name, &new_name_len) == FAILURE) {
    2339           0 :                 return;
    2340             :         }
    2341             : 
    2342           1 :         if (index < 0) {
    2343           0 :                 RETURN_FALSE;
    2344             :         }
    2345             : 
    2346           1 :         if (new_name_len < 1) {
    2347           0 :                 php_error_docref(NULL, E_NOTICE, "Empty string as new entry name");
    2348           0 :                 RETURN_FALSE;
    2349             :         }
    2350           1 :         if (zip_rename(intern, index, (const char *)new_name) != 0) {
    2351           0 :                 RETURN_FALSE;
    2352             :         }
    2353           1 :         RETURN_TRUE;
    2354             : }
    2355             : /* }}} */
    2356             : 
    2357             : /* {{{ proto bool ZipArchive::renameName(string name, string new_name)
    2358             : Rename an entry selected by its name to new_name */
    2359           1 : static ZIPARCHIVE_METHOD(renameName)
    2360             : {
    2361             :         struct zip *intern;
    2362           1 :         zval *self = getThis();
    2363             :         struct zip_stat sb;
    2364             :         char *name, *new_name;
    2365             :         size_t name_len, new_name_len;
    2366             : 
    2367           1 :         if (!self) {
    2368           0 :                 RETURN_FALSE;
    2369             :         }
    2370             : 
    2371           1 :         ZIP_FROM_OBJECT(intern, self);
    2372             : 
    2373           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &name_len, &new_name, &new_name_len) == FAILURE) {
    2374           0 :                 return;
    2375             :         }
    2376             : 
    2377           1 :         if (new_name_len < 1) {
    2378           0 :                 php_error_docref(NULL, E_NOTICE, "Empty string as new entry name");
    2379           0 :                 RETURN_FALSE;
    2380             :         }
    2381             : 
    2382           1 :         PHP_ZIP_STAT_PATH(intern, name, name_len, 0, sb);
    2383             : 
    2384           1 :         if (zip_rename(intern, sb.index, (const char *)new_name)) {
    2385           0 :                 RETURN_FALSE;
    2386             :         }
    2387           1 :         RETURN_TRUE;
    2388             : }
    2389             : /* }}} */
    2390             : 
    2391             : /* {{{ proto bool ZipArchive::unchangeIndex(int index)
    2392             : Changes to the file at position index are reverted */
    2393           0 : static ZIPARCHIVE_METHOD(unchangeIndex)
    2394             : {
    2395             :         struct zip *intern;
    2396           0 :         zval *self = getThis();
    2397             :         zend_long index;
    2398             : 
    2399           0 :         if (!self) {
    2400           0 :                 RETURN_FALSE;
    2401             :         }
    2402             : 
    2403           0 :         ZIP_FROM_OBJECT(intern, self);
    2404             : 
    2405           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
    2406           0 :                 return;
    2407             :         }
    2408             : 
    2409           0 :         if (index < 0) {
    2410           0 :                 RETURN_FALSE;
    2411             :         }
    2412             : 
    2413           0 :         if (zip_unchange(intern, index) != 0) {
    2414           0 :                 RETURN_FALSE;
    2415             :         } else {
    2416           0 :                 RETURN_TRUE;
    2417             :         }
    2418             : }
    2419             : /* }}} */
    2420             : 
    2421             : /* {{{ proto bool ZipArchive::unchangeName(string name)
    2422             : Changes to the file named 'name' are reverted */
    2423           0 : static ZIPARCHIVE_METHOD(unchangeName)
    2424             : {
    2425             :         struct zip *intern;
    2426           0 :         zval *self = getThis();
    2427             :         struct zip_stat sb;
    2428             :         char *name;
    2429             :         size_t name_len;
    2430             : 
    2431           0 :         if (!self) {
    2432           0 :                 RETURN_FALSE;
    2433             :         }
    2434             : 
    2435           0 :         ZIP_FROM_OBJECT(intern, self);
    2436             : 
    2437           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
    2438           0 :                 return;
    2439             :         }
    2440             : 
    2441           0 :         if (name_len < 1) {
    2442           0 :                 RETURN_FALSE;
    2443             :         }
    2444             : 
    2445           0 :         PHP_ZIP_STAT_PATH(intern, name, name_len, 0, sb);
    2446             : 
    2447           0 :         if (zip_unchange(intern, sb.index) != 0) {
    2448           0 :                 RETURN_FALSE;
    2449             :         } else {
    2450           0 :                 RETURN_TRUE;
    2451             :         }
    2452             : }
    2453             : /* }}} */
    2454             : 
    2455             : /* {{{ proto bool ZipArchive::unchangeAll()
    2456             : All changes to files and global information in archive are reverted */
    2457           0 : static ZIPARCHIVE_METHOD(unchangeAll)
    2458             : {
    2459             :         struct zip *intern;
    2460           0 :         zval *self = getThis();
    2461             : 
    2462           0 :         if (!self) {
    2463           0 :                 RETURN_FALSE;
    2464             :         }
    2465             : 
    2466           0 :         ZIP_FROM_OBJECT(intern, self);
    2467             : 
    2468           0 :         if (zip_unchange_all(intern) != 0) {
    2469           0 :                 RETURN_FALSE;
    2470             :         } else {
    2471           0 :                 RETURN_TRUE;
    2472             :         }
    2473             : }
    2474             : /* }}} */
    2475             : 
    2476             : /* {{{ proto bool ZipArchive::unchangeArchive()
    2477             : Revert all global changes to the archive archive.  For now, this only reverts archive comment changes. */
    2478           0 : static ZIPARCHIVE_METHOD(unchangeArchive)
    2479             : {
    2480             :         struct zip *intern;
    2481           0 :         zval *self = getThis();
    2482             : 
    2483           0 :         if (!self) {
    2484           0 :                 RETURN_FALSE;
    2485             :         }
    2486             : 
    2487           0 :         ZIP_FROM_OBJECT(intern, self);
    2488             : 
    2489           0 :         if (zip_unchange_archive(intern) != 0) {
    2490           0 :                 RETURN_FALSE;
    2491             :         } else {
    2492           0 :                 RETURN_TRUE;
    2493             :         }
    2494             : }
    2495             : /* }}} */
    2496             : 
    2497             : /* {{{ proto bool ZipArchive::extractTo(string pathto[, mixed files])
    2498             : Extract one or more file from a zip archive */
    2499             : /* TODO:
    2500             :  * - allow index or array of indeces
    2501             :  * - replace path
    2502             :  * - patterns
    2503             :  */
    2504           6 : static ZIPARCHIVE_METHOD(extractTo)
    2505             : {
    2506             :         struct zip *intern;
    2507             : 
    2508           6 :         zval *self = getThis();
    2509           6 :         zval *zval_files = NULL;
    2510           6 :         zval *zval_file = NULL;
    2511             :         php_stream_statbuf ssb;
    2512             :         char *pathto;
    2513             :         size_t pathto_len;
    2514             :         int ret, i;
    2515             : 
    2516             :         int nelems;
    2517             : 
    2518           6 :         if (!self) {
    2519           0 :                 RETURN_FALSE;
    2520             :         }
    2521             : 
    2522           6 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|z", &pathto, &pathto_len, &zval_files) == FAILURE) {
    2523           0 :                 return;
    2524             :         }
    2525             : 
    2526           6 :         if (pathto_len < 1) {
    2527           0 :                 RETURN_FALSE;
    2528             :         }
    2529             : 
    2530           6 :         if (php_stream_stat_path_ex(pathto, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL) < 0) {
    2531           1 :                         ret = php_stream_mkdir(pathto, 0777,  PHP_STREAM_MKDIR_RECURSIVE, NULL);
    2532           1 :                         if (!ret) {
    2533           0 :                                         RETURN_FALSE;
    2534             :                         }
    2535             :         }
    2536             : 
    2537           6 :         ZIP_FROM_OBJECT(intern, self);
    2538          11 :         if (zval_files && (Z_TYPE_P(zval_files) != IS_NULL)) {
    2539           4 :                 switch (Z_TYPE_P(zval_files)) {
    2540             :                         case IS_STRING:
    2541           1 :                                 if (!php_zip_extract_file(intern, pathto, Z_STRVAL_P(zval_files), Z_STRLEN_P(zval_files))) {
    2542           0 :                                         RETURN_FALSE;
    2543             :                                 }
    2544           1 :                                 break;
    2545             :                         case IS_ARRAY:
    2546           1 :                                 nelems = zend_hash_num_elements(Z_ARRVAL_P(zval_files));
    2547           1 :                                 if (nelems == 0 ) {
    2548           0 :                                         RETURN_FALSE;
    2549             :                                 }
    2550           3 :                                 for (i = 0; i < nelems; i++) {
    2551           2 :                                         if ((zval_file = zend_hash_index_find(Z_ARRVAL_P(zval_files), i)) != NULL) {
    2552           2 :                                                 switch (Z_TYPE_P(zval_file)) {
    2553             :                                                         case IS_LONG:
    2554           0 :                                                                 break;
    2555             :                                                         case IS_STRING:
    2556           2 :                                                                 if (!php_zip_extract_file(intern, pathto, Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file))) {
    2557           0 :                                                                         RETURN_FALSE;
    2558             :                                                                 }
    2559             :                                                                 break;
    2560             :                                                 }
    2561             :                                         }
    2562             :                                 }
    2563           1 :                                 break;
    2564             :                         case IS_LONG:
    2565             :                         default:
    2566           0 :                                 php_error_docref(NULL, E_WARNING, "Invalid argument, expect string or array of strings");
    2567             :                                 break;
    2568             :                 }
    2569             :         } else {
    2570             :                 /* Extract all files */
    2571           4 :                 int filecount = zip_get_num_files(intern);
    2572             : 
    2573           4 :                 if (filecount == -1) {
    2574           0 :                                 php_error_docref(NULL, E_WARNING, "Illegal archive");
    2575           0 :                                 RETURN_FALSE;
    2576             :                 }
    2577             : 
    2578          11 :                 for (i = 0; i < filecount; i++) {
    2579           8 :                         char *file = (char*)zip_get_name(intern, i, ZIP_FL_UNCHANGED);
    2580           8 :                         if (!php_zip_extract_file(intern, pathto, file, strlen(file))) {
    2581           1 :                                         RETURN_FALSE;
    2582             :                         }
    2583             :                 }
    2584             :         }
    2585           5 :         RETURN_TRUE;
    2586             : }
    2587             : /* }}} */
    2588             : 
    2589           2 : static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
    2590             : {
    2591             :         struct zip *intern;
    2592           2 :         zval *self = getThis();
    2593             : 
    2594             :         struct zip_stat sb;
    2595             :         struct zip_file *zf;
    2596             : 
    2597           2 :         zend_long index = -1;
    2598           2 :         zend_long flags = 0;
    2599           2 :         zend_long len = 0;
    2600             : 
    2601             :         zend_string *filename;
    2602             :         zend_string *buffer;
    2603             : 
    2604           2 :         int n = 0;
    2605             : 
    2606           2 :         if (!self) {
    2607           0 :                 RETURN_FALSE;
    2608             :         }
    2609             : 
    2610           2 :         ZIP_FROM_OBJECT(intern, self);
    2611             : 
    2612           2 :         if (type == 1) {
    2613           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|ll", &filename, &len, &flags) == FAILURE) {
    2614           0 :                         return;
    2615             :                 }
    2616           1 :                 PHP_ZIP_STAT_PATH(intern, filename->val, filename->len, flags, sb);
    2617             :         } else {
    2618           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|ll", &index, &len, &flags) == FAILURE) {
    2619           0 :                         return;
    2620             :                 }
    2621           1 :                 PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
    2622             :         }
    2623             : 
    2624           2 :         if (sb.size < 1) {
    2625           0 :                 RETURN_EMPTY_STRING();
    2626             :         }
    2627             : 
    2628           2 :         if (len < 1) {
    2629           2 :                 len = sb.size;
    2630             :         }
    2631           2 :         if (index >= 0) {
    2632           1 :                 zf = zip_fopen_index(intern, index, flags);
    2633             :         } else {
    2634           1 :                 zf = zip_fopen(intern, filename->val, flags);
    2635             :         }
    2636             : 
    2637           2 :         if (zf == NULL) {
    2638           0 :                 RETURN_FALSE;
    2639             :         }
    2640             : 
    2641           4 :         buffer = zend_string_alloc(len, 0);
    2642           2 :         n = zip_fread(zf, buffer->val, buffer->len);
    2643           2 :         if (n < 1) {
    2644             :                 zend_string_free(buffer);
    2645           0 :                 RETURN_EMPTY_STRING();
    2646             :         }
    2647             : 
    2648           2 :         zip_fclose(zf);
    2649           2 :         buffer->val[n] = '\0';
    2650           2 :         buffer->len = n;
    2651           2 :         RETURN_STR(buffer);
    2652             : }
    2653             : /* }}} */
    2654             : 
    2655             : /* {{{ proto string ZipArchive::getFromName(string entryname[, int len [, int flags]])
    2656             : get the contents of an entry using its name */
    2657           1 : static ZIPARCHIVE_METHOD(getFromName)
    2658             : {
    2659           1 :         php_zip_get_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
    2660           1 : }
    2661             : /* }}} */
    2662             : 
    2663             : /* {{{ proto string ZipArchive::getFromIndex(int index[, int len [, int flags]])
    2664             : get the contents of an entry using its index */
    2665           1 : static ZIPARCHIVE_METHOD(getFromIndex)
    2666             : {
    2667           1 :         php_zip_get_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
    2668           1 : }
    2669             : /* }}} */
    2670             : 
    2671             : /* {{{ proto resource ZipArchive::getStream(string entryname)
    2672             : get a stream for an entry using its name */
    2673           4 : static ZIPARCHIVE_METHOD(getStream)
    2674             : {
    2675             :         struct zip *intern;
    2676           4 :         zval *self = getThis();
    2677             :         struct zip_stat sb;
    2678           4 :         char *mode = "rb";
    2679             :         zend_string *filename;
    2680             :         php_stream *stream;
    2681             :         ze_zip_object *obj;
    2682             : 
    2683           4 :         if (!self) {
    2684           0 :                 RETURN_FALSE;
    2685             :         }
    2686             : 
    2687           4 :         ZIP_FROM_OBJECT(intern, self);
    2688             : 
    2689           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &filename) == FAILURE) {
    2690           0 :                 return;
    2691             :         }
    2692             : 
    2693           4 :         if (zip_stat(intern, filename->val, 0, &sb) != 0) {
    2694           0 :                 RETURN_FALSE;
    2695             :         }
    2696             : 
    2697           4 :         obj = Z_ZIP_P(self);
    2698             : 
    2699           4 :         stream = php_stream_zip_open(obj->filename, filename->val, mode STREAMS_CC);
    2700           4 :         if (stream) {
    2701           4 :                 php_stream_to_zval(stream, return_value);
    2702             :         }
    2703             : }
    2704             : /* }}} */
    2705             : 
    2706             : /* {{{ arginfo */
    2707             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_open, 0, 0, 1)
    2708             :         ZEND_ARG_INFO(0, filename)
    2709             :         ZEND_ARG_INFO(0, flags)
    2710             : ZEND_END_ARG_INFO()
    2711             : 
    2712             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setpassword, 0, 0, 1)
    2713             :         ZEND_ARG_INFO(0, password)
    2714             : ZEND_END_ARG_INFO()
    2715             : 
    2716             : ZEND_BEGIN_ARG_INFO(arginfo_ziparchive__void, 0)
    2717             : ZEND_END_ARG_INFO()
    2718             : 
    2719             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addemptydir, 0, 0, 1)
    2720             :         ZEND_ARG_INFO(0, dirname)
    2721             : ZEND_END_ARG_INFO()
    2722             : 
    2723             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addglob, 0, 0, 1)
    2724             :         ZEND_ARG_INFO(0, pattern)
    2725             :         ZEND_ARG_INFO(0, flags)
    2726             :         ZEND_ARG_INFO(0, options)
    2727             : ZEND_END_ARG_INFO()
    2728             : 
    2729             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addpattern, 0, 0, 1)
    2730             :         ZEND_ARG_INFO(0, pattern)
    2731             :         ZEND_ARG_INFO(0, path)
    2732             :         ZEND_ARG_INFO(0, options)
    2733             : ZEND_END_ARG_INFO()
    2734             : 
    2735             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addfile, 0, 0, 1)
    2736             :         ZEND_ARG_INFO(0, filepath)
    2737             :         ZEND_ARG_INFO(0, entryname)
    2738             :         ZEND_ARG_INFO(0, start)
    2739             :         ZEND_ARG_INFO(0, length)
    2740             : ZEND_END_ARG_INFO()
    2741             : 
    2742             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addfromstring, 0, 0, 2)
    2743             :         ZEND_ARG_INFO(0, name)
    2744             :         ZEND_ARG_INFO(0, content)
    2745             : ZEND_END_ARG_INFO()
    2746             : 
    2747             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_statname, 0, 0, 1)
    2748             :         ZEND_ARG_INFO(0, filename)
    2749             :         ZEND_ARG_INFO(0, flags)
    2750             : ZEND_END_ARG_INFO()
    2751             : 
    2752             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_statindex, 0, 0, 1)
    2753             :         ZEND_ARG_INFO(0, index)
    2754             :         ZEND_ARG_INFO(0, flags)
    2755             : ZEND_END_ARG_INFO()
    2756             : 
    2757             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setarchivecomment, 0, 0, 1)
    2758             :         ZEND_ARG_INFO(0, comment)
    2759             : ZEND_END_ARG_INFO()
    2760             : 
    2761             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setcommentindex, 0, 0, 2)
    2762             :         ZEND_ARG_INFO(0, index)
    2763             :         ZEND_ARG_INFO(0, comment)
    2764             : ZEND_END_ARG_INFO()
    2765             : 
    2766             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getcommentname, 0, 0, 1)
    2767             :         ZEND_ARG_INFO(0, name)
    2768             :         ZEND_ARG_INFO(0, flags)
    2769             : ZEND_END_ARG_INFO()
    2770             : 
    2771             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getcommentindex, 0, 0, 1)
    2772             :         ZEND_ARG_INFO(0, index)
    2773             :         ZEND_ARG_INFO(0, flags)
    2774             : ZEND_END_ARG_INFO()
    2775             : 
    2776             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_renameindex, 0, 0, 2)
    2777             :         ZEND_ARG_INFO(0, index)
    2778             :         ZEND_ARG_INFO(0, new_name)
    2779             : ZEND_END_ARG_INFO()
    2780             : 
    2781             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_renamename, 0, 0, 2)
    2782             :         ZEND_ARG_INFO(0, name)
    2783             :         ZEND_ARG_INFO(0, new_name)
    2784             : ZEND_END_ARG_INFO()
    2785             : 
    2786             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_unchangeindex, 0, 0, 1)
    2787             :         ZEND_ARG_INFO(0, index)
    2788             : ZEND_END_ARG_INFO()
    2789             : 
    2790             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_unchangename, 0, 0, 1)
    2791             :         ZEND_ARG_INFO(0, name)
    2792             : ZEND_END_ARG_INFO()
    2793             : 
    2794             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_extractto, 0, 0, 1)
    2795             :         ZEND_ARG_INFO(0, pathto)
    2796             :         ZEND_ARG_INFO(0, files)
    2797             : ZEND_END_ARG_INFO()
    2798             : 
    2799             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getfromname, 0, 0, 1)
    2800             :         ZEND_ARG_INFO(0, entryname)
    2801             :         ZEND_ARG_INFO(0, len)
    2802             :         ZEND_ARG_INFO(0, flags)
    2803             : ZEND_END_ARG_INFO()
    2804             : 
    2805             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getfromindex, 0, 0, 1)
    2806             :         ZEND_ARG_INFO(0, index)
    2807             :         ZEND_ARG_INFO(0, len)
    2808             :         ZEND_ARG_INFO(0, flags)
    2809             : ZEND_END_ARG_INFO()
    2810             : 
    2811             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getarchivecomment, 0, 0, 0)
    2812             :         ZEND_ARG_INFO(0, flags)
    2813             : ZEND_END_ARG_INFO()
    2814             : 
    2815             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setcommentname, 0, 0, 2)
    2816             :         ZEND_ARG_INFO(0, name)
    2817             :         ZEND_ARG_INFO(0, comment)
    2818             : ZEND_END_ARG_INFO()
    2819             : 
    2820             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getstream, 0, 0, 1)
    2821             :         ZEND_ARG_INFO(0, entryname)
    2822             : ZEND_END_ARG_INFO()
    2823             : 
    2824             : #ifdef ZIP_OPSYS_DEFAULT
    2825             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setextattrname, 0, 0, 3)
    2826             :         ZEND_ARG_INFO(0, name)
    2827             :         ZEND_ARG_INFO(0, opsys)
    2828             :         ZEND_ARG_INFO(0, attr)
    2829             :         ZEND_ARG_INFO(0, flags)
    2830             : ZEND_END_ARG_INFO()
    2831             : 
    2832             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setextattrindex, 0, 0, 3)
    2833             :         ZEND_ARG_INFO(0, index)
    2834             :         ZEND_ARG_INFO(0, opsys)
    2835             :         ZEND_ARG_INFO(0, attr)
    2836             :         ZEND_ARG_INFO(0, flags)
    2837             : ZEND_END_ARG_INFO()
    2838             : 
    2839             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getextattrname, 0, 0, 3)
    2840             :         ZEND_ARG_INFO(0, name)
    2841             :         ZEND_ARG_INFO(1, opsys)
    2842             :         ZEND_ARG_INFO(1, attr)
    2843             :         ZEND_ARG_INFO(0, flags)
    2844             : ZEND_END_ARG_INFO()
    2845             : 
    2846             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getextattrindex, 0, 0, 3)
    2847             :         ZEND_ARG_INFO(0, index)
    2848             :         ZEND_ARG_INFO(1, opsys)
    2849             :         ZEND_ARG_INFO(1, attr)
    2850             :         ZEND_ARG_INFO(0, flags)
    2851             : ZEND_END_ARG_INFO()
    2852             : #endif /* ifdef ZIP_OPSYS_DEFAULT */
    2853             : /* }}} */
    2854             : 
    2855             : /* {{{ ze_zip_object_class_functions */
    2856             : static const zend_function_entry zip_class_functions[] = {
    2857             :         ZIPARCHIVE_ME(open,                                     arginfo_ziparchive_open, ZEND_ACC_PUBLIC)
    2858             :         ZIPARCHIVE_ME(setPassword,                      arginfo_ziparchive_setpassword, ZEND_ACC_PUBLIC)
    2859             :         ZIPARCHIVE_ME(close,                            arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
    2860             :         ZIPARCHIVE_ME(getStatusString,          arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
    2861             :         ZIPARCHIVE_ME(addEmptyDir,                      arginfo_ziparchive_addemptydir, ZEND_ACC_PUBLIC)
    2862             :         ZIPARCHIVE_ME(addFromString,            arginfo_ziparchive_addfromstring, ZEND_ACC_PUBLIC)
    2863             :         ZIPARCHIVE_ME(addFile,                          arginfo_ziparchive_addfile, ZEND_ACC_PUBLIC)
    2864             :         ZIPARCHIVE_ME(addGlob,                          arginfo_ziparchive_addglob, ZEND_ACC_PUBLIC)
    2865             :         ZIPARCHIVE_ME(addPattern,                       arginfo_ziparchive_addpattern, ZEND_ACC_PUBLIC)
    2866             :         ZIPARCHIVE_ME(renameIndex,                      arginfo_ziparchive_renameindex, ZEND_ACC_PUBLIC)
    2867             :         ZIPARCHIVE_ME(renameName,                       arginfo_ziparchive_renamename, ZEND_ACC_PUBLIC)
    2868             :         ZIPARCHIVE_ME(setArchiveComment,        arginfo_ziparchive_setarchivecomment, ZEND_ACC_PUBLIC)
    2869             :         ZIPARCHIVE_ME(getArchiveComment,        arginfo_ziparchive_getarchivecomment, ZEND_ACC_PUBLIC)
    2870             :         ZIPARCHIVE_ME(setCommentIndex,          arginfo_ziparchive_setcommentindex, ZEND_ACC_PUBLIC)
    2871             :         ZIPARCHIVE_ME(setCommentName,           arginfo_ziparchive_setcommentname, ZEND_ACC_PUBLIC)
    2872             :         ZIPARCHIVE_ME(getCommentIndex,          arginfo_ziparchive_getcommentindex, ZEND_ACC_PUBLIC)
    2873             :         ZIPARCHIVE_ME(getCommentName,           arginfo_ziparchive_getcommentname, ZEND_ACC_PUBLIC)
    2874             :         ZIPARCHIVE_ME(deleteIndex,                      arginfo_ziparchive_unchangeindex, ZEND_ACC_PUBLIC)
    2875             :         ZIPARCHIVE_ME(deleteName,                       arginfo_ziparchive_unchangename, ZEND_ACC_PUBLIC)
    2876             :         ZIPARCHIVE_ME(statName,                         arginfo_ziparchive_statname, ZEND_ACC_PUBLIC)
    2877             :         ZIPARCHIVE_ME(statIndex,                        arginfo_ziparchive_statindex, ZEND_ACC_PUBLIC)
    2878             :         ZIPARCHIVE_ME(locateName,                       arginfo_ziparchive_statname, ZEND_ACC_PUBLIC)
    2879             :         ZIPARCHIVE_ME(getNameIndex,                     arginfo_ziparchive_statindex, ZEND_ACC_PUBLIC)
    2880             :         ZIPARCHIVE_ME(unchangeArchive,          arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
    2881             :         ZIPARCHIVE_ME(unchangeAll,                      arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
    2882             :         ZIPARCHIVE_ME(unchangeIndex,            arginfo_ziparchive_unchangeindex, ZEND_ACC_PUBLIC)
    2883             :         ZIPARCHIVE_ME(unchangeName,                     arginfo_ziparchive_unchangename, ZEND_ACC_PUBLIC)
    2884             :         ZIPARCHIVE_ME(extractTo,                        arginfo_ziparchive_extractto, ZEND_ACC_PUBLIC)
    2885             :         ZIPARCHIVE_ME(getFromName,                      arginfo_ziparchive_getfromname, ZEND_ACC_PUBLIC)
    2886             :         ZIPARCHIVE_ME(getFromIndex,                     arginfo_ziparchive_getfromindex, ZEND_ACC_PUBLIC)
    2887             :         ZIPARCHIVE_ME(getStream,                        arginfo_ziparchive_getstream, ZEND_ACC_PUBLIC)
    2888             :         ZIPARCHIVE_ME(setExternalAttributesName,        arginfo_ziparchive_setextattrname, ZEND_ACC_PUBLIC)
    2889             :         ZIPARCHIVE_ME(setExternalAttributesIndex,       arginfo_ziparchive_setextattrindex, ZEND_ACC_PUBLIC)
    2890             :         ZIPARCHIVE_ME(getExternalAttributesName,        arginfo_ziparchive_getextattrname, ZEND_ACC_PUBLIC)
    2891             :         ZIPARCHIVE_ME(getExternalAttributesIndex,       arginfo_ziparchive_getextattrindex, ZEND_ACC_PUBLIC)
    2892             :         {NULL, NULL, NULL}
    2893             : };
    2894             : /* }}} */
    2895             : 
    2896      104525 : static void php_zip_free_prop_handler(zval *el) /* {{{ */ {
    2897      104525 :         pefree(Z_PTR_P(el), 1);
    2898      104525 : } /* }}} */
    2899             : 
    2900             : /* {{{ PHP_MINIT_FUNCTION */
    2901       20871 : static PHP_MINIT_FUNCTION(zip)
    2902             : {
    2903             :         zend_class_entry ce;
    2904             : 
    2905       20871 :         memcpy(&zip_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
    2906       20871 :         zip_object_handlers.offset = XtOffsetOf(ze_zip_object, zo);
    2907       20871 :         zip_object_handlers.free_obj = php_zip_object_free_storage;
    2908       20871 :         zip_object_handlers.clone_obj = NULL;
    2909       20871 :         zip_object_handlers.get_property_ptr_ptr = php_zip_get_property_ptr_ptr;
    2910             : 
    2911       20871 :         zip_object_handlers.get_properties = php_zip_get_properties;
    2912       20871 :         zip_object_handlers.read_property       = php_zip_read_property;
    2913       20871 :         zip_object_handlers.has_property        = php_zip_has_property;
    2914             : 
    2915       20871 :         INIT_CLASS_ENTRY(ce, "ZipArchive", zip_class_functions);
    2916       20871 :         ce.create_object = php_zip_object_new;
    2917       20871 :         zip_class_entry = zend_register_internal_class(&ce);
    2918             : 
    2919       20871 :         zend_hash_init(&zip_prop_handlers, 0, NULL, php_zip_free_prop_handler, 1);
    2920       20871 :         php_zip_register_prop_handler(&zip_prop_handlers, "status",    php_zip_status, NULL, NULL, IS_LONG);
    2921       20871 :         php_zip_register_prop_handler(&zip_prop_handlers, "statusSys", php_zip_status_sys, NULL, NULL, IS_LONG);
    2922       20871 :         php_zip_register_prop_handler(&zip_prop_handlers, "numFiles",  php_zip_get_num_files, NULL, NULL, IS_LONG);
    2923       20871 :         php_zip_register_prop_handler(&zip_prop_handlers, "filename", NULL, NULL, php_zipobj_get_filename, IS_STRING);
    2924       20871 :         php_zip_register_prop_handler(&zip_prop_handlers, "comment", NULL, php_zipobj_get_zip_comment, NULL, IS_STRING);
    2925             : 
    2926       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CREATE", ZIP_CREATE);
    2927       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("EXCL", ZIP_EXCL);
    2928       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CHECKCONS", ZIP_CHECKCONS);
    2929       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OVERWRITE", ZIP_OVERWRITE);
    2930             : 
    2931       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("FL_NOCASE", ZIP_FL_NOCASE);
    2932       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("FL_NODIR", ZIP_FL_NODIR);
    2933       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("FL_COMPRESSED", ZIP_FL_COMPRESSED);
    2934       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("FL_UNCHANGED", ZIP_FL_UNCHANGED);
    2935       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_DEFAULT", ZIP_CM_DEFAULT);
    2936       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_STORE", ZIP_CM_STORE);
    2937       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_SHRINK", ZIP_CM_SHRINK);
    2938       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_REDUCE_1", ZIP_CM_REDUCE_1);
    2939       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_REDUCE_2", ZIP_CM_REDUCE_2);
    2940       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_REDUCE_3", ZIP_CM_REDUCE_3);
    2941       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_REDUCE_4", ZIP_CM_REDUCE_4);
    2942       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_IMPLODE", ZIP_CM_IMPLODE);
    2943       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_DEFLATE", ZIP_CM_DEFLATE);
    2944       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_DEFLATE64", ZIP_CM_DEFLATE64);
    2945       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_PKWARE_IMPLODE", ZIP_CM_PKWARE_IMPLODE);
    2946       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_BZIP2", ZIP_CM_BZIP2);
    2947       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_LZMA", ZIP_CM_LZMA);
    2948       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_TERSE", ZIP_CM_TERSE);
    2949       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_LZ77", ZIP_CM_LZ77);
    2950       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_WAVPACK", ZIP_CM_WAVPACK);
    2951       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("CM_PPMD", ZIP_CM_PPMD);
    2952             : 
    2953             :         /* Error code */
    2954       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_OK",                        ZIP_ER_OK);                     /* N No error */
    2955       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_MULTIDISK", ZIP_ER_MULTIDISK);      /* N Multi-disk zip archives not supported */
    2956       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_RENAME",            ZIP_ER_RENAME);         /* S Renaming temporary file failed */
    2957       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_CLOSE",             ZIP_ER_CLOSE);          /* S Closing zip archive failed */
    2958       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_SEEK",              ZIP_ER_SEEK);           /* S Seek error */
    2959       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_READ",              ZIP_ER_READ);           /* S Read error */
    2960       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_WRITE",             ZIP_ER_WRITE);          /* S Write error */
    2961       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_CRC",                       ZIP_ER_CRC);            /* N CRC error */
    2962       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_ZIPCLOSED", ZIP_ER_ZIPCLOSED);      /* N Containing zip archive was closed */
    2963       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_NOENT",             ZIP_ER_NOENT);          /* N No such file */
    2964       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_EXISTS",            ZIP_ER_EXISTS);         /* N File already exists */
    2965       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_OPEN",              ZIP_ER_OPEN);           /* S Can't open file */
    2966       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_TMPOPEN",           ZIP_ER_TMPOPEN);        /* S Failure to create temporary file */
    2967       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_ZLIB",              ZIP_ER_ZLIB);           /* Z Zlib error */
    2968       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_MEMORY",            ZIP_ER_MEMORY);         /* N Malloc failure */
    2969       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_CHANGED",           ZIP_ER_CHANGED);        /* N Entry has been changed */
    2970       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_COMPNOTSUPP",       ZIP_ER_COMPNOTSUPP);/* N Compression method not supported */
    2971       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_EOF",                       ZIP_ER_EOF);            /* N Premature EOF */
    2972       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_INVAL",             ZIP_ER_INVAL);          /* N Invalid argument */
    2973       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_NOZIP",             ZIP_ER_NOZIP);          /* N Not a zip archive */
    2974       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_INTERNAL",  ZIP_ER_INTERNAL);       /* N Internal error */
    2975       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_INCONS",            ZIP_ER_INCONS);         /* N Zip archive inconsistent */
    2976       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_REMOVE",            ZIP_ER_REMOVE);         /* S Can't remove file */
    2977       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("ER_DELETED",   ZIP_ER_DELETED);        /* N Entry has been deleted */
    2978             : 
    2979             : #ifdef ZIP_OPSYS_DEFAULT
    2980       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_DOS",                            ZIP_OPSYS_DOS);
    2981       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_AMIGA",                  ZIP_OPSYS_AMIGA);
    2982       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_OPENVMS",                        ZIP_OPSYS_OPENVMS);
    2983       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_UNIX",                           ZIP_OPSYS_UNIX);
    2984       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_VM_CMS",                 ZIP_OPSYS_VM_CMS);
    2985       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_ATARI_ST",                       ZIP_OPSYS_ATARI_ST);
    2986       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_OS_2",                           ZIP_OPSYS_OS_2);
    2987       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_MACINTOSH",              ZIP_OPSYS_MACINTOSH);
    2988       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_Z_SYSTEM",                       ZIP_OPSYS_Z_SYSTEM);
    2989       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_Z_CPM",                  ZIP_OPSYS_CPM);
    2990       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_WINDOWS_NTFS",           ZIP_OPSYS_WINDOWS_NTFS);
    2991       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_MVS",                            ZIP_OPSYS_MVS);
    2992       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_VSE",                            ZIP_OPSYS_VSE);
    2993       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_ACORN_RISC",             ZIP_OPSYS_ACORN_RISC);
    2994       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_VFAT",                           ZIP_OPSYS_VFAT);
    2995       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_ALTERNATE_MVS",  ZIP_OPSYS_ALTERNATE_MVS);
    2996       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_BEOS",                           ZIP_OPSYS_BEOS);
    2997       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_TANDEM",                 ZIP_OPSYS_TANDEM);
    2998       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_OS_400",                 ZIP_OPSYS_OS_400);
    2999       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_OS_X",                           ZIP_OPSYS_OS_X);
    3000             : 
    3001       20871 :         REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_DEFAULT", ZIP_OPSYS_DEFAULT);
    3002             : #endif /* ifdef ZIP_OPSYS_DEFAULT */
    3003             : 
    3004       20871 :         php_register_url_stream_wrapper("zip", &php_stream_zip_wrapper);
    3005             : 
    3006       20871 :         le_zip_dir   = zend_register_list_destructors_ex(php_zip_free_dir,   NULL, le_zip_dir_name,   module_number);
    3007       20871 :         le_zip_entry = zend_register_list_destructors_ex(php_zip_free_entry, NULL, le_zip_entry_name, module_number);
    3008             : 
    3009       20871 :         return SUCCESS;
    3010             : }
    3011             : /* }}} */
    3012             : 
    3013             : /* {{{ PHP_MSHUTDOWN_FUNCTION
    3014             :  */
    3015       20905 : static PHP_MSHUTDOWN_FUNCTION(zip)
    3016             : {
    3017       20905 :         zend_hash_destroy(&zip_prop_handlers);
    3018       20905 :         php_unregister_url_stream_wrapper("zip");
    3019       20905 :         return SUCCESS;
    3020             : }
    3021             : /* }}} */
    3022             : 
    3023             : /* {{{ PHP_MINFO_FUNCTION
    3024             :  */
    3025         145 : static PHP_MINFO_FUNCTION(zip)
    3026             : {
    3027         145 :         php_info_print_table_start();
    3028             : 
    3029         145 :         php_info_print_table_row(2, "Zip", "enabled");
    3030         145 :         php_info_print_table_row(2, "Extension Version","$Id: e90ee9f9792048f73be3647d4b4da6c2a817f0bd $");
    3031         145 :         php_info_print_table_row(2, "Zip version", PHP_ZIP_VERSION);
    3032         145 :         php_info_print_table_row(2, "Libzip version", LIBZIP_VERSION);
    3033             : 
    3034         145 :         php_info_print_table_end();
    3035         145 : }
    3036             : /* }}} */
    3037             : 
    3038             : /*
    3039             :  * Local variables:
    3040             :  * tab-width: 4
    3041             :  * c-basic-offset: 4
    3042             :  * End:
    3043             :  * vim600: noet sw=4 ts=4 fdm=marker
    3044             :  * vim<600: noet sw=4 ts=4
    3045             :  */

Generated by: LCOV version 1.10

Generated at Sun, 01 Mar 2015 23:22:37 +0000 (31 hours ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.