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
|
#include "rgw_common.h"
#include "rgw_log.h"
#include <string>
#include <map>
RGWEnv rgw_env;
RGWEnv::RGWEnv()
{
conf = new RGWConf;
}
RGWEnv::~RGWEnv()
{
delete conf;
}
void RGWEnv::reinit(char **envp)
{
const char *p;
env_map.clear();
for (int i=0; (p = envp[i]); ++i) {
string s(p);
int pos = s.find('=');
if (pos <= 0) // should never be 0
continue;
string name = s.substr(0, pos);
string val = s.substr(pos + 1);
env_map[name] = val;
}
conf->init(this);
}
const char *RGWEnv::get(const char *name, const char *def_val)
{
map<string, string>::iterator iter = env_map.find(name);
if (iter == env_map.end())
return def_val;
return iter->second.c_str();
}
int RGWEnv::get_int(const char *name, int def_val)
{
map<string, string>::iterator iter = env_map.find(name);
if (iter == env_map.end())
return def_val;
const char *s = iter->second.c_str();
return atoi(s);
}
bool RGWEnv::get_bool(const char *name, bool def_val)
{
map<string, string>::iterator iter = env_map.find(name);
if (iter == env_map.end())
return def_val;
const char *s = iter->second.c_str();
return rgw_str_to_bool(s, def_val);
}
size_t RGWEnv::get_size(const char *name, size_t def_val)
{
map<string, string>::iterator iter = env_map.find(name);
if (iter == env_map.end())
return def_val;
const char *s = iter->second.c_str();
return atoll(s);
}
void RGWConf::init(RGWEnv *env)
{
max_cache_lru = env->get_size("RGW_MAX_CACHE_LRU", 10000);
log_level = env->get_int("RGW_LOG_LEVEL", g_conf->rgw_log);
should_log = env->get_bool("RGW_SHOULD_LOG", RGW_SHOULD_LOG_DEFAULT);
}
|