Botan  1.10.9
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  */
58 
59  global_state().initialize(thread_safe);
60  }
61  catch(...)
62  {
63  deinitialize();
64  throw;
65  }
66  }
67 
68 /*
69 * Library Shutdown
70 */
72  {
74  }
75 
76 }
void set_global_state(Library_State *new_state)
static void initialize(const std::string &options="")
Definition: init.cpp:18
std::vector< std::string > split_on(const std::string &str, char delim)
Definition: parsing.cpp:152
Library_State & global_state()
void initialize(bool thread_safe)
Definition: libstate.cpp:197
static void deinitialize()
Definition: init.cpp:71