bonefish+mmlr:
* Move most of MIME database support out of libbe and into registrar * Use the (async) MessageDeliverer instead of a synchronous SendMessage in _SendMonitorUpdate This fixes a deadlock when the message port of a MIME database watching application gets full as documented in bug #1311. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23423 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _MIME_ASSOCIATED_TYPES_H
|
||||
#define _MIME_ASSOCIATED_TYPES_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
class BMessage;
|
||||
class BString;
|
||||
struct entry_ref;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Storage {
|
||||
namespace Mime {
|
||||
|
||||
class AssociatedTypes {
|
||||
public:
|
||||
AssociatedTypes();
|
||||
~AssociatedTypes();
|
||||
|
||||
status_t GetAssociatedTypes(const char *extension, BMessage *types);
|
||||
status_t GuessMimeType(const char *filename, BString *result);
|
||||
status_t GuessMimeType(const entry_ref *ref, BString *result);
|
||||
|
||||
status_t SetFileExtensions(const char *type, const BMessage *extensions);
|
||||
status_t DeleteFileExtensions(const char *type);
|
||||
|
||||
void PrintToStream() const;
|
||||
private:
|
||||
status_t AddAssociatedType(const char *extension, const char *type);
|
||||
status_t RemoveAssociatedType(const char *extension, const char *type);
|
||||
|
||||
status_t BuildAssociatedTypesTable();
|
||||
|
||||
status_t ProcessType(const char *type);
|
||||
std::string PrepExtension(const char *extension) const;
|
||||
|
||||
std::map<std::string, std::set<std::string> > fFileExtensions; // mime type => set of associated file extensions
|
||||
std::map<std::string, std::set<std::string> > fAssociatedTypes; // file extension => set of associated mime types
|
||||
|
||||
bool fHaveDoneFullBuild;
|
||||
};
|
||||
|
||||
} // namespace Mime
|
||||
} // namespace Storage
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif // _MIME_ASSOCIATED_TYPES_H
|
||||
@@ -1,31 +0,0 @@
|
||||
//----------------------------------------------------------------------
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//---------------------------------------------------------------------
|
||||
/*!
|
||||
\file CreateAppMetaMimeThread.h
|
||||
CreateAppMetaMimeThread interface declaration
|
||||
*/
|
||||
|
||||
#ifndef _CREATE_APP_META_MIME_THREAD_H
|
||||
#define _CREATE_APP_META_MIME_THREAD_H
|
||||
|
||||
#include <mime/MimeUpdateThread.h>
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Storage {
|
||||
namespace Mime {
|
||||
|
||||
class CreateAppMetaMimeThread : public MimeUpdateThread {
|
||||
public:
|
||||
CreateAppMetaMimeThread(const char *name, int32 priority,
|
||||
BMessenger managerMessenger, const entry_ref *root, bool recursive,
|
||||
int32 force, BMessage *replyee);
|
||||
status_t DoMimeUpdate(const entry_ref *entry, bool *entryIsDir);
|
||||
};
|
||||
|
||||
} // namespace Mime
|
||||
} // namespace Storage
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif // _CREATE_APP_META_MIME_THREAD_H
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2006, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Tyler Dauwalder
|
||||
*/
|
||||
#ifndef _MIME_DATABASE_H
|
||||
#define _MIME_DATABASE_H
|
||||
|
||||
|
||||
#include <Mime.h>
|
||||
#include <mime/AssociatedTypes.h>
|
||||
#include <mime/InstalledTypes.h>
|
||||
#include <mime/SnifferRules.h>
|
||||
#include <mime/SupportingApps.h>
|
||||
#include <mime/database_access.h>
|
||||
#include <Messenger.h>
|
||||
#include <StorageDefs.h>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
class BNode;
|
||||
class BBitmap;
|
||||
class BMessage;
|
||||
class BString;
|
||||
|
||||
struct entry_ref;
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Storage {
|
||||
namespace Mime {
|
||||
|
||||
// types of mime update functions that may be run asynchronously
|
||||
typedef enum {
|
||||
B_REG_UPDATE_MIME_INFO,
|
||||
B_REG_CREATE_APP_META_MIME,
|
||||
} mime_update_function;
|
||||
|
||||
class Database {
|
||||
public:
|
||||
Database();
|
||||
~Database();
|
||||
|
||||
status_t InitCheck() const;
|
||||
|
||||
// Type management
|
||||
status_t Install(const char *type);
|
||||
status_t Delete(const char *type);
|
||||
|
||||
// Set()
|
||||
status_t SetAppHint(const char *type, const entry_ref *ref);
|
||||
status_t SetAttrInfo(const char *type, const BMessage *info);
|
||||
status_t SetShortDescription(const char *type, const char *description);
|
||||
status_t SetLongDescription(const char *type, const char *description);
|
||||
status_t SetFileExtensions(const char *type, const BMessage *extensions);
|
||||
status_t SetIcon(const char *type, const void *data, size_t dataSize,
|
||||
icon_size which);
|
||||
status_t SetIcon(const char *type, const void *data, size_t dataSize);
|
||||
status_t SetIconForType(const char *type, const char *fileType,
|
||||
const void *data, size_t dataSize, icon_size which);
|
||||
status_t SetIconForType(const char *type, const char *fileType,
|
||||
const void *data, size_t dataSize);
|
||||
status_t SetPreferredApp(const char *type, const char *signature,
|
||||
app_verb verb = B_OPEN);
|
||||
status_t SetSnifferRule(const char *type, const char *rule);
|
||||
status_t SetSupportedTypes(const char *type, const BMessage *types, bool fullSync);
|
||||
|
||||
// Non-atomic Get()
|
||||
status_t GetInstalledSupertypes(BMessage *super_types);
|
||||
status_t GetInstalledTypes(BMessage *types);
|
||||
status_t GetInstalledTypes(const char *super_type,
|
||||
BMessage *subtypes);
|
||||
status_t GetSupportingApps(const char *type, BMessage *signatures);
|
||||
status_t GetAssociatedTypes(const char *extension, BMessage *types);
|
||||
|
||||
// Sniffer
|
||||
status_t GuessMimeType(const entry_ref *file, BString *result);
|
||||
status_t GuessMimeType(const void *buffer, int32 length, BString *result);
|
||||
status_t GuessMimeType(const char *filename, BString *result);
|
||||
|
||||
// Monitor
|
||||
status_t StartWatching(BMessenger target);
|
||||
status_t StopWatching(BMessenger target);
|
||||
|
||||
// Delete()
|
||||
status_t DeleteAppHint(const char *type);
|
||||
status_t DeleteAttrInfo(const char *type);
|
||||
status_t DeleteShortDescription(const char *type);
|
||||
status_t DeleteLongDescription(const char *type);
|
||||
status_t DeleteFileExtensions(const char *type);
|
||||
status_t DeleteIcon(const char *type, icon_size size);
|
||||
status_t DeleteIcon(const char *type);
|
||||
status_t DeleteIconForType(const char *type, const char *fileType,
|
||||
icon_size which);
|
||||
status_t DeleteIconForType(const char *type, const char *fileType);
|
||||
status_t DeletePreferredApp(const char *type, app_verb verb = B_OPEN);
|
||||
status_t DeleteSnifferRule(const char *type);
|
||||
status_t DeleteSupportedTypes(const char *type, bool fullSync);
|
||||
|
||||
private:
|
||||
status_t _SetStringValue(const char *type, int32 what,
|
||||
const char* attribute, type_code attributeType,
|
||||
size_t maxLength, const char *value);
|
||||
|
||||
// Functions to send monitor notifications
|
||||
status_t _SendInstallNotification(const char *type);
|
||||
status_t _SendDeleteNotification(const char *type);
|
||||
status_t _SendMonitorUpdate(int32 which, const char *type,
|
||||
const char *extraType, bool largeIcon, int32 action);
|
||||
status_t _SendMonitorUpdate(int32 which, const char *type,
|
||||
const char *extraType, int32 action);
|
||||
status_t _SendMonitorUpdate(int32 which, const char *type,
|
||||
bool largeIcon, int32 action);
|
||||
status_t _SendMonitorUpdate(int32 which, const char *type,
|
||||
int32 action);
|
||||
status_t _SendMonitorUpdate(BMessage &msg);
|
||||
|
||||
private:
|
||||
status_t fStatus;
|
||||
std::set<BMessenger> fMonitorMessengers;
|
||||
AssociatedTypes fAssociatedTypes;
|
||||
InstalledTypes fInstalledTypes;
|
||||
SnifferRules fSnifferRules;
|
||||
SupportingApps fSupportingApps;
|
||||
};
|
||||
|
||||
} // namespace Mime
|
||||
} // namespace Storage
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif // _MIME_DATABASE_H
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2006, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Tyler Dauwalder
|
||||
* Ingo Weinhold, [email protected]
|
||||
* Axel Dörfler, [email protected]
|
||||
*/
|
||||
#ifndef _MIME_INSTALLED_TYPES_H
|
||||
#define _MIME_INSTALLED_TYPES_H
|
||||
|
||||
|
||||
#include <mime/Supertype.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
class BMessage;
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Storage {
|
||||
namespace Mime {
|
||||
|
||||
class InstalledTypes {
|
||||
public:
|
||||
InstalledTypes();
|
||||
~InstalledTypes();
|
||||
|
||||
status_t GetInstalledTypes(BMessage *types);
|
||||
status_t GetInstalledTypes(const char *supertype, BMessage *types);
|
||||
status_t GetInstalledSupertypes(BMessage *types);
|
||||
|
||||
status_t AddType(const char *type);
|
||||
status_t RemoveType(const char *type);
|
||||
|
||||
private:
|
||||
status_t _AddSupertype(const char *super,
|
||||
std::map<std::string, Supertype>::iterator &i);
|
||||
status_t _AddSubtype(const char *super, const char *sub);
|
||||
status_t _AddSubtype(Supertype &super, const char *sub);
|
||||
|
||||
status_t _RemoveSupertype(const char *super);
|
||||
status_t _RemoveSubtype(const char *super, const char *sub);
|
||||
|
||||
void _Unset();
|
||||
void _ClearCachedMessages();
|
||||
|
||||
status_t _CreateMessageWithTypes(BMessage **result) const;
|
||||
status_t _CreateMessageWithSupertypes(BMessage **result) const;
|
||||
void _FillMessageWithSupertypes(BMessage *msg);
|
||||
|
||||
status_t _BuildInstalledTypesList();
|
||||
|
||||
std::map<std::string, Supertype> fSupertypes;
|
||||
BMessage *fCachedMessage;
|
||||
BMessage *fCachedSupertypesMessage;
|
||||
bool fHaveDoneFullBuild;
|
||||
};
|
||||
|
||||
} // namespace Mime
|
||||
} // namespace Storage
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif // _MIME_INSTALLED_TYPES_H
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
//----------------------------------------------------------------------
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//---------------------------------------------------------------------
|
||||
/*!
|
||||
\file MimeUpdateThread.h
|
||||
MimeUpdateThread interface declaration
|
||||
*/
|
||||
|
||||
#ifndef _MIME_UPDATE_THREAD_H
|
||||
#define _MIME_UPDATE_THREAD_H
|
||||
|
||||
#include <Entry.h>
|
||||
#include <RegistrarThread.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <list>
|
||||
#include <utility>
|
||||
|
||||
struct entry_ref;
|
||||
class BMessage;
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Storage {
|
||||
namespace Mime {
|
||||
|
||||
class MimeUpdateThread : public RegistrarThread {
|
||||
public:
|
||||
MimeUpdateThread(const char *name, int32 priority,
|
||||
BMessenger managerMessenger, const entry_ref *root, bool recursive,
|
||||
int32 force, BMessage *replyee);
|
||||
virtual ~MimeUpdateThread();
|
||||
|
||||
virtual status_t InitCheck();
|
||||
|
||||
protected:
|
||||
virtual status_t ThreadFunction();
|
||||
virtual status_t DoMimeUpdate(const entry_ref *entry, bool *entryIsDir) = 0;
|
||||
|
||||
const entry_ref fRoot;
|
||||
const bool fRecursive;
|
||||
const int32 fForce;
|
||||
BMessage *fReplyee;
|
||||
|
||||
bool DeviceSupportsAttributes(dev_t device);
|
||||
|
||||
private:
|
||||
std::list< std::pair<dev_t, bool> > fAttributeSupportList;
|
||||
|
||||
status_t UpdateEntry(const entry_ref *ref);
|
||||
|
||||
status_t fStatus;
|
||||
};
|
||||
|
||||
} // namespace Mime
|
||||
} // namespace Storage
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif // _MIME_UPDATE_THREAD_H
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _MIME_SNIFFER_RULES_H
|
||||
#define _MIME_SNIFFER_RULES_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
class BFile;
|
||||
class BString;
|
||||
struct entry_ref;
|
||||
|
||||
|
||||
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
|
||||
@@ -1,50 +0,0 @@
|
||||
//----------------------------------------------------------------------
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//---------------------------------------------------------------------
|
||||
/*!
|
||||
\file Supertype.h
|
||||
Supertype class declarations
|
||||
*/
|
||||
|
||||
#ifndef _MIME_SUPERTYPE_H
|
||||
#define _MIME_SUPERTYPE_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
class BMessage;
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Storage {
|
||||
namespace Mime {
|
||||
|
||||
class Supertype {
|
||||
public:
|
||||
Supertype(const char *super = NULL);
|
||||
~Supertype();
|
||||
|
||||
status_t GetInstalledSubtypes(BMessage *types);
|
||||
|
||||
status_t AddSubtype(const char *sub);
|
||||
status_t RemoveSubtype(const char *sub);
|
||||
|
||||
void SetName(const char *super);
|
||||
const char* GetName();
|
||||
|
||||
status_t FillMessageWithTypes(BMessage &msg) const;
|
||||
private:
|
||||
status_t CreateMessageWithTypes(BMessage **result) const;
|
||||
|
||||
std::set<std::string> fSubtypes;
|
||||
BMessage *fCachedMessage;
|
||||
std::string fName;
|
||||
};
|
||||
|
||||
} // namespace Mime
|
||||
} // namespace Storage
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif // _MIME_SUPERTYPE_H
|
||||
@@ -1,51 +0,0 @@
|
||||
//----------------------------------------------------------------------
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//---------------------------------------------------------------------
|
||||
/*!
|
||||
\file SupportingApps.h
|
||||
SupportingApps class declarations
|
||||
*/
|
||||
|
||||
#ifndef _MIME_SUPPORTING_APPS_H
|
||||
#define _MIME_SUPPORTING_APPS_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
class BMessage;
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Storage {
|
||||
namespace Mime {
|
||||
|
||||
class SupportingApps {
|
||||
public:
|
||||
SupportingApps();
|
||||
~SupportingApps();
|
||||
|
||||
status_t GetSupportingApps(const char *type, BMessage *apps);
|
||||
|
||||
status_t SetSupportedTypes(const char *app, const BMessage *types, bool fullSync);
|
||||
status_t DeleteSupportedTypes(const char *app, bool fullSync);
|
||||
private:
|
||||
status_t AddSupportingApp(const char *type, const char *app);
|
||||
status_t RemoveSupportingApp(const char *type, const char *app);
|
||||
|
||||
status_t BuildSupportingAppsTable();
|
||||
|
||||
std::map<std::string, std::set<std::string> > fSupportedTypes; // app sig => set of supported types
|
||||
std::map<std::string, std::set<std::string> > fSupportingApps; // mime type => set of supporting apps
|
||||
std::map<std::string, std::set<std::string> > fStrandedTypes; // app sig => set of no longer supported types for whom the
|
||||
// given app is still listed as a supporting app
|
||||
bool fHaveDoneFullBuild;
|
||||
};
|
||||
|
||||
} // namespace Mime
|
||||
} // namespace Storage
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif // _MIME_SUPPORTING_APPS_H
|
||||
@@ -1,31 +0,0 @@
|
||||
//----------------------------------------------------------------------
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//---------------------------------------------------------------------
|
||||
/*!
|
||||
\file UpdateMimeInfoThread.h
|
||||
UpdateMimeInfoThread interface declaration
|
||||
*/
|
||||
|
||||
#ifndef _MIME_UPDATE_MIME_INFO_THREAD_H
|
||||
#define _MIME_UPDATE_MIME_INFO_THREAD_H
|
||||
|
||||
#include <mime/MimeUpdateThread.h>
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Storage {
|
||||
namespace Mime {
|
||||
|
||||
class UpdateMimeInfoThread : public MimeUpdateThread {
|
||||
public:
|
||||
UpdateMimeInfoThread(const char *name, int32 priority,
|
||||
BMessenger managerMessenger, const entry_ref *root, bool recursive,
|
||||
int32 force, BMessage *replyee);
|
||||
status_t DoMimeUpdate(const entry_ref *entry, bool *entryIsDir);
|
||||
};
|
||||
|
||||
} // namespace Mime
|
||||
} // namespace Storage
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif // _MIME_UPDATE_MIME_INFO_THREAD_H
|
||||
Reference in New Issue
Block a user