2007-01-21 23:25:50 +08:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| phar php single - file executable PHP extension |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2007-02-06 05:38:50 +08:00
| Copyright ( c ) 2005 - 2007 The PHP Group |
2007-01-21 23:25:50 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| 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 |
| available through the world - wide - web at the following url : |
| http : //www.php.net/license/3_01.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ php . net so we can mail you a copy immediately . |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Authors : Gregory Beaver < cellog @ php . net > |
| Marcus Boerger < helly @ php . net > |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
/* $Id$ */
# include "phar_internal.h"
2008-01-11 15:30:03 +08:00
# include "func_interceptors.h"
2007-01-21 23:25:50 +08:00
static zend_class_entry * phar_ce_archive ;
2008-02-28 05:34:26 +08:00
static zend_class_entry * phar_ce_data ;
2007-01-29 14:02:19 +08:00
static zend_class_entry * phar_ce_PharException ;
2007-01-21 23:25:50 +08:00
# if HAVE_SPL
static zend_class_entry * phar_ce_entry ;
# endif
2007-03-26 03:03:38 +08:00
static int phar_get_extract_list ( void * pDest , int num_args , va_list args , zend_hash_key * hash_key ) /* { { { */
{
zval * return_value = va_arg ( args , zval * ) ;
2007-05-10 02:09:41 +08:00
add_assoc_string_ex ( return_value , * ( char * * ) & hash_key - > arKey , hash_key - > nKeyLength , ( char * ) pDest , 1 ) ;
2007-03-26 03:03:38 +08:00
return ZEND_HASH_APPLY_KEEP ;
}
/* }}} */
2008-02-08 17:25:02 +08:00
/* {{{ proto array Phar::getExtractList()
2007-03-26 03:03:38 +08:00
* Return array of extract list
*/
PHP_METHOD ( Phar , getExtractList )
{
array_init ( return_value ) ;
2007-05-17 07:16:51 +08:00
phar_request_initialize ( TSRMLS_C ) ;
2007-03-26 03:03:38 +08:00
zend_hash_apply_with_arguments ( & PHAR_G ( phar_plain_map ) , phar_get_extract_list , 1 , return_value ) ;
}
/* }}} */
2008-02-08 17:25:02 +08:00
static int phar_file_type ( HashTable * mimes , char * file , char * * mime_type TSRMLS_DC ) /* { { { */
2007-12-24 05:12:42 +08:00
{
char * ext ;
phar_mime_type * mime ;
ext = strrchr ( file , ' . ' ) ;
if ( ! ext ) {
* mime_type = " text/plain " ;
/* no file extension = assume text/plain */
return PHAR_MIME_OTHER ;
}
2008-03-23 06:11:49 +08:00
+ + ext ;
2007-12-24 05:12:42 +08:00
if ( SUCCESS ! = zend_hash_find ( mimes , ext , strlen ( ext ) , ( void * * ) & mime ) ) {
* mime_type = " application/octet-stream " ;
return PHAR_MIME_OTHER ;
}
* mime_type = mime - > mime ;
return mime - > type ;
}
/* }}} */
2008-02-08 17:25:02 +08:00
static void phar_mung_server_vars ( char * fname , char * entry , int entry_len , char * basename , int basename_len , char * request_uri , int request_uri_len TSRMLS_DC ) /* { { { */
2008-01-04 12:57:11 +08:00
{
zval * * _SERVER , * * stuff ;
char * path_info ;
/* "tweak" $_SERVER variables requested in earlier call to Phar::mungServer() */
if ( SUCCESS ! = zend_hash_find ( & EG ( symbol_table ) , " _SERVER " , sizeof ( " _SERVER " ) , ( void * * ) & _SERVER ) ) {
return ;
}
2008-01-11 10:52:13 +08:00
/* PATH_INFO and PATH_TRANSLATED should always be munged */
if ( SUCCESS = = zend_hash_find ( Z_ARRVAL_PP ( _SERVER ) , " PATH_INFO " , sizeof ( " PATH_INFO " ) , ( void * * ) & stuff ) ) {
int code ;
zval * temp ;
char newname [ ] = " PHAR_PATH_INFO " ;
2008-02-08 07:42:03 +08:00
2008-03-23 06:56:04 +08:00
path_info = Z_STRVAL_PP ( stuff ) ;
code = Z_STRLEN_PP ( stuff ) ;
if ( Z_STRLEN_PP ( stuff ) > entry_len & & ! memcmp ( Z_STRVAL_PP ( stuff ) , entry , entry_len ) ) {
2008-04-23 01:11:30 +08:00
ZVAL_STRINGL ( * stuff , Z_STRVAL_PP ( stuff ) + entry_len , request_uri_len , 1 ) ;
2008-02-08 07:42:03 +08:00
2008-03-23 06:56:04 +08:00
MAKE_STD_ZVAL ( temp ) ;
ZVAL_STRINGL ( temp , path_info , code , 0 ) ;
zend_hash_update ( Z_ARRVAL_PP ( _SERVER ) , newname , sizeof ( newname ) , ( void * ) & temp , sizeof ( zval * * ) , NULL ) ;
}
2008-01-11 10:52:13 +08:00
}
if ( SUCCESS = = zend_hash_find ( Z_ARRVAL_PP ( _SERVER ) , " PATH_TRANSLATED " , sizeof ( " PATH_TRANSLATED " ) , ( void * * ) & stuff ) ) {
int code ;
zval * temp ;
char newname [ ] = " PHAR_PATH_TRANSLATED " ;
2008-02-08 07:42:03 +08:00
2008-01-11 10:52:13 +08:00
path_info = Z_STRVAL_PP ( stuff ) ;
code = Z_STRLEN_PP ( stuff ) ;
Z_STRLEN_PP ( stuff ) = spprintf ( & ( Z_STRVAL_PP ( stuff ) ) , 4096 , " phar://%s%s " , fname , entry ) ;
2008-02-08 07:42:03 +08:00
MAKE_STD_ZVAL ( temp ) ;
ZVAL_STRINGL ( temp , path_info , code , 0 ) ;
zend_hash_update ( Z_ARRVAL_PP ( _SERVER ) , newname , sizeof ( newname ) , ( void * ) & temp , sizeof ( zval * * ) , NULL ) ;
2008-01-11 10:52:13 +08:00
}
if ( ! PHAR_GLOBALS - > phar_SERVER_mung_list . arBuckets | | ! zend_hash_num_elements ( & ( PHAR_GLOBALS - > phar_SERVER_mung_list ) ) ) {
return ;
}
2008-02-08 07:42:03 +08:00
if ( zend_hash_exists ( & ( PHAR_GLOBALS - > phar_SERVER_mung_list ) , " REQUEST_URI " , sizeof ( " REQUEST_URI " ) - 1 ) ) {
if ( SUCCESS = = zend_hash_find ( Z_ARRVAL_PP ( _SERVER ) , " REQUEST_URI " , sizeof ( " REQUEST_URI " ) , ( void * * ) & stuff ) ) {
int code ;
zval * temp ;
char newname [ ] = " PHAR_REQUEST_URI " ;
path_info = Z_STRVAL_PP ( stuff ) ;
code = Z_STRLEN_PP ( stuff ) ;
2008-03-23 06:56:04 +08:00
if ( Z_STRLEN_PP ( stuff ) > basename_len & & ! memcmp ( Z_STRVAL_PP ( stuff ) , basename , basename_len ) ) {
ZVAL_STRINGL ( * stuff , Z_STRVAL_PP ( stuff ) + basename_len , Z_STRLEN_PP ( stuff ) - basename_len , 1 ) ;
2008-02-08 07:42:03 +08:00
2008-03-23 06:56:04 +08:00
MAKE_STD_ZVAL ( temp ) ;
ZVAL_STRINGL ( temp , path_info , code , 0 ) ;
zend_hash_update ( Z_ARRVAL_PP ( _SERVER ) , newname , sizeof ( newname ) , ( void * ) & temp , sizeof ( zval * * ) , NULL ) ;
}
2008-02-08 07:42:03 +08:00
}
}
if ( zend_hash_exists ( & ( PHAR_GLOBALS - > phar_SERVER_mung_list ) , " PHP_SELF " , sizeof ( " PHP_SELF " ) - 1 ) ) {
if ( SUCCESS = = zend_hash_find ( Z_ARRVAL_PP ( _SERVER ) , " PHP_SELF " , sizeof ( " PHP_SELF " ) , ( void * * ) & stuff ) ) {
int code ;
zval * temp ;
char newname [ ] = " PHAR_PHP_SELF " ;
path_info = Z_STRVAL_PP ( stuff ) ;
code = Z_STRLEN_PP ( stuff ) ;
2008-03-23 06:56:04 +08:00
if ( Z_STRLEN_PP ( stuff ) > basename_len & & ! memcmp ( Z_STRVAL_PP ( stuff ) , basename , basename_len ) ) {
ZVAL_STRINGL ( * stuff , Z_STRVAL_PP ( stuff ) + basename_len , Z_STRLEN_PP ( stuff ) - basename_len , 1 ) ;
2008-02-08 07:42:03 +08:00
2008-03-23 06:56:04 +08:00
MAKE_STD_ZVAL ( temp ) ;
ZVAL_STRINGL ( temp , path_info , code , 0 ) ;
zend_hash_update ( Z_ARRVAL_PP ( _SERVER ) , newname , sizeof ( newname ) , ( void * ) & temp , sizeof ( zval * * ) , NULL ) ;
}
2008-02-08 07:42:03 +08:00
}
}
2008-01-04 12:57:11 +08:00
if ( zend_hash_exists ( & ( PHAR_GLOBALS - > phar_SERVER_mung_list ) , " SCRIPT_NAME " , sizeof ( " SCRIPT_NAME " ) - 1 ) ) {
if ( SUCCESS = = zend_hash_find ( Z_ARRVAL_PP ( _SERVER ) , " SCRIPT_NAME " , sizeof ( " SCRIPT_NAME " ) , ( void * * ) & stuff ) ) {
int code ;
zval * temp ;
char newname [ ] = " PHAR_SCRIPT_NAME " ;
path_info = Z_STRVAL_PP ( stuff ) ;
code = Z_STRLEN_PP ( stuff ) ;
2008-04-23 01:13:07 +08:00
ZVAL_STRINGL ( * stuff , entry , entry_len , 1 ) ;
2008-02-08 07:42:03 +08:00
MAKE_STD_ZVAL ( temp ) ;
ZVAL_STRINGL ( temp , path_info , code , 0 ) ;
zend_hash_update ( Z_ARRVAL_PP ( _SERVER ) , newname , sizeof ( newname ) , ( void * ) & temp , sizeof ( zval * * ) , NULL ) ;
2008-01-04 12:57:11 +08:00
}
}
if ( zend_hash_exists ( & ( PHAR_GLOBALS - > phar_SERVER_mung_list ) , " SCRIPT_FILENAME " , sizeof ( " SCRIPT_FILENAME " ) - 1 ) ) {
if ( SUCCESS = = zend_hash_find ( Z_ARRVAL_PP ( _SERVER ) , " SCRIPT_FILENAME " , sizeof ( " SCRIPT_FILENAME " ) , ( void * * ) & stuff ) ) {
int code ;
zval * temp ;
char newname [ ] = " PHAR_SCRIPT_FILENAME " ;
2008-02-08 07:42:03 +08:00
2008-01-04 12:57:11 +08:00
path_info = Z_STRVAL_PP ( stuff ) ;
code = Z_STRLEN_PP ( stuff ) ;
Z_STRLEN_PP ( stuff ) = spprintf ( & ( Z_STRVAL_PP ( stuff ) ) , 4096 , " phar://%s%s " , fname , entry ) ;
2008-02-08 07:42:03 +08:00
MAKE_STD_ZVAL ( temp ) ;
ZVAL_STRINGL ( temp , path_info , code , 0 ) ;
zend_hash_update ( Z_ARRVAL_PP ( _SERVER ) , newname , sizeof ( newname ) , ( void * ) & temp , sizeof ( zval * * ) , NULL ) ;
2008-01-04 12:57:11 +08:00
}
}
}
2008-02-08 17:25:02 +08:00
/* }}} */
2008-01-04 12:57:11 +08:00
2008-02-08 17:25:02 +08:00
static int phar_file_action ( phar_entry_data * phar , char * mime_type , int code , char * entry , int entry_len , char * arch , int arch_len , char * basename , int basename_len , char * ru , int ru_len TSRMLS_DC ) /* { { { */
2007-12-24 05:12:42 +08:00
{
2008-01-10 23:13:00 +08:00
char * name = NULL , buf [ 8192 ] , * cwd ;
2007-12-24 05:12:42 +08:00
zend_syntax_highlighter_ini syntax_highlighter_ini ;
sapi_header_line ctr = { 0 } ;
size_t got ;
int dummy = 1 , name_len , ret ;
zend_file_handle file_handle ;
zend_op_array * new_op_array ;
zval * result = NULL ;
switch ( code ) {
case PHAR_MIME_PHPS :
2008-01-04 12:57:11 +08:00
efree ( basename ) ;
2007-12-24 05:12:42 +08:00
/* highlight source */
2007-12-29 10:01:12 +08:00
if ( entry [ 0 ] = = ' / ' ) {
name_len = spprintf ( & name , 4096 , " phar://%s%s " , arch , entry ) ;
} else {
name_len = spprintf ( & name , 4096 , " phar://%s/%s " , arch , entry ) ;
}
2007-12-24 05:12:42 +08:00
php_get_highlight_struct ( & syntax_highlighter_ini ) ;
2008-02-08 07:42:03 +08:00
highlight_file ( name , & syntax_highlighter_ini TSRMLS_CC ) ;
2007-12-24 05:12:42 +08:00
phar_entry_delref ( phar TSRMLS_CC ) ;
efree ( name ) ;
2007-12-27 00:59:01 +08:00
# ifdef PHP_WIN32
efree ( arch ) ;
# endif
2007-12-24 05:12:42 +08:00
zend_bailout ( ) ;
case PHAR_MIME_OTHER :
/* send headers, output file contents */
2008-01-04 12:57:11 +08:00
efree ( basename ) ;
2007-12-24 05:12:42 +08:00
ctr . line_len = spprintf ( & ( ctr . line ) , 0 , " Content-type: %s " , mime_type ) ;
sapi_header_op ( SAPI_HEADER_REPLACE , & ctr TSRMLS_CC ) ;
efree ( ctr . line ) ;
ctr . line_len = spprintf ( & ( ctr . line ) , 0 , " Content-length: %d " , phar - > internal_file - > uncompressed_filesize ) ;
sapi_header_op ( SAPI_HEADER_REPLACE , & ctr TSRMLS_CC ) ;
efree ( ctr . line ) ;
if ( FAILURE = = sapi_send_headers ( TSRMLS_C ) ) {
phar_entry_delref ( phar TSRMLS_CC ) ;
zend_bailout ( ) ;
}
/* prepare to output */
2008-04-21 14:17:51 +08:00
if ( ! phar_get_efp ( phar - > internal_file , 1 TSRMLS_CC ) ) {
2008-01-01 06:42:40 +08:00
char * error ;
if ( ! phar_open_jit ( phar - > phar , phar - > internal_file , phar - > phar - > fp , & error , 0 TSRMLS_CC ) ) {
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
return - 1 ;
}
2008-04-21 14:17:51 +08:00
phar - > fp = phar_get_efp ( phar - > internal_file , 1 TSRMLS_CC ) ;
2008-01-28 16:52:08 +08:00
phar - > zero = phar - > internal_file - > offset ;
2007-12-24 05:12:42 +08:00
}
2008-04-21 14:17:51 +08:00
phar_seek_efp ( phar - > internal_file , 0 , SEEK_SET , 0 , 1 TSRMLS_CC ) ;
2007-12-24 05:12:42 +08:00
do {
2008-01-28 16:52:08 +08:00
got = php_stream_read ( phar - > fp , buf , MIN ( 8192 , phar - > internal_file - > uncompressed_filesize - phar - > position ) ) ;
PHPWRITE ( buf , got ) ;
phar - > position = php_stream_tell ( phar - > fp ) - phar - > zero ;
if ( phar - > position = = ( off_t ) phar - > internal_file - > uncompressed_filesize ) {
break ;
2007-12-24 05:12:42 +08:00
}
} while ( 1 ) ;
phar_entry_delref ( phar TSRMLS_CC ) ;
2008-01-04 09:45:37 +08:00
zend_bailout ( ) ;
2007-12-24 05:12:42 +08:00
case PHAR_MIME_PHP :
2008-01-04 12:57:11 +08:00
if ( basename ) {
2008-02-08 07:42:03 +08:00
phar_mung_server_vars ( arch , entry , entry_len , basename , basename_len , ru , ru_len TSRMLS_CC ) ;
2008-01-04 12:57:11 +08:00
efree ( basename ) ;
}
2007-12-24 05:12:42 +08:00
phar_entry_delref ( phar TSRMLS_CC ) ;
2007-12-29 10:01:12 +08:00
if ( entry [ 0 ] = = ' / ' ) {
name_len = spprintf ( & name , 4096 , " phar://%s%s " , arch , entry ) ;
} else {
name_len = spprintf ( & name , 4096 , " phar://%s/%s " , arch , entry ) ;
}
2007-12-24 05:12:42 +08:00
ret = php_stream_open_for_zend_ex ( name , & file_handle , ENFORCE_SAFE_MODE | USE_PATH | STREAM_OPEN_FOR_INCLUDE TSRMLS_CC ) ;
if ( ret ! = SUCCESS ) {
efree ( name ) ;
return - 1 ;
}
2008-01-10 23:13:00 +08:00
PHAR_G ( cwd ) = NULL ;
PHAR_G ( cwd_len ) = 0 ;
2007-12-24 05:12:42 +08:00
if ( zend_hash_add ( & EG ( included_files ) , file_handle . opened_path , strlen ( file_handle . opened_path ) + 1 , ( void * ) & dummy , sizeof ( int ) , NULL ) = = SUCCESS ) {
2008-04-23 01:19:06 +08:00
if ( ( cwd = strrchr ( entry , ' / ' ) ) ) {
2008-01-13 06:16:00 +08:00
if ( entry = = cwd ) {
/* root directory */
PHAR_G ( cwd_len ) = 0 ;
PHAR_G ( cwd ) = NULL ;
} else if ( entry [ 0 ] = = ' / ' ) {
2008-01-10 23:13:00 +08:00
PHAR_G ( cwd_len ) = cwd - ( entry + 1 ) ;
PHAR_G ( cwd ) = estrndup ( entry + 1 , PHAR_G ( cwd_len ) ) ;
} else {
PHAR_G ( cwd_len ) = cwd - entry ;
PHAR_G ( cwd ) = estrndup ( entry , PHAR_G ( cwd_len ) ) ;
}
}
2007-12-24 05:12:42 +08:00
new_op_array = zend_compile_file ( & file_handle , ZEND_REQUIRE TSRMLS_CC ) ;
zend_destroy_file_handle ( & file_handle TSRMLS_CC ) ;
} else {
new_op_array = NULL ;
2008-03-17 16:55:56 +08:00
# if PHP_VERSION_ID >= 50300
zend_file_handle_dtor ( & file_handle TSRMLS_CC ) ;
# else
2007-12-24 05:12:42 +08:00
zend_file_handle_dtor ( & file_handle ) ;
2008-03-17 16:55:56 +08:00
# endif
2007-12-24 05:12:42 +08:00
}
2007-12-27 00:59:01 +08:00
# ifdef PHP_WIN32
efree ( arch ) ;
# endif
2007-12-24 05:12:42 +08:00
if ( new_op_array ) {
EG ( return_value_ptr_ptr ) = & result ;
EG ( active_op_array ) = new_op_array ;
2008-01-10 23:13:00 +08:00
zend_try {
zend_execute ( new_op_array TSRMLS_CC ) ;
destroy_op_array ( new_op_array TSRMLS_CC ) ;
efree ( new_op_array ) ;
if ( ! EG ( exception ) ) {
if ( EG ( return_value_ptr_ptr ) ) {
zval_ptr_dtor ( EG ( return_value_ptr_ptr ) ) ;
}
2007-12-24 05:12:42 +08:00
}
2008-01-10 23:13:00 +08:00
} zend_catch {
} zend_end_try ( ) ;
2008-04-23 01:34:00 +08:00
if ( PHAR_G ( cwd ) ) {
efree ( PHAR_G ( cwd ) ) ;
PHAR_G ( cwd ) = NULL ;
PHAR_G ( cwd_len ) = 0 ;
}
efree ( name ) ;
2007-12-24 05:12:42 +08:00
zend_bailout ( ) ;
}
return PHAR_MIME_PHP ;
}
return - 1 ;
}
2008-02-08 17:25:02 +08:00
/* }}} */
2007-12-24 05:12:42 +08:00
2008-02-08 17:25:02 +08:00
static void phar_do_403 ( char * entry , int entry_len TSRMLS_DC ) /* { { { */
2008-02-08 07:42:03 +08:00
{
sapi_header_line ctr = { 0 } ;
ctr . response_code = 403 ;
ctr . line_len = sizeof ( " HTTP/1.0 403 Access Denied " ) ;
ctr . line = " HTTP/1.0 403 Access Denied " ;
sapi_header_op ( SAPI_HEADER_REPLACE , & ctr TSRMLS_CC ) ;
sapi_send_headers ( TSRMLS_C ) ;
PHPWRITE ( " <html> \n <head> \n <title>Access Denied</title> \n </head> \n <body> \n <h1>403 - File " , sizeof ( " <html> \n <head> \n <title>Access Denied</title> \n </head> \n <body> \n <h1>403 - File " ) - 1 ) ;
PHPWRITE ( entry , entry_len ) ;
PHPWRITE ( " Access Denied</h1> \n </body> \n </html> " , sizeof ( " Access Denied</h1> \n </body> \n </html> " ) - 1 ) ;
}
2008-02-08 17:25:02 +08:00
/* }}} */
2008-02-08 07:42:03 +08:00
2008-02-08 17:25:02 +08:00
static void phar_do_404 ( char * fname , int fname_len , char * f404 , int f404_len , char * entry , int entry_len TSRMLS_DC ) /* { { { */
2007-12-29 09:35:46 +08:00
{
int hi ;
phar_entry_data * phar ;
char * error ;
if ( f404_len ) {
2008-01-09 08:58:37 +08:00
if ( FAILURE = = phar_get_entry_data ( & phar , fname , fname_len , f404 , f404_len , " r " , 0 , & error TSRMLS_CC ) ) {
2007-12-29 09:35:46 +08:00
if ( error ) {
efree ( error ) ;
}
goto nofile ;
}
2008-02-08 07:42:03 +08:00
hi = phar_file_action ( phar , " text/html " , PHAR_MIME_PHP , f404 , f404_len , fname , fname_len , NULL , 0 , NULL , 0 TSRMLS_CC ) ;
2007-12-29 09:35:46 +08:00
} else {
sapi_header_line ctr = { 0 } ;
nofile :
ctr . response_code = 404 ;
ctr . line_len = sizeof ( " HTTP/1.0 404 Not Found " ) + 1 ;
ctr . line = " HTTP/1.0 404 Not Found " ;
sapi_header_op ( SAPI_HEADER_REPLACE , & ctr TSRMLS_CC ) ;
sapi_send_headers ( TSRMLS_C ) ;
2008-02-08 07:42:03 +08:00
PHPWRITE ( " <html> \n <head> \n <title>File Not Found</title> \n </head> \n <body> \n <h1>404 - File " , sizeof ( " <html> \n <head> \n <title>File Not Found</title> \n </head> \n <body> \n <h1>404 - File " ) - 1 ) ;
2008-01-05 12:03:33 +08:00
PHPWRITE ( entry , entry_len ) ;
PHPWRITE ( " Not Found</h1> \n </body> \n </html> " , sizeof ( " Not Found</h1> \n </body> \n </html> " ) - 1 ) ;
2007-12-29 09:35:46 +08:00
}
}
2008-02-08 17:25:02 +08:00
/* }}} */
2007-12-29 09:35:46 +08:00
2008-04-24 00:00:06 +08:00
/* post-process REQUEST_URI and retrieve the actual request URI. This is for
cases like http : //localhost/blah.phar/path/to/file.php/extra/stuff
which calls " blah.phar " file " path/to/file.php " with PATH_INFO " /extra/stuff " */
2008-02-08 17:25:02 +08:00
static void phar_postprocess_ru_web ( char * fname , int fname_len , char * * entry , int * entry_len , char * * ru , int * ru_len TSRMLS_DC ) /* { { { */
2008-02-08 07:42:03 +08:00
{
2008-04-22 01:59:28 +08:00
char * e = * entry + 1 , * u = NULL , * u1 = NULL , * saveu = NULL ;
2008-02-08 07:42:03 +08:00
int e_len = * entry_len - 1 , u_len = 0 ;
phar_archive_data * * pphar ;
/* we already know we can retrieve the phar if we reach here */
zend_hash_find ( & ( PHAR_GLOBALS - > phar_fname_map ) , fname , fname_len , ( void * * ) & pphar ) ;
do {
if ( zend_hash_exists ( & ( ( * pphar ) - > manifest ) , e , e_len ) ) {
if ( u ) {
u [ 0 ] = ' / ' ;
* ru = estrndup ( u , u_len + 1 ) ;
2008-03-23 06:11:49 +08:00
+ + u_len ;
2008-02-08 07:42:03 +08:00
u [ 0 ] = ' \0 ' ;
} else {
* ru = NULL ;
}
* ru_len = u_len ;
* entry_len = e_len + 1 ;
return ;
}
if ( u ) {
2008-04-22 01:59:28 +08:00
u1 = strrchr ( e , ' / ' ) ;
2008-02-08 07:42:03 +08:00
u [ 0 ] = ' / ' ;
saveu = u ;
2008-04-22 01:59:28 +08:00
e_len + = u_len + 1 ;
u = u1 ;
if ( ! u ) {
return ;
}
} else {
u = strrchr ( e , ' / ' ) ;
if ( ! u ) {
if ( saveu ) {
saveu [ 0 ] = ' / ' ;
}
return ;
2008-02-08 07:42:03 +08:00
}
}
u [ 0 ] = ' \0 ' ;
u_len = strlen ( u + 1 ) ;
e_len - = u_len + 1 ;
2008-04-22 01:46:24 +08:00
if ( e_len < 0 ) {
if ( saveu ) {
saveu [ 0 ] = ' / ' ;
}
return ;
}
2008-02-08 07:42:03 +08:00
} while ( 1 ) ;
}
2008-02-08 17:25:02 +08:00
/* }}} */
2008-02-08 07:42:03 +08:00
2008-03-23 14:00:31 +08:00
/* {{{ proto void Phar::running([bool retphar = true])
* return the name of the currently running phar archive . If the optional parameter
* is set to true , return the phar : // URL to the currently running phar
2008-02-25 12:23:36 +08:00
*/
2008-03-23 14:00:31 +08:00
PHP_METHOD ( Phar , running )
2008-02-25 12:23:36 +08:00
{
char * fname , * arch , * entry ;
int fname_len , arch_len , entry_len ;
2008-03-23 14:00:31 +08:00
zend_bool retphar = 1 ;
2008-03-24 01:36:57 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |b " , & retphar ) = = FAILURE ) {
2008-03-23 14:00:31 +08:00
return ;
}
2008-02-25 12:23:36 +08:00
fname = zend_get_executed_filename ( TSRMLS_C ) ;
fname_len = strlen ( fname ) ;
2008-04-22 02:06:20 +08:00
if ( fname_len > 7 & & ! memcmp ( fname , " phar:// " , 7 ) & & SUCCESS = = phar_split_fname ( fname , fname_len , & arch , & arch_len , & entry , & entry_len , 2 , 0 TSRMLS_CC ) ) {
2008-02-25 12:23:36 +08:00
efree ( entry ) ;
2008-03-23 14:00:31 +08:00
if ( retphar ) {
RETVAL_STRINGL ( fname , arch_len + 7 , 1 ) ;
efree ( arch ) ;
return ;
} else {
RETURN_STRINGL ( arch , arch_len , 0 ) ;
}
2008-02-25 12:23:36 +08:00
}
2008-04-22 02:06:20 +08:00
RETURN_STRINGL ( " " , 0 , 1 ) ;
2008-02-25 12:23:36 +08:00
}
/* }}} */
2008-02-18 12:32:50 +08:00
/* {{{ proto void Phar::mount(string pharpath, string externalfile)
* mount an external file or path to a location within the phar . This maps
* an external file or directory to a location within the phar archive , allowing
* reference to an external location as if it were within the phar archive . This
* is useful for writable temp files like databases
*/
PHP_METHOD ( Phar , mount )
{
char * fname , * arch , * entry , * path , * actual ;
int fname_len , arch_len , entry_len , path_len , actual_len ;
2008-02-25 12:23:36 +08:00
phar_archive_data * * pphar ;
2008-02-18 12:32:50 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " ss " , & path , & path_len , & actual , & actual_len ) = = FAILURE ) {
return ;
}
fname = zend_get_executed_filename ( TSRMLS_C ) ;
fname_len = strlen ( fname ) ;
2008-04-22 02:21:54 +08:00
if ( fname_len > 7 & & ! memcmp ( fname , " phar:// " , 7 ) & & SUCCESS = = phar_split_fname ( fname , fname_len , & arch , & arch_len , & entry , & entry_len , 2 , 0 TSRMLS_CC ) ) {
2008-02-25 12:23:36 +08:00
efree ( entry ) ;
2008-04-22 02:21:54 +08:00
entry = NULL ;
if ( path_len > 7 & & ! memcmp ( path , " phar:// " , 7 ) ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " Can only mount internal paths within a phar archive, use a relative path instead of \" %s \" " , path ) ;
efree ( arch ) ;
return ;
}
carry_on2 :
2008-02-18 12:32:50 +08:00
if ( SUCCESS ! = zend_hash_find ( & ( PHAR_GLOBALS - > phar_fname_map ) , arch , arch_len , ( void * * ) & pphar ) ) {
2008-02-25 12:23:36 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " %s is not a phar archive, cannot mount " , arch ) ;
efree ( arch ) ;
2008-02-18 12:32:50 +08:00
return ;
}
2008-02-25 12:23:36 +08:00
carry_on :
2008-02-18 12:32:50 +08:00
if ( SUCCESS ! = phar_mount_entry ( * pphar , actual , actual_len , path , path_len TSRMLS_CC ) ) {
2008-04-22 02:21:54 +08:00
if ( path & & path = = entry ) {
efree ( entry ) ;
}
2008-02-25 12:23:36 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " Mounting of %s to %s within phar %s failed " , path , actual , arch ) ;
2008-02-18 12:32:50 +08:00
}
2008-04-22 02:21:54 +08:00
if ( path & & path = = entry ) {
efree ( entry ) ;
}
2008-02-25 12:23:36 +08:00
efree ( arch ) ;
return ;
} else if ( SUCCESS = = zend_hash_find ( & ( PHAR_GLOBALS - > phar_fname_map ) , fname , fname_len , ( void * * ) & pphar ) ) {
goto carry_on ;
2008-04-22 02:21:54 +08:00
} else if ( SUCCESS = = phar_split_fname ( path , path_len , & arch , & arch_len , & entry , & entry_len , 2 , 0 TSRMLS_CC ) ) {
path = entry ;
path_len = entry_len ;
goto carry_on2 ;
2008-02-18 12:32:50 +08:00
}
}
/* }}} */
2008-02-08 07:42:03 +08:00
/* {{{ proto void Phar::webPhar([string alias, [string index, [string f404, [array mimetypes, [callback rewrites]]]]])
2007-12-24 05:12:42 +08:00
* mapPhar for web - based phars . Reads the currently executed file ( a phar )
2007-12-25 04:30:44 +08:00
* and registers its manifest . When executed in the CLI or CGI command - line sapi ,
* this works exactly like mapPhar ( ) . When executed by a web - based sapi , this
* reads $ _SERVER [ ' REQUEST_URI ' ] ( the actual original value ) and parses out the
* intended internal file .
2007-12-24 05:12:42 +08:00
*/
PHP_METHOD ( Phar , webPhar )
{
HashTable mimetypes ;
phar_mime_type mime ;
2008-02-08 07:42:03 +08:00
zval * mimeoverride = NULL , * rewrite = NULL ;
char * alias = NULL , * error , * plain_map , * index_php , * f404 = NULL , * ru = NULL ;
int alias_len = 0 , ret , f404_len = 0 , free_pathinfo = 0 , ru_len = 0 ;
2008-01-04 12:57:11 +08:00
char * fname , * basename , * path_info , * mime_type , * entry , * pt ;
2008-02-08 08:58:39 +08:00
int fname_len , entry_len , code , index_php_len = 0 , not_cgi ;
2007-12-24 05:12:42 +08:00
phar_entry_data * phar ;
2008-02-08 07:42:03 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |s!s!saz " , & alias , & alias_len , & index_php , & index_php_len , & f404 , & f404_len , & mimeoverride , & rewrite ) = = FAILURE ) {
2007-12-24 05:12:42 +08:00
return ;
}
phar_request_initialize ( TSRMLS_C ) ;
2008-02-11 14:49:22 +08:00
fname = zend_get_executed_filename ( TSRMLS_C ) ;
fname_len = strlen ( fname ) ;
2008-01-05 12:03:33 +08:00
if ( zend_hash_num_elements ( & ( PHAR_GLOBALS - > phar_plain_map ) ) ) {
if ( ( alias & &
zend_hash_find ( & ( PHAR_GLOBALS - > phar_plain_map ) , alias , alias_len + 1 , ( void * * ) & plain_map ) = = SUCCESS )
| | ( zend_hash_find ( & ( PHAR_GLOBALS - > phar_plain_map ) , fname , fname_len + 1 , ( void * * ) & plain_map ) = = SUCCESS )
) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " Cannot use Phar::webPhar() from an extracted phar archive, simply use the extracted files directly " ) ;
return ;
}
}
2007-12-24 05:12:42 +08:00
if ( phar_open_compiled_file ( alias , alias_len , & error TSRMLS_CC ) ! = SUCCESS ) {
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
return ;
}
/* retrieve requested file within phar */
if ( ! ( SG ( request_info ) . request_method & & SG ( request_info ) . request_uri & & ( ! strcmp ( SG ( request_info ) . request_method , " GET " ) | | ! strcmp ( SG ( request_info ) . request_method , " POST " ) ) ) ) {
return ;
}
2007-12-27 00:59:01 +08:00
# ifdef PHP_WIN32
fname = estrndup ( fname , fname_len ) ;
phar_unixify_path_separators ( fname , fname_len ) ;
# endif
basename = strrchr ( fname , ' / ' ) ;
2007-12-24 05:12:42 +08:00
if ( ! basename ) {
basename = fname ;
} else {
2008-03-23 06:11:49 +08:00
+ + basename ;
2007-12-24 05:12:42 +08:00
}
2008-01-04 12:57:11 +08:00
2008-03-23 06:04:21 +08:00
if ( ( strlen ( sapi_module . name ) = = sizeof ( " cgi-fcgi " ) - 1 & & ! strncmp ( sapi_module . name , " cgi-fcgi " , sizeof ( " cgi-fcgi " ) - 1 ) )
| | ( strlen ( sapi_module . name ) = = sizeof ( " cgi " ) - 1 & & ! strncmp ( sapi_module . name , " cgi " , sizeof ( " cgi " ) - 1 ) ) ) {
2008-02-07 12:24:58 +08:00
char * testit ;
testit = sapi_getenv ( " SCRIPT_NAME " , sizeof ( " SCRIPT_NAME " ) - 1 TSRMLS_CC ) ;
if ( ! ( pt = strstr ( testit , basename ) ) ) {
return ;
}
path_info = sapi_getenv ( " PATH_INFO " , sizeof ( " PATH_INFO " ) - 1 TSRMLS_CC ) ;
if ( path_info ) {
entry = estrdup ( path_info ) ;
entry_len = strlen ( entry ) ;
spprintf ( & path_info , 0 , " %s%s " , testit , path_info ) ;
free_pathinfo = 1 ;
} else {
path_info = testit ;
entry = estrndup ( " " , 0 ) ;
entry_len = 0 ;
}
pt = estrndup ( testit , ( pt - testit ) + ( fname_len - ( basename - fname ) ) ) ;
2008-02-08 09:08:02 +08:00
not_cgi = 0 ;
2008-02-07 12:24:58 +08:00
} else {
path_info = SG ( request_info ) . request_uri ;
2008-02-08 07:42:03 +08:00
if ( ! ( pt = strstr ( path_info , basename ) ) ) {
/* this can happen with rewrite rules - and we have no idea what to do then, so return */
return ;
}
entry_len = strlen ( path_info ) ;
entry_len - = ( pt - path_info ) + ( fname_len - ( basename - fname ) ) ;
entry = estrndup ( pt + ( fname_len - ( basename - fname ) ) , entry_len ) ;
pt = estrndup ( path_info , ( pt - path_info ) + ( fname_len - ( basename - fname ) ) ) ;
2008-02-08 09:08:02 +08:00
not_cgi = 1 ;
2008-01-04 12:57:11 +08:00
}
2008-02-08 07:42:03 +08:00
if ( rewrite ) {
zend_fcall_info fci ;
zend_fcall_info_cache fcc ;
zval * params , * retval_ptr , * * zp [ 1 ] ;
MAKE_STD_ZVAL ( params ) ;
ZVAL_STRINGL ( params , entry , entry_len , 1 ) ;
zp [ 0 ] = & params ;
2008-02-08 17:25:02 +08:00
# if PHP_VERSION_ID < 50300
2008-02-11 12:48:58 +08:00
if ( FAILURE = = zend_fcall_info_init ( rewrite , & fci , & fcc TSRMLS_CC ) ) {
2008-02-08 17:25:02 +08:00
# else
2008-02-08 17:21:24 +08:00
if ( FAILURE = = zend_fcall_info_init ( rewrite , 0 , & fci , & fcc , NULL , NULL TSRMLS_CC ) ) {
2008-02-08 17:25:02 +08:00
# endif
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " phar error: invalid rewrite callback " ) ;
2008-02-08 07:42:03 +08:00
if ( free_pathinfo ) {
efree ( path_info ) ;
}
return ;
}
fci . param_count = 1 ;
fci . params = zp ;
# if PHP_VERSION_ID < 50300
2008-03-23 06:11:49 +08:00
+ + ( params - > refcount ) ;
2008-02-08 07:42:03 +08:00
# else
Z_ADDREF_P ( params ) ;
# endif
fci . retval_ptr_ptr = & retval_ptr ;
2008-01-04 12:57:11 +08:00
2008-02-08 07:42:03 +08:00
if ( FAILURE = = zend_call_function ( & fci , & fcc TSRMLS_CC ) ) {
if ( ! EG ( exception ) ) {
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " phar error: failed to call rewrite callback " ) ;
2008-02-08 07:42:03 +08:00
}
if ( free_pathinfo ) {
efree ( path_info ) ;
}
return ;
}
2008-04-24 01:18:28 +08:00
if ( ! fci . retval_ptr_ptr | | ! retval_ptr ) {
2008-02-08 07:42:03 +08:00
if ( free_pathinfo ) {
efree ( path_info ) ;
}
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " phar error: rewrite callback must return a string or false " ) ;
2008-02-08 07:42:03 +08:00
return ;
}
switch ( Z_TYPE_P ( retval_ptr ) ) {
case IS_STRING :
efree ( entry ) ;
2008-04-24 01:18:28 +08:00
if ( fci . retval_ptr_ptr ! = & retval_ptr ) {
entry = estrndup ( Z_STRVAL_PP ( fci . retval_ptr_ptr ) , Z_STRLEN_PP ( fci . retval_ptr_ptr ) ) ;
entry_len = Z_STRLEN_PP ( fci . retval_ptr_ptr ) ;
} else {
entry = Z_STRVAL_P ( retval_ptr ) ;
entry_len = Z_STRLEN_P ( retval_ptr ) ;
}
2008-02-08 07:42:03 +08:00
break ;
case IS_BOOL :
phar_do_403 ( entry , entry_len TSRMLS_CC ) ;
if ( free_pathinfo ) {
efree ( path_info ) ;
}
zend_bailout ( ) ;
return ;
default :
efree ( retval_ptr ) ;
if ( free_pathinfo ) {
efree ( path_info ) ;
}
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " phar error: rewrite callback must return a string or false " ) ;
2008-02-08 07:42:03 +08:00
return ;
}
}
2008-02-07 12:24:58 +08:00
2008-02-08 07:42:03 +08:00
if ( entry_len ) {
phar_postprocess_ru_web ( fname , fname_len , & entry , & entry_len , & ru , & ru_len TSRMLS_CC ) ;
}
2008-01-04 12:57:11 +08:00
if ( ! entry_len | | ( entry_len = = 1 & & entry [ 0 ] = = ' / ' ) ) {
efree ( entry ) ;
/* direct request */
if ( index_php_len ) {
entry = index_php ;
entry_len = index_php_len ;
2008-02-02 13:20:37 +08:00
if ( entry [ 0 ] ! = ' / ' ) {
spprintf ( & entry , 0 , " /%s " , index_php ) ;
2008-03-23 06:11:49 +08:00
+ + entry_len ;
2008-02-02 13:20:37 +08:00
}
2008-01-04 12:57:11 +08:00
} else {
/* assume "index.php" is starting point */
entry = estrndup ( " /index.php " , sizeof ( " /index.php " ) ) ;
entry_len = sizeof ( " /index.php " ) - 1 ;
}
2008-04-24 01:23:32 +08:00
if ( FAILURE = = phar_get_entry_data ( & phar , fname , fname_len , entry , entry_len , " r " , 0 , NULL TSRMLS_CC ) ) {
2008-01-05 12:03:33 +08:00
phar_do_404 ( fname , fname_len , f404 , f404_len , entry , entry_len TSRMLS_CC ) ;
2008-02-07 12:24:58 +08:00
if ( free_pathinfo ) {
efree ( path_info ) ;
}
2008-01-04 12:57:11 +08:00
zend_bailout ( ) ;
} else {
2008-02-02 13:20:37 +08:00
char * tmp , sa ;
2008-01-04 12:57:11 +08:00
sapi_header_line ctr = { 0 } ;
ctr . response_code = 301 ;
ctr . line_len = sizeof ( " HTTP/1.1 301 Moved Permanently " ) + 1 ;
ctr . line = " HTTP/1.1 301 Moved Permanently " ;
sapi_header_op ( SAPI_HEADER_REPLACE , & ctr TSRMLS_CC ) ;
2008-02-08 08:58:39 +08:00
if ( not_cgi ) {
tmp = strstr ( path_info , basename ) + fname_len ;
2008-02-08 08:55:38 +08:00
sa = * tmp ;
* tmp = ' \0 ' ;
}
2008-01-04 12:57:11 +08:00
ctr . response_code = 0 ;
2008-02-02 13:20:37 +08:00
if ( path_info [ strlen ( path_info ) - 1 ] = = ' / ' ) {
ctr . line_len = spprintf ( & ( ctr . line ) , 4096 , " Location: %s%s " , path_info , entry + 1 ) ;
2008-01-05 11:49:01 +08:00
} else {
2008-02-02 13:20:37 +08:00
ctr . line_len = spprintf ( & ( ctr . line ) , 4096 , " Location: %s%s " , path_info , entry ) ;
2008-01-05 11:49:01 +08:00
}
2008-02-08 08:58:39 +08:00
if ( not_cgi ) {
2008-02-08 08:55:38 +08:00
* tmp = sa ;
}
2008-02-07 12:24:58 +08:00
if ( free_pathinfo ) {
efree ( path_info ) ;
}
2008-01-04 12:57:11 +08:00
sapi_header_op ( SAPI_HEADER_REPLACE , & ctr TSRMLS_CC ) ;
sapi_send_headers ( TSRMLS_C ) ;
phar_entry_delref ( phar TSRMLS_CC ) ;
efree ( ctr . line ) ;
zend_bailout ( ) ;
2007-12-25 04:30:44 +08:00
}
2007-12-24 05:12:42 +08:00
}
2008-01-09 08:58:37 +08:00
if ( FAILURE = = phar_get_entry_data ( & phar , fname , fname_len , entry , entry_len , " r " , 0 , & error TSRMLS_CC ) ) {
2008-01-05 12:03:33 +08:00
phar_do_404 ( fname , fname_len , f404 , f404_len , entry , entry_len TSRMLS_CC ) ;
2007-12-29 09:35:46 +08:00
# ifdef PHP_WIN32
efree ( fname ) ;
# endif
zend_bailout ( ) ;
}
2007-12-24 05:12:42 +08:00
/* set up mime types */
zend_hash_init ( & mimetypes , sizeof ( phar_mime_type * ) , zend_get_hash_value , NULL , 0 ) ;
2008-01-11 15:39:02 +08:00
# define PHAR_SET_MIME(mimetype, ret, fileext) \
2007-12-24 05:12:42 +08:00
mime . mime = mimetype ; \
mime . len = sizeof ( ( mimetype ) ) + 1 ; \
mime . type = ret ; \
2008-01-11 15:39:02 +08:00
zend_hash_add ( & mimetypes , fileext , sizeof ( fileext ) - 1 , ( void * ) & mime , sizeof ( phar_mime_type ) , NULL ) ; \
2007-12-24 05:12:42 +08:00
PHAR_SET_MIME ( " text/html " , PHAR_MIME_PHPS , " phps " )
2008-01-11 15:39:02 +08:00
PHAR_SET_MIME ( " text/plain " , PHAR_MIME_OTHER , " c " )
PHAR_SET_MIME ( " text/plain " , PHAR_MIME_OTHER , " cc " )
PHAR_SET_MIME ( " text/plain " , PHAR_MIME_OTHER , " cpp " )
PHAR_SET_MIME ( " text/plain " , PHAR_MIME_OTHER , " c++ " )
PHAR_SET_MIME ( " text/plain " , PHAR_MIME_OTHER , " dtd " )
PHAR_SET_MIME ( " text/plain " , PHAR_MIME_OTHER , " h " )
PHAR_SET_MIME ( " text/plain " , PHAR_MIME_OTHER , " log " )
PHAR_SET_MIME ( " text/plain " , PHAR_MIME_OTHER , " rng " )
PHAR_SET_MIME ( " text/plain " , PHAR_MIME_OTHER , " txt " )
PHAR_SET_MIME ( " text/plain " , PHAR_MIME_OTHER , " xsd " )
PHAR_SET_MIME ( " " , PHAR_MIME_PHP , " php " )
PHAR_SET_MIME ( " " , PHAR_MIME_PHP , " inc " )
2007-12-24 05:12:42 +08:00
PHAR_SET_MIME ( " video/avi " , PHAR_MIME_OTHER , " avi " )
PHAR_SET_MIME ( " image/bmp " , PHAR_MIME_OTHER , " bmp " )
PHAR_SET_MIME ( " text/css " , PHAR_MIME_OTHER , " css " )
PHAR_SET_MIME ( " image/gif " , PHAR_MIME_OTHER , " gif " )
2008-01-11 15:39:02 +08:00
PHAR_SET_MIME ( " text/html " , PHAR_MIME_OTHER , " htm " )
PHAR_SET_MIME ( " text/html " , PHAR_MIME_OTHER , " html " )
PHAR_SET_MIME ( " text/html " , PHAR_MIME_OTHER , " htmls " )
2007-12-24 05:12:42 +08:00
PHAR_SET_MIME ( " image/x-ico " , PHAR_MIME_OTHER , " ico " )
2008-01-11 15:39:02 +08:00
PHAR_SET_MIME ( " image/jpeg " , PHAR_MIME_OTHER , " jpe " )
PHAR_SET_MIME ( " image/jpeg " , PHAR_MIME_OTHER , " jpg " )
PHAR_SET_MIME ( " image/jpeg " , PHAR_MIME_OTHER , " jpeg " )
2007-12-24 05:12:42 +08:00
PHAR_SET_MIME ( " application/x-javascript " , PHAR_MIME_OTHER , " js " )
2008-01-11 15:39:02 +08:00
PHAR_SET_MIME ( " audio/midi " , PHAR_MIME_OTHER , " midi " )
2008-01-20 08:49:45 +08:00
PHAR_SET_MIME ( " audio/midi " , PHAR_MIME_OTHER , " mid " )
2007-12-24 05:12:42 +08:00
PHAR_SET_MIME ( " audio/mod " , PHAR_MIME_OTHER , " mod " )
PHAR_SET_MIME ( " movie/quicktime " , PHAR_MIME_OTHER , " mov " )
PHAR_SET_MIME ( " audio/mp3 " , PHAR_MIME_OTHER , " mp3 " )
2008-01-11 15:39:02 +08:00
PHAR_SET_MIME ( " video/mpeg " , PHAR_MIME_OTHER , " mpg " )
PHAR_SET_MIME ( " video/mpeg " , PHAR_MIME_OTHER , " mpeg " )
2007-12-24 05:12:42 +08:00
PHAR_SET_MIME ( " application/pdf " , PHAR_MIME_OTHER , " pdf " )
PHAR_SET_MIME ( " image/png " , PHAR_MIME_OTHER , " png " )
PHAR_SET_MIME ( " application/shockwave-flash " , PHAR_MIME_OTHER , " swf " )
2008-01-11 15:39:02 +08:00
PHAR_SET_MIME ( " image/tiff " , PHAR_MIME_OTHER , " tif " )
PHAR_SET_MIME ( " image/tiff " , PHAR_MIME_OTHER , " tiff " )
2007-12-24 05:12:42 +08:00
PHAR_SET_MIME ( " audio/wav " , PHAR_MIME_OTHER , " wav " )
PHAR_SET_MIME ( " image/xbm " , PHAR_MIME_OTHER , " xbm " )
PHAR_SET_MIME ( " text/xml " , PHAR_MIME_OTHER , " xml " )
/* set up user overrides */
# define PHAR_SET_USER_MIME(ret) \
2008-01-05 14:14:43 +08:00
if ( Z_TYPE_PP ( val ) = = IS_LONG ) { \
mime . mime = " " ; \
mime . len = 0 ; \
} else { \
mime . mime = Z_STRVAL_PP ( val ) ; \
mime . len = Z_STRLEN_PP ( val ) ; \
} \
2007-12-24 05:12:42 +08:00
mime . type = ret ; \
2008-01-05 14:14:43 +08:00
zend_hash_update ( & mimetypes , key , keylen - 1 , ( void * ) & mime , sizeof ( phar_mime_type ) , NULL ) ;
2007-12-24 05:12:42 +08:00
if ( mimeoverride ) {
2007-12-29 10:38:29 +08:00
if ( ! zend_hash_num_elements ( Z_ARRVAL_P ( mimeoverride ) ) ) {
goto no_mimes ;
}
2008-01-04 12:57:11 +08:00
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 ) ) ) {
2008-01-05 14:14:43 +08:00
zval * * val ;
2007-12-24 05:12:42 +08:00
char * 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 ) ) {
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " Key of MIME type overrides array must be a file extension, was \" %d \" " , intkey ) ;
2008-01-05 13:47:47 +08:00
phar_entry_delref ( phar TSRMLS_CC ) ;
2007-12-27 00:59:01 +08:00
# ifdef PHP_WIN32
efree ( fname ) ;
# endif
2007-12-24 05:12:42 +08:00
RETURN_FALSE ;
}
if ( FAILURE = = zend_hash_get_current_data ( Z_ARRVAL_P ( mimeoverride ) , ( void * * ) & val ) ) {
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " Failed to retrieve Mime type for extension \" %s \" " , key ) ;
2008-01-05 13:47:47 +08:00
phar_entry_delref ( phar TSRMLS_CC ) ;
2007-12-27 00:59:01 +08:00
# ifdef PHP_WIN32
efree ( fname ) ;
# endif
2007-12-24 05:12:42 +08:00
RETURN_FALSE ;
}
2008-01-05 14:14:43 +08:00
switch ( Z_TYPE_PP ( val ) ) {
2007-12-24 05:12:42 +08:00
case IS_LONG :
2008-01-05 14:14:43 +08:00
if ( Z_LVAL_PP ( val ) = = PHAR_MIME_PHP | | Z_LVAL_PP ( val ) = = PHAR_MIME_PHPS ) {
2008-01-12 12:32:19 +08:00
PHAR_SET_USER_MIME ( ( char ) Z_LVAL_PP ( val ) )
2007-12-24 05:12:42 +08:00
} else {
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed " ) ;
2008-01-05 13:47:47 +08:00
phar_entry_delref ( phar TSRMLS_CC ) ;
# ifdef PHP_WIN32
efree ( fname ) ;
# endif
2007-12-24 05:12:42 +08:00
RETURN_FALSE ;
}
break ;
case IS_STRING :
PHAR_SET_USER_MIME ( PHAR_MIME_OTHER )
break ;
default :
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed " ) ;
2008-01-05 13:47:47 +08:00
phar_entry_delref ( phar TSRMLS_CC ) ;
# ifdef PHP_WIN32
efree ( fname ) ;
# endif
2007-12-24 05:12:42 +08:00
RETURN_FALSE ;
}
}
}
2007-12-29 10:38:29 +08:00
no_mimes :
2007-12-24 05:12:42 +08:00
code = phar_file_type ( & mimetypes , entry , & mime_type TSRMLS_CC ) ;
zend_hash_destroy ( & mimetypes ) ;
2008-04-24 01:23:32 +08:00
ret = phar_file_action ( phar , mime_type , code , entry , entry_len , fname , fname_len , pt , strlen ( pt ) , ru , ru_len TSRMLS_CC ) ;
2007-12-24 05:12:42 +08:00
}
2008-02-08 17:25:02 +08:00
/* }}} */
2007-12-24 05:12:42 +08:00
2008-01-04 12:57:11 +08:00
/* {{{ proto void Phar::mungServer(array munglist)
* Defines a list of up to 4 $ _SERVER variables that should be modified for execution
* to mask the presence of the phar archive . This should be used in conjunction with
* Phar : : webPhar ( ) , and has no effect otherwise
* SCRIPT_NAME , PHP_SELF , REQUEST_URI and SCRIPT_FILENAME
*/
PHP_METHOD ( Phar , mungServer )
{
zval * mungvalues ;
int php_self = 0 , request_uri = 0 , script_name = 0 , script_filename = 0 ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " a " , & mungvalues ) = = FAILURE ) {
return ;
}
if ( ! zend_hash_num_elements ( Z_ARRVAL_P ( mungvalues ) ) ) {
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " No values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME " ) ;
2008-01-04 12:57:11 +08:00
return ;
}
if ( zend_hash_num_elements ( Z_ARRVAL_P ( mungvalues ) ) > 4 ) {
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " Too many values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME " ) ;
2008-01-04 12:57:11 +08:00
return ;
}
2008-01-06 06:02:33 +08:00
phar_request_initialize ( TSRMLS_C ) ;
2008-01-04 12:57:11 +08:00
for ( zend_hash_internal_pointer_reset ( Z_ARRVAL_P ( mungvalues ) ) ; SUCCESS = = zend_hash_has_more_elements ( Z_ARRVAL_P ( mungvalues ) ) ; zend_hash_move_forward ( Z_ARRVAL_P ( mungvalues ) ) ) {
2008-01-13 06:21:50 +08:00
zval * * data = NULL ;
2008-01-04 12:57:11 +08:00
2008-01-13 06:21:50 +08:00
if ( SUCCESS ! = zend_hash_get_current_data ( Z_ARRVAL_P ( mungvalues ) , ( void * * ) & data ) ) {
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " unable to retrieve array value in Phar::mungServer() " ) ;
2008-01-04 12:57:11 +08:00
return ;
}
2008-01-13 06:21:50 +08:00
if ( Z_TYPE_PP ( data ) ! = IS_STRING ) {
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " Non-string value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME " ) ;
2008-01-04 12:57:11 +08:00
return ;
}
2008-01-13 06:21:50 +08:00
if ( ! php_self & & Z_STRLEN_PP ( data ) = = sizeof ( " PHP_SELF " ) - 1 & & ! strncmp ( Z_STRVAL_PP ( data ) , " PHP_SELF " , sizeof ( " PHP_SELF " ) - 1 ) ) {
2008-01-04 12:57:11 +08:00
if ( SUCCESS ! = zend_hash_add_empty_element ( & ( PHAR_GLOBALS - > phar_SERVER_mung_list ) , " PHP_SELF " , sizeof ( " PHP_SELF " ) - 1 ) ) {
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " Unable to add PHP_SELF to Phar::mungServer() list of values to mung " ) ;
2008-01-04 12:57:11 +08:00
return ;
}
php_self = 1 ;
}
2008-01-13 06:21:50 +08:00
if ( Z_STRLEN_PP ( data ) = = sizeof ( " REQUEST_URI " ) - 1 ) {
if ( ! request_uri & & ! strncmp ( Z_STRVAL_PP ( data ) , " REQUEST_URI " , sizeof ( " REQUEST_URI " ) - 1 ) ) {
2008-01-04 12:57:11 +08:00
if ( SUCCESS ! = zend_hash_add_empty_element ( & ( PHAR_GLOBALS - > phar_SERVER_mung_list ) , " REQUEST_URI " , sizeof ( " REQUEST_URI " ) - 1 ) ) {
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " Unable to add REQUEST_URI to Phar::mungServer() list of values to mung " ) ;
2008-01-04 12:57:11 +08:00
return ;
}
request_uri = 1 ;
}
2008-01-13 06:21:50 +08:00
if ( ! script_name & & ! strncmp ( Z_STRVAL_PP ( data ) , " SCRIPT_NAME " , sizeof ( " SCRIPT_NAME " ) - 1 ) ) {
2008-01-04 12:57:11 +08:00
if ( SUCCESS ! = zend_hash_add_empty_element ( & ( PHAR_GLOBALS - > phar_SERVER_mung_list ) , " SCRIPT_NAME " , sizeof ( " SCRIPT_NAME " ) - 1 ) ) {
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " Unable to add SCRIPT_NAME to Phar::mungServer() list of values to mung " ) ;
2008-01-04 12:57:11 +08:00
return ;
}
script_name = 1 ;
}
}
2008-01-13 06:21:50 +08:00
if ( ! script_filename & & Z_STRLEN_PP ( data ) = = sizeof ( " SCRIPT_FILENAME " ) - 1 & & ! strncmp ( Z_STRVAL_PP ( data ) , " SCRIPT_FILENAME " , sizeof ( " SCRIPT_FILENAME " ) - 1 ) ) {
2008-01-04 12:57:11 +08:00
if ( SUCCESS ! = zend_hash_add_empty_element ( & ( PHAR_GLOBALS - > phar_SERVER_mung_list ) , " SCRIPT_FILENAME " , sizeof ( " SCRIPT_FILENAME " ) - 1 ) ) {
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " Unable to add SCRIPT_FILENAME to Phar::mungServer() list of values to mung " ) ;
2008-01-04 12:57:11 +08:00
return ;
}
script_filename = 1 ;
}
}
}
/* }}} */
2008-01-11 15:30:03 +08:00
/* {{{ proto void Phar::interceptFileFuncs()
* instructs phar to intercept fopen , file_get_contents , opendir , and all of the stat - related functions
* and return stat on files within the phar for relative paths
*
* Once called , this cannot be reversed , and continue until the end of the request .
*
* This allows legacy scripts to be pharred unmodified
*/
PHP_METHOD ( Phar , interceptFileFuncs )
{
phar_intercept_functions ( TSRMLS_C ) ;
}
/* }}} */
2008-02-08 17:25:02 +08:00
/* {{{ proto array Phar::createDefaultStub([string indexfile[, string webindexfile]])
2008-01-19 12:26:22 +08:00
* Return a stub that can be used to run a phar - based archive without the phar extension
2008-01-20 08:49:45 +08:00
* indexfile is the CLI startup filename , which defaults to " index.php " , webindexfile
* is the web startup filename , and also defaults to " index.php "
2008-01-19 12:26:22 +08:00
*/
PHP_METHOD ( Phar , createDefaultStub )
{
2008-02-19 05:45:02 +08:00
char * index = NULL , * webindex = NULL , * stub , * error ;
2008-01-20 08:49:45 +08:00
int index_len , webindex_len ;
2008-01-19 12:26:22 +08:00
size_t stub_len ;
2008-02-19 05:45:02 +08:00
2008-01-20 08:49:45 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |ss " , & index , & index_len , & webindex , & webindex_len ) = = FAILURE ) {
2008-01-19 12:26:22 +08:00
return ;
}
2008-02-19 05:45:02 +08:00
stub = phar_create_default_stub ( index , webindex , & stub_len , & error TSRMLS_CC ) ;
2008-01-19 12:26:22 +08:00
if ( error ) {
2008-04-13 05:43:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
2008-01-19 12:26:22 +08:00
efree ( error ) ;
return ;
}
2008-02-19 05:45:02 +08:00
RETURN_STRINGL ( stub , stub_len , 0 ) ;
2008-01-19 12:26:22 +08:00
}
2008-02-08 17:25:02 +08:00
/* }}} */
2008-01-19 12:26:22 +08:00
2007-05-29 02:07:49 +08:00
/* {{{ proto mixed Phar::mapPhar([string alias, [int dataoffset]])
2007-01-21 23:25:50 +08:00
* Reads the currently executed file ( a phar ) and registers its manifest */
PHP_METHOD ( Phar , mapPhar )
{
2007-05-22 00:43:53 +08:00
char * fname , * alias = NULL , * error , * plain_map ;
int fname_len , alias_len = 0 ;
2007-05-29 02:07:49 +08:00
long dataoffset ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |s!l " , & alias , & alias_len , & dataoffset ) = = FAILURE ) {
2007-01-21 23:25:50 +08:00
return ;
}
2007-05-22 00:43:53 +08:00
phar_request_initialize ( TSRMLS_C ) ;
if ( zend_hash_num_elements ( & ( PHAR_GLOBALS - > phar_plain_map ) ) ) {
fname = zend_get_executed_filename ( TSRMLS_C ) ;
fname_len = strlen ( fname ) ;
if ( ( alias & &
zend_hash_find ( & ( PHAR_GLOBALS - > phar_plain_map ) , alias , alias_len + 1 , ( void * * ) & plain_map ) = = SUCCESS )
| | ( zend_hash_find ( & ( PHAR_GLOBALS - > phar_plain_map ) , fname , fname_len + 1 , ( void * * ) & plain_map ) = = SUCCESS )
) {
RETURN_STRING ( plain_map , 1 ) ;
}
}
2007-01-29 14:02:19 +08:00
RETVAL_BOOL ( phar_open_compiled_file ( alias , alias_len , & error TSRMLS_CC ) = = SUCCESS ) ;
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
2007-01-21 23:25:50 +08:00
} /* }}} */
/* {{{ proto mixed Phar::loadPhar(string filename [, string alias])
* Loads any phar archive with an alias */
PHP_METHOD ( Phar , loadPhar )
{
2007-05-22 00:43:53 +08:00
char * fname , * alias = NULL , * error , * plain_map ;
2007-01-21 23:25:50 +08:00
int fname_len , alias_len = 0 ;
2007-05-20 00:06:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s|s! " , & fname , & fname_len , & alias , & alias_len ) = = FAILURE ) {
2007-01-21 23:25:50 +08:00
return ;
}
2007-05-22 00:43:53 +08:00
phar_request_initialize ( TSRMLS_C ) ;
if ( zend_hash_num_elements ( & ( PHAR_GLOBALS - > phar_plain_map ) ) ) {
if ( ( alias & &
zend_hash_find ( & ( PHAR_GLOBALS - > phar_plain_map ) , alias , alias_len + 1 , ( void * * ) & plain_map ) = = SUCCESS )
| | ( zend_hash_find ( & ( PHAR_GLOBALS - > phar_plain_map ) , fname , fname_len + 1 , ( void * * ) & plain_map ) = = SUCCESS )
) {
RETURN_STRING ( plain_map , 1 ) ;
}
}
2007-01-29 14:02:19 +08:00
RETVAL_BOOL ( phar_open_filename ( fname , fname_len , alias , alias_len , REPORT_ERRORS , NULL , & error TSRMLS_CC ) = = SUCCESS ) ;
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
2007-01-21 23:25:50 +08:00
} /* }}} */
2007-02-03 21:42:10 +08:00
/* {{{ proto string Phar::apiVersion()
2007-01-21 23:25:50 +08:00
* Returns the api version */
PHP_METHOD ( Phar , apiVersion )
{
2008-03-23 01:09:24 +08:00
RETURN_STRINGL ( PHP_PHAR_API_VERSION , sizeof ( PHP_PHAR_API_VERSION ) - 1 , 1 ) ;
2007-01-21 23:25:50 +08:00
}
/* }}}*/
2007-02-07 07:56:39 +08:00
/* {{{ proto bool Phar::canCompress([int method])
2007-01-21 23:25:50 +08:00
* Returns whether phar extension supports compression using zlib / bzip2 */
PHP_METHOD ( Phar , canCompress )
{
2007-02-07 07:56:39 +08:00
long method = 0 ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |l " , & method ) = = FAILURE ) {
return ;
}
switch ( method ) {
case PHAR_ENT_COMPRESSED_GZ :
2007-12-19 01:01:24 +08:00
if ( phar_has_zlib ) {
2007-11-25 13:04:40 +08:00
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
2007-02-07 07:56:39 +08:00
case PHAR_ENT_COMPRESSED_BZ2 :
2007-12-19 01:01:24 +08:00
if ( phar_has_bz2 ) {
2007-11-25 13:04:40 +08:00
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
2007-02-07 07:56:39 +08:00
default :
2008-01-17 11:48:29 +08:00
if ( phar_has_zlib | | phar_has_bz2 ) {
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
2007-02-07 07:56:39 +08:00
}
2007-01-21 23:25:50 +08:00
}
/* }}} */
2007-02-03 21:42:10 +08:00
/* {{{ proto bool Phar::canWrite()
2007-01-21 23:25:50 +08:00
* Returns whether phar extension supports writing and creating phars */
PHP_METHOD ( Phar , canWrite )
{
2007-05-10 02:09:41 +08:00
RETURN_BOOL ( ! PHAR_G ( readonly ) ) ;
2007-01-21 23:25:50 +08:00
}
/* }}} */
2008-04-18 12:13:13 +08:00
/* {{{ proto bool Phar::isValidPharFilename(string filename[, bool executable = true])
2007-11-16 12:17:37 +08:00
* Returns whether the given filename is a valid phar filename */
2007-05-16 04:42:38 +08:00
PHP_METHOD ( Phar , isValidPharFilename )
{
2008-03-22 08:11:43 +08:00
char * fname ;
const char * ext_str ;
2007-05-16 04:42:38 +08:00
int fname_len , ext_len ;
2008-04-18 12:13:13 +08:00
zend_bool executable = 1 ;
2007-05-16 04:42:38 +08:00
2008-04-24 02:11:20 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s|b " , & fname , & fname_len , & executable ) = = FAILURE ) {
2007-05-16 04:42:38 +08:00
return ;
}
2008-04-18 12:13:13 +08:00
fname_len = executable ;
2008-04-24 02:11:20 +08:00
RETVAL_BOOL ( phar_detect_phar_fname_ext ( fname , 1 , & ext_str , & ext_len , fname_len , 2 , 1 TSRMLS_CC ) = = SUCCESS ) ;
2007-05-16 04:42:38 +08:00
}
/* }}} */
2007-01-21 23:25:50 +08:00
# if HAVE_SPL
/**
* from spl_directory
*/
static void phar_spl_foreign_dtor ( spl_filesystem_object * object TSRMLS_DC ) /* { { { */
{
2007-01-27 03:58:22 +08:00
phar_archive_delref ( ( phar_archive_data * ) object - > oth TSRMLS_CC ) ;
object - > oth = NULL ;
2007-01-21 23:25:50 +08:00
}
/* }}} */
/**
* from spl_directory
*/
static void phar_spl_foreign_clone ( spl_filesystem_object * src , spl_filesystem_object * dst TSRMLS_DC ) /* { { { */
{
phar_archive_data * phar_data = ( phar_archive_data * ) dst - > oth ;
2008-03-23 06:11:49 +08:00
+ + ( phar_data - > refcount ) ;
2007-01-21 23:25:50 +08:00
}
/* }}} */
static spl_other_handler phar_spl_foreign_handler = {
phar_spl_foreign_dtor ,
phar_spl_foreign_clone
} ;
# endif /* HAVE_SPL */
/* {{{ proto void Phar::__construct(string fname [, int flags [, string alias]])
* Construct a Phar archive object
2008-02-28 05:34:26 +08:00
* { { { proto void PharData : : __construct ( string fname [ , int flags [ , string alias ] ] )
* Construct a PharData archive object
2007-01-21 23:25:50 +08:00
*/
PHP_METHOD ( Phar , __construct )
{
# if !HAVE_SPL
zend_throw_exception_ex ( zend_exception_get_default ( TSRMLS_C ) , 0 TSRMLS_CC , " Cannot instantiate Phar object without SPL extension " ) ;
# else
2008-03-03 16:41:15 +08:00
char * fname , * alias = NULL , * error , * arch , * entry = NULL , * save_fname , * objname ;
2008-02-28 05:34:26 +08:00
int fname_len , alias_len = 0 , arch_len , entry_len , is_data ;
2007-01-21 23:25:50 +08:00
long flags = 0 ;
phar_archive_object * phar_obj ;
phar_archive_data * phar_data ;
zval * zobj = getThis ( ) , arg1 , arg2 ;
2007-05-19 01:50:39 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s|ls! " , & fname , & fname_len , & flags , & alias , & alias_len ) = = FAILURE ) {
2007-01-21 23:25:50 +08:00
return ;
}
phar_obj = ( phar_archive_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
if ( phar_obj - > arc . archive ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Cannot call constructor twice " ) ;
return ;
}
2008-04-18 12:13:13 +08:00
# if PHP_VERSION_ID >= 60000
objname = phar_obj - > std . ce - > name . s ;
# else
objname = phar_obj - > std . ce - > name ;
# endif
if ( ! strncmp ( objname , " PharData " , 8 ) ) {
is_data = 1 ;
} else {
is_data = 0 ;
}
if ( SUCCESS = = phar_split_fname ( fname , fname_len , & arch , & arch_len , & entry , & entry_len , ! is_data , 2 TSRMLS_CC ) ) {
2008-02-28 05:34:26 +08:00
/* use arch (the basename for the archive) for fname instead of fname */
2008-02-11 14:46:44 +08:00
/* this allows support for RecursiveDirectoryIterator of subdirectories */
save_fname = fname ;
2008-02-11 15:33:20 +08:00
# ifdef PHP_WIN32
phar_unixify_path_separators ( arch , arch_len ) ;
# endif
2008-02-11 14:46:44 +08:00
fname = arch ;
fname_len = arch_len ;
2008-02-11 15:33:20 +08:00
# ifdef PHP_WIN32
} else {
arch = estrndup ( fname , fname_len ) ;
2008-04-25 12:34:03 +08:00
arch_len = fname_len ;
2008-02-11 15:33:20 +08:00
save_fname = fname ;
fname = arch ;
phar_unixify_path_separators ( arch , arch_len ) ;
# endif
2008-02-11 14:46:44 +08:00
}
2008-02-28 05:34:26 +08:00
2008-04-18 12:13:13 +08:00
if ( phar_open_or_create_filename ( fname , fname_len , alias , alias_len , is_data , REPORT_ERRORS , & phar_data , & error TSRMLS_CC ) = = FAILURE ) {
2008-02-28 05:34:26 +08:00
2008-02-11 14:46:44 +08:00
if ( fname = = arch ) {
efree ( arch ) ;
fname = save_fname ;
}
2008-03-03 16:41:15 +08:00
if ( entry ) {
2008-02-11 14:46:44 +08:00
efree ( entry ) ;
2008-03-03 16:41:15 +08:00
}
if ( error ) {
2007-01-29 14:02:19 +08:00
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
2008-03-03 16:41:15 +08:00
" %s " , error ) ;
2007-01-29 14:02:19 +08:00
efree ( error ) ;
}
2007-01-21 23:25:50 +08:00
return ;
}
2008-02-11 14:46:44 +08:00
if ( fname = = arch ) {
efree ( arch ) ;
fname = save_fname ;
}
2008-02-28 05:34:26 +08:00
is_data = phar_data - > is_data ;
2008-03-23 06:11:49 +08:00
+ + ( phar_data - > refcount ) ;
2007-01-21 23:25:50 +08:00
phar_obj - > arc . archive = phar_data ;
phar_obj - > spl . oth_handler = & phar_spl_foreign_handler ;
2008-02-11 14:46:44 +08:00
if ( entry ) {
fname_len = spprintf ( & fname , 0 , " phar://%s%s " , phar_data - > fname , entry ) ;
efree ( entry ) ;
} else {
fname_len = spprintf ( & fname , 0 , " phar://%s " , phar_data - > fname ) ;
}
2008-02-28 05:34:26 +08:00
2007-01-21 23:25:50 +08:00
INIT_PZVAL ( & arg1 ) ;
ZVAL_STRINGL ( & arg1 , fname , fname_len , 0 ) ;
if ( ZEND_NUM_ARGS ( ) > 1 ) {
INIT_PZVAL ( & arg2 ) ;
ZVAL_LONG ( & arg2 , flags ) ;
zend_call_method_with_2_params ( & zobj , Z_OBJCE_P ( zobj ) ,
& spl_ce_RecursiveDirectoryIterator - > constructor , " __construct " , NULL , & arg1 , & arg2 ) ;
} else {
zend_call_method_with_1_params ( & zobj , Z_OBJCE_P ( zobj ) ,
& spl_ce_RecursiveDirectoryIterator - > constructor , " __construct " , NULL , & arg1 ) ;
}
2008-02-28 05:34:26 +08:00
phar_obj - > arc . archive - > is_data = is_data ;
2007-01-21 23:25:50 +08:00
phar_obj - > spl . info_class = phar_ce_entry ;
efree ( fname ) ;
# endif /* HAVE_SPL */
}
/* }}} */
2007-12-19 01:01:24 +08:00
/* {{{ proto array Phar::getSupportedSignatures()
* Return array of supported signature types
*/
PHP_METHOD ( Phar , getSupportedSignatures )
{
array_init ( return_value ) ;
add_next_index_stringl ( return_value , " MD5 " , 3 , 1 ) ;
add_next_index_stringl ( return_value , " SHA-1 " , 5 , 1 ) ;
# if HAVE_HASH_EXT
add_next_index_stringl ( return_value , " SHA-256 " , 7 , 1 ) ;
add_next_index_stringl ( return_value , " SHA-512 " , 7 , 1 ) ;
# endif
}
/* }}} */
/* {{{ proto array Phar::getSupportedCompression()
* Return array of supported comparession algorithms
*/
PHP_METHOD ( Phar , getSupportedCompression )
{
array_init ( return_value ) ;
if ( phar_has_zlib ) {
add_next_index_stringl ( return_value , " GZ " , 2 , 1 ) ;
}
if ( phar_has_bz2 ) {
add_next_index_stringl ( return_value , " BZIP2 " , 5 , 1 ) ;
}
}
/* }}} */
2007-01-21 23:25:50 +08:00
# if HAVE_SPL
# define PHAR_ARCHIVE_OBJECT() \
phar_archive_object * phar_obj = ( phar_archive_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ; \
if ( ! phar_obj - > arc . archive ) { \
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , \
2007-01-24 07:31:14 +08:00
" Cannot call method on an uninitialized Phar object " ) ; \
2007-01-21 23:25:50 +08:00
return ; \
}
2008-02-08 17:25:02 +08:00
static int phar_build ( zend_object_iterator * iter , void * puser TSRMLS_DC ) /* { { { */
2007-12-13 08:54:15 +08:00
{
zval * * value ;
zend_uchar key_type ;
2007-12-15 03:45:22 +08:00
zend_bool is_splfileinfo = 0 , close_fp = 1 ;
2007-12-13 08:54:15 +08:00
ulong int_key ;
struct _t {
phar_archive_object * p ;
zend_class_entry * c ;
char * b ;
uint l ;
zval * ret ;
} * p_obj = ( struct _t * ) puser ;
2007-12-13 13:22:06 +08:00
uint str_key_len , base_len = p_obj - > l , fname_len ;
2007-12-13 08:54:15 +08:00
phar_entry_data * data ;
php_stream * fp ;
long contents_len ;
2007-12-13 13:22:06 +08:00
char * fname , * error , * str_key , * base = p_obj - > b , * opened , * save = NULL ;
2007-12-13 08:54:15 +08:00
zend_class_entry * ce = p_obj - > c ;
phar_archive_object * phar_obj = p_obj - > p ;
2007-12-15 03:45:22 +08:00
char * str = " [stream] " ;
2007-12-13 08:54:15 +08:00
iter - > funcs - > get_current_data ( iter , & value TSRMLS_CC ) ;
if ( EG ( exception ) ) {
return ZEND_HASH_APPLY_STOP ;
}
if ( ! value ) {
/* failure in get_current_data */
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC , " Iterator %s returned no value " , ce - > name ) ;
2008-01-14 13:12:46 +08:00
return ZEND_HASH_APPLY_STOP ;
2007-12-13 08:54:15 +08:00
}
2007-12-13 13:22:06 +08:00
switch ( Z_TYPE_PP ( value ) ) {
case IS_STRING :
break ;
2007-12-15 03:45:22 +08:00
case IS_RESOURCE :
php_stream_from_zval_no_verify ( fp , value ) ;
if ( ! fp ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Iterator %s returned an invalid stream handle " , ce - > name ) ;
return ZEND_HASH_APPLY_STOP ;
}
if ( iter - > funcs - > get_current_key ) {
key_type = iter - > funcs - > get_current_key ( iter , & str_key , & str_key_len , & int_key TSRMLS_CC ) ;
if ( EG ( exception ) ) {
return ZEND_HASH_APPLY_STOP ;
}
if ( key_type = = HASH_KEY_IS_LONG ) {
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 - - ;
} 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 ;
}
close_fp = 0 ;
opened = ( char * ) estrndup ( str , sizeof ( " [stream] " ) + 1 ) ;
goto after_open_fp ;
2007-12-13 13:22:06 +08:00
case IS_OBJECT :
2007-12-14 12:08:34 +08:00
if ( instanceof_function ( Z_OBJCE_PP ( value ) , spl_ce_SplFileInfo TSRMLS_CC ) ) {
2007-12-14 12:10:14 +08:00
char * test = NULL ;
2007-12-13 13:22:06 +08:00
zval dummy ;
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( * value TSRMLS_CC ) ;
if ( ! base_len ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Iterator %s returns an SplFileInfo object, so base directory must be specified " , ce - > name ) ;
return ZEND_HASH_APPLY_STOP ;
}
switch ( intern - > type ) {
case SPL_FS_DIR :
2008-01-31 07:50:23 +08:00
# if PHP_VERSION_ID >= 60000
test = spl_filesystem_object_get_path ( intern , NULL , NULL TSRMLS_CC ) . s ;
# elif PHP_VERSION_ID >= 50300
2008-01-31 04:31:09 +08:00
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 ) ;
2007-12-13 13:22:06 +08:00
php_stat ( fname , fname_len , FS_IS_DIR , & dummy TSRMLS_CC ) ;
if ( Z_BVAL ( dummy ) ) {
/* ignore directories */
efree ( fname ) ;
return ZEND_HASH_APPLY_KEEP ;
}
2008-02-01 19:25:59 +08:00
test = expand_filepath ( fname , NULL TSRMLS_CC ) ;
2007-12-13 13:22:06 +08:00
if ( test ) {
efree ( fname ) ;
fname = test ;
fname_len = strlen ( fname ) ;
}
save = fname ;
is_splfileinfo = 1 ;
goto phar_spl_fileinfo ;
case SPL_FS_INFO :
case SPL_FS_FILE :
return ZEND_HASH_APPLY_KEEP ;
}
}
/* fall-through */
default :
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC , " Iterator %s returned an invalid value (must return a string) " , ce - > name ) ;
return ZEND_HASH_APPLY_STOP ;
2007-12-13 08:54:15 +08:00
}
fname = Z_STRVAL_PP ( value ) ;
2007-12-13 13:22:06 +08:00
fname_len = Z_STRLEN_PP ( value ) ;
2007-12-13 09:16:56 +08:00
2007-12-13 13:22:06 +08:00
phar_spl_fileinfo :
2007-12-13 08:54:15 +08:00
if ( base_len ) {
if ( strstr ( fname , base ) ) {
2007-12-13 13:22:06 +08:00
str_key_len = fname_len - base_len ;
2007-12-13 08:54:15 +08:00
if ( str_key_len < = 0 ) {
2007-12-13 13:22:06 +08:00
if ( save ) {
efree ( save ) ;
}
2007-12-13 08:54:15 +08:00
return ZEND_HASH_APPLY_KEEP ;
}
str_key = fname + base_len ;
} else {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC , " Iterator %s returned a path \" %s \" that is not in the base directory \" %s \" " , ce - > name , fname , base ) ;
2007-12-13 13:22:06 +08:00
if ( save ) {
efree ( save ) ;
}
2007-12-13 08:54:15 +08:00
return ZEND_HASH_APPLY_STOP ;
}
2007-12-13 13:22:06 +08:00
} else {
2007-12-13 09:16:56 +08:00
if ( iter - > funcs - > get_current_key ) {
key_type = iter - > funcs - > get_current_key ( iter , & str_key , & str_key_len , & int_key TSRMLS_CC ) ;
if ( EG ( exception ) ) {
return ZEND_HASH_APPLY_STOP ;
}
if ( key_type = = HASH_KEY_IS_LONG ) {
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 - - ;
} 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 ;
}
2007-12-13 08:54:15 +08:00
}
# if PHP_MAJOR_VERSION < 6
if ( PG ( safe_mode ) & & ( ! php_checkuid ( fname , NULL , CHECKUID_ALLOW_ONLY_FILE ) ) ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC , " Iterator %s returned a path \" %s \" that safe mode prevents opening " , ce - > name , fname ) ;
2007-12-13 13:22:06 +08:00
if ( save ) {
efree ( save ) ;
}
2007-12-13 08:54:15 +08:00
return ZEND_HASH_APPLY_STOP ;
}
# endif
if ( php_check_open_basedir ( fname TSRMLS_CC ) ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC , " Iterator %s returned a path \" %s \" that open_basedir prevents opening " , ce - > name , fname ) ;
2007-12-13 13:22:06 +08:00
if ( save ) {
efree ( save ) ;
}
2007-12-13 08:54:15 +08:00
return ZEND_HASH_APPLY_STOP ;
}
/* try to open source file, then create internal phar file and copy contents */
fp = php_stream_open_wrapper ( fname , " rb " , STREAM_MUST_SEEK | 0 , & opened ) ;
if ( ! fp ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC , " Iterator %s returned a file that could not be opened \" %s \" " , ce - > name , fname ) ;
2007-12-13 13:22:06 +08:00
if ( save ) {
efree ( save ) ;
}
2007-12-13 08:54:15 +08:00
return ZEND_HASH_APPLY_STOP ;
}
2007-12-15 03:45:22 +08:00
after_open_fp :
2008-01-09 08:58:37 +08:00
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 ) ) ) {
2007-12-13 08:54:15 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Entry %s cannot be created: %s " , str_key , error ) ;
efree ( error ) ;
2007-12-13 13:22:06 +08:00
if ( save ) {
efree ( save ) ;
}
2007-12-15 03:45:22 +08:00
if ( close_fp ) {
php_stream_close ( fp ) ;
}
2007-12-13 08:54:15 +08:00
return ZEND_HASH_APPLY_STOP ;
} else {
if ( error ) {
efree ( error ) ;
}
contents_len = php_stream_copy_to_stream ( fp , data - > fp , PHP_STREAM_COPY_ALL ) ;
}
2007-12-15 03:45:22 +08:00
if ( close_fp ) {
php_stream_close ( fp ) ;
}
2007-12-13 08:54:15 +08:00
2007-12-13 09:01:27 +08:00
add_assoc_string ( p_obj - > ret , str_key , opened , 0 ) ;
2007-12-13 13:22:06 +08:00
if ( save ) {
efree ( save ) ;
}
2007-12-13 08:54:15 +08:00
data - > internal_file - > compressed_filesize = data - > internal_file - > uncompressed_filesize = contents_len ;
phar_entry_delref ( data TSRMLS_CC ) ;
return ZEND_HASH_APPLY_KEEP ;
}
2008-02-08 17:25:02 +08:00
/* }}} */
2007-12-13 08:54:15 +08:00
/* {{{ proto array Phar::buildFromIterator(Iterator iter[, string base_directory])
2007-12-13 02:01:40 +08:00
* Construct a phar archive from an iterator . The iterator must return a series of strings
* that are full paths to files that should be added to the phar . The iterator key should
* be the path that the file will have within the phar archive .
*
* If base directory is specified , then the key will be ignored , and instead the portion of
* the current value minus the base directory will be used
2007-12-13 08:54:15 +08:00
*
* Returned is an array mapping phar index to actual file added
2007-12-13 02:01:40 +08:00
*/
PHP_METHOD ( Phar , buildFromIterator )
{
2007-12-13 08:54:15 +08:00
zval * obj ;
char * error ;
uint base_len = 0 ;
char * base ;
struct {
phar_archive_object * p ;
zend_class_entry * c ;
char * b ;
uint l ;
zval * ret ;
} pass ;
2007-12-13 02:01:40 +08:00
PHAR_ARCHIVE_OBJECT ( ) ;
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
2007-12-13 02:01:40 +08:00
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot write out phar archive, phar is read-only " ) ;
return ;
}
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " O|s " , & obj , zend_ce_traversable , & base , & base_len ) = = FAILURE ) {
RETURN_FALSE ;
}
2007-12-13 08:54:15 +08:00
array_init ( return_value ) ;
2007-12-13 02:01:40 +08:00
2007-12-13 08:54:15 +08:00
pass . c = Z_OBJCE_P ( obj ) ;
pass . p = phar_obj ;
pass . b = base ;
pass . l = base_len ;
pass . ret = return_value ;
2007-12-13 02:01:40 +08:00
2007-12-14 12:08:34 +08:00
if ( SUCCESS = = spl_iterator_apply ( obj , ( spl_iterator_apply_func_t ) phar_build , ( void * ) & pass TSRMLS_CC ) ) {
2008-02-25 06:29:06 +08:00
phar_flush ( phar_obj - > arc . archive , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-12-13 08:54:15 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
2007-12-13 02:01:40 +08:00
}
}
}
/* }}} */
2007-01-21 23:25:50 +08:00
/* {{{ proto int Phar::count()
* Returns the number of entries in the Phar archive
*/
PHP_METHOD ( Phar , count )
{
PHAR_ARCHIVE_OBJECT ( ) ;
RETURN_LONG ( zend_hash_num_elements ( & phar_obj - > arc . archive - > manifest ) ) ;
}
/* }}} */
2008-01-07 13:41:09 +08:00
/* {{{ proto bool Phar::isTar()
* Returns true if the phar archive is based on the tar file format
*/
PHP_METHOD ( Phar , isTar )
{
PHAR_ARCHIVE_OBJECT ( ) ;
RETURN_BOOL ( phar_obj - > arc . archive - > is_tar ) ;
}
/* }}} */
/* {{{ proto bool Phar::isZip()
* Returns true if the phar archive is based on the Zip file format
*/
PHP_METHOD ( Phar , isZip )
{
PHAR_ARCHIVE_OBJECT ( ) ;
RETURN_BOOL ( phar_obj - > arc . archive - > is_zip ) ;
}
/* }}} */
/* {{{ proto bool Phar::isPhar()
* Returns true if the phar archive is based on the phar file format
*/
PHP_METHOD ( Phar , isPhar )
{
PHAR_ARCHIVE_OBJECT ( ) ;
RETURN_BOOL ( ! phar_obj - > arc . archive - > is_tar & & ! phar_obj - > arc . archive - > is_zip ) ;
}
/* }}} */
2008-01-16 15:24:39 +08:00
static int phar_copy_file_contents ( phar_entry_info * entry , php_stream * fp TSRMLS_DC ) /* { { { */
{
2008-01-28 16:52:08 +08:00
char * error ;
off_t offset ;
2008-04-21 14:17:51 +08:00
phar_entry_info * link ;
2008-01-28 16:52:08 +08:00
2008-04-21 14:17:51 +08:00
if ( FAILURE = = phar_open_entry_fp ( entry , & error , 1 TSRMLS_CC ) ) {
2008-01-28 16:52:08 +08:00
if ( error ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot convert phar archive \" %s \" , unable to open entry \" %s \" contents: %s " , entry - > phar - > fname , entry - > filename , error ) ;
efree ( error ) ;
} else {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot convert phar archive \" %s \" , unable to open entry \" %s \" contents " , entry - > phar - > fname , entry - > filename ) ;
2008-01-16 15:24:39 +08:00
}
2008-01-28 16:52:08 +08:00
return FAILURE ;
2008-01-16 15:24:39 +08:00
}
/* copy old contents in entirety */
2008-04-21 14:17:51 +08:00
phar_seek_efp ( entry , 0 , SEEK_SET , 0 , 1 TSRMLS_CC ) ;
2008-01-28 16:52:08 +08:00
offset = php_stream_tell ( fp ) ;
2008-04-21 14:17:51 +08:00
link = phar_get_link_source ( entry TSRMLS_CC ) ;
if ( ! link ) {
link = entry ;
}
if ( link - > uncompressed_filesize ! = php_stream_copy_to_stream ( phar_get_efp ( link , 0 TSRMLS_CC ) , fp , link - > uncompressed_filesize ) ) {
2008-01-16 15:24:39 +08:00
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot convert phar archive \" %s \" , unable to copy entry \" %s \" contents " , entry - > phar - > fname , entry - > filename ) ;
return FAILURE ;
}
2008-01-28 16:52:08 +08:00
if ( entry - > fp_type = = PHAR_MOD ) {
/* save for potential restore on error */
entry - > cfp = entry - > fp ;
2008-01-16 15:24:39 +08:00
entry - > fp = NULL ;
}
2008-01-28 16:52:08 +08:00
/* set new location of file contents */
entry - > fp_type = PHAR_FP ;
entry - > offset = offset ;
2008-01-16 15:24:39 +08:00
return SUCCESS ;
}
/* }}} */
2008-03-24 06:42:45 +08:00
static zval * phar_rename_archive ( phar_archive_data * phar , char * ext , zend_bool compress TSRMLS_DC )
2008-01-28 16:52:08 +08:00
{
2008-03-24 06:42:45 +08:00
char * oldname = NULL , * oldpath = NULL ;
char * basename = NULL , * basepath = NULL ;
char * newname = NULL , * newpath = NULL ;
zval * ret , arg1 ;
zend_class_entry * ce ;
char * error ;
if ( ! ext ) {
if ( phar - > is_zip ) {
if ( phar - > is_data ) {
ext = " zip " ;
} else {
ext = " phar.zip " ;
}
} else if ( phar - > is_tar ) {
switch ( phar - > flags ) {
case PHAR_FILE_COMPRESSED_GZ :
if ( phar - > is_data ) {
ext = " tar.gz " ;
} else {
ext = " phar.tar.gz " ;
}
break ;
case PHAR_FILE_COMPRESSED_BZ2 :
if ( phar - > is_data ) {
ext = " tar.bz2 " ;
} else {
ext = " phar.tar.bz2 " ;
}
break ;
default :
if ( phar - > is_data ) {
ext = " tar " ;
} else {
ext = " phar.tar " ;
}
}
} else {
switch ( phar - > flags ) {
case PHAR_FILE_COMPRESSED_GZ :
ext = " phar.gz " ;
break ;
case PHAR_FILE_COMPRESSED_BZ2 :
ext = " phar.bz2 " ;
break ;
default :
ext = " phar " ;
}
}
}
if ( ext [ 0 ] = = ' . ' ) {
+ + ext ;
}
oldpath = estrndup ( phar - > fname , phar - > fname_len ) ;
oldname = strrchr ( phar - > fname , ' / ' ) ;
+ + oldname ;
2008-01-28 16:52:08 +08:00
2008-03-24 06:42:45 +08:00
basename = estrndup ( oldname , strlen ( oldname ) ) ;
spprintf ( & newname , 0 , " %s.%s " , strtok ( basename , " . " ) , ext ) ;
efree ( basename ) ;
basepath = estrndup ( oldpath , strlen ( oldpath ) - strlen ( oldname ) ) ;
phar - > fname_len = spprintf ( & newpath , 0 , " %s%s " , basepath , newname ) ;
phar - > fname = newpath ;
efree ( basepath ) ;
efree ( newname ) ;
if ( zend_hash_exists ( & ( PHAR_GLOBALS - > phar_fname_map ) , newpath , phar - > fname_len ) ) {
2008-04-24 02:30:53 +08:00
efree ( oldpath ) ;
2008-03-24 06:42:45 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Unable to add newly converted phar \" %s \" to the list of phars, a phar with that name already exists " , phar - > fname ) ;
return NULL ;
}
if ( SUCCESS ! = zend_hash_add ( & ( PHAR_GLOBALS - > phar_fname_map ) , newpath , phar - > fname_len , ( void * ) & phar , sizeof ( phar_archive_data * ) , NULL ) ) {
2008-04-24 02:30:53 +08:00
efree ( oldpath ) ;
2008-03-24 06:42:45 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Unable to add newly converted phar \" %s \" to the list of phars " , phar - > fname ) ;
return NULL ;
}
if ( ! phar - > is_data ) {
if ( phar - > alias ) {
2008-03-24 11:01:31 +08:00
if ( phar - > is_temporary_alias ) {
phar - > alias = NULL ;
phar - > alias_len = 0 ;
} else {
phar - > alias = estrndup ( newpath , strlen ( newpath ) ) ;
phar - > alias_len = strlen ( newpath ) ;
phar - > is_temporary_alias = 1 ;
zend_hash_update ( & ( PHAR_GLOBALS - > phar_alias_map ) , newpath , phar - > fname_len , ( void * ) & phar , sizeof ( phar_archive_data * ) , NULL ) ;
}
2008-03-24 06:42:45 +08:00
}
2008-03-24 11:01:31 +08:00
} else {
phar - > alias = NULL ;
phar - > alias_len = 0 ;
2008-03-24 06:42:45 +08:00
}
phar_flush ( phar , 0 , 0 , 1 , & error TSRMLS_CC ) ;
if ( error ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
2008-04-24 02:30:53 +08:00
efree ( oldpath ) ;
2008-03-24 06:42:45 +08:00
return NULL ;
}
efree ( oldpath ) ;
if ( phar - > is_data ) {
ce = phar_ce_data ;
2008-01-28 16:52:08 +08:00
} else {
2008-03-24 06:42:45 +08:00
ce = phar_ce_archive ;
2008-01-28 16:52:08 +08:00
}
2008-03-24 06:42:45 +08:00
MAKE_STD_ZVAL ( ret ) ;
if ( SUCCESS ! = object_init_ex ( ret , ce ) ) {
zval_dtor ( ret ) ;
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Unable to instantiate phar object when converting archive \" %s \" " , phar - > fname ) ;
return NULL ;
}
INIT_PZVAL ( & arg1 ) ;
ZVAL_STRINGL ( & arg1 , phar - > fname , phar - > fname_len , 0 ) ;
zend_call_method_with_1_params ( & ret , ce , & ce - > constructor , " __construct " , NULL , & arg1 ) ;
return ret ;
2008-01-28 16:52:08 +08:00
}
2008-03-24 06:42:45 +08:00
static zval * phar_convert_to_other ( phar_archive_data * source , int convert , char * ext , php_uint32 flags TSRMLS_DC ) /* { { { */
2008-01-16 15:24:39 +08:00
{
2008-03-24 06:42:45 +08:00
phar_archive_data * phar ;
2008-01-28 16:52:08 +08:00
phar_entry_info * entry , newentry ;
2008-03-24 06:42:45 +08:00
zval * ret ;
2008-01-16 15:24:39 +08:00
2008-03-24 06:42:45 +08:00
phar = ( phar_archive_data * ) ecalloc ( 1 , sizeof ( phar_archive_data ) ) ;
2008-02-28 05:34:26 +08:00
/* set whole-archive compression and type from parameter */
2008-03-24 06:42:45 +08:00
phar - > flags = flags ;
2008-02-28 05:34:26 +08:00
2008-03-24 06:42:45 +08:00
phar - > is_data = source - > is_data ;
2008-01-16 15:24:39 +08:00
switch ( convert ) {
2008-04-11 12:20:15 +08:00
case PHAR_FORMAT_TAR :
2008-03-24 06:42:45 +08:00
phar - > is_tar = 1 ;
2008-01-16 15:24:39 +08:00
break ;
2008-04-11 12:20:15 +08:00
case PHAR_FORMAT_ZIP :
2008-03-24 06:42:45 +08:00
phar - > is_zip = 1 ;
break ;
default :
phar - > is_data = 0 ;
2008-01-16 15:24:39 +08:00
break ;
}
2008-03-24 06:42:45 +08:00
zend_hash_init ( & ( phar - > manifest ) , sizeof ( phar_entry_info ) ,
2008-01-16 15:24:39 +08:00
zend_get_hash_value , destroy_phar_manifest_entry , 0 ) ;
2008-03-24 06:42:45 +08:00
phar - > fp = php_stream_fopen_tmpfile ( ) ;
phar - > fname = source - > fname ;
phar - > fname_len = source - > fname_len ;
phar - > is_temporary_alias = source - > is_temporary_alias ;
2008-03-24 11:01:31 +08:00
phar - > alias = source - > alias ;
2008-01-16 15:24:39 +08:00
/* first copy each file's uncompressed contents to a temporary file and set per-file flags */
for ( zend_hash_internal_pointer_reset ( & source - > manifest ) ; SUCCESS = = zend_hash_has_more_elements ( & source - > manifest ) ; zend_hash_move_forward ( & source - > manifest ) ) {
2008-01-28 16:52:08 +08:00
2008-01-16 15:24:39 +08:00
if ( FAILURE = = zend_hash_get_current_data ( & source - > manifest , ( void * * ) & entry ) ) {
2008-03-24 06:42:45 +08:00
zend_hash_destroy ( & ( phar - > manifest ) ) ;
php_stream_close ( phar - > fp ) ;
efree ( phar ) ;
2008-01-16 15:24:39 +08:00
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot convert phar archive \" %s \" " , source - > fname ) ;
2008-03-24 06:42:45 +08:00
return NULL ;
2008-01-16 15:24:39 +08:00
}
newentry = * entry ;
2008-03-24 06:42:45 +08:00
if ( FAILURE = = phar_copy_file_contents ( & newentry , phar - > fp TSRMLS_CC ) ) {
zend_hash_destroy ( & ( phar - > manifest ) ) ;
php_stream_close ( phar - > fp ) ;
efree ( phar ) ;
2008-01-16 15:24:39 +08:00
/* exception already thrown */
2008-03-24 06:42:45 +08:00
return NULL ;
2008-01-16 15:24:39 +08:00
}
newentry . filename = estrndup ( newentry . filename , newentry . filename_len ) ;
if ( newentry . metadata ) {
2008-02-08 11:53:17 +08:00
zval * t ;
t = newentry . metadata ;
ALLOC_ZVAL ( newentry . metadata ) ;
* newentry . metadata = * t ;
zval_copy_ctor ( newentry . metadata ) ;
# if PHP_VERSION_ID < 50300
2008-02-11 14:58:56 +08:00
newentry . metadata - > refcount = 1 ;
2008-02-08 11:53:17 +08:00
# else
Z_SET_REFCOUNT_P ( newentry . metadata , 1 ) ;
# endif
newentry . metadata_str . c = NULL ;
newentry . metadata_str . len = 0 ;
2008-01-16 15:24:39 +08:00
}
2008-03-24 06:42:45 +08:00
newentry . is_zip = phar - > is_zip ;
newentry . is_tar = phar - > is_tar ;
2008-01-16 15:24:39 +08:00
if ( newentry . is_tar ) {
newentry . tar_type = ( entry - > is_dir ? TAR_DIR : TAR_FILE ) ;
}
newentry . is_modified = 1 ;
2008-03-24 06:42:45 +08:00
newentry . phar = phar ;
2008-01-16 15:24:39 +08:00
newentry . old_flags = newentry . flags & ~ PHAR_ENT_COMPRESSION_MASK ; /* remove compression from old_flags */
2008-03-24 06:42:45 +08:00
zend_hash_add ( & ( phar - > manifest ) , newentry . filename , newentry . filename_len , ( void * ) & newentry , sizeof ( phar_entry_info ) , NULL ) ;
2008-01-28 16:52:08 +08:00
}
2008-02-28 05:34:26 +08:00
2008-03-24 06:42:45 +08:00
if ( ( ret = phar_rename_archive ( phar , ext , 0 TSRMLS_CC ) ) ) {
return ret ;
2008-01-28 16:52:08 +08:00
} else {
2008-03-24 06:42:45 +08:00
zend_hash_destroy ( & ( phar - > manifest ) ) ;
php_stream_close ( phar - > fp ) ;
efree ( phar - > fname ) ;
efree ( phar ) ;
return NULL ;
2008-02-25 06:29:06 +08:00
}
2008-01-16 15:24:39 +08:00
}
2008-02-08 17:25:02 +08:00
/* }}} */
2008-01-16 15:24:39 +08:00
2008-04-11 12:20:15 +08:00
/* {{{ proto object Phar::convertToExecutable([int format[, int compression [, string file_ext]]])
* Convert a phar . tar or phar . zip archive to the phar file format . The
* optional parameter allows the user to determine the new
* filename extension ( default is phar ) .
2008-01-16 15:24:39 +08:00
*/
2008-04-11 12:20:15 +08:00
PHP_METHOD ( Phar , convertToExecutable )
2008-01-16 15:24:39 +08:00
{
2008-03-02 05:31:03 +08:00
char * ext = NULL ;
2008-04-11 12:20:15 +08:00
int is_data , ext_len = 0 ;
php_uint32 flags ;
2008-03-24 06:42:45 +08:00
zval * ret ;
2008-04-11 12:20:15 +08:00
/* a number that is not 0, 1 or 2 (Which is also Greg's birthday, so there) */
long format = 9021976 , method = 9021976 ;
2008-01-16 15:24:39 +08:00
PHAR_ARCHIVE_OBJECT ( ) ;
2008-02-25 06:29:06 +08:00
2008-04-11 12:20:15 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |lls " , & format , & method , & ext , & ext_len ) = = FAILURE ) {
2008-02-25 06:29:06 +08:00
return ;
}
2008-02-28 09:08:34 +08:00
2008-01-16 15:24:39 +08:00
if ( PHAR_G ( readonly ) ) {
2008-03-24 06:42:45 +08:00
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
2008-04-11 12:20:15 +08:00
" Cannot write out executable phar archive, phar is read-only " ) ;
2008-03-24 06:42:45 +08:00
return ;
2008-01-16 15:24:39 +08:00
}
2008-01-17 05:09:32 +08:00
2008-04-11 12:20:15 +08:00
switch ( format ) {
case 9021976 :
2008-04-24 02:44:43 +08:00
case PHAR_FORMAT_SAME : /* null is converted to 0 */
2008-04-11 12:20:15 +08:00
/* by default, use the existing format */
if ( phar_obj - > arc . archive - > is_tar ) {
format = PHAR_FORMAT_TAR ;
} else if ( phar_obj - > arc . archive - > is_zip ) {
format = PHAR_FORMAT_ZIP ;
} else {
format = PHAR_FORMAT_PHAR ;
}
break ;
case PHAR_FORMAT_PHAR :
case PHAR_FORMAT_TAR :
case PHAR_FORMAT_ZIP :
break ;
default :
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Unknown file format specified, please pass one of Phar::PHAR, Phar::TAR or Phar::ZIP " ) ;
return ;
2008-03-03 16:41:15 +08:00
}
2008-01-17 05:09:32 +08:00
switch ( method ) {
2008-04-11 12:20:15 +08:00
case 9021976 :
flags = phar_obj - > arc . archive - > flags & PHAR_FILE_COMPRESSION_MASK ;
break ;
2008-01-17 05:09:32 +08:00
case 0 :
flags = PHAR_FILE_COMPRESSED_NONE ;
break ;
case PHAR_ENT_COMPRESSED_GZ :
2008-04-11 12:20:15 +08:00
if ( format = = PHAR_FORMAT_ZIP ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress entire archive with gzip, zip archives do not support whole-archive compression " ) ;
return ;
}
2008-01-17 05:09:32 +08:00
if ( ! phar_has_zlib ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress entire archive with gzip, enable ext/zlib in php.ini " ) ;
return ;
}
flags = PHAR_FILE_COMPRESSED_GZ ;
break ;
2008-04-10 21:40:26 +08:00
2008-01-17 05:09:32 +08:00
case PHAR_ENT_COMPRESSED_BZ2 :
2008-04-11 12:20:15 +08:00
if ( format = = PHAR_FORMAT_ZIP ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress entire archive with bz2, zip archives do not support whole-archive compression " ) ;
return ;
}
2008-01-17 05:09:32 +08:00
if ( ! phar_has_bz2 ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress entire archive with bz2, enable ext/bz2 in php.ini " ) ;
return ;
}
flags = PHAR_FILE_COMPRESSED_BZ2 ;
break ;
default :
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2 " ) ;
return ;
}
2008-01-16 15:24:39 +08:00
2008-04-11 12:20:15 +08:00
is_data = phar_obj - > arc . archive - > is_data ;
2008-03-24 06:42:45 +08:00
phar_obj - > arc . archive - > is_data = 0 ;
2008-04-11 12:20:15 +08:00
ret = phar_convert_to_other ( phar_obj - > arc . archive , format , ext , flags TSRMLS_CC ) ;
phar_obj - > arc . archive - > is_data = is_data ;
2008-03-24 06:42:45 +08:00
if ( ret ) {
RETURN_ZVAL ( ret , 1 , 1 ) ;
} else {
RETURN_NULL ( ) ;
}
}
/* }}} */
2008-04-11 12:20:15 +08:00
/* {{{ proto object Phar::convertToData([int format[, int compression [, string file_ext]]])
* Convert an archive to a non - executable . tar or . zip .
2008-03-24 06:42:45 +08:00
* The optional parameter allows the user to determine the new
* filename extension ( default is . zip or . tar ) .
*/
PHP_METHOD ( Phar , convertToData )
{
char * ext = NULL ;
2008-04-11 12:20:15 +08:00
int is_data , ext_len = 0 ;
php_uint32 flags ;
2008-03-24 06:42:45 +08:00
zval * ret ;
2008-04-11 12:20:15 +08:00
/* a number that is not 0, 1 or 2 (Which is also Greg's birthday so there) */
long format = 9021976 , method = 9021976 ;
2008-03-24 06:42:45 +08:00
PHAR_ARCHIVE_OBJECT ( ) ;
2008-04-11 12:20:15 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |lls " , & format , & method , & ext , & ext_len ) = = FAILURE ) {
2008-03-24 06:42:45 +08:00
return ;
}
2008-04-11 12:20:15 +08:00
switch ( format ) {
case 9021976 :
2008-04-24 02:44:43 +08:00
case PHAR_FORMAT_SAME : /* null is converted to 0 */
2008-04-11 12:20:15 +08:00
/* by default, use the existing format */
if ( phar_obj - > arc . archive - > is_tar ) {
format = PHAR_FORMAT_TAR ;
} else if ( phar_obj - > arc . archive - > is_zip ) {
format = PHAR_FORMAT_ZIP ;
} else {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot write out data phar archive, use Phar::TAR or Phar::ZIP " ) ;
2008-04-24 02:54:09 +08:00
return ;
2008-04-11 12:20:15 +08:00
}
break ;
case PHAR_FORMAT_PHAR :
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot write out data phar archive, use Phar::TAR or Phar::ZIP " ) ;
return ;
case PHAR_FORMAT_TAR :
case PHAR_FORMAT_ZIP :
break ;
default :
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Unknown file format specified, please pass one of Phar::TAR or Phar::ZIP " ) ;
return ;
2008-03-24 06:42:45 +08:00
}
2008-04-11 12:20:15 +08:00
switch ( method ) {
case 9021976 :
flags = phar_obj - > arc . archive - > flags & PHAR_FILE_COMPRESSION_MASK ;
break ;
case 0 :
flags = PHAR_FILE_COMPRESSED_NONE ;
break ;
case PHAR_ENT_COMPRESSED_GZ :
if ( format = = PHAR_FORMAT_ZIP ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress entire archive with gzip, zip archives do not support whole-archive compression " ) ;
return ;
}
if ( ! phar_has_zlib ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress entire archive with gzip, enable ext/zlib in php.ini " ) ;
return ;
}
flags = PHAR_FILE_COMPRESSED_GZ ;
break ;
case PHAR_ENT_COMPRESSED_BZ2 :
if ( format = = PHAR_FORMAT_ZIP ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress entire archive with bz2, zip archives do not support whole-archive compression " ) ;
return ;
}
if ( ! phar_has_bz2 ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress entire archive with bz2, enable ext/bz2 in php.ini " ) ;
return ;
}
flags = PHAR_FILE_COMPRESSED_BZ2 ;
break ;
default :
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2 " ) ;
return ;
2008-03-24 06:42:45 +08:00
}
2008-04-11 12:20:15 +08:00
is_data = phar_obj - > arc . archive - > is_data ;
2008-03-24 06:42:45 +08:00
phar_obj - > arc . archive - > is_data = 1 ;
2008-04-11 12:20:15 +08:00
ret = phar_convert_to_other ( phar_obj - > arc . archive , format , ext , flags TSRMLS_CC ) ;
phar_obj - > arc . archive - > is_data = is_data ;
2008-03-24 06:42:45 +08:00
if ( ret ) {
RETURN_ZVAL ( ret , 1 , 1 ) ;
} else {
RETURN_NULL ( ) ;
}
2008-01-16 15:24:39 +08:00
}
/* }}} */
2008-01-21 13:28:09 +08:00
/* {{{ proto int|false Phar::isCompressed()
2008-02-26 00:27:23 +08:00
* Returns Phar : : GZ or PHAR : : BZ2 if the entire archive is compressed
* ( . tar . gz / tar . bz2 and so on ) , or FALSE otherwise .
2008-01-09 15:09:04 +08:00
*/
PHP_METHOD ( Phar , isCompressed )
{
PHAR_ARCHIVE_OBJECT ( ) ;
if ( phar_obj - > arc . archive - > flags & PHAR_FILE_COMPRESSED_GZ ) {
RETURN_LONG ( PHAR_ENT_COMPRESSED_GZ ) ;
}
if ( phar_obj - > arc . archive - > flags & PHAR_FILE_COMPRESSED_BZ2 ) {
RETURN_LONG ( PHAR_ENT_COMPRESSED_BZ2 ) ;
}
2008-01-21 13:28:09 +08:00
RETURN_FALSE ;
2008-01-09 15:09:04 +08:00
}
/* }}} */
2008-04-10 11:32:10 +08:00
/* {{{ proto bool Phar::isWritable()
* Returns true if phar . readonly = 0 or phar is a PharData AND the actual file is writable .
*/
PHP_METHOD ( Phar , isWritable )
{
php_stream_statbuf ssb ;
PHAR_ARCHIVE_OBJECT ( ) ;
if ( ! phar_obj - > arc . archive - > is_writeable ) {
RETURN_FALSE ;
}
if ( SUCCESS ! = php_stream_stat_path ( phar_obj - > arc . archive - > fname , & ssb ) ) {
if ( phar_obj - > arc . archive - > is_brandnew ) {
/* assume it works if the file doesn't exist yet */
RETURN_TRUE ;
}
RETURN_FALSE ;
}
RETURN_BOOL ( ( ssb . sb . st_mode & ( S_IWOTH | S_IWGRP | S_IWUSR ) ) ! = 0 ) ;
}
/* }}} */
2008-02-21 01:58:56 +08:00
/* {{{ proto bool Phar::delete(string entry)
2008-02-26 00:27:23 +08:00
* Deletes a named file within the archive .
2007-08-25 09:32:35 +08:00
*/
PHP_METHOD ( Phar , delete )
{
char * fname ;
int fname_len ;
char * error ;
phar_entry_info * entry ;
PHAR_ARCHIVE_OBJECT ( ) ;
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
2007-08-25 09:32:35 +08:00
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot write out phar archive, phar is read-only " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-08-25 09:32:35 +08:00
}
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s " , & fname , & fname_len ) = = FAILURE ) {
RETURN_FALSE ;
}
if ( zend_hash_exists ( & phar_obj - > arc . archive - > manifest , fname , ( uint ) fname_len ) ) {
if ( SUCCESS = = zend_hash_find ( & phar_obj - > arc . archive - > manifest , fname , ( uint ) fname_len , ( void * * ) & entry ) ) {
if ( entry - > is_deleted ) {
/* entry is deleted, but has not been flushed to disk yet */
RETURN_TRUE ;
} else {
entry - > is_deleted = 1 ;
entry - > is_modified = 1 ;
phar_obj - > arc . archive - > is_modified = 1 ;
}
}
} else {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Entry %s does not exist and cannot be deleted " , fname ) ;
RETURN_FALSE ;
}
2008-02-25 06:29:06 +08:00
phar_flush ( phar_obj - > arc . archive , NULL , 0 , 0 , & error TSRMLS_CC ) ;
2007-08-25 09:32:35 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
RETURN_TRUE ;
}
2007-08-25 09:36:21 +08:00
/* }}} */
2007-08-25 09:32:35 +08:00
2007-05-19 01:50:39 +08:00
/* {{{ proto int Phar::getAlias()
2008-02-26 00:27:23 +08:00
* Returns the alias for the Phar or NULL .
2007-05-19 01:50:39 +08:00
*/
PHP_METHOD ( Phar , getAlias )
{
PHAR_ARCHIVE_OBJECT ( ) ;
if ( phar_obj - > arc . archive - > alias & & phar_obj - > arc . archive - > alias ! = phar_obj - > arc . archive - > fname ) {
RETURN_STRINGL ( phar_obj - > arc . archive - > alias , phar_obj - > arc . archive - > alias_len , 1 ) ;
}
}
/* }}} */
2008-03-24 03:03:15 +08:00
/* {{{ proto int Phar::getPath()
* Returns the real path to the phar archive on disk
*/
PHP_METHOD ( Phar , getPath )
{
PHAR_ARCHIVE_OBJECT ( ) ;
RETURN_STRINGL ( phar_obj - > arc . archive - > fname , phar_obj - > arc . archive - > fname_len , 1 ) ;
}
/* }}} */
2007-08-23 12:49:39 +08:00
/* {{{ proto bool Phar::setAlias(string alias)
2008-02-26 00:27:23 +08:00
* Sets the alias for a Phar archive . The default value is the full path
* to the archive .
2007-08-23 12:49:39 +08:00
*/
PHP_METHOD ( Phar , setAlias )
{
2008-02-11 14:46:44 +08:00
char * alias , * error , * oldalias ;
2008-02-02 03:50:06 +08:00
phar_archive_data * * fd_ptr ;
2008-02-11 14:46:44 +08:00
int alias_len , oldalias_len , old_temp , readd = 0 ;
2007-08-23 12:49:39 +08:00
PHAR_ARCHIVE_OBJECT ( ) ;
2007-08-25 09:32:35 +08:00
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
2007-08-25 09:32:35 +08:00
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot write out phar archive, phar is read-only " ) ;
2008-03-24 09:33:30 +08:00
RETURN_FALSE ;
2007-08-25 09:32:35 +08:00
}
2008-02-28 05:34:26 +08:00
if ( phar_obj - > arc . archive - > is_data ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" A Phar alias cannot be set in a plain %s archive " , phar_obj - > arc . archive - > is_tar ? " tar " : " zip " ) ;
2008-03-24 09:33:30 +08:00
RETURN_FALSE ;
2008-02-28 05:34:26 +08:00
}
2007-08-23 12:49:39 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s " , & alias , & alias_len ) = = SUCCESS ) {
2007-08-24 07:23:26 +08:00
if ( alias_len = = phar_obj - > arc . archive - > alias_len & & memcmp ( phar_obj - > arc . archive - > alias , alias , alias_len ) = = 0 ) {
RETURN_TRUE ;
}
2008-01-29 04:18:15 +08:00
if ( alias_len & & SUCCESS = = zend_hash_find ( & ( PHAR_GLOBALS - > phar_alias_map ) , alias , alias_len , ( void * * ) & fd_ptr ) ) {
2007-08-24 07:23:26 +08:00
spprintf ( & error , 0 , " alias \" %s \" is already used for archive \" %s \" and cannot be used for other archives " , alias , ( * fd_ptr ) - > fname ) ;
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
RETURN_FALSE ;
}
2008-03-24 09:33:30 +08:00
if ( ! phar_validate_alias ( alias , alias_len ) ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Invalid alias \" %s \" specified for phar \" %s \" " , alias , phar_obj - > arc . archive - > fname ) ;
RETURN_FALSE ;
}
2008-01-29 04:18:15 +08:00
if ( phar_obj - > arc . archive - > alias_len & & SUCCESS = = zend_hash_find ( & ( PHAR_GLOBALS - > phar_alias_map ) , phar_obj - > arc . archive - > alias , phar_obj - > arc . archive - > alias_len , ( void * * ) & fd_ptr ) ) {
zend_hash_del ( & ( PHAR_GLOBALS - > phar_alias_map ) , phar_obj - > arc . archive - > alias , phar_obj - > arc . archive - > alias_len ) ;
2008-02-11 14:46:44 +08:00
readd = 1 ;
2007-08-23 12:49:39 +08:00
}
2008-02-11 14:46:44 +08:00
oldalias = phar_obj - > arc . archive - > alias ;
oldalias_len = phar_obj - > arc . archive - > alias_len ;
old_temp = phar_obj - > arc . archive - > is_temporary_alias ;
2008-01-01 06:42:40 +08:00
if ( alias_len ) {
phar_obj - > arc . archive - > alias = estrndup ( alias , alias_len ) ;
} else {
phar_obj - > arc . archive - > alias = NULL ;
}
2007-08-23 12:49:39 +08:00
phar_obj - > arc . archive - > alias_len = alias_len ;
2008-02-11 14:46:44 +08:00
phar_obj - > arc . archive - > is_temporary_alias = 0 ;
2008-01-29 04:18:15 +08:00
2008-02-25 06:29:06 +08:00
phar_flush ( phar_obj - > arc . archive , NULL , 0 , 0 , & error TSRMLS_CC ) ;
2007-08-23 12:49:39 +08:00
if ( error ) {
2008-02-11 14:46:44 +08:00
phar_obj - > arc . archive - > alias = oldalias ;
phar_obj - > arc . archive - > alias_len = oldalias_len ;
phar_obj - > arc . archive - > is_temporary_alias = old_temp ;
2007-08-23 12:49:39 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
2008-02-11 14:46:44 +08:00
if ( readd ) {
zend_hash_add ( & ( PHAR_GLOBALS - > phar_alias_map ) , oldalias , oldalias_len , ( void * ) & ( phar_obj - > arc . archive ) , sizeof ( phar_archive_data * ) , NULL ) ;
}
2007-08-23 12:49:39 +08:00
efree ( error ) ;
2008-03-24 09:33:30 +08:00
RETURN_FALSE ;
2008-02-11 14:46:44 +08:00
}
zend_hash_add ( & ( PHAR_GLOBALS - > phar_alias_map ) , alias , alias_len , ( void * ) & ( phar_obj - > arc . archive ) , sizeof ( phar_archive_data * ) , NULL ) ;
if ( oldalias ) {
efree ( oldalias ) ;
2007-08-23 12:49:39 +08:00
}
RETURN_TRUE ;
}
RETURN_FALSE ;
}
2008-02-08 17:25:02 +08:00
/* }}} */
2007-08-23 12:49:39 +08:00
2007-01-21 23:25:50 +08:00
/* {{{ proto string Phar::getVersion()
* Return version info of Phar archive
*/
PHP_METHOD ( Phar , getVersion )
{
PHAR_ARCHIVE_OBJECT ( ) ;
RETURN_STRING ( phar_obj - > arc . archive - > version , 1 ) ;
}
/* }}} */
2007-03-23 00:31:46 +08:00
/* {{{ proto void Phar::startBuffering()
2007-01-26 22:52:10 +08:00
* Do not flush a writeable phar ( save its contents ) until explicitly requested
*/
2007-03-23 00:31:46 +08:00
PHP_METHOD ( Phar , startBuffering )
2007-01-26 22:52:10 +08:00
{
PHAR_ARCHIVE_OBJECT ( ) ;
phar_obj - > arc . archive - > donotflush = 1 ;
}
/* }}} */
2007-03-23 00:31:46 +08:00
/* {{{ proto bool Phar::isBuffering()
2008-02-26 00:27:23 +08:00
* Returns whether write operations are flushing to disk immediately .
2007-01-31 04:58:14 +08:00
*/
2007-03-23 00:31:46 +08:00
PHP_METHOD ( Phar , isBuffering )
2007-01-31 04:58:14 +08:00
{
PHAR_ARCHIVE_OBJECT ( ) ;
2007-03-23 00:31:46 +08:00
RETURN_BOOL ( ! phar_obj - > arc . archive - > donotflush ) ;
2007-01-31 04:58:14 +08:00
}
/* }}} */
2007-03-23 00:31:46 +08:00
/* {{{ proto bool Phar::stopBuffering()
2008-02-26 00:27:23 +08:00
* Saves the contents of a modified archive to disk .
2007-01-26 22:52:10 +08:00
*/
2007-03-23 00:31:46 +08:00
PHP_METHOD ( Phar , stopBuffering )
2007-01-26 22:52:10 +08:00
{
2007-01-29 14:02:19 +08:00
char * error ;
2007-01-26 22:52:10 +08:00
PHAR_ARCHIVE_OBJECT ( ) ;
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
2007-01-26 22:52:10 +08:00
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot write out phar archive, phar is read-only " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-01-26 22:52:10 +08:00
}
2007-01-29 03:56:09 +08:00
phar_obj - > arc . archive - > donotflush = 0 ;
2008-02-25 06:29:06 +08:00
phar_flush ( phar_obj - > arc . archive , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-01-29 14:02:19 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
2007-01-29 06:11:28 +08:00
}
/* }}} */
/* {{{ proto bool Phar::setStub(string|stream stub [, int len])
2008-02-26 00:27:23 +08:00
* Change the stub in a phar , phar . tar or phar . zip archive to something other
* than the default . The stub * must * end with a call to __HALT_COMPILER ( ) .
2007-01-29 06:11:28 +08:00
*/
PHP_METHOD ( Phar , setStub )
{
zval * zstub ;
2007-01-29 14:02:19 +08:00
char * stub , * error ;
2007-01-29 06:11:28 +08:00
int stub_len ;
long len = - 1 ;
php_stream * stream ;
PHAR_ARCHIVE_OBJECT ( ) ;
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
2007-01-29 06:11:28 +08:00
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot change stub, phar is read-only " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-01-29 06:11:28 +08:00
}
2008-02-28 05:34:26 +08:00
if ( phar_obj - > arc . archive - > is_data ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" A Phar stub cannot be set in a plain %s archive " , phar_obj - > arc . archive - > is_tar ? " tar " : " zip " ) ;
return ;
}
2007-01-29 06:11:28 +08:00
if ( zend_parse_parameters_ex ( ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS ( ) TSRMLS_CC , " r|l " , & zstub , & len ) = = SUCCESS ) {
if ( ( php_stream_from_zval_no_verify ( stream , & zstub ) ) ! = NULL ) {
if ( len > 0 ) {
len = - len ;
} else {
len = - 1 ;
}
2008-02-25 06:29:06 +08:00
phar_flush ( phar_obj - > arc . archive , ( char * ) & zstub , len , 0 , & error TSRMLS_CC ) ;
2007-01-29 14:02:19 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
2007-01-29 06:11:28 +08:00
RETURN_TRUE ;
2007-01-27 23:31:24 +08:00
} else {
2007-01-29 06:11:28 +08:00
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot change stub, unable to read from input stream " ) ;
2007-01-26 22:52:10 +08:00
}
2007-01-29 06:11:28 +08:00
} else if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s " , & stub , & stub_len ) = = SUCCESS ) {
2008-02-25 06:29:06 +08:00
phar_flush ( phar_obj - > arc . archive , stub , stub_len , 0 , & error TSRMLS_CC ) ;
2007-01-29 14:02:19 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
2007-01-29 06:11:28 +08:00
RETURN_TRUE ;
2007-01-26 22:52:10 +08:00
}
2007-01-29 06:11:28 +08:00
RETURN_FALSE ;
2007-01-26 22:52:10 +08:00
}
/* }}} */
2008-02-21 03:22:12 +08:00
/* {{{ proto bool Phar::setDefaultStub([string index[, string webindex]])
2008-02-26 00:27:23 +08:00
* In a pure phar archive , sets a stub that can be used to run the archive
* regardless of whether the phar extension is available . The first parameter
* is the CLI startup filename , which defaults to " index.php " . The second
* parameter is the web startup filename and also defaults to " index.php "
* ( falling back to CLI behaviour ) .
* Both parameters are optional .
* In a phar . zip or phar . tar archive , the default stub is used only to
* identify the archive to the extension as a Phar object . This allows the
* extension to treat phar . zip and phar . tar types as honorary phars . Since
* files cannot be loaded via this kind of stub , no parameters are accepted
* when the Phar object is zip - or tar - based .
2008-02-21 03:22:12 +08:00
*/
PHP_METHOD ( Phar , setDefaultStub )
{
2008-02-25 06:29:06 +08:00
char * index = NULL , * webindex = NULL , * error = NULL , * stub = NULL ;
2008-02-23 22:59:52 +08:00
int index_len = 0 , webindex_len = 0 , created_stub = 0 ;
2008-02-21 08:24:38 +08:00
size_t stub_len = 0 ;
2008-02-21 03:22:12 +08:00
PHAR_ARCHIVE_OBJECT ( ) ;
2008-02-28 05:34:26 +08:00
if ( phar_obj - > arc . archive - > is_data ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" A Phar stub cannot be set in a plain %s archive " , phar_obj - > arc . archive - > is_tar ? " tar " : " zip " ) ;
return ;
}
2008-02-21 08:24:38 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |s!s " , & index , & index_len , & webindex , & webindex_len ) = = FAILURE ) {
2008-02-21 03:22:12 +08:00
RETURN_FALSE ;
}
2008-02-21 08:24:38 +08:00
if ( ZEND_NUM_ARGS ( ) > 0 & & ( phar_obj - > arc . archive - > is_tar | | phar_obj - > arc . archive - > is_zip ) ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " method accepts no arguments for a tar- or zip-based phar stub, %d given " , ZEND_NUM_ARGS ( ) ) ;
2008-02-21 03:22:12 +08:00
RETURN_FALSE ;
}
if ( PHAR_G ( readonly ) ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot change stub: phar.readonly=1 " ) ;
RETURN_FALSE ;
}
2008-02-21 08:24:38 +08:00
if ( ! phar_obj - > arc . archive - > is_tar & & ! phar_obj - > arc . archive - > is_zip ) {
2008-02-25 06:29:06 +08:00
2008-02-21 08:24:38 +08:00
stub = phar_create_default_stub ( index , webindex , & stub_len , & error TSRMLS_CC ) ;
2008-02-21 03:22:12 +08:00
2008-02-21 08:24:38 +08:00
if ( error ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
2008-02-23 22:59:52 +08:00
if ( stub ) {
efree ( stub ) ;
}
2008-02-21 08:24:38 +08:00
RETURN_FALSE ;
}
2008-02-23 22:59:52 +08:00
created_stub = 1 ;
2008-02-21 03:22:12 +08:00
}
2008-02-25 06:29:06 +08:00
phar_flush ( phar_obj - > arc . archive , stub , stub_len , 1 , & error TSRMLS_CC ) ;
2008-02-23 22:59:52 +08:00
if ( created_stub ) {
efree ( stub ) ;
}
2008-02-21 03:22:12 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
RETURN_FALSE ;
}
RETURN_TRUE ;
}
/* }}} */
2007-03-26 08:00:56 +08:00
/* {{{ proto array Phar::setSignatureAlgorithm(int sigtype)
2008-02-26 00:27:23 +08:00
* Sets the signature algorithm for a phar and applies it . The signature
* algorithm must be one of Phar : : MD5 , Phar : : SHA1 , Phar : : SHA256 ,
* Phar : : SHA512 , or Phar : : PGP ( PGP is not yet supported and falls back to
* SHA - 1 ) . Note that zip - and tar - based phar archives cannot support
* signatures .
2007-03-26 08:00:56 +08:00
*/
PHP_METHOD ( Phar , setSignatureAlgorithm )
{
long algo ;
char * error ;
PHAR_ARCHIVE_OBJECT ( ) ;
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
2007-03-26 08:00:56 +08:00
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
2008-01-03 12:45:00 +08:00
" Cannot set signature algorithm, phar is read-only " ) ;
2008-01-14 13:12:46 +08:00
return ;
2008-01-03 12:45:00 +08:00
}
if ( phar_obj - > arc . archive - > is_tar ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot set signature algorithm, not possible with tar-based phar archives " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-03-26 08:00:56 +08:00
}
2008-01-21 13:28:09 +08:00
if ( phar_obj - > arc . archive - > is_zip ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot set signature algorithm, not possible with zip-based phar archives " ) ;
return ;
}
2007-03-26 08:00:56 +08:00
if ( zend_parse_parameters_ex ( ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS ( ) TSRMLS_CC , " l " , & algo ) ! = SUCCESS ) {
return ;
}
switch ( algo ) {
case PHAR_SIG_SHA256 :
case PHAR_SIG_SHA512 :
# if !HAVE_HASH_EXT
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" SHA-256 and SHA-512 signatures are only supported if the hash extension is enabled " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-03-26 08:00:56 +08:00
# endif
case PHAR_SIG_MD5 :
case PHAR_SIG_SHA1 :
case PHAR_SIG_PGP :
phar_obj - > arc . archive - > sig_flags = algo ;
phar_obj - > arc . archive - > is_modified = 1 ;
2008-02-25 06:29:06 +08:00
phar_flush ( phar_obj - > arc . archive , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-03-26 08:00:56 +08:00
if ( error ) {
2008-01-21 13:28:09 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
2007-03-26 08:00:56 +08:00
efree ( error ) ;
}
2007-03-26 08:29:22 +08:00
break ;
2007-03-26 08:00:56 +08:00
default :
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Unknown signature algorithm specified " ) ;
}
}
/* }}} */
2007-01-21 23:25:50 +08:00
/* {{{ proto array|false Phar::getSignature()
2008-02-26 00:27:23 +08:00
* Returns a hash signature , or FALSE if the archive is unsigned .
2007-01-21 23:25:50 +08:00
*/
PHP_METHOD ( Phar , getSignature )
{
PHAR_ARCHIVE_OBJECT ( ) ;
if ( phar_obj - > arc . archive - > signature ) {
array_init ( return_value ) ;
add_assoc_stringl ( return_value , " hash " , phar_obj - > arc . archive - > signature , phar_obj - > arc . archive - > sig_len , 1 ) ;
switch ( phar_obj - > arc . archive - > sig_flags ) {
case PHAR_SIG_MD5 :
2007-03-26 05:43:49 +08:00
add_assoc_stringl ( return_value , " hash_type " , " MD5 " , 3 , 1 ) ;
2007-01-21 23:25:50 +08:00
break ;
case PHAR_SIG_SHA1 :
2007-03-26 05:43:49 +08:00
add_assoc_stringl ( return_value , " hash_type " , " SHA-1 " , 5 , 1 ) ;
break ;
case PHAR_SIG_SHA256 :
add_assoc_stringl ( return_value , " hash_type " , " SHA-256 " , 7 , 1 ) ;
break ;
case PHAR_SIG_SHA512 :
add_assoc_stringl ( return_value , " hash_type " , " SHA-512 " , 7 , 1 ) ;
2007-01-21 23:25:50 +08:00
break ;
}
} else {
RETURN_FALSE ;
}
}
/* }}} */
/* {{{ proto bool Phar::getModified()
* Return whether phar was modified
*/
PHP_METHOD ( Phar , getModified )
{
PHAR_ARCHIVE_OBJECT ( ) ;
RETURN_BOOL ( phar_obj - > arc . archive - > is_modified ) ;
}
/* }}} */
2007-01-28 03:26:58 +08:00
static int phar_set_compression ( void * pDest , void * argument TSRMLS_DC ) /* { { { */
{
phar_entry_info * entry = ( phar_entry_info * ) pDest ;
php_uint32 compress = * ( php_uint32 * ) argument ;
if ( entry - > is_deleted ) {
return ZEND_HASH_APPLY_KEEP ;
}
2007-08-17 12:47:50 +08:00
entry - > old_flags = entry - > flags ;
2007-01-28 03:26:58 +08:00
entry - > flags & = ~ PHAR_ENT_COMPRESSION_MASK ;
entry - > flags | = compress ;
entry - > is_modified = 1 ;
return ZEND_HASH_APPLY_KEEP ;
}
/* }}} */
static int phar_test_compression ( void * pDest , void * argument TSRMLS_DC ) /* { { { */
{
phar_entry_info * entry = ( phar_entry_info * ) pDest ;
if ( entry - > is_deleted ) {
return ZEND_HASH_APPLY_KEEP ;
}
2007-12-19 01:01:24 +08:00
if ( ! phar_has_bz2 ) {
2007-11-24 12:06:44 +08:00
if ( entry - > flags & PHAR_ENT_COMPRESSED_BZ2 ) {
* ( int * ) argument = 0 ;
}
2007-01-28 03:26:58 +08:00
}
2007-12-19 01:01:24 +08:00
if ( ! phar_has_zlib ) {
2007-11-25 13:04:40 +08:00
if ( entry - > flags & PHAR_ENT_COMPRESSED_GZ ) {
* ( int * ) argument = 0 ;
}
}
2007-01-28 03:26:58 +08:00
return ZEND_HASH_APPLY_KEEP ;
}
/* }}} */
static void pharobj_set_compression ( HashTable * manifest , php_uint32 compress TSRMLS_DC ) /* { { { */
{
zend_hash_apply_with_argument ( manifest , phar_set_compression , & compress TSRMLS_CC ) ;
}
/* }}} */
static int pharobj_cancompress ( HashTable * manifest TSRMLS_DC ) /* { { { */
{
int test ;
test = 1 ;
zend_hash_apply_with_argument ( manifest , phar_test_compression , & test TSRMLS_CC ) ;
return test ;
}
/* }}} */
2008-04-11 21:41:59 +08:00
/* {{{ proto object Phar::compress(int method[, string extension])
* Compress a . tar , or . phar . tar with whole - file compression
* The parameter can be one of Phar : : GZ or Phar : : BZ2 to specify
* the kind of compression desired
*/
PHP_METHOD ( Phar , compress )
{
long method = 0 ;
char * ext = NULL ;
int ext_len ;
php_uint32 flags ;
zval * ret ;
PHAR_ARCHIVE_OBJECT ( ) ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " l|s " , & method , & ext , & ext_len ) = = FAILURE ) {
return ;
}
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot compress phar archive, phar is read-only " ) ;
return ;
}
if ( phar_obj - > arc . archive - > is_zip ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
2008-04-24 12:05:20 +08:00
" Cannot compress zip-based archives with whole-archive compression " ) ;
2008-04-11 21:41:59 +08:00
return ;
}
switch ( method ) {
case 0 :
flags = PHAR_FILE_COMPRESSED_NONE ;
break ;
case PHAR_ENT_COMPRESSED_GZ :
if ( ! phar_has_zlib ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress entire archive with gzip, enable ext/zlib in php.ini " ) ;
return ;
}
flags = PHAR_FILE_COMPRESSED_GZ ;
break ;
case PHAR_ENT_COMPRESSED_BZ2 :
if ( ! phar_has_bz2 ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress entire archive with bz2, enable ext/bz2 in php.ini " ) ;
return ;
}
flags = PHAR_FILE_COMPRESSED_BZ2 ;
break ;
default :
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2 " ) ;
return ;
}
if ( phar_obj - > arc . archive - > is_tar ) {
ret = phar_convert_to_other ( phar_obj - > arc . archive , PHAR_FORMAT_TAR , ext , flags TSRMLS_CC ) ;
} else {
ret = phar_convert_to_other ( phar_obj - > arc . archive , PHAR_FORMAT_PHAR , ext , flags TSRMLS_CC ) ;
}
if ( ret ) {
RETURN_ZVAL ( ret , 1 , 1 ) ;
} else {
RETURN_NULL ( ) ;
}
}
/* }}} */
/* {{{ proto object Phar::decompress([string extension])
* Decompress a . tar , or . phar . tar with whole - file compression
*/
PHP_METHOD ( Phar , decompress )
{
char * ext = NULL ;
int ext_len ;
zval * ret ;
PHAR_ARCHIVE_OBJECT ( ) ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |s " , & ext , & ext_len ) = = FAILURE ) {
return ;
}
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
2008-04-24 12:05:20 +08:00
" Cannot decompress phar archive, phar is read-only " ) ;
2008-04-11 21:41:59 +08:00
return ;
}
if ( phar_obj - > arc . archive - > is_zip ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
2008-04-24 12:05:20 +08:00
" Cannot decompress zip-based archives with whole-archive compression " ) ;
2008-04-11 21:41:59 +08:00
return ;
}
if ( phar_obj - > arc . archive - > is_tar ) {
ret = phar_convert_to_other ( phar_obj - > arc . archive , PHAR_FORMAT_TAR , ext , PHAR_FILE_COMPRESSED_NONE TSRMLS_CC ) ;
} else {
ret = phar_convert_to_other ( phar_obj - > arc . archive , PHAR_FORMAT_PHAR , ext , PHAR_FILE_COMPRESSED_NONE TSRMLS_CC ) ;
}
if ( ret ) {
RETURN_ZVAL ( ret , 1 , 1 ) ;
} else {
RETURN_NULL ( ) ;
}
}
/* }}} */
2008-04-10 21:40:26 +08:00
/* {{{ proto object Phar::compressFiles(int method)
* Compress all files within a phar or zip archive using the specified compression
* The parameter can be one of Phar : : GZ or Phar : : BZ2 to specify
* the kind of compression desired
2007-01-28 03:26:58 +08:00
*/
2008-04-10 21:40:26 +08:00
PHP_METHOD ( Phar , compressFiles )
2007-01-28 03:26:58 +08:00
{
2007-01-29 14:02:19 +08:00
char * error ;
2008-04-10 21:40:26 +08:00
php_uint32 flags ;
long method ;
2007-01-28 03:26:58 +08:00
PHAR_ARCHIVE_OBJECT ( ) ;
2008-04-10 21:40:26 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " l " , & method ) = = FAILURE ) {
2008-01-14 13:12:46 +08:00
return ;
2007-01-28 03:26:58 +08:00
}
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
2007-02-03 12:04:18 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
2007-01-28 03:26:58 +08:00
" Phar is readonly, cannot change compression " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-01-28 03:26:58 +08:00
}
2008-04-10 21:40:26 +08:00
switch ( method ) {
case PHAR_ENT_COMPRESSED_GZ :
if ( ! phar_has_zlib ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress files within archive with gzip, enable ext/zlib in php.ini " ) ;
return ;
}
flags = PHAR_ENT_COMPRESSED_GZ ;
break ;
case PHAR_ENT_COMPRESSED_BZ2 :
if ( ! phar_has_bz2 ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress files within archive with bz2, enable ext/bz2 in php.ini " ) ;
return ;
}
flags = PHAR_ENT_COMPRESSED_BZ2 ;
break ;
default :
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2 " ) ;
return ;
2007-11-24 12:06:44 +08:00
}
2008-03-24 06:42:45 +08:00
if ( phar_obj - > arc . archive - > is_tar ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
2008-04-10 21:40:26 +08:00
" Cannot compress with Gzip compression, tar archives cannot compress individual files, use compress() to compress the whole archive " ) ;
2008-03-24 06:42:45 +08:00
return ;
}
2007-01-28 03:26:58 +08:00
if ( ! pharobj_cancompress ( & phar_obj - > arc . archive - > manifest TSRMLS_CC ) ) {
2008-04-10 21:40:26 +08:00
if ( flags = = PHAR_FILE_COMPRESSED_GZ ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress all files as Gzip, some are compressed as bzip2 and cannot be decompressed " ) ;
} else {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress all files as Bzip2, some are compressed as gzip and cannot be decompressed " ) ;
}
2008-01-14 13:12:46 +08:00
return ;
2007-01-28 03:26:58 +08:00
}
2008-04-10 21:40:26 +08:00
pharobj_set_compression ( & phar_obj - > arc . archive - > manifest , flags TSRMLS_CC ) ;
2008-03-09 12:46:16 +08:00
2007-01-28 03:26:58 +08:00
phar_obj - > arc . archive - > is_modified = 1 ;
2008-03-09 12:46:16 +08:00
2008-02-25 06:29:06 +08:00
phar_flush ( phar_obj - > arc . archive , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-01-29 14:02:19 +08:00
if ( error ) {
2007-02-03 12:04:18 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , error ) ;
2007-01-29 14:02:19 +08:00
efree ( error ) ;
}
2007-01-28 03:26:58 +08:00
}
/* }}} */
2008-04-10 21:40:26 +08:00
/* {{{ proto bool Phar::decompressFiles()
* decompress every file
2007-01-28 03:26:58 +08:00
*/
2008-04-10 21:40:26 +08:00
PHP_METHOD ( Phar , decompressFiles )
2007-01-28 03:26:58 +08:00
{
2007-01-29 14:02:19 +08:00
char * error ;
2007-01-28 03:26:58 +08:00
PHAR_ARCHIVE_OBJECT ( ) ;
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
2007-02-03 12:04:18 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
2007-01-28 03:26:58 +08:00
" Phar is readonly, cannot change compression " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-01-28 03:26:58 +08:00
}
if ( ! pharobj_cancompress ( & phar_obj - > arc . archive - > manifest TSRMLS_CC ) ) {
2007-02-03 12:04:18 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
2008-04-10 21:40:26 +08:00
" Cannot decompress all files, some are compressed as bzip2 or gzip and cannot be decompressed " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-01-28 03:26:58 +08:00
}
2008-01-21 13:28:09 +08:00
if ( phar_obj - > arc . archive - > is_tar ) {
2008-03-24 06:42:45 +08:00
RETURN_TRUE ;
2008-01-21 13:28:09 +08:00
} else {
pharobj_set_compression ( & phar_obj - > arc . archive - > manifest , PHAR_ENT_COMPRESSED_NONE TSRMLS_CC ) ;
}
2008-03-09 12:46:16 +08:00
2007-01-28 03:26:58 +08:00
phar_obj - > arc . archive - > is_modified = 1 ;
2008-03-09 12:46:16 +08:00
2008-02-25 06:29:06 +08:00
phar_flush ( phar_obj - > arc . archive , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-01-29 14:02:19 +08:00
if ( error ) {
2007-02-03 12:04:18 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , error ) ;
2007-01-29 14:02:19 +08:00
efree ( error ) ;
}
2008-03-24 06:42:45 +08:00
RETURN_TRUE ;
2007-01-28 03:26:58 +08:00
}
/* }}} */
2007-12-16 08:57:39 +08:00
/* {{{ proto bool Phar::copy(string oldfile, string newfile)
* copy a file internal to the phar archive to another new file within the phar
*/
PHP_METHOD ( Phar , copy )
{
char * oldfile , * newfile , * error ;
const char * pcr_error ;
int oldfile_len , newfile_len ;
phar_entry_info * oldentry , newentry = { 0 } , * temp ;
PHAR_ARCHIVE_OBJECT ( ) ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " ss " , & oldfile , & oldfile_len , & newfile , & newfile_len ) = = FAILURE ) {
return ;
}
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
2007-12-16 08:57:39 +08:00
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" Cannot copy \" %s \" to \" %s \" , phar is read-only " , oldfile , newfile ) ;
RETURN_FALSE ;
}
2008-04-24 12:14:05 +08:00
if ( ! zend_hash_exists ( & phar_obj - > arc . archive - > manifest , oldfile , ( uint ) oldfile_len ) | | SUCCESS ! = zend_hash_find ( & phar_obj - > arc . archive - > manifest , oldfile , ( uint ) oldfile_len , ( void * * ) & oldentry ) | | oldentry - > is_deleted ) {
2007-12-16 08:57:39 +08:00
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
2008-04-24 12:14:05 +08:00
" file \" %s \" cannot be copied to file \" %s \" , file does not exist in %s " , oldfile , newfile , phar_obj - > arc . archive - > fname ) ;
2007-12-16 08:57:39 +08:00
RETURN_FALSE ;
}
if ( zend_hash_exists ( & phar_obj - > arc . archive - > manifest , newfile , ( uint ) newfile_len ) ) {
if ( SUCCESS = = zend_hash_find ( & phar_obj - > arc . archive - > manifest , newfile , ( uint ) newfile_len , ( void * * ) & temp ) | | ! temp - > is_deleted ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
2008-04-24 12:14:05 +08:00
" file \" %s \" cannot be copied to file \" %s \" , file must not already exist in phar %s " , oldfile , newfile , phar_obj - > arc . archive - > fname ) ;
2007-12-16 08:57:39 +08:00
RETURN_FALSE ;
}
}
if ( phar_path_check ( & newfile , & newfile_len , & pcr_error ) > pcr_is_ok ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC ,
" file \" %s \" contains invalid characters %s, cannot be copied from \" %s \" in phar %s " , newfile , pcr_error , oldfile , phar_obj - > arc . archive - > fname ) ;
RETURN_FALSE ;
}
memcpy ( ( void * ) & newentry , oldentry , sizeof ( phar_entry_info ) ) ;
if ( newentry . metadata ) {
2008-02-08 11:53:17 +08:00
zval * t ;
t = newentry . metadata ;
ALLOC_ZVAL ( newentry . metadata ) ;
* newentry . metadata = * t ;
zval_copy_ctor ( newentry . metadata ) ;
# if PHP_VERSION_ID < 50300
2008-02-11 12:48:58 +08:00
newentry . metadata - > refcount = 1 ;
2008-02-08 11:53:17 +08:00
# else
Z_SET_REFCOUNT_P ( newentry . metadata , 1 ) ;
# endif
2007-12-16 14:31:00 +08:00
newentry . metadata_str . c = NULL ;
newentry . metadata_str . len = 0 ;
2007-12-16 08:57:39 +08:00
}
2007-12-16 14:31:00 +08:00
newentry . filename = estrndup ( newfile , newfile_len ) ;
newentry . filename_len = newfile_len ;
2008-01-08 15:08:46 +08:00
newentry . fp_refcount = 0 ;
2008-01-28 16:52:08 +08:00
if ( oldentry - > fp_type ! = PHAR_FP ) {
if ( FAILURE = = phar_copy_entry_fp ( oldentry , & newentry , & error TSRMLS_CC ) ) {
efree ( newentry . filename ) ;
php_stream_close ( newentry . fp ) ;
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
return ;
}
}
zend_hash_add ( & oldentry - > phar - > manifest , newfile , newfile_len , ( void * ) & newentry , sizeof ( phar_entry_info ) , NULL ) ;
2007-12-16 14:31:00 +08:00
phar_obj - > arc . archive - > is_modified = 1 ;
2007-12-16 08:57:39 +08:00
2008-02-25 06:29:06 +08:00
phar_flush ( phar_obj - > arc . archive , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-12-16 08:57:39 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
2008-01-01 06:42:40 +08:00
2007-12-16 08:57:39 +08:00
RETURN_TRUE ;
}
2008-02-08 17:25:02 +08:00
/* }}} */
2007-12-16 08:57:39 +08:00
2008-02-21 01:58:56 +08:00
/* {{{ proto int Phar::offsetExists(string entry)
2007-01-21 23:25:50 +08:00
* determines whether a file exists in the phar
*/
PHP_METHOD ( Phar , offsetExists )
{
char * fname ;
int fname_len ;
phar_entry_info * entry ;
PHAR_ARCHIVE_OBJECT ( ) ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s " , & fname , & fname_len ) = = FAILURE ) {
return ;
}
if ( zend_hash_exists ( & phar_obj - > arc . archive - > manifest , fname , ( uint ) fname_len ) ) {
if ( SUCCESS = = zend_hash_find ( & phar_obj - > arc . archive - > manifest , fname , ( uint ) fname_len , ( void * * ) & entry ) ) {
if ( entry - > is_deleted ) {
/* entry is deleted, but has not been flushed to disk yet */
RETURN_FALSE ;
}
}
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
}
/* }}} */
2008-02-21 01:58:56 +08:00
/* {{{ proto int Phar::offsetGet(string entry)
2007-01-21 23:25:50 +08:00
* get a PharFileInfo object for a specific file
*/
PHP_METHOD ( Phar , offsetGet )
{
2007-02-05 04:10:03 +08:00
char * fname , * error ;
2007-01-21 23:25:50 +08:00
int fname_len ;
zval * zfname ;
2008-04-25 12:34:03 +08:00
phar_entry_info * entry ;
2007-01-21 23:25:50 +08:00
PHAR_ARCHIVE_OBJECT ( ) ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s " , & fname , & fname_len ) = = FAILURE ) {
return ;
}
2008-04-25 12:34:03 +08:00
if ( ! ( entry = phar_get_entry_info_dir ( phar_obj - > arc . archive , fname , fname_len , 1 , & error TSRMLS_CC ) ) ) {
2007-02-05 04:10:03 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Entry %s does not exist%s%s " , fname , error ? " , " : " " , error ? error : " " ) ;
2007-01-21 23:25:50 +08:00
} else {
2008-04-25 12:34:03 +08:00
if ( entry - > is_temp_dir ) {
efree ( entry - > filename ) ;
efree ( entry ) ;
}
2007-01-21 23:25:50 +08:00
fname_len = spprintf ( & fname , 0 , " phar://%s/%s " , phar_obj - > arc . archive - > fname , fname ) ;
MAKE_STD_ZVAL ( zfname ) ;
ZVAL_STRINGL ( zfname , fname , fname_len , 0 ) ;
2007-01-22 01:40:27 +08:00
spl_instantiate_arg_ex1 ( phar_obj - > spl . info_class , & return_value , 0 , zfname TSRMLS_CC ) ;
2007-01-21 23:25:50 +08:00
zval_ptr_dtor ( & zfname ) ;
}
}
/* }}} */
2008-04-10 03:23:31 +08:00
/* {{{ add a file within the phar archive from a string or resource
2007-01-21 23:25:50 +08:00
*/
2008-04-10 03:23:31 +08:00
static void phar_add_file ( phar_archive_data * phar , char * filename , int filename_len , char * cont_str , int cont_len , zval * zresource TSRMLS_DC )
2007-01-21 23:25:50 +08:00
{
2008-04-10 03:23:31 +08:00
char * error ;
2007-02-14 01:56:37 +08:00
long contents_len ;
2007-01-21 23:25:50 +08:00
phar_entry_data * data ;
2007-01-27 23:31:24 +08:00
php_stream * contents_file ;
2007-01-21 23:25:50 +08:00
2008-04-10 03:23:31 +08:00
if ( ! ( data = phar_get_or_create_entry_data ( phar - > fname , phar - > fname_len , filename , filename_len , " w+b " , 0 , & error TSRMLS_CC ) ) ) {
2007-01-28 05:23:02 +08:00
if ( error ) {
2008-04-10 03:23:31 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Entry %s does not exist and cannot be created: %s " , filename , error ) ;
2007-01-28 05:23:02 +08:00
efree ( error ) ;
} else {
2008-04-10 03:23:31 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Entry %s does not exist and cannot be created " , filename ) ;
2007-01-28 05:23:02 +08:00
}
2008-01-14 13:12:46 +08:00
return ;
2007-01-21 23:25:50 +08:00
} else {
2007-01-28 11:25:53 +08:00
if ( error ) {
efree ( error ) ;
}
2008-01-09 08:58:37 +08:00
if ( ! data - > internal_file - > is_dir ) {
if ( cont_str ) {
contents_len = php_stream_write ( data - > fp , cont_str , cont_len ) ;
if ( contents_len ! = cont_len ) {
2008-04-10 03:23:31 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Entry %s could not be written to " , filename ) ;
2008-01-14 13:12:46 +08:00
return ;
2008-01-09 08:58:37 +08:00
}
} else {
if ( ! ( php_stream_from_zval_no_verify ( contents_file , & zresource ) ) ) {
2008-04-10 03:23:31 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Entry %s could not be written to " , filename ) ;
2008-01-14 13:12:46 +08:00
return ;
2008-01-09 08:58:37 +08:00
}
contents_len = php_stream_copy_to_stream ( contents_file , data - > fp , PHP_STREAM_COPY_ALL ) ;
2007-01-26 22:52:10 +08:00
}
2008-01-09 08:58:37 +08:00
data - > internal_file - > compressed_filesize = data - > internal_file - > uncompressed_filesize = contents_len ;
2007-01-21 23:25:50 +08:00
}
2007-01-27 23:31:24 +08:00
phar_entry_delref ( data TSRMLS_CC ) ;
2008-04-10 03:23:31 +08:00
phar_flush ( phar , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-01-29 14:02:19 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
2007-01-21 23:25:50 +08:00
}
}
/* }}} */
2008-04-10 03:23:31 +08:00
/* {{{ create a directory within the phar archive
*/
static void phar_mkdir ( phar_archive_data * phar , char * dirname , int dirname_len TSRMLS_DC )
{
char * error ;
phar_entry_data * data ;
if ( ! ( data = phar_get_or_create_entry_data ( phar - > fname , phar - > fname_len , dirname , dirname_len , " w+b " , 2 , & error TSRMLS_CC ) ) ) {
if ( error ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Directory %s does not exist and cannot be created: %s " , dirname , error ) ;
efree ( error ) ;
} else {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Directory %s does not exist and cannot be created " , dirname ) ;
}
return ;
} else {
if ( error ) {
efree ( error ) ;
}
phar_entry_delref ( data TSRMLS_CC ) ;
phar_flush ( phar , 0 , 0 , 0 , & error TSRMLS_CC ) ;
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
}
}
/* }}} */
/* {{{ proto int Phar::offsetSet(string entry, string value)
* set the contents of an internal file to those of an external file
*/
PHP_METHOD ( Phar , offsetSet )
{
char * fname , * cont_str = NULL ;
int fname_len , cont_len ;
zval * zresource ;
PHAR_ARCHIVE_OBJECT ( ) ;
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Write operations disabled by INI setting " ) ;
return ;
}
if ( zend_parse_parameters_ex ( ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS ( ) TSRMLS_CC , " sr " , & fname , & fname_len , & zresource ) = = FAILURE
& & zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " ss " , & fname , & fname_len , & cont_str , & cont_len ) = = FAILURE ) {
return ;
}
if ( ( phar_obj - > arc . archive - > is_tar | | phar_obj - > arc . archive - > is_zip ) & & fname_len = = sizeof ( " .phar/stub.php " ) - 1 & & ! memcmp ( fname , " .phar/stub.php " , sizeof ( " .phar/stub.php " ) - 1 ) ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Cannot set stub \" .phar/stub.php \" directly in phar \" %s \" , use setStub " , phar_obj - > arc . archive - > fname ) ;
return ;
}
if ( ( phar_obj - > arc . archive - > is_tar | | phar_obj - > arc . archive - > is_zip ) & & fname_len = = sizeof ( " .phar/alias.txt " ) - 1 & & ! memcmp ( fname , " .phar/alias.txt " , sizeof ( " .phar/alias.txt " ) - 1 ) ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Cannot set alias \" .phar/alias.txt \" directly in phar \" %s \" , use setAlias " , phar_obj - > arc . archive - > fname ) ;
return ;
}
2008-04-15 01:14:54 +08:00
phar_add_file ( phar_obj - > arc . archive , fname , fname_len , cont_str , cont_len , zresource TSRMLS_CC ) ;
2008-04-10 03:23:31 +08:00
}
/* }}} */
2008-02-21 01:58:56 +08:00
/* {{{ proto int Phar::offsetUnset(string entry)
2007-01-21 23:25:50 +08:00
* remove a file from a phar
*/
PHP_METHOD ( Phar , offsetUnset )
{
2007-01-29 14:02:19 +08:00
char * fname , * error ;
2007-01-21 23:25:50 +08:00
int fname_len ;
phar_entry_info * entry ;
PHAR_ARCHIVE_OBJECT ( ) ;
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
2007-01-21 23:25:50 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Write operations disabled by INI setting " ) ;
return ;
}
2008-04-10 03:23:31 +08:00
2007-01-21 23:25:50 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s " , & fname , & fname_len ) = = FAILURE ) {
return ;
}
if ( zend_hash_exists ( & phar_obj - > arc . archive - > manifest , fname , ( uint ) fname_len ) ) {
if ( SUCCESS = = zend_hash_find ( & phar_obj - > arc . archive - > manifest , fname , ( uint ) fname_len , ( void * * ) & entry ) ) {
if ( entry - > is_deleted ) {
/* entry is deleted, but has not been flushed to disk yet */
return ;
}
entry - > is_modified = 0 ;
entry - > is_deleted = 1 ;
/* we need to "flush" the stream to save the newly deleted file on disk */
2008-02-25 06:29:06 +08:00
phar_flush ( phar_obj - > arc . archive , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-01-29 14:02:19 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
2007-01-21 23:25:50 +08:00
RETURN_TRUE ;
}
} else {
RETURN_FALSE ;
}
}
/* }}} */
2008-04-10 03:23:31 +08:00
/* {{{ proto string Phar::addEmptyDir(string dirname)
* Adds an empty directory to the phar archive
*/
PHP_METHOD ( Phar , addEmptyDir )
{
char * dirname ;
int dirname_len ;
PHAR_ARCHIVE_OBJECT ( ) ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s " , & dirname , & dirname_len ) = = FAILURE ) {
return ;
}
2008-04-15 01:14:54 +08:00
phar_mkdir ( phar_obj - > arc . archive , dirname , dirname_len TSRMLS_CC ) ;
2008-04-10 03:23:31 +08:00
}
/* }}} */
/* {{{ proto string Phar::addFile(string filename[, string localname])
* Adds a file to the archive using the filename , or the second parameter as the name within the archive
*/
PHP_METHOD ( Phar , addFile )
{
char * fname , * localname = NULL ;
int fname_len , localname_len ;
php_stream * resource ;
zval * zresource ;
PHAR_ARCHIVE_OBJECT ( ) ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s|s " , & fname , & fname_len , & localname , & localname_len ) = = FAILURE ) {
return ;
}
if ( ! ( resource = php_stream_open_wrapper ( fname , " rb " , 0 , NULL ) ) ) {
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC , " phar error: unable to open file \" %s \" to add to phar archive " , fname ) ;
return ;
}
if ( localname ) {
fname = localname ;
fname_len = localname_len ;
}
MAKE_STD_ZVAL ( zresource ) ;
php_stream_to_zval ( resource , zresource ) ;
2008-04-15 01:14:54 +08:00
phar_add_file ( phar_obj - > arc . archive , fname , fname_len , NULL , 0 , zresource TSRMLS_CC ) ;
2008-04-10 03:23:31 +08:00
efree ( zresource ) ;
}
/* }}} */
/* {{{ proto string Phar::addFromString(string localname, string contents)
* Adds a file to the archive using its contents as a string
*/
PHP_METHOD ( Phar , addFromString )
{
char * localname , * cont_str ;
int localname_len , cont_len ;
PHAR_ARCHIVE_OBJECT ( ) ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " ss " , & localname , & localname_len , & cont_str , & cont_len ) = = FAILURE ) {
return ;
}
2008-04-15 01:14:54 +08:00
phar_add_file ( phar_obj - > arc . archive , localname , localname_len , cont_str , cont_len , NULL TSRMLS_CC ) ;
2008-04-10 03:23:31 +08:00
}
/* }}} */
2007-01-22 08:17:14 +08:00
/* {{{ proto string Phar::getStub()
2008-02-26 00:27:23 +08:00
* Returns the stub at the head of a phar archive as a string .
2007-01-22 08:17:14 +08:00
*/
PHP_METHOD ( Phar , getStub )
{
2007-02-06 04:34:23 +08:00
size_t len ;
2008-01-28 16:52:08 +08:00
char * buf ;
2007-01-22 08:59:02 +08:00
php_stream * fp ;
2008-01-28 16:52:08 +08:00
php_stream_filter * filter = NULL ;
phar_entry_info * stub ;
2007-01-22 08:17:14 +08:00
PHAR_ARCHIVE_OBJECT ( ) ;
2008-01-28 16:52:08 +08:00
if ( phar_obj - > arc . archive - > is_tar | | phar_obj - > arc . archive - > is_zip ) {
2008-01-03 12:45:00 +08:00
if ( SUCCESS = = zend_hash_find ( & ( phar_obj - > arc . archive - > manifest ) , " .phar/stub.php " , sizeof ( " .phar/stub.php " ) - 1 , ( void * * ) & stub ) ) {
2008-01-28 16:52:08 +08:00
if ( phar_obj - > arc . archive - > fp & & ! phar_obj - > arc . archive - > is_brandnew & & ! ( stub - > flags & PHAR_ENT_COMPRESSION_MASK ) ) {
2008-01-03 12:45:00 +08:00
fp = phar_obj - > arc . archive - > fp ;
} else {
fp = php_stream_open_wrapper ( phar_obj - > arc . archive - > fname , " rb " , 0 , NULL ) ;
2008-01-28 16:52:08 +08:00
if ( stub - > flags & PHAR_ENT_COMPRESSION_MASK ) {
char * filter_name ;
if ( ( filter_name = phar_decompress_filter ( stub , 0 ) ) ! = NULL ) {
filter = php_stream_filter_create ( phar_decompress_filter ( stub , 0 ) , NULL , php_stream_is_persistent ( fp ) TSRMLS_CC ) ;
} else {
filter = NULL ;
}
if ( ! filter ) {
zend_throw_exception_ex ( spl_ce_UnexpectedValueException , 0 TSRMLS_CC , " phar error: unable to read stub of phar \" %s \" (cannot create %s filter) " , phar_obj - > arc . archive - > fname , phar_decompress_filter ( stub , 1 ) ) ;
return ;
}
php_stream_filter_append ( & fp - > readfilters , filter ) ;
}
2008-01-03 12:45:00 +08:00
}
if ( ! fp ) {
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC ,
" Unable to read stub " ) ;
return ;
}
2008-01-28 16:52:08 +08:00
php_stream_seek ( fp , stub - > offset_abs , SEEK_SET ) ;
2008-01-03 12:45:00 +08:00
len = stub - > uncompressed_filesize ;
goto carry_on ;
} else {
2008-01-11 10:52:13 +08:00
RETURN_STRINGL ( " " , 0 , 1 ) ;
2008-01-03 12:45:00 +08:00
}
}
2007-01-22 08:17:14 +08:00
len = phar_obj - > arc . archive - > halt_offset ;
2007-01-22 08:59:02 +08:00
2007-01-29 05:26:54 +08:00
if ( phar_obj - > arc . archive - > fp & & ! phar_obj - > arc . archive - > is_brandnew ) {
fp = phar_obj - > arc . archive - > fp ;
} else {
fp = php_stream_open_wrapper ( phar_obj - > arc . archive - > fname , " rb " , 0 , NULL ) ;
2007-01-22 08:59:02 +08:00
}
2007-01-22 08:17:14 +08:00
2007-01-22 08:59:02 +08:00
if ( ! fp ) {
2007-01-22 08:17:14 +08:00
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC ,
" Unable to read stub " ) ;
return ;
}
2007-01-22 08:59:02 +08:00
php_stream_rewind ( fp ) ;
2008-01-03 12:45:00 +08:00
carry_on :
buf = safe_emalloc ( len , 1 , 1 ) ;
2007-01-22 08:59:02 +08:00
if ( len ! = php_stream_read ( fp , buf , len ) ) {
if ( fp ! = phar_obj - > arc . archive - > fp ) {
php_stream_close ( fp ) ;
}
2007-01-22 08:17:14 +08:00
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC ,
" Unable to read stub " ) ;
efree ( buf ) ;
return ;
}
2008-01-28 16:52:08 +08:00
if ( filter ) {
php_stream_filter_flush ( filter , 1 ) ;
php_stream_filter_remove ( filter , 1 TSRMLS_CC ) ;
}
2007-01-22 08:59:02 +08:00
if ( fp ! = phar_obj - > arc . archive - > fp ) {
php_stream_close ( fp ) ;
}
2007-01-22 08:17:14 +08:00
buf [ len ] = ' \0 ' ;
2008-01-01 06:42:40 +08:00
2007-01-22 08:17:14 +08:00
RETURN_STRINGL ( buf , len , 0 ) ;
}
/* }}}*/
2007-05-16 04:42:38 +08:00
/* {{{ proto int Phar::hasMetaData()
2008-02-26 00:27:23 +08:00
* Returns TRUE if the phar has global metadata , FALSE otherwise .
2007-05-16 04:42:38 +08:00
*/
PHP_METHOD ( Phar , hasMetadata )
{
PHAR_ARCHIVE_OBJECT ( ) ;
RETURN_BOOL ( phar_obj - > arc . archive - > metadata ! = NULL ) ;
}
/* }}} */
2007-01-29 11:59:55 +08:00
/* {{{ proto int Phar::getMetaData()
2007-05-16 04:42:38 +08:00
* Returns the global metadata of the phar
2007-01-29 11:59:55 +08:00
*/
PHP_METHOD ( Phar , getMetadata )
{
PHAR_ARCHIVE_OBJECT ( ) ;
if ( phar_obj - > arc . archive - > metadata ) {
RETURN_ZVAL ( phar_obj - > arc . archive - > metadata , 1 , 0 ) ;
}
}
/* }}} */
/* {{{ proto int Phar::setMetaData(mixed $metadata)
2007-05-16 04:42:38 +08:00
* Sets the global metadata of the phar
2007-01-29 11:59:55 +08:00
*/
PHP_METHOD ( Phar , setMetadata )
{
2007-05-16 04:42:38 +08:00
char * error ;
2007-01-29 11:59:55 +08:00
zval * metadata ;
PHAR_ARCHIVE_OBJECT ( ) ;
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
2008-01-21 13:28:09 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Write operations disabled by INI setting " ) ;
return ;
}
2008-01-03 12:45:00 +08:00
if ( phar_obj - > arc . archive - > is_tar ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot set metadata, not possible with tar-based phar archives " ) ;
2008-01-14 13:12:46 +08:00
return ;
2008-01-03 12:45:00 +08:00
}
2007-01-29 11:59:55 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " z " , & metadata ) = = FAILURE ) {
return ;
}
if ( phar_obj - > arc . archive - > metadata ) {
zval_ptr_dtor ( & phar_obj - > arc . archive - > metadata ) ;
phar_obj - > arc . archive - > metadata = NULL ;
}
MAKE_STD_ZVAL ( phar_obj - > arc . archive - > metadata ) ;
ZVAL_ZVAL ( phar_obj - > arc . archive - > metadata , metadata , 1 , 0 ) ;
2007-05-16 04:42:38 +08:00
2008-02-25 06:29:06 +08:00
phar_flush ( phar_obj - > arc . archive , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-05-16 04:42:38 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
}
/* }}} */
2008-01-21 13:28:09 +08:00
/* {{{ proto int Phar::delMetadata()
2007-05-16 04:42:38 +08:00
* Deletes the global metadata of the phar
*/
PHP_METHOD ( Phar , delMetadata )
{
char * error ;
PHAR_ARCHIVE_OBJECT ( ) ;
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! phar_obj - > arc . archive - > is_data ) {
2008-01-21 13:28:09 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Write operations disabled by INI setting " ) ;
return ;
}
2008-03-24 11:01:31 +08:00
if ( phar_obj - > arc . archive - > is_tar ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot delete metadata, not possible with tar-based phar archives " ) ;
return ;
}
2007-05-16 04:42:38 +08:00
if ( phar_obj - > arc . archive - > metadata ) {
zval_ptr_dtor ( & phar_obj - > arc . archive - > metadata ) ;
phar_obj - > arc . archive - > metadata = NULL ;
2008-02-25 06:29:06 +08:00
phar_flush ( phar_obj - > arc . archive , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-05-16 04:42:38 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
RETURN_FALSE ;
} else {
RETURN_TRUE ;
}
} else {
2007-11-25 13:04:40 +08:00
RETURN_TRUE ;
2007-05-16 04:42:38 +08:00
}
2007-01-29 11:59:55 +08:00
}
/* }}} */
2007-01-21 23:25:50 +08:00
/* {{{ proto void PharFileInfo::__construct(string entry)
* Construct a Phar entry object
*/
PHP_METHOD ( PharFileInfo , __construct )
{
2007-01-29 14:02:19 +08:00
char * fname , * arch , * entry , * error ;
2007-01-21 23:25:50 +08:00
int fname_len , arch_len , entry_len ;
phar_entry_object * entry_obj ;
phar_entry_info * entry_info ;
phar_archive_data * phar_data ;
zval * zobj = getThis ( ) , arg1 ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s " , & fname , & fname_len ) = = FAILURE ) {
return ;
}
entry_obj = ( phar_entry_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
if ( entry_obj - > ent . entry ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Cannot call constructor twice " ) ;
return ;
}
2008-04-24 13:18:50 +08:00
if ( fname_len < 7 | | memcmp ( fname , " phar:// " , 7 ) | | phar_split_fname ( fname , fname_len , & arch , & arch_len , & entry , & entry_len , 2 , 0 TSRMLS_CC ) = = FAILURE ) {
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC ,
" '%s' is not a valid phar archive URL (must have at least phar://filename.phar) " , fname ) ;
2007-01-21 23:25:50 +08:00
return ;
}
2007-01-29 14:02:19 +08:00
if ( phar_open_filename ( arch , arch_len , NULL , 0 , REPORT_ERRORS , & phar_data , & error TSRMLS_CC ) = = FAILURE ) {
2007-01-21 23:25:50 +08:00
efree ( arch ) ;
efree ( entry ) ;
2007-01-29 14:02:19 +08:00
if ( error ) {
2008-04-24 13:18:50 +08:00
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC ,
2007-01-29 14:02:19 +08:00
" Cannot open phar file '%s': %s " , fname , error ) ;
efree ( error ) ;
} else {
2008-04-24 13:18:50 +08:00
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC ,
2007-01-29 14:02:19 +08:00
" Cannot open phar file '%s' " , fname ) ;
}
2007-01-21 23:25:50 +08:00
return ;
}
2007-10-04 11:33:21 +08:00
if ( ( entry_info = phar_get_entry_info_dir ( phar_data , entry , entry_len , 1 , & error TSRMLS_CC ) ) = = NULL ) {
2008-04-24 13:18:50 +08:00
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC ,
2007-02-05 04:10:03 +08:00
" Cannot access phar file entry '%s' in archive '%s'%s%s " , entry , arch , error ? " , " : " " , error ? error : " " ) ;
2007-10-04 11:33:21 +08:00
efree ( arch ) ;
2007-01-21 23:25:50 +08:00
efree ( entry ) ;
return ;
}
efree ( arch ) ;
efree ( entry ) ;
entry_obj - > ent . entry = entry_info ;
INIT_PZVAL ( & arg1 ) ;
ZVAL_STRINGL ( & arg1 , fname , fname_len , 0 ) ;
zend_call_method_with_1_params ( & zobj , Z_OBJCE_P ( zobj ) ,
& spl_ce_SplFileInfo - > constructor , " __construct " , NULL , & arg1 ) ;
}
/* }}} */
# define PHAR_ENTRY_OBJECT() \
phar_entry_object * entry_obj = ( phar_entry_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ; \
if ( ! entry_obj - > ent . entry ) { \
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , \
2007-01-24 07:31:14 +08:00
" Cannot call method on an uninitialized PharFileInfo object " ) ; \
2007-01-21 23:25:50 +08:00
return ; \
}
2007-10-04 11:33:21 +08:00
/* {{{ proto void PharFileInfo::__destruct()
* clean up directory - based entry objects
*/
PHP_METHOD ( PharFileInfo , __destruct )
{
2008-03-22 07:56:52 +08:00
phar_entry_object * entry_obj = ( phar_entry_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ; \
2007-10-04 11:33:21 +08:00
2008-03-22 07:56:52 +08:00
if ( entry_obj - > ent . entry & & entry_obj - > ent . entry - > is_temp_dir ) {
2008-01-07 13:41:09 +08:00
if ( entry_obj - > ent . entry - > filename ) {
2007-10-04 11:33:21 +08:00
efree ( entry_obj - > ent . entry - > filename ) ;
entry_obj - > ent . entry - > filename = NULL ;
}
efree ( entry_obj - > ent . entry ) ;
entry_obj - > ent . entry = NULL ;
}
}
/* }}} */
2007-01-21 23:25:50 +08:00
/* {{{ proto int PharFileInfo::getCompressedSize()
* Returns the compressed size
*/
PHP_METHOD ( PharFileInfo , getCompressedSize )
{
PHAR_ENTRY_OBJECT ( ) ;
2007-10-04 11:33:21 +08:00
2007-01-21 23:25:50 +08:00
RETURN_LONG ( entry_obj - > ent . entry - > compressed_filesize ) ;
}
/* }}} */
2008-04-11 21:07:14 +08:00
/* {{{ proto bool PharFileInfo::isCompressed([int compression_type])
* Returns whether the entry is compressed , and whether it is compressed with Phar : : GZ or Phar : : BZ2 if specified
2007-01-21 23:25:50 +08:00
*/
PHP_METHOD ( PharFileInfo , isCompressed )
{
2008-04-11 21:07:14 +08:00
/* a number that is not Phar::GZ or Phar::BZ2 */
long method = 9021976 ;
2007-01-21 23:25:50 +08:00
PHAR_ENTRY_OBJECT ( ) ;
2008-04-11 21:26:03 +08:00
2008-04-11 21:07:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |l " , & method ) = = FAILURE ) {
return ;
}
switch ( method ) {
case 9021976 :
RETURN_BOOL ( entry_obj - > ent . entry - > flags & PHAR_ENT_COMPRESSION_MASK ) ;
case PHAR_ENT_COMPRESSED_GZ :
RETURN_BOOL ( entry_obj - > ent . entry - > flags & PHAR_ENT_COMPRESSED_GZ ) ;
case PHAR_ENT_COMPRESSED_BZ2 :
RETURN_BOOL ( entry_obj - > ent . entry - > flags & PHAR_ENT_COMPRESSED_BZ2 ) ;
default :
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , \
" Unknown compression type specified " ) ; \
}
2007-01-21 23:25:50 +08:00
}
/* }}} */
/* {{{ proto int PharFileInfo::getCRC32()
* Returns CRC32 code or throws an exception if not CRC checked
*/
PHP_METHOD ( PharFileInfo , getCRC32 )
{
PHAR_ENTRY_OBJECT ( ) ;
2007-10-04 11:33:21 +08:00
if ( entry_obj - > ent . entry - > is_dir ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , \
" Phar entry is a directory, does not have a CRC " ) ; \
2008-01-14 13:12:46 +08:00
return ;
2007-10-04 11:33:21 +08:00
}
2007-01-21 23:25:50 +08:00
if ( entry_obj - > ent . entry - > is_crc_checked ) {
RETURN_LONG ( entry_obj - > ent . entry - > crc32 ) ;
} else {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , \
" Phar entry was not CRC checked " ) ; \
}
}
/* }}} */
/* {{{ proto int PharFileInfo::isCRCChecked()
* Returns whether file entry is CRC checked
*/
PHP_METHOD ( PharFileInfo , isCRCChecked )
{
PHAR_ENTRY_OBJECT ( ) ;
RETURN_BOOL ( entry_obj - > ent . entry - > is_crc_checked ) ;
}
/* }}} */
/* {{{ proto int PharFileInfo::getPharFlags()
* Returns the Phar file entry flags
*/
PHP_METHOD ( PharFileInfo , getPharFlags )
{
PHAR_ENTRY_OBJECT ( ) ;
RETURN_LONG ( entry_obj - > ent . entry - > flags & ~ ( PHAR_ENT_PERM_MASK | PHAR_ENT_COMPRESSION_MASK ) ) ;
}
/* }}} */
2007-02-06 13:41:18 +08:00
/* {{{ proto int PharFileInfo::chmod()
* set the file permissions for the Phar . This only allows setting execution bit , read / write
*/
PHP_METHOD ( PharFileInfo , chmod )
{
2007-02-07 01:09:37 +08:00
char * error ;
2007-02-06 13:41:18 +08:00
long perms ;
PHAR_ENTRY_OBJECT ( ) ;
2008-01-09 06:14:16 +08:00
if ( entry_obj - > ent . entry - > is_temp_dir ) {
2007-10-04 11:33:21 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , \
" Phar entry is a directory, cannot chmod " ) ; \
2008-01-08 15:08:46 +08:00
return ;
2007-10-04 11:33:21 +08:00
}
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! entry_obj - > ent . entry - > phar - > is_data ) {
2008-01-08 15:08:46 +08:00
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , " Cannot modify permissions for file \" %s \" in phar \" %s \" , write operations are prohibited " , entry_obj - > ent . entry - > filename , entry_obj - > ent . entry - > phar - > fname ) ;
return ;
}
2007-02-06 13:41:18 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " l " , & perms ) = = FAILURE ) {
return ;
}
/* clear permissions */
entry_obj - > ent . entry - > flags & = ~ PHAR_ENT_PERM_MASK ;
perms & = 0777 ;
entry_obj - > ent . entry - > flags | = perms ;
2007-08-17 12:47:50 +08:00
entry_obj - > ent . entry - > old_flags = entry_obj - > ent . entry - > flags ;
2007-02-07 01:09:37 +08:00
entry_obj - > ent . entry - > phar - > is_modified = 1 ;
entry_obj - > ent . entry - > is_modified = 1 ;
/* hackish cache in php_stat needs to be cleared */
/* if this code fails to work, check main/streams/streams.c, _php_stream_stat_path */
if ( BG ( CurrentLStatFile ) ) {
efree ( BG ( CurrentLStatFile ) ) ;
}
if ( BG ( CurrentStatFile ) ) {
efree ( BG ( CurrentStatFile ) ) ;
}
BG ( CurrentLStatFile ) = NULL ;
BG ( CurrentStatFile ) = NULL ;
2008-02-25 06:29:06 +08:00
phar_flush ( entry_obj - > ent . entry - > phar , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-02-07 01:09:37 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
2007-02-06 13:41:18 +08:00
}
/* }}} */
2007-05-15 01:13:07 +08:00
/* {{{ proto int PharFileInfo::hasMetaData()
* Returns the metadata of the entry
*/
PHP_METHOD ( PharFileInfo , hasMetadata )
{
PHAR_ENTRY_OBJECT ( ) ;
RETURN_BOOL ( entry_obj - > ent . entry - > metadata ! = NULL ) ;
}
/* }}} */
2007-01-22 04:12:50 +08:00
/* {{{ proto int PharFileInfo::getMetaData()
* Returns the metadata of the entry
*/
PHP_METHOD ( PharFileInfo , getMetadata )
{
PHAR_ENTRY_OBJECT ( ) ;
2007-02-06 13:41:18 +08:00
2007-01-22 04:12:50 +08:00
if ( entry_obj - > ent . entry - > metadata ) {
RETURN_ZVAL ( entry_obj - > ent . entry - > metadata , 1 , 0 ) ;
}
}
/* }}} */
/* {{{ proto int PharFileInfo::setMetaData(mixed $metadata)
2007-05-15 01:13:07 +08:00
* Sets the metadata of the entry
2007-01-22 04:12:50 +08:00
*/
PHP_METHOD ( PharFileInfo , setMetadata )
{
2007-05-15 02:11:53 +08:00
char * error ;
2007-01-22 04:12:50 +08:00
zval * metadata ;
PHAR_ENTRY_OBJECT ( ) ;
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! entry_obj - > ent . entry - > phar - > is_data ) {
2008-01-21 13:28:09 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Write operations disabled by INI setting " ) ;
return ;
}
2008-01-03 12:45:00 +08:00
if ( entry_obj - > ent . entry - > is_tar ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot set metadata, not possible with tar-based phar archives " ) ;
2008-01-14 13:12:46 +08:00
return ;
2008-01-03 12:45:00 +08:00
}
2007-10-04 11:33:21 +08:00
if ( entry_obj - > ent . entry - > is_dir ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , \
" Phar entry is a directory, cannot set metadata " ) ; \
2008-01-14 13:12:46 +08:00
return ;
2007-10-04 11:33:21 +08:00
}
2007-01-22 04:12:50 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " z " , & metadata ) = = FAILURE ) {
return ;
}
if ( entry_obj - > ent . entry - > metadata ) {
zval_ptr_dtor ( & entry_obj - > ent . entry - > metadata ) ;
entry_obj - > ent . entry - > metadata = NULL ;
}
MAKE_STD_ZVAL ( entry_obj - > ent . entry - > metadata ) ;
ZVAL_ZVAL ( entry_obj - > ent . entry - > metadata , metadata , 1 , 0 ) ;
2007-05-15 02:11:53 +08:00
2008-02-25 06:29:06 +08:00
phar_flush ( entry_obj - > ent . entry - > phar , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-05-15 02:11:53 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
2007-01-22 04:12:50 +08:00
}
/* }}} */
2007-05-15 01:13:07 +08:00
/* {{{ proto bool PharFileInfo::delMetaData()
* Deletes the metadata of the entry
*/
PHP_METHOD ( PharFileInfo , delMetadata )
{
2007-05-15 02:11:53 +08:00
char * error ;
2007-05-15 01:13:07 +08:00
PHAR_ENTRY_OBJECT ( ) ;
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! entry_obj - > ent . entry - > phar - > is_data ) {
2008-01-21 13:28:09 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Write operations disabled by INI setting " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-10-04 11:33:21 +08:00
}
2008-03-24 11:01:31 +08:00
if ( entry_obj - > ent . entry - > is_tar ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot delete metadata, not possible with tar-based phar archives " ) ;
return ;
}
2008-01-21 13:28:09 +08:00
if ( entry_obj - > ent . entry - > is_temp_dir ) {
RETURN_FALSE ;
}
2007-05-15 01:13:07 +08:00
if ( entry_obj - > ent . entry - > metadata ) {
zval_ptr_dtor ( & entry_obj - > ent . entry - > metadata ) ;
entry_obj - > ent . entry - > metadata = NULL ;
2007-05-15 02:11:53 +08:00
2008-02-25 06:29:06 +08:00
phar_flush ( entry_obj - > ent . entry - > phar , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-05-15 02:11:53 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
RETURN_FALSE ;
} else {
RETURN_TRUE ;
}
2007-05-15 01:13:07 +08:00
} else {
2007-11-25 13:04:40 +08:00
RETURN_TRUE ;
2007-05-15 01:13:07 +08:00
}
}
/* }}} */
2008-04-10 21:41:29 +08:00
/* {{{ proto string PharFileInfo::getContent()
2008-04-10 02:12:41 +08:00
* return the complete file contents of the entry ( like file_get_contents )
*/
2008-04-10 21:41:29 +08:00
PHP_METHOD ( PharFileInfo , getContent )
2008-04-10 02:12:41 +08:00
{
char * error ;
php_stream * fp ;
2008-04-21 14:17:51 +08:00
phar_entry_info * link ;
2008-04-10 02:12:41 +08:00
PHAR_ENTRY_OBJECT ( ) ;
if ( entry_obj - > ent . entry - > is_dir ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Phar error: Cannot retrieve contents, \" %s \" in phar \" %s \" is a directory " , entry_obj - > ent . entry - > filename , entry_obj - > ent . entry - > phar - > fname ) ;
return ;
}
2008-04-21 14:17:51 +08:00
link = phar_get_link_source ( entry_obj - > ent . entry TSRMLS_CC ) ;
if ( ! link ) {
link = entry_obj - > ent . entry ;
}
if ( SUCCESS ! = phar_open_entry_fp ( link , & error , 0 TSRMLS_CC ) ) {
2008-04-10 02:12:41 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Phar error: Cannot retrieve contents, \" %s \" in phar \" %s \" : %s " , entry_obj - > ent . entry - > filename , entry_obj - > ent . entry - > phar - > fname , error ) ;
efree ( error ) ;
return ;
}
2008-04-21 14:17:51 +08:00
if ( ! ( fp = phar_get_efp ( link , 0 TSRMLS_CC ) ) ) {
2008-04-10 02:12:41 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Phar error: Cannot retrieve contents of \" %s \" in phar \" %s \" " , entry_obj - > ent . entry - > filename , entry_obj - > ent . entry - > phar - > fname ) ;
return ;
}
2008-04-21 14:17:51 +08:00
phar_seek_efp ( link , 0 , SEEK_SET , 0 , 0 TSRMLS_CC ) ;
2008-04-10 02:12:41 +08:00
Z_TYPE_P ( return_value ) = IS_STRING ;
2008-04-21 14:17:51 +08:00
Z_STRLEN_P ( return_value ) = php_stream_copy_to_mem ( fp , & ( Z_STRVAL_P ( return_value ) ) , link - > uncompressed_filesize , 0 ) ;
if ( ! Z_STRVAL_P ( return_value ) ) {
Z_STRVAL_P ( return_value ) = estrndup ( " " , 0 ) ;
}
2008-04-10 02:12:41 +08:00
}
/* }}} */
2008-04-11 21:26:03 +08:00
/* {{{ proto int PharFileInfo::compress(int compression_type)
* Instructs the Phar class to compress the current file using zlib or bzip2 compression
2007-01-22 08:13:20 +08:00
*/
2008-04-11 21:26:03 +08:00
PHP_METHOD ( PharFileInfo , compress )
2007-01-22 08:13:20 +08:00
{
2008-04-11 21:26:03 +08:00
long method = 9021976 ;
2007-01-29 14:02:19 +08:00
char * error ;
2007-01-22 08:13:20 +08:00
PHAR_ENTRY_OBJECT ( ) ;
2008-04-11 21:26:03 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " l " , & method ) = = FAILURE ) {
return ;
}
2008-01-03 12:45:00 +08:00
if ( entry_obj - > ent . entry - > is_tar ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress with Gzip compression, not possible with tar-based phar archives " ) ;
2008-01-14 13:12:46 +08:00
return ;
2008-01-03 12:45:00 +08:00
}
2007-10-04 11:33:21 +08:00
if ( entry_obj - > ent . entry - > is_dir ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , \
" Phar entry is a directory, cannot set compression " ) ; \
2008-01-14 13:12:46 +08:00
return ;
2007-10-04 11:33:21 +08:00
}
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! entry_obj - > ent . entry - > phar - > is_data ) {
2007-01-22 08:13:20 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Phar is readonly, cannot change compression " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-01-22 08:13:20 +08:00
}
if ( entry_obj - > ent . entry - > is_deleted ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress deleted file " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-01-22 08:13:20 +08:00
}
2008-04-11 21:26:03 +08:00
switch ( method ) {
case PHAR_ENT_COMPRESSED_GZ :
if ( entry_obj - > ent . entry - > flags & PHAR_ENT_COMPRESSED_GZ ) {
RETURN_TRUE ;
return ;
}
if ( ( entry_obj - > ent . entry - > flags & PHAR_ENT_COMPRESSED_BZ2 ) ! = 0 ) {
if ( ! phar_has_bz2 ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress with gzip compression, file is already compressed with bzip2 compression and bz2 extension is not enabled, cannot decompress " ) ;
return ;
}
/* decompress this file indirectly */
2008-04-21 14:17:51 +08:00
if ( SUCCESS ! = phar_open_entry_fp ( entry_obj - > ent . entry , & error , 1 TSRMLS_CC ) ) {
2008-04-11 21:26:03 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Phar error: Cannot decompress bzip2-compressed file \" %s \" in phar \" %s \" in order to compress with gzip: %s " , entry_obj - > ent . entry - > filename , entry_obj - > ent . entry - > phar - > fname , error ) ;
efree ( error ) ;
return ;
}
}
2008-04-25 03:57:22 +08:00
if ( ! phar_has_zlib ) {
2008-04-11 21:26:03 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress with gzip compression, zlib extension is not enabled " ) ;
return ;
}
entry_obj - > ent . entry - > old_flags = entry_obj - > ent . entry - > flags ;
entry_obj - > ent . entry - > flags & = ~ PHAR_ENT_COMPRESSION_MASK ;
entry_obj - > ent . entry - > flags | = PHAR_ENT_COMPRESSED_GZ ;
break ;
case PHAR_ENT_COMPRESSED_BZ2 :
if ( entry_obj - > ent . entry - > flags & PHAR_ENT_COMPRESSED_BZ2 ) {
RETURN_TRUE ;
return ;
}
if ( ( entry_obj - > ent . entry - > flags & PHAR_ENT_COMPRESSED_GZ ) ! = 0 ) {
if ( ! phar_has_zlib ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress with bzip2 compression, file is already compressed with gzip compression and zlib extension is not enabled, cannot decompress " ) ;
return ;
}
/* decompress this file indirectly */
2008-04-21 14:17:51 +08:00
if ( SUCCESS ! = phar_open_entry_fp ( entry_obj - > ent . entry , & error , 1 TSRMLS_CC ) ) {
2008-04-11 21:26:03 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Phar error: Cannot decompress gzip-compressed file \" %s \" in phar \" %s \" in order to compress with bzip2: %s " , entry_obj - > ent . entry - > filename , entry_obj - > ent . entry - > phar - > fname , error ) ;
efree ( error ) ;
return ;
}
}
2008-04-25 03:57:22 +08:00
if ( ! phar_has_bz2 ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress with bzip2 compression, bz2 extension is not enabled " ) ;
return ;
}
2008-04-11 21:26:03 +08:00
entry_obj - > ent . entry - > old_flags = entry_obj - > ent . entry - > flags ;
entry_obj - > ent . entry - > flags & = ~ PHAR_ENT_COMPRESSION_MASK ;
entry_obj - > ent . entry - > flags | = PHAR_ENT_COMPRESSED_BZ2 ;
break ;
default :
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , \
" Unknown compression type specified " ) ; \
2007-01-29 14:02:19 +08:00
}
2007-01-22 08:13:20 +08:00
entry_obj - > ent . entry - > phar - > is_modified = 1 ;
entry_obj - > ent . entry - > is_modified = 1 ;
2008-02-25 06:29:06 +08:00
phar_flush ( entry_obj - > ent . entry - > phar , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-01-29 14:02:19 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
2007-01-22 08:13:20 +08:00
RETURN_TRUE ;
}
/* }}} */
2008-04-11 20:56:53 +08:00
/* {{{ proto int PharFileInfo::decompress()
* Instructs the Phar class to decompress the current file
2007-01-22 08:13:20 +08:00
*/
2008-04-11 20:56:53 +08:00
PHP_METHOD ( PharFileInfo , decompress )
2007-01-22 08:13:20 +08:00
{
2008-04-25 03:57:22 +08:00
char * error ;
2007-01-22 08:13:20 +08:00
PHAR_ENTRY_OBJECT ( ) ;
2007-10-04 11:33:21 +08:00
if ( entry_obj - > ent . entry - > is_dir ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , \
" Phar entry is a directory, cannot set compression " ) ; \
2008-01-14 13:12:46 +08:00
return ;
2007-10-04 11:33:21 +08:00
}
2007-01-22 08:13:20 +08:00
if ( ( entry_obj - > ent . entry - > flags & PHAR_ENT_COMPRESSION_MASK ) = = 0 ) {
RETURN_TRUE ;
return ;
}
2008-03-24 11:01:31 +08:00
if ( PHAR_G ( readonly ) & & ! entry_obj - > ent . entry - > phar - > is_data ) {
2007-01-22 08:13:20 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
2008-04-25 03:57:22 +08:00
" Phar is readonly, cannot decompress " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-01-22 08:13:20 +08:00
}
if ( entry_obj - > ent . entry - > is_deleted ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
" Cannot compress deleted file " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-01-22 08:13:20 +08:00
}
2008-04-11 21:26:03 +08:00
if ( ( entry_obj - > ent . entry - > flags & PHAR_ENT_COMPRESSED_GZ ) ! = 0 & & ! phar_has_zlib ) {
2007-11-25 13:04:40 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
2008-04-11 20:56:53 +08:00
" Cannot decompress Gzip-compressed file, zlib extension is not enabled " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-11-25 13:04:40 +08:00
}
2008-04-11 21:26:03 +08:00
if ( ( entry_obj - > ent . entry - > flags & PHAR_ENT_COMPRESSED_BZ2 ) ! = 0 & & ! phar_has_bz2 ) {
2007-11-24 12:06:44 +08:00
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC ,
2008-04-11 20:56:53 +08:00
" Cannot decompress Bzip2-compressed file, bz2 extension is not enabled " ) ;
2008-01-14 13:12:46 +08:00
return ;
2007-11-24 12:06:44 +08:00
}
2007-01-26 22:52:10 +08:00
if ( ! entry_obj - > ent . entry - > fp ) {
2008-04-25 03:57:22 +08:00
if ( FAILURE = = phar_open_archive_fp ( entry_obj - > ent . entry - > phar TSRMLS_CC ) ) {
zend_throw_exception_ex ( spl_ce_BadMethodCallException , 0 TSRMLS_CC , " Cannot decompress entry \" %s \" , phar error: Cannot open phar archive \" %s \" for reading " , entry_obj - > ent . entry - > filename , entry_obj - > ent . entry - > phar - > fname ) ;
return ;
}
entry_obj - > ent . entry - > fp_type = PHAR_FP ;
2007-01-22 08:13:20 +08:00
}
2007-08-17 12:47:50 +08:00
entry_obj - > ent . entry - > old_flags = entry_obj - > ent . entry - > flags ;
2007-01-22 08:13:20 +08:00
entry_obj - > ent . entry - > flags & = ~ PHAR_ENT_COMPRESSION_MASK ;
entry_obj - > ent . entry - > phar - > is_modified = 1 ;
entry_obj - > ent . entry - > is_modified = 1 ;
2008-02-25 06:29:06 +08:00
phar_flush ( entry_obj - > ent . entry - > phar , 0 , 0 , 0 , & error TSRMLS_CC ) ;
2007-01-29 14:02:19 +08:00
if ( error ) {
zend_throw_exception_ex ( phar_ce_PharException , 0 TSRMLS_CC , error ) ;
efree ( error ) ;
}
2007-01-22 08:13:20 +08:00
RETURN_TRUE ;
}
/* }}} */
2007-01-21 23:25:50 +08:00
# endif /* HAVE_SPL */
/* {{{ phar methods */
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar___construct , 0 , 0 , 1 )
2008-02-21 01:58:56 +08:00
ZEND_ARG_INFO ( 0 , filename )
2007-01-21 23:25:50 +08:00
ZEND_ARG_INFO ( 0 , flags )
ZEND_ARG_INFO ( 0 , alias )
ZEND_END_ARG_INFO ( ) ;
2008-02-21 01:58:56 +08:00
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_createDS , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , index )
ZEND_ARG_INFO ( 0 , webindex )
ZEND_END_ARG_INFO ( ) ;
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_loadPhar , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , filename )
ZEND_ARG_INFO ( 0 , alias )
ZEND_END_ARG_INFO ( ) ;
2007-01-21 23:25:50 +08:00
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_mapPhar , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , alias )
2007-12-24 05:12:42 +08:00
ZEND_ARG_INFO ( 0 , offset )
ZEND_END_ARG_INFO ( ) ;
2008-02-21 01:58:56 +08:00
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_mount , 0 , 0 , 2 )
ZEND_ARG_INFO ( 0 , inphar )
ZEND_ARG_INFO ( 0 , externalfile )
ZEND_END_ARG_INFO ( ) ;
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_mungServer , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , munglist )
ZEND_END_ARG_INFO ( ) ;
2007-12-24 05:12:42 +08:00
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_webPhar , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , alias )
2007-12-25 04:30:44 +08:00
ZEND_ARG_INFO ( 0 , index )
2007-12-29 09:37:12 +08:00
ZEND_ARG_INFO ( 0 , f404 )
2007-12-24 05:12:42 +08:00
ZEND_ARG_INFO ( 0 , mimetypes )
2007-12-29 10:38:29 +08:00
ZEND_ARG_INFO ( 0 , rewrites )
2007-01-21 23:25:50 +08:00
ZEND_END_ARG_INFO ( ) ;
2008-04-13 05:43:39 +08:00
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_running , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , retphar )
ZEND_END_ARG_INFO ( ) ;
2008-02-21 01:58:56 +08:00
# if HAVE_SPL
2008-01-04 12:57:11 +08:00
static
2008-02-21 01:58:56 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_build , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , iterator )
ZEND_ARG_INFO ( 0 , base_directory )
2008-01-04 12:57:11 +08:00
ZEND_END_ARG_INFO ( ) ;
2008-01-19 12:26:22 +08:00
static
2008-02-21 01:58:56 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_conv , 0 , 0 , 0 )
2008-04-11 12:20:15 +08:00
ZEND_ARG_INFO ( 0 , format )
ZEND_ARG_INFO ( 0 , compression_type )
2008-02-25 20:21:19 +08:00
ZEND_ARG_INFO ( 0 , file_ext )
ZEND_END_ARG_INFO ( ) ;
2008-04-11 21:41:59 +08:00
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_comps , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , compression_type )
ZEND_ARG_INFO ( 0 , file_ext )
ZEND_END_ARG_INFO ( ) ;
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_decomp , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , file_ext )
ZEND_END_ARG_INFO ( ) ;
2008-02-25 20:21:19 +08:00
static
2008-03-24 06:42:45 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_comp , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , compression_type )
2008-01-19 12:26:22 +08:00
ZEND_END_ARG_INFO ( ) ;
2008-04-11 21:26:03 +08:00
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_compo , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , compression_type )
ZEND_END_ARG_INFO ( ) ;
2007-01-22 07:22:57 +08:00
static
2008-02-21 01:58:56 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_copy , 0 , 0 , 2 )
ZEND_ARG_INFO ( 0 , newfile )
ZEND_ARG_INFO ( 0 , oldfile )
2007-01-22 07:22:57 +08:00
ZEND_END_ARG_INFO ( ) ;
2007-01-21 23:25:50 +08:00
static
2008-02-21 01:58:56 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_delete , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , entry )
2007-01-21 23:25:50 +08:00
ZEND_END_ARG_INFO ( ) ;
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_offsetExists , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , entry )
ZEND_END_ARG_INFO ( ) ;
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_offsetSet , 0 , 0 , 2 )
ZEND_ARG_INFO ( 0 , entry )
ZEND_ARG_INFO ( 0 , value )
ZEND_END_ARG_INFO ( ) ;
2007-12-13 02:01:40 +08:00
static
2008-02-21 01:58:56 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_setAlias , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , alias )
2007-12-13 02:01:40 +08:00
ZEND_END_ARG_INFO ( ) ;
2007-12-16 08:57:39 +08:00
static
2008-02-21 01:58:56 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_setMetadata , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , metadata )
2007-12-16 08:57:39 +08:00
ZEND_END_ARG_INFO ( ) ;
2008-01-17 05:09:32 +08:00
2008-02-18 12:32:50 +08:00
static
2008-02-21 01:58:56 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_setSigAlgo , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , algorithm )
2008-02-18 12:32:50 +08:00
ZEND_END_ARG_INFO ( ) ;
2008-01-17 05:09:32 +08:00
static
2008-02-21 01:58:56 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_setStub , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , newstub )
ZEND_ARG_INFO ( 0 , maxlen )
2008-01-17 05:09:32 +08:00
ZEND_END_ARG_INFO ( ) ;
2007-01-21 23:25:50 +08:00
2008-04-10 03:23:31 +08:00
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_emptydir , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , dirname )
ZEND_END_ARG_INFO ( ) ;
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_addfile , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , filename )
ZEND_ARG_INFO ( 0 , localname )
ZEND_END_ARG_INFO ( ) ;
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_phar_fromstring , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , localname )
ZEND_ARG_INFO ( 0 , contents )
ZEND_END_ARG_INFO ( ) ;
2008-02-21 01:58:56 +08:00
# endif /* HAVE_SPL */
2007-01-29 11:59:55 +08:00
2007-01-21 23:25:50 +08:00
zend_function_entry php_archive_methods [ ] = {
# if !HAVE_SPL
2007-01-28 03:26:58 +08:00
PHP_ME ( Phar , __construct , arginfo_phar___construct , ZEND_ACC_PRIVATE )
2007-01-21 23:25:50 +08:00
# else
2007-01-28 03:26:58 +08:00
PHP_ME ( Phar , __construct , arginfo_phar___construct , ZEND_ACC_PUBLIC )
2008-04-10 03:23:31 +08:00
PHP_ME ( Phar , addEmptyDir , arginfo_phar_emptydir , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , addFile , arginfo_phar_addfile , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , addFromString , arginfo_phar_fromstring , ZEND_ACC_PUBLIC )
2008-02-21 01:58:56 +08:00
PHP_ME ( Phar , buildFromIterator , arginfo_phar_build , ZEND_ACC_PUBLIC )
2008-04-10 21:40:26 +08:00
PHP_ME ( Phar , compressFiles , arginfo_phar_comp , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , decompressFiles , NULL , ZEND_ACC_PUBLIC )
2008-04-11 21:41:59 +08:00
PHP_ME ( Phar , compress , arginfo_phar_comps , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , decompress , arginfo_phar_decomp , ZEND_ACC_PUBLIC )
2008-04-11 12:20:15 +08:00
PHP_ME ( Phar , convertToExecutable , arginfo_phar_conv , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , convertToData , arginfo_phar_conv , ZEND_ACC_PUBLIC )
2007-12-16 08:57:39 +08:00
PHP_ME ( Phar , copy , arginfo_phar_copy , ZEND_ACC_PUBLIC )
2007-01-28 03:26:58 +08:00
PHP_ME ( Phar , count , NULL , ZEND_ACC_PUBLIC )
2008-02-21 01:58:56 +08:00
PHP_ME ( Phar , delete , arginfo_phar_delete , ZEND_ACC_PUBLIC )
2007-05-16 04:42:38 +08:00
PHP_ME ( Phar , delMetadata , NULL , ZEND_ACC_PUBLIC )
2007-05-19 01:50:39 +08:00
PHP_ME ( Phar , getAlias , NULL , ZEND_ACC_PUBLIC )
2008-03-24 03:03:15 +08:00
PHP_ME ( Phar , getPath , NULL , ZEND_ACC_PUBLIC )
2007-01-31 04:58:14 +08:00
PHP_ME ( Phar , getMetadata , NULL , ZEND_ACC_PUBLIC )
2007-01-28 03:26:58 +08:00
PHP_ME ( Phar , getModified , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , getSignature , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , getStub , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , getVersion , NULL , ZEND_ACC_PUBLIC )
2007-05-16 04:42:38 +08:00
PHP_ME ( Phar , hasMetadata , NULL , ZEND_ACC_PUBLIC )
2008-02-21 01:58:56 +08:00
PHP_ME ( Phar , isBuffering , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , isCompressed , NULL , ZEND_ACC_PUBLIC )
2008-04-10 11:32:10 +08:00
PHP_ME ( Phar , isWritable , NULL , ZEND_ACC_PUBLIC )
2008-02-21 01:58:56 +08:00
PHP_ME ( Phar , isPhar , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , isTar , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , isZip , NULL , ZEND_ACC_PUBLIC )
2007-01-28 03:26:58 +08:00
PHP_ME ( Phar , offsetExists , arginfo_phar_offsetExists , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , offsetGet , arginfo_phar_offsetExists , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , offsetSet , arginfo_phar_offsetSet , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , offsetUnset , arginfo_phar_offsetExists , ZEND_ACC_PUBLIC )
2008-02-21 01:58:56 +08:00
PHP_ME ( Phar , setAlias , arginfo_phar_setAlias , ZEND_ACC_PUBLIC )
2008-02-21 03:22:12 +08:00
PHP_ME ( Phar , setDefaultStub , arginfo_phar_createDS , ZEND_ACC_PUBLIC )
2008-02-21 01:58:56 +08:00
PHP_ME ( Phar , setMetadata , arginfo_phar_setMetadata , ZEND_ACC_PUBLIC )
2008-04-11 21:26:36 +08:00
PHP_ME ( Phar , setSignatureAlgorithm , arginfo_phar_setSigAlgo , ZEND_ACC_PUBLIC )
2008-02-21 01:58:56 +08:00
PHP_ME ( Phar , setStub , arginfo_phar_setStub , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , startBuffering , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( Phar , stopBuffering , NULL , ZEND_ACC_PUBLIC )
2007-01-21 23:25:50 +08:00
# endif
/* static member functions */
2007-01-28 03:26:58 +08:00
PHP_ME ( Phar , apiVersion , NULL , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
PHP_ME ( Phar , canCompress , NULL , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
PHP_ME ( Phar , canWrite , NULL , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
2008-02-21 01:58:56 +08:00
PHP_ME ( Phar , createDefaultStub , arginfo_phar_createDS , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
PHP_ME ( Phar , getExtractList , NULL , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
PHP_ME ( Phar , getSupportedCompression , NULL , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
PHP_ME ( Phar , getSupportedSignatures , NULL , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
PHP_ME ( Phar , interceptFileFuncs , NULL , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
PHP_ME ( Phar , isValidPharFilename , NULL , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
2007-01-28 03:26:58 +08:00
PHP_ME ( Phar , loadPhar , arginfo_phar_loadPhar , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
PHP_ME ( Phar , mapPhar , arginfo_phar_mapPhar , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
2008-03-23 14:00:31 +08:00
PHP_ME ( Phar , running , arginfo_phar_running , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
2008-02-18 12:32:50 +08:00
PHP_ME ( Phar , mount , arginfo_phar_mount , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
2008-01-04 12:57:11 +08:00
PHP_ME ( Phar , mungServer , arginfo_phar_mungServer , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
2008-02-21 01:58:56 +08:00
PHP_ME ( Phar , webPhar , arginfo_phar_webPhar , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_FINAL )
2007-01-21 23:25:50 +08:00
{ NULL , NULL , NULL }
} ;
# if HAVE_SPL
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_entry___construct , 0 , 0 , 1 )
2008-02-21 01:58:56 +08:00
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( ) ;
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_entry_chmod , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , perms )
2007-01-21 23:25:50 +08:00
ZEND_END_ARG_INFO ( ) ;
zend_function_entry php_entry_methods [ ] = {
2008-04-11 21:26:03 +08:00
PHP_ME ( PharFileInfo , __construct , arginfo_entry___construct , ZEND_ACC_PUBLIC )
PHP_ME ( PharFileInfo , __destruct , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( PharFileInfo , chmod , arginfo_entry_chmod , ZEND_ACC_PUBLIC )
PHP_ME ( PharFileInfo , delMetadata , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( PharFileInfo , getContent , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( PharFileInfo , getCompressedSize , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( PharFileInfo , getCRC32 , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( PharFileInfo , getMetadata , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( PharFileInfo , getPharFlags , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( PharFileInfo , hasMetadata , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( PharFileInfo , isCompressed , arginfo_phar_compo , ZEND_ACC_PUBLIC )
PHP_ME ( PharFileInfo , isCRCChecked , NULL , ZEND_ACC_PUBLIC )
PHP_ME ( PharFileInfo , compress , arginfo_phar_comp , ZEND_ACC_PUBLIC )
PHP_ME ( PharFileInfo , setMetadata , arginfo_phar_setMetadata , ZEND_ACC_PUBLIC )
PHP_ME ( PharFileInfo , decompress , NULL , ZEND_ACC_PUBLIC )
2007-01-21 23:25:50 +08:00
{ NULL , NULL , NULL }
} ;
2008-02-21 01:58:56 +08:00
# endif /* HAVE_SPL */
2007-01-29 14:02:19 +08:00
zend_function_entry phar_exception_methods [ ] = {
{ NULL , NULL , NULL }
} ;
2007-01-21 23:25:50 +08:00
/* }}} */
# 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 ) ;
2007-02-04 00:31:36 +08:00
# 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
2007-01-21 23:25:50 +08:00
void phar_object_init ( TSRMLS_D ) /* { { { */
{
zend_class_entry ce ;
2007-01-29 14:02:19 +08:00
INIT_CLASS_ENTRY ( ce , " PharException " , phar_exception_methods ) ;
2007-02-04 00:31:36 +08:00
phar_ce_PharException = zend_register_internal_class_ex ( & ce , phar_exception_get_default ( ) , NULL TSRMLS_CC ) ;
2007-01-29 14:02:19 +08:00
2007-01-21 23:25:50 +08:00
# if HAVE_SPL
INIT_CLASS_ENTRY ( ce , " Phar " , php_archive_methods ) ;
phar_ce_archive = zend_register_internal_class_ex ( & ce , spl_ce_RecursiveDirectoryIterator , NULL TSRMLS_CC ) ;
zend_class_implements ( phar_ce_archive TSRMLS_CC , 2 , spl_ce_Countable , zend_ce_arrayaccess ) ;
2008-02-28 05:34:26 +08:00
INIT_CLASS_ENTRY ( ce , " PharData " , php_archive_methods ) ;
phar_ce_data = zend_register_internal_class_ex ( & ce , spl_ce_RecursiveDirectoryIterator , NULL TSRMLS_CC ) ;
zend_class_implements ( phar_ce_data TSRMLS_CC , 2 , spl_ce_Countable , zend_ce_arrayaccess ) ;
2007-01-21 23:25:50 +08:00
INIT_CLASS_ENTRY ( ce , " PharFileInfo " , php_entry_methods ) ;
phar_ce_entry = zend_register_internal_class_ex ( & ce , spl_ce_SplFileInfo , NULL TSRMLS_CC ) ;
# else
INIT_CLASS_ENTRY ( ce , " Phar " , php_archive_methods ) ;
phar_ce_archive = zend_register_internal_class ( & ce TSRMLS_CC ) ;
phar_ce_archive - > ce_flags | = ZEND_ACC_FINAL_CLASS ;
2008-02-28 05:34:26 +08:00
INIT_CLASS_ENTRY ( ce , " PharData " , php_archive_methods ) ;
phar_ce_data = zend_register_internal_class ( & ce TSRMLS_CC ) ;
phar_ce_data - > ce_flags | = ZEND_ACC_FINAL_CLASS ;
2007-01-21 23:25:50 +08:00
# endif
REGISTER_PHAR_CLASS_CONST_LONG ( phar_ce_archive , " BZ2 " , PHAR_ENT_COMPRESSED_BZ2 )
2008-02-21 01:58:56 +08:00
REGISTER_PHAR_CLASS_CONST_LONG ( phar_ce_archive , " GZ " , PHAR_ENT_COMPRESSED_GZ )
2008-03-24 06:42:45 +08:00
REGISTER_PHAR_CLASS_CONST_LONG ( phar_ce_archive , " NONE " , PHAR_ENT_COMPRESSED_NONE )
2008-04-11 12:20:15 +08:00
REGISTER_PHAR_CLASS_CONST_LONG ( phar_ce_archive , " PHAR " , PHAR_FORMAT_PHAR )
REGISTER_PHAR_CLASS_CONST_LONG ( phar_ce_archive , " TAR " , PHAR_FORMAT_TAR )
REGISTER_PHAR_CLASS_CONST_LONG ( phar_ce_archive , " ZIP " , PHAR_FORMAT_ZIP )
2008-02-21 01:58:56 +08:00
REGISTER_PHAR_CLASS_CONST_LONG ( phar_ce_archive , " COMPRESSED " , PHAR_ENT_COMPRESSION_MASK )
REGISTER_PHAR_CLASS_CONST_LONG ( phar_ce_archive , " PHP " , PHAR_MIME_PHP )
REGISTER_PHAR_CLASS_CONST_LONG ( phar_ce_archive , " PHPS " , PHAR_MIME_PHPS )
2007-03-26 08:00:56 +08:00
REGISTER_PHAR_CLASS_CONST_LONG ( phar_ce_archive , " MD5 " , PHAR_SIG_MD5 )
2008-02-21 01:58:56 +08:00
REGISTER_PHAR_CLASS_CONST_LONG ( phar_ce_archive , " PGP " , PHAR_SIG_PGP )
2007-03-26 08:00:56 +08:00
REGISTER_PHAR_CLASS_CONST_LONG ( phar_ce_archive , " SHA1 " , PHAR_SIG_SHA1 )
REGISTER_PHAR_CLASS_CONST_LONG ( phar_ce_archive , " SHA256 " , PHAR_SIG_SHA256 )
REGISTER_PHAR_CLASS_CONST_LONG ( phar_ce_archive , " SHA512 " , PHAR_SIG_SHA512 )
2007-01-21 23:25:50 +08:00
}
/* }}} */
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
* vim600 : noet sw = 4 ts = 4 fdm = marker
* vim < 600 : noet sw = 4 ts = 4
*/