e4f35acf7c
representing the interface for, well, MIME sniffer add-ons. * Implemented the respective add-on manager and make use of it in the MIME database code. Unfortunately the MIME DB code completely lives in libbe.so and hence I had to put my code there too. IMHO we should (one day) remove the direct (read-only) MIME DB access from libbe and move everything into the registrar. Currently the add-on manager supports built-in add-ons only; it doesn't really load anything from disk ATM. * Added a built-in text sniffer add-on to the registrar. It's based upon the BSD file tool code. This closes bug #250 (plain text files are identified as such, now). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17784 a95241bf-73f2-0310-859d-f6bbb57e9c96
68 lines
1.6 KiB
C++
68 lines
1.6 KiB
C++
//----------------------------------------------------------------------
|
|
// This software is part of the OpenBeOS distribution and is covered
|
|
// by the OpenBeOS license.
|
|
//---------------------------------------------------------------------
|
|
/*!
|
|
\file SnifferRules.h
|
|
SnifferRules class declarations
|
|
*/
|
|
|
|
#ifndef _MIME_SNIFFER_RULES_H
|
|
#define _MIME_SNIFFER_RULES_H
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
#include <list>
|
|
#include <string>
|
|
|
|
struct entry_ref;
|
|
class BString;
|
|
|
|
namespace BPrivate {
|
|
namespace Storage {
|
|
|
|
namespace Sniffer {
|
|
class Rule;
|
|
}
|
|
|
|
namespace Mime {
|
|
|
|
class SnifferRules {
|
|
public:
|
|
SnifferRules();
|
|
~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();
|
|
};
|
|
private:
|
|
status_t BuildRuleList();
|
|
status_t GuessMimeType(BFile* file, const void *buffer, int32 length,
|
|
BString *type);
|
|
ssize_t MaxBytesNeeded();
|
|
status_t ProcessType(const char *type, ssize_t *bytesNeeded);
|
|
|
|
std::list<sniffer_rule> fRuleList;
|
|
ssize_t fMaxBytesNeeded;
|
|
bool fHaveDoneFullBuild;
|
|
};
|
|
|
|
} // namespace Mime
|
|
} // namespace Storage
|
|
} // namespace BPrivate
|
|
|
|
#endif // _MIME_SNIFFER_H
|