Botan 1.10.17

init.cpp
Go to the documentation of this file.
1 /*
2 * Default Initialization Function
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/init.h>
9 #include <botan/parsing.h>
10 #include <botan/libstate.h>
11 #include <botan/global_state.h>
12
13 namespace Botan {
14
15 /*
16 * Library Initialization
17 */
18 void LibraryInitializer::initialize(const std::string& arg_string)
19 {
20 bool thread_safe = false;
21
22 const std::vector<std::string> arg_list = split_on(arg_string, ' ');
23 for(size_t i = 0; i != arg_list.size(); ++i)
24 {
25 if(arg_list[i].size() == 0)
26 continue;
27
28 std::string name, value;
29
30 if(arg_list[i].find('=') == std::string::npos)
31 {
32 name = arg_list[i];
33 value = "true";
34 }
35 else
36 {
37 std::vector<std::string> name_and_value = split_on(arg_list[i], '=');
38 name = name_and_value[0];
39 value = name_and_value[1];
40 }
41
42 bool is_on =
43 (value == "1" || value == "true" || value == "yes" || value == "on");
44
45 if(name == "thread_safe")
46 thread_safe = is_on;
47 }
48
49 try
50 {
51 /*
52 This two stage initialization process is because Library_State's
53 constructor will implicitly refer to global state through the
54 allocators and so forth, so global_state() has to be a valid
55 reference before initialize() can be called. Yeah, gross.
56 */
57 Global_State_Management::set_global_state(new Library_State);
58
59 global_state().initialize(thread_safe);
60 }
61 catch(...)
62 {
63 deinitialize();
64 throw;
65 }
66 }
67
68 /*
69 * Library Shutdown
70 */
71 void LibraryInitializer::deinitialize()
72 {
73 Global_State_Management::set_global_state(0);
74 }
75
76 }
Botan::Library_State
Definition: libstate.h:27
Botan::Global_State_Management::set_global_state
void set_global_state(Library_State *new_state)
Definition: global_state.cpp:49
Botan::LibraryInitializer::initialize
static void initialize(const std::string &options="")
Definition: init.cpp:18
Botan::split_on
std::vector< std::string > split_on(const std::string &str, char delim)
Definition: parsing.cpp:152
Botan::Global_State_Management::global_state
Library_State & global_state()
Definition: global_state.cpp:32
Botan::Library_State::initialize
void initialize(bool thread_safe)
Definition: libstate.cpp:197
Botan::LibraryInitializer::deinitialize
static void deinitialize()
Definition: init.cpp:71
Botan
Definition: algo_base.h:14