diff options
author | Xinchen Hui <laruence@gmail.com> | 2014-05-05 10:49:27 +0800 |
---|---|---|
committer | Xinchen Hui <laruence@gmail.com> | 2014-05-05 10:49:27 +0800 |
commit | bea30846bb40e84eab19243823c5c8baa2f0137c (patch) | |
tree | 0d83c863718159ba6919838dbb764eb77b76766e /ext/zip | |
parent | cf15e94e0797bbafe89efec5176a248839250909 (diff) | |
download | php-git-bea30846bb40e84eab19243823c5c8baa2f0137c.tar.gz |
Refactor Zip (1 test failed)
Diffstat (limited to 'ext/zip')
-rw-r--r-- | ext/zip/php_zip.c | 555 | ||||
-rw-r--r-- | ext/zip/php_zip.h | 15 | ||||
-rw-r--r-- | ext/zip/tests/doubleclose.phpt | 2 | ||||
-rw-r--r-- | ext/zip/tests/zip_entry_close.phpt | 2 | ||||
-rw-r--r-- | ext/zip/zip_stream.c | 9 |
5 files changed, 223 insertions, 360 deletions
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index df6ea03dab..3315970753 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -51,23 +51,7 @@ static PHP_NAMED_FUNCTION(zif_zip_entry_close); #endif #endif -#if PHP_VERSION_ID < 50400 -#define ARG_PATH "s" -#define KEY_ARG_DC -#define KEY_ARG_CC -#else -#define ARG_PATH "p" -#define KEY_ARG_DC , const zend_literal *key -#define KEY_ARG_CC , key -#endif - -#if PHP_VERSION_ID < 50500 -#define TYPE_ARG_DC -#define TYPE_ARG_CC -#else -#define TYPE_ARG_DC , int type -#define TYPE_ARG_CC , type -#endif +#define ARG_PATH "P" /* {{{ Resource le */ static int le_zip_dir; @@ -107,11 +91,8 @@ static int le_zip_entry; RETURN_TRUE; /* }}} */ -#if (PHP_MAJOR_VERSION < 6) # define add_ascii_assoc_string add_assoc_string # define add_ascii_assoc_long add_assoc_long -#endif - /* Flatten a path by making a relative path (to .)*/ static char * php_zip_make_relative_path(char *path, int path_len) /* {{{ */ @@ -150,15 +131,8 @@ static char * php_zip_make_relative_path(char *path, int path_len) /* {{{ */ } /* }}} */ -#ifdef PHP_ZIP_USE_OO - -#if PHP_VERSION_ID < 50600 -# define CWD_STATE_ALLOC(l) malloc(l) -# define CWD_STATE_FREE(s) free(s) -#else # define CWD_STATE_ALLOC(l) emalloc(l) # define CWD_STATE_FREE(s) efree(s) -#endif /* {{{ php_zip_extract_file */ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int file_len TSRMLS_DC) @@ -337,7 +311,7 @@ static int php_zip_add_file(struct zip *za, const char *filename, size_t filenam } php_stat(resolved_path, strlen(resolved_path), FS_EXISTS, &exists_flag TSRMLS_CC); - if (!Z_BVAL(exists_flag)) { + if (Z_TYPE(exists_flag) == IS_FALSE) { return -1; } @@ -355,62 +329,61 @@ static int php_zip_add_file(struct zip *za, const char *filename, size_t filenam } /* }}} */ -static int php_zip_parse_options(zval *options, long *remove_all_path, - char **remove_path, int *remove_path_len, char **add_path, int *add_path_len TSRMLS_DC) /* {{{ */ +static int php_zip_parse_options(zval *options, long *remove_all_path, char **remove_path, int *remove_path_len, char **add_path, int *add_path_len TSRMLS_DC) /* {{{ */ { - zval **option; - if (zend_hash_find(HASH_OF(options), "remove_all_path", sizeof("remove_all_path"), (void **)&option) == SUCCESS) { + zval *option; + if ((option = zend_hash_str_find(HASH_OF(options), "remove_all_path", sizeof("remove_all_path") - 1)) != NULL) { long opt; - if (Z_TYPE_PP(option) != IS_LONG) { - zval tmp = **option; - zval_copy_ctor(&tmp); + if (Z_TYPE_P(option) != IS_LONG) { + zval tmp; + ZVAL_DUP(&tmp, option); convert_to_long(&tmp); opt = Z_LVAL(tmp); } else { - opt = Z_LVAL_PP(option); + opt = Z_LVAL_P(option); } *remove_all_path = opt; } /* If I add more options, it would make sense to create a nice static struct and loop over it. */ - if (zend_hash_find(HASH_OF(options), "remove_path", sizeof("remove_path"), (void **)&option) == SUCCESS) { - if (Z_TYPE_PP(option) != IS_STRING) { + if ((options = zend_hash_str_find(HASH_OF(options), "remove_path", sizeof("remove_path") - 1)) != NULL) { + if (Z_TYPE_P(option) != IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "remove_path option expected to be a string"); return -1; } - if (Z_STRLEN_PP(option) < 1) { + if (Z_STRLEN_P(option) < 1) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Empty string given as remove_path option"); return -1; } - if (Z_STRLEN_PP(option) >= MAXPATHLEN) { + if (Z_STRLEN_P(option) >= MAXPATHLEN) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "remove_path string is too long (max: %i, %i given)", - MAXPATHLEN - 1, Z_STRLEN_PP(option)); + MAXPATHLEN - 1, Z_STRLEN_P(option)); return -1; } - *remove_path_len = Z_STRLEN_PP(option); - *remove_path = Z_STRVAL_PP(option); + *remove_path_len = Z_STRLEN_P(option); + *remove_path = Z_STRVAL_P(option); } - if (zend_hash_find(HASH_OF(options), "add_path", sizeof("add_path"), (void **)&option) == SUCCESS) { - if (Z_TYPE_PP(option) != IS_STRING) { + if ((option = zend_hash_str_find(HASH_OF(options), "add_path", sizeof("add_path") - 1)) != NULL) { + if (Z_TYPE_P(option) != IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "add_path option expected to be a string"); return -1; } - if (Z_STRLEN_PP(option) < 1) { + if (Z_STRLEN_P(option) < 1) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Empty string given as the add_path option"); return -1; } - if (Z_STRLEN_PP(option) >= MAXPATHLEN) { + if (Z_STRLEN_P(option) >= MAXPATHLEN) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "add_path string too long (max: %i, %i given)", - MAXPATHLEN - 1, Z_STRLEN_PP(option)); + MAXPATHLEN - 1, Z_STRLEN_P(option)); return -1; } - *add_path_len = Z_STRLEN_PP(option); - *add_path = Z_STRVAL_PP(option); + *add_path_len = Z_STRLEN_P(option); + *add_path = Z_STRVAL_P(option); } return 1; } @@ -424,7 +397,7 @@ static int php_zip_parse_options(zval *options, long *remove_all_path, /* {{{ ZIP_FROM_OBJECT */ #define ZIP_FROM_OBJECT(intern, object) \ { \ - ze_zip_object *obj = (ze_zip_object*) zend_object_store_get_object(object TSRMLS_CC); \ + ze_zip_object *obj = Z_ZIP_P(object); \ intern = obj->za; \ if (!intern) { \ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid or uninitialized Zip object"); \ @@ -632,7 +605,7 @@ int php_zip_glob(char *pattern, int pattern_len, long flags, zval *return_value } /* }}} */ -int php_zip_pcre(char *regexp, int regexp_len, char *path, int path_len, zval *return_value TSRMLS_DC) /* {{{ */ +int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_value TSRMLS_DC) /* {{{ */ { #ifdef ZTS char cwd[MAXPATHLEN]; @@ -641,7 +614,7 @@ int php_zip_pcre(char *regexp, int regexp_len, char *path, int path_len, zval *r char *result; #endif int files_cnt; - char **namelist; + zend_string **namelist; #ifdef ZTS if (!IS_ABSOLUTE_PATH(path, path_len)) { @@ -668,7 +641,7 @@ int php_zip_pcre(char *regexp, int regexp_len, char *path, int path_len, zval *r files_cnt = php_stream_scandir(path, &namelist, NULL, (void *) php_stream_dirent_alphasort); if (files_cnt > 0) { - pcre *re = NULL; + pcre *re = NULL; pcre_extra *pcre_extra = NULL; int preg_options = 0, i; @@ -686,44 +659,43 @@ int php_zip_pcre(char *regexp, int regexp_len, char *path, int path_len, zval *r char fullpath[MAXPATHLEN]; int ovector[3]; int matches; - int namelist_len = strlen(namelist[i]); + int namelist_len = namelist[i]->len; - - if ((namelist_len == 1 && namelist[i][0] == '.') || - (namelist_len == 2 && namelist[i][0] == '.' && namelist[i][1] == '.')) { - efree(namelist[i]); + if ((namelist_len == 1 && namelist[i]->val[0] == '.') || + (namelist_len == 2 && namelist[i]->val[0] == '.' && namelist[i]->val[1] == '.')) { + STR_RELEASE(namelist[i]); continue; } if ((path_len + namelist_len + 1) >= MAXPATHLEN) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "add_path string too long (max: %i, %i given)", MAXPATHLEN - 1, (path_len + namelist_len + 1)); - efree(namelist[i]); + STR_RELEASE(namelist[i]); break; } - snprintf(fullpath, MAXPATHLEN, "%s%c%s", path, DEFAULT_SLASH, namelist[i]); + snprintf(fullpath, MAXPATHLEN, "%s%c%s", path, DEFAULT_SLASH, namelist[i]->val); if (0 != VCWD_STAT(fullpath, &s)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot read <%s>", fullpath); - efree(namelist[i]); + STR_RELEASE(namelist[i]); continue; } if (S_IFDIR == (s.st_mode & S_IFMT)) { - efree(namelist[i]); + STR_RELEASE(namelist[i]); continue; } - matches = pcre_exec(re, NULL, namelist[i], strlen(namelist[i]), 0, 0, ovector, 3); + matches = pcre_exec(re, NULL, namelist[i]->val, namelist[i]->len, 0, 0, ovector, 3); /* 0 means that the vector is too small to hold all the captured substring offsets */ if (matches < 0) { - efree(namelist[i]); + STR_RELEASE(namelist[i]); continue; } add_next_index_string(return_value, fullpath); - efree(namelist[i]); + STR_RELEASE(namelist[i]); } efree(namelist); } @@ -731,8 +703,6 @@ int php_zip_pcre(char *regexp, int regexp_len, char *path, int path_len, zval *r } /* }}} */ -#endif - /* {{{ arginfo */ ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_open, 0, 0, 1) ZEND_ARG_INFO(0, filename) @@ -799,7 +769,6 @@ static const zend_function_entry zip_functions[] = { /* }}} */ /* {{{ ZE2 OO definitions */ -#ifdef PHP_ZIP_USE_OO static zend_class_entry *zip_class_entry; static zend_object_handlers zip_object_handlers; @@ -816,10 +785,8 @@ typedef struct _zip_prop_handler { int type; } zip_prop_handler; -#endif /* }}} */ -#ifdef PHP_ZIP_USE_OO 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 TSRMLS_DC) /* {{{ */ { zip_prop_handler hnd; @@ -828,11 +795,11 @@ static void php_zip_register_prop_handler(HashTable *prop_handler, char *name, z hnd.read_int_func = read_int_func; hnd.read_const_char_from_obj_func = read_char_from_obj_func; hnd.type = rettype; - zend_hash_add(prop_handler, name, strlen(name)+1, &hnd, sizeof(zip_prop_handler), NULL); + zend_hash_str_add_mem(prop_handler, name, strlen(name), &hnd, sizeof(zip_prop_handler)); } /* }}} */ -static int php_zip_property_reader(ze_zip_object *obj, zip_prop_handler *hnd, zval **retval, int newzval TSRMLS_DC) /* {{{ */ +static zval *php_zip_property_reader(ze_zip_object *obj, zip_prop_handler *hnd, zval *rv TSRMLS_DC) /* {{{ */ { const char *retchar = NULL; int retint = 0; @@ -846,7 +813,7 @@ static int php_zip_property_reader(ze_zip_object *obj, zip_prop_handler *hnd, zv retint = hnd->read_int_func(obj->za TSRMLS_CC); if (retint == -1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal zip error returned"); - return FAILURE; + return NULL; } } else { if (hnd->read_const_char_from_obj_func) { @@ -857,187 +824,146 @@ static int php_zip_property_reader(ze_zip_object *obj, zip_prop_handler *hnd, zv } } - if (newzval) { - ALLOC_ZVAL(*retval); - } - switch (hnd->type) { case IS_STRING: if (retchar) { - ZVAL_STRINGL(*retval, (char *) retchar, len, 1); + ZVAL_STRINGL(rv, (char *) retchar, len); } else { - ZVAL_EMPTY_STRING(*retval); + ZVAL_EMPTY_STRING(rv); } break; - case IS_BOOL: - ZVAL_BOOL(*retval, (long)retint); + /* case IS_TRUE */ + case IS_FALSE: + ZVAL_BOOL(rv, (long)retint); break; case IS_LONG: - ZVAL_LONG(*retval, (long)retint); + ZVAL_LONG(rv, (long)retint); break; default: - ZVAL_NULL(*retval); + ZVAL_NULL(rv); } - return SUCCESS; + return rv; } /* }}} */ -static zval **php_zip_get_property_ptr_ptr(zval *object, zval *member TYPE_ARG_DC KEY_ARG_DC TSRMLS_DC) /* {{{ */ +static zval *php_zip_get_property_ptr_ptr(zval *object, zval *member, int type, zend_uint cache_slot TSRMLS_DC) /* {{{ */ { ze_zip_object *obj; zval tmp_member; - zval **retval = NULL; - - zip_prop_handler *hnd; + zval *retval = NULL; + zip_prop_handler *hnd = NULL; zend_object_handlers *std_hnd; - int ret; - if (member->type != IS_STRING) { - tmp_member = *member; - zval_copy_ctor(&tmp_member); + if (Z_TYPE_P(member) != IS_STRING) { + ZVAL_DUP(&tmp_member, member); convert_to_string(&tmp_member); member = &tmp_member; -#if PHP_VERSION_ID >= 50400 - key = NULL; -#endif + cache_slot = -1; } - ret = FAILURE; - obj = (ze_zip_object *)zend_objects_get_address(object TSRMLS_CC); + obj = Z_ZIP_P(object); if (obj->prop_handler != NULL) { -#if PHP_VERSION_ID >= 50400 - if (key) { - ret = zend_hash_quick_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, key->hash_value, (void **) &hnd); - } else -#endif - ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd); + hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member)); } - - if (ret == FAILURE) { + if (hnd == NULL) { std_hnd = zend_get_std_object_handlers(); - retval = std_hnd->get_property_ptr_ptr(object, member TYPE_ARG_CC KEY_ARG_CC TSRMLS_CC); + retval = std_hnd->get_property_ptr_ptr(object, member, type, cache_slot TSRMLS_CC); } if (member == &tmp_member) { zval_dtor(member); } + return retval; } /* }}} */ -static zval* php_zip_read_property(zval *object, zval *member, int type KEY_ARG_DC TSRMLS_DC) /* {{{ */ +static zval *php_zip_read_property(zval *object, zval *member, int type, zend_uint cache_slot, zval *rv TSRMLS_DC) /* {{{ */ { ze_zip_object *obj; zval tmp_member; - zval *retval; - zip_prop_handler *hnd; + zval *retval = NULL; + zip_prop_handler *hnd = NULL; zend_object_handlers *std_hnd; - int ret; - if (member->type != IS_STRING) { - tmp_member = *member; - zval_copy_ctor(&tmp_member); + if (Z_TYPE_P(member) != IS_STRING) { + ZVAL_DUP(&tmp_member, member); convert_to_string(&tmp_member); member = &tmp_member; -#if PHP_VERSION_ID >= 50400 - key = NULL; -#endif + cache_slot = -1; } - ret = FAILURE; - obj = (ze_zip_object *)zend_objects_get_address(object TSRMLS_CC); + obj = Z_ZIP_P(object); if (obj->prop_handler != NULL) { -#if PHP_VERSION_ID >= 50400 - if (key) { - ret = zend_hash_quick_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, key->hash_value, (void **) &hnd); - } else -#endif - ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd); + hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member)); } - if (ret == SUCCESS) { - ret = php_zip_property_reader(obj, hnd, &retval, 1 TSRMLS_CC); - if (ret == SUCCESS) { - /* ensure we're creating a temporary variable */ - Z_SET_REFCOUNT_P(retval, 0); - } else { - retval = EG(uninitialized_zval_ptr); + if (hnd != NULL) { + retval = php_zip_property_reader(obj, hnd, rv TSRMLS_CC); + if (retval == NULL) { + retval = &EG(uninitialized_zval); } } else { std_hnd = zend_get_std_object_handlers(); - retval = std_hnd->read_property(object, member, type KEY_ARG_CC TSRMLS_CC); + retval = std_hnd->read_property(object, member, type, cache_slot, rv TSRMLS_CC); } if (member == &tmp_member) { zval_dtor(member); } + return retval; } /* }}} */ -static int php_zip_has_property(zval *object, zval *member, int type KEY_ARG_DC TSRMLS_DC) /* {{{ */ +static int php_zip_has_property(zval *object, zval *member, int type, zend_uint cache_slot TSRMLS_DC) /* {{{ */ { ze_zip_object *obj; zval tmp_member; - zip_prop_handler *hnd; + zip_prop_handler *hnd = NULL; zend_object_handlers *std_hnd; - int ret, retval = 0; + int retval = 0; - if (member->type != IS_STRING) { - tmp_member = *member; - zval_copy_ctor(&tmp_member); + if (Z_TYPE_P(member) != IS_STRING) { + ZVAL_DUP(&tmp_member, member); convert_to_string(&tmp_member); member = &tmp_member; -#if PHP_VERSION_ID >= 50400 - key = NULL; -#endif + cache_slot = -1; } - ret = FAILURE; - obj = (ze_zip_object *)zend_objects_get_address(object TSRMLS_CC); + obj = Z_ZIP_P(object); if (obj->prop_handler != NULL) { -#if PHP_VERSION_ID >= 50400 - if (key) { - ret = zend_hash_quick_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, key->hash_value, (void **) &hnd); - } else -#endif - ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd); + hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member)); } - if (ret == SUCCESS) { - zval *tmp; - ALLOC_INIT_ZVAL(tmp); + if (hnd != NULL) { + zval tmp, *prop; if (type == 2) { retval = 1; - } else if (php_zip_property_reader(obj, hnd, &tmp, 0 TSRMLS_CC) == SUCCESS) { - Z_SET_REFCOUNT_P(tmp, 1); - Z_UNSET_ISREF_P(tmp); + } else if ((prop = php_zip_property_reader(obj, hnd, &tmp TSRMLS_CC)) != NULL) { if (type == 1) { -#if PHP_VERSION_ID >= 50699 - retval = zend_is_true(tmp TSRMLS_CC); -#else - retval = zend_is_true(tmp); -#endif + retval = zend_is_true(&tmp TSRMLS_CC); } else if (type == 0) { - retval = (Z_TYPE_P(tmp) != IS_NULL); + retval = (Z_TYPE(tmp) != IS_NULL); } } zval_ptr_dtor(&tmp); } else { std_hnd = zend_get_std_object_handlers(); - retval = std_hnd->has_property(object, member, type KEY_ARG_CC TSRMLS_CC); + retval = std_hnd->has_property(object, member, type, cache_slot TSRMLS_CC); } if (member == &tmp_member) { zval_dtor(member); } + return retval; } /* }}} */ @@ -1045,40 +971,34 @@ static int php_zip_has_property(zval *object, zval *member, int type KEY_ARG_DC static HashTable *php_zip_get_properties(zval *object TSRMLS_DC)/* {{{ */ { ze_zip_object *obj; - zip_prop_handler *hnd; HashTable *props; - zval *val; - int ret; - char *key; - uint key_len; - HashPosition pos; + zip_prop_handler *hnd; + zend_string *key; ulong num_key; - obj = (ze_zip_object *)zend_objects_get_address(object TSRMLS_CC); + obj = Z_ZIP_P(object); props = zend_std_get_properties(object TSRMLS_CC); if (obj->prop_handler == NULL) { return NULL; } - zend_hash_internal_pointer_reset_ex(obj->prop_handler, &pos); - while (zend_hash_get_current_data_ex(obj->prop_handler, (void**)&hnd, &pos) == SUCCESS) { - zend_hash_get_current_key_ex(obj->prop_handler, &key, &key_len, &num_key, 0, &pos); - MAKE_STD_ZVAL(val); - ret = php_zip_property_reader(obj, hnd, &val, 0 TSRMLS_CC); - if (ret != SUCCESS) { - val = EG(uninitialized_zval_ptr); + ZEND_HASH_FOREACH_KEY_PTR(obj->prop_handler, num_key, key, hnd) { + zval *ret, val; + ret = php_zip_property_reader(obj, hnd, &val TSRMLS_CC); + if (ret == NULL) { + ret = &EG(uninitialized_zval); } - zend_hash_update(props, key, key_len, (void *)&val, sizeof(zval *), NULL); - zend_hash_move_forward_ex(obj->prop_handler, &pos); - } + zend_hash_update(props, key, ret); + } ZEND_HASH_FOREACH_END(); + return props; } /* }}} */ -static void php_zip_object_free_storage(void *object TSRMLS_DC) /* {{{ */ +static void php_zip_object_free_storage(zend_object *object TSRMLS_DC) /* {{{ */ { - ze_zip_object * intern = (ze_zip_object *) object; + ze_zip_object * intern = php_zip_fetch_object(object); int i; if (!intern) { @@ -1100,76 +1020,32 @@ static void php_zip_object_free_storage(void *object TSRMLS_DC) /* {{{ */ } intern->za = NULL; - -#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 1 && PHP_RELEASE_VERSION > 2) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 1) || (PHP_MAJOR_VERSION > 5) zend_object_std_dtor(&intern->zo TSRMLS_CC); -#else - if (intern->zo.guards) { - zend_hash_destroy(intern->zo.guards); - FREE_HASHTABLE(intern->zo.guards); - } - - if (intern->zo.properties) { - zend_hash_destroy(intern->zo.properties); - FREE_HASHTABLE(intern->zo.properties); - } -#endif if (intern->filename) { efree(intern->filename); } - efree(intern); } /* }}} */ -static zend_object_value php_zip_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ +static zend_object *php_zip_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ { -#if PHP_VERSION_ID < 50400 - zval *tmp; -#endif ze_zip_object *intern; - zend_object_value retval; - - intern = emalloc(sizeof(ze_zip_object)); - memset(&intern->zo, 0, sizeof(zend_object)); - intern->za = NULL; - intern->buffers = NULL; - intern->filename = NULL; - intern->buffers_cnt = 0; + intern = ecalloc(1, sizeof(ze_zip_object) + sizeof(zval) * (class_type->default_properties_count - 1)); intern->prop_handler = &zip_prop_handlers; - -#if ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 1) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 1 && PHP_RELEASE_VERSION > 2)) zend_object_std_init(&intern->zo, class_type TSRMLS_CC); -#else - ALLOC_HASHTABLE(intern->zo.properties); - zend_hash_init(intern->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - intern->zo.ce = class_type; -#endif - - -#if PHP_VERSION_ID < 50400 - zend_hash_copy(intern->zo.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, - (void *) &tmp, sizeof(zval *)); -#else object_properties_init(&intern->zo, class_type); -#endif - retval.handle = zend_objects_store_put(intern, - NULL, - (zend_objects_free_object_storage_t) php_zip_object_free_storage, - NULL TSRMLS_CC); - - retval.handlers = (zend_object_handlers *) & zip_object_handlers; + intern->zo.handlers = &zip_object_handlers; - return retval; + return &intern->zo; } /* }}} */ -#endif /* {{{ Resource dtors */ /* {{{ php_zip_free_dir */ -static void php_zip_free_dir(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void php_zip_free_dir(zend_resource *rsrc TSRMLS_DC) { zip_rsrc * zip_int = (zip_rsrc *) rsrc->ptr; @@ -1189,7 +1065,7 @@ static void php_zip_free_dir(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* }}} */ /* {{{ php_zip_free_entry */ -static void php_zip_free_entry(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void php_zip_free_entry(zend_resource *rsrc TSRMLS_DC) { zip_read_rsrc *zr_rsrc = (zip_read_rsrc *) rsrc->ptr; @@ -1239,26 +1115,25 @@ ZEND_GET_MODULE(zip) Create new zip using source uri for output */ static PHP_NAMED_FUNCTION(zif_zip_open) { - char *filename; - int filename_len; char resolved_path[MAXPATHLEN + 1]; zip_rsrc *rsrc_int; int err = 0; + zend_string *filename; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH, &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH, &filename) == FAILURE) { return; } - if (filename_len == 0) { + if (filename->len == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string as source"); RETURN_FALSE; } - if (ZIP_OPENBASEDIR_CHECKPATH(filename)) { + if (ZIP_OPENBASEDIR_CHECKPATH(filename->val)) { RETURN_FALSE; } - if(!expand_filepath(filename, resolved_path TSRMLS_CC)) { + if(!expand_filepath(filename->val, resolved_path TSRMLS_CC)) { RETURN_FALSE; } @@ -1287,10 +1162,10 @@ static PHP_NAMED_FUNCTION(zif_zip_close) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zip) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(z_rsrc, zip_rsrc *, &zip, -1, le_zip_dir_name, le_zip_dir); + ZEND_FETCH_RESOURCE(z_rsrc, zip_rsrc *, zip, -1, le_zip_dir_name, le_zip_dir); /* really close the zip will break BC :-D */ - zend_list_delete(Z_LVAL_P(zip)); + zend_list_close(Z_RES_P(zip)); } /* }}} */ @@ -1306,7 +1181,8 @@ static PHP_NAMED_FUNCTION(zif_zip_read) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zip_dp) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(rsrc_int, zip_rsrc *, &zip_dp, -1, le_zip_dir_name, le_zip_dir); + + ZEND_FETCH_RESOURCE(rsrc_int, zip_rsrc *, zip_dp, -1, le_zip_dir_name, le_zip_dir); if (rsrc_int && rsrc_int->za) { if (rsrc_int->index_current >= rsrc_int->num_files) { @@ -1353,8 +1229,8 @@ static PHP_NAMED_FUNCTION(zif_zip_entry_open) return; } - ZEND_FETCH_RESOURCE(zr_rsrc, zip_read_rsrc *, &zip_entry, -1, le_zip_entry_name, le_zip_entry); - ZEND_FETCH_RESOURCE(z_rsrc, zip_rsrc *, &zip, -1, le_zip_dir_name, le_zip_dir); + ZEND_FETCH_RESOURCE(zr_rsrc, zip_read_rsrc *, zip_entry, -1, le_zip_entry_name, le_zip_entry); + ZEND_FETCH_RESOURCE(z_rsrc, zip_rsrc *, zip, -1, le_zip_dir_name, le_zip_dir); if (zr_rsrc->zf != NULL) { RETURN_TRUE; @@ -1375,9 +1251,9 @@ static PHP_NAMED_FUNCTION(zif_zip_entry_close) return; } - ZEND_FETCH_RESOURCE(zr_rsrc, zip_read_rsrc *, &zip_entry, -1, le_zip_entry_name, le_zip_entry); + ZEND_FETCH_RESOURCE(zr_rsrc, zip_read_rsrc *, zip_entry, -1, le_zip_entry_name, le_zip_entry); - RETURN_BOOL(SUCCESS == zend_list_delete(Z_LVAL_P(zip_entry))); + RETURN_BOOL(SUCCESS == zend_list_close(Z_RES_P(zip_entry))); } /* }}} */ @@ -1388,27 +1264,28 @@ static PHP_NAMED_FUNCTION(zif_zip_entry_read) zval * zip_entry; long len = 0; zip_read_rsrc * zr_rsrc; - char *buffer; + zend_string *buffer; int n = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zip_entry, &len) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(zr_rsrc, zip_read_rsrc *, &zip_entry, -1, le_zip_entry_name, le_zip_entry); + ZEND_FETCH_RESOURCE(zr_rsrc, zip_read_rsrc *, zip_entry, -1, le_zip_entry_name, le_zip_entry); if (len <= 0) { len = 1024; } if (zr_rsrc->zf) { - buffer = safe_emalloc(len, 1, 1); - n = zip_fread(zr_rsrc->zf, buffer, len); + buffer = STR_ALLOC(len, 0); + n = zip_fread(zr_rsrc->zf, buffer->val, buffer->len); if (n > 0) { - buffer[n] = 0; - RETURN_STRINGL(buffer, n, 0); + buffer->val[n] = '\0'; + buffer->len = n; + RETURN_STR(buffer); } else { - efree(buffer); + STR_FREE(buffer); RETURN_EMPTY_STRING() } } else { @@ -1426,7 +1303,7 @@ static void php_zip_entry_get_info(INTERNAL_FUNCTION_PARAMETERS, int opt) /* {{{ return; } - ZEND_FETCH_RESOURCE(zr_rsrc, zip_read_rsrc *, &zip_entry, -1, le_zip_entry_name, le_zip_entry); + ZEND_FETCH_RESOURCE(zr_rsrc, zip_read_rsrc *, zip_entry, -1, le_zip_entry_name, le_zip_entry); if (!zr_rsrc->zf) { RETURN_FALSE; @@ -1434,7 +1311,7 @@ static void php_zip_entry_get_info(INTERNAL_FUNCTION_PARAMETERS, int opt) /* {{{ switch (opt) { case 0: - RETURN_STRING((char *)zr_rsrc->sb.name, 1); + RETURN_STRING((char *)zr_rsrc->sb.name); break; case 1: RETURN_LONG((long) (zr_rsrc->sb.comp_size)); @@ -1445,31 +1322,31 @@ static void php_zip_entry_get_info(INTERNAL_FUNCTION_PARAMETERS, int opt) /* {{{ case 3: switch (zr_rsrc->sb.comp_method) { case 0: - RETURN_STRING("stored", 1); + RETURN_STRING("stored"); break; case 1: - RETURN_STRING("shrunk", 1); + RETURN_STRING("shrunk"); break; case 2: case 3: case 4: case 5: - RETURN_STRING("reduced", 1); + RETURN_STRING("reduced"); break; case 6: - RETURN_STRING("imploded", 1); + RETURN_STRING("imploded"); break; case 7: - RETURN_STRING("tokenized", 1); + RETURN_STRING("tokenized"); break; case 8: - RETURN_STRING("deflated", 1); + RETURN_STRING("deflated"); break; case 9: - RETURN_STRING("deflatedX", 1); + RETURN_STRING("deflatedX"); break; case 10: - RETURN_STRING("implodedX", 1); + RETURN_STRING("implodedX"); break; default: RETURN_FALSE; @@ -1513,40 +1390,37 @@ static PHP_NAMED_FUNCTION(zif_zip_entry_compressionmethod) } /* }}} */ -#ifdef PHP_ZIP_USE_OO /* {{{ proto mixed ZipArchive::open(string source [, int flags]) Create new zip using source uri for output, return TRUE on success or the error code */ static ZIPARCHIVE_METHOD(open) { struct zip *intern; - char *filename; - int filename_len; int err = 0; long flags = 0; char *resolved_path; - + zend_string *filename; zval *this = getThis(); ze_zip_object *ze_obj = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH "|l", &filename, &filename_len, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH "|l", &filename, &flags) == FAILURE) { return; } if (this) { /* We do not use ZIP_FROM_OBJECT, zip init function here */ - ze_obj = (ze_zip_object*) zend_object_store_get_object(this TSRMLS_CC); + ze_obj = Z_ZIP_P(this); } - if (filename_len == 0) { + if (filename->len == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string as source"); RETURN_FALSE; } - if (ZIP_OPENBASEDIR_CHECKPATH(filename)) { + if (ZIP_OPENBASEDIR_CHECKPATH(filename->val)) { RETURN_FALSE; } - if (!(resolved_path = expand_filepath(filename, NULL TSRMLS_CC))) { + if (!(resolved_path = expand_filepath(filename->val, NULL TSRMLS_CC))) { RETURN_FALSE; } @@ -1622,7 +1496,7 @@ static ZIPARCHIVE_METHOD(close) ZIP_FROM_OBJECT(intern, this); - ze_obj = (ze_zip_object*) zend_object_store_get_object(this TSRMLS_CC); + ze_obj = Z_ZIP_P(this); if (zip_close(intern)) { zip_discard(intern); @@ -1655,7 +1529,7 @@ static ZIPARCHIVE_METHOD(getStatusString) zip_error_get(intern, &zep, &syp); len = zip_error_to_str(error_string, 128, zep, syp); - RETVAL_STRINGL(error_string, len, 1); + RETVAL_STRINGL(error_string, len); } /* }}} */ @@ -1716,35 +1590,35 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* { struct zip *intern; zval *this = getThis(); - char *pattern; char *path = NULL; char *remove_path = NULL; char *add_path = NULL; - int pattern_len, add_path_len, remove_path_len = 0, path_len = 0; + int add_path_len, remove_path_len = 0, path_len = 0; long remove_all_path = 0; long flags = 0; zval *options = NULL; int found; + zend_string *pattern; if (!this) { RETURN_FALSE; } ZIP_FROM_OBJECT(intern, this); - /* 1 == glob, 2==pcre */ + /* 1 == glob, 2 == pcre */ if (type == 1) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH "|la", - &pattern, &pattern_len, &flags, &options) == FAILURE) { + &pattern, &flags, &options) == FAILURE) { return; } } else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH "|sa", - &pattern, &pattern_len, &path, &path_len, &options) == FAILURE) { + &pattern, &path, &path_len, &options) == FAILURE) { return; } } - if (pattern_len == 0) { + if (pattern->len == 0) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Empty string as pattern"); RETURN_FALSE; } @@ -1759,14 +1633,14 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* } if (type == 1) { - found = php_zip_glob(pattern, pattern_len, flags, return_value TSRMLS_CC); + found = php_zip_glob(pattern->val, pattern->len, flags, return_value TSRMLS_CC); } else { - found = php_zip_pcre(pattern, pattern_len, path, path_len, return_value TSRMLS_CC); + found = php_zip_pcre(pattern, path, path_len, return_value TSRMLS_CC); } if (found > 0) { int i; - zval **zval_file = NULL; + zval *zval_file; for (i = 0; i < found; i++) { char *file_stripped, *entry_name; @@ -1774,25 +1648,24 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* char entry_name_buf[MAXPATHLEN]; zend_string *basename = NULL; - if (zend_hash_index_find(Z_ARRVAL_P(return_value), i, (void **) &zval_file) == SUCCESS) { + if ((zval_file = zend_hash_index_find(Z_ARRVAL_P(return_value), i)) != NULL) { if (remove_all_path) { - basename = php_basename(Z_STRVAL_PP(zval_file), Z_STRLEN_PP(zval_file), NULL, 0, - &basename TSRMLS_CC); + basename = php_basename(Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file), NULL, 0); file_stripped = basename->val; file_stripped_len = basename->len; - } else if (remove_path && strstr(Z_STRVAL_PP(zval_file), remove_path) != NULL) { - file_stripped = Z_STRVAL_PP(zval_file) + remove_path_len + 1; - file_stripped_len = Z_STRLEN_PP(zval_file) - remove_path_len - 1; + } else if (remove_path && strstr(Z_STRVAL_P(zval_file), remove_path) != NULL) { + file_stripped = Z_STRVAL_P(zval_file) + remove_path_len + 1; + file_stripped_len = Z_STRLEN_P(zval_file) - remove_path_len - 1; } else { - file_stripped = Z_STRVAL_PP(zval_file); - file_stripped_len = Z_STRLEN_PP(zval_file); + file_stripped = Z_STRVAL_P(zval_file); + file_stripped_len = Z_STRLEN_P(zval_file); } if (add_path) { if ((add_path_len + file_stripped_len) > MAXPATHLEN) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Entry name too long (max: %d, %ld given)", MAXPATHLEN - 1, (add_path_len + file_stripped_len)); - zval_dtor(return_value); + zval_ptr_dtor(return_value); RETURN_FALSE; } @@ -1800,14 +1673,14 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* entry_name = entry_name_buf; entry_name_len = strlen(entry_name); } else { - entry_name = Z_STRVAL_PP(zval_file); - entry_name_len = Z_STRLEN_PP(zval_file); + entry_name = Z_STRVAL_P(zval_file); + entry_name_len = Z_STRLEN_P(zval_file); } if (basename) { STR_RELEASE(basename); basename = NULL; } - if (php_zip_add_file(intern, Z_STRVAL_PP(zval_file), Z_STRLEN_PP(zval_file), + if (php_zip_add_file(intern, Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file), entry_name, entry_name_len, 0, 0 TSRMLS_CC) < 0) { zval_dtor(return_value); RETURN_FALSE; @@ -1840,11 +1713,10 @@ static ZIPARCHIVE_METHOD(addFile) { struct zip *intern; zval *this = getThis(); - char *filename; - int filename_len; char *entry_name = NULL; int entry_name_len = 0; long offset_start = 0, offset_len = 0; + zend_string *filename; if (!this) { RETURN_FALSE; @@ -1853,22 +1725,21 @@ static ZIPARCHIVE_METHOD(addFile) ZIP_FROM_OBJECT(intern, this); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH "|sll", - &filename, &filename_len, &entry_name, &entry_name_len, &offset_start, &offset_len) == FAILURE) { + &filename, &entry_name, &entry_name_len, &offset_start, &offset_len) == FAILURE) { return; } - if (filename_len == 0) { + if (filename->len == 0) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Empty string as filename"); RETURN_FALSE; } if (entry_name_len == 0) { - entry_name = filename; - entry_name_len = filename_len; + entry_name = filename->val; + entry_name_len = filename->len; } - if (php_zip_add_file(intern, filename, filename_len, - entry_name, entry_name_len, 0, 0 TSRMLS_CC) < 0) { + if (php_zip_add_file(intern, filename->val, filename->len, entry_name, entry_name_len, 0, 0 TSRMLS_CC) < 0) { RETURN_FALSE; } else { RETURN_TRUE; @@ -1900,7 +1771,7 @@ static ZIPARCHIVE_METHOD(addFromString) return; } - ze_obj = (ze_zip_object*) zend_object_store_get_object(this TSRMLS_CC); + ze_obj = Z_ZIP_P(this); if (ze_obj->buffers_cnt) { ze_obj->buffers = (char **)erealloc(ze_obj->buffers, sizeof(char *) * (ze_obj->buffers_cnt+1)); pos = ze_obj->buffers_cnt++; @@ -1943,10 +1814,9 @@ static ZIPARCHIVE_METHOD(statName) { struct zip *intern; zval *this = getThis(); - char *name; - int name_len; long flags = 0; struct zip_stat sb; + zend_string *name; if (!this) { RETURN_FALSE; @@ -1954,12 +1824,11 @@ static ZIPARCHIVE_METHOD(statName) ZIP_FROM_OBJECT(intern, this); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH "|l", - &name, &name_len, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH "|l", &name, &flags) == FAILURE) { return; } - PHP_ZIP_STAT_PATH(intern, name, name_len, flags, sb); + PHP_ZIP_STAT_PATH(intern, name->val, name->len, flags, sb); RETURN_SB(&sb); } @@ -1999,10 +1868,9 @@ static ZIPARCHIVE_METHOD(locateName) { struct zip *intern; zval *this = getThis(); - char *name; - int name_len; long flags = 0; long idx = -1; + zend_string *name; if (!this) { RETURN_FALSE; @@ -2010,15 +1878,15 @@ static ZIPARCHIVE_METHOD(locateName) ZIP_FROM_OBJECT(intern, this); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH "|l", - &name, &name_len, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH "|l", &name, &flags) == FAILURE) { return; } - if (name_len<1) { + + if (name->len < 1) { RETURN_FALSE; } - idx = (long)zip_name_locate(intern, (const char *)name, flags); + idx = (long)zip_name_locate(intern, (const char *)name->val, flags); if (idx >= 0) { RETURN_LONG(idx); @@ -2051,7 +1919,7 @@ static ZIPARCHIVE_METHOD(getNameIndex) name = zip_get_name(intern, (int) index, flags); if (name) { - RETVAL_STRING((char *)name, 1); + RETVAL_STRING((char *)name); } else { RETURN_FALSE; } @@ -2108,7 +1976,7 @@ static ZIPARCHIVE_METHOD(getArchiveComment) if(comment==NULL) { RETURN_FALSE; } - RETURN_STRINGL((char *)comment, (long)comment_len, 1); + RETURN_STRINGL((char *)comment, (long)comment_len); } /* }}} */ @@ -2355,7 +2223,7 @@ static ZIPARCHIVE_METHOD(getCommentName) } comment = zip_get_file_comment(intern, idx, &comment_len, (int)flags); - RETURN_STRINGL((char *)comment, (long)comment_len, 1); + RETURN_STRINGL((char *)comment, (long)comment_len); } /* }}} */ @@ -2383,7 +2251,7 @@ static ZIPARCHIVE_METHOD(getCommentIndex) PHP_ZIP_STAT_INDEX(intern, index, 0, sb); comment = zip_get_file_comment(intern, index, &comment_len, (int)flags); - RETURN_STRINGL((char *)comment, (long)comment_len, 1); + RETURN_STRINGL((char *)comment, (long)comment_len); } /* }}} */ @@ -2637,7 +2505,7 @@ static ZIPARCHIVE_METHOD(extractTo) zval *this = getThis(); zval *zval_files = NULL; - zval **zval_file = NULL; + zval *zval_file = NULL; php_stream_statbuf ssb; char *pathto; int pathto_len; @@ -2678,12 +2546,12 @@ static ZIPARCHIVE_METHOD(extractTo) RETURN_FALSE; } for (i = 0; i < nelems; i++) { - if (zend_hash_index_find(Z_ARRVAL_P(zval_files), i, (void **) &zval_file) == SUCCESS) { - switch (Z_TYPE_PP(zval_file)) { + if ((zval_file = zend_hash_index_find(Z_ARRVAL_P(zval_files), i)) != NULL) { + switch (Z_TYPE_P(zval_file)) { case IS_LONG: break; case IS_STRING: - if (!php_zip_extract_file(intern, pathto, Z_STRVAL_PP(zval_file), Z_STRLEN_PP(zval_file) TSRMLS_CC)) { + if (!php_zip_extract_file(intern, pathto, Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file) TSRMLS_CC)) { RETURN_FALSE; } break; @@ -2724,13 +2592,13 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ struct zip_stat sb; struct zip_file *zf; - char *filename; - int filename_len; long index = -1; long flags = 0; long len = 0; - char *buffer; + zend_string *filename; + zend_string *buffer; + int n = 0; if (!this) { @@ -2740,10 +2608,10 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ ZIP_FROM_OBJECT(intern, this); if (type == 1) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH "|ll", &filename, &filename_len, &len, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH "|ll", &filename, &len, &flags) == FAILURE) { return; } - PHP_ZIP_STAT_PATH(intern, filename, filename_len, flags, sb); + PHP_ZIP_STAT_PATH(intern, filename->val, filename->len, flags, sb); } else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|ll", &index, &len, &flags) == FAILURE) { return; @@ -2761,23 +2629,24 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ if (index >= 0) { zf = zip_fopen_index(intern, index, flags); } else { - zf = zip_fopen(intern, filename, flags); + zf = zip_fopen(intern, filename->val, flags); } if (zf == NULL) { RETURN_FALSE; } - buffer = safe_emalloc(len, 1, 2); - n = zip_fread(zf, buffer, len); + buffer = STR_ALLOC(len, 0); + n = zip_fread(zf, buffer->val, buffer->len); if (n < 1) { - efree(buffer); + STR_FREE(buffer); RETURN_EMPTY_STRING(); } zip_fclose(zf); - buffer[n] = 0; - RETURN_STRINGL(buffer, n, 0); + buffer->val[n] = '\0'; + buffer->len = n; + RETURN_STR(buffer); } /* }}} */ @@ -2804,9 +2673,8 @@ static ZIPARCHIVE_METHOD(getStream) struct zip *intern; zval *this = getThis(); struct zip_stat sb; - char *filename; - int filename_len; char *mode = "rb"; + zend_string *filename; php_stream *stream; ze_zip_object *obj; @@ -2816,17 +2684,17 @@ static ZIPARCHIVE_METHOD(getStream) ZIP_FROM_OBJECT(intern, this); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH, &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ARG_PATH, &filename) == FAILURE) { return; } - if (zip_stat(intern, filename, 0, &sb) != 0) { + if (zip_stat(intern, filename->val, 0, &sb) != 0) { RETURN_FALSE; } - obj = (ze_zip_object*) zend_object_store_get_object(this TSRMLS_CC); + obj = Z_ZIP_P(this); - stream = php_stream_zip_open(obj->filename, filename, mode STREAMS_CC TSRMLS_CC); + stream = php_stream_zip_open(obj->filename, filename->val, mode STREAMS_CC TSRMLS_CC); if (stream) { php_stream_to_zval(stream, return_value); } @@ -3022,16 +2890,16 @@ static const zend_function_entry zip_class_functions[] = { {NULL, NULL, NULL} }; /* }}} */ -#endif /* {{{ PHP_MINIT_FUNCTION */ static PHP_MINIT_FUNCTION(zip) { -#ifdef PHP_ZIP_USE_OO zend_class_entry ce; memcpy(&zip_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - zip_object_handlers.clone_obj = NULL; + zip_object_handlers.offset = XtOffsetOf(ze_zip_object, zo); + zip_object_handlers.free_obj = php_zip_object_free_storage; + zip_object_handlers.clone_obj = NULL; zip_object_handlers.get_property_ptr_ptr = php_zip_get_property_ptr_ptr; zip_object_handlers.get_properties = php_zip_get_properties; @@ -3128,7 +2996,6 @@ static PHP_MINIT_FUNCTION(zip) #endif /* ifdef ZIP_OPSYS_DEFAULT */ php_register_url_stream_wrapper("zip", &php_stream_zip_wrapper TSRMLS_CC); -#endif /* ifdef PHP_ZIP_USE_OO */ le_zip_dir = zend_register_list_destructors_ex(php_zip_free_dir, NULL, le_zip_dir_name, module_number); le_zip_entry = zend_register_list_destructors_ex(php_zip_free_entry, NULL, le_zip_entry_name, module_number); @@ -3141,10 +3008,8 @@ static PHP_MINIT_FUNCTION(zip) */ static PHP_MSHUTDOWN_FUNCTION(zip) { -#ifdef PHP_ZIP_USE_OO zend_hash_destroy(&zip_prop_handlers); php_unregister_url_stream_wrapper("zip" TSRMLS_CC); -#endif return SUCCESS; } /* }}} */ diff --git a/ext/zip/php_zip.h b/ext/zip/php_zip.h index ffe4530415..f4ad99f293 100644 --- a/ext/zip/php_zip.h +++ b/ext/zip/php_zip.h @@ -40,10 +40,6 @@ extern zend_module_entry zip_module_entry; #define PHP_ZIP_VERSION "1.12.4" -#if ((PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 2) || PHP_MAJOR_VERSION >= 6) -# define PHP_ZIP_USE_OO 1 -#endif - #ifndef Z_SET_REFCOUNT_P # if PHP_MAJOR_VERSION < 6 && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) # define Z_SET_REFCOUNT_P(pz, rc) pz->refcount = rc @@ -74,27 +70,30 @@ typedef struct _ze_zip_read_rsrc { struct zip_stat sb; } zip_read_rsrc; -#ifdef PHP_ZIP_USE_OO #define ZIPARCHIVE_ME(name, arg_info, flags) {#name, c_ziparchive_ ##name, arg_info,(zend_uint) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags }, #define ZIPARCHIVE_METHOD(name) ZEND_NAMED_FUNCTION(c_ziparchive_ ##name) - /* Extends zend object */ typedef struct _ze_zip_object { - zend_object zo; struct zip *za; int buffers_cnt; char **buffers; HashTable *prop_handler; char *filename; int filename_len; + zend_object zo; } ze_zip_object; +static inline ze_zip_object *php_zip_fetch_object(zend_object *obj) { + return (ze_zip_object *)((char*)(obj) - XtOffsetOf(ze_zip_object, zo)); +} + +#define Z_ZIP_P(zv) php_zip_fetch_object(Z_OBJ_P((zv))) + php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); php_stream *php_stream_zip_open(const char *filename, const char *path, const char *mode STREAMS_DC TSRMLS_DC); extern php_stream_wrapper php_stream_zip_wrapper; -#endif #endif /* PHP_ZIP_H */ diff --git a/ext/zip/tests/doubleclose.phpt b/ext/zip/tests/doubleclose.phpt index abc62c8434..0eccc40bad 100644 --- a/ext/zip/tests/doubleclose.phpt +++ b/ext/zip/tests/doubleclose.phpt @@ -33,7 +33,7 @@ Done Procedural NULL -Warning: zip_close(): %i is not a valid Zip Directory resource in %s +Warning: zip_close(): supplied resource is not a valid Zip Directory resource in %s bool(false) Object bool(true) diff --git a/ext/zip/tests/zip_entry_close.phpt b/ext/zip/tests/zip_entry_close.phpt index 82b7819054..20e2123401 100644 --- a/ext/zip/tests/zip_entry_close.phpt +++ b/ext/zip/tests/zip_entry_close.phpt @@ -19,6 +19,6 @@ Done entry_open: bool(true) entry_close: bool(true) entry_close: -Warning: zip_entry_close(): %d is not a valid Zip Entry resource in %s +Warning: zip_entry_close(): supplied resource is not a valid Zip Entry resource in %s bool(false) Done diff --git a/ext/zip/zip_stream.c b/ext/zip/zip_stream.c index 956f066064..29ec3d022a 100644 --- a/ext/zip/zip_stream.c +++ b/ext/zip/zip_stream.c @@ -258,8 +258,7 @@ php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper, { int path_len; - char *file_basename; - size_t file_basename_len; + zend_string *file_basename; char file_dirname[MAXPATHLEN]; struct zip *za; @@ -293,11 +292,11 @@ php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper, memcpy(file_dirname, path, path_len - fragment_len); file_dirname[path_len - fragment_len] = '\0'; - php_basename(path, path_len - fragment_len, NULL, 0, &file_basename, &file_basename_len TSRMLS_CC); + file_basename = php_basename(path, path_len - fragment_len, NULL, 0 TSRMLS_CC); fragment++; if (ZIP_OPENBASEDIR_CHECKPATH(file_dirname)) { - efree(file_basename); + STR_RELEASE(file_basename); return NULL; } @@ -321,7 +320,7 @@ php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper, } } - efree(file_basename); + STR_RELEASE(file_basename); if (!stream) { return NULL; |