* 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.
** Distributed under the terms of the OpenBeOS License.
**
** Authors: Marcus Overhagen, Axel Dörfler
*/
* Copyright 2004-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Marcus Overhagen
* Axel Dörfler
*/
#include "AddOnManager.h"
#include "FormatManager.h"
#include "MetaFormat.h"
#include "media_server.h"
#include "debug.h"
#include <stdio.h>
#include <string.h>
#include <FindDirectory.h>
#include <Path.h>
@ -19,16 +20,20 @@
#include <Autolock.h>
#include <image.h>
#include <stdio.h>
#include <string.h>
#include <safemode.h>
#include <syscalls.h>
#include "FormatManager.h"
#include "MetaFormat.h"
#include "media_server.h"
#include "debug.h"
// #pragma mark ImageLoader
/** The ImageLoader class is a convenience class to temporarily load
* an image file, and unload it on deconstruction automatically.
*/
/*! The ImageLoader class is a convenience class to temporarily load
an image file, and unload it on deconstruction automatically.
*/
class ImageLoader {
public:
ImageLoader(BPath &path)
@ -83,18 +88,17 @@ AddOnManager::GetDecoderForFormat(xfer_entry_ref *_decoderRef,
const media_format &format)
{
if ((format.type == B_MEDIA_ENCODED_VIDEO
|| format.type == B_MEDIA_ENCODED_AUDIO
|| format.type == B_MEDIA_MULTISTREAM)
|| format.type == B_MEDIA_ENCODED_AUDIO
|| format.type == B_MEDIA_MULTISTREAM)
&& format.Encoding() == 0)
return B_MEDIA_BAD_FORMAT;
if (format.type == B_MEDIA_NO_TYPE
|| format.type == B_MEDIA_UNKNOWN_TYPE)
if (format.type == B_MEDIA_NO_TYPE || format.type == B_MEDIA_UNKNOWN_TYPE)
return B_MEDIA_BAD_FORMAT;
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;
for (fDecoderList.Rewind(); fDecoderList.GetNext(&info);) {
@ -104,8 +108,8 @@ AddOnManager::GetDecoderForFormat(xfer_entry_ref *_decoderRef,
if (!decoderFormat->Matches(&format))
continue;
printf("AddOnManager::GetDecoderForFormat: found decoder %s for encoding %ld\n",
info->ref.name, decoderFormat->Encoding());
printf("AddOnManager::GetDecoderForFormat: found decoder %s for "
"encoding %ld\n", info->ref.name, decoderFormat->Encoding());
*_decoderRef = info->ref;
return B_OK;
@ -116,16 +120,17 @@ AddOnManager::GetDecoderForFormat(xfer_entry_ref *_decoderRef,
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);
*out_count = 0;
fReaderList.Rewind();
reader_info *info;
for (*out_count = 0; fReaderList.GetNext(&info) && *out_count <= max_count; *out_count += 1)
out_res[*out_count] = info->ref;
for (*outCount = 0; fReaderList.GetNext(&info) && *outCount < maxCount;
(*outCount)++) {
outRefs[*outCount] = info->ref;
}
return B_OK;
}
@ -141,7 +146,8 @@ AddOnManager::RegisterAddOn(BEntry &entry)
if (status < B_OK)
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);
if ((status = loader.InitCheck()) < B_OK)
@ -151,15 +157,15 @@ AddOnManager::RegisterAddOn(BEntry &entry)
if (get_image_symbol(loader.Image(), "instantiate_plugin",
B_SYMBOL_TYPE_TEXT, (void **)&instantiate_plugin_func) < B_OK) {
printf("AddOnManager::RegisterAddOn(): can't find instantiate_plugin in \"%s\"\n",
path.Path());
printf("AddOnManager::RegisterAddOn(): can't find instantiate_plugin "
"in \"%s\"\n", path.Path());
return B_BAD_TYPE;
}
MediaPlugin *plugin = (*instantiate_plugin_func)();
if (plugin == NULL) {
printf("AddOnManager::RegisterAddOn(): instantiate_plugin in \"%s\" returned NULL\n",
path.Path());
printf("AddOnManager::RegisterAddOn(): instantiate_plugin in \"%s\" "
"returned NULL\n", path.Path());
return B_ERROR;
}
@ -185,22 +191,33 @@ AddOnManager::RegisterAddOns()
class CodecHandler : public AddOnMonitorHandler {
private:
AddOnManager * fManager;
public:
CodecHandler(AddOnManager * manager) {
CodecHandler(AddOnManager *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;
make_entry_ref(entry_info->dir_nref.device, entry_info->dir_nref.node,
entry_info->name, &ref);
make_entry_ref(entryInfo->dir_nref.device,
entryInfo->dir_nref.node, entryInfo->name, &ref);
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_BEOS_ADDONS_DIRECTORY,
};
fHandler = new CodecHandler(this);
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;
BDirectory directory;
BPath path;
for (uint i = 0 ; i < sizeof(directories) / sizeof(directory_which) ; i++) {
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)) {
if (disableUserAddOns && i <= 1)
continue;
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);
}
}
@ -269,7 +303,8 @@ AddOnManager::RegisterDecoder(DecoderPlugin *plugin, const entry_ref &ref)
media_format * formats = 0;
size_t count = 0;
if (plugin->GetSupportedFormats(&formats,&count) != B_OK) {
printf("AddOnManager::RegisterDecoder(): plugin->GetSupportedFormats(...) failed!\n");
printf("AddOnManager::RegisterDecoder(): plugin->GetSupportedFormats"
"(...) failed!\n");
return;
}
for (uint i = 0 ; i < count ; i++) {

View File

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