20#define PHAR_DIRSTREAM 1
41static int phar_dir_close(
php_stream *stream,
int close_handle)
48 stream->abstract =
NULL;
72 zend_hash_internal_pointer_reset(
data);
104 zend_hash_move_forward(
data);
143static int phar_add_empty(
HashTable *
ht,
char *arKey, uint32_t nKeyLength)
173 char *entry, *found, *save;
181 if ((*
dir ==
'/' && dirlen == 1 && (manifest->
nNumOfElements == 0)) || (dirlen >=
sizeof(
".phar")-1 && !memcmp(
dir,
".phar",
sizeof(
".phar")-1))) {
188 zend_hash_internal_pointer_reset(manifest);
190 while (
FAILURE != zend_hash_has_more_elements(manifest)) {
196 if (keylen <= dirlen) {
198 if (
SUCCESS != zend_hash_move_forward(manifest)) {
207 if (keylen >=
sizeof(
".phar")-1 && !memcmp(
ZSTR_VAL(str_key),
".phar",
sizeof(
".phar")-1)) {
209 if (
SUCCESS != zend_hash_move_forward(manifest)) {
215 if (
NULL != (found = (
char *) memchr(
ZSTR_VAL(str_key),
'/', keylen))) {
220 entry[keylen] =
'\0';
224 entry[keylen] =
'\0';
231 if (
SUCCESS != zend_hash_move_forward(manifest)) {
236 if (
ZSTR_VAL(str_key)[dirlen] !=
'/') {
237 if (
SUCCESS != zend_hash_move_forward(manifest)) {
248 if (
NULL != (found = (
char *) memchr(save,
'/', keylen - dirlen - 1))) {
251 entry = (
char *)
safe_emalloc(found - save + dirlen, 1, 1);
252 memcpy(entry, save + dirlen + 1, found - save - dirlen - 1);
253 keylen = found - save - dirlen - 1;
254 entry[keylen] =
'\0';
259 memcpy(entry, save + dirlen + 1, keylen - dirlen - 1);
260 entry[keylen - dirlen - 1] =
'\0';
261 keylen = keylen - dirlen - 1;
265 phar_add_empty(
data, entry, keylen);
270 if (
SUCCESS != zend_hash_move_forward(manifest)) {
275 if (
FAILURE != zend_hash_has_more_elements(
data)) {
277 zend_hash_sort(
data, phar_compare_dir_name, 0);
293 char *internal_file, *
error;
306 if (resource->
host && !resource->
path) {
341 if (*internal_file ==
'\0') {
343 internal_file =
estrndup(internal_file - 1, 1);
344 ret = phar_make_dirstream(internal_file, &phar->
manifest);
354 if (
NULL != (entry = zend_hash_str_find_ptr(&phar->
manifest, internal_file,
strlen(internal_file))) && !entry->
is_dir) {
357 }
else if (entry && entry->
is_dir) {
362 internal_file =
estrdup(internal_file);
364 return phar_make_dirstream(internal_file, &phar->
manifest);
366 size_t i_len =
strlen(internal_file);
369 zend_hash_internal_pointer_reset(&phar->
manifest);
372 zend_hash_get_current_key(&phar->
manifest, &str_key, &unused)) {
373 if (
ZSTR_LEN(str_key) > i_len && 0 == memcmp(
ZSTR_VAL(str_key), internal_file, i_len)) {
375 internal_file =
estrndup(internal_file,
378 return phar_make_dirstream(internal_file, &phar->
manifest);
400 char *
error, *arch, *entry2;
401 size_t arch_len, entry_len;
531 char *
error, *arch, *entry2;
532 size_t arch_len, entry_len;
595 for (zend_hash_internal_pointer_reset(&phar->
manifest);
597 zend_hash_move_forward(&phar->
manifest)
612 for (zend_hash_internal_pointer_reset(&phar->
virtual_dirs);
dir(string $directory, $context=null)
count(Countable|array $value, int $mode=COUNT_NORMAL)
int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context)
int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mode, int options, php_stream_context *context)
php_stream * phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC)
void phar_dostat(phar_archive_data *phar, phar_entry_info *data, php_stream_statbuf *ssb, bool is_dir)
memset(ptr, 0, type->size)
zend_ffi_ctype_name_buf buf
void phar_flush(phar_archive_data *phar, char **error)
zend_result phar_split_fname(const char *filename, size_t filename_len, char **arch, size_t *arch_len, char **entry, size_t *entry_len, int executable, int for_create)
void phar_request_initialize(void)
void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, size_t filename_len)
#define PHAR_ENT_PERM_DEF_DIR
phar_entry_info * phar_get_entry_info_dir(phar_archive_data *phar, char *path, size_t path_len, char dir, char **error, int security)
struct _phar_archive_data phar_archive_data
struct _phar_entry_info phar_entry_info
zend_result phar_get_archive(phar_archive_data **archive, char *fname, size_t fname_len, char *alias, size_t alias_len, char **error)
#define PHP_STRLCPY(dst, src, size, src_size)
PHP_JSON_API size_t int options
struct _php_stream php_stream
struct _php_stream_context php_stream_context
struct _php_stream_dirent php_stream_dirent
#define php_stream_opendir(path, options, context)
struct _php_stream_ops php_stream_ops
struct _php_stream_wrapper php_stream_wrapper
#define php_stream_alloc(ops, thisptr, persistent_id, mode)
struct _php_stream_statbuf php_stream_statbuf
PHPAPI void php_stream_wrapper_log_error(const php_stream_wrapper *wrapper, int options, const char *fmt,...) PHP_ATTRIBUTE_FORMAT(printf
php_url * phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options)
PHPAPI void php_url_free(php_url *theurl)
#define estrndup(s, length)
#define FREE_HASHTABLE(ht)
#define safe_emalloc(nmemb, size, offset)
#define ALLOC_HASHTABLE(ht)
strncmp(string $string1, string $string2, int $length)
ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht)
ZEND_API zval *ZEND_FASTCALL zend_hash_str_update(HashTable *ht, const char *str, size_t len, zval *pData)
ZEND_API zend_result ZEND_FASTCALL zend_hash_str_del(HashTable *ht, const char *str, size_t len)
#define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent)
#define HASH_KEY_NON_EXISTENT
#define HT_IS_INITIALIZED(ht)
struct _zend_string zend_string
ZEND_API int ZEND_FASTCALL zend_binary_strcmp(const char *s1, size_t len1, const char *s2, size_t len2)
#define ZEND_NORMALIZE_BOOL(n)
#define zend_string_equals_literal_ci(str, c)
struct _zend_array HashTable