added request amb948 - blocking of plugin loads

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401442
This commit is contained in:
David Anderson 2007-09-18 17:44:17 +00:00
parent 78e0de7a5b
commit 167c1d0a31
5 changed files with 45 additions and 12 deletions

View File

@ -6,10 +6,10 @@
* Available properties for plugins are: * Available properties for plugins are:
* "pause" - Whether or not the plugin should load paused - "yes" or "no" (defualt) * "pause" - Whether or not the plugin should load paused - "yes" or "no" (defualt)
* "lifetime" - Lifetime of the plugin. Options: * "lifetime" - Lifetime of the plugin. Options:
* "private" - Plugin is privately maintained and receives no forwards from Core
* "mapsync" - Plugins should be reloaded on mapchange if changed (default) * "mapsync" - Plugins should be reloaded on mapchange if changed (default)
* "maponly" - Plugin should be unloaded at the end of the map
* "global" - Plugin will never be unloaded or updated * "global" - Plugin will never be unloaded or updated
* "blockload" - Plugin will always be blocked from loading. Implicit (automatic) loads
* produce no error, but explicit (manual) loads will show an error message.
* *
* You can also have an "Options" section declaring options to pass onto the JIT: * You can also have an "Options" section declaring options to pass onto the JIT:
* "debug" - Whether or not to load the plugin in debug mode * "debug" - Whether or not to load the plugin in debug mode

View File

@ -42,6 +42,7 @@ void PluginSettings::Init()
optarray = -1; optarray = -1;
opts_num = 0; opts_num = 0;
opts_size = 0; opts_size = 0;
blockload_val = false;
} }
/** /**
@ -179,6 +180,8 @@ SMCParseResult CPluginInfoDatabase::ReadSMC_KeyValue(const char *key,
} else { } else {
return MakeError("Unknown value for key \"lifetime\": \"%s\"", value); return MakeError("Unknown value for key \"lifetime\": \"%s\"", value);
} }
} else if (strcmp(key, "blockload") == 0) {
plugin->blockload_val = true;
} else { } else {
return MakeError("Unknown property key: \"%s\"", key); return MakeError("Unknown property key: \"%s\"", key);
} }
@ -188,6 +191,7 @@ SMCParseResult CPluginInfoDatabase::ReadSMC_KeyValue(const char *key,
int validx = m_strtab->AddString(value); int validx = m_strtab->AddString(value);
PluginOpts *table; PluginOpts *table;
BaseMemTable *memtab = m_strtab->GetMemTable(); BaseMemTable *memtab = m_strtab->GetMemTable();
plugin = (PluginSettings *)memtab->GetAddress(cur_plugin);
if (plugin->opts_num + 1 > plugin->opts_size) if (plugin->opts_num + 1 > plugin->opts_size)
{ {
unsigned int oldsize = plugin->opts_size; unsigned int oldsize = plugin->opts_size;
@ -286,9 +290,10 @@ SMCParseResult CPluginInfoDatabase::ReadSMC_NewSection(const char *name, bool op
{ {
/* If we get a plugin node and we don't have a current plugin, create a new one */ /* If we get a plugin node and we don't have a current plugin, create a new one */
PluginSettings *plugin; PluginSettings *plugin;
int i_name = m_strtab->AddString(name);
cur_plugin = m_strtab->GetMemTable()->CreateMem(sizeof(PluginSettings), (void **)&plugin); cur_plugin = m_strtab->GetMemTable()->CreateMem(sizeof(PluginSettings), (void **)&plugin);
plugin->Init(); plugin->Init();
plugin->name = m_strtab->AddString(name); plugin->name = i_name;
in_options = false; in_options = false;
} else { } else {
if (!in_options && strcmp(name, "Options") == 0) if (!in_options && strcmp(name, "Options") == 0)

View File

@ -58,6 +58,7 @@ struct PluginSettings
int optarray; int optarray;
size_t opts_num; size_t opts_num;
size_t opts_size; size_t opts_size;
bool blockload_val;
}; };
class CPluginInfoDatabase : public ITextListener_SMC class CPluginInfoDatabase : public ITextListener_SMC

View File

@ -885,6 +885,22 @@ void CPluginManager::LoadPluginsFromDir(const char *basedir, const char *localpa
//well i have discovered that gabe newell is very fat, so i wrote this comment now //well i have discovered that gabe newell is very fat, so i wrote this comment now
LoadRes CPluginManager::_LoadPlugin(CPlugin **_plugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength) LoadRes CPluginManager::_LoadPlugin(CPlugin **_plugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength)
{ {
bool no_load = false;
PluginSettings *pset;
unsigned int setcount = m_PluginInfo.GetSettingsNum();
for (unsigned int i=0; i<setcount; i++)
{
if ((pset = m_PluginInfo.GetSettingsIfMatch(i, path)) == NULL)
{
continue;
}
if (pset->blockload_val)
{
no_load = true;
break;
}
}
/** /**
* Does this plugin already exist? * Does this plugin already exist?
*/ */
@ -894,7 +910,8 @@ LoadRes CPluginManager::_LoadPlugin(CPlugin **_plugin, const char *path, bool de
/* Check to see if we should try reloading it */ /* Check to see if we should try reloading it */
if (pPlugin->GetStatus() == Plugin_BadLoad if (pPlugin->GetStatus() == Plugin_BadLoad
|| pPlugin->GetStatus() == Plugin_Error || pPlugin->GetStatus() == Plugin_Error
|| pPlugin->GetStatus() == Plugin_Failed) || pPlugin->GetStatus() == Plugin_Failed
|| no_load)
{ {
UnloadPlugin(pPlugin); UnloadPlugin(pPlugin);
} else { } else {
@ -906,6 +923,11 @@ LoadRes CPluginManager::_LoadPlugin(CPlugin **_plugin, const char *path, bool de
} }
} }
if (no_load)
{
return LoadRes_NeverLoad;
}
pPlugin = CPlugin::CreatePlugin(path, error, maxlength); pPlugin = CPlugin::CreatePlugin(path, error, maxlength);
assert(pPlugin != NULL); assert(pPlugin != NULL);
@ -919,8 +941,6 @@ LoadRes CPluginManager::_LoadPlugin(CPlugin **_plugin, const char *path, bool de
co = pPlugin->StartMyCompile(g_pVM); co = pPlugin->StartMyCompile(g_pVM);
} }
PluginSettings *pset;
unsigned int setcount = m_PluginInfo.GetSettingsNum();
for (unsigned int i=0; i<setcount; i++) for (unsigned int i=0; i<setcount; i++)
{ {
if ((pset=m_PluginInfo.GetSettingsIfMatch(i, path)) == NULL) if ((pset=m_PluginInfo.GetSettingsIfMatch(i, path)) == NULL)
@ -1003,6 +1023,12 @@ IPlugin *CPluginManager::LoadPlugin(const char *path, bool debug, PluginType typ
return pl; return pl;
} }
if (res == LoadRes_NeverLoad)
{
UTIL_Format(error, maxlength, "This plugin is blocked from loading (see plugin_settings.cfg)");
return NULL;
}
AddPlugin(pl); AddPlugin(pl);
/* Run second pass if we need to */ /* Run second pass if we need to */
@ -1021,7 +1047,7 @@ IPlugin *CPluginManager::LoadPlugin(const char *path, bool debug, PluginType typ
void CPluginManager::LoadAutoPlugin(const char *plugin) void CPluginManager::LoadAutoPlugin(const char *plugin)
{ {
CPlugin *pl; CPlugin *pl = NULL;
LoadRes res; LoadRes res;
char error[255] = "Unknown error"; char error[255] = "Unknown error";

View File

@ -123,7 +123,8 @@ enum LoadRes
{ {
LoadRes_Successful, LoadRes_Successful,
LoadRes_AlreadyLoaded, LoadRes_AlreadyLoaded,
LoadRes_Failure LoadRes_Failure,
LoadRes_NeverLoad
}; };
struct AutoConfig struct AutoConfig