* Now checks and honours the "disable user add-ons" safemode setting.

* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24325 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2008-03-09 15:25:39 +00:00
parent a0b6e513b1
commit cfb3cc4648
2 changed files with 82 additions and 46 deletions

View File

@ -1,16 +1,17 @@
/* /*
** Copyright 2004, the OpenBeOS project. All rights reserved. * Copyright 2004-2008, Haiku. All rights reserved.
** Distributed under the terms of the OpenBeOS License. * Distributed under the terms of the MIT License.
** *
** Authors: Marcus Overhagen, Axel Dörfler * Authors:
*/ * Marcus Overhagen
* Axel Dörfler
*/
#include "AddOnManager.h" #include "AddOnManager.h"
#include "FormatManager.h"
#include "MetaFormat.h" #include <stdio.h>
#include "media_server.h" #include <string.h>
#include "debug.h"
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Path.h> #include <Path.h>
@ -19,16 +20,20 @@
#include <Autolock.h> #include <Autolock.h>
#include <image.h> #include <image.h>
#include <stdio.h> #include <safemode.h>
#include <string.h> #include <syscalls.h>
#include "FormatManager.h"
#include "MetaFormat.h"
#include "media_server.h"
#include "debug.h"
// #pragma mark ImageLoader // #pragma mark ImageLoader
/** The ImageLoader class is a convenience class to temporarily load /*! The ImageLoader class is a convenience class to temporarily load
* an image file, and unload it on deconstruction automatically. an image file, and unload it on deconstruction automatically.
*/ */
class ImageLoader { class ImageLoader {
public: public:
ImageLoader(BPath &path) ImageLoader(BPath &path)
@ -83,18 +88,17 @@ AddOnManager::GetDecoderForFormat(xfer_entry_ref *_decoderRef,
const media_format &format) const media_format &format)
{ {
if ((format.type == B_MEDIA_ENCODED_VIDEO if ((format.type == B_MEDIA_ENCODED_VIDEO
|| format.type == B_MEDIA_ENCODED_AUDIO || format.type == B_MEDIA_ENCODED_AUDIO
|| format.type == B_MEDIA_MULTISTREAM) || format.type == B_MEDIA_MULTISTREAM)
&& format.Encoding() == 0) && format.Encoding() == 0)
return B_MEDIA_BAD_FORMAT; return B_MEDIA_BAD_FORMAT;
if (format.type == B_MEDIA_NO_TYPE if (format.type == B_MEDIA_NO_TYPE || format.type == B_MEDIA_UNKNOWN_TYPE)
|| format.type == B_MEDIA_UNKNOWN_TYPE)
return B_MEDIA_BAD_FORMAT; return B_MEDIA_BAD_FORMAT;
BAutolock locker(fLock); BAutolock locker(fLock);
printf("AddOnManager::GetDecoderForFormat: searching decoder for encoding %ld\n", format.Encoding()); printf("AddOnManager::GetDecoderForFormat: searching decoder for encoding "
"%ld\n", format.Encoding());
decoder_info *info; decoder_info *info;
for (fDecoderList.Rewind(); fDecoderList.GetNext(&info);) { for (fDecoderList.Rewind(); fDecoderList.GetNext(&info);) {
@ -104,8 +108,8 @@ AddOnManager::GetDecoderForFormat(xfer_entry_ref *_decoderRef,
if (!decoderFormat->Matches(&format)) if (!decoderFormat->Matches(&format))
continue; continue;
printf("AddOnManager::GetDecoderForFormat: found decoder %s for encoding %ld\n", printf("AddOnManager::GetDecoderForFormat: found decoder %s for "
info->ref.name, decoderFormat->Encoding()); "encoding %ld\n", info->ref.name, decoderFormat->Encoding());
*_decoderRef = info->ref; *_decoderRef = info->ref;
return B_OK; return B_OK;
@ -116,16 +120,17 @@ AddOnManager::GetDecoderForFormat(xfer_entry_ref *_decoderRef,
status_t status_t
AddOnManager::GetReaders(xfer_entry_ref *out_res, int32 *out_count, int32 max_count) AddOnManager::GetReaders(xfer_entry_ref *outRefs, int32 *outCount,
int32 maxCount)
{ {
BAutolock locker(fLock); BAutolock locker(fLock);
*out_count = 0;
fReaderList.Rewind(); fReaderList.Rewind();
reader_info *info; reader_info *info;
for (*out_count = 0; fReaderList.GetNext(&info) && *out_count <= max_count; *out_count += 1) for (*outCount = 0; fReaderList.GetNext(&info) && *outCount < maxCount;
out_res[*out_count] = info->ref; (*outCount)++) {
outRefs[*outCount] = info->ref;
}
return B_OK; return B_OK;
} }
@ -141,7 +146,8 @@ AddOnManager::RegisterAddOn(BEntry &entry)
if (status < B_OK) if (status < B_OK)
return status; return status;
printf("AddOnManager::RegisterAddOn(): trying to load \"%s\"\n", path.Path()); printf("AddOnManager::RegisterAddOn(): trying to load \"%s\"\n",
path.Path());
ImageLoader loader(path); ImageLoader loader(path);
if ((status = loader.InitCheck()) < B_OK) if ((status = loader.InitCheck()) < B_OK)
@ -151,15 +157,15 @@ AddOnManager::RegisterAddOn(BEntry &entry)
if (get_image_symbol(loader.Image(), "instantiate_plugin", if (get_image_symbol(loader.Image(), "instantiate_plugin",
B_SYMBOL_TYPE_TEXT, (void **)&instantiate_plugin_func) < B_OK) { B_SYMBOL_TYPE_TEXT, (void **)&instantiate_plugin_func) < B_OK) {
printf("AddOnManager::RegisterAddOn(): can't find instantiate_plugin in \"%s\"\n", printf("AddOnManager::RegisterAddOn(): can't find instantiate_plugin "
path.Path()); "in \"%s\"\n", path.Path());
return B_BAD_TYPE; return B_BAD_TYPE;
} }
MediaPlugin *plugin = (*instantiate_plugin_func)(); MediaPlugin *plugin = (*instantiate_plugin_func)();
if (plugin == NULL) { if (plugin == NULL) {
printf("AddOnManager::RegisterAddOn(): instantiate_plugin in \"%s\" returned NULL\n", printf("AddOnManager::RegisterAddOn(): instantiate_plugin in \"%s\" "
path.Path()); "returned NULL\n", path.Path());
return B_ERROR; return B_ERROR;
} }
@ -185,22 +191,33 @@ AddOnManager::RegisterAddOns()
class CodecHandler : public AddOnMonitorHandler { class CodecHandler : public AddOnMonitorHandler {
private: private:
AddOnManager * fManager; AddOnManager * fManager;
public: public:
CodecHandler(AddOnManager * manager) { CodecHandler(AddOnManager *manager)
{
fManager = manager; fManager = manager;
} }
virtual void AddOnCreated(const add_on_entry_info * entry_info) {
virtual void AddOnCreated(const add_on_entry_info *entryInfo)
{
} }
virtual void AddOnEnabled(const add_on_entry_info * entry_info) {
virtual void AddOnEnabled(const add_on_entry_info *entryInfo)
{
entry_ref ref; entry_ref ref;
make_entry_ref(entry_info->dir_nref.device, entry_info->dir_nref.node, make_entry_ref(entryInfo->dir_nref.device,
entry_info->name, &ref); entryInfo->dir_nref.node, entryInfo->name, &ref);
BEntry entry(&ref, false); BEntry entry(&ref, false);
fManager->RegisterAddOn(entry); if (entry.InitCheck() == B_OK)
fManager->RegisterAddOn(entry);
} }
virtual void AddOnDisabled(const add_on_entry_info * entry_info) {
virtual void AddOnDisabled(const add_on_entry_info *entryInfo)
{
} }
virtual void AddOnRemoved(const add_on_entry_info * entry_info) {
virtual void AddOnRemoved(const add_on_entry_info *entryInfo)
{
} }
}; };
@ -209,17 +226,34 @@ AddOnManager::RegisterAddOns()
B_COMMON_ADDONS_DIRECTORY, B_COMMON_ADDONS_DIRECTORY,
B_BEOS_ADDONS_DIRECTORY, B_BEOS_ADDONS_DIRECTORY,
}; };
fHandler = new CodecHandler(this); fHandler = new CodecHandler(this);
fAddOnMonitor = new AddOnMonitor(fHandler); fAddOnMonitor = new AddOnMonitor(fHandler);
// get safemode option for disabling user add-ons
char buffer[16];
size_t size = sizeof(buffer);
bool disableUserAddOns = _kern_get_safemode_option(B_SAFEMODE_SAFE_MODE,
buffer, &size) == B_OK
&& (!strcasecmp(buffer, "true")
|| !strcasecmp(buffer, "yes")
|| !strcasecmp(buffer, "on")
|| !strcasecmp(buffer, "enabled")
|| !strcmp(buffer, "1"));
node_ref nref; node_ref nref;
BDirectory directory; BDirectory directory;
BPath path; BPath path;
for (uint i = 0 ; i < sizeof(directories) / sizeof(directory_which) ; i++) { for (uint i = 0 ; i < sizeof(directories) / sizeof(directory_which) ; i++) {
if ((find_directory(directories[i], &path) == B_OK) if (disableUserAddOns && i <= 1)
&& (path.Append("media/plugins") == B_OK) continue;
&& (directory.SetTo(path.Path()) == B_OK)
&& (directory.GetNodeRef(&nref) == B_OK)) { if (find_directory(directories[i], &path) == B_OK
&& path.Append("media/plugins") == B_OK
&& directory.SetTo(path.Path()) == B_OK
&& directory.GetNodeRef(&nref) == B_OK) {
fHandler->AddDirectory(&nref); fHandler->AddDirectory(&nref);
} }
} }
@ -269,7 +303,8 @@ AddOnManager::RegisterDecoder(DecoderPlugin *plugin, const entry_ref &ref)
media_format * formats = 0; media_format * formats = 0;
size_t count = 0; size_t count = 0;
if (plugin->GetSupportedFormats(&formats,&count) != B_OK) { if (plugin->GetSupportedFormats(&formats,&count) != B_OK) {
printf("AddOnManager::RegisterDecoder(): plugin->GetSupportedFormats(...) failed!\n"); printf("AddOnManager::RegisterDecoder(): plugin->GetSupportedFormats"
"(...) failed!\n");
return; return;
} }
for (uint i = 0 ; i < count ; i++) { for (uint i = 0 ; i < count ; i++) {

View File

@ -3,6 +3,7 @@ SubDir HAIKU_TOP src servers media ;
SetSubDirSupportedPlatformsBeOSCompatible ; SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders media shared storage ; UsePrivateHeaders media shared storage ;
UseHeaders $(TARGET_PRIVATE_KERNEL_HEADERS) : true ;
AddResources media_server : media_server.rdef ; AddResources media_server : media_server.rdef ;