diff options
author | lloyd <[email protected]> | 2008-10-26 02:18:05 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-10-26 02:18:05 +0000 |
commit | 17231ebbb95cc45cca50eabc4799c3058fc78ee9 (patch) | |
tree | 72b419fcd6a398463ccd0f763dc8bc639ab88b5c /src/libstate/libstate.h | |
parent | 6f2a68c40d85026da907c8ce5366998f14a99d9c (diff) |
Move libstate and selftest out of core/ dir to toplevel
Diffstat (limited to 'src/libstate/libstate.h')
-rw-r--r-- | src/libstate/libstate.h | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/src/libstate/libstate.h b/src/libstate/libstate.h new file mode 100644 index 000000000..74d3d8ef3 --- /dev/null +++ b/src/libstate/libstate.h @@ -0,0 +1,142 @@ +/************************************************* +* Library Internal/Global State Header File * +* (C) 1999-2008 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_LIB_STATE_H__ +#define BOTAN_LIB_STATE_H__ + +#include <botan/base.h> +#include <botan/init.h> +#include <string> +#include <vector> +#include <map> + +namespace Botan { + +/************************************************* +* Global State Container Base * +*************************************************/ +class BOTAN_DLL Library_State + { + public: + Library_State(); + ~Library_State(); + + void initialize(const InitializerOptions&, Modules&); + + void load(Modules&); + + void add_engine(class Engine*); + + class BOTAN_DLL Engine_Iterator + { + public: + class Engine* next(); + Engine_Iterator(const Library_State& l) : lib(l) { n = 0; } + private: + const Library_State& lib; + u32bit n; + }; + friend class Engine_Iterator; + + Allocator* get_allocator(const std::string& = "") const; + void add_allocator(Allocator*); + void set_default_allocator(const std::string&); + + /** + * Get a parameter value as std::string. + * @param section the section of the desired key + * @param key the desired keys name + * @result the value of the parameter + */ + std::string get(const std::string& section, + const std::string& key) const; + + /** + * Check whether a certain parameter is set + * or not. + * @param section the section of the desired key + * @param key the desired keys name + * @result true if the parameters value is set, + * false otherwise + */ + bool is_set(const std::string& section, const std::string& key) const; + + /** + * Set a configuration parameter. + * @param section the section of the desired key + * @param key the desired keys name + * @param overwrite if set to true, the parameters value + * will be overwritten even if it is already set, otherwise + * no existing values will be overwritten. + */ + void set(const std::string& section, const std::string& key, + const std::string& value, bool overwrite = true); + + /** + * Get a parameters value out of the "conf" section ( + * referred to as option). + * @param key the desired keys name + */ + std::string option(const std::string& key) const; + + /** + * Set an option. + * @param key the key of the option to set + * @param value the value to set + */ + /** + * Set an option. + * @param key the key of the option to set + * @param value the value to set + */ + void set_option(const std::string key, const std::string& value); + + /** + * Add a parameter value to the "alias" section. + * @param key the name of the parameter which shall have a new alias + * @param value the new alias + */ + void add_alias(const std::string&, const std::string&); + + /** + * Resolve an alias. + * @param alias the alias to resolve. + * @return what the alias stands for + */ + std::string deref_alias(const std::string&) const; + + class Mutex* get_mutex() const; + private: + void load_default_config(); + + Library_State(const Library_State&) {} + Library_State& operator=(const Library_State&) { return (*this); } + + class Engine* get_engine_n(u32bit) const; + + class Mutex_Factory* mutex_factory; + + std::map<std::string, std::string> config; + class Mutex* config_lock; + + class Mutex* allocator_lock; + std::map<std::string, Allocator*> alloc_factory; + mutable Allocator* cached_default_allocator; + std::vector<Allocator*> allocators; + + class Mutex* engine_lock; + std::vector<class Engine*> engines; + }; + +/************************************************* +* Global State * +*************************************************/ +BOTAN_DLL Library_State& global_state(); +BOTAN_DLL void set_global_state(Library_State*); +BOTAN_DLL Library_State* swap_global_state(Library_State*); + +} + +#endif |