version 1.1, 2012/02/21 23:47:59
|
version 1.1.1.5, 2014/06/15 20:03:53
|
Line 2
|
Line 2
|
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| phar php single-file executable PHP extension | |
| phar php single-file executable PHP extension | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| Copyright (c) 2005-2012 The PHP Group | | | Copyright (c) 2005-2014 The PHP Group | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| This source file is subject to version 3.01 of the PHP license, | |
| This source file is subject to version 3.01 of the PHP license, | |
| that is bundled with this package in the file LICENSE, and is | |
| that is bundled with this package in the file LICENSE, and is | |
Line 1738 static int phar_open_from_fp(php_stream* fp, char *fna
|
Line 1738 static int phar_open_from_fp(php_stream* fp, char *fna
|
static int phar_analyze_path(const char *fname, const char *ext, int ext_len, int for_create TSRMLS_DC) /* {{{ */ |
static int phar_analyze_path(const char *fname, const char *ext, int ext_len, int for_create TSRMLS_DC) /* {{{ */ |
{ |
{ |
php_stream_statbuf ssb; |
php_stream_statbuf ssb; |
char *realpath, old, *a = (char *)(ext + ext_len); | char *realpath; |
| char *filename = estrndup(fname, (ext - fname) + ext_len); |
|
|
old = *a; | if ((realpath = expand_filepath(filename, NULL TSRMLS_CC))) { |
*a = '\0'; | |
| |
if ((realpath = expand_filepath(fname, NULL TSRMLS_CC))) { | |
#ifdef PHP_WIN32 |
#ifdef PHP_WIN32 |
phar_unixify_path_separators(realpath, strlen(realpath)); |
phar_unixify_path_separators(realpath, strlen(realpath)); |
#endif |
#endif |
if (zend_hash_exists(&(PHAR_GLOBALS->phar_fname_map), realpath, strlen(realpath))) { |
if (zend_hash_exists(&(PHAR_GLOBALS->phar_fname_map), realpath, strlen(realpath))) { |
*a = old; |
|
efree(realpath); |
efree(realpath); |
|
efree(filename); |
return SUCCESS; |
return SUCCESS; |
} |
} |
|
|
if (PHAR_G(manifest_cached) && zend_hash_exists(&cached_phars, realpath, strlen(realpath))) { |
if (PHAR_G(manifest_cached) && zend_hash_exists(&cached_phars, realpath, strlen(realpath))) { |
*a = old; |
|
efree(realpath); |
efree(realpath); |
|
efree(filename); |
return SUCCESS; |
return SUCCESS; |
} |
} |
efree(realpath); |
efree(realpath); |
} |
} |
|
|
if (SUCCESS == php_stream_stat_path((char *) fname, &ssb)) { | if (SUCCESS == php_stream_stat_path((char *) filename, &ssb)) { |
*a = old; | |
|
|
|
efree(filename); |
|
|
if (ssb.sb.st_mode & S_IFDIR) { |
if (ssb.sb.st_mode & S_IFDIR) { |
return FAILURE; |
return FAILURE; |
} |
} |
Line 1777 static int phar_analyze_path(const char *fname, const
|
Line 1776 static int phar_analyze_path(const char *fname, const
|
char *slash; |
char *slash; |
|
|
if (!for_create) { |
if (!for_create) { |
*a = old; | efree(filename); |
return FAILURE; |
return FAILURE; |
} |
} |
|
|
slash = (char *) strrchr(fname, '/'); | slash = (char *) strrchr(filename, '/'); |
*a = old; | |
|
|
if (slash) { |
if (slash) { |
old = *slash; |
|
*slash = '\0'; |
*slash = '\0'; |
} |
} |
|
|
if (SUCCESS != php_stream_stat_path((char *) fname, &ssb)) { | if (SUCCESS != php_stream_stat_path((char *) filename, &ssb)) { |
if (slash) { | if (!slash) { |
*slash = old; | if (!(realpath = expand_filepath(filename, NULL TSRMLS_CC))) { |
} else { | efree(filename); |
if (!(realpath = expand_filepath(fname, NULL TSRMLS_CC))) { | |
return FAILURE; |
return FAILURE; |
} |
} |
#ifdef PHP_WIN32 |
#ifdef PHP_WIN32 |
phar_unixify_path_separators(realpath, strlen(realpath)); |
phar_unixify_path_separators(realpath, strlen(realpath)); |
#endif |
#endif |
a = strstr(realpath, fname) + ((ext - fname) + ext_len); | slash = strstr(realpath, filename) + ((ext - fname) + ext_len); |
*a = '\0'; | *slash = '\0'; |
slash = strrchr(realpath, '/'); |
slash = strrchr(realpath, '/'); |
|
|
if (slash) { |
if (slash) { |
*slash = '\0'; |
*slash = '\0'; |
} else { |
} else { |
efree(realpath); |
efree(realpath); |
|
efree(filename); |
return FAILURE; |
return FAILURE; |
} |
} |
|
|
if (SUCCESS != php_stream_stat_path(realpath, &ssb)) { |
if (SUCCESS != php_stream_stat_path(realpath, &ssb)) { |
efree(realpath); |
efree(realpath); |
|
efree(filename); |
return FAILURE; |
return FAILURE; |
} |
} |
|
|
efree(realpath); |
efree(realpath); |
|
|
if (ssb.sb.st_mode & S_IFDIR) { |
if (ssb.sb.st_mode & S_IFDIR) { |
|
efree(filename); |
return SUCCESS; |
return SUCCESS; |
} |
} |
} |
} |
|
|
|
efree(filename); |
return FAILURE; |
return FAILURE; |
} |
} |
|
|
if (slash) { | efree(filename); |
*slash = old; | |
} | |
|
|
if (ssb.sb.st_mode & S_IFDIR) { |
if (ssb.sb.st_mode & S_IFDIR) { |
return SUCCESS; |
return SUCCESS; |
Line 2335 int phar_open_executed_filename(char *alias, int alias
|
Line 2333 int phar_open_executed_filename(char *alias, int alias
|
*error = NULL; |
*error = NULL; |
} |
} |
|
|
fname = zend_get_executed_filename(TSRMLS_C); | fname = (char*)zend_get_executed_filename(TSRMLS_C); |
fname_len = strlen(fname); |
fname_len = strlen(fname); |
|
|
if (phar_open_parsed_phar(fname, fname_len, alias, alias_len, 0, REPORT_ERRORS, NULL, 0 TSRMLS_CC) == SUCCESS) { |
if (phar_open_parsed_phar(fname, fname_len, alias, alias_len, 0, REPORT_ERRORS, NULL, 0 TSRMLS_CC) == SUCCESS) { |
Line 2581 int phar_flush(phar_archive_data *phar, char *user_stu
|
Line 2579 int phar_flush(phar_archive_data *phar, char *user_stu
|
php_serialize_data_t metadata_hash; |
php_serialize_data_t metadata_hash; |
smart_str main_metadata_str = {0}; |
smart_str main_metadata_str = {0}; |
int free_user_stub, free_fp = 1, free_ufp = 1; |
int free_user_stub, free_fp = 1, free_ufp = 1; |
|
int manifest_hack = 0; |
|
|
if (phar->is_persistent) { |
if (phar->is_persistent) { |
if (error) { |
if (error) { |
Line 2649 int phar_flush(phar_archive_data *phar, char *user_stu
|
Line 2648 int phar_flush(phar_archive_data *phar, char *user_stu
|
len = -len; |
len = -len; |
} |
} |
user_stub = 0; |
user_stub = 0; |
#if PHP_MAJOR_VERSION >= 6 | |
if (!(len = php_stream_copy_to_mem(stubfile, (void **) &user_stub, len, 0)) || !user_stub) { | |
#else | |
if (!(len = php_stream_copy_to_mem(stubfile, &user_stub, len, 0)) || !user_stub) { |
if (!(len = php_stream_copy_to_mem(stubfile, &user_stub, len, 0)) || !user_stub) { |
#endif |
|
if (closeoldfile) { |
if (closeoldfile) { |
php_stream_close(oldfile); |
php_stream_close(oldfile); |
} |
} |
Line 2935 int phar_flush(phar_archive_data *phar, char *user_stu
|
Line 2931 int phar_flush(phar_archive_data *phar, char *user_stu
|
|
|
manifest_len = offset + phar->alias_len + sizeof(manifest) + main_metadata_str.len; |
manifest_len = offset + phar->alias_len + sizeof(manifest) + main_metadata_str.len; |
phar_set_32(manifest, manifest_len); |
phar_set_32(manifest, manifest_len); |
|
/* Hack - see bug #65028, add padding byte to the end of the manifest */ |
|
if(manifest[0] == '\r' || manifest[0] == '\n') { |
|
manifest_len++; |
|
phar_set_32(manifest, manifest_len); |
|
manifest_hack = 1; |
|
} |
phar_set_32(manifest+4, new_manifest_count); |
phar_set_32(manifest+4, new_manifest_count); |
if (has_dirs) { |
if (has_dirs) { |
*(manifest + 8) = (unsigned char) (((PHAR_API_VERSION) >> 8) & 0xFF); |
*(manifest + 8) = (unsigned char) (((PHAR_API_VERSION) >> 8) & 0xFF); |
Line 3059 int phar_flush(phar_archive_data *phar, char *user_stu
|
Line 3061 int phar_flush(phar_archive_data *phar, char *user_stu
|
return EOF; |
return EOF; |
} |
} |
} |
} |
|
/* Hack - see bug #65028, add padding byte to the end of the manifest */ |
|
if(manifest_hack) { |
|
if(1 != php_stream_write(newfile, manifest, 1)) { |
|
if (closeoldfile) { |
|
php_stream_close(oldfile); |
|
} |
|
|
|
php_stream_close(newfile); |
|
|
|
if (error) { |
|
spprintf(error, 0, "unable to write manifest padding byte"); |
|
} |
|
|
|
return EOF; |
|
} |
|
} |
|
|
/* now copy the actual file data to the new phar */ |
/* now copy the actual file data to the new phar */ |
offset = php_stream_tell(newfile); |
offset = php_stream_tell(newfile); |
for (zend_hash_internal_pointer_reset(&phar->manifest); |
for (zend_hash_internal_pointer_reset(&phar->manifest); |
Line 3340 static zend_op_array *phar_compile_file(zend_file_hand
|
Line 3358 static zend_op_array *phar_compile_file(zend_file_hand
|
return phar_orig_compile_file(file_handle, type TSRMLS_CC); |
return phar_orig_compile_file(file_handle, type TSRMLS_CC); |
} |
} |
if (strstr(file_handle->filename, ".phar") && !strstr(file_handle->filename, "://")) { |
if (strstr(file_handle->filename, ".phar") && !strstr(file_handle->filename, "://")) { |
if (SUCCESS == phar_open_from_filename(file_handle->filename, strlen(file_handle->filename), NULL, 0, 0, &phar, NULL TSRMLS_CC)) { | if (SUCCESS == phar_open_from_filename((char*)file_handle->filename, strlen(file_handle->filename), NULL, 0, 0, &phar, NULL TSRMLS_CC)) { |
if (phar->is_zip || phar->is_tar) { |
if (phar->is_zip || phar->is_tar) { |
zend_file_handle f = *file_handle; |
zend_file_handle f = *file_handle; |
|
|
Line 3421 int phar_zend_open(const char *filename, zend_file_han
|
Line 3439 int phar_zend_open(const char *filename, zend_file_han
|
char *fname; |
char *fname; |
int fname_len; |
int fname_len; |
|
|
fname = zend_get_executed_filename(TSRMLS_C); | fname = (char*)zend_get_executed_filename(TSRMLS_C); |
fname_len = strlen(fname); |
fname_len = strlen(fname); |
|
|
if (fname_len > 7 && !strncasecmp(fname, "phar://", 7)) { |
if (fname_len > 7 && !strncasecmp(fname, "phar://", 7)) { |
Line 3669 PHP_MINFO_FUNCTION(phar) /* {{{ */
|
Line 3687 PHP_MINFO_FUNCTION(phar) /* {{{ */
|
php_info_print_table_header(2, "Phar: PHP Archive support", "enabled"); |
php_info_print_table_header(2, "Phar: PHP Archive support", "enabled"); |
php_info_print_table_row(2, "Phar EXT version", PHP_PHAR_VERSION); |
php_info_print_table_row(2, "Phar EXT version", PHP_PHAR_VERSION); |
php_info_print_table_row(2, "Phar API version", PHP_PHAR_API_VERSION); |
php_info_print_table_row(2, "Phar API version", PHP_PHAR_API_VERSION); |
php_info_print_table_row(2, "SVN revision", "$Revision$"); | php_info_print_table_row(2, "SVN revision", "$Id$"); |
php_info_print_table_row(2, "Phar-based phar archives", "enabled"); |
php_info_print_table_row(2, "Phar-based phar archives", "enabled"); |
php_info_print_table_row(2, "Tar-based phar archives", "enabled"); |
php_info_print_table_row(2, "Tar-based phar archives", "enabled"); |
php_info_print_table_row(2, "ZIP-based phar archives", "enabled"); |
php_info_print_table_row(2, "ZIP-based phar archives", "enabled"); |