* Added new (currently private) API class BMimeSnifferAddon,
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
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/* MIME Sniffer Add-On Protocol
|
||||
*
|
||||
* Copyright 2006, Haiku Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _MIME_SNIFFER_ADDON_H
|
||||
#define _MIME_SNIFFER_ADDON_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
class BFile;
|
||||
class BMimeType;
|
||||
|
||||
// **********************************
|
||||
// *** WARNING: EXPERIMENTAL API! ***
|
||||
// **********************************
|
||||
|
||||
class BMimeSnifferAddon {
|
||||
public:
|
||||
BMimeSnifferAddon();
|
||||
virtual ~BMimeSnifferAddon();
|
||||
|
||||
virtual size_t MinimalBufferSize();
|
||||
|
||||
virtual float GuessMimeType(const char* fileName,
|
||||
BMimeType* type);
|
||||
virtual float GuessMimeType(BFile* file,
|
||||
const void* buffer, int32 length,
|
||||
BMimeType* type);
|
||||
};
|
||||
|
||||
#endif // _MIME_SNIFFER_ADDON_H
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2006, Ingo Weinhold <[email protected]>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef MIME_SNIFFER_ADDON_MANAGER_H
|
||||
#define MIME_SNIFFER_ADDON_MANAGER_H
|
||||
|
||||
#include <List.h>
|
||||
#include <Locker.h>
|
||||
|
||||
class BFile;
|
||||
class BMimeSnifferAddon;
|
||||
class BMimeType;
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Storage {
|
||||
namespace Mime {
|
||||
|
||||
|
||||
class MimeSnifferAddonManager {
|
||||
private:
|
||||
MimeSnifferAddonManager();
|
||||
~MimeSnifferAddonManager();
|
||||
|
||||
public:
|
||||
static MimeSnifferAddonManager* Default();
|
||||
static status_t CreateDefault();
|
||||
static void DeleteDefault();
|
||||
|
||||
status_t AddMimeSnifferAddon(BMimeSnifferAddon* addon);
|
||||
|
||||
size_t MinimalBufferSize();
|
||||
|
||||
float GuessMimeType(const char* fileName,
|
||||
BMimeType* type);
|
||||
float GuessMimeType(BFile* file,
|
||||
const void* buffer, int32 length,
|
||||
BMimeType* type);
|
||||
|
||||
private:
|
||||
struct AddonReference;
|
||||
|
||||
status_t _GetAddons(AddonReference**& references,
|
||||
int32& count);
|
||||
void _PutAddons(AddonReference** references,
|
||||
int32 count);
|
||||
|
||||
static MimeSnifferAddonManager* sManager;
|
||||
|
||||
BLocker fLock;
|
||||
BList fAddons;
|
||||
size_t fMinimalBufferSize;
|
||||
};
|
||||
|
||||
} // namespace Mime
|
||||
} // namespace Storage
|
||||
} // namespace BPrivate
|
||||
|
||||
using BPrivate::Storage::Mime::MimeSnifferAddonManager;
|
||||
|
||||
#endif // MIME_SNIFFER_ADDON_MANAGER_H
|
||||
|
||||
@@ -50,7 +50,8 @@ public:
|
||||
};
|
||||
private:
|
||||
status_t BuildRuleList();
|
||||
status_t GuessMimeType(BPositionIO *data, BString *type);
|
||||
status_t GuessMimeType(BFile* file, const void *buffer, int32 length,
|
||||
BString *type);
|
||||
ssize_t MaxBytesNeeded();
|
||||
status_t ProcessType(const char *type, ssize_t *bytesNeeded);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user