aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstate.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-07-01 21:09:54 +0000
committerlloyd <[email protected]>2006-07-01 21:09:54 +0000
commit6d3a4de1efcb6b04a1ab87037d487f979d7ca445 (patch)
tree02342b193a3808d2010b441480f65aa45a23dc92 /src/libstate.cpp
parent3d1d14cf405111e30643cf4c7674d441cc07a2e0 (diff)
Access the global configuration through an object reference instead
of stand-alone functions. Store the configuration in a distinct object, rather than just a map inside the library state.
Diffstat (limited to 'src/libstate.cpp')
-rw-r--r--src/libstate.cpp76
1 files changed, 25 insertions, 51 deletions
diff --git a/src/libstate.cpp b/src/libstate.cpp
index 36d6299ad..dd81342bc 100644
--- a/src/libstate.cpp
+++ b/src/libstate.cpp
@@ -4,6 +4,7 @@
*************************************************/
#include <botan/libstate.h>
+#include <botan/config.h>
#include <botan/modules.h>
#include <botan/engine.h>
#include <botan/x509stat.h>
@@ -23,6 +24,9 @@ Library_State* global_lib_state = 0;
}
+/*************************************************
+* Access the global state object *
+*************************************************/
Library_State& global_state()
{
if(!global_lib_state)
@@ -33,11 +37,17 @@ Library_State& global_state()
return (*global_lib_state);
}
+/*************************************************
+* Set a new global state object *
+*************************************************/
void set_global_state(Library_State* new_state)
{
delete swap_global_state(new_state);
}
+/*************************************************
+* Swap two global state objects *
+*************************************************/
Library_State* swap_global_state(Library_State* new_state)
{
Library_State* old_state = global_lib_state;
@@ -84,10 +94,7 @@ Allocator* Library_State::get_allocator(const std::string& type) const
if(!cached_default_allocator)
{
- const std::string key_name = "conf/base/default_allocator";
-
- Named_Mutex_Holder lock("settings");
- std::string chosen = search_map(settings, key_name);
+ std::string chosen = config().option("base/default_allocator");
if(chosen == "")
chosen = "malloc";
@@ -116,7 +123,7 @@ void Library_State::add_allocator(Allocator* allocator,
alloc_factory[type] = allocator;
if(set_as_default)
- set_option("conf", "base/default_allocator", type);
+ config().set("conf", "base/default_allocator", type);
}
/*************************************************
@@ -213,51 +220,6 @@ u32bit Library_State::seed_prng(bool slow_poll, u32bit bits_to_get)
}
/*************************************************
-* Set a named option *
-*************************************************/
-void Library_State::set_option(const std::string& section,
- const std::string& name,
- const std::string& value,
- bool overwrite)
- {
- Named_Mutex_Holder lock("settings");
-
- std::map<std::string, std::string>::const_iterator i = settings.find(name);
-
- if(overwrite || i == settings.end() || i->second == "")
- {
- const std::string full_name = section + "/" + name;
- settings[full_name] = value;
-
- if(full_name == "base/default_allocator")
- cached_default_allocator = 0;
- }
- }
-
-/*************************************************
-* Get the value of the named option *
-*************************************************/
-std::string Library_State::get_option(const std::string& section,
- const std::string& name) const
- {
- Named_Mutex_Holder lock("settings");
-
- return search_map<std::string, std::string>(settings,
- section + "/" + name, "");
- }
-
-/*************************************************
-* See if a particular option has been set *
-*************************************************/
-bool Library_State::option_set(const std::string& section,
- const std::string& name) const
- {
- Named_Mutex_Holder lock("settings");
-
- return search_map(settings, section + "/" + name, false, true);
- }
-
-/*************************************************
* Get an engine out of the list *
*************************************************/
Engine* Library_State::get_engine_n(u32bit n) const
@@ -311,7 +273,7 @@ void Library_State::set_x509_state(X509_GlobalState* new_x509_state_obj)
}
/*************************************************
-* Set the X509 global state class *
+* Get the X509 global state class *
*************************************************/
X509_GlobalState& Library_State::x509_state()
{
@@ -322,6 +284,17 @@ X509_GlobalState& Library_State::x509_state()
}
/*************************************************
+* Set the configuration object *
+*************************************************/
+Config& Library_State::config() const
+ {
+ if(!config_obj)
+ throw Invalid_State("Library_State::config(): No config set");
+
+ return (*config_obj);
+ }
+
+/*************************************************
* Load modules *
*************************************************/
void Library_State::load(Modules& modules)
@@ -354,6 +327,7 @@ Library_State::Library_State(Mutex_Factory* mutex_factory)
this->mutex_factory = mutex_factory;
this->timer = new Timer();
this->transcoder = 0;
+ this->config_obj = new Config();
locks["settings"] = get_mutex();
locks["allocator"] = get_mutex();