]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_env.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rgw / rgw_env.cc
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
44 const char *RGWEnv::get(const char *name, const char *def_val)
45 {
46 map<string, string, ltstr_nocase>::iterator iter = env_map.find(name);
47 if (iter == env_map.end())
48 return def_val;
49
50 return iter->second.c_str();
51 }
52
53 int RGWEnv::get_int(const char *name, int def_val)
54 {
55 map<string, string, ltstr_nocase>::iterator iter = env_map.find(name);
56 if (iter == env_map.end())
57 return def_val;
58
59 const char *s = iter->second.c_str();
60 return atoi(s);
61 }
62
63 bool RGWEnv::get_bool(const char *name, bool def_val)
64 {
65 map<string, string, ltstr_nocase>::iterator iter = env_map.find(name);
66 if (iter == env_map.end())
67 return def_val;
68
69 const char *s = iter->second.c_str();
70 return rgw_str_to_bool(s, def_val);
71 }
72
73 size_t RGWEnv::get_size(const char *name, size_t def_val)
74 {
75 map<string, string, ltstr_nocase>::iterator iter = env_map.find(name);
76 if (iter == env_map.end())
77 return def_val;
78
79 const char *s = iter->second.c_str();
80 return atoll(s);
81 }
82
83 bool RGWEnv::exists(const char *name)
84 {
85 map<string, string, ltstr_nocase>::iterator iter = env_map.find(name);
86 return (iter != env_map.end());
87 }
88
89 bool RGWEnv::exists_prefix(const char *prefix)
90 {
91 if (env_map.empty() || prefix == NULL)
92 return false;
93
94 map<string, string, ltstr_nocase>::iterator iter = env_map.lower_bound(prefix);
95 if (iter == env_map.end())
96 return false;
97
98 return (strncmp(iter->first.c_str(), prefix, strlen(prefix)) == 0);
99 }
100
101 void RGWEnv::remove(const char *name)
102 {
103 map<string, string, ltstr_nocase>::iterator iter = env_map.find(name);
104 if (iter != env_map.end())
105 env_map.erase(iter);
106 }
107
108 void RGWConf::init(CephContext *cct, RGWEnv *env)
109 {
110 enable_ops_log = cct->_conf->rgw_enable_ops_log;
111 enable_usage_log = cct->_conf->rgw_enable_usage_log;
112
113 defer_to_bucket_acls = 0; // default
114 if (cct->_conf->rgw_defer_to_bucket_acls == "recurse") {
115 defer_to_bucket_acls = RGW_DEFER_TO_BUCKET_ACLS_RECURSE;
116 } else if (cct->_conf->rgw_defer_to_bucket_acls == "full_control") {
117 defer_to_bucket_acls = RGW_DEFER_TO_BUCKET_ACLS_FULL_CONTROL;
118 }
119 }