Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / protocols / ace / HTBP / HTBP_Environment.cpp
blob038f64493541f7d0e33e27753b0909d36c320919
1 #include "HTBP_Environment.h"
3 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
5 ACE::HTBP::Environment::Environment (ACE_Configuration *config,
6 int using_registry,
7 const ACE_TCHAR *persistent_file)
8 : config_ (config),
9 imp_exp_ (0),
10 own_config_ (config != 0)
12 initialize (using_registry,
13 persistent_file);
16 ACE::HTBP::Environment::~Environment ()
18 if (!own_config_)
19 this->clear();
20 else
21 delete this->config_;
23 delete this->imp_exp_;
26 void
27 ACE::HTBP::Environment::clear ()
29 if (this->config_)
30 this->config_->remove_section (config_->root_section (),
31 ACE_TEXT("htbp"),
32 1);
35 int
36 ACE::HTBP::Environment::initialize (int use_registry,
37 const ACE_TCHAR *persistent_file)
39 if (this->config_ == 0)
41 int result = -1;
42 if (use_registry)
43 result = this->open_registry_config();
44 if (result == -1)
45 result = this->open_persistent_config (persistent_file);
46 if (result != 0)
48 ACE_ERROR_RETURN ((LM_ERROR,
49 ACE_TEXT("(%P|%t) ACE::HTBP::Environment")
50 ACE_TEXT("::initialize ")
51 ACE_TEXT("Open Config failed")),
52 -1);
57 ACE_NEW_RETURN (this->imp_exp_,
58 ACE_Ini_ImpExp (*this->config_),
59 -1);
61 if (this->config_->open_section (config_->root_section (),
62 ACE_TEXT("htbp"), 1,
63 this->htbp_key_) != 0)
64 ACE_ERROR_RETURN ((LM_ERROR,
65 ACE_TEXT("(%P|%t) ACE::HTBP::Environment::initialize ")
66 ACE_TEXT("Open HTBP Section failed")),
67 -1);
68 return 0;
71 int
72 ACE::HTBP::Environment::open_registry_config ()
74 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
75 HKEY root =
76 ACE_Configuration_Win32Registry::resolve_key
77 (HKEY_LOCAL_MACHINE,ACE_TEXT("Software\\HTBP\\Environment"));
79 ACE_NEW_RETURN (this->config_,
80 ACE_Configuration_Win32Registry (root),
81 -1);
82 this->own_config_ = true;
83 return 0;
84 #else
85 errno = ENOTSUP;
86 return -1;
87 #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_REGISTRY */
90 int
91 ACE::HTBP::Environment::open_persistent_config (const ACE_TCHAR *persistent_file)
93 ACE_Configuration_Heap *heap;
94 ACE_NEW_RETURN (heap,
95 ACE_Configuration_Heap,
96 -1);
97 // do this before trying to open so it isn't leaked if the open fails.
98 this->config_ = heap;
99 this->own_config_ = true;
100 if (persistent_file == 0)
101 heap->open();
102 else
103 if (heap->open (persistent_file) != 0)
104 ACE_ERROR_RETURN (( LM_ERROR,
105 ACE_TEXT ("(%P|%t) ACE::HTBP::Environment::")
106 ACE_TEXT ("open_config: %p\n"),
107 persistent_file),
108 -1 );
109 return 0;
113 ACE::HTBP::Environment::get_htid_url (ACE_TString &htid_url) const
115 return this->config_->get_string_value (this->htbp_key_,
116 ACE_TEXT("htid_url"),
117 htid_url);
121 ACE::HTBP::Environment::set_htid_url (const ACE_TCHAR *htid_generator_url)
123 return this->config_->set_string_value (this->htbp_key_,
124 ACE_TEXT("htid_url"),
125 htid_generator_url);
130 ACE::HTBP::Environment::get_htid_via_proxy (int &via_proxy) const
132 return this->config_->get_integer_value (this->htbp_key_,
133 ACE_TEXT("htid_via_proxy"),
134 (u_int &)via_proxy);
138 ACE::HTBP::Environment::set_htid_via_proxy (int via_proxy)
140 return this->config_->set_integer_value (this->htbp_key_,
141 ACE_TEXT("htid_via_proxy"),
142 (u_int)via_proxy);
146 ACE::HTBP::Environment::get_proxy_host (ACE_TString &proxy_host) const
148 return this->config_->get_string_value (this->htbp_key_,
149 ACE_TEXT("proxy_host"),
150 proxy_host);
154 ACE::HTBP::Environment::set_proxy_host (const ACE_TCHAR *proxy_host)
156 return this->config_->set_string_value (this->htbp_key_,
157 ACE_TEXT("proxy_host"),
158 proxy_host);
162 ACE::HTBP::Environment::get_proxy_port (unsigned int &proxy_port) const
164 int result = this->config_->get_integer_value (this->htbp_key_,
165 ACE_TEXT("proxy_port"),
166 proxy_port);
167 if (result != 0)
169 ACE_TString port_str;
170 result = this->config_->get_string_value (this->htbp_key_,
171 ACE_TEXT("proxy_port"),
172 port_str);
173 if (result == 0)
174 proxy_port = ACE_OS::strtol(port_str.c_str(),0,10);
176 return result;
180 ACE::HTBP::Environment::set_proxy_port (unsigned int proxy_port)
182 return this->config_->set_integer_value (this->htbp_key_,
183 ACE_TEXT("proxy_port"),
184 proxy_port);
188 ACE::HTBP::Environment::import_config (const ACE_TCHAR *filename)
190 return this->imp_exp_->import_config (filename);
194 ACE::HTBP::Environment::export_config (const ACE_TCHAR *filename)
196 return this->imp_exp_->export_config (filename);
199 ACE_END_VERSIONED_NAMESPACE_DECL