]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #include "rgw_common.h" | |
5 | #include "rgw_log.h" | |
6 | ||
7 | #include <string> | |
8 | #include <map> | |
9 | #include "include/assert.h" | |
10 | #include "rgw_crypt_sanitize.h" | |
11 | ||
12 | #define dout_context g_ceph_context | |
13 | #define dout_subsys ceph_subsys_rgw | |
14 | ||
15 | void RGWEnv::init(CephContext *cct) | |
16 | { | |
17 | conf.init(cct, this); | |
18 | } | |
19 | ||
20 | void RGWEnv::set(const boost::string_ref& name, const boost::string_ref& val) | |
21 | { | |
22 | env_map[std::string{name}] = std::string{val}; | |
23 | } | |
24 | ||
25 | void RGWEnv::init(CephContext *cct, char **envp) | |
26 | { | |
27 | const char *p; | |
28 | ||
29 | env_map.clear(); | |
30 | ||
31 | for (int i=0; (p = envp[i]); ++i) { | |
32 | string s(p); | |
33 | int pos = s.find('='); | |
34 | if (pos <= 0) // should never be 0 | |
35 | continue; | |
36 | string name = s.substr(0, pos); | |
37 | string val = s.substr(pos + 1); | |
38 | env_map[name] = val; | |
39 | } | |
40 | ||
41 | init(cct); | |
42 | } | |
43 | ||
31f18b77 | 44 | const char *rgw_conf_get(const map<string, string, ltstr_nocase>& conf_map, const char *name, const char *def_val) |
7c673cae | 45 | { |
31f18b77 FG |
46 | auto iter = conf_map.find(name); |
47 | if (iter == conf_map.end()) | |
7c673cae FG |
48 | return def_val; |
49 | ||
50 | return iter->second.c_str(); | |
51 | } | |
52 | ||
31f18b77 | 53 | const char *RGWEnv::get(const char *name, const char *def_val) const |
7c673cae | 54 | { |
31f18b77 FG |
55 | return rgw_conf_get(env_map, name, def_val); |
56 | } | |
57 | ||
58 | int rgw_conf_get_int(const map<string, string, ltstr_nocase>& conf_map, const char *name, int def_val) | |
59 | { | |
60 | auto iter = conf_map.find(name); | |
61 | if (iter == conf_map.end()) | |
7c673cae FG |
62 | return def_val; |
63 | ||
64 | const char *s = iter->second.c_str(); | |
65 | return atoi(s); | |
66 | } | |
67 | ||
31f18b77 | 68 | int RGWEnv::get_int(const char *name, int def_val) const |
7c673cae | 69 | { |
31f18b77 FG |
70 | return rgw_conf_get_int(env_map, name, def_val); |
71 | } | |
72 | ||
73 | bool rgw_conf_get_bool(const map<string, string, ltstr_nocase>& conf_map, const char *name, bool def_val) | |
74 | { | |
75 | auto iter = conf_map.find(name); | |
76 | if (iter == conf_map.end()) | |
7c673cae FG |
77 | return def_val; |
78 | ||
79 | const char *s = iter->second.c_str(); | |
80 | return rgw_str_to_bool(s, def_val); | |
81 | } | |
82 | ||
31f18b77 | 83 | bool RGWEnv::get_bool(const char *name, bool def_val) |
7c673cae | 84 | { |
31f18b77 FG |
85 | return rgw_conf_get_bool(env_map, name, def_val); |
86 | } | |
87 | ||
88 | size_t RGWEnv::get_size(const char *name, size_t def_val) const | |
89 | { | |
90 | const auto iter = env_map.find(name); | |
7c673cae FG |
91 | if (iter == env_map.end()) |
92 | return def_val; | |
93 | ||
31f18b77 FG |
94 | size_t sz; |
95 | try{ | |
96 | sz = stoull(iter->second); | |
97 | } catch(...){ | |
98 | /* it is very unlikely that we'll ever encounter out_of_range, but let's | |
99 | return the default eitherway */ | |
100 | sz = def_val; | |
101 | } | |
102 | ||
103 | return sz; | |
7c673cae FG |
104 | } |
105 | ||
31f18b77 | 106 | bool RGWEnv::exists(const char *name) const |
7c673cae | 107 | { |
31f18b77 | 108 | return env_map.find(name)!= env_map.end(); |
7c673cae FG |
109 | } |
110 | ||
31f18b77 | 111 | bool RGWEnv::exists_prefix(const char *prefix) const |
7c673cae FG |
112 | { |
113 | if (env_map.empty() || prefix == NULL) | |
114 | return false; | |
115 | ||
31f18b77 | 116 | const auto iter = env_map.lower_bound(prefix); |
7c673cae FG |
117 | if (iter == env_map.end()) |
118 | return false; | |
119 | ||
120 | return (strncmp(iter->first.c_str(), prefix, strlen(prefix)) == 0); | |
121 | } | |
122 | ||
123 | void RGWEnv::remove(const char *name) | |
124 | { | |
125 | map<string, string, ltstr_nocase>::iterator iter = env_map.find(name); | |
126 | if (iter != env_map.end()) | |
127 | env_map.erase(iter); | |
128 | } | |
129 | ||
130 | void RGWConf::init(CephContext *cct, RGWEnv *env) | |
131 | { | |
132 | enable_ops_log = cct->_conf->rgw_enable_ops_log; | |
133 | enable_usage_log = cct->_conf->rgw_enable_usage_log; | |
134 | ||
135 | defer_to_bucket_acls = 0; // default | |
136 | if (cct->_conf->rgw_defer_to_bucket_acls == "recurse") { | |
137 | defer_to_bucket_acls = RGW_DEFER_TO_BUCKET_ACLS_RECURSE; | |
138 | } else if (cct->_conf->rgw_defer_to_bucket_acls == "full_control") { | |
139 | defer_to_bucket_acls = RGW_DEFER_TO_BUCKET_ACLS_FULL_CONTROL; | |
140 | } | |
141 | } |