summaryrefslogtreecommitdiff
path: root/ext/phar/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/phar/util.c')
-rw-r--r--ext/phar/util.c621
1 files changed, 287 insertions, 334 deletions
diff --git a/ext/phar/util.c b/ext/phar/util.c
index 4bbd8676cb..eca33efc38 100644
--- a/ext/phar/util.c
+++ b/ext/phar/util.c
@@ -38,11 +38,11 @@
#include <openssl/ssl.h>
#include <openssl/pkcs12.h>
#else
-static int phar_call_openssl_signverify(int is_sign, php_stream *fp, off_t end, char *key, int key_len, char **signature, int *signature_len TSRMLS_DC);
+static int phar_call_openssl_signverify(int is_sign, php_stream *fp, zend_off_t end, char *key, int key_len, char **signature, int *signature_len);
#endif
/* for links to relative location, prepend cwd of the entry */
-static char *phar_get_link_location(phar_entry_info *entry TSRMLS_DC) /* {{{ */
+static char *phar_get_link_location(phar_entry_info *entry) /* {{{ */
{
char *p, *ret = NULL;
if (!entry->link) {
@@ -61,7 +61,7 @@ static char *phar_get_link_location(phar_entry_info *entry TSRMLS_DC) /* {{{ */
}
/* }}} */
-phar_entry_info *phar_get_link_source(phar_entry_info *entry TSRMLS_DC) /* {{{ */
+phar_entry_info *phar_get_link_source(phar_entry_info *entry) /* {{{ */
{
phar_entry_info *link_entry;
char *link;
@@ -70,13 +70,13 @@ phar_entry_info *phar_get_link_source(phar_entry_info *entry TSRMLS_DC) /* {{{ *
return entry;
}
- link = phar_get_link_location(entry TSRMLS_CC);
- if (SUCCESS == zend_hash_find(&(entry->phar->manifest), entry->link, strlen(entry->link), (void **)&link_entry) ||
- SUCCESS == zend_hash_find(&(entry->phar->manifest), link, strlen(link), (void **)&link_entry)) {
+ link = phar_get_link_location(entry);
+ if (NULL != (link_entry = zend_hash_str_find_ptr(&(entry->phar->manifest), entry->link, strlen(entry->link))) ||
+ NULL != (link_entry = zend_hash_str_find_ptr(&(entry->phar->manifest), link, strlen(link)))) {
if (link != entry->link) {
efree(link);
}
- return phar_get_link_source(link_entry TSRMLS_CC);
+ return phar_get_link_source(link_entry);
} else {
if (link != entry->link) {
efree(link);
@@ -87,24 +87,24 @@ phar_entry_info *phar_get_link_source(phar_entry_info *entry TSRMLS_DC) /* {{{ *
/* }}} */
/* retrieve a phar_entry_info's current file pointer for reading contents */
-php_stream *phar_get_efp(phar_entry_info *entry, int follow_links TSRMLS_DC) /* {{{ */
+php_stream *phar_get_efp(phar_entry_info *entry, int follow_links) /* {{{ */
{
if (follow_links && entry->link) {
- phar_entry_info *link_entry = phar_get_link_source(entry TSRMLS_CC);
+ phar_entry_info *link_entry = phar_get_link_source(entry);
if (link_entry && link_entry != entry) {
- return phar_get_efp(link_entry, 1 TSRMLS_CC);
+ return phar_get_efp(link_entry, 1);
}
}
- if (phar_get_fp_type(entry TSRMLS_CC) == PHAR_FP) {
- if (!phar_get_entrypfp(entry TSRMLS_CC)) {
+ if (phar_get_fp_type(entry) == PHAR_FP) {
+ if (!phar_get_entrypfp(entry)) {
/* re-open just in time for cases where our refcount reached 0 on the phar archive */
- phar_open_archive_fp(entry->phar TSRMLS_CC);
+ phar_open_archive_fp(entry->phar);
}
- return phar_get_entrypfp(entry TSRMLS_CC);
- } else if (phar_get_fp_type(entry TSRMLS_CC) == PHAR_UFP) {
- return phar_get_entrypufp(entry TSRMLS_CC);
+ return phar_get_entrypfp(entry);
+ } else if (phar_get_fp_type(entry) == PHAR_UFP) {
+ return phar_get_entrypufp(entry);
} else if (entry->fp_type == PHAR_MOD) {
return entry->fp;
} else {
@@ -117,10 +117,10 @@ php_stream *phar_get_efp(phar_entry_info *entry, int follow_links TSRMLS_DC) /*
}
/* }}} */
-int phar_seek_efp(phar_entry_info *entry, off_t offset, int whence, off_t position, int follow_links TSRMLS_DC) /* {{{ */
+int phar_seek_efp(phar_entry_info *entry, zend_off_t offset, int whence, zend_off_t position, int follow_links) /* {{{ */
{
- php_stream *fp = phar_get_efp(entry, follow_links TSRMLS_CC);
- off_t temp, eoffset;
+ php_stream *fp = phar_get_efp(entry, follow_links);
+ zend_off_t temp, eoffset;
if (!fp) {
return -1;
@@ -128,7 +128,7 @@ int phar_seek_efp(phar_entry_info *entry, off_t offset, int whence, off_t positi
if (follow_links) {
phar_entry_info *t;
- t = phar_get_link_source(entry TSRMLS_CC);
+ t = phar_get_link_source(entry);
if (t) {
entry = t;
}
@@ -138,7 +138,7 @@ int phar_seek_efp(phar_entry_info *entry, off_t offset, int whence, off_t positi
return 0;
}
- eoffset = phar_get_fp_offset(entry TSRMLS_CC);
+ eoffset = phar_get_fp_offset(entry);
switch (whence) {
case SEEK_END:
@@ -154,7 +154,7 @@ int phar_seek_efp(phar_entry_info *entry, off_t offset, int whence, off_t positi
temp = 0;
}
- if (temp > eoffset + (off_t) entry->uncompressed_filesize) {
+ if (temp > eoffset + (zend_off_t) entry->uncompressed_filesize) {
return -1;
}
@@ -167,7 +167,7 @@ int phar_seek_efp(phar_entry_info *entry, off_t offset, int whence, off_t positi
/* }}} */
/* mount an absolute path or uri to a path internal to the phar archive */
-int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len, char *path, int path_len TSRMLS_DC) /* {{{ */
+int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len, char *path, int path_len) /* {{{ */
{
phar_entry_info entry = {0};
php_stream_statbuf ssb;
@@ -194,7 +194,7 @@ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len,
if (is_phar) {
entry.tmp = estrndup(filename, filename_len);
} else {
- entry.tmp = expand_filepath(filename, NULL TSRMLS_CC);
+ entry.tmp = expand_filepath(filename, NULL);
if (!entry.tmp) {
entry.tmp = estrndup(filename, filename_len);
}
@@ -209,7 +209,7 @@ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len,
filename = entry.tmp;
/* only check openbasedir for files, not for phar streams */
- if (!is_phar && php_check_open_basedir(filename TSRMLS_CC)) {
+ if (!is_phar && php_check_open_basedir(filename)) {
efree(entry.tmp);
efree(entry.filename);
return FAILURE;
@@ -227,7 +227,7 @@ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len,
if (ssb.sb.st_mode & S_IFDIR) {
entry.is_dir = 1;
- if (SUCCESS != zend_hash_add(&phar->mounted_dirs, entry.filename, path_len, (void *)&(entry.filename), sizeof(char *), NULL)) {
+ if (NULL == zend_hash_str_add_ptr(&phar->mounted_dirs, entry.filename, path_len, entry.filename)) {
/* directory already mounted */
efree(entry.tmp);
efree(entry.filename);
@@ -240,7 +240,7 @@ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len,
entry.flags = ssb.sb.st_mode;
- if (SUCCESS == zend_hash_add(&phar->manifest, entry.filename, path_len, (void*)&entry, sizeof(phar_entry_info), NULL)) {
+ if (NULL != zend_hash_str_add_mem(&phar->manifest, entry.filename, path_len, (void*)&entry, sizeof(phar_entry_info))) {
return SUCCESS;
}
@@ -250,10 +250,11 @@ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len,
}
/* }}} */
-char *phar_find_in_include_path(char *filename, int filename_len, phar_archive_data **pphar TSRMLS_DC) /* {{{ */
+zend_string *phar_find_in_include_path(char *filename, int filename_len, phar_archive_data **pphar) /* {{{ */
{
- char *path, *fname, *arch, *entry, *ret, *test;
- int arch_len, entry_len, fname_len, ret_len;
+ zend_string *ret;
+ char *path, *fname, *arch, *entry, *test;
+ int arch_len, entry_len, fname_len;
phar_archive_data *phar;
if (pphar) {
@@ -262,11 +263,11 @@ char *phar_find_in_include_path(char *filename, int filename_len, phar_archive_d
pphar = &phar;
}
- if (!zend_is_executing(TSRMLS_C) || !PHAR_G(cwd)) {
- return phar_save_resolve_path(filename, filename_len TSRMLS_CC);
+ if (!zend_is_executing() || !PHAR_G(cwd)) {
+ return phar_save_resolve_path(filename, filename_len);
}
- fname = (char*)zend_get_executed_filename(TSRMLS_C);
+ fname = (char*)zend_get_executed_filename();
fname_len = strlen(fname);
if (PHAR_G(last_phar) && !memcmp(fname, "phar://", 7) && fname_len - 7 >= PHAR_G(last_phar_name_len) && !memcmp(fname + 7, PHAR_G(last_phar_name), PHAR_G(last_phar_name_len))) {
@@ -276,8 +277,8 @@ char *phar_find_in_include_path(char *filename, int filename_len, phar_archive_d
goto splitted;
}
- if (fname_len < 7 || memcmp(fname, "phar://", 7) || SUCCESS != phar_split_fname(fname, strlen(fname), &arch, &arch_len, &entry, &entry_len, 1, 0 TSRMLS_CC)) {
- return phar_save_resolve_path(filename, filename_len TSRMLS_CC);
+ if (fname_len < 7 || memcmp(fname, "phar://", 7) || SUCCESS != phar_split_fname(fname, strlen(fname), &arch, &arch_len, &entry, &entry_len, 1, 0)) {
+ return phar_save_resolve_path(filename, filename_len);
}
efree(entry);
@@ -285,9 +286,9 @@ char *phar_find_in_include_path(char *filename, int filename_len, phar_archive_d
if (*filename == '.') {
int try_len;
- if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL TSRMLS_CC)) {
+ if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL)) {
efree(arch);
- return phar_save_resolve_path(filename, filename_len TSRMLS_CC);
+ return phar_save_resolve_path(filename, filename_len);
}
splitted:
if (pphar) {
@@ -295,18 +296,18 @@ splitted:
}
try_len = filename_len;
- test = phar_fix_filepath(estrndup(filename, filename_len), &try_len, 1 TSRMLS_CC);
+ test = phar_fix_filepath(estrndup(filename, filename_len), &try_len, 1);
if (*test == '/') {
- if (zend_hash_exists(&(phar->manifest), test + 1, try_len - 1)) {
- spprintf(&ret, 0, "phar://%s%s", arch, test);
+ if (zend_hash_str_exists(&(phar->manifest), test + 1, try_len - 1)) {
+ ret = strpprintf(0, "phar://%s%s", arch, test);
efree(arch);
efree(test);
return ret;
}
} else {
- if (zend_hash_exists(&(phar->manifest), test, try_len)) {
- spprintf(&ret, 0, "phar://%s/%s", arch, test);
+ if (zend_hash_str_exists(&(phar->manifest), test, try_len)) {
+ ret = strpprintf(0, "phar://%s/%s", arch, test);
efree(arch);
efree(test);
return ret;
@@ -317,21 +318,19 @@ splitted:
spprintf(&path, MAXPATHLEN, "phar://%s/%s%c%s", arch, PHAR_G(cwd), DEFAULT_DIR_SEPARATOR, PG(include_path));
efree(arch);
- ret = php_resolve_path(filename, filename_len, path TSRMLS_CC);
+ ret = php_resolve_path(filename, filename_len, path);
efree(path);
- if (ret && strlen(ret) > 8 && !strncmp(ret, "phar://", 7)) {
- ret_len = strlen(ret);
+ if (ret && ZSTR_LEN(ret) > 8 && !strncmp(ZSTR_VAL(ret), "phar://", 7)) {
/* found phar:// */
-
- if (SUCCESS != phar_split_fname(ret, ret_len, &arch, &arch_len, &entry, &entry_len, 1, 0 TSRMLS_CC)) {
+ if (SUCCESS != phar_split_fname(ZSTR_VAL(ret), ZSTR_LEN(ret), &arch, &arch_len, &entry, &entry_len, 1, 0)) {
return ret;
}
- zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len, (void **) &pphar);
+ *pphar = zend_hash_str_find_ptr(&(PHAR_G(phar_fname_map)), arch, arch_len);
- if (!pphar && PHAR_G(manifest_cached)) {
- zend_hash_find(&cached_phars, arch, arch_len, (void **) &pphar);
+ if (!*pphar && PHAR_G(manifest_cached)) {
+ *pphar = zend_hash_str_find_ptr(&cached_phars, arch, arch_len);
}
efree(arch);
@@ -350,7 +349,7 @@ splitted:
* appended, truncated, or read. For read, if the entry is marked unmodified, it is
* assumed that the file pointer, if present, is opened for reading
*/
-int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char *path, int path_len, const char *mode, char allow_dir, char **error, int security TSRMLS_DC) /* {{{ */
+int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char *path, int path_len, const char *mode, char allow_dir, char **error, int security) /* {{{ */
{
phar_archive_data *phar;
phar_entry_info *entry;
@@ -369,7 +368,7 @@ int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char
*error = NULL;
}
- if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, error TSRMLS_CC)) {
+ if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, error)) {
return FAILURE;
}
@@ -388,14 +387,14 @@ int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char
}
really_get_entry:
if (allow_dir) {
- if ((entry = phar_get_entry_info_dir(phar, path, path_len, allow_dir, for_create && !PHAR_G(readonly) && !phar->is_data ? NULL : error, security TSRMLS_CC)) == NULL) {
+ if ((entry = phar_get_entry_info_dir(phar, path, path_len, allow_dir, for_create && !PHAR_G(readonly) && !phar->is_data ? NULL : error, security)) == NULL) {
if (for_create && (!PHAR_G(readonly) || phar->is_data)) {
return SUCCESS;
}
return FAILURE;
}
} else {
- if ((entry = phar_get_entry_info(phar, path, path_len, for_create && !PHAR_G(readonly) && !phar->is_data ? NULL : error, security TSRMLS_CC)) == NULL) {
+ if ((entry = phar_get_entry_info(phar, path, path_len, for_create && !PHAR_G(readonly) && !phar->is_data ? NULL : error, security)) == NULL) {
if (for_create && (!PHAR_G(readonly) || phar->is_data)) {
return SUCCESS;
}
@@ -404,7 +403,7 @@ really_get_entry:
}
if (for_write && phar->is_persistent) {
- if (FAILURE == phar_copy_on_write(&phar TSRMLS_CC)) {
+ if (FAILURE == phar_copy_on_write(&phar)) {
if (error) {
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, could not make cached phar writeable", path, fname);
}
@@ -455,11 +454,11 @@ really_get_entry:
if (entry->fp_type == PHAR_MOD) {
if (for_trunc) {
- if (FAILURE == phar_create_writeable_entry(phar, entry, error TSRMLS_CC)) {
+ if (FAILURE == phar_create_writeable_entry(phar, entry, error)) {
return FAILURE;
}
} else if (for_append) {
- phar_seek_efp(entry, 0, SEEK_END, 0, 0 TSRMLS_CC);
+ phar_seek_efp(entry, 0, SEEK_END, 0, 0);
}
} else {
if (for_write) {
@@ -470,16 +469,16 @@ really_get_entry:
}
if (for_trunc) {
- if (FAILURE == phar_create_writeable_entry(phar, entry, error TSRMLS_CC)) {
+ if (FAILURE == phar_create_writeable_entry(phar, entry, error)) {
return FAILURE;
}
} else {
- if (FAILURE == phar_separate_entry_fp(entry, error TSRMLS_CC)) {
+ if (FAILURE == phar_separate_entry_fp(entry, error)) {
return FAILURE;
}
}
} else {
- if (FAILURE == phar_open_entry_fp(entry, error, 1 TSRMLS_CC)) {
+ if (FAILURE == phar_open_entry_fp(entry, error, 1)) {
return FAILURE;
}
}
@@ -492,16 +491,16 @@ really_get_entry:
(*ret)->internal_file = entry;
(*ret)->is_zip = entry->is_zip;
(*ret)->is_tar = entry->is_tar;
- (*ret)->fp = phar_get_efp(entry, 1 TSRMLS_CC);
+ (*ret)->fp = phar_get_efp(entry, 1);
if (entry->link) {
- phar_entry_info *link = phar_get_link_source(entry TSRMLS_CC);
+ phar_entry_info *link = phar_get_link_source(entry);
if(!link) {
efree(*ret);
return FAILURE;
}
- (*ret)->zero = phar_get_fp_offset(link TSRMLS_CC);
+ (*ret)->zero = phar_get_fp_offset(link);
} else {
- (*ret)->zero = phar_get_fp_offset(entry TSRMLS_CC);
+ (*ret)->zero = phar_get_fp_offset(entry);
}
if (!phar->is_persistent) {
@@ -516,7 +515,7 @@ really_get_entry:
/**
* Create a new dummy file slot within a writeable phar for a newly created file
*/
-phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char *path, int path_len, const char *mode, char allow_dir, char **error, int security TSRMLS_DC) /* {{{ */
+phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char *path, int path_len, const char *mode, char allow_dir, char **error, int security) /* {{{ */
{
phar_archive_data *phar;
phar_entry_info *entry, etemp;
@@ -530,11 +529,11 @@ phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char
is_dir = (path_len && path[path_len - 1] == '/') ? 1 : 0;
- if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, error TSRMLS_CC)) {
+ if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, error)) {
return NULL;
}
- if (FAILURE == phar_get_entry_data(&ret, fname, fname_len, path, path_len, mode, allow_dir, error, security TSRMLS_CC)) {
+ if (FAILURE == phar_get_entry_data(&ret, fname, fname_len, path, path_len, mode, allow_dir, error, security)) {
return NULL;
} else if (ret) {
return ret;
@@ -547,7 +546,7 @@ phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char
return NULL;
}
- if (phar->is_persistent && FAILURE == phar_copy_on_write(&phar TSRMLS_CC)) {
+ if (phar->is_persistent && FAILURE == phar_copy_on_write(&phar)) {
if (error) {
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be created, could not make cached phar writeable", path, fname);
}
@@ -584,7 +583,7 @@ phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char
path_len--;
}
- phar_add_virtual_dirs(phar, path, path_len TSRMLS_CC);
+ phar_add_virtual_dirs(phar, path, path_len);
etemp.is_modified = 1;
etemp.timestamp = time(0);
etemp.is_crc_checked = 1;
@@ -597,7 +596,7 @@ phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char
etemp.tar_type = etemp.is_dir ? TAR_DIR : TAR_FILE;
}
- if (FAILURE == zend_hash_add(&phar->manifest, etemp.filename, path_len, (void*)&etemp, sizeof(phar_entry_info), (void **) &entry)) {
+ if (NULL == (entry = zend_hash_str_add_mem(&phar->manifest, etemp.filename, path_len, (void*)&etemp, sizeof(phar_entry_info)))) {
php_stream_close(etemp.fp);
if (error) {
spprintf(error, 0, "phar error: unable to add new entry \"%s\" to phar \"%s\"", etemp.filename, phar->fname);
@@ -628,19 +627,19 @@ phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char
/* }}} */
/* initialize a phar_archive_data's read-only fp for existing phar data */
-int phar_open_archive_fp(phar_archive_data *phar TSRMLS_DC) /* {{{ */
+int phar_open_archive_fp(phar_archive_data *phar) /* {{{ */
{
- if (phar_get_pharfp(phar TSRMLS_CC)) {
+ if (phar_get_pharfp(phar)) {
return SUCCESS;
}
- if (php_check_open_basedir(phar->fname TSRMLS_CC)) {
+ if (php_check_open_basedir(phar->fname)) {
return FAILURE;
}
- phar_set_pharfp(phar, php_stream_open_wrapper(phar->fname, "rb", IGNORE_URL|STREAM_MUST_SEEK|0, NULL) TSRMLS_CC);
+ phar_set_pharfp(phar, php_stream_open_wrapper(phar->fname, "rb", IGNORE_URL|STREAM_MUST_SEEK|0, NULL));
- if (!phar_get_pharfp(phar TSRMLS_CC)) {
+ if (!phar_get_pharfp(phar)) {
return FAILURE;
}
@@ -649,11 +648,11 @@ int phar_open_archive_fp(phar_archive_data *phar TSRMLS_DC) /* {{{ */
/* }}} */
/* copy file data from an existing to a new phar_entry_info that is not in the manifest */
-int phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, char **error TSRMLS_DC) /* {{{ */
+int phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, char **error) /* {{{ */
{
phar_entry_info *link;
- if (FAILURE == phar_open_entry_fp(source, error, 1 TSRMLS_CC)) {
+ if (FAILURE == phar_open_entry_fp(source, error, 1)) {
return FAILURE;
}
@@ -671,14 +670,14 @@ int phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, char **er
spprintf(error, 0, "phar error: unable to create temporary file");
return EOF;
}
- phar_seek_efp(source, 0, SEEK_SET, 0, 1 TSRMLS_CC);
- link = phar_get_link_source(source TSRMLS_CC);
+ phar_seek_efp(source, 0, SEEK_SET, 0, 1);
+ link = phar_get_link_source(source);
if (!link) {
link = source;
}
- if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(link, 0 TSRMLS_CC), dest->fp, link->uncompressed_filesize, NULL)) {
+ if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(link, 0), dest->fp, link->uncompressed_filesize, NULL)) {
php_stream_close(dest->fp);
dest->fp_type = PHAR_FP;
if (error) {
@@ -693,19 +692,19 @@ int phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, char **er
/* open and decompress a compressed phar entry
*/
-int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TSRMLS_DC) /* {{{ */
+int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links) /* {{{ */
{
php_stream_filter *filter;
phar_archive_data *phar = entry->phar;
char *filtername;
- off_t loc;
+ zend_off_t loc;
php_stream *ufp;
phar_entry_data dummy;
if (follow_links && entry->link) {
- phar_entry_info *link_entry = phar_get_link_source(entry TSRMLS_CC);
+ phar_entry_info *link_entry = phar_get_link_source(entry);
if (link_entry && link_entry != entry) {
- return phar_open_entry_fp(link_entry, error, 1 TSRMLS_CC);
+ return phar_open_entry_fp(link_entry, error, 1);
}
}
@@ -725,8 +724,8 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TS
return SUCCESS;
}
- if (!phar_get_pharfp(phar TSRMLS_CC)) {
- if (FAILURE == phar_open_archive_fp(phar TSRMLS_CC)) {
+ if (!phar_get_pharfp(phar)) {
+ if (FAILURE == phar_open_archive_fp(phar)) {
spprintf(error, 4096, "phar error: Cannot open phar archive \"%s\" for reading", phar->fname);
return FAILURE;
}
@@ -736,16 +735,16 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TS
dummy.internal_file = entry;
dummy.phar = phar;
dummy.zero = entry->offset;
- dummy.fp = phar_get_pharfp(phar TSRMLS_CC);
- if (FAILURE == phar_postprocess_file(&dummy, entry->crc32, error, 1 TSRMLS_CC)) {
+ dummy.fp = phar_get_pharfp(phar);
+ if (FAILURE == phar_postprocess_file(&dummy, entry->crc32, error, 1)) {
return FAILURE;
}
return SUCCESS;
}
- if (!phar_get_entrypufp(entry TSRMLS_CC)) {
- phar_set_entrypufp(entry, php_stream_fopen_tmpfile() TSRMLS_CC);
- if (!phar_get_entrypufp(entry TSRMLS_CC)) {
+ if (!phar_get_entrypufp(entry)) {
+ phar_set_entrypufp(entry, php_stream_fopen_tmpfile());
+ if (!phar_get_entrypufp(entry)) {
spprintf(error, 4096, "phar error: Cannot open temporary file for decompressing phar archive \"%s\" file \"%s\"", phar->fname, entry->filename);
return FAILURE;
}
@@ -754,15 +753,15 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TS
dummy.internal_file = entry;
dummy.phar = phar;
dummy.zero = entry->offset;
- dummy.fp = phar_get_pharfp(phar TSRMLS_CC);
- if (FAILURE == phar_postprocess_file(&dummy, entry->crc32, error, 1 TSRMLS_CC)) {
+ dummy.fp = phar_get_pharfp(phar);
+ if (FAILURE == phar_postprocess_file(&dummy, entry->crc32, error, 1)) {
return FAILURE;
}
- ufp = phar_get_entrypufp(entry TSRMLS_CC);
+ ufp = phar_get_entrypufp(entry);
if ((filtername = phar_decompress_filter(entry, 0)) != NULL) {
- filter = php_stream_filter_create(filtername, NULL, 0 TSRMLS_CC);
+ filter = php_stream_filter_create(filtername, NULL, 0);
} else {
filter = NULL;
}
@@ -777,21 +776,21 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TS
php_stream_seek(ufp, 0, SEEK_END);
loc = php_stream_tell(ufp);
php_stream_filter_append(&ufp->writefilters, filter);
- php_stream_seek(phar_get_entrypfp(entry TSRMLS_CC), phar_get_fp_offset(entry TSRMLS_CC), SEEK_SET);
+ php_stream_seek(phar_get_entrypfp(entry), phar_get_fp_offset(entry), SEEK_SET);
if (entry->uncompressed_filesize) {
- if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_entrypfp(entry TSRMLS_CC), ufp, entry->compressed_filesize, NULL)) {
+ if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_entrypfp(entry), ufp, entry->compressed_filesize, NULL)) {
spprintf(error, 4096, "phar error: internal corruption of phar \"%s\" (actual filesize mismatch on file \"%s\")", phar->fname, entry->filename);
- php_stream_filter_remove(filter, 1 TSRMLS_CC);
+ php_stream_filter_remove(filter, 1);
return FAILURE;
}
}
php_stream_filter_flush(filter, 1);
php_stream_flush(ufp);
- php_stream_filter_remove(filter, 1 TSRMLS_CC);
+ php_stream_filter_remove(filter, 1);
- if (php_stream_tell(ufp) - loc != (off_t) entry->uncompressed_filesize) {
+ if (php_stream_tell(ufp) - loc != (zend_off_t) entry->uncompressed_filesize) {
spprintf(error, 4096, "phar error: internal corruption of phar \"%s\" (actual filesize mismatch on file \"%s\")", phar->fname, entry->filename);
return FAILURE;
}
@@ -799,17 +798,17 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TS
entry->old_flags = entry->flags;
/* this is now the new location of the file contents within this fp */
- phar_set_fp_type(entry, PHAR_UFP, loc TSRMLS_CC);
+ phar_set_fp_type(entry, PHAR_UFP, loc);
dummy.zero = entry->offset;
dummy.fp = ufp;
- if (FAILURE == phar_postprocess_file(&dummy, entry->crc32, error, 0 TSRMLS_CC)) {
+ if (FAILURE == phar_postprocess_file(&dummy, entry->crc32, error, 0)) {
return FAILURE;
}
return SUCCESS;
}
/* }}} */
-int phar_create_writeable_entry(phar_archive_data *phar, phar_entry_info *entry, char **error TSRMLS_DC) /* {{{ */
+int phar_create_writeable_entry(phar_archive_data *phar, phar_entry_info *entry, char **error) /* {{{ */
{
if (entry->fp_type == PHAR_MOD) {
/* already newly created, truncate */
@@ -862,12 +861,12 @@ int phar_create_writeable_entry(phar_archive_data *phar, phar_entry_info *entry,
}
/* }}} */
-int phar_separate_entry_fp(phar_entry_info *entry, char **error TSRMLS_DC) /* {{{ */
+int phar_separate_entry_fp(phar_entry_info *entry, char **error) /* {{{ */
{
php_stream *fp;
phar_entry_info *link;
- if (FAILURE == phar_open_entry_fp(entry, error, 1 TSRMLS_CC)) {
+ if (FAILURE == phar_open_entry_fp(entry, error, 1)) {
return FAILURE;
}
@@ -880,14 +879,14 @@ int phar_separate_entry_fp(phar_entry_info *entry, char **error TSRMLS_DC) /* {{
spprintf(error, 0, "phar error: unable to create temporary file");
return FAILURE;
}
- phar_seek_efp(entry, 0, SEEK_SET, 0, 1 TSRMLS_CC);
- link = phar_get_link_source(entry TSRMLS_CC);
+ phar_seek_efp(entry, 0, SEEK_SET, 0, 1);
+ link = phar_get_link_source(entry);
if (!link) {
link = entry;
}
- if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(link, 0 TSRMLS_CC), fp, link->uncompressed_filesize, NULL)) {
+ if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(link, 0), fp, link->uncompressed_filesize, NULL)) {
if (error) {
spprintf(error, 4096, "phar error: cannot separate entry file \"%s\" contents in phar archive \"%s\" for write access", entry->filename, entry->phar->fname);
}
@@ -911,16 +910,16 @@ int phar_separate_entry_fp(phar_entry_info *entry, char **error TSRMLS_DC) /* {{
/**
* helper function to open an internal file's fp just-in-time
*/
-phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, char **error TSRMLS_DC) /* {{{ */
+phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, char **error) /* {{{ */
{
if (error) {
*error = NULL;
}
/* seek to start of internal file and read it */
- if (FAILURE == phar_open_entry_fp(entry, error, 1 TSRMLS_CC)) {
+ if (FAILURE == phar_open_entry_fp(entry, error, 1)) {
return NULL;
}
- if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 1 TSRMLS_CC)) {
+ if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 1)) {
spprintf(error, 4096, "phar error: cannot seek to start of file \"%s\" in phar \"%s\"", entry->filename, phar->fname);
return NULL;
}
@@ -928,26 +927,26 @@ phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry,
}
/* }}} */
-PHP_PHAR_API int phar_resolve_alias(char *alias, int alias_len, char **filename, int *filename_len TSRMLS_DC) /* {{{ */ {
- phar_archive_data **fd_ptr;
- if (PHAR_GLOBALS->phar_alias_map.arBuckets
- && SUCCESS == zend_hash_find(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, (void**)&fd_ptr)) {
- *filename = (*fd_ptr)->fname;
- *filename_len = (*fd_ptr)->fname_len;
+PHP_PHAR_API int phar_resolve_alias(char *alias, int alias_len, char **filename, int *filename_len) /* {{{ */ {
+ phar_archive_data *fd_ptr;
+ if (PHAR_G(phar_alias_map.u.flags)
+ && NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), alias, alias_len))) {
+ *filename = fd_ptr->fname;
+ *filename_len = fd_ptr->fname_len;
return SUCCESS;
}
return FAILURE;
}
/* }}} */
-int phar_free_alias(phar_archive_data *phar, char *alias, int alias_len TSRMLS_DC) /* {{{ */
+int phar_free_alias(phar_archive_data *phar, char *alias, int alias_len) /* {{{ */
{
if (phar->refcount || phar->is_persistent) {
return FAILURE;
}
/* this archive has no open references, so emit an E_STRICT and remove it */
- if (zend_hash_del(&(PHAR_GLOBALS->phar_fname_map), phar->fname, phar->fname_len) != SUCCESS) {
+ if (zend_hash_str_del(&(PHAR_G(phar_fname_map)), phar->fname, phar->fname_len) != SUCCESS) {
return FAILURE;
}
@@ -963,14 +962,13 @@ int phar_free_alias(phar_archive_data *phar, char *alias, int alias_len TSRMLS_D
* Looks up a phar archive in the filename map, connecting it to the alias
* (if any) or returns null
*/
-int phar_get_archive(phar_archive_data **archive, char *fname, int fname_len, char *alias, int alias_len, char **error TSRMLS_DC) /* {{{ */
+int phar_get_archive(phar_archive_data **archive, char *fname, int fname_len, char *alias, int alias_len, char **error) /* {{{ */
{
- phar_archive_data *fd, **fd_ptr;
+ phar_archive_data *fd, *fd_ptr;
char *my_realpath, *save;
int save_len;
- ulong fhash, ahash = 0;
- phar_request_initialize(TSRMLS_C);
+ phar_request_initialize();
if (error) {
*error = NULL;
@@ -990,11 +988,11 @@ int phar_get_archive(phar_archive_data **archive, char *fname, int fname_len, ch
return FAILURE;
}
- if (PHAR_G(last_phar)->alias_len && SUCCESS == zend_hash_find(&(PHAR_GLOBALS->phar_alias_map), PHAR_G(last_phar)->alias, PHAR_G(last_phar)->alias_len, (void**)&fd_ptr)) {
- zend_hash_del(&(PHAR_GLOBALS->phar_alias_map), PHAR_G(last_phar)->alias, PHAR_G(last_phar)->alias_len);
+ if (PHAR_G(last_phar)->alias_len && NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), PHAR_G(last_phar)->alias, PHAR_G(last_phar)->alias_len))) {
+ zend_hash_str_del(&(PHAR_G(phar_alias_map)), PHAR_G(last_phar)->alias, PHAR_G(last_phar)->alias_len);
}
- zend_hash_add(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, (void*)&(*archive), sizeof(phar_archive_data*), NULL);
+ zend_hash_str_add_ptr(&(PHAR_G(phar_alias_map)), alias, alias_len, *archive);
PHAR_G(last_alias) = alias;
PHAR_G(last_alias_len) = alias_len;
}
@@ -1004,19 +1002,18 @@ int phar_get_archive(phar_archive_data **archive, char *fname, int fname_len, ch
if (alias && alias_len && PHAR_G(last_phar) && alias_len == PHAR_G(last_alias_len) && !memcmp(alias, PHAR_G(last_alias), alias_len)) {
fd = PHAR_G(last_phar);
- fd_ptr = &fd;
+ fd_ptr = fd;
goto alias_success;
}
if (alias && alias_len) {
- ahash = zend_inline_hash_func(alias, alias_len);
- if (SUCCESS == zend_hash_quick_find(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, ahash, (void**)&fd_ptr)) {
+ if (NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), alias, alias_len))) {
alias_success:
- if (fname && (fname_len != (*fd_ptr)->fname_len || strncmp(fname, (*fd_ptr)->fname, fname_len))) {
+ if (fname && (fname_len != fd_ptr->fname_len || strncmp(fname, fd_ptr->fname, fname_len))) {
if (error) {
- spprintf(error, 0, "alias \"%s\" is already used for archive \"%s\" cannot be overloaded with \"%s\"", alias, (*fd_ptr)->fname, fname);
+ spprintf(error, 0, "alias \"%s\" is already used for archive \"%s\" cannot be overloaded with \"%s\"", alias, fd_ptr->fname, fname);
}
- if (SUCCESS == phar_free_alias(*fd_ptr, alias, alias_len TSRMLS_CC)) {
+ if (SUCCESS == phar_free_alias(fd_ptr, alias, alias_len)) {
if (error) {
efree(*error);
*error = NULL;
@@ -1025,8 +1022,8 @@ alias_success:
return FAILURE;
}
- *archive = *fd_ptr;
- fd = *fd_ptr;
+ *archive = fd_ptr;
+ fd = fd_ptr;
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
PHAR_G(last_phar_name_len) = fd->fname_len;
@@ -1036,34 +1033,33 @@ alias_success:
return SUCCESS;
}
- if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_quick_find(&cached_alias, alias, alias_len, ahash, (void **)&fd_ptr)) {
+ if (PHAR_G(manifest_cached) && NULL != (fd_ptr = zend_hash_str_find_ptr(&cached_alias, alias, alias_len))) {
goto alias_success;
}
}
- fhash = zend_inline_hash_func(fname, fname_len);
my_realpath = NULL;
save = fname;
save_len = fname_len;
if (fname && fname_len) {
- if (SUCCESS == zend_hash_quick_find(&(PHAR_GLOBALS->phar_fname_map), fname, fname_len, fhash, (void**)&fd_ptr)) {
- *archive = *fd_ptr;
- fd = *fd_ptr;
+ if (NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_fname_map)), fname, fname_len))) {
+ *archive = fd_ptr;
+ fd = fd_ptr;
if (alias && alias_len) {
if (!fd->is_temporary_alias && (alias_len != fd->alias_len || memcmp(fd->alias, alias, alias_len))) {
if (error) {
- spprintf(error, 0, "alias \"%s\" is already used for archive \"%s\" cannot be overloaded with \"%s\"", alias, (*fd_ptr)->fname, fname);
+ spprintf(error, 0, "alias \"%s\" is already used for archive \"%s\" cannot be overloaded with \"%s\"", alias, fd_ptr->fname, fname);
}
return FAILURE;
}
- if (fd->alias_len && SUCCESS == zend_hash_find(&(PHAR_GLOBALS->phar_alias_map), fd->alias, fd->alias_len, (void**)&fd_ptr)) {
- zend_hash_del(&(PHAR_GLOBALS->phar_alias_map), fd->alias, fd->alias_len);
+ if (fd->alias_len && NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), fd->alias, fd->alias_len))) {
+ zend_hash_str_del(&(PHAR_G(phar_alias_map)), fd->alias, fd->alias_len);
}
- zend_hash_quick_add(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, ahash, (void*)&fd, sizeof(phar_archive_data*), NULL);
+ zend_hash_str_add_ptr(&(PHAR_G(phar_alias_map)), alias, alias_len, fd);
}
PHAR_G(last_phar) = fd;
@@ -1075,16 +1071,16 @@ alias_success:
return SUCCESS;
}
- if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_quick_find(&cached_phars, fname, fname_len, fhash, (void**)&fd_ptr)) {
- *archive = *fd_ptr;
- fd = *fd_ptr;
+ if (PHAR_G(manifest_cached) && NULL != (fd_ptr = zend_hash_str_find_ptr(&cached_phars, fname, fname_len))) {
+ *archive = fd_ptr;
+ fd = fd_ptr;
/* this could be problematic - alias should never be different from manifest alias
for cached phars */
if (!fd->is_temporary_alias && alias && alias_len) {
if (alias_len != fd->alias_len || memcmp(fd->alias, alias, alias_len)) {
if (error) {
- spprintf(error, 0, "alias \"%s\" is already used for archive \"%s\" cannot be overloaded with \"%s\"", alias, (*fd_ptr)->fname, fname);
+ spprintf(error, 0, "alias \"%s\" is already used for archive \"%s\" cannot be overloaded with \"%s\"", alias, fd_ptr->fname, fname);
}
return FAILURE;
}
@@ -1099,8 +1095,8 @@ alias_success:
return SUCCESS;
}
- if (SUCCESS == zend_hash_quick_find(&(PHAR_GLOBALS->phar_alias_map), save, save_len, fhash, (void**)&fd_ptr)) {
- fd = *archive = *fd_ptr;
+ if (NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), save, save_len))) {
+ fd = *archive = fd_ptr;
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
@@ -1111,8 +1107,8 @@ alias_success:
return SUCCESS;
}
- if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_quick_find(&cached_alias, save, save_len, fhash, (void**)&fd_ptr)) {
- fd = *archive = *fd_ptr;
+ if (PHAR_G(manifest_cached) && NULL != (fd_ptr = zend_hash_str_find_ptr(&cached_alias, save, save_len))) {
+ fd = *archive = fd_ptr;
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
@@ -1124,7 +1120,7 @@ alias_success:
}
/* not found, try converting \ to / */
- my_realpath = expand_filepath(fname, my_realpath TSRMLS_CC);
+ my_realpath = expand_filepath(fname, my_realpath);
if (my_realpath) {
fname_len = strlen(my_realpath);
@@ -1135,15 +1131,14 @@ alias_success:
#ifdef PHP_WIN32
phar_unixify_path_separators(fname, fname_len);
#endif
- fhash = zend_inline_hash_func(fname, fname_len);
- if (SUCCESS == zend_hash_quick_find(&(PHAR_GLOBALS->phar_fname_map), fname, fname_len, fhash, (void**)&fd_ptr)) {
+ if (NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_fname_map)), fname, fname_len))) {
realpath_success:
- *archive = *fd_ptr;
- fd = *fd_ptr;
+ *archive = fd_ptr;
+ fd = fd_ptr;
if (alias && alias_len) {
- zend_hash_quick_add(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, ahash, (void*)&fd, sizeof(phar_archive_data*), NULL);
+ zend_hash_str_add_ptr(&(PHAR_G(phar_alias_map)), alias, alias_len, fd);
}
efree(my_realpath);
@@ -1157,7 +1152,7 @@ realpath_success:
return SUCCESS;
}
- if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_quick_find(&cached_phars, fname, fname_len, fhash, (void**)&fd_ptr)) {
+ if (PHAR_G(manifest_cached) && NULL != (fd_ptr = zend_hash_str_find_ptr(&cached_phars, fname, fname_len))) {
goto realpath_success;
}
@@ -1211,9 +1206,9 @@ char * phar_decompress_filter(phar_entry_info * entry, int return_unknown) /* {{
/**
* retrieve information on a file contained within a phar, or null if it ain't there
*/
-phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, int path_len, char **error, int security TSRMLS_DC) /* {{{ */
+phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, int path_len, char **error, int security) /* {{{ */
{
- return phar_get_entry_info_dir(phar, path, path_len, 0, error, security TSRMLS_CC);
+ return phar_get_entry_info_dir(phar, path, path_len, 0, error, security);
}
/* }}} */
/**
@@ -1221,7 +1216,7 @@ phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, int pa
* allow_dir is 0 for none, 1 for both empty directories in the phar and temp directories, and 2 for only
* valid pre-existing empty directory entries
*/
-phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, int path_len, char dir, char **error, int security TSRMLS_DC) /* {{{ */
+phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, int path_len, char dir, char **error, int security) /* {{{ */
{
const char *pcr_error;
phar_entry_info *entry;
@@ -1258,7 +1253,7 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
return NULL;
}
- if (!phar->manifest.arBuckets) {
+ if (!phar->manifest.u.flags) {
return NULL;
}
@@ -1269,7 +1264,7 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
path_len--;
}
- if (SUCCESS == zend_hash_find(&phar->manifest, path, path_len, (void**)&entry)) {
+ if (NULL != (entry = zend_hash_str_find_ptr(&phar->manifest, path, path_len))) {
if (entry->is_deleted) {
/* entry is deleted, but has not been flushed to disk yet */
return NULL;
@@ -1291,7 +1286,7 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
}
if (dir) {
- if (zend_hash_exists(&phar->virtual_dirs, path, path_len)) {
+ if (zend_hash_str_exists(&phar->virtual_dirs, path, path_len)) {
/* a file or directory exists in a sub-directory of this path */
entry = (phar_entry_info *) ecalloc(1, sizeof(phar_entry_info));
/* this next line tells PharFileInfo->__destruct() to efree the filename */
@@ -1303,39 +1298,32 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
}
}
- if (phar->mounted_dirs.arBuckets && zend_hash_num_elements(&phar->mounted_dirs)) {
- char *str_key;
- ulong unused;
- uint keylen;
-
- zend_hash_internal_pointer_reset(&phar->mounted_dirs);
- while (FAILURE != zend_hash_has_more_elements(&phar->mounted_dirs)) {
- if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(&phar->mounted_dirs, &str_key, &keylen, &unused, 0, NULL)) {
- break;
- }
+ if (phar->mounted_dirs.u.flags && zend_hash_num_elements(&phar->mounted_dirs)) {
+ zend_string *str_key;
- if ((int)keylen >= path_len || strncmp(str_key, path, keylen)) {
+ ZEND_HASH_FOREACH_STR_KEY(&phar->mounted_dirs, str_key) {
+ if ((int)ZSTR_LEN(str_key) >= path_len || strncmp(ZSTR_VAL(str_key), path, ZSTR_LEN(str_key))) {
continue;
} else {
char *test;
int test_len;
php_stream_statbuf ssb;
- if (SUCCESS != zend_hash_find(&phar->manifest, str_key, keylen, (void **) &entry)) {
+ if (NULL == (entry = zend_hash_find_ptr(&phar->manifest, str_key))) {
if (error) {
- spprintf(error, 4096, "phar internal error: mounted path \"%s\" could not be retrieved from manifest", str_key);
+ spprintf(error, 4096, "phar internal error: mounted path \"%s\" could not be retrieved from manifest", ZSTR_VAL(str_key));
}
return NULL;
}
if (!entry->tmp || !entry->is_mounted) {
if (error) {
- spprintf(error, 4096, "phar internal error: mounted path \"%s\" is not properly initialized as a mounted path", str_key);
+ spprintf(error, 4096, "phar internal error: mounted path \"%s\" is not properly initialized as a mounted path", ZSTR_VAL(str_key));
}
return NULL;
}
- test_len = spprintf(&test, MAXPATHLEN, "%s%s", entry->tmp, path + keylen);
+ test_len = spprintf(&test, MAXPATHLEN, "%s%s", entry->tmp, path + ZSTR_LEN(str_key));
if (SUCCESS != php_stream_stat_path(test, &ssb)) {
efree(test);
@@ -1360,7 +1348,7 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
}
/* mount the file just in time */
- if (SUCCESS != phar_mount_entry(phar, test, test_len, path, path_len TSRMLS_CC)) {
+ if (SUCCESS != phar_mount_entry(phar, test, test_len, path, path_len)) {
efree(test);
if (error) {
spprintf(error, 4096, "phar error: path \"%s\" exists as file \"%s\" and could not be mounted", path, test);
@@ -1370,7 +1358,7 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
efree(test);
- if (SUCCESS != zend_hash_find(&phar->manifest, path, path_len, (void**)&entry)) {
+ if (NULL == (entry = zend_hash_str_find_ptr(&phar->manifest, path, path_len))) {
if (error) {
spprintf(error, 4096, "phar error: path \"%s\" exists as file \"%s\" and could not be retrieved after being mounted", path, test);
}
@@ -1378,7 +1366,7 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
}
return entry;
}
- }
+ } ZEND_HASH_FOREACH_END();
}
return NULL;
@@ -1387,7 +1375,7 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
static const char hexChars[] = "0123456789ABCDEF";
-static int phar_hex_str(const char *digest, size_t digest_len, char **signature TSRMLS_DC) /* {{{ */
+static int phar_hex_str(const char *digest, size_t digest_len, char **signature) /* {{{ */
{
int pos = -1;
size_t len = 0;
@@ -1404,123 +1392,98 @@ static int phar_hex_str(const char *digest, size_t digest_len, char **signature
/* }}} */
#ifndef PHAR_HAVE_OPENSSL
-static int phar_call_openssl_signverify(int is_sign, php_stream *fp, off_t end, char *key, int key_len, char **signature, int *signature_len TSRMLS_DC) /* {{{ */
+static int phar_call_openssl_signverify(int is_sign, php_stream *fp, zend_off_t end, char *key, int key_len, char **signature, int *signature_len) /* {{{ */
{
zend_fcall_info fci;
zend_fcall_info_cache fcc;
- zval *zdata, *zsig, *zkey, *retval_ptr, **zp[3], *openssl;
-
- MAKE_STD_ZVAL(zdata);
- MAKE_STD_ZVAL(openssl);
- ZVAL_STRINGL(openssl, is_sign ? "openssl_sign" : "openssl_verify", is_sign ? sizeof("openssl_sign")-1 : sizeof("openssl_verify")-1, 1);
- MAKE_STD_ZVAL(zsig);
- ZVAL_STRINGL(zsig, *signature, *signature_len, 1);
- MAKE_STD_ZVAL(zkey);
- ZVAL_STRINGL(zkey, key, key_len, 1);
- zp[0] = &zdata;
- zp[1] = &zsig;
- zp[2] = &zkey;
+ zval retval, zp[3], openssl;
+ zend_string *str;
+ ZVAL_STRINGL(&openssl, is_sign ? "openssl_sign" : "openssl_verify", is_sign ? sizeof("openssl_sign")-1 : sizeof("openssl_verify")-1);
+ ZVAL_STRINGL(&zp[1], *signature, *signature_len);
+ ZVAL_STRINGL(&zp[2], key, key_len);
php_stream_rewind(fp);
- Z_TYPE_P(zdata) = IS_STRING;
- Z_STRLEN_P(zdata) = end;
-
- if (end != (off_t) php_stream_copy_to_mem(fp, &(Z_STRVAL_P(zdata)), (size_t) end, 0)) {
- zval_dtor(zdata);
- zval_dtor(zsig);
- zval_dtor(zkey);
- zval_dtor(openssl);
- efree(openssl);
- efree(zdata);
- efree(zkey);
- efree(zsig);
+ str = php_stream_copy_to_mem(fp, (size_t) end, 0);
+ if (str) {
+ ZVAL_STR(&zp[0], str);
+ } else {
+ ZVAL_EMPTY_STRING(&zp[0]);
+ }
+
+ if (end != Z_STRLEN(zp[0])) {
+ zval_dtor(&zp[0]);
+ zval_dtor(&zp[1]);
+ zval_dtor(&zp[2]);
+ zval_dtor(&openssl);
return FAILURE;
}
- if (FAILURE == zend_fcall_info_init(openssl, 0, &fci, &fcc, NULL, NULL TSRMLS_CC)) {
- zval_dtor(zdata);
- zval_dtor(zsig);
- zval_dtor(zkey);
- zval_dtor(openssl);
- efree(openssl);
- efree(zdata);
- efree(zkey);
- efree(zsig);
+ if (FAILURE == zend_fcall_info_init(&openssl, 0, &fci, &fcc, NULL, NULL)) {
+ zval_dtor(&zp[0]);
+ zval_dtor(&zp[1]);
+ zval_dtor(&zp[2]);
+ zval_dtor(&openssl);
return FAILURE;
}
fci.param_count = 3;
fci.params = zp;
- Z_ADDREF_P(zdata);
+ Z_ADDREF(zp[0]);
if (is_sign) {
- Z_SET_ISREF_P(zsig);
+ ZVAL_NEW_REF(&zp[1], &zp[1]);
} else {
- Z_ADDREF_P(zsig);
+ Z_ADDREF(zp[1]);
}
- Z_ADDREF_P(zkey);
+ Z_ADDREF(zp[2]);
- fci.retval_ptr_ptr = &retval_ptr;
+ fci.retval = &retval;
- if (FAILURE == zend_call_function(&fci, &fcc TSRMLS_CC)) {
- zval_dtor(zdata);
- zval_dtor(zsig);
- zval_dtor(zkey);
- zval_dtor(openssl);
- efree(openssl);
- efree(zdata);
- efree(zkey);
- efree(zsig);
+ if (FAILURE == zend_call_function(&fci, &fcc)) {
+ zval_dtor(&zp[0]);
+ zval_dtor(&zp[1]);
+ zval_dtor(&zp[2]);
+ zval_dtor(&openssl);
return FAILURE;
}
- zval_dtor(openssl);
- efree(openssl);
- Z_DELREF_P(zdata);
+ zval_dtor(&openssl);
+ Z_DELREF(zp[0]);
if (is_sign) {
- Z_UNSET_ISREF_P(zsig);
+ ZVAL_UNREF(&zp[1]);
} else {
- Z_DELREF_P(zsig);
+ Z_DELREF(zp[1]);
}
- Z_DELREF_P(zkey);
+ Z_DELREF(zp[2]);
- zval_dtor(zdata);
- efree(zdata);
- zval_dtor(zkey);
- efree(zkey);
+ zval_dtor(&zp[0]);
+ zval_dtor(&zp[2]);
- switch (Z_TYPE_P(retval_ptr)) {
+ switch (Z_TYPE(retval)) {
default:
case IS_LONG:
- zval_dtor(zsig);
- efree(zsig);
- if (1 == Z_LVAL_P(retval_ptr)) {
- efree(retval_ptr);
+ zval_dtor(&zp[1]);
+ if (1 == Z_LVAL(retval)) {
return SUCCESS;
}
- efree(retval_ptr);
return FAILURE;
- case IS_BOOL:
- efree(retval_ptr);
- if (Z_BVAL_P(retval_ptr)) {
- *signature = estrndup(Z_STRVAL_P(zsig), Z_STRLEN_P(zsig));
- *signature_len = Z_STRLEN_P(zsig);
- zval_dtor(zsig);
- efree(zsig);
- return SUCCESS;
- }
- zval_dtor(zsig);
- efree(zsig);
+ case IS_TRUE:
+ *signature = estrndup(Z_STRVAL(zp[1]), Z_STRLEN(zp[1]));
+ *signature_len = Z_STRLEN(zp[1]);
+ zval_dtor(&zp[1]);
+ return SUCCESS;
+ case IS_FALSE:
+ zval_dtor(&zp[1]);
return FAILURE;
}
}
/* }}} */
#endif /* #ifndef PHAR_HAVE_OPENSSL */
-int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_type, char *sig, int sig_len, char *fname, char **signature, int *signature_len, char **error TSRMLS_DC) /* {{{ */
+int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_type, char *sig, int sig_len, char *fname, char **signature, int *signature_len, char **error) /* {{{ */
{
int read_size, len;
- off_t read_len;
+ zend_off_t read_len;
unsigned char buf[1024];
php_stream_rewind(fp);
@@ -1535,11 +1498,11 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
#else
int tempsig;
#endif
- php_uint32 pubkey_len;
- char *pubkey = NULL, *pfile;
+ zend_string *pubkey = NULL;
+ char *pfile;
php_stream *pfp;
#ifndef PHAR_HAVE_OPENSSL
- if (!zend_hash_exists(&module_registry, "openssl", sizeof("openssl"))) {
+ if (!zend_hash_str_exists(&module_registry, "openssl", sizeof("openssl")-1)) {
if (error) {
spprintf(error, 0, "openssl not loaded");
}
@@ -1551,11 +1514,7 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
pfp = php_stream_open_wrapper(pfile, "rb", 0, NULL);
efree(pfile);
-#if PHP_MAJOR_VERSION > 5
- if (!pfp || !(pubkey_len = php_stream_copy_to_mem(pfp, (void **) &pubkey, PHP_STREAM_COPY_ALL, 0)) || !pubkey) {
-#else
- if (!pfp || !(pubkey_len = php_stream_copy_to_mem(pfp, &pubkey, PHP_STREAM_COPY_ALL, 0)) || !pubkey) {
-#endif
+ if (!pfp || !(pubkey = php_stream_copy_to_mem(pfp, PHP_STREAM_COPY_ALL, 0)) || !ZSTR_LEN(pubkey)) {
if (pfp) {
php_stream_close(pfp);
}
@@ -1569,9 +1528,9 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
#ifndef PHAR_HAVE_OPENSSL
tempsig = sig_len;
- if (FAILURE == phar_call_openssl_signverify(0, fp, end_of_phar, pubkey, pubkey_len, &sig, &tempsig TSRMLS_CC)) {
+ if (FAILURE == phar_call_openssl_signverify(0, fp, end_of_phar, pubkey ? ZSTR_VAL(pubkey) : NULL, pubkey ? ZSTR_LEN(pubkey) : 0, &sig, &tempsig)) {
if (pubkey) {
- efree(pubkey);
+ zend_string_release(pubkey);
}
if (error) {
@@ -1582,15 +1541,15 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
}
if (pubkey) {
- efree(pubkey);
+ zend_string_release(pubkey);
}
sig_len = tempsig;
#else
- in = BIO_new_mem_buf(pubkey, pubkey_len);
+ in = BIO_new_mem_buf(pubkey ? ZSTR_VAL(pubkey) : NULL, pubkey ? ZSTR_LEN(pubkey) : 0);
if (NULL == in) {
- efree(pubkey);
+ zend_string_release(pubkey);
if (error) {
spprintf(error, 0, "openssl signature could not be processed");
}
@@ -1599,7 +1558,7 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
key = PEM_read_bio_PUBKEY(in, NULL,NULL, NULL);
BIO_free(in);
- efree(pubkey);
+ zend_string_release(pubkey);
if (NULL == key) {
if (error) {
@@ -1621,7 +1580,7 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
while (read_size && (len = php_stream_read(fp, (char*)buf, read_size)) > 0) {
EVP_VerifyUpdate (&md_ctx, buf, len);
- read_len -= (off_t)len;
+ read_len -= (zend_off_t)len;
if (read_len < read_size) {
read_size = (int)read_len;
@@ -1642,7 +1601,7 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
EVP_MD_CTX_cleanup(&md_ctx);
#endif
- *signature_len = phar_hex_str((const char*)sig, sig_len, signature TSRMLS_CC);
+ *signature_len = phar_hex_str((const char*)sig, sig_len, signature);
}
break;
#ifdef PHAR_HASH_OK
@@ -1661,7 +1620,7 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
while ((len = php_stream_read(fp, (char*)buf, read_size)) > 0) {
PHP_SHA512Update(&context, buf, len);
- read_len -= (off_t)len;
+ read_len -= (zend_off_t)len;
if (read_len < read_size) {
read_size = (int)read_len;
}
@@ -1676,7 +1635,7 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
return FAILURE;
}
- *signature_len = phar_hex_str((const char*)digest, sizeof(digest), signature TSRMLS_CC);
+ *signature_len = phar_hex_str((const char*)digest, sizeof(digest), signature);
break;
}
case PHAR_SIG_SHA256: {
@@ -1694,7 +1653,7 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
while ((len = php_stream_read(fp, (char*)buf, read_size)) > 0) {
PHP_SHA256Update(&context, buf, len);
- read_len -= (off_t)len;
+ read_len -= (zend_off_t)len;
if (read_len < read_size) {
read_size = (int)read_len;
}
@@ -1709,7 +1668,7 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
return FAILURE;
}
- *signature_len = phar_hex_str((const char*)digest, sizeof(digest), signature TSRMLS_CC);
+ *signature_len = phar_hex_str((const char*)digest, sizeof(digest), signature);
break;
}
#else
@@ -1735,7 +1694,7 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
while ((len = php_stream_read(fp, (char*)buf, read_size)) > 0) {
PHP_SHA1Update(&context, buf, len);
- read_len -= (off_t)len;
+ read_len -= (zend_off_t)len;
if (read_len < read_size) {
read_size = (int)read_len;
}
@@ -1750,7 +1709,7 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
return FAILURE;
}
- *signature_len = phar_hex_str((const char*)digest, sizeof(digest), signature TSRMLS_CC);
+ *signature_len = phar_hex_str((const char*)digest, sizeof(digest), signature);
break;
}
case PHAR_SIG_MD5: {
@@ -1768,7 +1727,7 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
while ((len = php_stream_read(fp, (char*)buf, read_size)) > 0) {
PHP_MD5Update(&context, buf, len);
- read_len -= (off_t)len;
+ read_len -= (zend_off_t)len;
if (read_len < read_size) {
read_size = (int)read_len;
}
@@ -1783,7 +1742,7 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
return FAILURE;
}
- *signature_len = phar_hex_str((const char*)digest, sizeof(digest), signature TSRMLS_CC);
+ *signature_len = phar_hex_str((const char*)digest, sizeof(digest), signature);
break;
}
default:
@@ -1796,7 +1755,7 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
}
/* }}} */
-int phar_create_signature(phar_archive_data *phar, php_stream *fp, char **signature, int *signature_length, char **error TSRMLS_DC) /* {{{ */
+int phar_create_signature(phar_archive_data *phar, php_stream *fp, char **signature, int *signature_length, char **error) /* {{{ */
{
unsigned char buf[1024];
int sig_len;
@@ -1914,7 +1873,7 @@ int phar_create_signature(phar_archive_data *phar, php_stream *fp, char **signat
siglen = 0;
php_stream_seek(fp, 0, SEEK_END);
- if (FAILURE == phar_call_openssl_signverify(1, fp, php_stream_tell(fp), PHAR_G(openssl_privatekey), PHAR_G(openssl_privatekey_len), (char **)&sigbuf, &siglen TSRMLS_CC)) {
+ if (FAILURE == phar_call_openssl_signverify(1, fp, php_stream_tell(fp), PHAR_G(openssl_privatekey), PHAR_G(openssl_privatekey_len), (char **)&sigbuf, &siglen)) {
if (error) {
spprintf(error, 0, "unable to write phar \"%s\" with requested openssl signature", phar->fname);
}
@@ -1959,28 +1918,27 @@ int phar_create_signature(phar_archive_data *phar, php_stream *fp, char **signat
}
}
- phar->sig_len = phar_hex_str((const char *)*signature, *signature_length, &phar->signature TSRMLS_CC);
+ phar->sig_len = phar_hex_str((const char *)*signature, *signature_length, &phar->signature);
return SUCCESS;
}
/* }}} */
-void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename_len TSRMLS_DC) /* {{{ */
+void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename_len) /* {{{ */
{
const char *s;
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || NULL == zend_hash_str_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
}
/* }}} */
-static int phar_update_cached_entry(void *data, void *argument) /* {{{ */
+static int phar_update_cached_entry(zval *data, void *argument) /* {{{ */
{
- phar_entry_info *entry = (phar_entry_info *)data;
- TSRMLS_FETCH();
+ phar_entry_info *entry = (phar_entry_info *)Z_PTR_P(data);
entry->phar = (phar_archive_data *)argument;
@@ -1992,38 +1950,39 @@ static int phar_update_cached_entry(void *data, void *argument) /* {{{ */
entry->tmp = estrdup(entry->tmp);
}
- entry->metadata_str.c = 0;
+ entry->metadata_str.s = NULL;
entry->filename = estrndup(entry->filename, entry->filename_len);
entry->is_persistent = 0;
- if (entry->metadata) {
+ if (Z_TYPE(entry->metadata) != IS_UNDEF) {
if (entry->metadata_len) {
- char *buf = estrndup((char *) entry->metadata, entry->metadata_len);
+ char *buf = estrndup((char *) Z_PTR(entry->metadata), entry->metadata_len);
/* assume success, we would have failed before */
- phar_parse_metadata((char **) &buf, &entry->metadata, entry->metadata_len TSRMLS_CC);
+ phar_parse_metadata((char **) &buf, &entry->metadata, entry->metadata_len);
efree(buf);
} else {
- zval *t;
-
- t = entry->metadata;
- ALLOC_ZVAL(entry->metadata);
- *entry->metadata = *t;
- zval_copy_ctor(entry->metadata);
- Z_SET_REFCOUNT_P(entry->metadata, 1);
- entry->metadata_str.c = NULL;
- entry->metadata_str.len = 0;
+ zval_copy_ctor(&entry->metadata);
+ entry->metadata_str.s = NULL;
}
}
return ZEND_HASH_APPLY_KEEP;
}
/* }}} */
-static void phar_copy_cached_phar(phar_archive_data **pphar TSRMLS_DC) /* {{{ */
+static void phar_manifest_copy_ctor(zval *zv) /* {{{ */
+{
+ phar_entry_info *info = emalloc(sizeof(phar_entry_info));
+ memcpy(info, Z_PTR_P(zv), sizeof(phar_entry_info));
+ Z_PTR_P(zv) = info;
+}
+/* }}} */
+
+static void phar_copy_cached_phar(phar_archive_data **pphar) /* {{{ */
{
phar_archive_data *phar;
HashTable newmanifest;
char *fname;
- phar_archive_object **objphar;
+ phar_archive_object *objphar;
phar = (phar_archive_data *) emalloc(sizeof(phar_archive_data));
*phar = **pphar;
@@ -2040,66 +1999,60 @@ static void phar_copy_cached_phar(phar_archive_data **pphar TSRMLS_DC) /* {{{ */
phar->signature = estrdup(phar->signature);
}
- if (phar->metadata) {
+ if (Z_TYPE(phar->metadata) != IS_UNDEF) {
/* assume success, we would have failed before */
if (phar->metadata_len) {
- char *buf = estrndup((char *) phar->metadata, phar->metadata_len);
- phar_parse_metadata(&buf, &phar->metadata, phar->metadata_len TSRMLS_CC);
+ char *buf = estrndup((char *) Z_PTR(phar->metadata), phar->metadata_len);
+ phar_parse_metadata(&buf, &phar->metadata, phar->metadata_len);
efree(buf);
} else {
- zval *t;
-
- t = phar->metadata;
- ALLOC_ZVAL(phar->metadata);
- *phar->metadata = *t;
- zval_copy_ctor(phar->metadata);
- Z_SET_REFCOUNT_P(phar->metadata, 1);
+ zval_copy_ctor(&phar->metadata);
}
}
zend_hash_init(&newmanifest, sizeof(phar_entry_info),
zend_get_hash_value, destroy_phar_manifest_entry, 0);
- zend_hash_copy(&newmanifest, &(*pphar)->manifest, NULL, NULL, sizeof(phar_entry_info));
- zend_hash_apply_with_argument(&newmanifest, (apply_func_arg_t) phar_update_cached_entry, (void *)phar TSRMLS_CC);
+ zend_hash_copy(&newmanifest, &(*pphar)->manifest, phar_manifest_copy_ctor);
+ zend_hash_apply_with_argument(&newmanifest, phar_update_cached_entry, (void *)phar);
phar->manifest = newmanifest;
zend_hash_init(&phar->mounted_dirs, sizeof(char *),
zend_get_hash_value, NULL, 0);
zend_hash_init(&phar->virtual_dirs, sizeof(char *),
zend_get_hash_value, NULL, 0);
- zend_hash_copy(&phar->virtual_dirs, &(*pphar)->virtual_dirs, NULL, NULL, sizeof(void *));
+ zend_hash_copy(&phar->virtual_dirs, &(*pphar)->virtual_dirs, NULL);
*pphar = phar;
/* now, scan the list of persistent Phar objects referencing this phar and update the pointers */
- for (zend_hash_internal_pointer_reset(&PHAR_GLOBALS->phar_persist_map);
- SUCCESS == zend_hash_get_current_data(&PHAR_GLOBALS->phar_persist_map, (void **) &objphar);
- zend_hash_move_forward(&PHAR_GLOBALS->phar_persist_map)) {
- if (objphar[0]->arc.archive->fname_len == phar->fname_len && !memcmp(objphar[0]->arc.archive->fname, phar->fname, phar->fname_len)) {
- objphar[0]->arc.archive = phar;
+ ZEND_HASH_FOREACH_PTR(&PHAR_G(phar_persist_map), objphar) {
+ if (objphar->archive->fname_len == phar->fname_len && !memcmp(objphar->archive->fname, phar->fname, phar->fname_len)) {
+ objphar->archive = phar;
}
- }
+ } ZEND_HASH_FOREACH_END();
}
/* }}} */
-int phar_copy_on_write(phar_archive_data **pphar TSRMLS_DC) /* {{{ */
+int phar_copy_on_write(phar_archive_data **pphar) /* {{{ */
{
- phar_archive_data **newpphar, *newphar = NULL;
+ zval zv, *pzv;
+ phar_archive_data *newpphar;
- if (SUCCESS != zend_hash_add(&(PHAR_GLOBALS->phar_fname_map), (*pphar)->fname, (*pphar)->fname_len, (void *)&newphar, sizeof(phar_archive_data *), (void **)&newpphar)) {
+ ZVAL_PTR(&zv, *pphar);
+ if (NULL == (pzv = zend_hash_str_add(&(PHAR_G(phar_fname_map)), (*pphar)->fname, (*pphar)->fname_len, &zv))) {
return FAILURE;
}
- *newpphar = *pphar;
- phar_copy_cached_phar(newpphar TSRMLS_CC);
+ phar_copy_cached_phar((phar_archive_data **)&Z_PTR_P(pzv));
+ newpphar = Z_PTR_P(pzv);
/* invalidate phar cache */
PHAR_G(last_phar) = NULL;
PHAR_G(last_phar_name) = PHAR_G(last_alias) = NULL;
- if (newpphar[0]->alias_len && FAILURE == zend_hash_add(&(PHAR_GLOBALS->phar_alias_map), newpphar[0]->alias, newpphar[0]->alias_len, (void*)newpphar, sizeof(phar_archive_data*), NULL)) {
- zend_hash_del(&(PHAR_GLOBALS->phar_fname_map), (*pphar)->fname, (*pphar)->fname_len);
+ if (newpphar->alias_len && NULL == zend_hash_str_add_ptr(&(PHAR_G(phar_alias_map)), newpphar->alias, newpphar->alias_len, newpphar)) {
+ zend_hash_str_del(&(PHAR_G(phar_fname_map)), (*pphar)->fname, (*pphar)->fname_len);
return FAILURE;
}
- *pphar = *newpphar;
+ *pphar = newpphar;
return SUCCESS;
}
/* }}} */