version 1.1.1.1, 2012/02/21 23:47:56
|
version 1.1.1.3, 2013/07/22 01:31:50
|
Line 2
|
Line 2
|
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| PHP Version 5 | |
| PHP Version 5 | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| Copyright (c) 1997-2012 The PHP Group | | | Copyright (c) 1997-2013 The PHP Group | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| This source file is subject to version 3.0 of the PHP license, | |
| This source file is subject to version 3.0 of the PHP license, | |
| that is bundled with this package in the file LICENSE, and is | |
| that is bundled with this package in the file LICENSE, and is | |
Line 76 struct finfo_object {
|
Line 76 struct finfo_object {
|
} \ |
} \ |
} |
} |
|
|
/* {{{ finfo_objects_dtor | /* {{{ finfo_objects_free |
*/ |
*/ |
static void finfo_objects_dtor(void *object, zend_object_handle handle TSRMLS_DC) | static void finfo_objects_free(void *object TSRMLS_DC) |
{ |
{ |
struct finfo_object *intern = (struct finfo_object *) object; |
struct finfo_object *intern = (struct finfo_object *) object; |
|
|
Line 98 PHP_FILEINFO_API zend_object_value finfo_objects_new(z
|
Line 98 PHP_FILEINFO_API zend_object_value finfo_objects_new(z
|
{ |
{ |
zend_object_value retval; |
zend_object_value retval; |
struct finfo_object *intern; |
struct finfo_object *intern; |
zval *tmp; |
|
|
|
intern = emalloc(sizeof(struct finfo_object)); |
intern = emalloc(sizeof(struct finfo_object)); |
memset(intern, 0, sizeof(struct finfo_object)); |
memset(intern, 0, sizeof(struct finfo_object)); |
|
|
zend_object_std_init(&intern->zo, class_type TSRMLS_CC); |
zend_object_std_init(&intern->zo, class_type TSRMLS_CC); |
zend_hash_copy(intern->zo.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &tmp, sizeof(zval *)); | object_properties_init(&intern->zo, class_type); |
|
|
intern->ptr = NULL; |
intern->ptr = NULL; |
|
|
retval.handle = zend_objects_store_put(intern, finfo_objects_dtor, NULL, NULL TSRMLS_CC); | retval.handle = zend_objects_store_put(intern, NULL, |
| finfo_objects_free, NULL TSRMLS_CC); |
retval.handlers = (zend_object_handlers *) &finfo_object_handlers; |
retval.handlers = (zend_object_handlers *) &finfo_object_handlers; |
|
|
return retval; |
return retval; |
Line 270 ZEND_GET_MODULE(fileinfo)
|
Line 270 ZEND_GET_MODULE(fileinfo)
|
PHP_MINFO_FUNCTION(fileinfo) |
PHP_MINFO_FUNCTION(fileinfo) |
{ |
{ |
php_info_print_table_start(); |
php_info_print_table_start(); |
php_info_print_table_header(2, "fileinfo support", "enabled"); | php_info_print_table_row(2, "fileinfo support", "enabled"); |
php_info_print_table_row(2, "version", PHP_FILEINFO_VERSION); |
php_info_print_table_row(2, "version", PHP_FILEINFO_VERSION); |
php_info_print_table_end(); |
php_info_print_table_end(); |
} |
} |
/* }}} */ |
/* }}} */ |
|
|
|
#define FILEINFO_DESTROY_OBJECT(object) \ |
|
do { \ |
|
if (object) { \ |
|
zend_object_store_ctor_failed(object TSRMLS_CC); \ |
|
zval_dtor(object); \ |
|
ZVAL_NULL(object); \ |
|
} \ |
|
} while (0) |
|
|
/* {{{ proto resource finfo_open([int options [, string arg]]) |
/* {{{ proto resource finfo_open([int options [, string arg]]) |
Create a new fileinfo resource. */ |
Create a new fileinfo resource. */ |
PHP_FUNCTION(finfo_open) |
PHP_FUNCTION(finfo_open) |
Line 287 PHP_FUNCTION(finfo_open)
|
Line 296 PHP_FUNCTION(finfo_open)
|
FILEINFO_DECLARE_INIT_OBJECT(object) |
FILEINFO_DECLARE_INIT_OBJECT(object) |
char resolved_path[MAXPATHLEN]; |
char resolved_path[MAXPATHLEN]; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ls", &options, &file, &file_len) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lp", &options, &file, &file_len) == FAILURE) { |
| FILEINFO_DESTROY_OBJECT(object); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
| |
if (object) { |
if (object) { |
struct finfo_object *finfo_obj = (struct finfo_object*)zend_object_store_get_object(object TSRMLS_CC); |
struct finfo_object *finfo_obj = (struct finfo_object*)zend_object_store_get_object(object TSRMLS_CC); |
| |
if (finfo_obj->ptr) { |
if (finfo_obj->ptr) { |
magic_close(finfo_obj->ptr->magic); |
magic_close(finfo_obj->ptr->magic); |
efree(finfo_obj->ptr); |
efree(finfo_obj->ptr); |
Line 304 PHP_FUNCTION(finfo_open)
|
Line 314 PHP_FUNCTION(finfo_open)
|
if (file_len == 0) { |
if (file_len == 0) { |
file = NULL; |
file = NULL; |
} else if (file && *file) { /* user specified file, perform open_basedir checks */ |
} else if (file && *file) { /* user specified file, perform open_basedir checks */ |
if (strlen(file) != file_len) { |
|
RETURN_FALSE; |
|
} |
|
if (!VCWD_REALPATH(file, resolved_path)) { |
|
RETURN_FALSE; |
|
} |
|
file = resolved_path; |
|
|
|
#if PHP_API_VERSION < 20100412 |
#if PHP_API_VERSION < 20100412 |
if ((PG(safe_mode) && (!php_checkuid(file, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(file TSRMLS_CC)) { |
if ((PG(safe_mode) && (!php_checkuid(file, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(file TSRMLS_CC)) { |
#else |
#else |
if (php_check_open_basedir(file TSRMLS_CC)) { |
if (php_check_open_basedir(file TSRMLS_CC)) { |
#endif |
#endif |
|
FILEINFO_DESTROY_OBJECT(object); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
if (!expand_filepath_with_mode(file, resolved_path, NULL, 0, CWD_EXPAND TSRMLS_CC)) { |
|
FILEINFO_DESTROY_OBJECT(object); |
|
RETURN_FALSE; |
|
} |
|
file = resolved_path; |
} |
} |
|
|
finfo = emalloc(sizeof(struct php_fileinfo)); |
finfo = emalloc(sizeof(struct php_fileinfo)); |
Line 329 PHP_FUNCTION(finfo_open)
|
Line 338 PHP_FUNCTION(finfo_open)
|
if (finfo->magic == NULL) { |
if (finfo->magic == NULL) { |
efree(finfo); |
efree(finfo); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid mode '%ld'.", options); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid mode '%ld'.", options); |
RETURN_FALSE; | FILEINFO_DESTROY_OBJECT(object); |
| RETURN_FALSE; |
} |
} |
|
|
if (magic_load(finfo->magic, file) == -1) { |
if (magic_load(finfo->magic, file) == -1) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to load magic database at '%s'.", file); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to load magic database at '%s'.", file); |
magic_close(finfo->magic); |
magic_close(finfo->magic); |
efree(finfo); |
efree(finfo); |
|
FILEINFO_DESTROY_OBJECT(object); |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
if (object) { |
if (object) { |
FILEINFO_REGISTER_OBJECT(object, finfo); |
FILEINFO_REGISTER_OBJECT(object, finfo); |
} else { |
} else { |
ZEND_REGISTER_RESOURCE(return_value, finfo, le_fileinfo); |
ZEND_REGISTER_RESOURCE(return_value, finfo, le_fileinfo); |
} | } |
} |
} |
/* }}} */ |
/* }}} */ |
|
|
Line 499 static void _php_finfo_get_type(INTERNAL_FUNCTION_PARA
|
Line 510 static void _php_finfo_get_type(INTERNAL_FUNCTION_PARA
|
wrap = php_stream_locate_url_wrapper(buffer, &tmp2, 0 TSRMLS_CC); |
wrap = php_stream_locate_url_wrapper(buffer, &tmp2, 0 TSRMLS_CC); |
|
|
if (wrap) { |
if (wrap) { |
|
php_stream *stream; |
php_stream_context *context = php_stream_context_from_zval(zcontext, 0); |
php_stream_context *context = php_stream_context_from_zval(zcontext, 0); |
|
|
|
#ifdef PHP_WIN32 |
|
if (php_stream_stat_path_ex(buffer, 0, &ssb, context) == SUCCESS) { |
|
if (ssb.sb.st_mode & S_IFDIR) { |
|
ret_val = mime_directory; |
|
goto common; |
|
} |
|
} |
|
#endif |
|
|
#if PHP_API_VERSION < 20100412 |
#if PHP_API_VERSION < 20100412 |
php_stream *stream = php_stream_open_wrapper_ex(buffer, "rb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); | stream = php_stream_open_wrapper_ex(buffer, "rb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); |
#else |
#else |
php_stream *stream = php_stream_open_wrapper_ex(buffer, "rb", REPORT_ERRORS, NULL, context); | stream = php_stream_open_wrapper_ex(buffer, "rb", REPORT_ERRORS, NULL, context); |
#endif |
#endif |
|
|
if (!stream) { |
if (!stream) { |