xref: /haiku/headers/private/storage/mime/SnifferRules.h (revision 3cb015b1ee509d69c643506e8ff573808c86dcfc)
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 
43 	struct sniffer_rule {
44 		std::string type;							// The mime type that own the rule
45 		std::string rule_string;					// The unparsed string version of the rule
46 		BPrivate::Storage::Sniffer::Rule *rule;		// The parsed rule
47 
48 		sniffer_rule(BPrivate::Storage::Sniffer::Rule *rule = NULL);
49 		~sniffer_rule();
50 	};
51 private:
52 	status_t BuildRuleList();
53 	status_t GuessMimeType(BFile* file, const void *buffer, int32 length,
54 		BString *type);
55 	ssize_t MaxBytesNeeded();
56 	status_t ProcessType(const char *type, ssize_t *bytesNeeded);
57 
58 	std::list<sniffer_rule> fRuleList;
59 	ssize_t fMaxBytesNeeded;
60 	bool fHaveDoneFullBuild;
61 };
62 
63 } // namespace Mime
64 } // namespace Storage
65 } // namespace BPrivate
66 
67 #endif	// _MIME_SNIFFER_H
68