Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions frontend/widgets/OBSBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ static void SetSafeModuleNames()
#endif
}

static void SetDefaultModuleNames()
{
#ifndef SAFE_MODULES
return;
#else
string module;
stringstream modules(SAFE_MODULES);

while (getline(modules, module, '|'))
obs_add_default_module(module.c_str());
#endif
}

extern void setupDockAction(QDockWidget *dock);

OBSBasic::OBSBasic(QWidget *parent) : OBSMainWindow(parent), undo_s(ui), ui(new Ui::OBSBasic)
Expand Down Expand Up @@ -952,6 +965,9 @@ void OBSBasic::OBSInit()
#endif
struct obs_module_failure_info mfi;

if (!portable_mode)
SetDefaultModuleNames();

/* Safe Mode disables third-party plugins so we don't need to add earch
* paths outside the OBS bundle/installation. */
if (safe_mode || disable_3p_plugins) {
Expand Down
2 changes: 1 addition & 1 deletion libobs/obs-cocoa.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void add_default_module_paths(void)
NSString *pluginModulePath = [[pluginURL path] stringByAppendingString:@"/%module%.plugin/Contents/MacOS/"];
NSString *pluginDataPath = [[pluginURL path] stringByAppendingString:@"/%module%.plugin/Contents/Resources/"];

obs_add_module_path(pluginModulePath.UTF8String, pluginDataPath.UTF8String);
obs_add_default_module_path(pluginModulePath.UTF8String, pluginDataPath.UTF8String);
}

char *find_libobs_data_file(const char *file)
Expand Down
2 changes: 2 additions & 0 deletions libobs/obs-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ extern void free_module(struct obs_module *mod);
struct obs_module_path {
char *bin;
char *data;
bool is_default;
};

static inline void free_module_path(struct obs_module_path *omp)
Expand Down Expand Up @@ -489,6 +490,7 @@ struct obs_core {
struct obs_module *first_module;
DARRAY(struct obs_module_path) module_paths;
DARRAY(char *) safe_modules;
DARRAY(char *) default_modules;

obs_source_info_array_t source_types;
obs_source_info_array_t input_types;
Expand Down
52 changes: 52 additions & 0 deletions libobs/obs-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ void obs_add_module_path(const char *bin, const char *data)

omp.bin = bstrdup(bin);
omp.data = bstrdup(data);
omp.is_default = false;
da_push_back(obs->module_paths, &omp);
}

void obs_add_default_module_path(const char *bin, const char *data)
{
struct obs_module_path omp;

if (!obs || !bin || !data)
return;

omp.bin = bstrdup(bin);
omp.data = bstrdup(data);
omp.is_default = true;
da_push_back(obs->module_paths, &omp);
}

Expand All @@ -276,6 +290,15 @@ void obs_add_safe_module(const char *name)
da_push_back(obs->safe_modules, &item);
}

void obs_add_default_module(const char *name)
{
if (!obs || !name)
return;

char *item = bstrdup(name);
da_push_back(obs->default_modules, &item);
}

extern void get_plugin_info(const char *path, bool *is_obs_plugin, bool *can_load);

struct fail_info {
Expand All @@ -296,6 +319,30 @@ static bool is_safe_module(const char *name)
return false;
}

static bool is_default_module(const char *name)
{
if (!obs->default_modules.num)
return true;

for (size_t i = 0; i < obs->default_modules.num; i++) {
if (strcmp(name, obs->default_modules.array[i]) == 0)
return true;
}

return false;
}

static bool is_default_path(const char *name)
{
for (size_t i = 0; i < obs->module_paths.num; i++) {
if (strstr(name, obs->module_paths.array[i].bin) != NULL &&
obs->module_paths.array[i].is_default == true)
return true;
}

return false;
}

static void load_all_callback(void *param, const struct obs_module_info2 *info)
{
struct fail_info *fail_info = param;
Expand All @@ -311,6 +358,11 @@ static void load_all_callback(void *param, const struct obs_module_info2 *info)
return;
}

if (is_default_path(info->bin_path) && !is_default_module(info->name)) {
blog(LOG_WARNING, "Skipping module '%s', not a default plugin in the default directory", info->name);
return;
}

if (!is_safe_module(info->name)) {
blog(LOG_WARNING, "Skipping module '%s', not on safe list", info->name);
return;
Expand Down
2 changes: 1 addition & 1 deletion libobs/obs-nix.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void add_default_module_paths(void)
bfree(module_data_path);

for (int i = 0; i < module_patterns_size; i++) {
obs_add_module_path(module_bin[i], module_data[i]);
obs_add_default_module_path(module_bin[i], module_data[i]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion libobs/obs-windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static const int module_patterns_size = sizeof(module_bin) / sizeof(module_bin[0
void add_default_module_paths(void)
{
for (int i = 0; i < module_patterns_size; i++)
obs_add_module_path(module_bin[i], module_data[i]);
obs_add_default_module_path(module_bin[i], module_data[i]);
}

/* on windows, points to [base directory]/data/libobs */
Expand Down
4 changes: 4 additions & 0 deletions libobs/obs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,10 @@ void obs_shutdown(void)
bfree(obs->safe_modules.array[i]);
da_free(obs->safe_modules);

for (size_t i = 0; i < obs->default_modules.num; i++)
bfree(obs->default_modules.array[i]);
da_free(obs->default_modules);

if (obs->name_store_owned)
profiler_name_store_free(obs->name_store);

Expand Down
15 changes: 15 additions & 0 deletions libobs/obs.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,14 @@ EXPORT const char *obs_get_module_data_path(obs_module_t *module);
*/
EXPORT void obs_add_module_path(const char *bin, const char *data);

/**
* Adds a search path for default modules.
*
* @param bin Specifies the default module's binary directory search path.
* @param data Specifies the default module's data directory search path.
*/
EXPORT void obs_add_default_module_path(const char *bin, const char *data);

/**
* Adds a module to the list of modules allowed to load in Safe Mode.
* If the list is empty, all modules are allowed.
Expand All @@ -533,6 +541,13 @@ EXPORT void obs_add_module_path(const char *bin, const char *data);
*/
EXPORT void obs_add_safe_module(const char *name);

/**
* Adds a module to the list of default modules
*
* @param name Specifies the module's name (filename sans extension).
*/
EXPORT void obs_add_default_module(const char *name);

/** Automatically loads all modules from module paths (convenience function) */
EXPORT void obs_load_all_modules(void);

Expand Down
Loading