diff options
author | Xinchen Hui <laruence@php.net> | 2013-11-05 18:47:12 +0800 |
---|---|---|
committer | Xinchen Hui <laruence@php.net> | 2013-11-05 18:47:12 +0800 |
commit | 63dba7ec9d7ce1ec5e2d48742c71ce66db973b93 (patch) | |
tree | 3f2ad6160551e39c221a6dadf0794623f74b73dd | |
parent | 906d3ae0edb1c371f4ad73585ef25337f8e0ef97 (diff) | |
download | php-git-63dba7ec9d7ce1ec5e2d48742c71ce66db973b93.tar.gz |
Remove outdate codes, make it clearer, although just a bit..
-rw-r--r-- | ext/phar/phar.c | 94 | ||||
-rw-r--r-- | ext/phar/phar_internal.h | 59 | ||||
-rw-r--r-- | ext/phar/phar_object.c | 78 | ||||
-rw-r--r-- | ext/phar/stream.c | 12 | ||||
-rw-r--r-- | ext/phar/util.c | 299 | ||||
-rw-r--r-- | ext/phar/zip.c | 10 |
6 files changed, 6 insertions, 546 deletions
diff --git a/ext/phar/phar.c b/ext/phar/phar.c index ec8e5fbde7..13b3d6428e 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -27,9 +27,7 @@ static void destroy_phar_data(void *pDest); ZEND_DECLARE_MODULE_GLOBALS(phar) -#if PHP_VERSION_ID >= 50300 char *(*phar_save_resolve_path)(const char *filename, int filename_len TSRMLS_DC); -#endif /** * set's phar->is_writeable based on the current INI value @@ -3321,31 +3319,18 @@ static size_t phar_zend_stream_reader(void *handle, char *buf, size_t len TSRMLS } /* }}} */ -#if PHP_VERSION_ID >= 50300 static size_t phar_zend_stream_fsizer(void *handle TSRMLS_DC) /* {{{ */ { return ((phar_archive_data*)handle)->halt_offset + 32; } /* }}} */ -#else /* PHP_VERSION_ID */ - -static long phar_stream_fteller_for_zend(void *handle TSRMLS_DC) /* {{{ */ -{ - return (long)php_stream_tell(phar_get_pharfp((phar_archive_data*)handle TSRMLS_CC)); -} -/* }}} */ -#endif - zend_op_array *(*phar_orig_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC); -#if PHP_VERSION_ID >= 50300 #define phar_orig_zend_open zend_stream_open_function + static char *phar_resolve_path(const char *filename, int filename_len TSRMLS_DC) { return phar_find_in_include_path((char *) filename, filename_len, NULL TSRMLS_CC); } -#else -int (*phar_orig_zend_open)(const char *filename, zend_file_handle *handle TSRMLS_DC); -#endif static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC) /* {{{ */ { @@ -3378,7 +3363,6 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type } } else if (phar->flags & PHAR_FILE_COMPRESSION_MASK) { /* compressed phar */ -#if PHP_VERSION_ID >= 50300 file_handle->type = ZEND_HANDLE_STREAM; /* we do our own reading directly from the phar, don't change the next line */ file_handle->handle.stream.handle = phar; @@ -3390,18 +3374,6 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type php_stream_rewind(PHAR_GLOBALS->cached_fp[phar->phar_pos].fp) : php_stream_rewind(phar->fp); memset(&file_handle->handle.stream.mmap, 0, sizeof(file_handle->handle.stream.mmap)); -#else /* PHP_VERSION_ID */ - file_handle->type = ZEND_HANDLE_STREAM; - /* we do our own reading directly from the phar, don't change the next line */ - file_handle->handle.stream.handle = phar; - file_handle->handle.stream.reader = phar_zend_stream_reader; - file_handle->handle.stream.closer = NULL; /* don't close - let phar handle this one */ - file_handle->handle.stream.fteller = phar_stream_fteller_for_zend; - file_handle->handle.stream.interactive = 0; - phar->is_persistent ? - php_stream_rewind(PHAR_GLOBALS->cached_fp[phar->phar_pos].fp) : - php_stream_rewind(phar->fp); -#endif } } } @@ -3426,60 +3398,6 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type } /* }}} */ -#if PHP_VERSION_ID < 50300 -int phar_zend_open(const char *filename, zend_file_handle *handle TSRMLS_DC) /* {{{ */ -{ - char *arch, *entry; - int arch_len, entry_len; - - /* this code is obsoleted in php 5.3 */ - entry = (char *) filename; - if (!IS_ABSOLUTE_PATH(entry, strlen(entry)) && !strstr(entry, "://")) { - phar_archive_data **pphar = NULL; - char *fname; - int fname_len; - - fname = (char*)zend_get_executed_filename(TSRMLS_C); - fname_len = strlen(fname); - - if (fname_len > 7 && !strncasecmp(fname, "phar://", 7)) { - if (SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len, 1, 0 TSRMLS_CC)) { - zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len, (void **) &pphar); - if (!pphar && PHAR_G(manifest_cached)) { - zend_hash_find(&cached_phars, arch, arch_len, (void **) &pphar); - } - efree(arch); - efree(entry); - } - } - - /* retrieving an include within the current directory, so use this if possible */ - if (!(entry = phar_find_in_include_path((char *) filename, strlen(filename), NULL TSRMLS_CC))) { - /* this file is not in the phar, use the original path */ - goto skip_phar; - } - - if (SUCCESS == phar_orig_zend_open(entry, handle TSRMLS_CC)) { - if (!handle->opened_path) { - handle->opened_path = entry; - } - if (entry != filename) { - handle->free_filename = 1; - } - return SUCCESS; - } - - if (entry != filename) { - efree(entry); - } - - return FAILURE; - } -skip_phar: - return phar_orig_zend_open(filename, handle TSRMLS_CC); -} -/* }}} */ -#endif typedef zend_op_array* (zend_compile_t)(zend_file_handle*, int TSRMLS_DC); typedef zend_compile_t* (compile_hook)(zend_compile_t *ptr); @@ -3556,13 +3474,8 @@ PHP_MINIT_FUNCTION(phar) /* {{{ */ phar_orig_compile_file = zend_compile_file; zend_compile_file = phar_compile_file; -#if PHP_VERSION_ID >= 50300 phar_save_resolve_path = zend_resolve_path; zend_resolve_path = phar_resolve_path; -#else - phar_orig_zend_open = zend_stream_open_function; - zend_stream_open_function = phar_zend_open; -#endif phar_object_init(TSRMLS_C); @@ -3583,11 +3496,6 @@ PHP_MSHUTDOWN_FUNCTION(phar) /* {{{ */ zend_compile_file = phar_orig_compile_file; } -#if PHP_VERSION_ID < 50300 - if (zend_stream_open_function == phar_zend_open) { - zend_stream_open_function = phar_orig_zend_open; - } -#endif if (PHAR_G(manifest_cached)) { zend_hash_destroy(&(cached_phars)); zend_hash_destroy(&(cached_alias)); diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h index daa85f1b70..fcfb647184 100644 --- a/ext/phar/phar_internal.h +++ b/ext/phar/phar_internal.h @@ -516,76 +516,17 @@ union _phar_entry_object { #endif #ifndef PHAR_MAIN -# if PHP_VERSION_ID >= 50300 extern char *(*phar_save_resolve_path)(const char *filename, int filename_len TSRMLS_DC); -# endif #endif -#if PHP_VERSION_ID < 50209 -static inline size_t phar_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen, size_t *len STREAMS_DC TSRMLS_DC) -{ - size_t ret = php_stream_copy_to_stream(src, dest, maxlen); - if (len) { - *len = ret; - } - if (ret) { - return SUCCESS; - } - return FAILURE; -} -#else # define phar_stream_copy_to_stream(src, dest, maxlen, len) _php_stream_copy_to_stream_ex((src), (dest), (maxlen), (len) STREAMS_CC TSRMLS_CC) -#endif - -#if PHP_VERSION_ID >= 60000 -typedef zstr phar_zstr; -#define PHAR_STR(a, b) \ - spprintf(&b, 0, "%s", a.s); -#define PHAR_ZSTR(a, b) \ - b = ZSTR(a); -#define PHAR_STR_FREE(a) \ - efree(a); -static inline int phar_make_unicode(zstr *c_var, char *arKey, uint nKeyLength TSRMLS_DC) -{ - int c_var_len; - UConverter *conv = ZEND_U_CONVERTER(UG(runtime_encoding_conv)); - - c_var->u = NULL; - if (zend_string_to_unicode(conv, &c_var->u, &c_var_len, arKey, nKeyLength TSRMLS_CC) == FAILURE) { - - if (c_var->u) { - efree(c_var->u); - } - return 0; - - } - return c_var_len; -} -static inline int phar_find_key(HashTable *_SERVER, char *key, int len, void **stuff TSRMLS_DC) -{ - if (SUCCESS == zend_hash_find(_SERVER, key, len, stuff)) { - return 1; - } else { - int s = len; - zstr var; - s = phar_make_unicode(&var, key, len TSRMLS_CC); - if (SUCCESS == zend_u_hash_find(_SERVER, IS_UNICODE, var, s, stuff)) { - efree(var.u); - return 1; - } - efree(var.u); - return 0; - } -} -#else typedef char *phar_zstr; #define PHAR_STR(a, b) \ b = a; #define PHAR_ZSTR(a, b) \ b = a; #define PHAR_STR_FREE(a) -#endif BEGIN_EXTERN_C() diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index dcb67fe9fa..7d2922fbaa 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -685,11 +685,7 @@ PHP_METHOD(Phar, webPhar) ZVAL_STRINGL(params, entry, entry_len, 1); zp[0] = ¶ms; -#if PHP_VERSION_ID < 50300 - if (FAILURE == zend_fcall_info_init(rewrite, &fci, &fcc TSRMLS_CC)) { -#else if (FAILURE == zend_fcall_info_init(rewrite, 0, &fci, &fcc, NULL, NULL TSRMLS_CC)) { -#endif zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "phar error: invalid rewrite callback"); if (free_pathinfo) { @@ -701,11 +697,7 @@ PHP_METHOD(Phar, webPhar) fci.param_count = 1; fci.params = zp; -#if PHP_VERSION_ID < 50300 - ++(params->refcount); -#else Z_ADDREF_P(params); -#endif fci.retval_ptr_ptr = &retval_ptr; if (FAILURE == zend_call_function(&fci, &fcc TSRMLS_CC)) { @@ -729,11 +721,6 @@ PHP_METHOD(Phar, webPhar) } switch (Z_TYPE_P(retval_ptr)) { -#if PHP_VERSION_ID >= 60000 - case IS_UNICODE: - zval_unicode_to_string(retval_ptr TSRMLS_CC); - /* break intentionally omitted */ -#endif case IS_STRING: efree(entry); @@ -1155,11 +1142,7 @@ PHP_METHOD(Phar, __construct) #else char *fname, *alias = NULL, *error, *arch = NULL, *entry = NULL, *save_fname; int fname_len, alias_len = 0, arch_len, entry_len, is_data; -#if PHP_VERSION_ID < 50300 - long flags = 0; -#else long flags = SPL_FILE_DIR_SKIPDOTS|SPL_FILE_DIR_UNIXPATHS; -#endif long format = 0; phar_archive_object *phar_obj; phar_archive_data *phar_data; @@ -1459,11 +1442,6 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ } switch (Z_TYPE_PP(value)) { -#if PHP_VERSION_ID >= 60000 - case IS_UNICODE: - zval_unicode_to_string(*(value) TSRMLS_CC); - /* break intentionally omitted */ -#endif case IS_STRING: break; case IS_RESOURCE: @@ -1514,13 +1492,7 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ switch (intern->type) { case SPL_FS_DIR: -#if PHP_VERSION_ID >= 60000 - test = spl_filesystem_object_get_path(intern, NULL, NULL TSRMLS_CC).s; -#elif PHP_VERSION_ID >= 50300 test = spl_filesystem_object_get_path(intern, NULL TSRMLS_CC); -#else - test = intern->path; -#endif fname_len = spprintf(&fname, 0, "%s%c%s", test, DEFAULT_SLASH, intern->u.dir.entry.d_name); php_stat(fname, fname_len, FS_IS_DIR, &dummy TSRMLS_CC); @@ -1545,25 +1517,7 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ goto phar_spl_fileinfo; case SPL_FS_INFO: case SPL_FS_FILE: -#if PHP_VERSION_ID >= 60000 - if (intern->file_name_type == IS_UNICODE) { - zval zv; - - INIT_ZVAL(zv); - Z_UNIVAL(zv) = intern->file_name; - Z_UNILEN(zv) = intern->file_name_len; - Z_TYPE(zv) = IS_UNICODE; - - zval_copy_ctor(&zv); - zval_unicode_to_string(&zv TSRMLS_CC); - fname = expand_filepath(Z_STRVAL(zv), NULL TSRMLS_CC); - ezfree(Z_UNIVAL(zv)); - } else { - fname = expand_filepath(intern->file_name.s, NULL TSRMLS_CC); - } -#else fname = expand_filepath(intern->file_name, NULL TSRMLS_CC); -#endif if (!fname) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Could not resolve file path"); return ZEND_HASH_APPLY_STOP; @@ -1816,11 +1770,7 @@ PHP_METHOD(Phar, buildFromDirectory) INIT_PZVAL(&arg); ZVAL_STRINGL(&arg, dir, dir_len, 0); INIT_PZVAL(&arg2); -#if PHP_VERSION_ID < 50300 - ZVAL_LONG(&arg2, 0); -#else ZVAL_LONG(&arg2, SPL_FILE_DIR_SKIPDOTS|SPL_FILE_DIR_UNIXPATHS); -#endif zend_call_method_with_2_params(&iter, spl_ce_RecursiveDirectoryIterator, &spl_ce_RecursiveDirectoryIterator->constructor, "__construct", NULL, &arg, &arg2); @@ -2313,11 +2263,7 @@ static zval *phar_convert_to_other(phar_archive_data *source, int convert, char ALLOC_ZVAL(phar->metadata); *phar->metadata = *t; zval_copy_ctor(phar->metadata); -#if PHP_VERSION_ID < 50300 - phar->metadata->refcount = 1; -#else Z_SET_REFCOUNT_P(phar->metadata, 1); -#endif phar->metadata_len = 0; } @@ -2365,11 +2311,7 @@ no_copy: ALLOC_ZVAL(newentry.metadata); *newentry.metadata = *t; zval_copy_ctor(newentry.metadata); -#if PHP_VERSION_ID < 50300 - newentry.metadata->refcount = 1; -#else Z_SET_REFCOUNT_P(newentry.metadata, 1); -#endif newentry.metadata_str.c = NULL; newentry.metadata_str.len = 0; @@ -3552,11 +3494,7 @@ PHP_METHOD(Phar, copy) ALLOC_ZVAL(newentry.metadata); *newentry.metadata = *t; zval_copy_ctor(newentry.metadata); -#if PHP_VERSION_ID < 50300 - newentry.metadata->refcount = 1; -#else Z_SET_REFCOUNT_P(newentry.metadata, 1); -#endif newentry.metadata_str.c = NULL; newentry.metadata_str.len = 0; @@ -4371,11 +4309,6 @@ PHP_METHOD(Phar, extractTo) switch (Z_TYPE_P(zval_files)) { case IS_NULL: goto all_files; -#if PHP_VERSION_ID >= 60000 - case IS_UNICODE: - zval_unicode_to_string(zval_files TSRMLS_CC); - /* break intentionally omitted */ -#endif case IS_STRING: filename = Z_STRVAL_P(zval_files); filename_len = Z_STRLEN_P(zval_files); @@ -4389,11 +4322,6 @@ PHP_METHOD(Phar, extractTo) zval **zval_file; if (zend_hash_index_find(Z_ARRVAL_P(zval_files), i, (void **) &zval_file) == SUCCESS) { switch (Z_TYPE_PP(zval_file)) { -#if PHP_VERSION_ID >= 60000 - case IS_UNICODE: - zval_unicode_to_string(*(zval_file) TSRMLS_CC); - /* break intentionally omitted */ -#endif case IS_STRING: break; default: @@ -5414,11 +5342,7 @@ zend_function_entry phar_exception_methods[] = { #define REGISTER_PHAR_CLASS_CONST_LONG(class_name, const_name, value) \ zend_declare_class_constant_long(class_name, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); -#if PHP_VERSION_ID < 50200 -# define phar_exception_get_default() zend_exception_get_default() -#else -# define phar_exception_get_default() zend_exception_get_default(TSRMLS_C) -#endif +#define phar_exception_get_default() zend_exception_get_default(TSRMLS_C) void phar_object_init(TSRMLS_D) /* {{{ */ { diff --git a/ext/phar/stream.c b/ext/phar/stream.c index 401d81e109..f4197a5b11 100644 --- a/ext/phar/stream.c +++ b/ext/phar/stream.c @@ -942,11 +942,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char entry->filename_len = new_key_len; PHAR_ZSTR(new_str_key, new_key); -#if PHP_VERSION_ID < 50300 - zend_hash_update_current_key_ex(&phar->manifest, key_type, new_key, new_key_len, 0, NULL); -#else zend_hash_update_current_key_ex(&phar->manifest, key_type, new_key, new_key_len, 0, HASH_UPDATE_KEY_ANYWAY, NULL); -#endif } PHAR_STR_FREE(str_key); } @@ -968,11 +964,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char new_str_key[new_key_len] = 0; PHAR_ZSTR(new_str_key, new_key); -#if PHP_VERSION_ID < 50300 - zend_hash_update_current_key_ex(&phar->virtual_dirs, key_type, new_key, new_key_len, 0, NULL); -#else zend_hash_update_current_key_ex(&phar->virtual_dirs, key_type, new_key, new_key_len, 0, HASH_UPDATE_KEY_ANYWAY, NULL); -#endif efree(new_str_key); } PHAR_STR_FREE(str_key); @@ -996,11 +988,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char new_str_key[new_key_len] = 0; PHAR_ZSTR(new_str_key, new_key); -#if PHP_VERSION_ID < 50300 - zend_hash_update_current_key_ex(&phar->mounted_dirs, key_type, new_key, new_key_len, 0, NULL); -#else zend_hash_update_current_key_ex(&phar->mounted_dirs, key_type, new_key, new_key_len, 0, HASH_UPDATE_KEY_ANYWAY, NULL); -#endif efree(new_str_key); } PHAR_STR_FREE(str_key); diff --git a/ext/phar/util.c b/ext/phar/util.c index f2271dffd4..31d12e3da7 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -41,10 +41,6 @@ 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); #endif -#if !defined(PHP_VERSION_ID) || PHP_VERSION_ID < 50300 -extern php_stream_wrapper php_stream_phar_wrapper; -#endif - /* for links to relative location, prepend cwd of the entry */ static char *phar_get_link_location(phar_entry_info *entry TSRMLS_DC) /* {{{ */ { @@ -256,7 +252,6 @@ 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) /* {{{ */ { -#if PHP_VERSION_ID >= 50300 char *path, *fname, *arch, *entry, *ret, *test; int arch_len, entry_len, fname_len, ret_len; phar_archive_data *phar; @@ -344,223 +339,6 @@ splitted: } return ret; -#else /* PHP 5.2 */ - char resolved_path[MAXPATHLEN]; - char trypath[MAXPATHLEN]; - char *ptr, *end, *path = PG(include_path); - php_stream_wrapper *wrapper; - const char *p; - int n = 0; - char *fname, *arch, *entry, *ret, *test; - int arch_len, entry_len; - phar_archive_data *phar = NULL; - - if (!filename) { - return NULL; - } - - if (!zend_is_executing(TSRMLS_C) || !PHAR_G(cwd)) { - goto doit; - } - - fname = (char*)zend_get_executed_filename(TSRMLS_C); - - if (SUCCESS != phar_split_fname(fname, strlen(fname), &arch, &arch_len, &entry, &entry_len, 1, 0 TSRMLS_CC)) { - goto doit; - } - - efree(entry); - - if (*filename == '.') { - int try_len; - - if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL TSRMLS_CC)) { - efree(arch); - goto doit; - } - - try_len = filename_len; - test = phar_fix_filepath(estrndup(filename, filename_len), &try_len, 1 TSRMLS_CC); - - if (*test == '/') { - if (zend_hash_exists(&(phar->manifest), test + 1, try_len - 1)) { - spprintf(&ret, 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); - efree(arch); - efree(test); - return ret; - } - } - - efree(test); - } - - efree(arch); -doit: - if (*filename == '.' || IS_ABSOLUTE_PATH(filename, filename_len) || !path || !*path) { - if (tsrm_realpath(filename, resolved_path TSRMLS_CC)) { - return estrdup(resolved_path); - } else { - return NULL; - } - } - - /* test for stream wrappers and return */ - for (p = filename; p - filename < filename_len && (isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'); ++p, ++n); - - if (n < filename_len - 3 && (*p == ':') && (!strncmp("//", p+1, 2) || ( filename_len > 4 && !memcmp("data", filename, 4)))) { - /* found stream wrapper, this is an absolute path until stream wrappers implement realpath */ - return estrndup(filename, filename_len); - } - - ptr = (char *) path; - while (ptr && *ptr) { - int len, is_stream_wrapper = 0, maybe_stream = 1; - - end = strchr(ptr, DEFAULT_DIR_SEPARATOR); -#ifndef PHP_WIN32 - /* search for stream wrapper */ - if (end - ptr <= 1) { - maybe_stream = 0; - goto not_stream; - } - - for (p = ptr, n = 0; p < end && (isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'); ++p, ++n); - - if (n == end - ptr && *p && !strncmp("//", p+1, 2)) { - is_stream_wrapper = 1; - /* seek to real end of include_path portion */ - end = strchr(end + 1, DEFAULT_DIR_SEPARATOR); - } else { - maybe_stream = 0; - } -not_stream: -#endif - if (end) { - if ((end-ptr) + 1 + filename_len + 1 >= MAXPATHLEN) { - ptr = end + 1; - continue; - } - - memcpy(trypath, ptr, end-ptr); - len = end-ptr; - trypath[end-ptr] = '/'; - memcpy(trypath+(end-ptr)+1, filename, filename_len+1); - ptr = end+1; - } else { - len = strlen(ptr); - - if (len + 1 + filename_len + 1 >= MAXPATHLEN) { - break; - } - - memcpy(trypath, ptr, len); - trypath[len] = '/'; - memcpy(trypath+len+1, filename, filename_len+1); - ptr = NULL; - } - - if (!is_stream_wrapper && maybe_stream) { - /* search for stream wrapper */ - for (p = trypath, n = 0; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; ++p, ++n); - } - - if (is_stream_wrapper || (n < len - 3 && (*p == ':') && (n > 1) && (!strncmp("//", p+1, 2) || !memcmp("data", trypath, 4)))) { - char *actual; - - wrapper = php_stream_locate_url_wrapper(trypath, &actual, STREAM_OPEN_FOR_INCLUDE TSRMLS_CC); - if (wrapper == &php_plain_files_wrapper) { - strlcpy(trypath, actual, sizeof(trypath)); - } else if (!wrapper) { - /* if wrapper is NULL, there was a mal-formed include_path stream wrapper, so skip this ptr */ - continue; - } else { - if (wrapper->wops->url_stat) { - php_stream_statbuf ssb; - - if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, 0, &ssb, NULL TSRMLS_CC)) { - if (wrapper == &php_stream_phar_wrapper) { - char *arch, *entry; - int arch_len, entry_len, ret_len; - - ret_len = strlen(trypath); - /* found phar:// */ - - if (SUCCESS != phar_split_fname(trypath, ret_len, &arch, &arch_len, &entry, &entry_len, 1, 0 TSRMLS_CC)) { - return estrndup(trypath, ret_len); - } - - zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len, (void **) &pphar); - - if (!pphar && PHAR_G(manifest_cached)) { - zend_hash_find(&cached_phars, arch, arch_len, (void **) &pphar); - } - - efree(arch); - efree(entry); - - return estrndup(trypath, ret_len); - } - return estrdup(trypath); - } - } - continue; - } - } - - if (tsrm_realpath(trypath, resolved_path TSRMLS_CC)) { - return estrdup(resolved_path); - } - } /* end provided path */ - - /* check in calling scripts' current working directory as a fall back case */ - if (zend_is_executing(TSRMLS_C)) { - char *exec_fname = (char*)zend_get_executed_filename(TSRMLS_C); - int exec_fname_length = strlen(exec_fname); - const char *p; - int n = 0; - - while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length])); - if (exec_fname && exec_fname[0] != '[' && - exec_fname_length > 0 && - exec_fname_length + 1 + filename_len + 1 < MAXPATHLEN) { - memcpy(trypath, exec_fname, exec_fname_length + 1); - memcpy(trypath+exec_fname_length + 1, filename, filename_len+1); - - /* search for stream wrapper */ - for (p = trypath; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; ++p, ++n); - - if (n < exec_fname_length - 3 && (*p == ':') && (n > 1) && (!strncmp("//", p+1, 2) || !memcmp("data", trypath, 4))) { - char *actual; - - wrapper = php_stream_locate_url_wrapper(trypath, &actual, STREAM_OPEN_FOR_INCLUDE TSRMLS_CC); - - if (wrapper == &php_plain_files_wrapper) { - /* this should never technically happen, but we'll leave it here for completeness */ - strlcpy(trypath, actual, sizeof(trypath)); - } else if (!wrapper) { - /* if wrapper is NULL, there was a malformed include_path stream wrapper - this also should be impossible */ - return NULL; - } else { - return estrdup(trypath); - } - } - - if (tsrm_realpath(trypath, resolved_path TSRMLS_CC)) { - return estrdup(resolved_path); - } - } - } - - return NULL; -#endif /* PHP 5.2 */ } /* }}} */ @@ -850,11 +628,6 @@ int phar_open_archive_fp(phar_archive_data *phar TSRMLS_DC) /* {{{ */ if (phar_get_pharfp(phar TSRMLS_CC)) { return SUCCESS; } -#if PHP_API_VERSION < 20100412 - if (PG(safe_mode) && (!php_checkuid(phar->fname, NULL, CHECKUID_ALLOW_ONLY_FILE))) { - return FAILURE; - } -#endif if (php_check_open_basedir(phar->fname TSRMLS_CC)) { return FAILURE; @@ -1031,47 +804,12 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TS } /* }}} */ -#if defined(PHP_VERSION_ID) && PHP_VERSION_ID < 50202 -typedef struct { - char *data; - size_t fpos; - size_t fsize; - size_t smax; - int mode; - php_stream **owner_ptr; -} php_stream_memory_data; -#endif - int phar_create_writeable_entry(phar_archive_data *phar, phar_entry_info *entry, char **error TSRMLS_DC) /* {{{ */ { if (entry->fp_type == PHAR_MOD) { /* already newly created, truncate */ -#if PHP_VERSION_ID >= 50202 php_stream_truncate_set_size(entry->fp, 0); -#else - if (php_stream_is(entry->fp, PHP_STREAM_IS_TEMP)) { - if (php_stream_is(*(php_stream**)entry->fp->abstract, PHP_STREAM_IS_MEMORY)) { - php_stream *inner = *(php_stream**)entry->fp->abstract; - php_stream_memory_data *memfp = (php_stream_memory_data*)inner->abstract; - memfp->fpos = 0; - memfp->fsize = 0; - } else if (php_stream_is(*(php_stream**)entry->fp->abstract, PHP_STREAM_IS_STDIO)) { - php_stream_truncate_set_size(*(php_stream**)entry->fp->abstract, 0); - } else { - if (error) { - spprintf(error, 0, "phar error: file \"%s\" cannot be opened for writing, no truncate support", phar->fname); - } - return FAILURE; - } - } else if (php_stream_is(entry->fp, PHP_STREAM_IS_STDIO)) { - php_stream_truncate_set_size(entry->fp, 0); - } else { - if (error) { - spprintf(error, 0, "phar error: file \"%s\" cannot be opened for writing, no truncate support", phar->fname); - } - return FAILURE; - } -#endif + entry->old_flags = entry->flags; entry->is_modified = 1; phar->is_modified = 1; @@ -1689,11 +1427,7 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, off_t end, Z_TYPE_P(zdata) = IS_STRING; Z_STRLEN_P(zdata) = end; -#if PHP_MAJOR_VERSION > 5 - if (end != (off_t) php_stream_copy_to_mem(fp, (void **) &(Z_STRVAL_P(zdata)), (size_t) end, 0)) { -#else if (end != (off_t) php_stream_copy_to_mem(fp, &(Z_STRVAL_P(zdata)), (size_t) end, 0)) { -#endif zval_dtor(zdata); zval_dtor(zsig); zval_dtor(zkey); @@ -1705,11 +1439,7 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, off_t end, return FAILURE; } -#if PHP_VERSION_ID < 50300 - if (FAILURE == zend_fcall_info_init(openssl, &fci, &fcc TSRMLS_CC)) { -#else if (FAILURE == zend_fcall_info_init(openssl, 0, &fci, &fcc, NULL, NULL TSRMLS_CC)) { -#endif zval_dtor(zdata); zval_dtor(zsig); zval_dtor(zkey); @@ -1723,13 +1453,6 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, off_t end, fci.param_count = 3; fci.params = zp; -#if PHP_VERSION_ID < 50300 - ++(zdata->refcount); - if (!is_sign) { - ++(zsig->refcount); - } - ++(zkey->refcount); -#else Z_ADDREF_P(zdata); if (is_sign) { Z_SET_ISREF_P(zsig); @@ -1737,7 +1460,7 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, off_t end, Z_ADDREF_P(zsig); } Z_ADDREF_P(zkey); -#endif + fci.retval_ptr_ptr = &retval_ptr; if (FAILURE == zend_call_function(&fci, &fcc TSRMLS_CC)) { @@ -1754,21 +1477,15 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, off_t end, zval_dtor(openssl); efree(openssl); -#if PHP_VERSION_ID < 50300 - --(zdata->refcount); - if (!is_sign) { - --(zsig->refcount); - } - --(zkey->refcount); -#else Z_DELREF_P(zdata); + if (is_sign) { Z_UNSET_ISREF_P(zsig); } else { Z_DELREF_P(zsig); } Z_DELREF_P(zkey); -#endif + zval_dtor(zdata); efree(zdata); zval_dtor(zkey); @@ -2294,11 +2011,7 @@ static int phar_update_cached_entry(void *data, void *argument) /* {{{ */ ALLOC_ZVAL(entry->metadata); *entry->metadata = *t; zval_copy_ctor(entry->metadata); -#if PHP_VERSION_ID < 50300 - entry->metadata->refcount = 1; -#else Z_SET_REFCOUNT_P(entry->metadata, 1); -#endif entry->metadata_str.c = NULL; entry->metadata_str.len = 0; } @@ -2342,11 +2055,7 @@ static void phar_copy_cached_phar(phar_archive_data **pphar TSRMLS_DC) /* {{{ */ ALLOC_ZVAL(phar->metadata); *phar->metadata = *t; zval_copy_ctor(phar->metadata); -#if PHP_VERSION_ID < 50300 - phar->metadata->refcount = 1; -#else Z_SET_REFCOUNT_P(phar->metadata, 1); -#endif } } diff --git a/ext/phar/zip.c b/ext/phar/zip.c index 6ba745e9cb..e3b64859b8 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -578,10 +578,6 @@ foundit: /* construct actual offset to file start - local extra_len can be different from central extra_len */ entry.offset = entry.offset_abs = sizeof(local) + entry.header_offset + PHAR_GET_16(local.filename_len) + PHAR_GET_16(local.extra_len); -#if PHP_VERSION_ID < 50207 - /* work around Bug #46147 */ - fp->writepos = fp->readpos = 0; -#endif php_stream_seek(fp, entry.offset, SEEK_SET); /* these next lines should be for php < 5.2.6 after 5.3 filters are fixed */ fp->writepos = 0; @@ -605,9 +601,6 @@ foundit: if (!(entry.uncompressed_filesize = php_stream_copy_to_mem(fp, &actual_alias, entry.uncompressed_filesize, 0)) || !actual_alias) { pefree(entry.filename, entry.is_persistent); -#if PHP_VERSION_ID < 50207 - PHAR_ZIP_FAIL("unable to read in alias, truncated (PHP 5.2.7 and newer has a potential fix for this problem)"); -#endif PHAR_ZIP_FAIL("unable to read in alias, truncated"); } @@ -626,9 +619,6 @@ foundit: if (!(entry.uncompressed_filesize = php_stream_copy_to_mem(fp, &actual_alias, entry.uncompressed_filesize, 0)) || !actual_alias) { pefree(entry.filename, entry.is_persistent); -#if PHP_VERSION_ID < 50207 - PHAR_ZIP_FAIL("unable to read in alias, truncated (PHP 5.2.7 and newer has a potential fix for this problem)"); -#endif PHAR_ZIP_FAIL("unable to read in alias, truncated"); } |