Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GetSnifferRule() , SetSnifferRule() , CheckSnifferRule()
- status_t GetSnifferRule(BString *result) const
- status_t SetSnifferRule(const char *rule)
- static status_t CheckSnifferRule(const char *rule, BString *parseError)
- GetSnifferRule() and SetSnifferRule() get and set the pattern-matching rule that the file type sniffer uses to detect the MIME type represented by this object. The sniffer rule is a string that follows this format:
- rating [begin:end] ( [begin:end] 'pattern1' | [begin:end] 'pattern2' | ... )
- * rating is a mandatory float between 0.0 and 1.0 that describes the priority of the rule, compared to other rules for the same type.
- * [begin:end] is the optional "global byte range" declaration. The sniffer will look for a matching pattern that begins within this range of data. The [begin:end] that appears outside the parenthesis (i.e. just after rating) applies to all the patterns for this rule. If a pattern must begin at a particular byte offset, you can exclude the ":end" declaration.
- * 'pattern1', 'pattern2', etc. These are the patterns themselves. You can OR patterns with the "|" operator. (You can't AND patterns.) An immediately preceding byte range declaration applies to the following pattern (only), and overrides the global byte range declaration.
- If no byte range declaration is provided, [0:0] is assumed—i.e. the pattern(s) must start at the first byte.
- For example, the following rule strings says that the content of an examined file must begin with the characters 'ABCD':
- "1.0 ('ABCD')"
- This rule says that the content must contain the characters 'ABCD' or 'abcd' starting somewhere in the first three bytes:
- "1.0 [0:3] ('ABCD' | 'abcd')"
- Here the content must contain 'ABCD' or 'abcd' starting in the first three bytes, or it must contain 'EFGH' starting at byte 13:
- "1.0 [0:3] ('ABCD' | 'abcd' | [13] 'EFGH')"
- The CheckSnifferRule() function is a debugging tool that checks your sniffer rule (independent of MIME type) and returns a string that describes the error. If the rule is correct, you get back (in result) a string that says "rule is correct". Otherwise, the result string contains an error message with a pointer to the offending part of the rule. The string is meant to be viewed in a monospace font.
- B_SNIFFER_RULE_CHANGED
- enum { ... B_SNIFFER_RULE_CHANGED, ... };
- B_SNIFFER_RULE_CHANGED is a new MIME database-watching bit vector value. If your application has called BMimeType::StartWatching() and someone changes a sniffer rule, your target will receive a B_META_MIME_CHANGED message that has, as in its "be:which" field, the value B_SNIFFER_RULE_CHANGED.
- GuessMimeType()
- static status_t GuessMimeType(const entry_ref *file, BMimeType *result)
- static status_t GuessMimeType(const void *buffer, int32 length, BMimeType *result)
- static status_t GuessMimeType(const char *filename, BMimeType *result)
- These new class functions ask the sniffer to identify the MIME type of a file or data. result must be allocated before it's passed in.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement