Back to index

php5  5.3.10
Defines | Functions | Variables
php_fileinfo.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define phpext_fileinfo_ptr   &fileinfo_module_entry
#define PHP_FILEINFO_VERSION   "1.0.5-dev"
#define PHP_FILEINFO_API
#define FILEINFO_G(v)   (fileinfo_globals.v)

Functions

 PHP_MINFO_FUNCTION (fileinfo)
 PHP_FUNCTION (finfo_open)
 PHP_FUNCTION (finfo_close)
 PHP_FUNCTION (finfo_set_flags)
 PHP_FUNCTION (finfo_file)
 PHP_FUNCTION (finfo_buffer)
 PHP_FUNCTION (mime_content_type)

Variables

zend_module_entry fileinfo_module_entry

Define Documentation

#define FILEINFO_G (   v)    (fileinfo_globals.v)

Definition at line 51 of file php_fileinfo.h.

Definition at line 32 of file php_fileinfo.h.

#define PHP_FILEINFO_VERSION   "1.0.5-dev"

Definition at line 27 of file php_fileinfo.h.

Definition at line 25 of file php_fileinfo.h.


Function Documentation

PHP_FUNCTION ( finfo_open  )

Definition at line 281 of file fileinfo.c.

{
       long options = MAGIC_NONE;
       char *file = NULL;
       int file_len = 0;
       struct php_fileinfo *finfo;
       FILEINFO_DECLARE_INIT_OBJECT(object)
       char resolved_path[MAXPATHLEN];

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ls", &options, &file, &file_len) == FAILURE) {
              RETURN_FALSE;
       }
       
       if (object) {
              struct finfo_object *finfo_obj = (struct finfo_object*)zend_object_store_get_object(object TSRMLS_CC);
              
              if (finfo_obj->ptr) {
                     magic_close(finfo_obj->ptr->magic);
                     efree(finfo_obj->ptr);
                     finfo_obj->ptr = NULL;
              }
       }

       if (file_len == 0) {
              file = NULL;
       } 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 ((PG(safe_mode) && (!php_checkuid(file, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(file TSRMLS_CC)) {
#else
              if (php_check_open_basedir(file TSRMLS_CC)) {
#endif
                     RETURN_FALSE;
              }
       }

       finfo = emalloc(sizeof(struct php_fileinfo));

       finfo->options = options;
       finfo->magic = magic_open(options);

       if (finfo->magic == NULL) {
              efree(finfo);
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid mode '%ld'.", options);
              RETURN_FALSE; 
       }

       if (magic_load(finfo->magic, file) == -1) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to load magic database at '%s'.", file);
              magic_close(finfo->magic);
              efree(finfo);
              RETURN_FALSE;
       }      

       if (object) {
              FILEINFO_REGISTER_OBJECT(object, finfo);
       } else {
              ZEND_REGISTER_RESOURCE(return_value, finfo, le_fileinfo);
       }      
}

Here is the call graph for this function:

PHP_FUNCTION ( finfo_close  )

Definition at line 352 of file fileinfo.c.

{
       struct php_fileinfo *finfo;
       zval *zfinfo;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zfinfo) == FAILURE) {
              RETURN_FALSE;
       }
       ZEND_FETCH_RESOURCE(finfo, struct php_fileinfo *, &zfinfo, -1, "file_info", le_fileinfo);

       zend_list_delete(Z_RESVAL_P(zfinfo));

       RETURN_TRUE;
}

Here is the call graph for this function:

PHP_FUNCTION ( finfo_set_flags  )

Definition at line 370 of file fileinfo.c.

{
       long options;
       struct php_fileinfo *finfo;
       zval *zfinfo;
       FILEINFO_DECLARE_INIT_OBJECT(object)

       if (object) {
              if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &options) == FAILURE) {
                     RETURN_FALSE;
              }
              FILEINFO_FROM_OBJECT(finfo, object);
       } else {
              if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zfinfo, &options) == FAILURE) {
                     RETURN_FALSE;
              }
              ZEND_FETCH_RESOURCE(finfo, struct php_fileinfo *, &zfinfo, -1, "file_info", le_fileinfo);
       }

       FINFO_SET_OPTION(finfo->magic, options)
       finfo->options = options;

       RETURN_TRUE;
}

Here is the call graph for this function:

PHP_FUNCTION ( finfo_file  )

Definition at line 554 of file fileinfo.c.

Here is the call graph for this function:

PHP_FUNCTION ( finfo_buffer  )

Definition at line 562 of file fileinfo.c.

Here is the call graph for this function:

PHP_FUNCTION ( mime_content_type  )

Definition at line 570 of file fileinfo.c.

Here is the call graph for this function:

PHP_MINFO_FUNCTION ( fileinfo  )

Definition at line 270 of file fileinfo.c.

Here is the call graph for this function:


Variable Documentation

zend_module_entry fileinfo_module_entry

Definition at line 250 of file fileinfo.c.