mirror of
https://github.com/bdnugget/php-src.git
synced 2026-11-08 09:47:30 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d6817e7f1 |
No files matched your search
@@ -0,0 +1,5 @@
|
||||
|
||||
LTLIBRARY_NAME = libregex.la
|
||||
LTLIBRARY_SOURCES = regcomp.c regexec.c regerror.c regfree.c
|
||||
|
||||
include $(top_srcdir)/build/ltlib.mk
|
||||
@@ -1,2 +0,0 @@
|
||||
fileinfo
|
||||
Ilia Alshanetsky, Derick Rethans
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
$(builddir)/libmagic/apprentice.lo: $(srcdir)/data_file.c
|
||||
@@ -1,21 +0,0 @@
|
||||
dnl $Id$
|
||||
dnl config.m4 for extension fileinfo
|
||||
|
||||
PHP_ARG_ENABLE(fileinfo, for fileinfo support,
|
||||
[ --disable-fileinfo Disable fileinfo support], yes)
|
||||
|
||||
if test "$PHP_FILEINFO" != "no"; then
|
||||
|
||||
libmagic_sources=" \
|
||||
libmagic/apprentice.c libmagic/apptype.c libmagic/ascmagic.c \
|
||||
libmagic/compress.c libmagic/fsmagic.c libmagic/funcs.c \
|
||||
libmagic/is_tar.c libmagic/magic.c libmagic/print.c \
|
||||
libmagic/readelf.c libmagic/softmagic.c"
|
||||
|
||||
PHP_NEW_EXTENSION(fileinfo, fileinfo.c $libmagic_sources, $ext_shared,,-I@ext_srcdir@/libmagic)
|
||||
PHP_ADD_BUILD_DIR($ext_builddir/libmagic)
|
||||
|
||||
AC_CHECK_FUNCS([utimes strndup])
|
||||
|
||||
PHP_ADD_MAKEFILE_FRAGMENT
|
||||
fi
|
||||
@@ -1,26 +0,0 @@
|
||||
// $Id$
|
||||
// vim:ft=javascript
|
||||
|
||||
ARG_ENABLE("fileinfo", "fileinfo support", "no");
|
||||
|
||||
if (PHP_FILEINFO != 'no') {
|
||||
|
||||
if (CHECK_HEADER_ADD_INCLUDE("dirent.h", "CFLAGS_FILEINFO") &&
|
||||
CHECK_LIB("dirent_a.lib", "fileinfo", PHP_FILEINFO)) {
|
||||
|
||||
LIBMAGIC_SOURCES=" apprentice.c apptype.c ascmagic.c \
|
||||
compress.c fsmagic.c funcs.c is_tar.c \
|
||||
magic.c print.c \
|
||||
readelf.c softmagic.c";
|
||||
|
||||
if (VCVERS <1500) {
|
||||
ADD_FLAG('CFLAGS', '/Zm1000');
|
||||
}
|
||||
|
||||
EXTENSION('fileinfo', 'fileinfo.c', true, "/I" + configure_module_dirname + "/libmagic /I" + configure_module_dirname);
|
||||
ADD_SOURCES(configure_module_dirname + '\\libmagic', LIBMAGIC_SOURCES, "fileinfo");
|
||||
} else {
|
||||
WARNING("fileinfo not enabled; libraries and headers not found");
|
||||
PHP_FILEINFO = "no";
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/* This is a generated file, do not modify */
|
||||
/* Usage: php create_data_file.php /path/to/magic.mgc > data_file.c */
|
||||
<?php
|
||||
$dta = file_get_contents( $argv[1] );
|
||||
$dta_l = strlen($dta);
|
||||
$j = 0;
|
||||
|
||||
echo "const unsigned char php_magic_database[$dta_l] = {\n";
|
||||
for ($i = 0; $i < $dta_l; $i++) {
|
||||
printf("0x%02X, ", ord($dta[$i]));
|
||||
if ($j % 16 == 15) {
|
||||
echo "\n";
|
||||
}
|
||||
$j++;
|
||||
}
|
||||
echo "};\n";
|
||||
?>
|
||||
-104932
File diff suppressed because it is too large.
Load diff
@@ -1,590 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2004 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| 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 |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| http://www.php.net/license/3_0.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. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Ilia Alshanetsky <ilia@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
#include "php.h"
|
||||
|
||||
#include <magic.h>
|
||||
/*
|
||||
* HOWMANY specifies the maximum offset libmagic will look at
|
||||
* this is currently hardcoded in the libmagic source but not exported
|
||||
*/
|
||||
#ifndef HOWMANY
|
||||
#define HOWMANY 65536
|
||||
#endif
|
||||
|
||||
#include "php_ini.h"
|
||||
#include "ext/standard/info.h"
|
||||
#include "ext/standard/file.h" /* needed for context stuff */
|
||||
#include "php_fileinfo.h"
|
||||
#include "fopen_wrappers.h" /* needed for is_url */
|
||||
|
||||
#ifndef _S_IFDIR
|
||||
# define _S_IFDIR S_IFDIR
|
||||
#endif
|
||||
|
||||
/* {{{ macros and type definitions */
|
||||
struct php_fileinfo {
|
||||
long options;
|
||||
struct magic_set *magic;
|
||||
};
|
||||
|
||||
#ifdef ZEND_ENGINE_2
|
||||
/* {{{ */
|
||||
static zend_object_handlers finfo_object_handlers;
|
||||
zend_class_entry *finfo_class_entry;
|
||||
|
||||
struct finfo_object {
|
||||
zend_object zo;
|
||||
struct php_fileinfo *ptr;
|
||||
};
|
||||
|
||||
#define FILEINFO_DECLARE_INIT_OBJECT(object) \
|
||||
zval *object = getThis();
|
||||
|
||||
#define FILEINFO_REGISTER_OBJECT(_object, _ptr) \
|
||||
{ \
|
||||
struct finfo_object *obj; \
|
||||
obj = (struct finfo_object*)zend_object_store_get_object(_object TSRMLS_CC); \
|
||||
obj->ptr = _ptr; \
|
||||
}
|
||||
|
||||
#define FILEINFO_FROM_OBJECT(finfo, object) \
|
||||
{ \
|
||||
struct finfo_object *obj = zend_object_store_get_object(object TSRMLS_CC); \
|
||||
finfo = obj->ptr; \
|
||||
if (!finfo) { \
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The invalid fileinfo object."); \
|
||||
RETURN_FALSE; \
|
||||
} \
|
||||
}
|
||||
|
||||
/* {{{ finfo_objects_dtor
|
||||
*/
|
||||
static void finfo_objects_dtor(void *object, zend_object_handle handle TSRMLS_DC)
|
||||
{
|
||||
struct finfo_object *intern = (struct finfo_object *) object;
|
||||
|
||||
if (intern->ptr) {
|
||||
magic_close(intern->ptr->magic);
|
||||
efree(intern->ptr);
|
||||
}
|
||||
|
||||
zend_object_std_dtor(&intern->zo TSRMLS_CC);
|
||||
efree(intern);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ finfo_objects_new
|
||||
*/
|
||||
PHP_FILEINFO_API zend_object_value finfo_objects_new(zend_class_entry *class_type TSRMLS_DC)
|
||||
{
|
||||
zend_object_value retval;
|
||||
struct finfo_object *intern;
|
||||
zval *tmp;
|
||||
|
||||
intern = emalloc(sizeof(struct finfo_object));
|
||||
|
||||
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 *));
|
||||
|
||||
intern->ptr = NULL;
|
||||
|
||||
retval.handle = zend_objects_store_put(intern, finfo_objects_dtor, NULL, NULL TSRMLS_CC);
|
||||
retval.handlers = (zend_object_handlers *) &finfo_object_handlers;
|
||||
|
||||
return retval;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ arginfo */
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_open, 0, 0, 0)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
ZEND_ARG_INFO(0, arg)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_close, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, finfo)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_set_flags, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, finfo)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_method_set_flags, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_file, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, finfo)
|
||||
ZEND_ARG_INFO(0, filename)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
ZEND_ARG_INFO(0, context)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_method_file, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, filename)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
ZEND_ARG_INFO(0, context)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_buffer, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, finfo)
|
||||
ZEND_ARG_INFO(0, string)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
ZEND_ARG_INFO(0, context)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_method_buffer, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, string)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
ZEND_ARG_INFO(0, context)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_mime_content_type, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, string)
|
||||
ZEND_END_ARG_INFO()
|
||||
/* }}} */
|
||||
|
||||
/* {{{ finfo_class_functions
|
||||
*/
|
||||
function_entry finfo_class_functions[] = {
|
||||
#if PHP_VERSION_ID >= 50200
|
||||
ZEND_ME_MAPPING(finfo, finfo_open, arginfo_finfo_open, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME_MAPPING(set_flags, finfo_set_flags,arginfo_finfo_method_set_flags, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME_MAPPING(file, finfo_file, arginfo_finfo_method_file, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME_MAPPING(buffer, finfo_buffer, arginfo_finfo_method_buffer, ZEND_ACC_PUBLIC)
|
||||
#else
|
||||
ZEND_ME_MAPPING(finfo, finfo_open, arginfo_finfo_open)
|
||||
ZEND_ME_MAPPING(set_flags, finfo_set_flags,arginfo_finfo_method_set_flags)
|
||||
ZEND_ME_MAPPING(file, finfo_file, arginfo_finfo_method_file)
|
||||
ZEND_ME_MAPPING(buffer, finfo_buffer, arginfo_finfo_method_buffer)
|
||||
#endif
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
/* }}} */
|
||||
#else
|
||||
/* {{{ */
|
||||
#define FILEINFO_REGISTER_OBJECT(_object, _ptr) {}
|
||||
#define FILEINFO_FROM_OBJECT(socket_id, object) {}
|
||||
|
||||
#define FILEINFO_DECLARE_INIT_OBJECT(object)
|
||||
#define object 0
|
||||
|
||||
/* }}} */
|
||||
#endif /* ZEND_ENGINE_2 */
|
||||
|
||||
#define FINFO_SET_OPTION(magic, options) \
|
||||
if (magic_setflags(magic, options) == -1) { \
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to set option '%ld' %d:%s", \
|
||||
options, magic_errno(magic), magic_error(magic)); \
|
||||
RETURN_FALSE; \
|
||||
}
|
||||
|
||||
/* True global resources - no need for thread safety here */
|
||||
static int le_fileinfo;
|
||||
/* }}} */
|
||||
|
||||
void finfo_resource_destructor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
if (rsrc->ptr) {
|
||||
struct php_fileinfo *finfo = (struct php_fileinfo *) rsrc->ptr;
|
||||
magic_close(finfo->magic);
|
||||
efree(rsrc->ptr);
|
||||
rsrc->ptr = NULL;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ fileinfo_functions[]
|
||||
*/
|
||||
function_entry fileinfo_functions[] = {
|
||||
PHP_FE(finfo_open, arginfo_finfo_open)
|
||||
PHP_FE(finfo_close, arginfo_finfo_close)
|
||||
PHP_FE(finfo_set_flags, arginfo_finfo_set_flags)
|
||||
PHP_FE(finfo_file, arginfo_finfo_file)
|
||||
PHP_FE(finfo_buffer, arginfo_finfo_buffer)
|
||||
PHP_FE(mime_content_type, arginfo_mime_content_type)
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
/* {{{ PHP_MINIT_FUNCTION
|
||||
*/
|
||||
PHP_MINIT_FUNCTION(finfo)
|
||||
{
|
||||
#ifdef ZEND_ENGINE_2
|
||||
zend_class_entry _finfo_class_entry;
|
||||
INIT_CLASS_ENTRY(_finfo_class_entry, "finfo", finfo_class_functions);
|
||||
_finfo_class_entry.create_object = finfo_objects_new;
|
||||
finfo_class_entry = zend_register_internal_class(&_finfo_class_entry TSRMLS_CC);
|
||||
|
||||
/* copy the standard object handlers to you handler table */
|
||||
memcpy(&finfo_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
||||
#endif /* ZEND_ENGINE_2 */
|
||||
|
||||
le_fileinfo = zend_register_list_destructors_ex(finfo_resource_destructor, NULL, "file_info", module_number);
|
||||
|
||||
REGISTER_LONG_CONSTANT("FILEINFO_NONE", MAGIC_NONE, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("FILEINFO_SYMLINK", MAGIC_SYMLINK, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("FILEINFO_MIME", MAGIC_MIME, CONST_CS|CONST_PERSISTENT);
|
||||
/* REGISTER_LONG_CONSTANT("FILEINFO_COMPRESS", MAGIC_COMPRESS, CONST_CS|CONST_PERSISTENT); disabled, as it does fork now */
|
||||
REGISTER_LONG_CONSTANT("FILEINFO_DEVICES", MAGIC_DEVICES, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("FILEINFO_CONTINUE", MAGIC_CONTINUE, CONST_CS|CONST_PERSISTENT);
|
||||
#ifdef MAGIC_PRESERVE_ATIME
|
||||
REGISTER_LONG_CONSTANT("FILEINFO_PRESERVE_ATIME", MAGIC_PRESERVE_ATIME, CONST_CS|CONST_PERSISTENT);
|
||||
#endif
|
||||
#ifdef MAGIC_RAW
|
||||
REGISTER_LONG_CONSTANT("FILEINFO_RAW", MAGIC_RAW, CONST_CS|CONST_PERSISTENT);
|
||||
#endif
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ fileinfo_module_entry
|
||||
*/
|
||||
zend_module_entry fileinfo_module_entry = {
|
||||
#if ZEND_MODULE_API_NO >= 20010901
|
||||
STANDARD_MODULE_HEADER,
|
||||
#endif
|
||||
"fileinfo",
|
||||
fileinfo_functions,
|
||||
PHP_MINIT(finfo),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
PHP_MINFO(fileinfo),
|
||||
#if ZEND_MODULE_API_NO >= 20010901
|
||||
PHP_FILEINFO_VERSION,
|
||||
#endif
|
||||
STANDARD_MODULE_PROPERTIES
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
#ifdef COMPILE_DL_FILEINFO
|
||||
ZEND_GET_MODULE(fileinfo)
|
||||
#endif
|
||||
|
||||
/* {{{ PHP_MINFO_FUNCTION
|
||||
*/
|
||||
PHP_MINFO_FUNCTION(fileinfo)
|
||||
{
|
||||
php_info_print_table_start();
|
||||
php_info_print_table_header(2, "fileinfo support", "enabled");
|
||||
php_info_print_table_row(2, "version", PHP_FILEINFO_VERSION);
|
||||
php_info_print_table_end();
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto resource finfo_open([int options [, string arg]])
|
||||
Create a new fileinfo resource. */
|
||||
PHP_FUNCTION(finfo_open)
|
||||
{
|
||||
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 (file && *file) { /* user specified file, perform open_basedir checks */
|
||||
if (!VCWD_REALPATH(file, resolved_path)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
file = resolved_path;
|
||||
|
||||
if ((PG(safe_mode) && (!php_checkuid(file, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(file TSRMLS_CC)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto resource finfo_close(resource finfo)
|
||||
Close fileinfo resource. */
|
||||
PHP_FUNCTION(finfo_close)
|
||||
{
|
||||
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;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool finfo_set_flags(resource finfo, int options)
|
||||
Set libmagic configuration options. */
|
||||
PHP_FUNCTION(finfo_set_flags)
|
||||
{
|
||||
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;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#define FILEINFO_MODE_BUFFER 0
|
||||
#define FILEINFO_MODE_STREAM 1
|
||||
#define FILEINFO_MODE_FILE 2
|
||||
|
||||
static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mimetype_emu) /* {{{ */
|
||||
{
|
||||
long options = 0;
|
||||
char *ret_val = NULL, *buffer = NULL;
|
||||
int buffer_len;
|
||||
struct php_fileinfo *finfo;
|
||||
zval *zfinfo, *zcontext = NULL;
|
||||
zval *what;
|
||||
char mime_directory[] = "directory";
|
||||
|
||||
struct magic_set *magic = NULL;
|
||||
FILEINFO_DECLARE_INIT_OBJECT(object)
|
||||
|
||||
if (mimetype_emu) {
|
||||
|
||||
/* mime_content_type(..) emulation */
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &what) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (Z_TYPE_P(what)) {
|
||||
case IS_STRING:
|
||||
buffer = Z_STRVAL_P(what);
|
||||
buffer_len = Z_STRLEN_P(what);
|
||||
mode = FILEINFO_MODE_FILE;
|
||||
break;
|
||||
|
||||
case IS_RESOURCE:
|
||||
mode = FILEINFO_MODE_STREAM;
|
||||
break;
|
||||
|
||||
default:
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only process string or stream arguments");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
magic = magic_open(MAGIC_MIME);
|
||||
if (magic_load(magic, NULL) == -1) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to load magic database.");
|
||||
goto common;
|
||||
}
|
||||
} else if (object) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lr", &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
FILEINFO_FROM_OBJECT(finfo, object);
|
||||
magic = finfo->magic;
|
||||
} else {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|lr", &zfinfo, &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
ZEND_FETCH_RESOURCE(finfo, struct php_fileinfo *, &zfinfo, -1, "file_info", le_fileinfo);
|
||||
magic = finfo->magic;
|
||||
}
|
||||
|
||||
/* Set options for the current file/buffer. */
|
||||
if (options) {
|
||||
FINFO_SET_OPTION(magic, options)
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case FILEINFO_MODE_BUFFER:
|
||||
{
|
||||
ret_val = (char *) magic_buffer(magic, buffer, buffer_len);
|
||||
break;
|
||||
}
|
||||
|
||||
case FILEINFO_MODE_STREAM:
|
||||
{
|
||||
php_stream *stream;
|
||||
off_t streampos;
|
||||
|
||||
php_stream_from_zval_no_verify(stream, &what);
|
||||
if (!stream) {
|
||||
goto common;
|
||||
}
|
||||
|
||||
streampos = php_stream_tell(stream); /* remember stream position for restoration */
|
||||
php_stream_seek(stream, 0, SEEK_SET);
|
||||
|
||||
ret_val = (char *) magic_stream(magic, stream);
|
||||
|
||||
php_stream_seek(stream, streampos, SEEK_SET);
|
||||
break;
|
||||
}
|
||||
|
||||
case FILEINFO_MODE_FILE:
|
||||
{
|
||||
/* determine if the file is a local file or remote URL */
|
||||
char *tmp2;
|
||||
php_stream_wrapper *wrap;
|
||||
struct stat sb;
|
||||
|
||||
if (buffer == NULL || !*buffer) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty filename or path");
|
||||
RETVAL_FALSE;
|
||||
goto clean;
|
||||
}
|
||||
|
||||
if (php_sys_stat(buffer, &sb) == 0) {
|
||||
if (sb.st_mode & _S_IFDIR) {
|
||||
ret_val = mime_directory;
|
||||
goto common;
|
||||
}
|
||||
} else {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "File or path not found '%s'", buffer);
|
||||
RETVAL_FALSE;
|
||||
goto clean;
|
||||
}
|
||||
|
||||
wrap = php_stream_locate_url_wrapper(buffer, &tmp2, 0 TSRMLS_CC);
|
||||
|
||||
if (wrap) {
|
||||
php_stream_context *context = php_stream_context_from_zval(zcontext, 0);
|
||||
|
||||
php_stream *stream = php_stream_open_wrapper_ex(buffer, "rb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context);
|
||||
|
||||
if (!stream) {
|
||||
RETVAL_FALSE;
|
||||
goto clean;
|
||||
}
|
||||
|
||||
ret_val = (char *)magic_stream(magic, stream);
|
||||
php_stream_close(stream);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only process string or stream arguments");
|
||||
}
|
||||
|
||||
common:
|
||||
if (ret_val) {
|
||||
RETVAL_STRING(ret_val, 1);
|
||||
} else {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed identify data %d:%s", magic_errno(magic), magic_error(magic));
|
||||
RETVAL_FALSE;
|
||||
}
|
||||
|
||||
clean:
|
||||
if (mimetype_emu) {
|
||||
magic_close(magic);
|
||||
}
|
||||
|
||||
/* Restore options */
|
||||
if (options) {
|
||||
FINFO_SET_OPTION(magic, finfo->options)
|
||||
}
|
||||
return;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string finfo_file(resource finfo, char *file_name [, int options [, resource context]])
|
||||
Return information about a file. */
|
||||
PHP_FUNCTION(finfo_file)
|
||||
{
|
||||
_php_finfo_get_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, FILEINFO_MODE_FILE, 0);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string finfo_buffer(resource finfo, char *string [, int options [, resource context]])
|
||||
Return infromation about a string buffer. */
|
||||
PHP_FUNCTION(finfo_buffer)
|
||||
{
|
||||
_php_finfo_get_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, FILEINFO_MODE_BUFFER, 0);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string mime_content_type(string filename|resource stream)
|
||||
Return content-type for file */
|
||||
PHP_FUNCTION(mime_content_type)
|
||||
{
|
||||
_php_finfo_get_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, -1, 1);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
if(!extension_loaded('fileinfo')) {
|
||||
dl('fileinfo.' . PHP_SHLIB_SUFFIX);
|
||||
}
|
||||
if(!extension_loaded('fileinfo')) {
|
||||
die("fileinfo extension is not avaliable, please compile it.\n");
|
||||
}
|
||||
|
||||
// normal operation
|
||||
$res = finfo_open(FILEINFO_MIME); /* return mime type ala mimetype extension */
|
||||
$files = glob("*");
|
||||
foreach ($files as $file) {
|
||||
echo finfo_file($res, $file) . "\n";
|
||||
}
|
||||
finfo_close($res);
|
||||
|
||||
// OO mode
|
||||
/*
|
||||
* FILEINFO_PRESERVE_ATIME - if possible preserve the original access time
|
||||
* FILEINFO_SYMLINK - follow symlinks
|
||||
* FILEINFO_DEVICES - look at the contents of blocks or character special devices
|
||||
* FILEINFO_COMPRESS - decompress compressed files
|
||||
*/
|
||||
$fi = new finfo(FILEINFO_PRESERVE_ATIME|FILEINFO_SYMLINK|FILEINFO_DEVICES|FILEINFO_COMPRESS);
|
||||
$files = glob("*");
|
||||
foreach ($files as $file) {
|
||||
echo $fi->buffer(file_get_contents($file)) . "\n";
|
||||
}
|
||||
?>
|
||||
@@ -1,127 +0,0 @@
|
||||
Index: libmagic/apprentice.c
|
||||
===================================================================
|
||||
RCS file: /repository/pecl/fileinfo/libmagic/apprentice.c,v
|
||||
retrieving revision 1.1
|
||||
diff -u -r1.1 apprentice.c
|
||||
--- libmagic/apprentice.c 11 Jul 2008 14:13:50 -0000 1.1
|
||||
+++ libmagic/apprentice.c 25 Jul 2008 08:18:07 -0000
|
||||
@@ -157,6 +157,10 @@
|
||||
}
|
||||
#endif /* COMPILE_ONLY */
|
||||
|
||||
+#ifdef PHP_BUNDLE
|
||||
+#include "../data_file.c"
|
||||
+#endif
|
||||
+
|
||||
static const struct type_tbl_s {
|
||||
const char name[16];
|
||||
const size_t len;
|
||||
@@ -310,6 +314,11 @@
|
||||
if (p == NULL)
|
||||
return;
|
||||
switch (type) {
|
||||
+#ifdef PHP_BUNDLE
|
||||
+ case 3:
|
||||
+ /* Do nothing, it's part of the code segment */
|
||||
+ break;
|
||||
+#endif
|
||||
#ifdef QUICK
|
||||
case 2:
|
||||
p--;
|
||||
@@ -339,8 +348,19 @@
|
||||
|
||||
if (fn == NULL)
|
||||
fn = getenv("MAGIC");
|
||||
- if (fn == NULL)
|
||||
+ if (fn == NULL) {
|
||||
+#ifdef PHP_BUNDLE
|
||||
+ if ((mlist = malloc(sizeof(*mlist))) == NULL) {
|
||||
+ file_oomem(ms, sizeof(*mlist));
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ mlist->next = mlist->prev = mlist;
|
||||
+ apprentice_1(ms, fn, action, mlist);
|
||||
+ return mlist;
|
||||
+#else
|
||||
fn = MAGIC;
|
||||
+#endif
|
||||
+ }
|
||||
|
||||
if ((mfn = strdup(fn)) == NULL) {
|
||||
file_oomem(ms, strlen(fn));
|
||||
@@ -1886,6 +1906,15 @@
|
||||
int needsbyteswap;
|
||||
char *dbname = NULL;
|
||||
void *mm = NULL;
|
||||
+ int ret = 0;
|
||||
+
|
||||
+#ifdef PHP_BUNDLE
|
||||
+ if (fn == NULL) {
|
||||
+ mm = &php_magic_database;
|
||||
+ ret = 3;
|
||||
+ goto internal_loaded;
|
||||
+ }
|
||||
+#endif
|
||||
|
||||
mkdbname(fn, &dbname, 0);
|
||||
if (dbname == NULL)
|
||||
@@ -1909,7 +1938,7 @@
|
||||
file_error(ms, errno, "cannot map `%s'", dbname);
|
||||
goto error1;
|
||||
}
|
||||
-#define RET 2
|
||||
+ ret = 2;
|
||||
#else
|
||||
if ((mm = malloc((size_t)st.st_size)) == NULL) {
|
||||
file_oomem(ms, (size_t)st.st_size);
|
||||
@@ -1919,11 +1948,14 @@
|
||||
file_badread(ms);
|
||||
goto error1;
|
||||
}
|
||||
-#define RET 1
|
||||
+ ret = 1;
|
||||
#endif
|
||||
- *magicp = mm;
|
||||
(void)close(fd);
|
||||
fd = -1;
|
||||
+#ifdef PHP_BUNDLE
|
||||
+internal_loaded:
|
||||
+#endif
|
||||
+ *magicp = mm;
|
||||
ptr = (uint32_t *)(void *)*magicp;
|
||||
if (*ptr != MAGICNO) {
|
||||
if (swap4(*ptr) != MAGICNO) {
|
||||
@@ -1943,6 +1975,11 @@
|
||||
VERSIONNO, dbname, version);
|
||||
goto error1;
|
||||
}
|
||||
+#ifdef PHP_BUNDLE
|
||||
+ if (fn == NULL)
|
||||
+ *nmagicp = (sizeof(php_magic_database) / sizeof(struct magic));
|
||||
+ else /* the statement after the #endif is used */
|
||||
+#endif
|
||||
*nmagicp = (uint32_t)(st.st_size / sizeof(struct magic));
|
||||
if (*nmagicp > 0)
|
||||
(*nmagicp)--;
|
||||
@@ -1950,7 +1987,7 @@
|
||||
if (needsbyteswap)
|
||||
byteswap(*magicp, *nmagicp);
|
||||
free(dbname);
|
||||
- return RET;
|
||||
+ return ret;
|
||||
|
||||
error1:
|
||||
if (fd != -1)
|
||||
Index: libmagic/config.h
|
||||
===================================================================
|
||||
RCS file: /repository/pecl/fileinfo/libmagic/config.h,v
|
||||
retrieving revision 1.2
|
||||
retrieving revision 1.3
|
||||
diff -u -r1.2 -r1.3
|
||||
--- libmagic/config.h 11 Jul 2008 14:49:45 -0000 1.2
|
||||
+++ libmagic/config.h 24 Jul 2008 13:40:21 -0000 1.3
|
||||
@@ -2,3 +2,4 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "../config.h"
|
||||
#endif
|
||||
+#define PHP_BUNDLE
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,170 +0,0 @@
|
||||
/*
|
||||
* Adapted from: apptype.c, Written by Eberhard Mattes and put into the
|
||||
* public domain
|
||||
*
|
||||
* Notes: 1. Qualify the filename so that DosQueryAppType does not do extraneous
|
||||
* searches.
|
||||
*
|
||||
* 2. DosQueryAppType will return FAPPTYP_DOS on a file ending with ".com"
|
||||
* (other than an OS/2 exe or Win exe with this name). Eberhard Mattes
|
||||
* remarks Tue, 6 Apr 93: Moreover, it reports the type of the (new and very
|
||||
* bug ridden) Win Emacs as "OS/2 executable".
|
||||
*
|
||||
* 3. apptype() uses the filename if given, otherwise a tmp file is created with
|
||||
* the contents of buf. If buf is not the complete file, apptype can
|
||||
* incorrectly identify the exe type. The "-z" option of "file" is the reason
|
||||
* for this ugly code.
|
||||
*/
|
||||
|
||||
/*
|
||||
* amai: Darrel Hankerson did the changes described here.
|
||||
*
|
||||
* It remains to check the validity of comments (2.) since it's referred to an
|
||||
* "old" OS/2 version.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "file.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#ifndef lint
|
||||
FILE_RCSID("@(#)$File: apptype.c,v 1.7 2007/01/12 17:38:27 christos Exp $")
|
||||
#endif /* lint */
|
||||
|
||||
#ifdef __EMX__
|
||||
#include <io.h>
|
||||
#define INCL_DOSSESMGR
|
||||
#define INCL_DOSERRORS
|
||||
#define INCL_DOSFILEMGR
|
||||
#include <os2.h>
|
||||
typedef ULONG APPTYPE;
|
||||
|
||||
protected int
|
||||
file_os2_apptype(struct magic_set *ms, const char *fn, const void *buf,
|
||||
size_t nb)
|
||||
{
|
||||
APPTYPE rc, type;
|
||||
char path[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR],
|
||||
fname[_MAX_FNAME], ext[_MAX_EXT];
|
||||
char *filename;
|
||||
FILE *fp;
|
||||
|
||||
if (fn)
|
||||
filename = strdup(fn);
|
||||
else if ((filename = tempnam("./", "tmp")) == NULL) {
|
||||
file_error(ms, errno, "cannot create tempnam");
|
||||
return -1;
|
||||
}
|
||||
/* qualify the filename to prevent extraneous searches */
|
||||
_splitpath(filename, drive, dir, fname, ext);
|
||||
(void)sprintf(path, "%s%s%s%s", drive,
|
||||
(*dir == '\0') ? "./" : dir,
|
||||
fname,
|
||||
(*ext == '\0') ? "." : ext);
|
||||
|
||||
if (fn == NULL) {
|
||||
if ((fp = fopen(path, "wb")) == NULL) {
|
||||
file_error(ms, errno, "cannot open tmp file `%s'", path);
|
||||
return -1;
|
||||
}
|
||||
if (fwrite(buf, 1, nb, fp) != nb) {
|
||||
file_error(ms, errno, "cannot write tmp file `%s'",
|
||||
path);
|
||||
return -1;
|
||||
}
|
||||
(void)fclose(fp);
|
||||
}
|
||||
rc = DosQueryAppType(path, &type);
|
||||
|
||||
if (fn == NULL) {
|
||||
unlink(path);
|
||||
free(filename);
|
||||
}
|
||||
#if 0
|
||||
if (rc == ERROR_INVALID_EXE_SIGNATURE)
|
||||
printf("%s: not an executable file\n", fname);
|
||||
else if (rc == ERROR_FILE_NOT_FOUND)
|
||||
printf("%s: not found\n", fname);
|
||||
else if (rc == ERROR_ACCESS_DENIED)
|
||||
printf("%s: access denied\n", fname);
|
||||
else if (rc != 0)
|
||||
printf("%s: error code = %lu\n", fname, rc);
|
||||
else
|
||||
#else
|
||||
|
||||
/*
|
||||
* for our purpose here it's sufficient to just ignore the error and
|
||||
* return w/o success (=0)
|
||||
*/
|
||||
|
||||
if (rc)
|
||||
return (0);
|
||||
|
||||
#endif
|
||||
|
||||
if (type & FAPPTYP_32BIT)
|
||||
if (file_printf(ms, "32-bit ") == -1)
|
||||
return -1;
|
||||
if (type & FAPPTYP_PHYSDRV) {
|
||||
if (file_printf(ms, "physical device driver") == -1)
|
||||
return -1;
|
||||
} else if (type & FAPPTYP_VIRTDRV) {
|
||||
if (file_printf(ms, "virtual device driver") == -1)
|
||||
return -1;
|
||||
} else if (type & FAPPTYP_DLL) {
|
||||
if (type & FAPPTYP_PROTDLL)
|
||||
if (file_printf(ms, "protected ") == -1)
|
||||
return -1;
|
||||
if (file_printf(ms, "DLL") == -1)
|
||||
return -1;
|
||||
} else if (type & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT)) {
|
||||
if (file_printf(ms, "Windows executable") == -1)
|
||||
return -1;
|
||||
} else if (type & FAPPTYP_DOS) {
|
||||
/*
|
||||
* The API routine is partially broken on filenames ending
|
||||
* ".com".
|
||||
*/
|
||||
if (stricmp(ext, ".com") == 0)
|
||||
if (strncmp((const char *)buf, "MZ", 2))
|
||||
return (0);
|
||||
if (file_printf(ms, "DOS executable") == -1)
|
||||
return -1;
|
||||
/* ---------------------------------------- */
|
||||
/* Might learn more from the magic(4) entry */
|
||||
if (file_printf(ms, ", magic(4)-> ") == -1)
|
||||
return -1;
|
||||
return (0);
|
||||
/* ---------------------------------------- */
|
||||
} else if (type & FAPPTYP_BOUND) {
|
||||
if (file_printf(ms, "bound executable") == -1)
|
||||
return -1;
|
||||
} else if ((type & 7) == FAPPTYP_WINDOWAPI) {
|
||||
if (file_printf(ms, "PM executable") == -1)
|
||||
return -1;
|
||||
} else if (file_printf(ms, "OS/2 executable") == -1)
|
||||
return -1;
|
||||
|
||||
switch (type & (FAPPTYP_NOTWINDOWCOMPAT |
|
||||
FAPPTYP_WINDOWCOMPAT |
|
||||
FAPPTYP_WINDOWAPI)) {
|
||||
case FAPPTYP_NOTWINDOWCOMPAT:
|
||||
if (file_printf(ms, " [NOTWINDOWCOMPAT]") == -1)
|
||||
return -1;
|
||||
break;
|
||||
case FAPPTYP_WINDOWCOMPAT:
|
||||
if (file_printf(ms, " [WINDOWCOMPAT]") == -1)
|
||||
return -1;
|
||||
break;
|
||||
case FAPPTYP_WINDOWAPI:
|
||||
if (file_printf(ms, " [WINDOWAPI]") == -1)
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
@@ -1,788 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
* Software written by Ian F. Darwin and others;
|
||||
* maintained 1995-present by Christos Zoulas and others.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice immediately at the beginning of the file, without modification,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* ASCII magic -- file types that we know based on keywords
|
||||
* that can appear anywhere in the file.
|
||||
*
|
||||
* Extensively modified by Eric Fischer <enf@pobox.com> in July, 2000,
|
||||
* to handle character codes other than ASCII on a unified basis.
|
||||
*
|
||||
* Joerg Wunsch <joerg@freebsd.org> wrote the original support for 8-bit
|
||||
* international characters, now subsumed into this file.
|
||||
*/
|
||||
|
||||
#include "file.h"
|
||||
#include "magic.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "names.h"
|
||||
|
||||
#ifndef lint
|
||||
FILE_RCSID("@(#)$File: ascmagic.c,v 1.62 2008/03/01 22:21:48 rrt Exp $")
|
||||
#endif /* lint */
|
||||
|
||||
#define MAXLINELEN 300 /* longest sane line length */
|
||||
#define ISSPC(x) ((x) == ' ' || (x) == '\t' || (x) == '\r' || (x) == '\n' \
|
||||
|| (x) == 0x85 || (x) == '\f')
|
||||
|
||||
private int looks_ascii(const unsigned char *, size_t, unichar *, size_t *);
|
||||
private int looks_utf8_with_BOM(const unsigned char *, size_t, unichar *,
|
||||
size_t *);
|
||||
private int looks_ucs16(const unsigned char *, size_t, unichar *, size_t *);
|
||||
private int looks_latin1(const unsigned char *, size_t, unichar *, size_t *);
|
||||
private int looks_extended(const unsigned char *, size_t, unichar *, size_t *);
|
||||
private void from_ebcdic(const unsigned char *, size_t, unsigned char *);
|
||||
private int ascmatch(const unsigned char *, const unichar *, size_t);
|
||||
private unsigned char *encode_utf8(unsigned char *, size_t, unichar *, size_t);
|
||||
|
||||
|
||||
protected int
|
||||
file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char *nbuf = NULL, *utf8_buf = NULL, *utf8_end;
|
||||
unichar *ubuf = NULL;
|
||||
size_t ulen, mlen;
|
||||
const struct names *p;
|
||||
int rv = -1;
|
||||
int mime = ms->flags & MAGIC_MIME;
|
||||
|
||||
const char *code = NULL;
|
||||
const char *code_mime = NULL;
|
||||
const char *type = NULL;
|
||||
const char *subtype = NULL;
|
||||
const char *subtype_mime = NULL;
|
||||
|
||||
int has_escapes = 0;
|
||||
int has_backspace = 0;
|
||||
int seen_cr = 0;
|
||||
|
||||
int n_crlf = 0;
|
||||
int n_lf = 0;
|
||||
int n_cr = 0;
|
||||
int n_nel = 0;
|
||||
|
||||
size_t last_line_end = (size_t)-1;
|
||||
int has_long_lines = 0;
|
||||
|
||||
/*
|
||||
* Undo the NUL-termination kindly provided by process()
|
||||
* but leave at least one byte to look at
|
||||
*/
|
||||
while (nbytes > 1 && buf[nbytes - 1] == '\0') {
|
||||
nbytes--;
|
||||
}
|
||||
|
||||
nbuf = ecalloc(1, (nbytes + 1) * sizeof(nbuf[0]));
|
||||
ubuf = ecalloc(1, (nbytes + 1) * sizeof(ubuf[0]));
|
||||
|
||||
/*
|
||||
* Then try to determine whether it's any character code we can
|
||||
* identify. Each of these tests, if it succeeds, will leave
|
||||
* the text converted into one-unichar-per-character Unicode in
|
||||
* ubuf, and the number of characters converted in ulen.
|
||||
*/
|
||||
if (looks_ascii(buf, nbytes, ubuf, &ulen)) {
|
||||
code = "ASCII";
|
||||
code_mime = "us-ascii";
|
||||
type = "text";
|
||||
} else if (looks_utf8_with_BOM(buf, nbytes, ubuf, &ulen) > 0) {
|
||||
code = "UTF-8 Unicode (with BOM)";
|
||||
code_mime = "utf-8";
|
||||
type = "text";
|
||||
} else if (file_looks_utf8(buf, nbytes, ubuf, &ulen) > 1) {
|
||||
code = "UTF-8 Unicode";
|
||||
code_mime = "utf-8";
|
||||
type = "text";
|
||||
} else if ((i = looks_ucs16(buf, nbytes, ubuf, &ulen)) != 0) {
|
||||
if (i == 1)
|
||||
code = "Little-endian UTF-16 Unicode";
|
||||
else
|
||||
code = "Big-endian UTF-16 Unicode";
|
||||
|
||||
type = "character data";
|
||||
code_mime = "utf-16"; /* is this defined? */
|
||||
} else if (looks_latin1(buf, nbytes, ubuf, &ulen)) {
|
||||
code = "ISO-8859";
|
||||
type = "text";
|
||||
code_mime = "iso-8859-1";
|
||||
} else if (looks_extended(buf, nbytes, ubuf, &ulen)) {
|
||||
code = "Non-ISO extended-ASCII";
|
||||
type = "text";
|
||||
code_mime = "unknown";
|
||||
} else {
|
||||
from_ebcdic(buf, nbytes, nbuf);
|
||||
|
||||
if (looks_ascii(nbuf, nbytes, ubuf, &ulen)) {
|
||||
code = "EBCDIC";
|
||||
type = "character data";
|
||||
code_mime = "ebcdic";
|
||||
} else if (looks_latin1(nbuf, nbytes, ubuf, &ulen)) {
|
||||
code = "International EBCDIC";
|
||||
type = "character data";
|
||||
code_mime = "ebcdic";
|
||||
} else {
|
||||
rv = 0;
|
||||
goto done; /* doesn't look like text at all */
|
||||
}
|
||||
}
|
||||
|
||||
if (nbytes <= 1) {
|
||||
rv = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Convert ubuf to UTF-8 and try text soft magic */
|
||||
/* If original was ASCII or UTF-8, could use nbuf instead of
|
||||
re-converting. */
|
||||
/* malloc size is a conservative overestimate; could be
|
||||
re-converting improved, or at least realloced after
|
||||
re-converting conversion. */
|
||||
mlen = ulen * 6;
|
||||
utf8_buf = emalloc(mlen);
|
||||
|
||||
if ((utf8_end = encode_utf8(utf8_buf, mlen, ubuf, ulen)) == NULL)
|
||||
goto done;
|
||||
if (file_softmagic(ms, utf8_buf, utf8_end - utf8_buf, TEXTTEST) != 0) {
|
||||
rv = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* look for tokens from names.h - this is expensive! */
|
||||
if ((ms->flags & MAGIC_NO_CHECK_TOKENS) != 0)
|
||||
goto subtype_identified;
|
||||
|
||||
i = 0;
|
||||
while (i < ulen) {
|
||||
size_t end;
|
||||
|
||||
/* skip past any leading space */
|
||||
while (i < ulen && ISSPC(ubuf[i]))
|
||||
i++;
|
||||
if (i >= ulen)
|
||||
break;
|
||||
|
||||
/* find the next whitespace */
|
||||
for (end = i + 1; end < nbytes; end++)
|
||||
if (ISSPC(ubuf[end]))
|
||||
break;
|
||||
|
||||
/* compare the word thus isolated against the token list */
|
||||
for (p = names; p < names + NNAMES; p++) {
|
||||
if (ascmatch((const unsigned char *)p->name, ubuf + i,
|
||||
end - i)) {
|
||||
subtype = types[p->type].human;
|
||||
subtype_mime = types[p->type].mime;
|
||||
goto subtype_identified;
|
||||
}
|
||||
}
|
||||
|
||||
i = end;
|
||||
}
|
||||
|
||||
subtype_identified:
|
||||
|
||||
/* Now try to discover other details about the file. */
|
||||
for (i = 0; i < ulen; i++) {
|
||||
if (ubuf[i] == '\n') {
|
||||
if (seen_cr)
|
||||
n_crlf++;
|
||||
else
|
||||
n_lf++;
|
||||
last_line_end = i;
|
||||
} else if (seen_cr)
|
||||
n_cr++;
|
||||
|
||||
seen_cr = (ubuf[i] == '\r');
|
||||
if (seen_cr)
|
||||
last_line_end = i;
|
||||
|
||||
if (ubuf[i] == 0x85) { /* X3.64/ECMA-43 "next line" character */
|
||||
n_nel++;
|
||||
last_line_end = i;
|
||||
}
|
||||
|
||||
/* If this line is _longer_ than MAXLINELEN, remember it. */
|
||||
if (i > last_line_end + MAXLINELEN)
|
||||
has_long_lines = 1;
|
||||
|
||||
if (ubuf[i] == '\033')
|
||||
has_escapes = 1;
|
||||
if (ubuf[i] == '\b')
|
||||
has_backspace = 1;
|
||||
}
|
||||
|
||||
/* Beware, if the data has been truncated, the final CR could have
|
||||
been followed by a LF. If we have HOWMANY bytes, it indicates
|
||||
that the data might have been truncated, probably even before
|
||||
this function was called. */
|
||||
if (seen_cr && nbytes < HOWMANY)
|
||||
n_cr++;
|
||||
|
||||
if (mime) {
|
||||
if (mime & MAGIC_MIME_TYPE) {
|
||||
if (subtype_mime) {
|
||||
if (file_printf(ms, subtype_mime) == -1)
|
||||
goto done;
|
||||
} else {
|
||||
if (file_printf(ms, "text/plain") == -1)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
if ((mime == 0 || mime == MAGIC_MIME) && code_mime) {
|
||||
if ((mime & MAGIC_MIME_TYPE) &&
|
||||
file_printf(ms, "; charset=") == -1)
|
||||
goto done;
|
||||
if (file_printf(ms, code_mime) == -1)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (mime == MAGIC_MIME_ENCODING)
|
||||
file_printf(ms, "binary");
|
||||
} else {
|
||||
if (file_printf(ms, code) == -1)
|
||||
goto done;
|
||||
|
||||
if (subtype) {
|
||||
if (file_printf(ms, " ") == -1)
|
||||
goto done;
|
||||
if (file_printf(ms, subtype) == -1)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (file_printf(ms, " ") == -1)
|
||||
goto done;
|
||||
if (file_printf(ms, type) == -1)
|
||||
goto done;
|
||||
|
||||
if (has_long_lines)
|
||||
if (file_printf(ms, ", with very long lines") == -1)
|
||||
goto done;
|
||||
|
||||
/*
|
||||
* Only report line terminators if we find one other than LF,
|
||||
* or if we find none at all.
|
||||
*/
|
||||
if ((n_crlf == 0 && n_cr == 0 && n_nel == 0 && n_lf == 0) ||
|
||||
(n_crlf != 0 || n_cr != 0 || n_nel != 0)) {
|
||||
if (file_printf(ms, ", with") == -1)
|
||||
goto done;
|
||||
|
||||
if (n_crlf == 0 && n_cr == 0 && n_nel == 0 && n_lf == 0) {
|
||||
if (file_printf(ms, " no") == -1)
|
||||
goto done;
|
||||
} else {
|
||||
if (n_crlf) {
|
||||
if (file_printf(ms, " CRLF") == -1)
|
||||
goto done;
|
||||
if (n_cr || n_lf || n_nel)
|
||||
if (file_printf(ms, ",") == -1)
|
||||
goto done;
|
||||
}
|
||||
if (n_cr) {
|
||||
if (file_printf(ms, " CR") == -1)
|
||||
goto done;
|
||||
if (n_lf || n_nel)
|
||||
if (file_printf(ms, ",") == -1)
|
||||
goto done;
|
||||
}
|
||||
if (n_lf) {
|
||||
if (file_printf(ms, " LF") == -1)
|
||||
goto done;
|
||||
if (n_nel)
|
||||
if (file_printf(ms, ",") == -1)
|
||||
goto done;
|
||||
}
|
||||
if (n_nel)
|
||||
if (file_printf(ms, " NEL") == -1)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (file_printf(ms, " line terminators") == -1)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (has_escapes)
|
||||
if (file_printf(ms, ", with escape sequences") == -1)
|
||||
goto done;
|
||||
if (has_backspace)
|
||||
if (file_printf(ms, ", with overstriking") == -1)
|
||||
goto done;
|
||||
}
|
||||
rv = 1;
|
||||
done:
|
||||
if (nbuf)
|
||||
efree(nbuf);
|
||||
if (ubuf)
|
||||
efree(ubuf);
|
||||
if (utf8_buf)
|
||||
efree(utf8_buf);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
private int
|
||||
ascmatch(const unsigned char *s, const unichar *us, size_t ulen)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < ulen; i++) {
|
||||
if (s[i] != us[i])
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (s[i])
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* This table reflects a particular philosophy about what constitutes
|
||||
* "text," and there is room for disagreement about it.
|
||||
*
|
||||
* Version 3.31 of the file command considered a file to be ASCII if
|
||||
* each of its characters was approved by either the isascii() or
|
||||
* isalpha() function. On most systems, this would mean that any
|
||||
* file consisting only of characters in the range 0x00 ... 0x7F
|
||||
* would be called ASCII text, but many systems might reasonably
|
||||
* consider some characters outside this range to be alphabetic,
|
||||
* so the file command would call such characters ASCII. It might
|
||||
* have been more accurate to call this "considered textual on the
|
||||
* local system" than "ASCII."
|
||||
*
|
||||
* It considered a file to be "International language text" if each
|
||||
* of its characters was either an ASCII printing character (according
|
||||
* to the real ASCII standard, not the above test), a character in
|
||||
* the range 0x80 ... 0xFF, or one of the following control characters:
|
||||
* backspace, tab, line feed, vertical tab, form feed, carriage return,
|
||||
* escape. No attempt was made to determine the language in which files
|
||||
* of this type were written.
|
||||
*
|
||||
*
|
||||
* The table below considers a file to be ASCII if all of its characters
|
||||
* are either ASCII printing characters (again, according to the X3.4
|
||||
* standard, not isascii()) or any of the following controls: bell,
|
||||
* backspace, tab, line feed, form feed, carriage return, esc, nextline.
|
||||
*
|
||||
* I include bell because some programs (particularly shell scripts)
|
||||
* use it literally, even though it is rare in normal text. I exclude
|
||||
* vertical tab because it never seems to be used in real text. I also
|
||||
* include, with hesitation, the X3.64/ECMA-43 control nextline (0x85),
|
||||
* because that's what the dd EBCDIC->ASCII table maps the EBCDIC newline
|
||||
* character to. It might be more appropriate to include it in the 8859
|
||||
* set instead of the ASCII set, but it's got to be included in *something*
|
||||
* we recognize or EBCDIC files aren't going to be considered textual.
|
||||
* Some old Unix source files use SO/SI (^N/^O) to shift between Greek
|
||||
* and Latin characters, so these should possibly be allowed. But they
|
||||
* make a real mess on VT100-style displays if they're not paired properly,
|
||||
* so we are probably better off not calling them text.
|
||||
*
|
||||
* A file is considered to be ISO-8859 text if its characters are all
|
||||
* either ASCII, according to the above definition, or printing characters
|
||||
* from the ISO-8859 8-bit extension, characters 0xA0 ... 0xFF.
|
||||
*
|
||||
* Finally, a file is considered to be international text from some other
|
||||
* character code if its characters are all either ISO-8859 (according to
|
||||
* the above definition) or characters in the range 0x80 ... 0x9F, which
|
||||
* ISO-8859 considers to be control characters but the IBM PC and Macintosh
|
||||
* consider to be printing characters.
|
||||
*/
|
||||
|
||||
#define F 0 /* character never appears in text */
|
||||
#define T 1 /* character appears in plain ASCII text */
|
||||
#define I 2 /* character appears in ISO-8859 text */
|
||||
#define X 3 /* character appears in non-ISO extended ASCII (Mac, IBM PC) */
|
||||
|
||||
private char text_chars[256] = {
|
||||
/* BEL BS HT LF FF CR */
|
||||
F, F, F, F, F, F, F, T, T, T, T, F, T, T, F, F, /* 0x0X */
|
||||
/* ESC */
|
||||
F, F, F, F, F, F, F, F, F, F, F, T, F, F, F, F, /* 0x1X */
|
||||
T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x2X */
|
||||
T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x3X */
|
||||
T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x4X */
|
||||
T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x5X */
|
||||
T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x6X */
|
||||
T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, F, /* 0x7X */
|
||||
/* NEL */
|
||||
X, X, X, X, X, T, X, X, X, X, X, X, X, X, X, X, /* 0x8X */
|
||||
X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, /* 0x9X */
|
||||
I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xaX */
|
||||
I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xbX */
|
||||
I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xcX */
|
||||
I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xdX */
|
||||
I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xeX */
|
||||
I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I /* 0xfX */
|
||||
};
|
||||
|
||||
private int
|
||||
looks_ascii(const unsigned char *buf, size_t nbytes, unichar *ubuf,
|
||||
size_t *ulen)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
*ulen = 0;
|
||||
|
||||
for (i = 0; i < nbytes; i++) {
|
||||
int t = text_chars[buf[i]];
|
||||
|
||||
if (t != T)
|
||||
return 0;
|
||||
|
||||
ubuf[(*ulen)++] = buf[i];
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private int
|
||||
looks_latin1(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
*ulen = 0;
|
||||
|
||||
for (i = 0; i < nbytes; i++) {
|
||||
int t = text_chars[buf[i]];
|
||||
|
||||
if (t != T && t != I)
|
||||
return 0;
|
||||
|
||||
ubuf[(*ulen)++] = buf[i];
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private int
|
||||
looks_extended(const unsigned char *buf, size_t nbytes, unichar *ubuf,
|
||||
size_t *ulen)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
*ulen = 0;
|
||||
|
||||
for (i = 0; i < nbytes; i++) {
|
||||
int t = text_chars[buf[i]];
|
||||
|
||||
if (t != T && t != I && t != X)
|
||||
return 0;
|
||||
|
||||
ubuf[(*ulen)++] = buf[i];
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode Unicode string as UTF-8, returning pointer to character
|
||||
* after end of string, or NULL if an invalid character is found.
|
||||
*/
|
||||
private unsigned char *
|
||||
encode_utf8(unsigned char *buf, size_t len, unichar *ubuf, size_t ulen)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char *end = buf + len;
|
||||
|
||||
for (i = 0; i < ulen; i++) {
|
||||
if (ubuf[i] <= 0x7f) {
|
||||
if (end - buf < 1)
|
||||
return NULL;
|
||||
*buf++ = (unsigned char)ubuf[i];
|
||||
} else if (ubuf[i] <= 0x7ff) {
|
||||
if (end - buf < 2)
|
||||
return NULL;
|
||||
*buf++ = (unsigned char)((ubuf[i] >> 6) + 0xc0);
|
||||
*buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
|
||||
} else if (ubuf[i] <= 0xffff) {
|
||||
if (end - buf < 3)
|
||||
return NULL;
|
||||
*buf++ = (unsigned char)((ubuf[i] >> 12) + 0xe0);
|
||||
*buf++ = (unsigned char)(((ubuf[i] >> 6) & 0x3f) + 0x80);
|
||||
*buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
|
||||
} else if (ubuf[i] <= 0x1fffff) {
|
||||
if (end - buf < 4)
|
||||
return NULL;
|
||||
*buf++ = (unsigned char)((ubuf[i] >> 18) + 0xf0);
|
||||
*buf++ = (unsigned char)(((ubuf[i] >> 12) & 0x3f) + 0x80);
|
||||
*buf++ = (unsigned char)(((ubuf[i] >> 6) & 0x3f) + 0x80);
|
||||
*buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
|
||||
} else if (ubuf[i] <= 0x3ffffff) {
|
||||
if (end - buf < 5)
|
||||
return NULL;
|
||||
*buf++ = (unsigned char)((ubuf[i] >> 24) + 0xf8);
|
||||
*buf++ = (unsigned char)(((ubuf[i] >> 18) & 0x3f) + 0x80);
|
||||
*buf++ = (unsigned char)(((ubuf[i] >> 12) & 0x3f) + 0x80);
|
||||
*buf++ = (unsigned char)(((ubuf[i] >> 6) & 0x3f) + 0x80);
|
||||
*buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
|
||||
} else if (ubuf[i] <= 0x7fffffff) {
|
||||
if (end - buf < 6)
|
||||
return NULL;
|
||||
*buf++ = (unsigned char)((ubuf[i] >> 30) + 0xfc);
|
||||
*buf++ = (unsigned char)(((ubuf[i] >> 24) & 0x3f) + 0x80);
|
||||
*buf++ = (unsigned char)(((ubuf[i] >> 18) & 0x3f) + 0x80);
|
||||
*buf++ = (unsigned char)(((ubuf[i] >> 12) & 0x3f) + 0x80);
|
||||
*buf++ = (unsigned char)(((ubuf[i] >> 6) & 0x3f) + 0x80);
|
||||
*buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
|
||||
} else /* Invalid character */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decide whether some text looks like UTF-8. Returns:
|
||||
*
|
||||
* -1: invalid UTF-8
|
||||
* 0: uses odd control characters, so doesn't look like text
|
||||
* 1: 7-bit text
|
||||
* 2: definitely UTF-8 text (valid high-bit set bytes)
|
||||
*
|
||||
* If ubuf is non-NULL on entry, text is decoded into ubuf, *ulen;
|
||||
* ubuf must be big enough!
|
||||
*/
|
||||
protected int
|
||||
file_looks_utf8(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
|
||||
{
|
||||
size_t i;
|
||||
int n;
|
||||
unichar c;
|
||||
int gotone = 0, ctrl = 0;
|
||||
|
||||
if (ubuf)
|
||||
*ulen = 0;
|
||||
|
||||
for (i = 0; i < nbytes; i++) {
|
||||
if ((buf[i] & 0x80) == 0) { /* 0xxxxxxx is plain ASCII */
|
||||
/*
|
||||
* Even if the whole file is valid UTF-8 sequences,
|
||||
* still reject it if it uses weird control characters.
|
||||
*/
|
||||
|
||||
if (text_chars[buf[i]] != T)
|
||||
ctrl = 1;
|
||||
|
||||
if (ubuf)
|
||||
ubuf[(*ulen)++] = buf[i];
|
||||
} else if ((buf[i] & 0x40) == 0) { /* 10xxxxxx never 1st byte */
|
||||
return -1;
|
||||
} else { /* 11xxxxxx begins UTF-8 */
|
||||
int following;
|
||||
|
||||
if ((buf[i] & 0x20) == 0) { /* 110xxxxx */
|
||||
c = buf[i] & 0x1f;
|
||||
following = 1;
|
||||
} else if ((buf[i] & 0x10) == 0) { /* 1110xxxx */
|
||||
c = buf[i] & 0x0f;
|
||||
following = 2;
|
||||
} else if ((buf[i] & 0x08) == 0) { /* 11110xxx */
|
||||
c = buf[i] & 0x07;
|
||||
following = 3;
|
||||
} else if ((buf[i] & 0x04) == 0) { /* 111110xx */
|
||||
c = buf[i] & 0x03;
|
||||
following = 4;
|
||||
} else if ((buf[i] & 0x02) == 0) { /* 1111110x */
|
||||
c = buf[i] & 0x01;
|
||||
following = 5;
|
||||
} else
|
||||
return -1;
|
||||
|
||||
for (n = 0; n < following; n++) {
|
||||
i++;
|
||||
if (i >= nbytes)
|
||||
goto done;
|
||||
|
||||
if ((buf[i] & 0x80) == 0 || (buf[i] & 0x40))
|
||||
return -1;
|
||||
|
||||
c = (c << 6) + (buf[i] & 0x3f);
|
||||
}
|
||||
|
||||
if (ubuf)
|
||||
ubuf[(*ulen)++] = c;
|
||||
gotone = 1;
|
||||
}
|
||||
}
|
||||
done:
|
||||
return ctrl ? 0 : (gotone ? 2 : 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Decide whether some text looks like UTF-8 with BOM. If there is no
|
||||
* BOM, return -1; otherwise return the result of looks_utf8 on the
|
||||
* rest of the text.
|
||||
*/
|
||||
private int
|
||||
looks_utf8_with_BOM(const unsigned char *buf, size_t nbytes, unichar *ubuf,
|
||||
size_t *ulen)
|
||||
{
|
||||
if (nbytes > 3 && buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf)
|
||||
return file_looks_utf8(buf + 3, nbytes - 3, ubuf, ulen);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int
|
||||
looks_ucs16(const unsigned char *buf, size_t nbytes, unichar *ubuf,
|
||||
size_t *ulen)
|
||||
{
|
||||
int bigend;
|
||||
size_t i;
|
||||
|
||||
if (nbytes < 2)
|
||||
return 0;
|
||||
|
||||
if (buf[0] == 0xff && buf[1] == 0xfe)
|
||||
bigend = 0;
|
||||
else if (buf[0] == 0xfe && buf[1] == 0xff)
|
||||
bigend = 1;
|
||||
else
|
||||
return 0;
|
||||
|
||||
*ulen = 0;
|
||||
|
||||
for (i = 2; i + 1 < nbytes; i += 2) {
|
||||
/* XXX fix to properly handle chars > 65536 */
|
||||
|
||||
if (bigend)
|
||||
ubuf[(*ulen)++] = buf[i + 1] + 256 * buf[i];
|
||||
else
|
||||
ubuf[(*ulen)++] = buf[i] + 256 * buf[i + 1];
|
||||
|
||||
if (ubuf[*ulen - 1] == 0xfffe)
|
||||
return 0;
|
||||
if (ubuf[*ulen - 1] < 128 &&
|
||||
text_chars[(size_t)ubuf[*ulen - 1]] != T)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1 + bigend;
|
||||
}
|
||||
|
||||
#undef F
|
||||
#undef T
|
||||
#undef I
|
||||
#undef X
|
||||
|
||||
/*
|
||||
* This table maps each EBCDIC character to an (8-bit extended) ASCII
|
||||
* character, as specified in the rationale for the dd(1) command in
|
||||
* draft 11.2 (September, 1991) of the POSIX P1003.2 standard.
|
||||
*
|
||||
* Unfortunately it does not seem to correspond exactly to any of the
|
||||
* five variants of EBCDIC documented in IBM's _Enterprise Systems
|
||||
* Architecture/390: Principles of Operation_, SA22-7201-06, Seventh
|
||||
* Edition, July, 1999, pp. I-1 - I-4.
|
||||
*
|
||||
* Fortunately, though, all versions of EBCDIC, including this one, agree
|
||||
* on most of the printing characters that also appear in (7-bit) ASCII.
|
||||
* Of these, only '|', '!', '~', '^', '[', and ']' are in question at all.
|
||||
*
|
||||
* Fortunately too, there is general agreement that codes 0x00 through
|
||||
* 0x3F represent control characters, 0x41 a nonbreaking space, and the
|
||||
* remainder printing characters.
|
||||
*
|
||||
* This is sufficient to allow us to identify EBCDIC text and to distinguish
|
||||
* between old-style and internationalized examples of text.
|
||||
*/
|
||||
|
||||
private unsigned char ebcdic_to_ascii[] = {
|
||||
0, 1, 2, 3, 156, 9, 134, 127, 151, 141, 142, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 157, 133, 8, 135, 24, 25, 146, 143, 28, 29, 30, 31,
|
||||
128, 129, 130, 131, 132, 10, 23, 27, 136, 137, 138, 139, 140, 5, 6, 7,
|
||||
144, 145, 22, 147, 148, 149, 150, 4, 152, 153, 154, 155, 20, 21, 158, 26,
|
||||
' ', 160, 161, 162, 163, 164, 165, 166, 167, 168, 213, '.', '<', '(', '+', '|',
|
||||
'&', 169, 170, 171, 172, 173, 174, 175, 176, 177, '!', '$', '*', ')', ';', '~',
|
||||
'-', '/', 178, 179, 180, 181, 182, 183, 184, 185, 203, ',', '%', '_', '>', '?',
|
||||
186, 187, 188, 189, 190, 191, 192, 193, 194, '`', ':', '#', '@', '\'','=', '"',
|
||||
195, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 196, 197, 198, 199, 200, 201,
|
||||
202, 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', '^', 204, 205, 206, 207, 208,
|
||||
209, 229, 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 210, 211, 212, '[', 214, 215,
|
||||
216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, ']', 230, 231,
|
||||
'{', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 232, 233, 234, 235, 236, 237,
|
||||
'}', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 238, 239, 240, 241, 242, 243,
|
||||
'\\',159, 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 244, 245, 246, 247, 248, 249,
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 250, 251, 252, 253, 254, 255
|
||||
};
|
||||
|
||||
#ifdef notdef
|
||||
/*
|
||||
* The following EBCDIC-to-ASCII table may relate more closely to reality,
|
||||
* or at least to modern reality. It comes from
|
||||
*
|
||||
* http://ftp.s390.ibm.com/products/oe/bpxqp9.html
|
||||
*
|
||||
* and maps the characters of EBCDIC code page 1047 (the code used for
|
||||
* Unix-derived software on IBM's 390 systems) to the corresponding
|
||||
* characters from ISO 8859-1.
|
||||
*
|
||||
* If this table is used instead of the above one, some of the special
|
||||
* cases for the NEL character can be taken out of the code.
|
||||
*/
|
||||
|
||||
private unsigned char ebcdic_1047_to_8859[] = {
|
||||
0x00,0x01,0x02,0x03,0x9C,0x09,0x86,0x7F,0x97,0x8D,0x8E,0x0B,0x0C,0x0D,0x0E,0x0F,
|
||||
0x10,0x11,0x12,0x13,0x9D,0x0A,0x08,0x87,0x18,0x19,0x92,0x8F,0x1C,0x1D,0x1E,0x1F,
|
||||
0x80,0x81,0x82,0x83,0x84,0x85,0x17,0x1B,0x88,0x89,0x8A,0x8B,0x8C,0x05,0x06,0x07,
|
||||
0x90,0x91,0x16,0x93,0x94,0x95,0x96,0x04,0x98,0x99,0x9A,0x9B,0x14,0x15,0x9E,0x1A,
|
||||
0x20,0xA0,0xE2,0xE4,0xE0,0xE1,0xE3,0xE5,0xE7,0xF1,0xA2,0x2E,0x3C,0x28,0x2B,0x7C,
|
||||
0x26,0xE9,0xEA,0xEB,0xE8,0xED,0xEE,0xEF,0xEC,0xDF,0x21,0x24,0x2A,0x29,0x3B,0x5E,
|
||||
0x2D,0x2F,0xC2,0xC4,0xC0,0xC1,0xC3,0xC5,0xC7,0xD1,0xA6,0x2C,0x25,0x5F,0x3E,0x3F,
|
||||
0xF8,0xC9,0xCA,0xCB,0xC8,0xCD,0xCE,0xCF,0xCC,0x60,0x3A,0x23,0x40,0x27,0x3D,0x22,
|
||||
0xD8,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0xAB,0xBB,0xF0,0xFD,0xFE,0xB1,
|
||||
0xB0,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,0xAA,0xBA,0xE6,0xB8,0xC6,0xA4,
|
||||
0xB5,0x7E,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0xA1,0xBF,0xD0,0x5B,0xDE,0xAE,
|
||||
0xAC,0xA3,0xA5,0xB7,0xA9,0xA7,0xB6,0xBC,0xBD,0xBE,0xDD,0xA8,0xAF,0x5D,0xB4,0xD7,
|
||||
0x7B,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0xAD,0xF4,0xF6,0xF2,0xF3,0xF5,
|
||||
0x7D,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0xB9,0xFB,0xFC,0xF9,0xFA,0xFF,
|
||||
0x5C,0xF7,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0xB2,0xD4,0xD6,0xD2,0xD3,0xD5,
|
||||
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0xB3,0xDB,0xDC,0xD9,0xDA,0x9F
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copy buf[0 ... nbytes-1] into out[], translating EBCDIC to ASCII.
|
||||
*/
|
||||
private void
|
||||
from_ebcdic(const unsigned char *buf, size_t nbytes, unsigned char *out)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nbytes; i++) {
|
||||
out[i] = ebcdic_to_ascii[buf[i]];
|
||||
}
|
||||
}
|
||||
@@ -1,492 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
* Software written by Ian F. Darwin and others;
|
||||
* maintained 1995-present by Christos Zoulas and others.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice immediately at the beginning of the file, without modification,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* compress routines:
|
||||
* zmagic() - returns 0 if not recognized, uncompresses and prints
|
||||
* information if recognized
|
||||
* uncompress(method, old, n, newch) - uncompress old into new,
|
||||
* using method, return sizeof new
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "file.h"
|
||||
#include "magic.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#ifndef PHP_WIN32
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_WAIT_H
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
#if defined(HAVE_SYS_TIME_H)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#if defined(HAVE_ZLIB_H) && defined(HAVE_LIBZ)
|
||||
#define BUILTIN_DECOMPRESS
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
#undef FIONREAD
|
||||
|
||||
#ifndef lint
|
||||
FILE_RCSID("@(#)$File: compress.c,v 1.56 2008/02/07 00:58:52 christos Exp $")
|
||||
#endif
|
||||
|
||||
private const struct {
|
||||
const char magic[8];
|
||||
size_t maglen;
|
||||
const char *argv[3];
|
||||
int silent;
|
||||
} compr[] = {
|
||||
{ "\037\235", 2, { "gzip", "-cdq", NULL }, 1 }, /* compressed */
|
||||
/* Uncompress can get stuck; so use gzip first if we have it
|
||||
* Idea from Damien Clark, thanks! */
|
||||
{ "\037\235", 2, { "uncompress", "-c", NULL }, 1 }, /* compressed */
|
||||
{ "\037\213", 2, { "gzip", "-cdq", NULL }, 1 }, /* gzipped */
|
||||
{ "\037\236", 2, { "gzip", "-cdq", NULL }, 1 }, /* frozen */
|
||||
{ "\037\240", 2, { "gzip", "-cdq", NULL }, 1 }, /* SCO LZH */
|
||||
/* the standard pack utilities do not accept standard input */
|
||||
{ "\037\036", 2, { "gzip", "-cdq", NULL }, 0 }, /* packed */
|
||||
{ "PK\3\4", 4, { "gzip", "-cdq", NULL }, 1 }, /* pkzipped, */
|
||||
/* ...only first file examined */
|
||||
{ "BZh", 3, { "bzip2", "-cd", NULL }, 1 }, /* bzip2-ed */
|
||||
};
|
||||
|
||||
#define NODATA ((size_t)~0)
|
||||
|
||||
|
||||
private ssize_t swrite(int, const void *, size_t);
|
||||
#ifdef PHP_FILEINFO_UNCOMPRESS
|
||||
private size_t uncompressbuf(struct magic_set *, int, size_t,
|
||||
const unsigned char *, unsigned char **, size_t);
|
||||
#ifdef BUILTIN_DECOMPRESS
|
||||
private size_t uncompressgzipped(struct magic_set *, const unsigned char *,
|
||||
unsigned char **, size_t);
|
||||
#endif
|
||||
|
||||
protected int
|
||||
file_zmagic(struct magic_set *ms, int fd, const char *name,
|
||||
const unsigned char *buf, size_t nbytes)
|
||||
{
|
||||
unsigned char *newbuf = NULL;
|
||||
size_t i, nsz;
|
||||
int rv = 0;
|
||||
int mime = ms->flags & MAGIC_MIME;
|
||||
|
||||
if ((ms->flags & MAGIC_COMPRESS) == 0)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < ncompr; i++) {
|
||||
if (nbytes < compr[i].maglen)
|
||||
continue;
|
||||
if (memcmp(buf, compr[i].magic, compr[i].maglen) == 0 &&
|
||||
(nsz = uncompressbuf(ms, fd, i, buf, &newbuf,
|
||||
nbytes)) != NODATA) {
|
||||
ms->flags &= ~MAGIC_COMPRESS;
|
||||
rv = -1;
|
||||
if (file_buffer(ms, -1, name, newbuf, nsz) == -1)
|
||||
goto error;
|
||||
|
||||
if (mime == MAGIC_MIME || mime == 0) {
|
||||
if (file_printf(ms, mime ?
|
||||
" compressed-encoding=" : " (") == -1)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((mime == 0 || mime & MAGIC_MIME_ENCODING) &&
|
||||
file_buffer(ms, -1, NULL, buf, nbytes) == -1)
|
||||
goto error;
|
||||
|
||||
if (!mime && file_printf(ms, ")") == -1)
|
||||
goto error;
|
||||
rv = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
error:
|
||||
if (newbuf)
|
||||
efree(newbuf);
|
||||
ms->flags |= MAGIC_COMPRESS;
|
||||
return rv;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* `safe' write for sockets and pipes.
|
||||
*/
|
||||
private ssize_t
|
||||
swrite(int fd, const void *buf, size_t n)
|
||||
{
|
||||
int rv;
|
||||
size_t rn = n;
|
||||
|
||||
do
|
||||
switch (rv = write(fd, buf, n)) {
|
||||
case -1:
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
return -1;
|
||||
default:
|
||||
n -= rv;
|
||||
buf = ((const char *)buf) + rv;
|
||||
break;
|
||||
}
|
||||
while (n > 0);
|
||||
return rn;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* `safe' read for sockets and pipes.
|
||||
*/
|
||||
protected ssize_t
|
||||
sread(int fd, void *buf, size_t n, int canbepipe)
|
||||
{
|
||||
int rv;
|
||||
#ifdef FIONREAD
|
||||
int t = 0;
|
||||
#endif
|
||||
size_t rn = n;
|
||||
|
||||
if (fd == STDIN_FILENO)
|
||||
goto nocheck;
|
||||
|
||||
#ifdef FIONREAD
|
||||
if ((canbepipe && (ioctl(fd, FIONREAD, &t) == -1)) || (t == 0)) {
|
||||
#ifdef FD_ZERO
|
||||
for (cnt = 0;; cnt++) {
|
||||
fd_set check;
|
||||
struct timeval tout = {0, 100 * 1000};
|
||||
int selrv;
|
||||
|
||||
FD_ZERO(&check);
|
||||
FD_SET(fd, &check);
|
||||
|
||||
/*
|
||||
* Avoid soft deadlock: do not read if there
|
||||
* is nothing to read from sockets and pipes.
|
||||
*/
|
||||
selrv = select(fd + 1, &check, NULL, NULL, &tout);
|
||||
if (selrv == -1) {
|
||||
if (errno == EINTR || errno == EAGAIN)
|
||||
continue;
|
||||
} else if (selrv == 0 && cnt >= 5) {
|
||||
return 0;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
(void)ioctl(fd, FIONREAD, &t);
|
||||
}
|
||||
|
||||
if (t > 0 && (size_t)t < n) {
|
||||
n = t;
|
||||
rn = n;
|
||||
}
|
||||
#endif
|
||||
|
||||
nocheck:
|
||||
do
|
||||
switch ((rv = read(fd, buf, n))) {
|
||||
case -1:
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
return -1;
|
||||
case 0:
|
||||
return rn - n;
|
||||
default:
|
||||
n -= rv;
|
||||
buf = ((char *)buf) + rv;
|
||||
break;
|
||||
}
|
||||
while (n > 0);
|
||||
return rn;
|
||||
}
|
||||
|
||||
protected int
|
||||
file_pipe2file(struct magic_set *ms, int fd, const void *startbuf,
|
||||
size_t nbytes)
|
||||
{
|
||||
char buf[4096];
|
||||
int r, tfd;
|
||||
|
||||
(void)strcpy(buf, "/tmp/file.XXXXXX");
|
||||
#ifndef HAVE_MKSTEMP
|
||||
{
|
||||
char *ptr = mktemp(buf);
|
||||
tfd = open(ptr, O_RDWR|O_TRUNC|O_EXCL|O_CREAT, 0600);
|
||||
r = errno;
|
||||
(void)unlink(ptr);
|
||||
errno = r;
|
||||
}
|
||||
#else
|
||||
tfd = mkstemp(buf);
|
||||
r = errno;
|
||||
(void)unlink(buf);
|
||||
errno = r;
|
||||
#endif
|
||||
if (tfd == -1) {
|
||||
file_error(ms, errno,
|
||||
"cannot create temporary file for pipe copy");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (swrite(tfd, startbuf, nbytes) != (ssize_t)nbytes)
|
||||
r = 1;
|
||||
else {
|
||||
while ((r = sread(fd, buf, sizeof(buf), 1)) > 0)
|
||||
if (swrite(tfd, buf, (size_t)r) != r)
|
||||
break;
|
||||
}
|
||||
|
||||
switch (r) {
|
||||
case -1:
|
||||
file_error(ms, errno, "error copying from pipe to temp file");
|
||||
return -1;
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
file_error(ms, errno, "error while writing to temp file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* We duplicate the file descriptor, because fclose on a
|
||||
* tmpfile will delete the file, but any open descriptors
|
||||
* can still access the phantom inode.
|
||||
*/
|
||||
if ((fd = dup2(tfd, fd)) == -1) {
|
||||
file_error(ms, errno, "could not dup descriptor for temp file");
|
||||
return -1;
|
||||
}
|
||||
(void)close(tfd);
|
||||
if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
|
||||
file_badseek(ms);
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
#ifdef PHP_FILEINFO_UNCOMPRESS
|
||||
#ifdef BUILTIN_DECOMPRESS
|
||||
|
||||
#define FHCRC (1 << 1)
|
||||
#define FEXTRA (1 << 2)
|
||||
#define FNAME (1 << 3)
|
||||
#define FCOMMENT (1 << 4)
|
||||
|
||||
private size_t
|
||||
uncompressgzipped(struct magic_set *ms, const unsigned char *old,
|
||||
unsigned char **newch, size_t n)
|
||||
{
|
||||
unsigned char flg = old[3];
|
||||
size_t data_start = 10;
|
||||
z_stream z;
|
||||
int rc;
|
||||
|
||||
if (flg & FEXTRA) {
|
||||
if (data_start+1 >= n)
|
||||
return 0;
|
||||
data_start += 2 + old[data_start] + old[data_start + 1] * 256;
|
||||
}
|
||||
if (flg & FNAME) {
|
||||
while(data_start < n && old[data_start])
|
||||
data_start++;
|
||||
data_start++;
|
||||
}
|
||||
if(flg & FCOMMENT) {
|
||||
while(data_start < n && old[data_start])
|
||||
data_start++;
|
||||
data_start++;
|
||||
}
|
||||
if(flg & FHCRC)
|
||||
data_start += 2;
|
||||
|
||||
if (data_start >= n)
|
||||
return 0;
|
||||
*newch = (unsigned char *)emalloc(HOWMANY + 1));
|
||||
|
||||
/* XXX: const castaway, via strchr */
|
||||
z.next_in = (Bytef *)strchr((const char *)old + data_start,
|
||||
old[data_start]);
|
||||
z.avail_in = n - data_start;
|
||||
z.next_out = *newch;
|
||||
z.avail_out = HOWMANY;
|
||||
z.zalloc = Z_NULL;
|
||||
z.zfree = Z_NULL;
|
||||
z.opaque = Z_NULL;
|
||||
|
||||
rc = inflateInit2(&z, -15);
|
||||
if (rc != Z_OK) {
|
||||
file_error(ms, 0, "zlib: %s", z.msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
rc = inflate(&z, Z_SYNC_FLUSH);
|
||||
if (rc != Z_OK && rc != Z_STREAM_END) {
|
||||
file_error(ms, 0, "zlib: %s", z.msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
n = (size_t)z.total_out;
|
||||
(void)inflateEnd(&z);
|
||||
|
||||
/* let's keep the nul-terminate tradition */
|
||||
(*newch)[n] = '\0';
|
||||
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
private size_t
|
||||
uncompressbuf(struct magic_set *ms, int fd, size_t method,
|
||||
const unsigned char *old, unsigned char **newch, size_t n)
|
||||
{
|
||||
int fdin[2], fdout[2];
|
||||
int r;
|
||||
|
||||
#ifdef BUILTIN_DECOMPRESS
|
||||
/* FIXME: This doesn't cope with bzip2 */
|
||||
if (method == 2)
|
||||
return uncompressgzipped(ms, old, newch, n);
|
||||
#endif
|
||||
(void)fflush(stdout);
|
||||
(void)fflush(stderr);
|
||||
|
||||
if ((fd != -1 && pipe(fdin) == -1) || pipe(fdout) == -1) {
|
||||
file_error(ms, errno, "cannot create pipe");
|
||||
return NODATA;
|
||||
}
|
||||
switch (fork()) {
|
||||
case 0: /* child */
|
||||
(void) close(0);
|
||||
if (fd != -1) {
|
||||
(void) dup(fd);
|
||||
(void) lseek(0, (off_t)0, SEEK_SET);
|
||||
} else {
|
||||
(void) dup(fdin[0]);
|
||||
(void) close(fdin[0]);
|
||||
(void) close(fdin[1]);
|
||||
}
|
||||
|
||||
(void) close(1);
|
||||
(void) dup(fdout[1]);
|
||||
(void) close(fdout[0]);
|
||||
(void) close(fdout[1]);
|
||||
#ifndef DEBUG
|
||||
if (compr[method].silent)
|
||||
(void)close(2);
|
||||
#endif
|
||||
|
||||
(void)execvp(compr[method].argv[0],
|
||||
(char *const *)(intptr_t)compr[method].argv);
|
||||
#ifdef DEBUG
|
||||
(void)fprintf(stderr, "exec `%s' failed (%s)\n",
|
||||
compr[method].argv[0], strerror(errno));
|
||||
#endif
|
||||
exit(1);
|
||||
/*NOTREACHED*/
|
||||
case -1:
|
||||
file_error(ms, errno, "could not fork");
|
||||
return NODATA;
|
||||
|
||||
default: /* parent */
|
||||
(void) close(fdout[1]);
|
||||
if (fd == -1) {
|
||||
(void) close(fdin[0]);
|
||||
/*
|
||||
* fork again, to avoid blocking because both
|
||||
* pipes filled
|
||||
*/
|
||||
switch (fork()) {
|
||||
case 0: /* child */
|
||||
(void)close(fdout[0]);
|
||||
if (swrite(fdin[1], old, n) != (ssize_t)n) {
|
||||
#ifdef DEBUG
|
||||
(void)fprintf(stderr,
|
||||
"Write failed (%s)\n",
|
||||
strerror(errno));
|
||||
#endif
|
||||
exit(1);
|
||||
}
|
||||
exit(0);
|
||||
/*NOTREACHED*/
|
||||
|
||||
case -1:
|
||||
#ifdef DEBUG
|
||||
(void)fprintf(stderr, "Fork failed (%s)\n",
|
||||
strerror(errno));
|
||||
#endif
|
||||
exit(1);
|
||||
/*NOTREACHED*/
|
||||
|
||||
default: /* parent */
|
||||
break;
|
||||
}
|
||||
(void) close(fdin[1]);
|
||||
fdin[1] = -1;
|
||||
}
|
||||
|
||||
*newch = (unsigned char *) emalloc(HOWMANY + 1);
|
||||
|
||||
if ((r = sread(fdout[0], *newch, HOWMANY, 0)) <= 0) {
|
||||
#ifdef DEBUG
|
||||
(void)fprintf(stderr, "Read failed (%s)\n",
|
||||
strerror(errno));
|
||||
#endif
|
||||
efree(*newch);
|
||||
n = 0;
|
||||
newch[0] = '\0';
|
||||
goto err;
|
||||
} else {
|
||||
n = r;
|
||||
}
|
||||
/* NUL terminate, as every buffer is handled here. */
|
||||
(*newch)[n] = '\0';
|
||||
err:
|
||||
if (fdin[1] != -1)
|
||||
(void) close(fdin[1]);
|
||||
(void) close(fdout[0]);
|
||||
#ifdef WNOHANG
|
||||
while (waitpid(-1, NULL, WNOHANG) != -1)
|
||||
continue;
|
||||
#else
|
||||
(void)wait(NULL);
|
||||
#endif
|
||||
return n;
|
||||
}
|
||||
}
|
||||
#endif /* if PHP_FILEINFO_UNCOMPRESS */
|
||||
@@ -1 +0,0 @@
|
||||
#include "php.h"
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Christos Zoulas 2008.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice immediately at the beginning of the file, without modification,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
if (nbytes <= sizeof(elfhdr))
|
||||
return 0;
|
||||
|
||||
u.l = 1;
|
||||
(void)memcpy(&elfhdr, buf, sizeof elfhdr);
|
||||
swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
|
||||
|
||||
type = elf_getu16(swap, elfhdr.e_type);
|
||||
switch (type) {
|
||||
#ifdef ELFCORE
|
||||
case ET_CORE:
|
||||
if (dophn_core(ms, clazz, swap, fd,
|
||||
(off_t)elf_getu(swap, elfhdr.e_phoff),
|
||||
elf_getu16(swap, elfhdr.e_phnum),
|
||||
(size_t)elf_getu16(swap, elfhdr.e_phentsize),
|
||||
fsize, &flags) == -1)
|
||||
return -1;
|
||||
break;
|
||||
#endif
|
||||
case ET_EXEC:
|
||||
case ET_DYN:
|
||||
if (dophn_exec(ms, clazz, swap, fd,
|
||||
(off_t)elf_getu(swap, elfhdr.e_phoff),
|
||||
elf_getu16(swap, elfhdr.e_phnum),
|
||||
(size_t)elf_getu16(swap, elfhdr.e_phentsize),
|
||||
fsize, &flags, elf_getu16(swap, elfhdr.e_shnum))
|
||||
== -1)
|
||||
return -1;
|
||||
/*FALLTHROUGH*/
|
||||
case ET_REL:
|
||||
if (doshn(ms, clazz, swap, fd,
|
||||
(off_t)elf_getu(swap, elfhdr.e_shoff),
|
||||
elf_getu16(swap, elfhdr.e_shnum),
|
||||
(size_t)elf_getu16(swap, elfhdr.e_shentsize),
|
||||
&flags,
|
||||
elf_getu16(swap, elfhdr.e_machine)) == -1)
|
||||
return -1;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
@@ -1,401 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
* Software written by Ian F. Darwin and others;
|
||||
* maintained 1995-present by Christos Zoulas and others.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice immediately at the beginning of the file, without modification,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* file.h - definitions for file(1) program
|
||||
* @(#)$File: file.h,v 1.103 2008/03/01 22:21:49 rrt Exp $
|
||||
*/
|
||||
|
||||
#ifndef __file_h__
|
||||
#define __file_h__
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h> /* Include that here, to make sure __P gets defined */
|
||||
#include <errno.h>
|
||||
#include <fcntl.h> /* For open and flags */
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#ifdef PHP_WIN32
|
||||
#include "win32/php_stdint.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
#include "ext/standard/php_string.h"
|
||||
#include "ext/pcre/php_pcre.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
/* Do this here and now, because struct stat gets re-defined on solaris */
|
||||
#include <sys/stat.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define ENABLE_CONDITIONALS
|
||||
|
||||
#ifndef MAGIC
|
||||
#define MAGIC "/etc/magic"
|
||||
#endif
|
||||
|
||||
#if defined(__EMX__) || defined(PHP_WIN32)
|
||||
#define PATHSEP ';'
|
||||
#else
|
||||
#define PATHSEP ':'
|
||||
#endif
|
||||
|
||||
#define private static
|
||||
#ifndef protected
|
||||
#define protected
|
||||
#endif
|
||||
#define public
|
||||
|
||||
#ifndef __GNUC_PREREQ__
|
||||
#ifdef __GNUC__
|
||||
#define __GNUC_PREREQ__(x, y) \
|
||||
((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \
|
||||
(__GNUC__ > (x)))
|
||||
#else
|
||||
#define __GNUC_PREREQ__(x, y) 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef HOWMANY
|
||||
# define HOWMANY (256 * 1024) /* how much of the file to look at */
|
||||
#endif
|
||||
#define MAXMAGIS 8192 /* max entries in any one magic file
|
||||
or directory */
|
||||
#define MAXDESC 64 /* max leng of text description/MIME type */
|
||||
#define MAXstring 32 /* max leng of "string" types */
|
||||
|
||||
#define MAGICNO 0xF11E041C
|
||||
#define VERSIONNO 6
|
||||
#define FILE_MAGICSIZE (32 * 6)
|
||||
|
||||
#define FILE_LOAD 0
|
||||
#define FILE_CHECK 1
|
||||
#define FILE_COMPILE 2
|
||||
|
||||
union VALUETYPE {
|
||||
uint8_t b;
|
||||
uint16_t h;
|
||||
uint32_t l;
|
||||
uint64_t q;
|
||||
uint8_t hs[2]; /* 2 bytes of a fixed-endian "short" */
|
||||
uint8_t hl[4]; /* 4 bytes of a fixed-endian "long" */
|
||||
uint8_t hq[8]; /* 8 bytes of a fixed-endian "quad" */
|
||||
char s[MAXstring]; /* the search string or regex pattern */
|
||||
unsigned char us[MAXstring];
|
||||
float f;
|
||||
double d;
|
||||
};
|
||||
|
||||
struct magic {
|
||||
/* Word 1 */
|
||||
uint16_t cont_level; /* level of ">" */
|
||||
uint8_t flag;
|
||||
#define INDIR 0x01 /* if '(...)' appears */
|
||||
#define OFFADD 0x02 /* if '>&' or '>...(&' appears */
|
||||
#define INDIROFFADD 0x04 /* if '>&(' appears */
|
||||
#define UNSIGNED 0x08 /* comparison is unsigned */
|
||||
#define NOSPACE 0x10 /* suppress space character before output */
|
||||
#define BINTEST 0x20 /* test is for a binary type (set only
|
||||
for top-level tests) */
|
||||
#define TEXTTEST 0 /* for passing to file_softmagic */
|
||||
|
||||
uint8_t factor;
|
||||
|
||||
/* Word 2 */
|
||||
uint8_t reln; /* relation (0=eq, '>'=gt, etc) */
|
||||
uint8_t vallen; /* length of string value, if any */
|
||||
uint8_t type; /* comparison type (FILE_*) */
|
||||
uint8_t in_type; /* type of indirection */
|
||||
#define FILE_INVALID 0
|
||||
#define FILE_BYTE 1
|
||||
#define FILE_SHORT 2
|
||||
#define FILE_DEFAULT 3
|
||||
#define FILE_LONG 4
|
||||
#define FILE_STRING 5
|
||||
#define FILE_DATE 6
|
||||
#define FILE_BESHORT 7
|
||||
#define FILE_BELONG 8
|
||||
#define FILE_BEDATE 9
|
||||
#define FILE_LESHORT 10
|
||||
#define FILE_LELONG 11
|
||||
#define FILE_LEDATE 12
|
||||
#define FILE_PSTRING 13
|
||||
#define FILE_LDATE 14
|
||||
#define FILE_BELDATE 15
|
||||
#define FILE_LELDATE 16
|
||||
#define FILE_REGEX 17
|
||||
#define FILE_BESTRING16 18
|
||||
#define FILE_LESTRING16 19
|
||||
#define FILE_SEARCH 20
|
||||
#define FILE_MEDATE 21
|
||||
#define FILE_MELDATE 22
|
||||
#define FILE_MELONG 23
|
||||
#define FILE_QUAD 24
|
||||
#define FILE_LEQUAD 25
|
||||
#define FILE_BEQUAD 26
|
||||
#define FILE_QDATE 27
|
||||
#define FILE_LEQDATE 28
|
||||
#define FILE_BEQDATE 29
|
||||
#define FILE_QLDATE 30
|
||||
#define FILE_LEQLDATE 31
|
||||
#define FILE_BEQLDATE 32
|
||||
#define FILE_FLOAT 33
|
||||
#define FILE_BEFLOAT 34
|
||||
#define FILE_LEFLOAT 35
|
||||
#define FILE_DOUBLE 36
|
||||
#define FILE_BEDOUBLE 37
|
||||
#define FILE_LEDOUBLE 38
|
||||
#define FILE_NAMES_SIZE 39/* size of array to contain all names */
|
||||
|
||||
#define IS_LIBMAGIC_STRING(t) \
|
||||
((t) == FILE_STRING || \
|
||||
(t) == FILE_PSTRING || \
|
||||
(t) == FILE_BESTRING16 || \
|
||||
(t) == FILE_LESTRING16 || \
|
||||
(t) == FILE_REGEX || \
|
||||
(t) == FILE_SEARCH || \
|
||||
(t) == FILE_DEFAULT)
|
||||
|
||||
#define FILE_FMT_NONE 0
|
||||
#define FILE_FMT_NUM 1 /* "cduxXi" */
|
||||
#define FILE_FMT_STR 2 /* "s" */
|
||||
#define FILE_FMT_QUAD 3 /* "ll" */
|
||||
#define FILE_FMT_FLOAT 4 /* "eEfFgG" */
|
||||
#define FILE_FMT_DOUBLE 5 /* "eEfFgG" */
|
||||
|
||||
/* Word 3 */
|
||||
uint8_t in_op; /* operator for indirection */
|
||||
uint8_t mask_op; /* operator for mask */
|
||||
#ifdef ENABLE_CONDITIONALS
|
||||
uint8_t cond; /* conditional type */
|
||||
#else
|
||||
uint8_t dummy;
|
||||
#endif
|
||||
uint8_t factor_op;
|
||||
#define FILE_FACTOR_OP_PLUS '+'
|
||||
#define FILE_FACTOR_OP_MINUS '-'
|
||||
#define FILE_FACTOR_OP_TIMES '*'
|
||||
#define FILE_FACTOR_OP_DIV '/'
|
||||
#define FILE_FACTOR_OP_NONE '\0'
|
||||
|
||||
#define FILE_OPS "&|^+-*/%"
|
||||
#define FILE_OPAND 0
|
||||
#define FILE_OPOR 1
|
||||
#define FILE_OPXOR 2
|
||||
#define FILE_OPADD 3
|
||||
#define FILE_OPMINUS 4
|
||||
#define FILE_OPMULTIPLY 5
|
||||
#define FILE_OPDIVIDE 6
|
||||
#define FILE_OPMODULO 7
|
||||
#define FILE_OPS_MASK 0x07 /* mask for above ops */
|
||||
#define FILE_UNUSED_1 0x08
|
||||
#define FILE_UNUSED_2 0x10
|
||||
#define FILE_UNUSED_3 0x20
|
||||
#define FILE_OPINVERSE 0x40
|
||||
#define FILE_OPINDIRECT 0x80
|
||||
|
||||
#ifdef ENABLE_CONDITIONALS
|
||||
#define COND_NONE 0
|
||||
#define COND_IF 1
|
||||
#define COND_ELIF 2
|
||||
#define COND_ELSE 3
|
||||
#endif /* ENABLE_CONDITIONALS */
|
||||
|
||||
/* Word 4 */
|
||||
uint32_t offset; /* offset to magic number */
|
||||
/* Word 5 */
|
||||
int32_t in_offset; /* offset from indirection */
|
||||
/* Word 6 */
|
||||
uint32_t lineno; /* line number in magic file */
|
||||
/* Word 7,8 */
|
||||
union {
|
||||
uint64_t _mask; /* for use with numeric and date types */
|
||||
struct {
|
||||
uint32_t _count; /* repeat/line count */
|
||||
uint32_t _flags; /* modifier flags */
|
||||
} _s; /* for use with string types */
|
||||
} _u;
|
||||
#define num_mask _u._mask
|
||||
#define str_range _u._s._count
|
||||
#define str_flags _u._s._flags
|
||||
/* Words 9-16 */
|
||||
union VALUETYPE value; /* either number of string */
|
||||
/* Words 17..31 */
|
||||
char desc[MAXDESC]; /* description */
|
||||
/* Words 32..47 */
|
||||
char mimetype[MAXDESC]; /* MIME type */
|
||||
};
|
||||
|
||||
#define BIT(A) (1 << (A))
|
||||
#define STRING_COMPACT_BLANK BIT(0)
|
||||
#define STRING_COMPACT_OPTIONAL_BLANK BIT(1)
|
||||
#define STRING_IGNORE_LOWERCASE BIT(2)
|
||||
#define STRING_IGNORE_UPPERCASE BIT(3)
|
||||
#define REGEX_OFFSET_START BIT(4)
|
||||
#define CHAR_COMPACT_BLANK 'B'
|
||||
#define CHAR_COMPACT_OPTIONAL_BLANK 'b'
|
||||
#define CHAR_IGNORE_LOWERCASE 'c'
|
||||
#define CHAR_IGNORE_UPPERCASE 'C'
|
||||
#define CHAR_REGEX_OFFSET_START 's'
|
||||
#define STRING_IGNORE_CASE (STRING_IGNORE_LOWERCASE|STRING_IGNORE_UPPERCASE)
|
||||
#define STRING_DEFAULT_RANGE 100
|
||||
|
||||
|
||||
/* list of magic entries */
|
||||
struct mlist {
|
||||
struct magic *magic; /* array of magic entries */
|
||||
uint32_t nmagic; /* number of entries in array */
|
||||
int mapped; /* allocation type: 0 => apprentice_file
|
||||
* 1 => apprentice_map + malloc
|
||||
* 2 => apprentice_map + mmap */
|
||||
struct mlist *next, *prev;
|
||||
};
|
||||
|
||||
struct level_info {
|
||||
int32_t off;
|
||||
int got_match;
|
||||
#ifdef ENABLE_CONDITIONALS
|
||||
int last_match;
|
||||
int last_cond; /* used for error checking by parse() */
|
||||
#endif
|
||||
} *li;
|
||||
|
||||
struct magic_set {
|
||||
struct mlist *mlist;
|
||||
struct cont {
|
||||
size_t len;
|
||||
struct level_info *li;
|
||||
} c;
|
||||
struct out {
|
||||
char *buf; /* Accumulation buffer */
|
||||
char *pbuf; /* Printable buffer */
|
||||
} o;
|
||||
uint32_t offset;
|
||||
int error;
|
||||
int flags;
|
||||
int haderr;
|
||||
const char *file;
|
||||
size_t line; /* current magic line number */
|
||||
|
||||
/* data for searches */
|
||||
struct {
|
||||
const char *s; /* start of search in original source */
|
||||
size_t s_len; /* length of search region */
|
||||
size_t offset; /* starting offset in source: XXX - should this be off_t? */
|
||||
size_t rm_len; /* match length */
|
||||
} search;
|
||||
|
||||
/* FIXME: Make the string dynamically allocated so that e.g.
|
||||
strings matched in files can be longer than MAXstring */
|
||||
union VALUETYPE ms_value; /* either number or string */
|
||||
};
|
||||
|
||||
/* Type for Unicode characters */
|
||||
typedef unsigned long unichar;
|
||||
|
||||
struct stat;
|
||||
protected const char *file_fmttime(uint32_t, int);
|
||||
protected int file_buffer(struct magic_set *, php_stream *, const char *, const void *,
|
||||
size_t);
|
||||
protected int file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb, php_stream *stream);
|
||||
protected int file_pipe2file(struct magic_set *, int, const void *, size_t);
|
||||
protected int file_printf(struct magic_set *, const char *, ...);
|
||||
protected int file_reset(struct magic_set *);
|
||||
protected int file_tryelf(struct magic_set *, int, const unsigned char *,
|
||||
size_t);
|
||||
#ifdef PHP_FILEINFO_UNCOMPRESS
|
||||
protected int file_zmagic(struct magic_set *, int, const char *,
|
||||
const unsigned char *, size_t);
|
||||
#endif
|
||||
protected int file_ascmagic(struct magic_set *, const unsigned char *, size_t);
|
||||
protected int file_is_tar(struct magic_set *, const unsigned char *, size_t);
|
||||
protected int file_softmagic(struct magic_set *, const unsigned char *, size_t, int);
|
||||
protected struct mlist *file_apprentice(struct magic_set *, const char *, int);
|
||||
protected uint64_t file_signextend(struct magic_set *, struct magic *,
|
||||
uint64_t);
|
||||
protected void file_delmagic(struct magic *, int type, size_t entries);
|
||||
protected void file_badread(struct magic_set *);
|
||||
protected void file_badseek(struct magic_set *);
|
||||
protected void file_oomem(struct magic_set *, size_t);
|
||||
protected void file_error(struct magic_set *, int, const char *, ...);
|
||||
protected void file_magerror(struct magic_set *, const char *, ...);
|
||||
protected void file_magwarn(struct magic_set *, const char *, ...);
|
||||
protected void file_showstr(FILE *, const char *, size_t);
|
||||
protected size_t file_mbswidth(const char *);
|
||||
protected const char *file_getbuffer(struct magic_set *);
|
||||
protected ssize_t sread(int, void *, size_t, int);
|
||||
protected int file_check_mem(struct magic_set *, unsigned int);
|
||||
protected int file_looks_utf8(const unsigned char *, size_t, unichar *, size_t *);
|
||||
|
||||
extern const char *file_names[];
|
||||
extern const size_t file_nnames;
|
||||
|
||||
#ifndef HAVE_STRERROR
|
||||
extern int sys_nerr;
|
||||
extern char *sys_errlist[];
|
||||
#define strerror(e) \
|
||||
(((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOUL
|
||||
#define strtoul(a, b, c) strtol(a, b, c)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_MMAP) && defined(HAVE_SYS_MMAN_H) && !defined(QUICK)
|
||||
#define QUICK
|
||||
#endif
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __GNUC__
|
||||
static const char *rcsid(const char *) __attribute__((__used__));
|
||||
#endif
|
||||
#define FILE_RCSID(id) \
|
||||
static const char *rcsid(const char *p) { \
|
||||
return rcsid(p = id); \
|
||||
}
|
||||
#else
|
||||
#define FILE_RCSID(id)
|
||||
#endif
|
||||
|
||||
#endif /* __file_h__ */
|
||||
@@ -1,235 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
* Software written by Ian F. Darwin and others;
|
||||
* maintained 1995-present by Christos Zoulas and others.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice immediately at the beginning of the file, without modification,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* fsmagic - magic based on filesystem info - directory, special files, etc.
|
||||
*/
|
||||
|
||||
#include "file.h"
|
||||
#include "magic.h"
|
||||
#include <string.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
/* Since major is a function on SVR4, we cannot use `ifndef major'. */
|
||||
#ifdef MAJOR_IN_MKDEV
|
||||
# include <sys/mkdev.h>
|
||||
# define HAVE_MAJOR
|
||||
#endif
|
||||
#ifdef MAJOR_IN_SYSMACROS
|
||||
# include <sys/sysmacros.h>
|
||||
# define HAVE_MAJOR
|
||||
#endif
|
||||
#ifdef major /* Might be defined in sys/types.h. */
|
||||
# define HAVE_MAJOR
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MAJOR
|
||||
# define major(dev) (((dev) >> 8) & 0xff)
|
||||
# define minor(dev) ((dev) & 0xff)
|
||||
#endif
|
||||
#undef HAVE_MAJOR
|
||||
|
||||
#ifndef lint
|
||||
FILE_RCSID("@(#)$File: fsmagic.c,v 1.50 2008/02/12 17:22:54 rrt Exp $")
|
||||
#endif /* lint */
|
||||
|
||||
#ifdef PHP_WIN32
|
||||
|
||||
# undef S_IFIFO
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(mode) ((mode) & _S_IFDIR)
|
||||
#endif
|
||||
|
||||
#ifndef S_ISREG
|
||||
#define S_ISREG(mode) ((mode) & _S_IFREG)
|
||||
#endif
|
||||
|
||||
protected int
|
||||
file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb, php_stream *stream)
|
||||
{
|
||||
int mime = ms->flags & MAGIC_MIME;
|
||||
TSRMLS_FETCH();
|
||||
|
||||
if (!fn && !stream) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (stream) {
|
||||
php_stream_statbuf ssb;
|
||||
if (php_stream_stat(stream, &ssb) < 0) {
|
||||
if (ms->flags & MAGIC_ERROR) {
|
||||
file_error(ms, errno, "cannot stat `%s'", fn);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
memcpy(sb, &ssb.sb, sizeof(struct stat));
|
||||
} else {
|
||||
if (php_sys_stat(fn, sb) != 0) {
|
||||
if (ms->flags & MAGIC_ERROR) {
|
||||
file_error(ms, errno, "cannot stat `%s'", fn);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (mime) {
|
||||
if (!S_ISREG(sb->st_mode)) {
|
||||
if ((mime & MAGIC_MIME_TYPE) &&
|
||||
file_printf(ms, "application/x-not-regular-file") == -1) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (S_ISDIR(sb->st_mode)) {
|
||||
if (file_printf(ms, "directory") == -1) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
#ifdef S_ISUID
|
||||
if (sb->st_mode & S_ISUID)
|
||||
if (file_printf(ms, "setuid ") == -1)
|
||||
return -1;
|
||||
#endif
|
||||
#ifdef S_ISGID
|
||||
if (sb->st_mode & S_ISGID)
|
||||
if (file_printf(ms, "setgid ") == -1)
|
||||
return -1;
|
||||
#endif
|
||||
#ifdef S_ISVTX
|
||||
if (sb->st_mode & S_ISVTX)
|
||||
if (file_printf(ms, "sticky ") == -1)
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
switch (sb->st_mode & S_IFMT) {
|
||||
#ifndef PHP_WIN32
|
||||
# ifdef S_IFCHR
|
||||
case S_IFCHR:
|
||||
/*
|
||||
* If -s has been specified, treat character special files
|
||||
* like ordinary files. Otherwise, just report that they
|
||||
* are block special files and go on to the next file.
|
||||
*/
|
||||
if ((ms->flags & MAGIC_DEVICES) != 0) {
|
||||
break;
|
||||
}
|
||||
# ifdef HAVE_STAT_ST_RDEV
|
||||
# ifdef dv_unit
|
||||
if (file_printf(ms, "character special (%d/%d/%d)",
|
||||
major(sb->st_rdev), dv_unit(sb->st_rdev),
|
||||
dv_subunit(sb->st_rdev)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
# else
|
||||
if (file_printf(ms, "character special (%ld/%ld)",
|
||||
(long) major(sb->st_rdev), (long) minor(sb->st_rdev)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
# endif
|
||||
# else
|
||||
if (file_printf(ms, "character special") == -1) {
|
||||
return -1;
|
||||
}
|
||||
# endif
|
||||
return 1;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef S_IFIFO
|
||||
case S_IFIFO:
|
||||
if((ms->flags & MAGIC_DEVICES) != 0)
|
||||
break;
|
||||
if (file_printf(ms, "fifo (named pipe)") == -1)
|
||||
return -1;
|
||||
return 1;
|
||||
#endif
|
||||
#ifdef S_IFDOOR
|
||||
case S_IFDOOR:
|
||||
if (file_printf(ms, "door") == -1)
|
||||
return -1;
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
#ifdef S_IFLNK
|
||||
case S_IFLNK:
|
||||
/* stat is used, if it made here then the link is broken */
|
||||
if (ms->flags & MAGIC_ERROR) {
|
||||
file_error(ms, errno, "unreadable symlink `%s'", fn);
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
#ifdef S_IFSOCK
|
||||
#ifndef __COHERENT__
|
||||
case S_IFSOCK:
|
||||
if (file_printf(ms, "socket") == -1)
|
||||
return -1;
|
||||
return 1;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
case S_IFREG:
|
||||
break;
|
||||
|
||||
default:
|
||||
file_error(ms, 0, "invalid mode 0%o", sb->st_mode);
|
||||
return -1;
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
/*
|
||||
* regular file, check next possibility
|
||||
*
|
||||
* If stat() tells us the file has zero length, report here that
|
||||
* the file is empty, so we can skip all the work of opening and
|
||||
* reading the file.
|
||||
* But if the -s option has been given, we skip this optimization,
|
||||
* since on some systems, stat() reports zero size for raw disk
|
||||
* partitions. (If the block special device really has zero length,
|
||||
* the fact that it is empty will be detected and reported correctly
|
||||
* when we read the file.)
|
||||
*/
|
||||
if ((ms->flags & MAGIC_DEVICES) == 0 && sb->st_size == 0) {
|
||||
if ((!mime || (mime & MAGIC_MIME_TYPE)) &&
|
||||
file_printf(ms, mime ? "application/x-empty" :
|
||||
"empty") == -1)
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,331 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Christos Zoulas 2003.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice immediately at the beginning of the file, without modification,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
#include "file.h"
|
||||
#include "magic.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#if defined(HAVE_WCHAR_H)
|
||||
#include <wchar.h>
|
||||
#endif
|
||||
#if defined(HAVE_WCTYPE_H)
|
||||
#include <wctype.h>
|
||||
#endif
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX ((size_t) -1)
|
||||
#endif
|
||||
|
||||
#ifndef lint
|
||||
FILE_RCSID("@(#)$File: funcs.c,v 1.39 2008/03/01 22:21:49 rrt Exp $")
|
||||
#endif /* lint */
|
||||
|
||||
/*
|
||||
* Like printf, only we append to a buffer.
|
||||
*/
|
||||
protected int
|
||||
file_printf(struct magic_set *ms, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int len;
|
||||
char *buf = NULL, *newstr;
|
||||
|
||||
va_start(ap, fmt);
|
||||
len = vspprintf(&buf, 0, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (ms->o.buf != NULL) {
|
||||
len = spprintf(&newstr, 0, "%s%s", ms->o.buf, (buf ? buf : ""));
|
||||
if (buf) {
|
||||
efree(buf);
|
||||
}
|
||||
efree(ms->o.buf);
|
||||
ms->o.buf = newstr;
|
||||
} else {
|
||||
ms->o.buf = buf;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* error - print best error message possible
|
||||
*/
|
||||
/*VARARGS*/
|
||||
private void
|
||||
file_error_core(struct magic_set *ms, int error, const char *f, va_list va,
|
||||
uint32_t lineno)
|
||||
{
|
||||
char *buf = NULL;
|
||||
|
||||
/* Only the first error is ok */
|
||||
if (ms->haderr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (lineno != 0) {
|
||||
efree(ms->o.buf);
|
||||
ms->o.buf = NULL;
|
||||
file_printf(ms, "line %u: ", lineno);
|
||||
}
|
||||
|
||||
vspprintf(&buf, 0, f, va);
|
||||
va_end(va);
|
||||
|
||||
if (error > 0) {
|
||||
file_printf(ms, "%s (%s)", (*buf ? buf : ""), strerror(error));
|
||||
} else if (*buf) {
|
||||
file_printf(ms, "%s", buf);
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
efree(buf);
|
||||
}
|
||||
|
||||
ms->haderr++;
|
||||
ms->error = error;
|
||||
}
|
||||
|
||||
/*VARARGS*/
|
||||
protected void
|
||||
file_error(struct magic_set *ms, int error, const char *f, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, f);
|
||||
file_error_core(ms, error, f, va, 0);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print an error with magic line number.
|
||||
*/
|
||||
/*VARARGS*/
|
||||
protected void
|
||||
file_magerror(struct magic_set *ms, const char *f, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, f);
|
||||
file_error_core(ms, 0, f, va, ms->line);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
protected void
|
||||
file_badseek(struct magic_set *ms)
|
||||
{
|
||||
file_error(ms, errno, "error seeking");
|
||||
}
|
||||
|
||||
protected void
|
||||
file_badread(struct magic_set *ms)
|
||||
{
|
||||
file_error(ms, errno, "error reading");
|
||||
}
|
||||
|
||||
protected int
|
||||
file_buffer(struct magic_set *ms, php_stream *stream, const char *inname, const void *buf,
|
||||
size_t nb)
|
||||
{
|
||||
int m;
|
||||
int mime = ms->flags & MAGIC_MIME;
|
||||
const unsigned char *ubuf = buf;
|
||||
|
||||
if (nb == 0) {
|
||||
if ((!mime || (mime & MAGIC_MIME_TYPE)) &&
|
||||
file_printf(ms, mime ? "application/x-empty" :
|
||||
"empty") == -1)
|
||||
return -1;
|
||||
return 1;
|
||||
} else if (nb == 1) {
|
||||
if ((!mime || (mime & MAGIC_MIME_TYPE)) &&
|
||||
file_printf(ms, mime ? "application/octet-stream" :
|
||||
"very short file (no magic)") == -1)
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if defined(__EMX__)
|
||||
if ((ms->flags & MAGIC_NO_CHECK_APPTYPE) == 0 && inname) {
|
||||
switch (file_os2_apptype(ms, inname, buf, nb)) {
|
||||
case -1:
|
||||
return -1;
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PHP_FILEINFO_UNCOMPRESS
|
||||
/* try compression stuff */
|
||||
if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) != 0 ||
|
||||
(m = file_zmagic(ms, stream, inname, ubuf, nb)) == 0)
|
||||
#endif
|
||||
{
|
||||
/* Check if we have a tar file */
|
||||
if ((ms->flags & MAGIC_NO_CHECK_TAR) != 0 || (m = file_is_tar(ms, ubuf, nb)) == 0) {
|
||||
/* try tests in /etc/magic (or surrogate magic file) */
|
||||
if ((ms->flags & MAGIC_NO_CHECK_SOFT) != 0 || (m = file_softmagic(ms, ubuf, nb, BINTEST)) == 0) {
|
||||
/* try known keywords, check whether it is ASCII */
|
||||
if ((ms->flags & MAGIC_NO_CHECK_ASCII) != 0 || (m = file_ascmagic(ms, ubuf, nb)) == 0) {
|
||||
/* abandon hope, all ye who remain here */
|
||||
if ((!mime || (mime & MAGIC_MIME_TYPE)) && file_printf(ms, mime ? "application/octet-stream" : "data") == -1) {
|
||||
return -1;
|
||||
}
|
||||
m = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BUILTIN_ELF
|
||||
if ((ms->flags & MAGIC_NO_CHECK_ELF) == 0 && m == 1 && nb > 5 && fd != -1) {
|
||||
/*
|
||||
* We matched something in the file, so this *might*
|
||||
* be an ELF file, and the file is at least 5 bytes
|
||||
* long, so if it's an ELF file it has at least one
|
||||
* byte past the ELF magic number - try extracting
|
||||
* information from the ELF headers that cannot easily
|
||||
* be extracted with rules in the magic file.
|
||||
*/
|
||||
(void)file_tryelf(ms, stream, ubuf, nb);
|
||||
}
|
||||
#endif
|
||||
return m;
|
||||
}
|
||||
|
||||
protected int
|
||||
file_reset(struct magic_set *ms)
|
||||
{
|
||||
if (ms->mlist == NULL) {
|
||||
file_error(ms, 0, "no magic files loaded");
|
||||
return -1;
|
||||
}
|
||||
if (ms->o.buf) {
|
||||
efree(ms->o.buf);
|
||||
}
|
||||
ms->o.buf = NULL;
|
||||
ms->haderr = 0;
|
||||
ms->error = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define OCTALIFY(n, o) \
|
||||
/*LINTED*/ \
|
||||
(void)(*(n)++ = '\\', \
|
||||
*(n)++ = (((uint32_t)*(o) >> 6) & 3) + '0', \
|
||||
*(n)++ = (((uint32_t)*(o) >> 3) & 7) + '0', \
|
||||
*(n)++ = (((uint32_t)*(o) >> 0) & 7) + '0', \
|
||||
(o)++)
|
||||
|
||||
protected const char *
|
||||
file_getbuffer(struct magic_set *ms)
|
||||
{
|
||||
char *pbuf, *op, *np;
|
||||
size_t psize, len;
|
||||
|
||||
if (ms->haderr)
|
||||
return NULL;
|
||||
|
||||
if (ms->flags & MAGIC_RAW)
|
||||
return ms->o.buf;
|
||||
|
||||
/* * 4 is for octal representation, + 1 is for NUL */
|
||||
len = strlen(ms->o.buf);
|
||||
if (len > (SIZE_MAX - 1) / 4) {
|
||||
return NULL;
|
||||
}
|
||||
psize = len * 4 + 1;
|
||||
pbuf = erealloc(ms->o.pbuf, psize);
|
||||
ms->o.pbuf = pbuf;
|
||||
|
||||
#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)
|
||||
{
|
||||
mbstate_t state;
|
||||
wchar_t nextchar;
|
||||
int mb_conv = 1;
|
||||
size_t bytesconsumed;
|
||||
char *eop;
|
||||
(void)memset(&state, 0, sizeof(mbstate_t));
|
||||
|
||||
np = ms->o.pbuf;
|
||||
op = ms->o.buf;
|
||||
eop = op + len;
|
||||
|
||||
while (op < eop) {
|
||||
bytesconsumed = mbrtowc(&nextchar, op,
|
||||
(size_t)(eop - op), &state);
|
||||
if (bytesconsumed == (size_t)(-1) ||
|
||||
bytesconsumed == (size_t)(-2)) {
|
||||
mb_conv = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (iswprint(nextchar)) {
|
||||
(void)memcpy(np, op, bytesconsumed);
|
||||
op += bytesconsumed;
|
||||
np += bytesconsumed;
|
||||
} else {
|
||||
while (bytesconsumed-- > 0)
|
||||
OCTALIFY(np, op);
|
||||
}
|
||||
}
|
||||
*np = '\0';
|
||||
|
||||
/* Parsing succeeded as a multi-byte sequence */
|
||||
if (mb_conv != 0)
|
||||
return ms->o.pbuf;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (np = ms->o.pbuf, op = ms->o.buf; *op; op++) {
|
||||
if (isprint((unsigned char)*op)) {
|
||||
*np++ = *op;
|
||||
} else {
|
||||
OCTALIFY(np, op);
|
||||
}
|
||||
}
|
||||
*np = '\0';
|
||||
return ms->o.pbuf;
|
||||
}
|
||||
|
||||
protected int
|
||||
file_check_mem(struct magic_set *ms, unsigned int level)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if (level >= ms->c.len) {
|
||||
len = (ms->c.len += 20) * sizeof(*ms->c.li);
|
||||
ms->c.li = (ms->c.li == NULL) ? emalloc(len) : erealloc(ms->c.li, len);
|
||||
}
|
||||
ms->c.li[level].got_match = 0;
|
||||
#ifdef ENABLE_CONDITIONALS
|
||||
ms->c.li[level].last_match = 0;
|
||||
ms->c.li[level].last_cond = COND_NONE;
|
||||
#endif /* ENABLE_CONDITIONALS */
|
||||
return 0;
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
* Software written by Ian F. Darwin and others;
|
||||
* maintained 1995-present by Christos Zoulas and others.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice immediately at the beginning of the file, without modification,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* is_tar() -- figure out whether file is a tar archive.
|
||||
*
|
||||
* Stolen (by the author!) from the public domain tar program:
|
||||
* Public Domain version written 26 Aug 1985 John Gilmore (ihnp4!hoptoad!gnu).
|
||||
*
|
||||
* @(#)list.c 1.18 9/23/86 Public Domain - gnu
|
||||
*
|
||||
* Comments changed and some code/comments reformatted
|
||||
* for file command by Ian Darwin.
|
||||
*/
|
||||
|
||||
#include "file.h"
|
||||
#include "magic.h"
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include "tar.h"
|
||||
|
||||
#ifndef lint
|
||||
FILE_RCSID("@(#)$File: is_tar.c,v 1.31 2008/02/04 20:51:17 christos Exp $")
|
||||
#endif
|
||||
|
||||
#define isodigit(c) ( ((c) >= '0') && ((c) <= '7') )
|
||||
|
||||
private int is_tar(const unsigned char *, size_t);
|
||||
private int from_oct(int, const char *); /* Decode octal number */
|
||||
|
||||
static const char tartype[][32] = {
|
||||
"tar archive",
|
||||
"POSIX tar archive",
|
||||
"POSIX tar archive (GNU)",
|
||||
};
|
||||
|
||||
protected int
|
||||
file_is_tar(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
|
||||
{
|
||||
/*
|
||||
* Do the tar test first, because if the first file in the tar
|
||||
* archive starts with a dot, we can confuse it with an nroff file.
|
||||
*/
|
||||
int tar = is_tar(buf, nbytes);
|
||||
int mime = ms->flags & MAGIC_MIME;
|
||||
|
||||
if (tar < 1 || tar > 3)
|
||||
return 0;
|
||||
|
||||
if (mime == MAGIC_MIME_ENCODING)
|
||||
return 0;
|
||||
|
||||
if (file_printf(ms, mime ? "application/x-tar" :
|
||||
tartype[tar - 1]) == -1)
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return
|
||||
* 0 if the checksum is bad (i.e., probably not a tar archive),
|
||||
* 1 for old UNIX tar file,
|
||||
* 2 for Unix Std (POSIX) tar file,
|
||||
* 3 for GNU tar file.
|
||||
*/
|
||||
private int
|
||||
is_tar(const unsigned char *buf, size_t nbytes)
|
||||
{
|
||||
const union record *header = (const union record *)(const void *)buf;
|
||||
int i;
|
||||
int sum, recsum;
|
||||
const char *p;
|
||||
|
||||
if (nbytes < sizeof(union record))
|
||||
return 0;
|
||||
|
||||
recsum = from_oct(8, header->header.chksum);
|
||||
|
||||
sum = 0;
|
||||
p = header->charptr;
|
||||
for (i = sizeof(union record); --i >= 0;) {
|
||||
/*
|
||||
* We cannot use unsigned char here because of old compilers,
|
||||
* e.g. V7.
|
||||
*/
|
||||
sum += 0xFF & *p++;
|
||||
}
|
||||
|
||||
/* Adjust checksum to count the "chksum" field as blanks. */
|
||||
for (i = sizeof(header->header.chksum); --i >= 0;)
|
||||
sum -= 0xFF & header->header.chksum[i];
|
||||
sum += ' '* sizeof header->header.chksum;
|
||||
|
||||
if (sum != recsum)
|
||||
return 0; /* Not a tar archive */
|
||||
|
||||
if (strcmp(header->header.magic, GNUTMAGIC) == 0)
|
||||
return 3; /* GNU Unix Standard tar archive */
|
||||
if (strcmp(header->header.magic, TMAGIC) == 0)
|
||||
return 2; /* Unix Standard tar archive */
|
||||
|
||||
return 1; /* Old fashioned tar archive */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Quick and dirty octal conversion.
|
||||
*
|
||||
* Result is -1 if the field is invalid (all blank, or nonoctal).
|
||||
*/
|
||||
private int
|
||||
from_oct(int digs, const char *where)
|
||||
{
|
||||
int value;
|
||||
|
||||
while (isspace((unsigned char)*where)) { /* Skip spaces */
|
||||
where++;
|
||||
if (--digs <= 0)
|
||||
return -1; /* All blank field */
|
||||
}
|
||||
value = 0;
|
||||
while (digs > 0 && isodigit(*where)) { /* Scan til nonoctal */
|
||||
value = (value << 3) | (*where++ - '0');
|
||||
--digs;
|
||||
}
|
||||
|
||||
if (digs > 0 && *where && !isspace((unsigned char)*where))
|
||||
return -1; /* Ended on non-space/nul */
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -1,385 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Christos Zoulas 2003.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice immediately at the beginning of the file, without modification,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "file.h"
|
||||
#include "magic.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef PHP_WIN32
|
||||
#include "win32/unistd.h"
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef PHP_WIN32
|
||||
# include "config.w32.h"
|
||||
#else
|
||||
# include "php_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <limits.h> /* for PIPE_BUF */
|
||||
|
||||
#if defined(HAVE_UTIMES)
|
||||
# include <sys/time.h>
|
||||
#elif defined(HAVE_UTIME)
|
||||
# if defined(HAVE_SYS_UTIME_H)
|
||||
# include <sys/utime.h>
|
||||
# elif defined(HAVE_UTIME_H)
|
||||
# include <utime.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h> /* for read() */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LOCALE_H
|
||||
#include <locale.h>
|
||||
#endif
|
||||
#ifndef PHP_WIN32
|
||||
# include <netinet/in.h> /* for byte swapping */
|
||||
#endif
|
||||
#include "patchlevel.h"
|
||||
|
||||
#ifndef lint
|
||||
FILE_RCSID("@(#)$File: magic.c,v 1.50 2008/02/19 00:58:59 rrt Exp $")
|
||||
#endif /* lint */
|
||||
|
||||
#ifndef PIPE_BUF
|
||||
/* Get the PIPE_BUF from pathconf */
|
||||
#ifdef _PC_PIPE_BUF
|
||||
#define PIPE_BUF pathconf(".", _PC_PIPE_BUF)
|
||||
#else
|
||||
#define PIPE_BUF 512
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PHP_WIN32
|
||||
# undef S_IFLNK
|
||||
# undef S_IFIFO
|
||||
#endif
|
||||
|
||||
#ifdef __EMX__
|
||||
private char *apptypeName = NULL;
|
||||
protected int file_os2_apptype(struct magic_set *ms, const char *fn,
|
||||
const void *buf, size_t nb);
|
||||
#endif /* __EMX__ */
|
||||
|
||||
private void free_mlist(struct mlist *);
|
||||
private void close_and_restore(const struct magic_set *, const char *, int,
|
||||
const struct stat *);
|
||||
private int unreadable_info(struct magic_set *, mode_t, const char *);
|
||||
private const char *file_or_stream(struct magic_set *, const char *, php_stream *);
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
public struct magic_set *
|
||||
magic_open(int flags)
|
||||
{
|
||||
struct magic_set *ms;
|
||||
|
||||
ms = ecalloc((size_t)1, sizeof(struct magic_set));
|
||||
|
||||
if (magic_setflags(ms, flags) == -1) {
|
||||
errno = EINVAL;
|
||||
goto free;
|
||||
}
|
||||
|
||||
ms->o.buf = ms->o.pbuf = NULL;
|
||||
|
||||
ms->c.li = emalloc((ms->c.len = 10) * sizeof(*ms->c.li));
|
||||
|
||||
ms->haderr = 0;
|
||||
ms->error = -1;
|
||||
ms->mlist = NULL;
|
||||
ms->file = "unknown";
|
||||
ms->line = 0;
|
||||
return ms;
|
||||
free:
|
||||
efree(ms);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
private void
|
||||
free_mlist(struct mlist *mlist)
|
||||
{
|
||||
struct mlist *ml;
|
||||
|
||||
if (mlist == NULL)
|
||||
return;
|
||||
|
||||
for (ml = mlist->next; ml != mlist;) {
|
||||
struct mlist *next = ml->next;
|
||||
struct magic *mg = ml->magic;
|
||||
file_delmagic(mg, ml->mapped, ml->nmagic);
|
||||
efree(ml);
|
||||
ml = next;
|
||||
}
|
||||
efree(ml);
|
||||
}
|
||||
|
||||
private int
|
||||
unreadable_info(struct magic_set *ms, mode_t md, const char *file)
|
||||
{
|
||||
/* We cannot open it, but we were able to stat it. */
|
||||
if (access(file, W_OK) == 0)
|
||||
if (file_printf(ms, "writable, ") == -1)
|
||||
return -1;
|
||||
if (access(file, X_OK) == 0)
|
||||
if (file_printf(ms, "executable, ") == -1)
|
||||
return -1;
|
||||
if (S_ISREG(md))
|
||||
if (file_printf(ms, "regular file, ") == -1)
|
||||
return -1;
|
||||
if (file_printf(ms, "no read permission") == -1)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void
|
||||
magic_close(struct magic_set *ms)
|
||||
{
|
||||
if (ms->mlist) {
|
||||
free_mlist(ms->mlist);
|
||||
}
|
||||
if (ms->o.pbuf) {
|
||||
efree(ms->o.pbuf);
|
||||
}
|
||||
if (ms->o.buf) {
|
||||
efree(ms->o.buf);
|
||||
}
|
||||
if (ms->c.li) {
|
||||
efree(ms->c.li);
|
||||
}
|
||||
efree(ms);
|
||||
}
|
||||
|
||||
/*
|
||||
* load a magic file
|
||||
*/
|
||||
public int
|
||||
magic_load(struct magic_set *ms, const char *magicfile)
|
||||
{
|
||||
struct mlist *ml = file_apprentice(ms, magicfile, FILE_LOAD);
|
||||
if (ml) {
|
||||
free_mlist(ms->mlist);
|
||||
ms->mlist = ml;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int
|
||||
magic_compile(struct magic_set *ms, const char *magicfile)
|
||||
{
|
||||
struct mlist *ml = file_apprentice(ms, magicfile, FILE_COMPILE);
|
||||
free_mlist(ml);
|
||||
return ml ? 0 : -1;
|
||||
}
|
||||
|
||||
private void
|
||||
close_and_restore(const struct magic_set *ms, const char *name, int fd,
|
||||
const struct stat *sb)
|
||||
{
|
||||
if ((ms->flags & MAGIC_PRESERVE_ATIME) != 0) {
|
||||
/*
|
||||
* Try to restore access, modification times if read it.
|
||||
* This is really *bad* because it will modify the status
|
||||
* time of the file... And of course this will affect
|
||||
* backup programs
|
||||
*/
|
||||
#ifdef HAVE_UTIMES
|
||||
struct timeval utsbuf[2];
|
||||
(void)memset(utsbuf, 0, sizeof(utsbuf));
|
||||
utsbuf[0].tv_sec = sb->st_atime;
|
||||
utsbuf[1].tv_sec = sb->st_mtime;
|
||||
|
||||
(void) utimes(name, utsbuf); /* don't care if loses */
|
||||
#elif defined(HAVE_UTIME_H) || defined(HAVE_SYS_UTIME_H)
|
||||
struct utimbuf utbuf;
|
||||
|
||||
(void)memset(utbuf, 0, sizeof(utbuf));
|
||||
utbuf.actime = sb->st_atime;
|
||||
utbuf.modtime = sb->st_mtime;
|
||||
(void) utime(name, &utbuf); /* don't care if loses */
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* find type of descriptor
|
||||
*/
|
||||
public const char *
|
||||
magic_descriptor(struct magic_set *ms, int fd)
|
||||
{
|
||||
return file_or_stream(ms, NULL, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* find type of named file
|
||||
*/
|
||||
public const char *
|
||||
magic_file(struct magic_set *ms, const char *inname)
|
||||
{
|
||||
return file_or_stream(ms, inname, NULL);
|
||||
}
|
||||
|
||||
public const char *
|
||||
magic_stream(struct magic_set *ms, php_stream *stream)
|
||||
{
|
||||
return file_or_stream(ms, NULL, stream);
|
||||
}
|
||||
|
||||
private const char *
|
||||
file_or_stream(struct magic_set *ms, const char *inname, php_stream *stream)
|
||||
{
|
||||
int rv = -1;
|
||||
unsigned char *buf;
|
||||
struct stat sb;
|
||||
ssize_t nbytes = 0; /* number of bytes read from a datafile */
|
||||
int no_in_stream = 0;
|
||||
TSRMLS_FETCH();
|
||||
|
||||
if (!inname && !stream) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* one extra for terminating '\0', and
|
||||
* some overlapping space for matches near EOF
|
||||
*/
|
||||
#define SLOP (1 + sizeof(union VALUETYPE))
|
||||
buf = emalloc(HOWMANY + SLOP);
|
||||
|
||||
if (file_reset(ms) == -1) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
switch (file_fsmagic(ms, inname, &sb, stream)) {
|
||||
case -1: /* error */
|
||||
goto done;
|
||||
case 0: /* nothing found */
|
||||
break;
|
||||
default: /* matched it and printed type */
|
||||
rv = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
|
||||
if (!stream && inname) {
|
||||
no_in_stream = 1;
|
||||
#if (PHP_MAJOR_VERSION < 6)
|
||||
stream = php_stream_open_wrapper(inname, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL);
|
||||
#else
|
||||
stream = php_stream_open_wrapper(inname, "rb", REPORT_ERRORS, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!stream) {
|
||||
if (unreadable_info(ms, sb.st_mode,
|
||||
#ifdef __CYGWIN
|
||||
tmp
|
||||
#else
|
||||
inname
|
||||
#endif
|
||||
) == -1)
|
||||
goto done;
|
||||
rv = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
#ifdef O_NONBLOCK
|
||||
/* we should be already be in non blocking mode for network socket */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* try looking at the first HOWMANY bytes
|
||||
*/
|
||||
if ((nbytes = php_stream_read(stream, (char *)buf, HOWMANY)) < 0) {
|
||||
file_error(ms, errno, "cannot read `%s'", inname);
|
||||
goto done;
|
||||
}
|
||||
|
||||
(void)memset(buf + nbytes, 0, SLOP); /* NUL terminate */
|
||||
if (file_buffer(ms, stream, inname, buf, (size_t)nbytes) == -1)
|
||||
goto done;
|
||||
rv = 0;
|
||||
done:
|
||||
efree(buf);
|
||||
|
||||
if (no_in_stream && stream) {
|
||||
php_stream_close(stream);
|
||||
}
|
||||
|
||||
close_and_restore(ms, inname, 0, &sb);
|
||||
return rv == 0 ? file_getbuffer(ms) : NULL;
|
||||
}
|
||||
|
||||
public const char *
|
||||
magic_buffer(struct magic_set *ms, const void *buf, size_t nb)
|
||||
{
|
||||
if (file_reset(ms) == -1)
|
||||
return NULL;
|
||||
/*
|
||||
* The main work is done here!
|
||||
* We have the file name and/or the data buffer to be identified.
|
||||
*/
|
||||
if (file_buffer(ms, NULL, NULL, buf, nb) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
return file_getbuffer(ms);
|
||||
}
|
||||
|
||||
public const char *
|
||||
magic_error(struct magic_set *ms)
|
||||
{
|
||||
return ms->haderr ? ms->o.buf : NULL;
|
||||
}
|
||||
|
||||
public int
|
||||
magic_errno(struct magic_set *ms)
|
||||
{
|
||||
return ms->haderr ? ms->error : 0;
|
||||
}
|
||||
|
||||
public int
|
||||
magic_setflags(struct magic_set *ms, int flags)
|
||||
{
|
||||
#if !defined(HAVE_UTIME) && !defined(HAVE_UTIMES)
|
||||
if (flags & MAGIC_PRESERVE_ATIME)
|
||||
return -1;
|
||||
#endif
|
||||
ms->flags = flags;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Christos Zoulas 2003.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice immediately at the beginning of the file, without modification,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _MAGIC_H
|
||||
#define _MAGIC_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define MAGIC_NONE 0x000000 /* No flags */
|
||||
#define MAGIC_DEBUG 0x000001 /* Turn on debugging */
|
||||
#define MAGIC_SYMLINK 0x000002 /* Follow symlinks */
|
||||
#define MAGIC_COMPRESS 0x000004 /* Check inside compressed files */
|
||||
#define MAGIC_DEVICES 0x000008 /* Look at the contents of devices */
|
||||
#define MAGIC_MIME_TYPE 0x000010 /* Return only the MIME type */
|
||||
#define MAGIC_CONTINUE 0x000020 /* Return all matches */
|
||||
#define MAGIC_CHECK 0x000040 /* Print warnings to stderr */
|
||||
#define MAGIC_PRESERVE_ATIME 0x000080 /* Restore access time on exit */
|
||||
#define MAGIC_RAW 0x000100 /* Don't translate unprint chars */
|
||||
#define MAGIC_ERROR 0x000200 /* Handle ENOENT etc as real errors */
|
||||
#define MAGIC_MIME_ENCODING 0x000400 /* Return only the MIME encoding */
|
||||
#define MAGIC_MIME (MAGIC_MIME_TYPE|MAGIC_MIME_ENCODING)
|
||||
#define MAGIC_NO_CHECK_COMPRESS 0x001000 /* Don't check for compressed files */
|
||||
#define MAGIC_NO_CHECK_TAR 0x002000 /* Don't check for tar files */
|
||||
#define MAGIC_NO_CHECK_SOFT 0x004000 /* Don't check magic entries */
|
||||
#define MAGIC_NO_CHECK_APPTYPE 0x008000 /* Don't check application type */
|
||||
#define MAGIC_NO_CHECK_ELF 0x010000 /* Don't check for elf details */
|
||||
#define MAGIC_NO_CHECK_ASCII 0x020000 /* Don't check for ascii files */
|
||||
#define MAGIC_NO_CHECK_TOKENS 0x100000 /* Don't check ascii/tokens */
|
||||
|
||||
/* Defined for backwards compatibility; do nothing */
|
||||
#define MAGIC_NO_CHECK_FORTRAN 0x000000 /* Don't check ascii/fortran */
|
||||
#define MAGIC_NO_CHECK_TROFF 0x000000 /* Don't check ascii/troff */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct magic_set *magic_t;
|
||||
magic_t magic_open(int);
|
||||
void magic_close(magic_t);
|
||||
|
||||
const char *magic_file(magic_t, const char *);
|
||||
const char *magic_stream(magic_t, php_stream *);
|
||||
const char *magic_descriptor(magic_t, int);
|
||||
const char *magic_buffer(magic_t, const void *, size_t);
|
||||
|
||||
const char *magic_error(magic_t);
|
||||
int magic_setflags(magic_t, int);
|
||||
|
||||
int magic_load(magic_t, const char *);
|
||||
int magic_compile(magic_t, const char *);
|
||||
int magic_errno(magic_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* _MAGIC_H */
|
||||
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
* Software written by Ian F. Darwin and others;
|
||||
* maintained 1995-present by Christos Zoulas and others.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice immediately at the beginning of the file, without modification,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Names.h - names and types used by ascmagic in file(1).
|
||||
* These tokens are here because they can appear anywhere in
|
||||
* the first HOWMANY bytes, while tokens in MAGIC must
|
||||
* appear at fixed offsets into the file. Don't make HOWMANY
|
||||
* too high unless you have a very fast CPU.
|
||||
*
|
||||
* $File: names.h,v 1.32 2008/02/11 00:19:29 rrt Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
modified by Chris Lowth - 9 April 2000
|
||||
to add mime type strings to the types table.
|
||||
*/
|
||||
|
||||
/* these types are used to index the table 'types': keep em in sync! */
|
||||
#define L_C 0 /* first and foremost on UNIX */
|
||||
#define L_CC 1 /* Bjarne's postincrement */
|
||||
#define L_MAKE 2 /* Makefiles */
|
||||
#define L_PLI 3 /* PL/1 */
|
||||
#define L_MACH 4 /* some kinda assembler */
|
||||
#define L_ENG 5 /* English */
|
||||
#define L_PAS 6 /* Pascal */
|
||||
#define L_MAIL 7 /* Electronic mail */
|
||||
#define L_NEWS 8 /* Usenet Netnews */
|
||||
#define L_JAVA 9 /* Java code */
|
||||
#define L_HTML 10 /* HTML */
|
||||
#define L_BCPL 11 /* BCPL */
|
||||
#define L_M4 12 /* M4 */
|
||||
#define L_PO 13 /* PO */
|
||||
|
||||
static const struct {
|
||||
char human[48];
|
||||
char mime[16];
|
||||
} types[] = {
|
||||
{ "C program", "text/x-c", },
|
||||
{ "C++ program", "text/x-c++" },
|
||||
{ "make commands", "text/x-makefile" },
|
||||
{ "PL/1 program", "text/x-pl1" },
|
||||
{ "assembler program", "text/x-asm" },
|
||||
{ "English", "text/plain" },
|
||||
{ "Pascal program", "text/x-pascal" },
|
||||
{ "mail", "text/x-mail" },
|
||||
{ "news", "text/x-news" },
|
||||
{ "Java program", "text/x-java" },
|
||||
{ "HTML document", "text/html", },
|
||||
{ "BCPL program", "text/x-bcpl" },
|
||||
{ "M4 macro language pre-processor", "text/x-m4" },
|
||||
{ "PO (gettext message catalogue)", "text/x-po" },
|
||||
{ "cannot happen error on names.h/types", "error/x-error" }
|
||||
};
|
||||
|
||||
/*
|
||||
* XXX - how should we distinguish Java from C++?
|
||||
* The trick used in a Debian snapshot, of having "extends" or "implements"
|
||||
* as tags for Java, doesn't work very well, given that those keywords
|
||||
* are often preceded by "class", which flags it as C++.
|
||||
*
|
||||
* Perhaps we need to be able to say
|
||||
*
|
||||
* If "class" then
|
||||
*
|
||||
* if "extends" or "implements" then
|
||||
* Java
|
||||
* else
|
||||
* C++
|
||||
* endif
|
||||
*
|
||||
* Or should we use other keywords, such as "package" or "import"?
|
||||
* Unfortunately, Ada95 uses "package", and Modula-3 uses "import",
|
||||
* although I infer from the language spec at
|
||||
*
|
||||
* http://www.research.digital.com/SRC/m3defn/html/m3.html
|
||||
*
|
||||
* that Modula-3 uses "IMPORT" rather than "import", i.e. it must be
|
||||
* in all caps.
|
||||
*
|
||||
* So, for now, we go with "import". We must put it before the C++
|
||||
* stuff, so that we don't misidentify Java as C++. Not using "package"
|
||||
* means we won't identify stuff that defines a package but imports
|
||||
* nothing; hopefully, very little Java code imports nothing (one of the
|
||||
* reasons for doing OO programming is to import as much as possible
|
||||
* and write only what you need to, right?).
|
||||
*
|
||||
* Unfortunately, "import" may cause us to misidentify English text
|
||||
* as Java, as it comes after "the" and "The". Perhaps we need a fancier
|
||||
* heuristic to identify Java?
|
||||
*/
|
||||
static const struct names {
|
||||
char name[14];
|
||||
short type;
|
||||
} names[] = {
|
||||
/* These must be sorted by eye for optimal hit rate */
|
||||
/* Add to this list only after substantial meditation */
|
||||
{"msgid", L_PO},
|
||||
{"dnl", L_M4},
|
||||
{"import", L_JAVA},
|
||||
{"\"libhdr\"", L_BCPL},
|
||||
{"\"LIBHDR\"", L_BCPL},
|
||||
{"//", L_CC},
|
||||
{"template", L_CC},
|
||||
{"virtual", L_CC},
|
||||
{"class", L_CC},
|
||||
{"public:", L_CC},
|
||||
{"private:", L_CC},
|
||||
{"/*", L_C}, /* must precede "The", "the", etc. */
|
||||
{"#include", L_C},
|
||||
{"char", L_C},
|
||||
{"The", L_ENG},
|
||||
{"the", L_ENG},
|
||||
{"double", L_C},
|
||||
{"extern", L_C},
|
||||
{"float", L_C},
|
||||
{"struct", L_C},
|
||||
{"union", L_C},
|
||||
{"CFLAGS", L_MAKE},
|
||||
{"LDFLAGS", L_MAKE},
|
||||
{"all:", L_MAKE},
|
||||
{".PRECIOUS", L_MAKE},
|
||||
{".ascii", L_MACH},
|
||||
{".asciiz", L_MACH},
|
||||
{".byte", L_MACH},
|
||||
{".even", L_MACH},
|
||||
{".globl", L_MACH},
|
||||
{".text", L_MACH},
|
||||
{"clr", L_MACH},
|
||||
{"(input,", L_PAS},
|
||||
{"program", L_PAS},
|
||||
{"record", L_PAS},
|
||||
{"dcl", L_PLI},
|
||||
{"Received:", L_MAIL},
|
||||
{">From", L_MAIL},
|
||||
{"Return-Path:",L_MAIL},
|
||||
{"Cc:", L_MAIL},
|
||||
{"Newsgroups:", L_NEWS},
|
||||
{"Path:", L_NEWS},
|
||||
{"Organization:",L_NEWS},
|
||||
{"href=", L_HTML},
|
||||
{"HREF=", L_HTML},
|
||||
{"<body", L_HTML},
|
||||
{"<BODY", L_HTML},
|
||||
{"<html", L_HTML},
|
||||
{"<HTML", L_HTML},
|
||||
{"<!--", L_HTML},
|
||||
};
|
||||
#define NNAMES (sizeof(names)/sizeof(struct names))
|
||||
@@ -1,343 +0,0 @@
|
||||
#define FILE_VERSION_MAJOR 4
|
||||
#define patchlevel 25
|
||||
|
||||
/*
|
||||
* Patchlevel file for Ian Darwin's MAGIC command.
|
||||
* $File: patchlevel.h,v 1.68 2008/03/22 21:39:43 christos Exp $
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.1 2008/07/11 14:13:50 derick
|
||||
* - Move lib to libmagic
|
||||
*
|
||||
* Revision 1.1 2008/07/11 14:10:50 derick
|
||||
* - Step one for bundling the libmagic library. Some config.m4 issues left.
|
||||
*
|
||||
* Revision 1.69 2008/07/02 15:27:05 christos
|
||||
* welcome to 4.25
|
||||
*
|
||||
* Revision 1.68 2008/03/22 21:39:43 christos
|
||||
* file 4.24
|
||||
*
|
||||
* Revision 1.67 2007/12/28 20:08:40 christos
|
||||
* welcome to 4.23.
|
||||
*
|
||||
* Revision 1.66 2007/12/27 16:38:24 christos
|
||||
* welcome to 4.22
|
||||
*
|
||||
* Revision 1.65 2007/05/24 17:22:27 christos
|
||||
* Welcome to 4.21
|
||||
*
|
||||
* Revision 1.64 2007/03/01 22:14:55 christos
|
||||
* welcome to 4.20
|
||||
*
|
||||
* Revision 1.63 2007/01/12 17:38:28 christos
|
||||
* Use File id.
|
||||
*
|
||||
* Revision 1.62 2006/12/11 21:49:58 christos
|
||||
* time for 4.19
|
||||
*
|
||||
* Revision 1.61 2006/10/31 21:18:09 christos
|
||||
* bump
|
||||
*
|
||||
* Revision 1.60 2006/03/02 22:15:12 christos
|
||||
* welcome to 4.17
|
||||
*
|
||||
* Revision 1.59 2005/10/17 17:15:21 christos
|
||||
* welcome to 4.16
|
||||
*
|
||||
* Revision 1.58 2005/08/18 15:52:56 christos
|
||||
* welcome to 4.15
|
||||
*
|
||||
* Revision 1.57 2005/06/25 15:52:14 christos
|
||||
* Welcome to 4.14
|
||||
*
|
||||
* Revision 1.56 2005/02/09 19:25:13 christos
|
||||
* Welcome to 4.13
|
||||
*
|
||||
* Revision 1.55 2004/11/24 18:57:47 christos
|
||||
* Re-do the autoconf stuff once more; passes make dist now.
|
||||
*
|
||||
* Revision 1.54 2004/11/21 05:52:05 christos
|
||||
* ready for 4.11
|
||||
*
|
||||
* Revision 1.53 2004/07/24 20:40:46 christos
|
||||
* welcome to 4.10
|
||||
*
|
||||
* Revision 1.52 2004/04/07 00:32:25 christos
|
||||
* welcome to 4.09
|
||||
*
|
||||
* Revision 1.51 2004/03/22 21:17:11 christos
|
||||
* welcome to 4.08.
|
||||
*
|
||||
* Revision 1.50 2003/12/23 17:34:04 christos
|
||||
* 4.07
|
||||
*
|
||||
* Revision 1.49 2003/10/15 02:08:27 christos
|
||||
* welcome to 4.06
|
||||
*
|
||||
* Revision 1.48 2003/09/12 19:41:14 christos
|
||||
* this is 4.04
|
||||
*
|
||||
* Revision 1.47 2003/05/23 21:38:21 christos
|
||||
* welcome to 4.03
|
||||
*
|
||||
* Revision 1.46 2003/04/02 18:57:43 christos
|
||||
* prepare for 4.02
|
||||
*
|
||||
* Revision 1.45 2003/03/26 15:37:25 christos
|
||||
* - Pass lint
|
||||
* - make NULL in magic_file mean stdin
|
||||
* - Fix "-" argument to file to pass NULL to magic_file
|
||||
* - avoid pointer casts by using memcpy
|
||||
* - rename magic_buf -> magic_buffer
|
||||
* - keep only the first error
|
||||
* - manual page: new sentence, new line
|
||||
* - fix typo in api function (magic_buf -> magic_buffer)
|
||||
*
|
||||
* Revision 1.44 2003/03/23 22:23:31 christos
|
||||
* finish librarification.
|
||||
*
|
||||
* Revision 1.43 2003/03/23 21:16:26 christos
|
||||
* update copyrights.
|
||||
*
|
||||
* Revision 1.42 2003/03/23 04:06:05 christos
|
||||
* Library re-organization
|
||||
*
|
||||
* Revision 1.41 2003/02/27 20:53:45 christos
|
||||
* - fix memory allocation problem (Jeff Johnson)
|
||||
* - fix stack overflow corruption (David Endler)
|
||||
* - fixes from NetBSD source (Antti Kantee)
|
||||
* - magic fixes
|
||||
*
|
||||
* Revision 1.40 2003/02/08 18:33:53 christos
|
||||
* - detect inttypes.h too (Dave Love <d.love@dl.ac.uk>)
|
||||
* - eliminate unsigned char warnings (Petter Reinholdtsen <pere@hungry.com>)
|
||||
* - better elf PT_NOTE handling (Nalin Dahyabhai <nalin@redhat.com>)
|
||||
* - add options to format the output differently
|
||||
* - much more magic.
|
||||
*
|
||||
* Revision 1.39 2002/07/03 18:57:52 christos
|
||||
* - ansify/c99ize
|
||||
* - more magic
|
||||
* - better COMPILE_ONLY support.
|
||||
* - new magic files.
|
||||
* - fix solaris compilation problems.
|
||||
*
|
||||
* Revision 1.38 2002/05/16 18:45:56 christos
|
||||
* - pt_note elf additions from NetBSD
|
||||
* - EMX os specific changes (Alexander Mai)
|
||||
* - stdint.h detection, acconfig.h fixes (Maciej W. Rozycki, Franz Korntner)
|
||||
* - regex file additions (Kim Cromie)
|
||||
* - getopt_long support and misc cleanups (Michael Piefel)
|
||||
* - many magic fixes and additions
|
||||
*
|
||||
* Revision 1.37 2001/09/03 14:44:22 christos
|
||||
* daylight/tm_isdst detection
|
||||
* magic fixes
|
||||
* don't eat the whole file if it has only nulls
|
||||
*
|
||||
* Revision 1.36 2001/07/22 21:04:15 christos
|
||||
* - magic fixes
|
||||
* - add new operators, pascal strings, UTC date printing, $HOME/.magic
|
||||
* [from "Tom N Harris" <telliamed@mac.com>]
|
||||
*
|
||||
* Revision 1.35 2001/04/24 14:40:25 christos
|
||||
* - rename magic file sgi to mips and fix it
|
||||
* - add support for building magic.mgc
|
||||
* - portability fixes for mmap()
|
||||
* - try gzip before uncompress, because uncompress sometimes hangs
|
||||
* - be more conservative about pipe reads and writes
|
||||
* - many magic fixes
|
||||
*
|
||||
* Revision 1.34 2001/03/12 05:05:57 christos
|
||||
* - new compiled magic format
|
||||
* - lots of magic additions
|
||||
*
|
||||
* Revision 1.33 2000/11/13 00:30:50 christos
|
||||
* - wordperfect magic fix: freebsd pr 9388
|
||||
* - more msdos fixes from freebsd pr's 20131 and 20812
|
||||
* - sas and spss magic [Bruce Foster]
|
||||
* - mkinstalldirs [John Fremlin]
|
||||
* - sgi opengl fixes [Michael Pruett]
|
||||
* - netbsd magic fixes [Ignatios Souvatzis]
|
||||
* - audio additions [Michael Pruett]
|
||||
* - fix problem with non ansi RCSID [Andreas Ley]
|
||||
* - oggs magic [Felix von Leitner]
|
||||
* - gmon magic [Eugen Dedu]
|
||||
* - TNEF magic [Joomy]
|
||||
* - netpbm magic and misc other image stuff [Bryan Henderson]
|
||||
*
|
||||
* Revision 1.32 2000/08/05 18:24:18 christos
|
||||
* Correct indianness detection in elf (Charles Hannum)
|
||||
* FreeBSD elf core support (Guy Harris)
|
||||
* Use gzip in systems that don't have uncompress (Anthon van der Neut)
|
||||
* Internationalization/EBCDIC support (Eric Fisher)
|
||||
* Many many magic changes
|
||||
*
|
||||
* Revision 1.31 2000/05/14 17:58:36 christos
|
||||
* - new magic for claris files
|
||||
* - new magic for mathematica and maple files
|
||||
* - new magic for msvc files
|
||||
* - new -k flag to keep going matching all possible entries
|
||||
* - add the word executable on #! magic files, and fix the usage of
|
||||
* the word script
|
||||
* - lots of other magic fixes
|
||||
* - fix typo test -> text
|
||||
*
|
||||
* Revision 1.30 2000/04/11 02:41:17 christos
|
||||
* - add support for mime output (-i)
|
||||
* - make sure we free memory in case realloc fails
|
||||
* - magic fixes
|
||||
*
|
||||
* Revision 1.29 1999/11/28 20:02:29 christos
|
||||
* new string/[Bcb] magic from anthon, and adjustments to the magic files to
|
||||
* use it.
|
||||
*
|
||||
* Revision 1.28 1999/10/31 22:11:48 christos
|
||||
* - add "char" type for compatibility with HP/UX
|
||||
* - recognize HP/UX syntax &=n etc.
|
||||
* - include errno.h for CYGWIN
|
||||
* - conditionalize the S_IS* macros
|
||||
* - revert the SHT_DYNSYM test that broke the linux stripped binaries test
|
||||
* - lots of Magdir changes
|
||||
*
|
||||
* Revision 1.27 1999/02/14 17:21:41 christos
|
||||
* Automake support and misc cleanups from Rainer Orth
|
||||
* Enable reading character and block special files from Dale R. Worley
|
||||
*
|
||||
* Revision 1.26 1998/09/12 13:19:39 christos
|
||||
* - add support for bi-endian indirect offsets (Richard Verhoeven)
|
||||
* - add recognition for bcpl (Joseph Myers)
|
||||
* - remove non magic files from Magdir to avoid difficulties building
|
||||
* on os2 where files are case independent
|
||||
* - magic fixes.
|
||||
*
|
||||
* Revision 1.25 1998/06/27 14:04:04 christos
|
||||
* OLF patch Guy Harris
|
||||
* Recognize java/html (debian linux)
|
||||
* Const poisoning (debian linux)
|
||||
* More magic!
|
||||
*
|
||||
* Revision 1.24 1998/02/15 23:20:38 christos
|
||||
* Autoconf patch: Felix von Leitner <leitner@math.fu-berlin.de>
|
||||
* More magic fixes
|
||||
* Elf64 fixes
|
||||
*
|
||||
* Revision 1.23 1997/11/05 16:03:37 christos
|
||||
* - correct elf prps offset for SunOS-2.5.1 [guy@netapp.com]
|
||||
* - handle 64 bit time_t's correctly [ewt@redhat.com]
|
||||
* - new mime style magic [clarosse@netvista.net]
|
||||
* - new TI calculator magic [rmcguire@freenet.columbus.oh.us]
|
||||
* - new figlet fonts [obrien@freebsd.org]
|
||||
* - new cisco magic, and elf fixes [jhawk@bbnplanet.com]
|
||||
* - -b flag addition, and x86 filesystem magic [vax@linkhead.paranoia.com]
|
||||
* - s/Mpeg/MPEG, header and elf typo fixes [guy@netapp.com]
|
||||
* - Windows/NT registry files, audio code [guy@netapp.com]
|
||||
* - libGrx graphics lib fonts [guy@netapp.com]
|
||||
* - PNG fixes [guy@netapp.com]
|
||||
* - more m$ document magic [guy@netapp.com]
|
||||
* - PPD files [guy@netapp.com]
|
||||
* - archive magic cleanup [guy@netapp.com]
|
||||
* - linux kernel magic cleanup [guy@netapp.com]
|
||||
* - lecter magic [guy@netapp.com]
|
||||
* - vgetty magic [guy@netapp.com]
|
||||
* - sniffer additions [guy@netapp.com]
|
||||
*
|
||||
* Revision 1.22 1997/01/15 17:23:24 christos
|
||||
* - add support for elf core files: find the program name under SVR4 [Ken Pizzini]
|
||||
* - print strings only up to the first carriage return [various]
|
||||
* - freebsd international ascii support [J Wunsch]
|
||||
* - magic fixes and additions [Guy Harris]
|
||||
* - 64 bit fixes [Larry Schwimmer]
|
||||
* - support for both utime and utimes, but don't restore file access times
|
||||
* by default [various]
|
||||
* - \xXX only takes 2 hex digits, not 3.
|
||||
* - re-implement support for core files [Guy Harris]
|
||||
*
|
||||
* Revision 1.21 1996/10/05 18:15:29 christos
|
||||
* Segregate elf stuff and conditionally enable it with -DBUILTIN_ELF
|
||||
* More magic fixes
|
||||
*
|
||||
* Revision 1.20 1996/06/22 22:15:52 christos
|
||||
* - support relative offsets of the form >&
|
||||
* - fix bug with truncating magic strings that contain \n
|
||||
* - file -f - did not read from stdin as documented
|
||||
* - support elf file parsing using our own elf support.
|
||||
* - as always magdir fixes and additions.
|
||||
*
|
||||
* Revision 1.19 1995/10/27 23:14:46 christos
|
||||
* Ability to parse colon separated list of magic files
|
||||
* New LEGAL.NOTICE
|
||||
* Various magic file changes
|
||||
*
|
||||
* Revision 1.18 1995/05/20 22:09:21 christos
|
||||
* Passed incorrect argument to eatsize().
|
||||
* Use %ld and %lx where appropriate.
|
||||
* Remove unused variables
|
||||
* ELF support for both big and little endian
|
||||
* Fixes for small files again.
|
||||
*
|
||||
* Revision 1.17 1995/04/28 17:29:13 christos
|
||||
* - Incorrect nroff detection fix from der Mouse
|
||||
* - Lost and incorrect magic entries.
|
||||
* - Added ELF stripped binary detection [in C; ugh]
|
||||
* - Look for $MAGIC to find the magic file.
|
||||
* - Eat trailing size specifications from numbers i.e. ignore 10L
|
||||
* - More fixes for very short files
|
||||
*
|
||||
* Revision 1.16 1995/03/25 22:06:45 christos
|
||||
* - use strtoul() where it exists.
|
||||
* - fix sign-extend bug
|
||||
* - try to detect tar archives before nroff files, otherwise
|
||||
* tar files where the first file starts with a . will not work
|
||||
*
|
||||
* Revision 1.15 1995/01/21 21:03:35 christos
|
||||
* Added CSECTION for the file man page
|
||||
* Added version flag -v
|
||||
* Fixed bug with -f input flag (from iorio@violet.berkeley.edu)
|
||||
* Lots of magic fixes and reorganization...
|
||||
*
|
||||
* Revision 1.14 1994/05/03 17:58:23 christos
|
||||
* changes from mycroft@gnu.ai.mit.edu (Charles Hannum) for unsigned
|
||||
*
|
||||
* Revision 1.13 1994/01/21 01:27:01 christos
|
||||
* Fixed null termination bug from Don Seeley at BSDI in ascmagic.c
|
||||
*
|
||||
* Revision 1.12 1993/10/27 20:59:05 christos
|
||||
* Changed -z flag to understand gzip format too.
|
||||
* Moved builtin compression detection to a table, and move
|
||||
* the compress magic entry out of the source.
|
||||
* Made printing of numbers unsigned, and added the mask to it.
|
||||
* Changed the buffer size to 8k, because gzip will refuse to
|
||||
* unzip just a few bytes.
|
||||
*
|
||||
* Revision 1.11 1993/09/24 18:49:06 christos
|
||||
* Fixed small bug in softmagic.c introduced by
|
||||
* copying the data to be examined out of the input
|
||||
* buffer. Changed the Makefile to use sed to create
|
||||
* the correct man pages.
|
||||
*
|
||||
* Revision 1.10 1993/09/23 21:56:23 christos
|
||||
* Passed purify. Fixed indirections. Fixed byte order printing.
|
||||
* Fixed segmentation faults caused by referencing past the end
|
||||
* of the magic buffer. Fixed bus errors caused by referencing
|
||||
* unaligned shorts or longs.
|
||||
*
|
||||
* Revision 1.9 1993/03/24 14:23:40 ian
|
||||
* Batch of minor changes from several contributors.
|
||||
*
|
||||
* Revision 1.8 93/02/19 15:01:26 ian
|
||||
* Numerous changes from Guy Harris too numerous to mention but including
|
||||
* byte-order independance, fixing "old-style masking", etc. etc. A bugfix
|
||||
* for broken symlinks from martin@@d255s004.zfe.siemens.de.
|
||||
*
|
||||
* Revision 1.7 93/01/05 14:57:27 ian
|
||||
* Couple of nits picked by Christos (again, thanks).
|
||||
*
|
||||
* Revision 1.6 93/01/05 13:51:09 ian
|
||||
* Lotsa work on the Magic directory.
|
||||
*
|
||||
* Revision 1.5 92/09/14 14:54:51 ian
|
||||
* Fix a tiny null-pointer bug in previous fix for tar archive + uncompress.
|
||||
*
|
||||
*/
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
* Software written by Ian F. Darwin and others;
|
||||
* maintained 1995-present by Christos Zoulas and others.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice immediately at the beginning of the file, without modification,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* print.c - debugging printout routines
|
||||
*/
|
||||
|
||||
#include "php.h"
|
||||
|
||||
#include "file.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
|
||||
#ifndef lint
|
||||
FILE_RCSID("@(#)$File: print.c,v 1.63 2008/02/17 19:28:54 rrt Exp $")
|
||||
#endif /* lint */
|
||||
|
||||
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
/*VARARGS*/
|
||||
protected void
|
||||
file_magwarn(struct magic_set *ms, const char *f, ...)
|
||||
{
|
||||
va_list va;
|
||||
char *expanded_format;
|
||||
TSRMLS_FETCH();
|
||||
|
||||
va_start(va, f);
|
||||
vasprintf(&expanded_format, f, va);
|
||||
va_end(va);
|
||||
|
||||
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Warning: %s", expanded_format);
|
||||
|
||||
free(expanded_format);
|
||||
}
|
||||
|
||||
protected const char *
|
||||
file_fmttime(uint32_t v, int local)
|
||||
{
|
||||
char *pp;
|
||||
time_t t = (time_t)v;
|
||||
struct tm *tm;
|
||||
|
||||
if (local) {
|
||||
pp = ctime(&t);
|
||||
} else {
|
||||
#ifndef HAVE_DAYLIGHT
|
||||
private int daylight = 0;
|
||||
#ifdef HAVE_TM_ISDST
|
||||
private time_t now = (time_t)0;
|
||||
|
||||
if (now == (time_t)0) {
|
||||
struct tm *tm1;
|
||||
(void)time(&now);
|
||||
tm1 = localtime(&now);
|
||||
if (tm1 == NULL)
|
||||
return "*Invalid time*";
|
||||
daylight = tm1->tm_isdst;
|
||||
}
|
||||
#endif /* HAVE_TM_ISDST */
|
||||
#endif /* HAVE_DAYLIGHT */
|
||||
if (daylight)
|
||||
t += 3600;
|
||||
tm = gmtime(&t);
|
||||
if (tm == NULL)
|
||||
return "*Invalid time*";
|
||||
pp = asctime(tm);
|
||||
}
|
||||
|
||||
pp[strcspn(pp, "\n")] = '\0';
|
||||
return pp;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,312 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Christos Zoulas 2003.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice immediately at the beginning of the file, without modification,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp
|
||||
*
|
||||
* Provide elf data structures for non-elf machines, allowing file
|
||||
* non-elf hosts to determine if an elf binary is stripped.
|
||||
* Note: cobbled from the linux header file, with modifications
|
||||
*/
|
||||
#ifndef __fake_elf_h__
|
||||
#define __fake_elf_h__
|
||||
|
||||
#if HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
typedef uint32_t Elf32_Addr;
|
||||
typedef uint32_t Elf32_Off;
|
||||
typedef uint16_t Elf32_Half;
|
||||
typedef uint32_t Elf32_Word;
|
||||
typedef uint8_t Elf32_Char;
|
||||
|
||||
#if SIZEOF_LONG_LONG != 8
|
||||
#define USE_ARRAY_FOR_64BIT_TYPES
|
||||
typedef uint32_t Elf64_Addr[2];
|
||||
typedef uint32_t Elf64_Off[2];
|
||||
typedef uint32_t Elf64_Xword[2];
|
||||
#else
|
||||
#undef USE_ARRAY_FOR_64BIT_TYPES
|
||||
typedef uint64_t Elf64_Addr;
|
||||
typedef uint64_t Elf64_Off;
|
||||
typedef uint64_t Elf64_Xword;
|
||||
#endif
|
||||
typedef uint16_t Elf64_Half;
|
||||
typedef uint32_t Elf64_Word;
|
||||
typedef uint8_t Elf64_Char;
|
||||
|
||||
#define EI_NIDENT 16
|
||||
|
||||
typedef struct {
|
||||
Elf32_Char e_ident[EI_NIDENT];
|
||||
Elf32_Half e_type;
|
||||
Elf32_Half e_machine;
|
||||
Elf32_Word e_version;
|
||||
Elf32_Addr e_entry; /* Entry point */
|
||||
Elf32_Off e_phoff;
|
||||
Elf32_Off e_shoff;
|
||||
Elf32_Word e_flags;
|
||||
Elf32_Half e_ehsize;
|
||||
Elf32_Half e_phentsize;
|
||||
Elf32_Half e_phnum;
|
||||
Elf32_Half e_shentsize;
|
||||
Elf32_Half e_shnum;
|
||||
Elf32_Half e_shstrndx;
|
||||
} Elf32_Ehdr;
|
||||
|
||||
typedef struct {
|
||||
Elf64_Char e_ident[EI_NIDENT];
|
||||
Elf64_Half e_type;
|
||||
Elf64_Half e_machine;
|
||||
Elf64_Word e_version;
|
||||
Elf64_Addr e_entry; /* Entry point */
|
||||
Elf64_Off e_phoff;
|
||||
Elf64_Off e_shoff;
|
||||
Elf64_Word e_flags;
|
||||
Elf64_Half e_ehsize;
|
||||
Elf64_Half e_phentsize;
|
||||
Elf64_Half e_phnum;
|
||||
Elf64_Half e_shentsize;
|
||||
Elf64_Half e_shnum;
|
||||
Elf64_Half e_shstrndx;
|
||||
} Elf64_Ehdr;
|
||||
|
||||
/* e_type */
|
||||
#define ET_REL 1
|
||||
#define ET_EXEC 2
|
||||
#define ET_DYN 3
|
||||
#define ET_CORE 4
|
||||
|
||||
/* e_machine (used only for SunOS 5.x hardware capabilities) */
|
||||
#define EM_SPARC 2
|
||||
#define EM_386 3
|
||||
#define EM_SPARC32PLUS 18
|
||||
#define EM_SPARCV9 43
|
||||
#define EM_IA_64 50
|
||||
#define EM_AMD64 62
|
||||
|
||||
/* sh_type */
|
||||
#define SHT_SYMTAB 2
|
||||
#define SHT_NOTE 7
|
||||
#define SHT_DYNSYM 11
|
||||
#define SHT_SUNW_cap 0x6ffffff5 /* SunOS 5.x hw/sw capabilites */
|
||||
|
||||
/* elf type */
|
||||
#define ELFDATANONE 0 /* e_ident[EI_DATA] */
|
||||
#define ELFDATA2LSB 1
|
||||
#define ELFDATA2MSB 2
|
||||
|
||||
/* elf class */
|
||||
#define ELFCLASSNONE 0
|
||||
#define ELFCLASS32 1
|
||||
#define ELFCLASS64 2
|
||||
|
||||
/* magic number */
|
||||
#define EI_MAG0 0 /* e_ident[] indexes */
|
||||
#define EI_MAG1 1
|
||||
#define EI_MAG2 2
|
||||
#define EI_MAG3 3
|
||||
#define EI_CLASS 4
|
||||
#define EI_DATA 5
|
||||
#define EI_VERSION 6
|
||||
#define EI_PAD 7
|
||||
|
||||
#define ELFMAG0 0x7f /* EI_MAG */
|
||||
#define ELFMAG1 'E'
|
||||
#define ELFMAG2 'L'
|
||||
#define ELFMAG3 'F'
|
||||
#define ELFMAG "\177ELF"
|
||||
|
||||
#define OLFMAG1 'O'
|
||||
#define OLFMAG "\177OLF"
|
||||
|
||||
typedef struct {
|
||||
Elf32_Word p_type;
|
||||
Elf32_Off p_offset;
|
||||
Elf32_Addr p_vaddr;
|
||||
Elf32_Addr p_paddr;
|
||||
Elf32_Word p_filesz;
|
||||
Elf32_Word p_memsz;
|
||||
Elf32_Word p_flags;
|
||||
Elf32_Word p_align;
|
||||
} Elf32_Phdr;
|
||||
|
||||
typedef struct {
|
||||
Elf64_Word p_type;
|
||||
Elf64_Word p_flags;
|
||||
Elf64_Off p_offset;
|
||||
Elf64_Addr p_vaddr;
|
||||
Elf64_Addr p_paddr;
|
||||
Elf64_Xword p_filesz;
|
||||
Elf64_Xword p_memsz;
|
||||
Elf64_Xword p_align;
|
||||
} Elf64_Phdr;
|
||||
|
||||
#define PT_NULL 0 /* p_type */
|
||||
#define PT_LOAD 1
|
||||
#define PT_DYNAMIC 2
|
||||
#define PT_INTERP 3
|
||||
#define PT_NOTE 4
|
||||
#define PT_SHLIB 5
|
||||
#define PT_PHDR 6
|
||||
#define PT_NUM 7
|
||||
|
||||
typedef struct {
|
||||
Elf32_Word sh_name;
|
||||
Elf32_Word sh_type;
|
||||
Elf32_Word sh_flags;
|
||||
Elf32_Addr sh_addr;
|
||||
Elf32_Off sh_offset;
|
||||
Elf32_Word sh_size;
|
||||
Elf32_Word sh_link;
|
||||
Elf32_Word sh_info;
|
||||
Elf32_Word sh_addralign;
|
||||
Elf32_Word sh_entsize;
|
||||
} Elf32_Shdr;
|
||||
|
||||
typedef struct {
|
||||
Elf64_Word sh_name;
|
||||
Elf64_Word sh_type;
|
||||
Elf64_Off sh_flags;
|
||||
Elf64_Addr sh_addr;
|
||||
Elf64_Off sh_offset;
|
||||
Elf64_Off sh_size;
|
||||
Elf64_Word sh_link;
|
||||
Elf64_Word sh_info;
|
||||
Elf64_Off sh_addralign;
|
||||
Elf64_Off sh_entsize;
|
||||
} Elf64_Shdr;
|
||||
|
||||
#define NT_NETBSD_CORE_PROCINFO 1
|
||||
|
||||
/* Note header in a PT_NOTE section */
|
||||
typedef struct elf_note {
|
||||
Elf32_Word n_namesz; /* Name size */
|
||||
Elf32_Word n_descsz; /* Content size */
|
||||
Elf32_Word n_type; /* Content type */
|
||||
} Elf32_Nhdr;
|
||||
|
||||
typedef struct {
|
||||
Elf64_Word n_namesz;
|
||||
Elf64_Word n_descsz;
|
||||
Elf64_Word n_type;
|
||||
} Elf64_Nhdr;
|
||||
|
||||
/* Notes used in ET_CORE */
|
||||
#define NT_PRSTATUS 1
|
||||
#define NT_PRFPREG 2
|
||||
#define NT_PRPSINFO 3
|
||||
#define NT_PRXREG 4
|
||||
#define NT_TASKSTRUCT 4
|
||||
#define NT_PLATFORM 5
|
||||
#define NT_AUXV 6
|
||||
|
||||
/* Note types used in executables */
|
||||
/* NetBSD executables (name = "NetBSD") */
|
||||
#define NT_NETBSD_VERSION 1
|
||||
#define NT_NETBSD_EMULATION 2
|
||||
#define NT_FREEBSD_VERSION 1
|
||||
#define NT_OPENBSD_VERSION 1
|
||||
#define NT_DRAGONFLY_VERSION 1
|
||||
/* GNU executables (name = "GNU") */
|
||||
#define NT_GNU_VERSION 1
|
||||
|
||||
/* GNU OS tags */
|
||||
#define GNU_OS_LINUX 0
|
||||
#define GNU_OS_HURD 1
|
||||
#define GNU_OS_SOLARIS 2
|
||||
#define GNU_OS_KFREEBSD 3
|
||||
#define GNU_OS_KNETBSD 4
|
||||
|
||||
/* SunOS 5.x hardware/software capabilities */
|
||||
typedef struct {
|
||||
Elf32_Word c_tag;
|
||||
union {
|
||||
Elf32_Word c_val;
|
||||
Elf32_Addr c_ptr;
|
||||
} c_un;
|
||||
} Elf32_Cap;
|
||||
|
||||
typedef struct {
|
||||
Elf64_Xword c_tag;
|
||||
union {
|
||||
Elf64_Xword c_val;
|
||||
Elf64_Addr c_ptr;
|
||||
} c_un;
|
||||
} Elf64_Cap;
|
||||
|
||||
/* SunOS 5.x hardware/software capability tags */
|
||||
#define CA_SUNW_NULL 0
|
||||
#define CA_SUNW_HW_1 1
|
||||
#define CA_SUNW_SF_1 2
|
||||
|
||||
/* SunOS 5.x software capabilities */
|
||||
#define SF1_SUNW_FPKNWN 0x01
|
||||
#define SF1_SUNW_FPUSED 0x02
|
||||
#define SF1_SUNW_MASK 0x03
|
||||
|
||||
/* SunOS 5.x hardware capabilities: sparc */
|
||||
#define AV_SPARC_MUL32 0x0001
|
||||
#define AV_SPARC_DIV32 0x0002
|
||||
#define AV_SPARC_FSMULD 0x0004
|
||||
#define AV_SPARC_V8PLUS 0x0008
|
||||
#define AV_SPARC_POPC 0x0010
|
||||
#define AV_SPARC_VIS 0x0020
|
||||
#define AV_SPARC_VIS2 0x0040
|
||||
#define AV_SPARC_ASI_BLK_INIT 0x0080
|
||||
#define AV_SPARC_FMAF 0x0100
|
||||
#define AV_SPARC_FJFMAU 0x4000
|
||||
#define AV_SPARC_IMA 0x8000
|
||||
|
||||
/* SunOS 5.x hardware capabilities: 386 */
|
||||
#define AV_386_FPU 0x00000001
|
||||
#define AV_386_TSC 0x00000002
|
||||
#define AV_386_CX8 0x00000004
|
||||
#define AV_386_SEP 0x00000008
|
||||
#define AV_386_AMD_SYSC 0x00000010
|
||||
#define AV_386_CMOV 0x00000020
|
||||
#define AV_386_MMX 0x00000040
|
||||
#define AV_386_AMD_MMX 0x00000080
|
||||
#define AV_386_AMD_3DNow 0x00000100
|
||||
#define AV_386_AMD_3DNowx 0x00000200
|
||||
#define AV_386_FXSR 0x00000400
|
||||
#define AV_386_SSE 0x00000800
|
||||
#define AV_386_SSE2 0x00001000
|
||||
#define AV_386_PAUSE 0x00002000
|
||||
#define AV_386_SSE3 0x00004000
|
||||
#define AV_386_MON 0x00008000
|
||||
#define AV_386_CX16 0x00010000
|
||||
#define AV_386_AHF 0x00020000
|
||||
#define AV_386_TSCP 0x00040000
|
||||
#define AV_386_AMD_SSE4A 0x00080000
|
||||
#define AV_386_POPCNT 0x00100000
|
||||
#define AV_386_AMD_LZCNT 0x00200000
|
||||
#define AV_386_SSSE3 0x00400000
|
||||
#define AV_386_SSE4_1 0x00800000
|
||||
#define AV_386_SSE4_2 0x01000000
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
* Software written by Ian F. Darwin and others;
|
||||
* maintained 1995-present by Christos Zoulas and others.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice immediately at the beginning of the file, without modification,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Header file for public domain tar (tape archive) program.
|
||||
*
|
||||
* @(#)tar.h 1.20 86/10/29 Public Domain.
|
||||
*
|
||||
* Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
|
||||
*
|
||||
* $File: tar.h,v 1.12 2008/02/07 00:58:52 christos Exp $ # checkin only
|
||||
*/
|
||||
|
||||
/*
|
||||
* Header block on tape.
|
||||
*
|
||||
* I'm going to use traditional DP naming conventions here.
|
||||
* A "block" is a big chunk of stuff that we do I/O on.
|
||||
* A "record" is a piece of info that we care about.
|
||||
* Typically many "record"s fit into a "block".
|
||||
*/
|
||||
#define RECORDSIZE 512
|
||||
#define NAMSIZ 100
|
||||
#define TUNMLEN 32
|
||||
#define TGNMLEN 32
|
||||
|
||||
union record {
|
||||
char charptr[RECORDSIZE];
|
||||
struct header {
|
||||
char name[NAMSIZ];
|
||||
char mode[8];
|
||||
char uid[8];
|
||||
char gid[8];
|
||||
char size[12];
|
||||
char mtime[12];
|
||||
char chksum[8];
|
||||
char linkflag;
|
||||
char linkname[NAMSIZ];
|
||||
char magic[8];
|
||||
char uname[TUNMLEN];
|
||||
char gname[TGNMLEN];
|
||||
char devmajor[8];
|
||||
char devminor[8];
|
||||
} header;
|
||||
};
|
||||
|
||||
/* The magic field is filled with this if uname and gname are valid. */
|
||||
#define TMAGIC "ustar" /* 5 chars and a null */
|
||||
#define GNUTMAGIC "ustar " /* 7 chars and a null */
|
||||
@@ -1,44 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
||||
<!DOCTYPE package SYSTEM "../pear/package.dtd">
|
||||
<package>
|
||||
<name>Fileinfo</name>
|
||||
<summary>libmagic bindings</summary>
|
||||
<maintainers>
|
||||
<maintainer>
|
||||
<user>iliaa</user>
|
||||
<name>Ilia Alshanetsky</name>
|
||||
<email>ilia@php.net</email>
|
||||
<role>lead</role>
|
||||
</maintainer>
|
||||
</maintainers>
|
||||
<description>
|
||||
This extension allows retrieval of information regarding vast majority of file.
|
||||
This information may include dimensions, quality, length etc...
|
||||
|
||||
Additionally it can also be used to retrieve the mime type for a particular
|
||||
file and for text files proper language encoding.
|
||||
</description>
|
||||
<license>PHP</license>
|
||||
<release>
|
||||
<state>stable</state>
|
||||
<version>1.0.4</version>
|
||||
<date>2006-11-07</date>
|
||||
<notes>
|
||||
1) Fixed detection of magic files
|
||||
2) Fixed build problems with older version of libmagic
|
||||
</notes>
|
||||
<filelist>
|
||||
<file role="src" name="config.m4"/>
|
||||
<file role="src" name="fileinfo.c"/>
|
||||
<file role="src" name="php_fileinfo.h"/>
|
||||
<file role="doc" name="CREDITS"/>
|
||||
<file role="doc" name="EXPERIMENTAL"/>
|
||||
<file role="doc" name="fileinfo.php"/>
|
||||
</filelist>
|
||||
<deps>
|
||||
</deps>
|
||||
</release>
|
||||
</package>
|
||||
<!--
|
||||
vim:et:ts=1:sw=1
|
||||
-->
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2004 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| 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 |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| http://www.php.net/license/3_0.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. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Ilia Alshanetsky <ilia@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef PHP_FILEINFO_H
|
||||
#define PHP_FILEINFO_H
|
||||
|
||||
extern zend_module_entry fileinfo_module_entry;
|
||||
#define phpext_fileinfo_ptr &fileinfo_module_entry
|
||||
|
||||
#define PHP_FILEINFO_VERSION "1.0.5-dev"
|
||||
|
||||
#ifdef PHP_WIN32
|
||||
#define PHP_FILEINFO_API __declspec(dllexport)
|
||||
#else
|
||||
#define PHP_FILEINFO_API
|
||||
#endif
|
||||
|
||||
#ifdef ZTS
|
||||
#include "TSRM.h"
|
||||
#endif
|
||||
|
||||
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);
|
||||
|
||||
#ifdef ZTS
|
||||
#define FILEINFO_G(v) TSRMG(fileinfo_globals_id, zend_fileinfo_globals *, v)
|
||||
#else
|
||||
#define FILEINFO_G(v) (fileinfo_globals.v)
|
||||
#endif
|
||||
|
||||
#endif /* PHP_FILEINFO_H */
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
@@ -1,53 +0,0 @@
|
||||
--TEST--
|
||||
Test finfo_buffer() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string finfo_buffer(resource finfo, char *string [, int options [, resource context]])
|
||||
* Description: Return infromation about a string buffer.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
|
||||
$options = array(
|
||||
FILEINFO_NONE,
|
||||
FILEINFO_MIME,
|
||||
);
|
||||
|
||||
$buffers = array(
|
||||
"Regular string here",
|
||||
"\177ELF",
|
||||
"\000\000\0001\000\000\0000\000\000\0000\000\000\0002\000\000\0000\000\000\0000\000\000\0003",
|
||||
"\x55\x7A\x6E\x61",
|
||||
"id=ImageMagick",
|
||||
"RIFFüîò^BAVI LISTv",
|
||||
);
|
||||
|
||||
echo "*** Testing finfo_buffer() : basic functionality ***\n";
|
||||
|
||||
foreach( $options as $option ) {
|
||||
$finfo = finfo_open( $option, $magicFile );
|
||||
foreach( $buffers as $string ) {
|
||||
var_dump( finfo_buffer( $finfo, $string, $option ) );
|
||||
}
|
||||
finfo_close( $finfo );
|
||||
}
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_buffer() : basic functionality ***
|
||||
string(36) "ASCII text, with no line terminators"
|
||||
string(3) "ELF"
|
||||
string(22) "old ACE/gr binary file"
|
||||
string(12) "xo65 object,"
|
||||
string(15) "MIFF image data"
|
||||
string(25) "RIFF (little-endian) data"
|
||||
string(28) "text/plain; charset=us-ascii"
|
||||
string(26) "text/plain; charset=ebcdic"
|
||||
string(24) "application/octet-stream"
|
||||
string(28) "text/plain; charset=us-ascii"
|
||||
string(28) "text/plain; charset=us-ascii"
|
||||
string(25) "text/plain; charset=utf-8"
|
||||
===DONE===
|
||||
@@ -1,43 +0,0 @@
|
||||
--TEST--
|
||||
Test finfo_buffer() function : error conditions
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string finfo_buffer(resource finfo, char *string [, int options [, resource context]])
|
||||
* Description: Return infromation about a string buffer.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
|
||||
echo "*** Testing finfo_buffer() : error conditions ***\n";
|
||||
|
||||
$finfo = finfo_open( FILEINFO_NONE, $magicFile );
|
||||
|
||||
//Test finfo_buffer with one more than the expected number of arguments
|
||||
echo "\n-- Testing finfo_buffer() function with more than expected no. of arguments --\n";
|
||||
|
||||
$context = stream_context_get_default();
|
||||
$extra_arg = 10;
|
||||
var_dump( finfo_buffer($finfo, "foobar", FILEINFO_MIME, $context, $extra_arg) );
|
||||
|
||||
// Testing finfo_buffer with one less than the expected number of arguments
|
||||
echo "\n-- Testing finfo_buffer() function with less than expected no. of arguments --\n";
|
||||
|
||||
var_dump( finfo_buffer($finfo) );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_buffer() : error conditions ***
|
||||
|
||||
-- Testing finfo_buffer() function with more than expected no. of arguments --
|
||||
|
||||
Warning: finfo_buffer() expects at most 4 parameters, 5 given in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Testing finfo_buffer() function with less than expected no. of arguments --
|
||||
|
||||
Warning: finfo_buffer() expects at least 2 parameters, 1 given in %s on line %d
|
||||
bool(false)
|
||||
===DONE===
|
||||
@@ -1,52 +0,0 @@
|
||||
--TEST--
|
||||
Test finfo_buffer() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string finfo_buffer(resource finfo, char *string [, int options [, resource context]])
|
||||
* Description: Return infromation about a string buffer.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
|
||||
$options = array(
|
||||
FILEINFO_NONE,
|
||||
FILEINFO_MIME,
|
||||
);
|
||||
|
||||
$buffers = array(
|
||||
"Regular string here",
|
||||
"\177ELF",
|
||||
"\000\000\0001\000\000\0000\000\000\0000\000\000\0002\000\000\0000\000\000\0000\000\000\0003",
|
||||
"\x55\x7A\x6E\x61",
|
||||
"id=ImageMagick",
|
||||
"RIFFüîò^BAVI LISTv",
|
||||
);
|
||||
|
||||
echo "*** Testing finfo_buffer() : variation functionality with oo interface ***\n";
|
||||
|
||||
foreach( $options as $option ) {
|
||||
$finfo = new finfo( $option, $magicFile );
|
||||
foreach( $buffers as $string ) {
|
||||
var_dump( $finfo->buffer( $string, $option ) );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_buffer() : variation functionality with oo interface ***
|
||||
string(36) "ASCII text, with no line terminators"
|
||||
string(3) "ELF"
|
||||
string(22) "old ACE/gr binary file"
|
||||
string(12) "xo65 object,"
|
||||
string(15) "MIFF image data"
|
||||
string(25) "RIFF (little-endian) data"
|
||||
string(28) "text/plain; charset=us-ascii"
|
||||
string(26) "text/plain; charset=ebcdic"
|
||||
string(24) "application/octet-stream"
|
||||
string(28) "text/plain; charset=us-ascii"
|
||||
string(28) "text/plain; charset=us-ascii"
|
||||
string(25) "text/plain; charset=utf-8"
|
||||
===DONE===
|
||||
@@ -1,33 +0,0 @@
|
||||
--TEST--
|
||||
Test finfo_close() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : resource finfo_close(resource finfo)
|
||||
* Description: Close fileinfo resource.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
echo "*** Testing finfo_close() : basic functionality ***\n";
|
||||
|
||||
$magicFile = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'magic';
|
||||
|
||||
$finfo = finfo_open( FILEINFO_MIME, $magicFile );
|
||||
var_dump( $finfo );
|
||||
|
||||
// Calling finfo_close() with all possible arguments
|
||||
var_dump( finfo_close($finfo) );
|
||||
|
||||
$finfo = new finfo( FILEINFO_MIME, $magicFile );
|
||||
var_dump( $finfo );
|
||||
unset( $finfo );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_close() : basic functionality ***
|
||||
resource(%d) of type (file_info)
|
||||
bool(true)
|
||||
object(finfo)#%d (%d) {
|
||||
}
|
||||
===DONE===
|
||||
@@ -1,45 +0,0 @@
|
||||
--TEST--
|
||||
Test finfo_close() function : error conditions
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : resource finfo_close(resource finfo)
|
||||
* Description: Close fileinfo resource.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
echo "*** Testing finfo_close() : error conditions ***\n";
|
||||
|
||||
$magicFile = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'magic';
|
||||
$finfo = finfo_open( FILEINFO_MIME, $magicFile );
|
||||
$fp = fopen( __FILE__, 'r' );
|
||||
|
||||
echo "\n-- Testing finfo_close() function with Zero arguments --\n";
|
||||
var_dump( finfo_close() );
|
||||
|
||||
echo "\n-- Testing finfo_close() function with more than expected no. of arguments --\n";
|
||||
var_dump( finfo_close( $finfo, '10') );
|
||||
|
||||
echo "\n-- Testing finfo_close() function with wrong resource type --\n";
|
||||
var_dump( finfo_close( $fp ) );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_close() : error conditions ***
|
||||
|
||||
-- Testing finfo_close() function with Zero arguments --
|
||||
|
||||
Warning: finfo_close() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Testing finfo_close() function with more than expected no. of arguments --
|
||||
|
||||
Warning: finfo_close() expects exactly 1 parameter, 2 given in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Testing finfo_close() function with wrong resource type --
|
||||
|
||||
Warning: finfo_close(): supplied resource is not a valid file_info resource in %s on line %d
|
||||
bool(false)
|
||||
===DONE===
|
||||
@@ -1,26 +0,0 @@
|
||||
--TEST--
|
||||
finfo_file(): Testing file names
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$fp = finfo_open();
|
||||
var_dump(finfo_file($fp, "\0"));
|
||||
var_dump(finfo_file($fp, ''));
|
||||
var_dump(finfo_file($fp, NULL));
|
||||
var_dump(finfo_file($fp, '.'));
|
||||
var_dump(finfo_file($fp, '&'));
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: finfo_file(): Empty filename or path in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: finfo_file(): Empty filename or path in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: finfo_file(): Empty filename or path in %s on line %d
|
||||
bool(false)
|
||||
string(9) "directory"
|
||||
|
||||
Warning: finfo_file(): File or path not found '&' in %s on line %d
|
||||
bool(false)
|
||||
@@ -1,30 +0,0 @@
|
||||
--TEST--
|
||||
finfo_file(): Testing mime types
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$fp = finfo_open(FILEINFO_MIME);
|
||||
$results = array();
|
||||
|
||||
foreach (glob(__DIR__ . "/resources/*") as $filename) {
|
||||
if (is_file($filename)) {
|
||||
$results["$filename"] = finfo_file($fp, $filename);
|
||||
}
|
||||
}
|
||||
ksort($results);
|
||||
|
||||
var_dump($results);
|
||||
?>
|
||||
--EXPECTF--
|
||||
array(5) {
|
||||
["%s/resources/test.bmp"]=>
|
||||
string(14) "image/x-ms-bmp"
|
||||
["%s/resources/test.gif"]=>
|
||||
string(9) "image/gif"
|
||||
["%s/resources/test.jpg"]=>
|
||||
string(10) "image/jpeg"
|
||||
["%s/resources/test.pdf"]=>
|
||||
string(15) "application/pdf"
|
||||
["%s/resources/test.png"]=>
|
||||
string(9) "image/png"
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
--TEST--
|
||||
Test finfo_file() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string finfo_file(resource finfo, char *file_name [, int options [, resource context]])
|
||||
* Description: Return information about a file.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
$finfo = finfo_open( FILEINFO_MIME );
|
||||
|
||||
echo "*** Testing finfo_file() : basic functionality ***\n";
|
||||
|
||||
// Calling finfo_file() with all possible arguments
|
||||
var_dump( finfo_file( $finfo, __FILE__) );
|
||||
var_dump( finfo_file( $finfo, __FILE__, FILEINFO_CONTINUE ) );
|
||||
var_dump( finfo_file( $finfo, $magicFile ) );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_file() : basic functionality ***
|
||||
string(10) "text/x-php"
|
||||
string(15) "PHP script text"
|
||||
string(27) "text/plain; charset=unknown"
|
||||
===DONE===
|
||||
@@ -1,25 +0,0 @@
|
||||
--TEST--
|
||||
finfo_open(): Testing magic_file names
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
var_dump(finfo_open(FILEINFO_MIME, "\0"));
|
||||
var_dump(finfo_open(FILEINFO_MIME, NULL));
|
||||
var_dump(finfo_open(FILEINFO_MIME, ''));
|
||||
var_dump(finfo_open(FILEINFO_MIME, 123));
|
||||
var_dump(finfo_open(FILEINFO_MIME, 1.0));
|
||||
var_dump(finfo_open(FILEINFO_MIME, '/foo/bar/inexistent'));
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: finfo_open(): Failed to load magic database at ''. in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: finfo_open(): Failed to load magic database at ''. in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: finfo_open(): Failed to load magic database at ''. in %s on line %d
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(false)
|
||||
@@ -1,44 +0,0 @@
|
||||
--TEST--
|
||||
Test finfo_open() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : resource finfo_open([int options [, string arg]])
|
||||
* Description: Create a new fileinfo resource.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
|
||||
echo "*** Testing finfo_open() : basic functionality ***\n";
|
||||
|
||||
// Calling finfo_open() with different options
|
||||
var_dump( finfo_open( FILEINFO_MIME, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_NONE, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_SYMLINK, $magicFile ) );
|
||||
//var_dump( finfo_open( FILEINFO_COMPRESS, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_DEVICES, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_CONTINUE, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_PRESERVE_ATIME, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_RAW, $magicFile ) );
|
||||
|
||||
// OO inteface to finfo
|
||||
var_dump( new finfo( FILEINFO_MIME, $magicFile ) );
|
||||
var_dump( new finfo() );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_open() : basic functionality ***
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
object(finfo)#%d (%d) {
|
||||
}
|
||||
object(finfo)#%d (%d) {
|
||||
}
|
||||
===DONE===
|
||||
@@ -1,44 +0,0 @@
|
||||
--TEST--
|
||||
Test finfo_open() function : error functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : resource finfo_open([int options [, string arg]])
|
||||
* Description: Create a new fileinfo resource.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
|
||||
echo "*** Testing finfo_open() : error functionality ***\n";
|
||||
|
||||
var_dump( finfo_open( FILEINFO_MIME, 'foobarfile' ) );
|
||||
var_dump( finfo_open( array(), $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_MIME, $magicFile, 'extraArg' ) );
|
||||
var_dump( finfo_open( PHP_INT_MAX - 1, $magicFile ) );
|
||||
var_dump( finfo_open( 'foobar' ) );
|
||||
|
||||
var_dump( new finfo('foobar') );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_open() : error functionality ***
|
||||
bool(false)
|
||||
|
||||
Warning: finfo_open() expects parameter 1 to be long, array given in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: finfo_open() expects at most 2 parameters, 3 given in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Notice: finfo_open(): Warning: using regular magic file `%s' in %s on line %d
|
||||
resource(%d) of type (file_info)
|
||||
|
||||
Warning: finfo_open() expects parameter 1 to be long, %unicode_string_optional% given in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: finfo::finfo() expects parameter 1 to be long, %unicode_string_optional% given in %s on line %d
|
||||
object(finfo)#%d (%d) {
|
||||
}
|
||||
===DONE===
|
||||
@@ -1,26 +0,0 @@
|
||||
--TEST--
|
||||
Test finfo_open() function : variations in opening
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : resource finfo_open([int options [, string arg]])
|
||||
* Description: Create a new fileinfo resource.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
|
||||
echo "*** Testing finfo_open() : variations in opening ***\n";
|
||||
|
||||
// Calling finfo_open() with different options
|
||||
var_dump( finfo_open( FILEINFO_MIME | FILEINFO_SYMLINK, $magicFile ) );
|
||||
//var_dump( finfo_open( FILEINFO_COMPRESS | FILEINFO_PRESERVE_ATIME, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_DEVICES | FILEINFO_RAW, $magicFile ) );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_open() : variations in opening ***
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
===DONE===
|
||||
@@ -1,19 +0,0 @@
|
||||
--TEST--
|
||||
Test finfo extention : loading into phpinfo()
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
echo "*** Testing finfo extension : loading info phpinfo() ***\n";
|
||||
|
||||
ob_start();
|
||||
echo phpinfo(8);
|
||||
$output = ob_get_clean();
|
||||
|
||||
var_dump(preg_match("/fileinfo support => enabled/", $output));
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo extension : loading info phpinfo() ***
|
||||
int(1)
|
||||
===DONE===
|
||||
@@ -1,40 +0,0 @@
|
||||
--TEST--
|
||||
Test finfo_set_flags() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : bool finfo_set_flags(resource finfo, int options)
|
||||
* Description: Set libmagic configuration options.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
$finfo = finfo_open( FILEINFO_MIME, $magicFile );
|
||||
|
||||
echo "*** Testing finfo_set_flags() : basic functionality ***\n";
|
||||
|
||||
var_dump( finfo_set_flags( $finfo, FILEINFO_NONE ) );
|
||||
var_dump( finfo_set_flags( $finfo, FILEINFO_SYMLINK ) );
|
||||
var_dump( finfo_set_flags() );
|
||||
|
||||
finfo_close( $finfo );
|
||||
|
||||
// OO way
|
||||
$finfo = new finfo( FILEINFO_NONE, $magicFile );
|
||||
var_dump( $finfo->set_flags( FILEINFO_MIME ) );
|
||||
var_dump( $finfo->set_flags() );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_set_flags() : basic functionality ***
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: finfo_set_flags() expects exactly 2 parameters, 0 given in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
|
||||
Warning: finfo::set_flags() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
bool(false)
|
||||
===DONE===
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,28 +0,0 @@
|
||||
--TEST--
|
||||
mime_content_type(): Testing wrong parameters
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
mime_content_type(1);
|
||||
mime_content_type(NULL);
|
||||
mime_content_type(new stdclass);
|
||||
mime_content_type(array());
|
||||
mime_content_type('foo/inexistent');
|
||||
mime_content_type('');
|
||||
mime_content_type("\0");
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: mime_content_type(): Can only process string or stream arguments in %s on line %d
|
||||
|
||||
Warning: mime_content_type(): Can only process string or stream arguments in %s on line %d
|
||||
|
||||
Warning: mime_content_type(): Can only process string or stream arguments in %s on line %d
|
||||
|
||||
Warning: mime_content_type(): Can only process string or stream arguments in %s on line %d
|
||||
|
||||
Warning: mime_content_type(): File or path not found 'foo/inexistent' in %s on line %d
|
||||
|
||||
Warning: mime_content_type(): Empty filename or path in %s on line %d
|
||||
|
||||
Warning: mime_content_type(): Empty filename or path in %s on line %d
|
||||
@@ -1,16 +0,0 @@
|
||||
--TEST--
|
||||
mime_content_type(): Testing parameter
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
var_dump(mime_content_type(__FILE__));
|
||||
var_dump(mime_content_type(fopen(__FILE__, 'r')));
|
||||
var_dump(mime_content_type('.'));
|
||||
var_dump(mime_content_type('./..'));
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
string(%d) "%s"
|
||||
string(%d) "%s"
|
||||
string(9) "directory"
|
||||
string(9) "directory"
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 58 B |
Binary file not shown.
|
Before Width: | Height: | Size: 43 B |
Binary file not shown.
|
Before Width: | Height: | Size: 160 B |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 93 B |
@@ -0,0 +1,5 @@
|
||||
|
||||
LTLIBRARY_NAME = libregex.la
|
||||
LTLIBRARY_SOURCES = regcomp.c regexec.c regerror.c regfree.c
|
||||
|
||||
include $(top_srcdir)/build/ltlib.mk
|
||||
@@ -0,0 +1,142 @@
|
||||
# Microsoft Developer Studio Project File - Name="php4apache2" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=php4apache2 - Win32 Debug_TS
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "php4apache2.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "php4apache2.mak" CFG="php4apache2 - Win32 Debug_TS"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "php4apache2 - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "php4apache2 - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "php4apache2 - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "php4apache2 - Win32 Release_TS"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release_TS"
|
||||
# PROP BASE Intermediate_Dir "Release_TS"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release_TS"
|
||||
# PROP Intermediate_Dir "Release_TS"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4APACHE2_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\main" /I "..\..\TSRM" /D ZEND_DEBUG=0 /D "NDEBUG" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "WIN32" /D "_MBCS" /D "_WINSOCK2API_" /D "_MSWSOCK_" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x407 /d "NDEBUG"
|
||||
# ADD RSC /l 0x407 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 php4ts.lib libhttpd.lib libapr.lib libaprutil.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /libpath:"..\..\Release_TS" /libpath:"..\..\TSRM\Release_TS" /libpath:"..\..\Zend\Release_TS"
|
||||
|
||||
!ELSEIF "$(CFG)" == "php4apache2 - Win32 Release_TS_inline"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release_TS_inline"
|
||||
# PROP BASE Intermediate_Dir "Release_TS_inline"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release_TS_inline"
|
||||
# PROP Intermediate_Dir "Release_TS_inline"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4APACHE2_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\main" /I "..\..\TSRM" /D ZEND_DEBUG=0 /D "ZEND_WIN32_FORCE_INLINE" /D "NDEBUG" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "WIN32" /D "_MBCS" /D "_WINSOCK2API_" /D "_MSWSOCK_" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x407 /d "NDEBUG"
|
||||
# ADD RSC /l 0x407 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 php4ts.lib libhttpd.lib libapr.lib libaprutil.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS_inline/php4apache2.dll" /libpath:"..\..\Release_TS_inline" /libpath:"..\..\TSRM\Release_TS_inline" /libpath:"..\..\Zend\Release_TS_inline"
|
||||
|
||||
!ELSEIF "$(CFG)" == "php4apache2 - Win32 Debug_TS"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug_TS"
|
||||
# PROP BASE Intermediate_Dir "Debug_TS"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug_TS"
|
||||
# PROP Intermediate_Dir "Debug_TS"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4APACHE2_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\main" /I "..\..\TSRM" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "WIN32" /D "_MBCS" /D "_WINSOCK2API_" /D "_MSWSOCK_" /YX /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x407 /d "_DEBUG"
|
||||
# ADD RSC /l 0x407 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 php4ts.lib libhttpd.lib libapr.lib libaprutil.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"..\..\Debug_TS" /libpath:"..\..\TSRM\Debug_TS" /libpath:"..\..\Zend\Debug_TS"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "php4apache2 - Win32 Release_TS"
|
||||
# Name "php4apache2 - Win32 Release_TS_inline"
|
||||
# Name "php4apache2 - Win32 Debug_TS"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\apache_config.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\php_functions.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sapi_apache2.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\php_apache.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
@@ -0,0 +1,99 @@
|
||||
dnl
|
||||
dnl $Id$
|
||||
dnl
|
||||
|
||||
AC_DEFUN(PHP_TEST_WRITE_STDOUT,[
|
||||
AC_CACHE_CHECK(whether writing to stdout works,ac_cv_write_stdout,[
|
||||
AC_TRY_RUN([
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define TEXT "This is the test message -- "
|
||||
|
||||
main()
|
||||
{
|
||||
int n;
|
||||
|
||||
n = write(1, TEXT, sizeof(TEXT)-1);
|
||||
return (!(n == sizeof(TEXT)-1));
|
||||
}
|
||||
],[
|
||||
ac_cv_write_stdout=yes
|
||||
],[
|
||||
ac_cv_write_stdout=no
|
||||
],[
|
||||
ac_cv_write_stdout=no
|
||||
])
|
||||
])
|
||||
if test "$ac_cv_write_stdout" = "yes"; then
|
||||
AC_DEFINE(PHP_WRITE_STDOUT, 1, [whether write(2) works])
|
||||
fi
|
||||
])
|
||||
|
||||
if test "$PHP_SAPI" = "default"; then
|
||||
|
||||
PHP_TEST_WRITE_STDOUT
|
||||
|
||||
PHP_ARG_ENABLE(force-cgi-redirect,whether to force Apache CGI redirect,
|
||||
[ --enable-force-cgi-redirect
|
||||
Enable the security check for internal server
|
||||
redirects. You should use this if you are
|
||||
running the CGI version with Apache. ])
|
||||
|
||||
if test "$PHP_FORCE_CGI_REDIRECT" = "yes"; then
|
||||
REDIRECT=1
|
||||
else
|
||||
REDIRECT=0
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED(FORCE_CGI_REDIRECT,$REDIRECT,[ ])
|
||||
|
||||
PHP_ARG_ENABLE(discard-path,whether to discard path_info + path_translated,
|
||||
[ --enable-discard-path If this is enabled, the PHP CGI binary
|
||||
can safely be placed outside of the
|
||||
web tree and people will not be able
|
||||
to circumvent .htaccess security. ])
|
||||
|
||||
if test "$PHP_DISCARD_PATH" = "yes"; then
|
||||
DISCARD_PATH=1
|
||||
else
|
||||
DISCARD_PATH=0
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED(DISCARD_PATH, $DISCARD_PATH, [ ])
|
||||
|
||||
INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_PROGRAM \$(INSTALL_ROOT)\$(bindir)/php-cgi"
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING(for fhttpd module support)
|
||||
AC_ARG_WITH(fhttpd,
|
||||
[ --with-fhttpd[=DIR] Build fhttpd module. DIR is the fhttpd sources
|
||||
directory, defaults to /usr/local/src/fhttpd.],
|
||||
[
|
||||
if test "$withval" = "yes"; then
|
||||
# fhttpd source directory
|
||||
withval=/usr/local/src/fhttpd
|
||||
fi
|
||||
if test "$withval" != "no"; then
|
||||
# For fhttpd 0.3.x
|
||||
if test -f $withval/servproc.h; then
|
||||
FHTTPD_INCLUDE=-I$withval/
|
||||
FHTTPD_LIB=$withval/servproc.o
|
||||
FHTTPD_TARGET=$withval/
|
||||
PHP_BUILD_STATIC
|
||||
PHP_SAPI=cgi
|
||||
AC_DEFINE(FHTTPD,1,[ ])
|
||||
AC_MSG_RESULT(yes - fhttpd 0.3.x)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
AC_MSG_ERROR(Invalid fhttpd directory - unable to find servproc.h under $withval)
|
||||
fi
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
],[
|
||||
AC_MSG_RESULT(no)
|
||||
])
|
||||
INCLUDES="$INCLUDES $FHTTPD_INCLUDE"
|
||||
dnl## AC_SUBST(FHTTPD_INCLUDE)
|
||||
PHP_SUBST(FHTTPD_LIB)
|
||||
PHP_SUBST(FHTTPD_TARGET)
|
||||
@@ -0,0 +1,4 @@
|
||||
fastcgi
|
||||
Ben Mansell
|
||||
Stephen Landamore
|
||||
Daniel Silverstone
|
||||
@@ -0,0 +1,53 @@
|
||||
Using FastCGI PHP with Apache
|
||||
=============================
|
||||
|
||||
First of all, you may well ask 'Why?'. After all, Apache already has mod_php.
|
||||
However, there are advantages to running PHP with FastCGI. Separating the
|
||||
PHP code from the web server removes 'bloat' from the main server, and should
|
||||
improve the performance of non-PHP requests. Secondly, having one permanent
|
||||
PHP process as opposed to one per apache process means that shared resources
|
||||
like persistent database connections are used more efficiently.
|
||||
|
||||
First of all, make sure that the FastCGI module is enabled. You should have
|
||||
a line in your config like:
|
||||
|
||||
LoadModule fastcgi_module /usr/lib/apache/1.3/mod_fastcgi.so
|
||||
|
||||
Don't load mod_php, by the way. Make sure it is commented out!
|
||||
|
||||
#LoadModule php4_module /usr/lib/apache/1.3/libphp4.so
|
||||
|
||||
Now, we'll create a fcgi-bin directory, just like you would do with normal
|
||||
CGI scripts. You'll need to create a directory somewhere to store your
|
||||
FastCGI binaries. We'll use /space/fcgi-bin/ for this example. Remember to
|
||||
copy the FastCGI-PHP binary in there. (named just 'php')
|
||||
|
||||
ScriptAlias /fcgi-bin/ /space/fcgi-bin/
|
||||
<Location /fcgi-bin/>
|
||||
SetHandler fastcgi-script
|
||||
</Location>
|
||||
|
||||
Next, we need to tell Apache to use the FastCGI binary /fcgi-bin/php to
|
||||
deliver PHP pages. All that is needed is:
|
||||
|
||||
AddType application/x-httpd-php .php
|
||||
Action application/x-httpd-php /fcgi-bin/php
|
||||
|
||||
Now, if you restart Apache, php pages should now be delivered!
|
||||
|
||||
|
||||
Running PHP-FastCGI separately from the webserver
|
||||
-------------------------------------------------
|
||||
|
||||
(Read README.FastCGI for why you might want to do this).
|
||||
Easy! Add one more configuration line:
|
||||
|
||||
FastCgiExternalServer /space/fcgi-bin/php -host localhost:8002
|
||||
|
||||
Then, start the PHP off with the following command:
|
||||
|
||||
/space/fcgi-bin/php 8002
|
||||
|
||||
The number 8002 is the port that PHP will listen on for requests - change this
|
||||
to anything suitable. And be sure to firewall it out so that external
|
||||
connections are denied!
|
||||
@@ -0,0 +1,91 @@
|
||||
FastCGI module
|
||||
--------------
|
||||
|
||||
This module requires the FastCGI development kit, available from
|
||||
http://www.fastcgi.com/
|
||||
|
||||
Before building PHP, please enter the dev kit, and run:
|
||||
|
||||
./configure
|
||||
make
|
||||
make export
|
||||
|
||||
This will compile the library code required for the FastCGI module. All
|
||||
that is then required is to configure PHP with the '--with-fastcgi' option.
|
||||
After making the code, you will end up with a binary file called 'php'.
|
||||
Installation of this file will depend on the web server being used, please
|
||||
see their documentation for details.
|
||||
|
||||
|
||||
|
||||
Running the FastCGI PHP module
|
||||
------------------------------
|
||||
|
||||
There are two ways to run the resulting 'php' binary after the fastcgi
|
||||
version has been built:
|
||||
|
||||
1) Configure your web server to run the PHP binary itself.
|
||||
|
||||
This is the simplest method, obviously you will have to configure your
|
||||
web server appropriately. Some web servers may also not support this method,
|
||||
or may not be as efficient.
|
||||
|
||||
2) Run PHP separately from the web server.
|
||||
|
||||
In this setup, PHP is started as a separate process entirely from the web
|
||||
server. It will listen on a socket for new FastCGI requests, and deliver
|
||||
PHP pages as appropriate. This is the recommended way of running PHP-FastCGI.
|
||||
To run this way, you must start the PHP binary running by giving it a port
|
||||
number to listen to on the command line, e.g.:
|
||||
|
||||
./php 8002
|
||||
|
||||
(you can also specify a bind address, e.g. ./php localhost:8002. However, this
|
||||
relies on the FastCGI devkit and does not seem to work properly)
|
||||
|
||||
You must also configure your web server to connect to the appropriate port
|
||||
in order to talk to the PHP FastCGI process.
|
||||
|
||||
The advantage of running PHP in this way is that it entirely separates the
|
||||
web server and PHP process, so that one cannot disrupt the other. It also
|
||||
allows PHP to be on an entirely separate machine from the web server if need
|
||||
be, you could even have several web servers utilising the same running PHP
|
||||
process if required!
|
||||
|
||||
|
||||
Security
|
||||
--------
|
||||
|
||||
Be sure to run the php binary as an appropriate userid. Also, firewall out
|
||||
the port that PHP is listening on. In addition, you can set the environment
|
||||
variable FCGI_WEB_SERVER_ADDRS to control who can connect to the FastCGI.
|
||||
Set it to a comma separated list of IP addresses, e.g.:
|
||||
|
||||
export FCGI_WEB_SERVER_ADDRS=199.170.183.28,199.170.183.71
|
||||
|
||||
|
||||
Tuning
|
||||
------
|
||||
|
||||
There are a few tuning parameters that can be tweaked to control the
|
||||
performance of FastCGI PHP. The following are environment variables that can
|
||||
be set before running the PHP binary:
|
||||
|
||||
PHP_FCGI_CHILDREN (default value: 8)
|
||||
|
||||
This controls how many child processes the PHP process spawns. When the
|
||||
fastcgi starts, it creates a number of child processes which handle one
|
||||
page request at a time. So by default, you will be able to handle 8
|
||||
concurrent PHP page requests. Further requests will be queued.
|
||||
Increasing this number will allow for better concurrency, especially if you
|
||||
have pages that take a significant time to create, or supply a lot of data
|
||||
(e.g. downloading huge files via PHP). On the other hand, having more
|
||||
processes running will use more RAM, and letting too many PHP pages be
|
||||
generated concurrently will mean that each request will be slow.
|
||||
|
||||
PHP_FCGI_MAX_REQUESTS (default value: 500)
|
||||
|
||||
This controls how many requests each child process will handle before
|
||||
exitting. When one process exits, another will be created. This tuning is
|
||||
necessary because several PHP functions are known to have memory leaks. If the
|
||||
PHP processes were left around forever, they would be become very inefficient.
|
||||
@@ -0,0 +1,26 @@
|
||||
dnl
|
||||
dnl $Id$
|
||||
dnl
|
||||
|
||||
AC_MSG_CHECKING(for FastCGI support)
|
||||
AC_ARG_WITH(fastcgi,
|
||||
[ --with-fastcgi=SRCDIR Build PHP as FastCGI application],[
|
||||
if test "$withval" = "yes"; then
|
||||
FASTCGIPATH=/usr/local
|
||||
else
|
||||
FASTCGIPATH=$withval
|
||||
fi
|
||||
test -f "$FASTCGIPATH/lib/libfcgi.a" || AC_MSG_ERROR(Unable to find libfcgi.a in $FASTCGIPATH/lib)
|
||||
test -f "$FASTCGIPATH/include/fastcgi.h" || AC_MSG_ERROR(Unable to find fastcgi.h in $FASTCGIPATH/include)
|
||||
PHP_SELECT_SAPI(fastcgi, programm, fastcgi.c)
|
||||
PHP_LIBS=$FASTCGIPATH/lib/libfcgi.a
|
||||
PHP_ADD_INCLUDE($FASTCGIPATH/include)
|
||||
EXT_PROGRAM_LDADD="$EXT_PROGRAM_LDADD $FASTCGIPATH/lib/libfcgi.a"
|
||||
INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_PROGRAM \$(bindir)/$SAPI_FASTCGI"
|
||||
RESULT=yes
|
||||
PHP_SUBST(FASTCGI_LIBADD)
|
||||
PHP_SUBST(EXT_PROGRAM_LDADD)
|
||||
],[
|
||||
RESULT=no
|
||||
])
|
||||
AC_MSG_RESULT($RESULT)
|
||||
@@ -0,0 +1,609 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2002 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.02 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available at through the world-wide-web at |
|
||||
| http://www.php.net/license/2_02.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. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Ben Mansell <php@slimyhorror.com> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* Debugging */
|
||||
/* #define DEBUG_FASTCGI 1 */
|
||||
|
||||
/* Two configurables for the FastCGI runner.
|
||||
*
|
||||
* PHP_FCGI_CHILDREN - if set, the FastCGI will pre-fork this many processes
|
||||
* which will accept requests.
|
||||
*
|
||||
* PHP_FCGI_MAX_REQUESTS - if set, the runner will kill itself after handling
|
||||
* the given number of requests. This is to curb any
|
||||
* memory leaks in PHP.
|
||||
*/
|
||||
|
||||
|
||||
/* The following code is based mainly on the thttpd sapi and the original
|
||||
* CGI code, no doubt with many new and interesting bugs created... :)
|
||||
*/
|
||||
|
||||
#include "php.h"
|
||||
#include "SAPI.h"
|
||||
#include "php_main.h"
|
||||
#include "php_fastcgi.h"
|
||||
#include "php_variables.h"
|
||||
|
||||
#include "fcgi_config.h"
|
||||
#include "fcgiapp.h"
|
||||
#include <stdio.h>
|
||||
#if HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef PHP_WIN32
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include "win32/php_registry.h"
|
||||
#else
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#if HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#ifndef S_ISREG
|
||||
#define S_ISREG(mode) ((mode) & _S_IFREG)
|
||||
#endif
|
||||
|
||||
FCGX_Stream *in, *out, *err;
|
||||
FCGX_ParamArray envp;
|
||||
char *path_info = NULL;
|
||||
#ifndef PHP_WIN32
|
||||
struct sigaction act, old_term, old_quit, old_int;
|
||||
#endif
|
||||
|
||||
/* Our original environment from when the FastCGI first started */
|
||||
char **orig_env;
|
||||
|
||||
/* The environment given by the FastCGI */
|
||||
char **cgi_env;
|
||||
|
||||
/* The manufactured environment, from merging the base environ with
|
||||
* the parameters set by the per-connection environment
|
||||
*/
|
||||
char **merge_env;
|
||||
|
||||
/**
|
||||
* Number of child processes that will get created to service requests
|
||||
*/
|
||||
static int children = 8;
|
||||
|
||||
/**
|
||||
* Set to non-zero if we are the parent process
|
||||
*/
|
||||
static int parent = 1;
|
||||
|
||||
/**
|
||||
* Process group
|
||||
*/
|
||||
static pid_t pgroup;
|
||||
|
||||
|
||||
static int sapi_fastcgi_ub_write(const char *str, uint str_length TSRMLS_DC)
|
||||
{
|
||||
uint sent = FCGX_PutStr( str, str_length, out );
|
||||
return sent;
|
||||
}
|
||||
|
||||
|
||||
static void sapi_fastcgi_flush( void *server_context )
|
||||
{
|
||||
if( FCGX_FFlush( out ) == -1 ) {
|
||||
php_handle_aborted_connection();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void sapi_fastcgi_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC)
|
||||
{
|
||||
if( sapi_header ) {
|
||||
#ifdef DEBUG_FASTCGI
|
||||
fprintf( stderr, "Header: %s\n", sapi_header->header );
|
||||
#endif
|
||||
FCGX_PutStr( sapi_header->header, sapi_header->header_len, out );
|
||||
}
|
||||
FCGX_PutStr( "\r\n", 2, out );
|
||||
}
|
||||
|
||||
static int sapi_fastcgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
|
||||
{
|
||||
size_t read_bytes = 0;
|
||||
int c;
|
||||
char *pos = buffer;
|
||||
|
||||
while( count_bytes ) {
|
||||
c = FCGX_GetStr( pos, count_bytes, in );
|
||||
read_bytes += c;
|
||||
count_bytes -= c;
|
||||
pos += c;
|
||||
if( !c ) break;
|
||||
}
|
||||
return read_bytes;
|
||||
}
|
||||
|
||||
static char *sapi_fastcgi_read_cookies(TSRMLS_D)
|
||||
{
|
||||
return getenv( "HTTP_COOKIE" );
|
||||
}
|
||||
|
||||
|
||||
static void sapi_fastcgi_register_variables(zval *track_vars_array TSRMLS_DC)
|
||||
{
|
||||
/* In CGI mode, we consider the environment to be a part of the server
|
||||
* variables
|
||||
*/
|
||||
php_import_environment_variables(track_vars_array TSRMLS_CC);
|
||||
|
||||
/* Build the special-case PHP_SELF variable for the CGI version */
|
||||
php_register_variable("PHP_SELF", (SG(request_info).request_uri ? SG(request_info).request_uri:""), track_vars_array TSRMLS_CC);
|
||||
}
|
||||
|
||||
|
||||
static void sapi_fastcgi_log_message(char *message)
|
||||
{
|
||||
#ifdef DEBUG_FASTCGI
|
||||
fprintf( stderr, "Log Message: %s\n", message );
|
||||
#endif
|
||||
FCGX_FPrintF(err, "%s\n", message);
|
||||
}
|
||||
|
||||
|
||||
static sapi_module_struct fastcgi_sapi_module = {
|
||||
"fastcgi",
|
||||
"FastCGI",
|
||||
|
||||
php_module_startup,
|
||||
php_module_shutdown_wrapper,
|
||||
|
||||
NULL, /* activate */
|
||||
NULL, /* deactivate */
|
||||
|
||||
sapi_fastcgi_ub_write,
|
||||
sapi_fastcgi_flush,
|
||||
NULL, /* get uid */
|
||||
NULL, /* getenv */
|
||||
|
||||
php_error,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
sapi_fastcgi_send_header,
|
||||
sapi_fastcgi_read_post,
|
||||
sapi_fastcgi_read_cookies,
|
||||
|
||||
sapi_fastcgi_register_variables,
|
||||
sapi_fastcgi_log_message,
|
||||
|
||||
NULL, /* Block interruptions */
|
||||
NULL, /* Unblock interruptions */
|
||||
|
||||
STANDARD_SAPI_MODULE_PROPERTIES
|
||||
};
|
||||
|
||||
static void fastcgi_module_main(TSRMLS_D)
|
||||
{
|
||||
zend_file_handle file_handle;
|
||||
int c, retval = FAILURE;
|
||||
|
||||
file_handle.type = ZEND_HANDLE_FILENAME;
|
||||
file_handle.filename = SG(request_info).path_translated;
|
||||
file_handle.free_filename = 0;
|
||||
file_handle.opened_path = NULL;
|
||||
|
||||
/* eat the bang line */
|
||||
if (SG(request_info).path_translated) {
|
||||
retval = php_fopen_primary_script(&file_handle TSRMLS_CC);
|
||||
}
|
||||
|
||||
if (retval == SUCCESS) {
|
||||
/* #!php support */
|
||||
c = fgetc(file_handle.handle.fp);
|
||||
if (c == '#') {
|
||||
while (c != 10 && c != 13) {
|
||||
c = fgetc(file_handle.handle.fp); /* skip to end of line */
|
||||
}
|
||||
CG(zend_lineno)++;
|
||||
} else {
|
||||
rewind(file_handle.handle.fp);
|
||||
}
|
||||
}
|
||||
|
||||
if (php_request_startup(TSRMLS_C) == SUCCESS) {
|
||||
php_execute_script(&file_handle TSRMLS_CC);
|
||||
php_request_shutdown(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int init_request_info( TSRMLS_D )
|
||||
{
|
||||
char *content_length = getenv("CONTENT_LENGTH");
|
||||
char *content_type = getenv( "CONTENT_TYPE" );
|
||||
const char *auth;
|
||||
struct stat st;
|
||||
char *pi = getenv( "PATH_INFO" );
|
||||
char *pt = getenv( "PATH_TRANSLATED" );
|
||||
if (!pt) {
|
||||
pt = getenv("SCRIPT_FILENAME"); // apache mod_fastcgi sets this
|
||||
}
|
||||
path_info = strdup( pi );
|
||||
|
||||
SG(request_info).request_method = getenv("REQUEST_METHOD");
|
||||
SG(request_info).query_string = getenv("QUERY_STRING");
|
||||
SG(request_info).request_uri = path_info;
|
||||
if (!SG(request_info).request_uri) {
|
||||
SG(request_info).request_uri = getenv("SCRIPT_NAME");
|
||||
}
|
||||
SG(request_info).content_type = ( content_type ? content_type : "" );
|
||||
SG(request_info).content_length = (content_length?atoi(content_length):0);
|
||||
SG(sapi_headers).http_response_code = 200;
|
||||
|
||||
SG(request_info).path_translated = pt;
|
||||
if (!pt) return -1;
|
||||
/*
|
||||
* if the file doesn't exist, try to extract PATH_INFO out
|
||||
* of it by stat'ing back through the '/'
|
||||
*/
|
||||
if ( stat( pt, &st ) == -1 ) {
|
||||
int len = strlen(pt);
|
||||
char *ptr;
|
||||
while( ptr = strrchr(pt,'/') ) {
|
||||
*ptr = 0;
|
||||
if ( stat(pt, &st) == 0 && S_ISREG(st.st_mode) ) {
|
||||
/*
|
||||
* okay, we found the base script!
|
||||
* work out how many chars we had to strip off;
|
||||
* then we can modify PATH_INFO
|
||||
* accordingly
|
||||
*/
|
||||
int slen = len - strlen(pt);
|
||||
if ( pi ) {
|
||||
int pilen = strlen( pi );
|
||||
strcpy( pi, pi + pilen - slen );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* if we stripped out all the '/' and still didn't find
|
||||
* a valid path... we will fail, badly. of course we would
|
||||
* have failed anyway... is there a nice way to error?
|
||||
*/
|
||||
} else {
|
||||
/* the first stat succeeded... */
|
||||
if ( pi ) *pi = 0;
|
||||
}
|
||||
|
||||
/* The CGI RFC allows servers to pass on unvalidated Authorization data */
|
||||
auth = getenv("HTTP_AUTHORIZATION");
|
||||
#ifdef DEBUG_FASTCGI
|
||||
fprintf( stderr, "Authorization: %s\n", auth );
|
||||
#endif
|
||||
php_handle_auth_data(auth TSRMLS_CC);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void fastcgi_php_init(void)
|
||||
{
|
||||
TSRMLS_FETCH();
|
||||
sapi_startup(&fastcgi_sapi_module);
|
||||
fastcgi_sapi_module.startup(&fastcgi_sapi_module);
|
||||
SG(server_context) = (void *) 1;
|
||||
}
|
||||
|
||||
void fastcgi_php_shutdown(void)
|
||||
{
|
||||
TSRMLS_FETCH();
|
||||
if (SG(server_context) != NULL) {
|
||||
fastcgi_sapi_module.shutdown(&fastcgi_sapi_module);
|
||||
sapi_shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clean up child processes upon exit
|
||||
*/
|
||||
void fastcgi_cleanup(int signal)
|
||||
{
|
||||
|
||||
#ifdef DEBUG_FASTCGI
|
||||
fprintf( stderr, "FastCGI shutdown, pid %d\n", getpid() );
|
||||
#endif
|
||||
|
||||
#ifndef PHP_WIN32
|
||||
sigaction( SIGTERM, &old_term, 0 );
|
||||
|
||||
/* Kill all the processes in our process group */
|
||||
kill( -pgroup, SIGTERM );
|
||||
#endif
|
||||
|
||||
/* We should exit at this point, but MacOSX doesn't seem to */
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int exit_status = SUCCESS;
|
||||
#ifndef PHP_WIN32
|
||||
int c, i, len;
|
||||
zend_file_handle file_handle;
|
||||
char *s;
|
||||
int status;
|
||||
#endif
|
||||
char *argv0=NULL;
|
||||
char *script_file=NULL;
|
||||
zend_llist global_vars;
|
||||
int max_requests = 500;
|
||||
int requests = 0;
|
||||
int fcgi_fd = 0;
|
||||
int env_size, cgi_env_size;
|
||||
FCGX_Request request;
|
||||
#ifdef ZTS
|
||||
zend_compiler_globals *compiler_globals;
|
||||
zend_executor_globals *executor_globals;
|
||||
php_core_globals *core_globals;
|
||||
sapi_globals_struct *sapi_globals;
|
||||
void ***tsrm_ls;
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_FASTCGI
|
||||
fprintf( stderr, "Initialising now, pid %d!\n", getpid() );
|
||||
#endif
|
||||
|
||||
if( FCGX_IsCGI() ) {
|
||||
/* Did a bind address or port get configured on the command line? */
|
||||
if( argc >= 2 ) {
|
||||
/* Pass on the arg to the FastCGI library, with one exception.
|
||||
* If just a port is specified, then we prepend a ':' onto the
|
||||
* path (it's what the fastcgi library expects)
|
||||
*/
|
||||
int port = atoi( argv[ 1 ] );
|
||||
if( port ) {
|
||||
char bindport[ 32 ];
|
||||
snprintf( bindport, 32, ":%s", argv[ 1 ] );
|
||||
fcgi_fd = FCGX_OpenSocket( bindport, 128 );
|
||||
} else {
|
||||
fcgi_fd = FCGX_OpenSocket( argv[ 1 ], 128 );
|
||||
}
|
||||
if( fcgi_fd < 0 ) {
|
||||
fprintf( stderr, "Couldn't create FastCGI listen socket\n" );
|
||||
exit( 1 );
|
||||
}
|
||||
} else {
|
||||
fprintf( stderr, "The FastCGI version of PHP cannot be "
|
||||
"run as a CGI application\n" );
|
||||
exit( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate environment size */
|
||||
env_size = 0;
|
||||
while( environ[ env_size ] ) { env_size++; }
|
||||
/* Also include the final NULL pointer */
|
||||
env_size++;
|
||||
|
||||
/* Allocate for our environment */
|
||||
orig_env = malloc( env_size * sizeof( char *));
|
||||
if( !orig_env ) {
|
||||
perror( "Can't malloc environment" );
|
||||
exit( 1 );
|
||||
}
|
||||
memcpy( orig_env, environ, env_size * sizeof( char *));
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
#if defined(SIGPIPE) && defined(SIG_IGN)
|
||||
signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so
|
||||
that sockets created via fsockopen()
|
||||
don't kill PHP if the remote site
|
||||
closes it. in apache|apxs mode apache
|
||||
does that for us! thies@thieso.net
|
||||
20000419 */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ZTS
|
||||
tsrm_startup(1, 1, 0, NULL);
|
||||
#endif
|
||||
sapi_startup(&fastcgi_sapi_module);
|
||||
#ifdef PHP_WIN32
|
||||
_fmode = _O_BINARY; /*sets default for file streams to binary */
|
||||
setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */
|
||||
setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */
|
||||
setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
|
||||
#endif
|
||||
|
||||
if (php_module_startup(&fastcgi_sapi_module)==FAILURE) {
|
||||
return FAILURE;
|
||||
}
|
||||
#ifdef ZTS
|
||||
compiler_globals = ts_resource(compiler_globals_id);
|
||||
executor_globals = ts_resource(executor_globals_id);
|
||||
core_globals = ts_resource(core_globals_id);
|
||||
sapi_globals = ts_resource(sapi_globals_id);
|
||||
tsrm_ls = ts_resource(0);
|
||||
#endif
|
||||
|
||||
/* How many times to run PHP scripts before dying */
|
||||
if( getenv( "PHP_FCGI_MAX_REQUESTS" )) {
|
||||
max_requests = atoi( getenv( "PHP_FCGI_MAX_REQUESTS" ));
|
||||
if( !max_requests ) {
|
||||
fprintf( stderr,
|
||||
"PHP_FCGI_MAX_REQUESTS is not valid\n" );
|
||||
exit( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef PHP_WIN32
|
||||
/* Pre-fork, if required */
|
||||
if( getenv( "PHP_FCGI_CHILDREN" )) {
|
||||
children = atoi( getenv( "PHP_FCGI_CHILDREN" ));
|
||||
if( !children ) {
|
||||
fprintf( stderr,
|
||||
"PHP_FCGI_CHILDREN is not valid\n" );
|
||||
exit( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialise FastCGI request structure */
|
||||
FCGX_Init();
|
||||
FCGX_InitRequest( &request, fcgi_fd, 0 );
|
||||
|
||||
if( children ) {
|
||||
int running = 0;
|
||||
int i;
|
||||
pid_t pid;
|
||||
|
||||
/* Create a process group for ourself & children */
|
||||
setsid();
|
||||
pgroup = getpgrp();
|
||||
#ifdef DEBUG_FASTCGI
|
||||
fprintf( stderr, "Process group %d\n", pgroup );
|
||||
#endif
|
||||
|
||||
/* Set up handler to kill children upon exit */
|
||||
act.sa_flags = 0;
|
||||
act.sa_handler = fastcgi_cleanup;
|
||||
if( sigaction( SIGTERM, &act, &old_term ) ||
|
||||
sigaction( SIGINT, &act, &old_int ) ||
|
||||
sigaction( SIGQUIT, &act, &old_quit )) {
|
||||
perror( "Can't set signals" );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
while( parent ) {
|
||||
do {
|
||||
#ifdef DEBUG_FASTCGI
|
||||
fprintf( stderr, "Forking, %d running\n",
|
||||
running );
|
||||
#endif
|
||||
pid = fork();
|
||||
switch( pid ) {
|
||||
case 0:
|
||||
/* One of the children.
|
||||
* Make sure we don't go round the
|
||||
* fork loop any more
|
||||
*/
|
||||
parent = 0;
|
||||
|
||||
/* don't catch our signals */
|
||||
sigaction( SIGTERM, &old_term, 0 );
|
||||
sigaction( SIGQUIT, &old_quit, 0 );
|
||||
sigaction( SIGINT, &old_int, 0 );
|
||||
break;
|
||||
case -1:
|
||||
perror( "php (pre-forking)" );
|
||||
exit( 1 );
|
||||
break;
|
||||
default:
|
||||
/* Fine */
|
||||
running++;
|
||||
break;
|
||||
}
|
||||
} while( parent && ( running < children ));
|
||||
|
||||
if( parent ) {
|
||||
#ifdef DEBUG_FASTCGI
|
||||
fprintf( stderr, "Wait for kids, pid %d\n",
|
||||
getpid() );
|
||||
#endif
|
||||
wait( &status );
|
||||
running--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
/* Main FastCGI loop */
|
||||
#ifdef DEBUG_FASTCGI
|
||||
fprintf( stderr, "Going into accept loop\n" );
|
||||
#endif
|
||||
|
||||
while( FCGX_Accept_r( &request ) >= 0 ) {
|
||||
|
||||
#ifdef DEBUG_FASTCGI
|
||||
fprintf( stderr, "Got accept\n" );
|
||||
#endif
|
||||
|
||||
in = request.in;
|
||||
out = request.out;
|
||||
err = request.err;
|
||||
cgi_env = request.envp;
|
||||
cgi_env_size = 0;
|
||||
while( cgi_env[ cgi_env_size ] ) { cgi_env_size++; }
|
||||
merge_env = malloc( (env_size+cgi_env_size)*sizeof(char*) );
|
||||
if( !merge_env ) {
|
||||
perror( "Can't malloc environment" );
|
||||
exit( 1 );
|
||||
}
|
||||
memcpy( merge_env, orig_env, (env_size-1)*sizeof(char *) );
|
||||
memcpy( merge_env + env_size - 1,
|
||||
cgi_env, (cgi_env_size+1)*sizeof(char *) );
|
||||
environ = merge_env;
|
||||
|
||||
if (init_request_info(TSRMLS_C)!=0) {
|
||||
/* we received some invalid environment */
|
||||
//char *b = "Can't init the request\n";
|
||||
//sapi_fastcgi_ub_write(b, strlen(b) TSRMLS_C);
|
||||
//FCGX_Finish();
|
||||
//break;
|
||||
}
|
||||
SG(server_context) = (void *) 1; /* avoid server_context==NULL checks */
|
||||
SG(request_info).argv0 = argv0;
|
||||
zend_llist_init(&global_vars, sizeof(char *), NULL, 0);
|
||||
|
||||
fastcgi_module_main(TSRMLS_C);
|
||||
if( path_info ) {
|
||||
free( path_info );
|
||||
path_info = NULL;
|
||||
}
|
||||
|
||||
/* TODO: We should free our environment here, but
|
||||
* some platforms are unhappy if they've altered our
|
||||
* existing environment and we then free() the new
|
||||
* environ pointer
|
||||
*/
|
||||
|
||||
requests++;
|
||||
if( max_requests && ( requests == max_requests )) {
|
||||
FCGX_Finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ZTS
|
||||
tsrm_shutdown();
|
||||
#endif
|
||||
#ifdef DEBUG_FASTCGI
|
||||
fprintf( stderr, "Exiting...\n" );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
# Microsoft Developer Studio Project File - Name="fastcgi" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=fastcgi - Win32 Debug_TS
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "fastcgi.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "fastcgi.mak" CFG="fastcgi - Win32 Debug_TS"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "fastcgi - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "fastcgi - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "fastcgi - Win32 Debug_TS" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "fastcgi - Win32 Release_TS" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "fastcgi - Win32 Release_TS_inline" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "fastcgi - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "..\..\Release"
|
||||
# PROP Intermediate_Dir "..\..\Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "NDEBUG" /D "_CONSOLE" /D ZEND_DEBUG=0 /D "MSVC5" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32" /D "PHP_WIN32" /Fr /FD /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 php4nts.lib libfcgi.lib winmm.lib wsock32.lib netapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /version:4.0 /subsystem:console /machine:I386 /nodefaultlib:"libc.lib" /out:"..\..\Release/phpfcgi.exe" /libpath:"..\..\Release" /libpath:"fcgi\lib"
|
||||
|
||||
!ELSEIF "$(CFG)" == "fastcgi - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "DEBUG" /D "_DEBUG" /D "_CONSOLE" /D "MSVC5" /D "PHP_WIN32" /D ZEND_DEBUG=1 /D "ZEND_WIN32" /D "WIN32" /D "_MBCS" /FR /FD /GZ /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 libfcgi.lib winmm.lib wsock32.lib netapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4nts_debug.lib /nologo /version:4.0 /subsystem:console /debug /machine:I386 /nodefaultlib:"libcd" /nodefaultlib:"libcmt" /out:"..\Debug\phpfcgi.exe" /pdbtype:sept /libpath:"..\..\Debug" /libpath:"fcgi\lib"
|
||||
|
||||
!ELSEIF "$(CFG)" == "fastcgi - Win32 Debug_TS"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "fastcgi___Win32_Debug_TS"
|
||||
# PROP BASE Intermediate_Dir "fastcgi___Win32_Debug_TS"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug_TS"
|
||||
# PROP Intermediate_Dir "Debug_TS"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "DEBUG" /D "_DEBUG" /D "_CONSOLE" /D "MSVC5" /D "PHP_WIN32" /D ZEND_DEBUG=1 /D "ZEND_WIN32" /D "WIN32" /D "_MBCS" /FR /FD /GZ /c
|
||||
# SUBTRACT BASE CPP /YX
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "DEBUG" /D "_DEBUG" /D "_CONSOLE" /D "MSVC5" /D "PHP_WIN32" /D "ZTS" /D ZEND_DEBUG=1 /D "ZEND_WIN32" /D "WIN32" /D "_MBCS" /FR /FD /GZ /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 libfcgi.lib winmm.lib wsock32.lib netapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4nts_debug.lib /nologo /version:4.0 /subsystem:console /debug /machine:I386 /nodefaultlib:"libcd" /nodefaultlib:"libcmt" /out:"c:\php-fcgi\php-fcgi.exe" /pdbtype:sept /libpath:"..\..\Debug" /libpath:"fcgi\lib"
|
||||
# ADD LINK32 libfcgi.lib winmm.lib wsock32.lib netapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts_debug.lib /nologo /version:4.0 /subsystem:console /debug /machine:I386 /nodefaultlib:"libcd" /nodefaultlib:"libcmt" /out:"..\..\Debug_TS\phpfcgi.exe" /pdbtype:sept /libpath:"..\..\Debug_TS" /libpath:"fcgi\lib"
|
||||
|
||||
!ELSEIF "$(CFG)" == "fastcgi - Win32 Release_TS"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "fastcgi___Win32_Release_TS"
|
||||
# PROP BASE Intermediate_Dir "fastcgi___Win32_Release_TS"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release_TS"
|
||||
# PROP Intermediate_Dir "Release_TS"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "NDEBUG" /D "_CONSOLE" /D ZEND_DEBUG=0 /D "MSVC5" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32" /D "PHP_WIN32" /Fr /FD /c
|
||||
# SUBTRACT BASE CPP /YX
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "NDEBUG" /D "_CONSOLE" /D ZEND_DEBUG=0 /D "MSVC5" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "ZTS" /Fr /FD /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 php4nts.lib libfcgi.lib winmm.lib wsock32.lib netapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /version:4.0 /subsystem:console /machine:I386 /nodefaultlib:"libc.lib" /out:"..\..\Release/php-fcgi.exe" /libpath:"..\..\Release" /libpath:"fcgi\lib"
|
||||
# ADD LINK32 php4ts.lib libfcgi.lib winmm.lib wsock32.lib netapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /version:4.0 /subsystem:console /machine:I386 /nodefaultlib:"libc.lib" /out:"..\..\Release_TS/phpfcgi.exe" /libpath:"..\..\Release_TS" /libpath:"fcgi\lib"
|
||||
|
||||
!ELSEIF "$(CFG)" == "fastcgi - Win32 Release_TS_inline"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "fastcgi___Win32_Release_TS_inline"
|
||||
# PROP BASE Intermediate_Dir "fastcgi___Win32_Release_TS_inline"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release_TS_inline"
|
||||
# PROP Intermediate_Dir "Release_TS_inline"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "NDEBUG" /D "_CONSOLE" /D ZEND_DEBUG=0 /D "MSVC5" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "ZTS" /Fr /FD /c
|
||||
# SUBTRACT BASE CPP /YX
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "NDEBUG" /D "_CONSOLE" /D "ZEND_WIN32_FORCE_INLINE" /D ZEND_DEBUG=0 /D "MSVC5" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "ZTS" /Fr /FD /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 php4ts.lib libfcgi.lib winmm.lib wsock32.lib netapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /version:4.0 /subsystem:console /machine:I386 /nodefaultlib:"libc.lib" /out:"..\..\Release_TS/phpfcgi.exe" /libpath:"..\..\Release_TS" /libpath:"fcgi\lib"
|
||||
# ADD LINK32 php4ts.lib libfcgi.lib winmm.lib wsock32.lib netapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /version:4.0 /subsystem:console /machine:I386 /nodefaultlib:"libc.lib" /out:"..\..\Release_TS_inline/phpfcgi.exe" /libpath:"..\..\Release_TS_inline" /libpath:"fcgi\lib"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "fastcgi - Win32 Release"
|
||||
# Name "fastcgi - Win32 Debug"
|
||||
# Name "fastcgi - Win32 Debug_TS"
|
||||
# Name "fastcgi - Win32 Release_TS"
|
||||
# Name "fastcgi - Win32 Release_TS_inline"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\fastcgi.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\php_fastcgi.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
File renamed without changes.
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2002 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.02 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available at through the world-wide-web at |
|
||||
| http://www.php.net/license/2_02.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. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Sascha Schumann <sascha@schumann.cx> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifndef PHP_FASTCGI_H
|
||||
#define PHP_FASTCGI_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
void fastcgi_php_shutdown(void);
|
||||
void fastcgi_php_init(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
Windows support is currently experimental.
|
||||
|
||||
Tested under IIS with cgi-fcgi.exe and Apache with mod_fastcgi.
|
||||
|
||||
Compilation:
|
||||
Currently only supports Non-Thread safe compilation, however,
|
||||
that is realy all that is needed :)
|
||||
|
||||
Get the devkit from www.fastcgi.com, build it.
|
||||
Create the directories
|
||||
php4/sapi/fastcgi/fcgi
|
||||
php4/sapi/fastcgi/fcgi/include
|
||||
php4/sapi/fastcgi/fcgi/lib
|
||||
Place headers and libs in the include and lib directories.
|
||||
Load the php.dsw, and compile.
|
||||
|
||||
IIS configuration:
|
||||
|
||||
Under the application configuration in the IIS configuration program, use:
|
||||
.php C:\php-fcgi\cgi-fcgi.exe -connect php c:\php-fcgi\php-fcgi.exe
|
||||
|
||||
Apache Configuration:
|
||||
|
||||
LoadModule fastcgi_module modules/mod_fastcgi.dll
|
||||
<IfModule mod_fastcgi.c>
|
||||
AddHandler fastcgi-script fphp php
|
||||
</IfModule>
|
||||
|
||||
The scripts require the bang line as the first line
|
||||
of the script to work with mod_fastcgi,
|
||||
#!c:/php-fcgi/php-fcgi.exe
|
||||
|
||||
TODO:
|
||||
make 'thread-safe' compilation, though it isn't necessary.
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fhttpd
|
||||
Alex Belits
|
||||
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2002 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.02 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available at through the world-wide-web at |
|
||||
| http://www.php.net/license/2_02.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. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Alex Belits <abelits@phobos.illtel.denver.co.us> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
#include "php.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if FHTTPD
|
||||
#include <servproc.h>
|
||||
#include <signal.h>
|
||||
|
||||
struct http_server *server = NULL;
|
||||
struct request *req = NULL;
|
||||
struct httpresponse *response = NULL;
|
||||
int headermade = 0;
|
||||
int global_alarmflag = 0;
|
||||
int idle_timeout = IDLE_TIMEOUT;
|
||||
int exit_status = 0;
|
||||
char **currentheader = NULL;
|
||||
char *headerfirstline = NULL;
|
||||
int headerlines = 0;
|
||||
static int headerlinesallocated = 0;
|
||||
|
||||
void alarmhandler(SIGACTARGS)
|
||||
{
|
||||
global_alarmflag = 1;
|
||||
}
|
||||
|
||||
void setalarm(int t)
|
||||
{
|
||||
struct sigaction tmpsigaction;
|
||||
global_alarmflag = 0;
|
||||
if (t){
|
||||
bzero((char *) &tmpsigaction, sizeof(struct sigaction));
|
||||
tmpsigaction.sa_handler = alarmhandler;
|
||||
sigaddset(&tmpsigaction.sa_mask, SIGALRM);
|
||||
tmpsigaction.sa_flags = 0;
|
||||
sigaction(SIGALRM, &tmpsigaction, NULL);
|
||||
alarm(t);
|
||||
}
|
||||
}
|
||||
|
||||
int checkinput(int h)
|
||||
{
|
||||
fd_set readfd;
|
||||
FD_ZERO(&readfd);
|
||||
FD_SET(h, &readfd);
|
||||
return select(h + 1, &readfd, NULL, NULL, NULL) > 0;
|
||||
}
|
||||
|
||||
|
||||
PHPAPI void php_fhttpd_free_header(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (headerfirstline) {
|
||||
free(headerfirstline);
|
||||
headerfirstline = NULL;
|
||||
}
|
||||
if (currentheader) {
|
||||
for (i = 0; i < headerlines; i++) {
|
||||
free(currentheader[i]);
|
||||
}
|
||||
free(currentheader);
|
||||
currentheader = NULL;
|
||||
}
|
||||
headerlines = 0;
|
||||
headerlinesallocated = 0;
|
||||
headermade = 0;
|
||||
}
|
||||
|
||||
|
||||
PHPAPI void php_fhttpd_puts_header(char *s)
|
||||
{
|
||||
char *p0, *p1, *p2, *p3, **p;
|
||||
int l;
|
||||
|
||||
if (!s || !*s || *s == '\r' || *s == '\n')
|
||||
return;
|
||||
l = strlen(s);
|
||||
p2 = strchr(s, '\r');
|
||||
p3 = strchr(s, '\n');
|
||||
p0 = strchr(s, ':');
|
||||
p1 = strchr(s, ' ');
|
||||
if (p0 && (!p1 || p1 > p0)) {
|
||||
if (!headerlinesallocated) {
|
||||
currentheader = (char **) malloc(10 * sizeof(char *));
|
||||
if (currentheader)
|
||||
headerlinesallocated = 10;
|
||||
} else {
|
||||
if (headerlinesallocated <= headerlines) {
|
||||
p = (char **) realloc(currentheader, (headerlinesallocated + 10) * sizeof(char *));
|
||||
if (p) {
|
||||
currentheader = p;
|
||||
headerlinesallocated += 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (headerlinesallocated > headerlines) {
|
||||
currentheader[headerlines] = malloc(l + 3);
|
||||
if (currentheader[headerlines]) {
|
||||
strcpy(currentheader[headerlines], s);
|
||||
if (!p3) {
|
||||
if (p2) {
|
||||
(currentheader[headerlines] + (p2 - s))[1] = '\n';
|
||||
(currentheader[headerlines] + (p2 - s))[2] = 0;
|
||||
} else {
|
||||
currentheader[headerlines][l] = '\r';
|
||||
currentheader[headerlines][l + 1] = '\n';
|
||||
currentheader[headerlines][l + 2] = 0;
|
||||
}
|
||||
}
|
||||
headerlines++;
|
||||
headermade = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (headerfirstline)
|
||||
free(headerfirstline);
|
||||
headerfirstline = malloc(l + 3);
|
||||
if (headerfirstline) {
|
||||
strcpy(headerfirstline, s);
|
||||
if (!p3) {
|
||||
if (p2) {
|
||||
(headerfirstline + (p2 - s))[1] = '\n';
|
||||
(headerfirstline + (p2 - s))[2] = 0;
|
||||
} else {
|
||||
headerfirstline[l] = '\r';
|
||||
headerfirstline[l + 1] = '\n';
|
||||
headerfirstline[l + 2] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
headermade = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void fhttpd_flush(void)
|
||||
{
|
||||
}
|
||||
|
||||
PHPAPI void php_fhttpd_puts(char *s)
|
||||
{
|
||||
putlinetoresponse(response, s);
|
||||
}
|
||||
|
||||
PHPAPI void php_fhttpd_putc(char c)
|
||||
{
|
||||
writetoresponse(response, &c, 1);
|
||||
}
|
||||
|
||||
PHPAPI int php_fhttpd_write(char *a, int n)
|
||||
{
|
||||
return writetoresponse(response, a, n);
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# $Id$
|
||||
|
||||
dir=$1; shift
|
||||
for stubfile in $dir/*/config0.m4 $dir/*/config.m4; do
|
||||
echo "sinclude($stubfile)"
|
||||
done
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# do some automatic conversion of prototypes
|
||||
#
|
||||
|
||||
if test "$1" = "" ; then
|
||||
echo "usage: $0 list-of-files"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
tmpfile=`mktemp -q /tmp/asd.XXXXXX`
|
||||
|
||||
if test "$?" != "0" ; then
|
||||
echo "$0: cannot create temporary file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for file in ${1+"$@"} ; do
|
||||
echo "working on $file"
|
||||
cat $file | \
|
||||
sed -e \
|
||||
's/void php3_\(.*\)(INTERNAL_FUNCTION_PARAMETERS)/PHP_FUNCTION(\1)/' \
|
||||
-e 's/^extern void /void /' \
|
||||
-e 's/^extern PHP_FUNCTION/PHP_FUNCTION/' > $tmpfile
|
||||
cp $tmpfile $file
|
||||
done
|
||||
|
||||
rm -f $tmpfile
|
||||
|
||||
exit 0
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# +----------------------------------------------------------------------+
|
||||
# | PHP Version 4 |
|
||||
# +----------------------------------------------------------------------+
|
||||
# | Copyright (c) 1997-2002 The PHP Group |
|
||||
# +----------------------------------------------------------------------+
|
||||
# | This source file is subject to version 2.02 of the PHP license, |
|
||||
# | that is bundled with this package in the file LICENSE, and is |
|
||||
# | available at through the world-wide-web at |
|
||||
# | http://www.php.net/license/2_02.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. |
|
||||
# +----------------------------------------------------------------------+
|
||||
# | Author: Sascha Schumann <sascha@schumann.cx> |
|
||||
# +----------------------------------------------------------------------+
|
||||
#
|
||||
# $Id$
|
||||
|
||||
for i in $@; do
|
||||
echo -n "Processing $i... "
|
||||
sed \
|
||||
-e 's/(\*\([^()]\+\))->type/Z_TYPE_PP(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)->type/Z_TYPE_P(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)\.type/Z_TYPE(\1)/g' \
|
||||
-e 's/(\*\([^()]\+\))->value\.dval/Z_DVAL_PP(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)->value\.dval/Z_DVAL_P(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)\.value\.dval/Z_DVAL(\1)/g' \
|
||||
-e 's/(\*\([^()]\+\))->value\.lval/Z_LVAL_PP(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)->value\.lval/Z_LVAL_P(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)\.value\.lval/Z_LVAL(\1)/g' \
|
||||
-e 's/(\*\([^()]\+\))->value\.ht/Z_ARRVAL_PP(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)->value\.ht/Z_ARRVAL_P(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)\.value\.ht/Z_ARRVAL(\1)/g' \
|
||||
-e 's/(\*\([^()]\+\))->value\.str\.val/Z_STRVAL_PP(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)->value\.str\.val/Z_STRVAL_P(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)\.value\.str\.val/Z_STRVAL(\1)/g' \
|
||||
-e 's/(\*\([^()]\+\))->value\.str\.len/Z_STRLEN_PP(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)->value\.str\.len/Z_STRLEN_P(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)\.value\.str\.len/Z_STRLEN(\1)/g' \
|
||||
-e 's/(\*\([^()]\+\))->value\.obj\.properties/Z_OBJPROP_PP(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)->value\.obj\.properties/Z_OBJPROP_P(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)\.value\.obj\.properties/Z_OBJPROP(\1)/g' \
|
||||
-e 's/(\*\([^()]\+\))->value\.obj\.ce/Z_OBJCE_PP(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)->value\.obj\.ce/Z_OBJCE_P(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)\.value\.obj\.ce/Z_OBJCE(\1)/g' \
|
||||
-e 's/(\*\([^()]\+\))->value\.obj/Z_OBJ_PP(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)->value\.obj/Z_OBJ_P(\1)/g' \
|
||||
-e 's/\([a-z_][]a-z_0-9\[]*\)\.value\.obj/Z_OBJ(\1)/g' \
|
||||
-e 's/\([a-zA-Z_][a-zA-Z_0-9]*\)->Z_\([A-Z_]\+\)(/Z_\2(\1->/g' \
|
||||
-e 's/\([a-zA-Z_][a-zA-Z_0-9]*\)->Z_\([A-Z_]\+\)(/Z_\2(\1->/g' \
|
||||
-e 's/\([a-zA-Z_][a-zA-Z_0-9]*\)->Z_\([A-Z_]\+\)(/Z_\2(\1->/g' \
|
||||
-e 's/\([a-zA-Z_][a-zA-Z_0-9]*\)\.Z_\([A-Z_]\+\)(/Z_\2(\1./g' \
|
||||
-e 's/\([a-zA-Z_][a-zA-Z_0-9]*\)\.Z_\([A-Z_]\+\)(/Z_\2(\1./g' \
|
||||
-e 's/\([a-zA-Z_][a-zA-Z_0-9]*\)\.Z_\([A-Z_]\+\)(/Z_\2(\1./g' \
|
||||
< $i > tmp && cp tmp $i
|
||||
echo "DONE"
|
||||
done
|
||||
|
||||
rm -f tmp
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
awkprog='
|
||||
BEGIN { FS = "\n"; RS = "" }
|
||||
{ print "CREDIT_LINE(\""$1"\", \""$2"\");" }'
|
||||
|
||||
for what in ext sapi
|
||||
do
|
||||
file=ext/standard/credits_$what.h
|
||||
cat >$file <<END
|
||||
/*
|
||||
DO NOT EDIT THIS FILE!
|
||||
|
||||
it has been automaticaly created by php4/scripts/credits from
|
||||
the information found in the various php4/ext/.../CREDITS and
|
||||
php4/sapi/.../CREDITS files
|
||||
|
||||
if you want to change an entry you have to edit the appropriate
|
||||
CREDITS file instead
|
||||
|
||||
*/
|
||||
|
||||
END
|
||||
# Do not process skeleton #
|
||||
files=`find "$what" -name CREDITS | grep -v "$what"/skeleton/CREDITS`
|
||||
awk "$awkprog" $files | sort -f >> $file
|
||||
done
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
PHP Regression Tests
|
||||
====================
|
||||
|
||||
To run the tests, go to the top-level directory and
|
||||
run "./php -q run-tests.php".
|
||||
|
||||
Without parameters, "run-tests.php" will recursively scan through the
|
||||
file tree looking for directories called "tests", and run all the
|
||||
tests (.phpt files) within (recursively).
|
||||
|
||||
To run tests in a single directory, pass the directory as a parameter:
|
||||
"./php -q run-tests.php tests/lang".
|
||||
|
||||
To run one or more single tests, pass them as parameters:
|
||||
"./php -q run-tests.php tests/lang/015.phpt".
|
||||
|
||||
The format of the .phpt files is quite simple. There are 6 possible
|
||||
sections. Test, Skipif, Post, Get, File and Expect. The Test section
|
||||
contains the description of the test. The Skipif section contains
|
||||
code that should print "skip" if this test should be skipped for some
|
||||
reason (such as an extension that is not compiled in). The Post
|
||||
section contains any post data that the script might need. The Get
|
||||
section contains any Get data. Note that both the Post and the Get
|
||||
sections need to have this data in url-encoded format. The File
|
||||
section contains the actual script and the Expect section is the
|
||||
expected output, sans headers. Blank lines are ignored in the
|
||||
expected output.
|
||||
|
||||
A simple example which takes one argument through the POST method
|
||||
and one through the GET and displays these would be:
|
||||
|
||||
--TEST--
|
||||
Simple GET and POST test
|
||||
--SKIPIF--
|
||||
--POST--
|
||||
a=Hello
|
||||
--GET--
|
||||
b=There
|
||||
--FILE--
|
||||
<?php echo "$a $b">
|
||||
--EXPECT--
|
||||
Hello There
|
||||
|
||||
Another simple example that only runs if the PCRE extension is loaded:
|
||||
|
||||
--TEST--
|
||||
Simple Perl regexp test
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("pcre")) print "skip"; ?>
|
||||
--POST--
|
||||
--GET--
|
||||
--FILE--
|
||||
<?php
|
||||
$str="Hello 42 World";
|
||||
if (pcre_match('/^([a-z]+)\s+(\d+)\s+([a-z]+)/i', $str, $matches)) {
|
||||
printf("%s %s: %d\n", $matches[1], $matches[3], $matches[2]);
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Hello World: 42
|
||||
@@ -0,0 +1,30 @@
|
||||
--TEST--
|
||||
dirname test
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function check_dirname($path)
|
||||
{
|
||||
print "dirname($path) == " . dirname($path) . "\n";
|
||||
}
|
||||
|
||||
check_dirname("/foo/");
|
||||
check_dirname("/foo");
|
||||
check_dirname("/foo/bar");
|
||||
check_dirname("d:\\foo\\bar.inc");
|
||||
check_dirname("/");
|
||||
check_dirname(".../foo");
|
||||
check_dirname("./foo");
|
||||
check_dirname("foobar///");
|
||||
check_dirname("c:\foo");
|
||||
?>
|
||||
--EXPECT--
|
||||
dirname(/foo/) == /
|
||||
dirname(/foo) == /
|
||||
dirname(/foo/bar) == /foo
|
||||
dirname(d:\foo\bar.inc) == .
|
||||
dirname(/) == /
|
||||
dirname(.../foo) == ...
|
||||
dirname(./foo) == .
|
||||
dirname(foobar///) == .
|
||||
dirname(c:\foo) == .
|
||||
Reference in new issue
Block a user