aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstate.cpp')
-rw-r--r--src/libstate.cpp106
1 files changed, 82 insertions, 24 deletions
diff --git a/src/libstate.cpp b/src/libstate.cpp
index d0848b52d..f96a53d19 100644
--- a/src/libstate.cpp
+++ b/src/libstate.cpp
@@ -4,15 +4,13 @@
*************************************************/
#include <botan/libstate.h>
-#include <botan/config.h>
#include <botan/modules.h>
#include <botan/engine.h>
#include <botan/stl_util.h>
#include <botan/mutex.h>
#include <botan/charset.h>
-#include <botan/x931_rng.h>
-#include <botan/randpool.h>
#include <botan/selftest.h>
+#include <botan/lookup.h>
#include <algorithm>
namespace Botan {
@@ -27,6 +25,14 @@ Library_State* global_lib_state = 0;
}
/*************************************************
+* Dereference an alias *
+*************************************************/
+std::string deref_alias(const std::string& name)
+ {
+ return global_state().deref_alias(name);
+ }
+
+/*************************************************
* Access the global state object *
*************************************************/
Library_State& global_state()
@@ -82,7 +88,7 @@ Allocator* Library_State::get_allocator(const std::string& type) const
if(!cached_default_allocator)
{
- std::string chosen = config().option("base/default_allocator");
+ std::string chosen = this->option("base/default_allocator");
if(chosen == "")
chosen = "malloc";
@@ -110,14 +116,14 @@ void Library_State::add_allocator(Allocator* allocator)
/*************************************************
* Set the default allocator type *
*************************************************/
-void Library_State::set_default_allocator(const std::string& type) const
+void Library_State::set_default_allocator(const std::string& type)
{
Mutex_Holder lock(allocator_lock);
if(type == "")
return;
- config().set("conf", "base/default_allocator", type);
+ this->set("conf", "base/default_allocator", type);
cached_default_allocator = 0;
}
@@ -143,25 +149,79 @@ void Library_State::add_engine(Engine* engine)
}
/*************************************************
-* Get the configuration object *
+* Get a configuration value *
*************************************************/
-Config& Library_State::config() const
+std::string Library_State::get(const std::string& section,
+ const std::string& key) const
{
- if(!config_obj)
- {
- config_obj = new Config();
- config_obj->load_defaults();
- }
+ Mutex_Holder lock(config_lock);
+
+ return search_map<std::string, std::string>(config,
+ section + "/" + key, "");
+ }
+
+/*************************************************
+* See if a particular option has been set *
+*************************************************/
+bool Library_State::is_set(const std::string& section,
+ const std::string& key) const
+ {
+ Mutex_Holder lock(config_lock);
+
+ return search_map(config, section + "/" + key, false, true);
+ }
+
+/*************************************************
+* Set a configuration value *
+*************************************************/
+void Library_State::set(const std::string& section, const std::string& key,
+ const std::string& value, bool overwrite)
+ {
+ Mutex_Holder lock(config_lock);
+
+ std::string full_key = section + "/" + key;
+
+ std::map<std::string, std::string>::const_iterator i =
+ config.find(full_key);
- return (*config_obj);
+ if(overwrite || i == config.end() || i->second == "")
+ config[full_key] = value;
}
/*************************************************
-* Set the configuration object *
+* Add an alias *
*************************************************/
-std::string Library_State::option(const std::string& name) const
+void Library_State::add_alias(const std::string& key, const std::string& value)
{
- return config().option(name);
+ set("alias", key, value);
+ }
+
+/*************************************************
+* Dereference an alias to a fixed name *
+*************************************************/
+std::string Library_State::deref_alias(const std::string& key) const
+ {
+ std::string result = key;
+ while(is_set("alias", result))
+ result = get("alias", result);
+ return result;
+ }
+
+/*************************************************
+* Set/Add an option *
+*************************************************/
+void Library_State::set_option(const std::string key,
+ const std::string& value)
+ {
+ set("conf", key, value);
+ }
+
+/*************************************************
+* Get an option value *
+*************************************************/
+std::string Library_State::option(const std::string& key) const
+ {
+ return get("conf", key);
}
/*************************************************
@@ -180,6 +240,7 @@ void Library_State::initialize(const InitializerOptions& args,
allocator_lock = get_mutex();
engine_lock = get_mutex();
+ config_lock = get_mutex();
cached_default_allocator = 0;
@@ -189,6 +250,8 @@ void Library_State::initialize(const InitializerOptions& args,
set_default_allocator(modules.default_allocator());
+ load_default_config();
+
std::vector<Engine*> mod_engines = modules.engines();
for(u32bit j = 0; j != mod_engines.size(); ++j)
engines.push_back(mod_engines[j]);
@@ -206,11 +269,7 @@ void Library_State::initialize(const InitializerOptions& args,
Library_State::Library_State()
{
mutex_factory = 0;
-
- allocator_lock = engine_lock = 0;
-
- config_obj = 0;
-
+ allocator_lock = engine_lock = config_lock = 0;
cached_default_allocator = 0;
}
@@ -219,8 +278,6 @@ Library_State::Library_State()
*************************************************/
Library_State::~Library_State()
{
- delete config_obj;
-
std::for_each(engines.begin(), engines.end(), del_fun<Engine>());
cached_default_allocator = 0;
@@ -234,6 +291,7 @@ Library_State::~Library_State()
delete allocator_lock;
delete engine_lock;
delete mutex_factory;
+ delete config_lock;
}
}