2007-10-16 00:13:55 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2002-2007, Haiku, Inc. All Rights Reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-09-24 09:22:40 +04:00
|
|
|
#ifndef _MIME_SNIFFER_RULES_H
|
|
|
|
#define _MIME_SNIFFER_RULES_H
|
|
|
|
|
2007-10-16 00:13:55 +04:00
|
|
|
|
2002-09-24 09:22:40 +04:00
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
|
2007-10-16 00:13:55 +04:00
|
|
|
class BFile;
|
2002-09-24 09:22:40 +04:00
|
|
|
class BString;
|
2007-10-16 00:13:55 +04:00
|
|
|
struct entry_ref;
|
|
|
|
|
2002-09-24 09:22:40 +04:00
|
|
|
|
|
|
|
namespace BPrivate {
|
|
|
|
namespace Storage {
|
|
|
|
|
|
|
|
namespace Sniffer {
|
|
|
|
class Rule;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Mime {
|
|
|
|
|
2013-05-08 01:15:36 +04:00
|
|
|
|
|
|
|
class DatabaseLocation;
|
2013-05-07 19:54:29 +04:00
|
|
|
class MimeSniffer;
|
|
|
|
|
|
|
|
|
2002-09-24 09:22:40 +04:00
|
|
|
class SnifferRules {
|
|
|
|
public:
|
2013-05-08 01:15:36 +04:00
|
|
|
SnifferRules(DatabaseLocation* databaseLocation, MimeSniffer* mimeSniffer);
|
2002-09-24 09:22:40 +04:00
|
|
|
~SnifferRules();
|
|
|
|
|
|
|
|
status_t GuessMimeType(const entry_ref *ref, BString *type);
|
|
|
|
status_t GuessMimeType(const void *buffer, int32 length, BString *type);
|
|
|
|
|
|
|
|
status_t SetSnifferRule(const char *type, const char *rule);
|
|
|
|
status_t DeleteSnifferRule(const char *type);
|
|
|
|
|
|
|
|
void PrintToStream() const;
|
|
|
|
|
|
|
|
struct sniffer_rule {
|
|
|
|
std::string type; // The mime type that own the rule
|
|
|
|
std::string rule_string; // The unparsed string version of the rule
|
|
|
|
BPrivate::Storage::Sniffer::Rule *rule; // The parsed rule
|
|
|
|
|
|
|
|
sniffer_rule(BPrivate::Storage::Sniffer::Rule *rule = NULL);
|
|
|
|
~sniffer_rule();
|
|
|
|
};
|
2003-08-04 04:46:53 +04:00
|
|
|
private:
|
|
|
|
status_t BuildRuleList();
|
2006-06-10 00:48:50 +04:00
|
|
|
status_t GuessMimeType(BFile* file, const void *buffer, int32 length,
|
|
|
|
BString *type);
|
2003-08-04 04:46:53 +04:00
|
|
|
ssize_t MaxBytesNeeded();
|
|
|
|
status_t ProcessType(const char *type, ssize_t *bytesNeeded);
|
2002-09-24 09:22:40 +04:00
|
|
|
|
|
|
|
std::list<sniffer_rule> fRuleList;
|
2013-05-07 19:54:29 +04:00
|
|
|
|
|
|
|
private:
|
2013-05-08 01:15:36 +04:00
|
|
|
DatabaseLocation* fDatabaseLocation;
|
|
|
|
MimeSniffer* fMimeSniffer;
|
|
|
|
ssize_t fMaxBytesNeeded;
|
|
|
|
bool fHaveDoneFullBuild;
|
2002-09-24 09:22:40 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Mime
|
|
|
|
} // namespace Storage
|
|
|
|
} // namespace BPrivate
|
|
|
|
|
|
|
|
#endif // _MIME_SNIFFER_H
|