summaryrefslogtreecommitdiff
path: root/protocols/ace/HTBP/HTBP_Environment.cpp
blob: bd14abcce3d748e96d7e96c6f99cc6cf5439e621 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// $Id$

#include "HTBP_Environment.h"

ACE_RCSID (HTBP,
       	   ACE_HTBP_Environment,
	   "$Id$")

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

ACE::HTBP::Environment::Environment (ACE_Configuration *config,
                                     int using_registry,
                                     const ACE_TCHAR *persistent_file)
  : config_ (config),
    imp_exp_ (0),
    own_config_ (config != 0)
{
  initialize (using_registry,
              persistent_file);
}

ACE::HTBP::Environment::~Environment ()
{
  if (!own_config_)
    this->clear();
  else
    delete this->config_;

  delete this->imp_exp_;
}

void
ACE::HTBP::Environment::clear ()
{
  if (this->config_)
    this->config_->remove_section (config_->root_section (),
                                   ACE_TEXT("htbp"),
                                   1);
}

int
ACE::HTBP::Environment::initialize (int use_registry,
                                    const ACE_TCHAR *persistent_file)
{
  if (this->config_ == 0)
    {
      int result = -1;
      if (use_registry)
        result = this->open_registry_config();
      if (result == -1)
        result = this->open_persistent_config (persistent_file);
      if (result != 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT("ACE::HTBP::Environment::initialize (): ")
                             ACE_TEXT("Open Config failed")),
                            -1);
        }
    }


  ACE_NEW_RETURN (this->imp_exp_,
                  ACE_Ini_ImpExp (*this->config_),
                  -1);

  if (this->config_->open_section (config_->root_section (),
				   ACE_TEXT("htbp"), 1,
                                   this->htbp_key_) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT("ACE::HTBP::Environment::initialize (). ")
                       ACE_TEXT("Open HTBP Section failed")),
                      -1);
  return 0;
}

int
ACE::HTBP::Environment::open_registry_config ()
{
#if defined (ACE_WIN32)
  HKEY root =
    ACE_Configuration_Win32Registry::resolve_key
    (HKEY_LOCAL_MACHINE,ACE_TEXT("Software\\HTBP\\Environment"));

  ACE_NEW_RETURN (this->config_,
                  ACE_Configuration_Win32Registry (root),
                  -1);
  return 0;
#else
  errno = ENOTSUP;
  return -1;
#endif /* ACE_WIN32 */
}

int
ACE::HTBP::Environment::open_persistent_config (const ACE_TCHAR *persistent_file)
{
  ACE_Configuration_Heap *heap;
  ACE_NEW_RETURN (heap,
                  ACE_Configuration_Heap,
                  -1);
  // do this before trying to open so it isn't leaked if the open fails.
  this->config_ = heap;
  if (persistent_file == 0)
    heap->open();
  else
    if (heap->open (persistent_file) != 0)
      ACE_ERROR_RETURN (( LM_ERROR,
                          ACE_TEXT ("ACE::HTBP::Environment::open_config: %p\n"),
                          persistent_file),
                        -1 );
  return 0;
}

int
ACE::HTBP::Environment::get_htid_url (ACE_TString &htid_url) const
{
  return this->config_->get_string_value (this->htbp_key_,
                                          ACE_TEXT("htid_url"),
                                          htid_url);
}

int
ACE::HTBP::Environment::set_htid_url (const ACE_TCHAR *htid_generator_url)
{
  return this->config_->set_string_value (this->htbp_key_,
                                          ACE_TEXT("htid_url"),
                                          htid_generator_url);
}


int
ACE::HTBP::Environment::get_htid_via_proxy (int &via_proxy) const
{
  return this->config_->get_integer_value (this->htbp_key_,
                                           ACE_TEXT("htid_via_proxy"),
                                           (u_int &)via_proxy);
}

int
ACE::HTBP::Environment::set_htid_via_proxy (int via_proxy)
{
  return this->config_->set_integer_value (this->htbp_key_,
                                           ACE_TEXT("htid_via_proxy"),
                                           (u_int)via_proxy);
}

int
ACE::HTBP::Environment::get_proxy_host (ACE_TString &proxy_host) const
{
  return this->config_->get_string_value (this->htbp_key_,
                                          ACE_TEXT("proxy_host"),
                                          proxy_host);
}

int
ACE::HTBP::Environment::set_proxy_host (const ACE_TCHAR *proxy_host)
{
  return this->config_->set_string_value (this->htbp_key_,
                                          ACE_TEXT("proxy_host"),
                                          proxy_host);
}

int
ACE::HTBP::Environment::get_proxy_port (unsigned int &proxy_port) const
{
  int result = this->config_->get_integer_value (this->htbp_key_,
                                                 ACE_TEXT("proxy_port"),
                                                 proxy_port);
  if (result != 0)
    {
      ACE_TString port_str;
      result = this->config_->get_string_value (this->htbp_key_,
                                                ACE_TEXT("proxy_port"),
                                                port_str);
      if (result == 0)
        proxy_port = ACE_OS::strtol(port_str.c_str(),0,10);
    }
  return result;
}

int
ACE::HTBP::Environment::set_proxy_port (unsigned int proxy_port)
{
  return this->config_->set_integer_value (this->htbp_key_,
                                           ACE_TEXT("proxy_port"),
                                           proxy_port);
}

int
ACE::HTBP::Environment::import_config (const ACE_TCHAR *filename)
{
  return this->imp_exp_->import_config (filename);
}

int
ACE::HTBP::Environment::export_config (const ACE_TCHAR *filename)
{
  return this->imp_exp_->export_config (filename);
}

ACE_END_VERSIONED_NAMESPACE_DECL