1 //---------------------------------------------------------------------- 2 // This software is part of the OpenBeOS distribution and is covered 3 // by the OpenBeOS license. 4 //--------------------------------------------------------------------- 5 /*! 6 \file SnifferRules.h 7 SnifferRules class declarations 8 */ 9 10 #ifndef _MIME_SNIFFER_RULES_H 11 #define _MIME_SNIFFER_RULES_H 12 13 #include <SupportDefs.h> 14 15 #include <list> 16 #include <string> 17 18 struct entry_ref; 19 class BString; 20 21 namespace BPrivate { 22 namespace Storage { 23 24 namespace Sniffer { 25 class Rule; 26 } 27 28 namespace Mime { 29 30 class SnifferRules { 31 public: 32 SnifferRules(); 33 ~SnifferRules(); 34 35 status_t GuessMimeType(const entry_ref *ref, BString *type); 36 status_t GuessMimeType(const void *buffer, int32 length, BString *type); 37 38 status_t SetSnifferRule(const char *type, const char *rule); 39 status_t DeleteSnifferRule(const char *type); 40 41 void PrintToStream() const; 42 private: 43 status_t BuildRuleList(); 44 status_t GuessMimeType(BPositionIO *data, BString *type); 45 ssize_t MaxBytesNeeded(); 46 status_t ProcessType(const char *type, ssize_t *bytesNeeded); 47 48 struct sniffer_rule { 49 std::string type; // The mime type that own the rule 50 std::string rule_string; // The unparsed string version of the rule 51 BPrivate::Storage::Sniffer::Rule *rule; // The parsed rule 52 53 sniffer_rule(BPrivate::Storage::Sniffer::Rule *rule = NULL); 54 ~sniffer_rule(); 55 }; 56 57 std::list<sniffer_rule> fRuleList; 58 ssize_t fMaxBytesNeeded; 59 bool fHaveDoneFullBuild; 60 }; 61 62 } // namespace Mime 63 } // namespace Storage 64 } // namespace BPrivate 65 66 #endif // _MIME_SNIFFER_H 67