| Copyright | Copyright (C) 2005 John Goerzen |
|---|---|
| License | BSD-3-Clause |
| Maintainer | Philippe <philippedev101\@gmail.com> |
| Stability | provisional |
| Portability | portable |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Magic.Types
Description
The core types of the binding: the opaque Magic handle, the MagicFlag
enumeration (re-exported from Magic.Data) and the MagicParam tunables.
Written by John Goerzen.
Synopsis
- type Magic = ForeignPtr CMagic
- data CMagic
- data MagicFlag
- = MagicNone
- | MagicDebug
- | MagicSymlink
- | MagicCompress
- | MagicDevices
- | MagicMimeType
- | MagicMimeEncoding
- | MagicMime
- | MagicContinue
- | MagicCheck
- | MagicPreserveAtime
- | MagicRaw
- | MagicError
- | MagicApple
- | MagicExtension
- | MagicCompressTransp
- | MagicNoCompressFork
- | MagicNodesc
- | MagicNoCheckCompress
- | MagicNoCheckTar
- | MagicNoCheckSoft
- | MagicNoCheckApptype
- | MagicNoCheckElf
- | MagicNoCheckText
- | MagicNoCheckCdf
- | MagicNoCheckCsv
- | MagicNoCheckTokens
- | MagicNoCheckEncoding
- | MagicNoCheckJson
- | MagicNoCheckSimh
- | MagicNoCheckBuiltin
- | UnknownMagicFlag Int
- data MagicParam
Documentation
type Magic = ForeignPtr CMagic Source #
The magic handle: an opaque cookie obtained from magicOpen and passed to
the loading and querying functions.
Handles are closed (and their memory freed) automatically when they are garbage-collected by Haskell. There is no need to close them explicitly.
Thread safety. A single Magic handle is not safe for concurrent use:
the underlying libmagic cookie keeps mutable state, so calling operations on
the same handle from multiple threads at once is a data race. Use one handle
per thread, or serialise access to a shared handle (e.g. behind an MVar).
Distinct handles are independent and may be used concurrently. Programs doing
blocking work (loading databases, examining files) should also be built with
the threaded runtime (-threaded).
Phantom type standing in for the C magic_t cookie. It appears only as the
argument of a ForeignPtr (the Magic handle) and has no
values of its own.
Flags that control how libmagic examines a file and what it
reports. Combine them in the list passed to magicOpen or
magicSetFlags.
Constructors
| MagicNone | No special handling; return a textual description (the default). |
| MagicDebug | Print debugging messages to stderr. |
| MagicSymlink | Follow symbolic links. |
| MagicCompress | Look inside compressed files. |
| MagicDevices | Look at the contents of block or character special devices. |
| MagicMimeType | Return a MIME type string instead of a textual description. |
| MagicMimeEncoding | Return the MIME encoding (character set) instead of a textual description. |
| MagicMime | Return both the MIME type and the encoding. |
| MagicContinue | Return all matches, not just the first. |
| MagicCheck | Check the magic database for consistency and report problems. |
| MagicPreserveAtime | Preserve the access time of examined files. |
| MagicRaw | Do not translate unprintable characters to octal escapes. |
| MagicError | Treat errors while examining a file as real errors instead of embedding them in the result. |
| MagicApple | Return the Apple creator and type. |
| MagicExtension | Return a slash-separated list of valid file extensions for the detected type. |
| MagicCompressTransp | Report on the compressed contents only, without mentioning the compression itself (transparent decompression). |
| MagicNoCompressFork | Do not allow decompression that requires forking a helper process. |
| MagicNodesc | Composite of |
| MagicNoCheckCompress | Do not look inside compressed files. |
| MagicNoCheckTar | Do not examine tar archives. |
| MagicNoCheckSoft | Do not consult the magic database entries (soft magic). |
| MagicNoCheckApptype | Do not check for an application type (e.g. EMX). |
| MagicNoCheckElf | Do not examine ELF details. |
| MagicNoCheckText | Do not examine text files. |
| MagicNoCheckCdf | Do not examine CDF (Microsoft Compound Document) files. |
| MagicNoCheckCsv | Do not examine CSV files. |
| MagicNoCheckTokens | Do not look for known text tokens. |
| MagicNoCheckEncoding | Do not check text encodings. |
| MagicNoCheckJson | Do not examine JSON files. |
| MagicNoCheckSimh | Do not examine SIMH tape files. |
| MagicNoCheckBuiltin | Disable all built-in tests; consult only the magic database. |
| UnknownMagicFlag Int | A flag value returned by libmagic that these bindings do not recognise, carrying its raw integer value. |
Instances
| Enum MagicFlag Source # | |
| Show MagicFlag Source # | |
| Eq MagicFlag Source # | |
| Ord MagicFlag Source # | |
Defined in Magic.Data | |
data MagicParam Source #
Tunable limits that bound how hard libmagic works when examining data,
read and written with magicGetParam and magicSetParam (see
Magic.Operations). Lowering these (especially MagicParamBytesMax) is a way
to cap the effort spent on untrusted input. Defaults below are those documented
for libmagic 5.45.
Since: 1.1.2
Constructors
| MagicParamIndirMax | Maximum number of levels of recursion when following indirect magic. (Default: 15.) |
| MagicParamNameMax | Maximum length of a name used by name/use magic. (Default: 30.) |
| MagicParamElfPhnumMax | Maximum number of ELF program header sections processed. (Default: 128.) |
| MagicParamElfShnumMax | Maximum number of ELF section header sections processed. (Default: 32768.) |
| MagicParamElfNotesMax | Maximum number of ELF notes processed. (Default: 256.) |
| MagicParamRegexMax | Maximum length of a regex search. (Default: 8192.) |
| MagicParamBytesMax | Maximum number of bytes read from a file before giving up. (Default: 1048576, i.e. 1 MiB.) |
| MagicParamEncodingMax | Maximum number of bytes scanned when guessing a text encoding. |
| MagicParamElfShsizeMax | Maximum size of an ELF section processed. |
Instances
| Bounded MagicParam Source # | |
Defined in Magic.Types | |
| Enum MagicParam Source # | |
Defined in Magic.Types Methods succ :: MagicParam -> MagicParam pred :: MagicParam -> MagicParam toEnum :: Int -> MagicParam fromEnum :: MagicParam -> Int enumFrom :: MagicParam -> [MagicParam] enumFromThen :: MagicParam -> MagicParam -> [MagicParam] enumFromTo :: MagicParam -> MagicParam -> [MagicParam] enumFromThenTo :: MagicParam -> MagicParam -> MagicParam -> [MagicParam] | |
| Show MagicParam Source # | |
Defined in Magic.Types Methods showsPrec :: Int -> MagicParam -> ShowS show :: MagicParam -> String showList :: [MagicParam] -> ShowS | |
| Eq MagicParam Source # | |
Defined in Magic.Types | |
| Ord MagicParam Source # | |
Defined in Magic.Types Methods compare :: MagicParam -> MagicParam -> Ordering (<) :: MagicParam -> MagicParam -> Bool (<=) :: MagicParam -> MagicParam -> Bool (>) :: MagicParam -> MagicParam -> Bool (>=) :: MagicParam -> MagicParam -> Bool max :: MagicParam -> MagicParam -> MagicParam min :: MagicParam -> MagicParam -> MagicParam | |