- Don't expect any tests to pass.
{
size_t to_read;
HashTable *data = (HashTable *)stream->abstract;
- char *key;
+ zstr key;
uint keylen;
ulong unused;
return 0;
}
memset(buf, 0, sizeof(php_stream_dirent));
- memcpy(((php_stream_dirent *) buf)->d_name, key, to_read);
+ memcpy(((php_stream_dirent *) buf)->d_name, key.s, to_read);
((php_stream_dirent *) buf)->d_name[to_read + 1] = '\0';
return sizeof(php_stream_dirent);
{
HashTable *data;
int dirlen = strlen(dir);
- char *save, *found, *key;
+ zstr key;
+ char *entry, *found, *save;
uint keylen;
ulong unused;
- char *entry;
+
ALLOC_HASHTABLE(data);
zend_hash_init(data, 64, zend_get_hash_value, NULL, 0);
break;
}
if (keylen <= (uint)dirlen) {
- if (keylen < (uint)dirlen || !strncmp(key, dir, dirlen)) {
+ if (keylen < (uint)dirlen || !strncmp(key.s, dir, dirlen)) {
if (SUCCESS != zend_hash_move_forward(manifest)) {
break;
}
}
if (*dir == '/') {
/* root directory */
- if (NULL != (found = (char *) memchr(key, '/', keylen))) {
+ if (NULL != (found = (char *) memchr(key.s, '/', keylen))) {
/* the entry has a path separator and is a subdirectory */
- entry = (char *) safe_emalloc(found - key, 1, 1);
- memcpy(entry, key, found - key);
- keylen = found - key;
+ entry = (char *) safe_emalloc(found - key.s, 1, 1);
+ memcpy(entry, key.s, found - key.s);
+ keylen = found - key.s;
entry[keylen] = '\0';
} else {
entry = (char *) safe_emalloc(keylen, 1, 1);
- memcpy(entry, key, keylen);
+ memcpy(entry, key.s, keylen);
entry[keylen] = '\0';
}
goto PHAR_ADD_ENTRY;
} else {
- if (0 != memcmp(key, dir, dirlen)) {
+ if (0 != memcmp(key.s, dir, dirlen)) {
/* entry in directory not found */
if (SUCCESS != zend_hash_move_forward(manifest)) {
break;
}
continue;
} else {
- if (key[dirlen] != '/') {
+ if (key.s[dirlen] != '/') {
if (SUCCESS != zend_hash_move_forward(manifest)) {
break;
}
}
}
}
- save = key;
+ save = key.s;
save += dirlen + 1; /* seek to just past the path separator */
if (NULL != (found = (char *) memchr(save, '/', keylen - dirlen - 1))) {
/* is subdirectory */
{
php_url *resource = NULL;
php_stream *ret;
- char *internal_file, *key, *error;
+ char *internal_file, *error;
+ zstr key;
uint keylen;
ulong unused;
phar_archive_data *phar;
if (HASH_KEY_NON_EXISTANT !=
zend_hash_get_current_key_ex(
&phar->manifest, &key, &keylen, &unused, 0, NULL)) {
- if (keylen > (uint)i_len && 0 == memcmp(key, internal_file, i_len)) {
+ if (keylen > (uint)i_len && 0 == memcmp(key.s, internal_file, i_len)) {
/* directory found */
internal_file = estrndup(internal_file,
i_len);
goto stat_entry;
} else {
phar_archive_data *phar = *pphar;
- char *key;
+ zstr key;
uint keylen;
ulong unused;
if (HASH_KEY_NON_EXISTANT !=
zend_hash_get_current_key_ex(
&phar->manifest, &key, &keylen, &unused, 0, NULL)) {
- if (!memcmp(actual, key, actual_len)) {
+ if (!memcmp(actual, key.s, actual_len)) {
efree(save2);
efree(entry);
/* directory found, all dirs have the same stat */
- if (key[actual_len] == '/') {
+ if (key.s[actual_len] == '/') {
sb.st_size = 0;
sb.st_mode = 0777;
sb.st_mode |= S_IFDIR; /* regular directory */
return FAILURE;
}
} else {
- char *key;
+ zstr key;
uint keylen;
ulong unused;
zend_hash_move_forward(&(PHAR_GLOBALS->phar_fname_map));
continue;
}
- if (!memcmp(filename, key, keylen) && (filename_len == keylen
+ if (!memcmp(filename, key.s, keylen) && (filename_len == keylen
|| filename[keylen] == '/' || filename[keylen] == '\0')) {
if (FAILURE == zend_hash_get_current_data(&(PHAR_GLOBALS->phar_fname_map), (void **) &pphar)) {
break;
}
} else if (phar->flags & PHAR_FILE_COMPRESSION_MASK) {
/* compressed phar */
-#if PHP_VERSION_ID >= 50300 && PHP_VERSION_ID < 60000
+#if PHP_VERSION_ID >= 50300
file_handle->type = ZEND_HANDLE_STREAM;
file_handle->free_filename = 0;
file_handle->handle.stream.handle = phar;
mime.len = Z_STRLEN_PP(val); \
} \
mime.type = ret; \
- zend_hash_update(&mimetypes, key, keylen-1, (void *)&mime, sizeof(phar_mime_type), NULL);
+ zend_hash_update(&mimetypes, key.s, keylen-1, (void *)&mime, sizeof(phar_mime_type), NULL);
if (mimeoverride) {
if (!zend_hash_num_elements(Z_ARRVAL_P(mimeoverride))) {
}
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(mimeoverride)); SUCCESS == zend_hash_has_more_elements(Z_ARRVAL_P(mimeoverride)); zend_hash_move_forward(Z_ARRVAL_P(mimeoverride))) {
zval **val;
- char *key;
+ zstr key;
uint keylen;
ulong intkey;
if (HASH_KEY_IS_LONG == zend_hash_get_current_key_ex(Z_ARRVAL_P(mimeoverride), &key, &keylen, &intkey, 0, NULL)) {
RETURN_FALSE;
}
if (FAILURE == zend_hash_get_current_data(Z_ARRVAL_P(mimeoverride), (void **) &val)) {
- zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Failed to retrieve Mime type for extension \"%s\"", key);
+ zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Failed to retrieve Mime type for extension \"%s\"", key.s);
phar_entry_delref(phar TSRMLS_CC);
#ifdef PHP_WIN32
efree(fname);
phar_entry_data *data;
php_stream *fp;
long contents_len;
- char *fname, *error, *str_key, *base = p_obj->b, *opened, *save = NULL, *temp = NULL;
+ char *fname, *error, *base = p_obj->b, *opened, *save = NULL, *temp = NULL;
+ zstr str_key;
zend_class_entry *ce = p_obj->c;
phar_archive_object *phar_obj = p_obj->p;
char *str = "[stream]";
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %s returned an invalid key (must return a string)", ce->name);
return ZEND_HASH_APPLY_STOP;
}
- save = str_key;
- if (str_key[str_key_len - 1] == '\0') str_key_len--;
+ save = str_key.s;
+ if (str_key.s[str_key_len - 1] == '\0') str_key_len--;
} else {
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %s returned an invalid key (must return a string)", ce->name);
return ZEND_HASH_APPLY_STOP;
goto phar_spl_fileinfo;
case SPL_FS_INFO:
case SPL_FS_FILE:
- fname = expand_filepath(intern->file_name, NULL TSRMLS_CC);
+ fname = expand_filepath(intern->file_name.s, NULL TSRMLS_CC);
fname_len = strlen(fname);
save = fname;
is_splfileinfo = 1;
}
return ZEND_HASH_APPLY_KEEP;
}
- str_key = fname + base_len;
- if (*str_key == '/' || *str_key == '\\') {
- str_key++;
+ str_key.s = fname + base_len;
+ if (*str_key.s == '/' || *str_key.s == '\\') {
+ str_key.s++;
str_key_len--;
}
} else {
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %s returned an invalid key (must return a string)", ce->name);
return ZEND_HASH_APPLY_STOP;
}
- save = str_key;
- if (str_key[str_key_len - 1] == '\0') str_key_len--;
+ save = str_key.s;
+ if (str_key.s[str_key_len - 1] == '\0') str_key_len--;
} else {
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %s returned an invalid key (must return a string)", ce->name);
return ZEND_HASH_APPLY_STOP;
}
after_open_fp:
- if (!(data = phar_get_or_create_entry_data(phar_obj->arc.archive->fname, phar_obj->arc.archive->fname_len, str_key, str_key_len, "w+b", 0, &error TSRMLS_CC))) {
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Entry %s cannot be created: %s", str_key, error);
+ if (!(data = phar_get_or_create_entry_data(phar_obj->arc.archive->fname, phar_obj->arc.archive->fname_len, str_key.s, str_key_len, "w+b", 0, &error TSRMLS_CC))) {
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Entry %s cannot be created: %s", str_key.s, error);
efree(error);
if (save) {
efree(save);
php_stream_close(fp);
}
- add_assoc_string(p_obj->ret, str_key, opened, 0);
+ add_assoc_string(p_obj->ret, str_key.s, opened, 0);
if (save) {
efree(save);
php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) /* {{{ */
{
php_url *resource = NULL;
- char *internal_file, *key, *error;
+ zstr key;
+ char *internal_file, *error;
uint keylen;
ulong unused;
phar_archive_data *phar;
if (HASH_KEY_NON_EXISTANT !=
zend_hash_get_current_key_ex(
&phar->manifest, &key, &keylen, &unused, 0, NULL)) {
- if (keylen >= (uint)internal_file_len && 0 == memcmp(internal_file, key, internal_file_len)) {
+ if (keylen >= (uint)internal_file_len && 0 == memcmp(internal_file, key.s, internal_file_len)) {
/* directory found, all dirs have the same stat */
- if (key[internal_file_len] == '/') {
+ if (key.s[internal_file_len] == '/') {
phar_dostat(phar, NULL, ssb, 1, phar->alias, phar->alias_len TSRMLS_CC);
php_url_free(resource);
return SUCCESS;
}
/* check for mounted directories */
if (phar->mounted_dirs.arBuckets && zend_hash_num_elements(&phar->mounted_dirs)) {
- char *key;
+ zstr key;
ulong unused;
uint keylen;
if (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key_ex(&phar->mounted_dirs, &key, &keylen, &unused, 0, NULL)) {
break;
}
- if ((int)keylen >= internal_file_len || strncmp(key, internal_file, keylen)) {
+ if ((int)keylen >= internal_file_len || strncmp(key.s, internal_file, keylen)) {
continue;
} else {
char *test;
phar_entry_info *entry;
php_stream_statbuf ssbi;
- if (SUCCESS != zend_hash_find(&phar->manifest, key, keylen, (void **) &entry)) {
+ if (SUCCESS != zend_hash_find(&phar->manifest, key.s, keylen, (void **) &entry)) {
goto free_resource;
}
if (!entry->tmp || !entry->is_mounted) {
if (empty($comp)) $comp = $cont;
if (empty($ulen)) $ulen = strlen($cont);
if (empty($clen)) $clen = strlen($comp);
- if (empty($crc32))$crc32= crc32($cont);
+ if (empty($crc32))$crc32= crc32((binary)$cont);
if (isset($meta)) $meta = serialize($meta);
// write manifest entry
}
return entry;
} else if (phar->mounted_dirs.arBuckets && zend_hash_num_elements(&phar->mounted_dirs)) {
- char *key;
+ zstr key;
ulong unused;
uint keylen;
if (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key_ex(&phar->mounted_dirs, &key, &keylen, &unused, 0, NULL)) {
break;
}
- if ((int)keylen >= path_len || strncmp(key, path, keylen)) {
+ if ((int)keylen >= path_len || strncmp(key.s, path, keylen)) {
continue;
} else {
char *test;
phar_entry_info *entry;
php_stream_statbuf ssb;
- if (SUCCESS != zend_hash_find(&phar->manifest, key, keylen, (void **) &entry)) {
+ if (SUCCESS != zend_hash_find(&phar->manifest, key.s, keylen, (void **) &entry)) {
if (error) {
- spprintf(error, 4096, "phar internal error: mounted path \"%s\" could not be retrieved from manifest", key);
+ spprintf(error, 4096, "phar internal error: mounted path \"%s\" could not be retrieved from manifest", key.s);
}
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", key);
+ spprintf(error, 4096, "phar internal error: mounted path \"%s\" is not properly initialized as a mounted path", key.s);
}
return NULL;
}
if (dir) {
/* try to find a directory */
HashTable *manifest;
- char *key;
+ zstr key;
uint keylen;
ulong unused;
if (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
break;
}
- if (0 != memcmp(key, path, path_len)) {
+ if (0 != memcmp(key.s, path, path_len)) {
/* entry in directory not found */
if (SUCCESS != zend_hash_move_forward(manifest)) {
break;
}
continue;
} else {
- if (key[path_len] != '/') {
+ if (key.s[path_len] != '/') {
if (SUCCESS != zend_hash_move_forward(manifest)) {
break;
}