Advertisement
Guest User

BeOS R5 Releasenote Sniffer Rule

a guest
Mar 3rd, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. GetSnifferRule() , SetSnifferRule() , CheckSnifferRule()
  2.  
  3.  
  4.  
  5.  
  6. status_t GetSnifferRule(BString *result) const
  7.  
  8. status_t SetSnifferRule(const char *rule)
  9.  
  10. static status_t CheckSnifferRule(const char *rule, BString *parseError)
  11.  
  12. 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:
  13.  
  14. rating [begin:end] ( [begin:end] 'pattern1' | [begin:end] 'pattern2' | ... )
  15.  
  16. * 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.
  17.  
  18. * [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.
  19.  
  20. * '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.
  21.  
  22. If no byte range declaration is provided, [0:0] is assumed—i.e. the pattern(s) must start at the first byte.
  23.  
  24. For example, the following rule strings says that the content of an examined file must begin with the characters 'ABCD':
  25.  
  26. "1.0 ('ABCD')"
  27.  
  28. This rule says that the content must contain the characters 'ABCD' or 'abcd' starting somewhere in the first three bytes:
  29.  
  30. "1.0 [0:3] ('ABCD' | 'abcd')"
  31.  
  32. Here the content must contain 'ABCD' or 'abcd' starting in the first three bytes, or it must contain 'EFGH' starting at byte 13:
  33.  
  34. "1.0 [0:3] ('ABCD' | 'abcd' | [13] 'EFGH')"
  35.  
  36. 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.
  37.  
  38. B_SNIFFER_RULE_CHANGED
  39.  
  40.  
  41.  
  42.  
  43. enum { ... B_SNIFFER_RULE_CHANGED, ... };
  44.  
  45. 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.
  46.  
  47. GuessMimeType()
  48.  
  49.  
  50.  
  51.  
  52. static status_t GuessMimeType(const entry_ref *file, BMimeType *result)
  53.  
  54. static status_t GuessMimeType(const void *buffer, int32 length, BMimeType *result)
  55.  
  56. static status_t GuessMimeType(const char *filename, BMimeType *result)
  57.  
  58. 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