xref: /haiku/headers/private/storage/mime/SnifferRules.h (revision d9cebac2b77547b7064f22497514eecd2d047160)
1 /*
2  * Copyright 2002-2007, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _MIME_SNIFFER_RULES_H
6 #define _MIME_SNIFFER_RULES_H
7 
8 
9 #include <SupportDefs.h>
10 
11 #include <list>
12 #include <string>
13 
14 class BFile;
15 class BString;
16 struct entry_ref;
17 
18 
19 namespace BPrivate {
20 namespace Storage {
21 
22 namespace Sniffer {
23 	class Rule;
24 }
25 
26 namespace Mime {
27 
28 class SnifferRules {
29 public:
30 	SnifferRules();
31 	~SnifferRules();
32 
33 	status_t GuessMimeType(const entry_ref *ref, BString *type);
34 	status_t GuessMimeType(const void *buffer, int32 length, BString *type);
35 
36 	status_t SetSnifferRule(const char *type, const char *rule);
37 	status_t DeleteSnifferRule(const char *type);
38 
39 	void PrintToStream() const;
40 
41 	struct sniffer_rule {
42 		std::string type;							// The mime type that own the rule
43 		std::string rule_string;					// The unparsed string version of the rule
44 		BPrivate::Storage::Sniffer::Rule *rule;		// The parsed rule
45 
46 		sniffer_rule(BPrivate::Storage::Sniffer::Rule *rule = NULL);
47 		~sniffer_rule();
48 	};
49 private:
50 	status_t BuildRuleList();
51 	status_t GuessMimeType(BFile* file, const void *buffer, int32 length,
52 		BString *type);
53 	ssize_t MaxBytesNeeded();
54 	status_t ProcessType(const char *type, ssize_t *bytesNeeded);
55 
56 	std::list<sniffer_rule> fRuleList;
57 	ssize_t fMaxBytesNeeded;
58 	bool fHaveDoneFullBuild;
59 };
60 
61 } // namespace Mime
62 } // namespace Storage
63 } // namespace BPrivate
64 
65 #endif	// _MIME_SNIFFER_H
66