1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
4 #include "rgw_common.h"
9 #include "include/ceph_assert.h"
10 #include "rgw_crypt_sanitize.h"
12 #define dout_context g_ceph_context
13 #define dout_subsys ceph_subsys_rgw
17 void RGWEnv::init(CephContext
*cct
)
22 void RGWEnv::set(std::string name
, std::string val
)
24 env_map
[std::move(name
)] = std::move(val
);
27 void RGWEnv::init(CephContext
*cct
, char **envp
)
33 for (int i
=0; (p
= envp
[i
]); ++i
) {
35 int pos
= s
.find('=');
36 if (pos
<= 0) // should never be 0
38 string name
= s
.substr(0, pos
);
39 string val
= s
.substr(pos
+ 1);
46 const char *rgw_conf_get(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, const char *def_val
)
48 auto iter
= conf_map
.find(name
);
49 if (iter
== conf_map
.end())
52 return iter
->second
.c_str();
55 const char *RGWEnv::get(const char *name
, const char *def_val
) const
57 return rgw_conf_get(env_map
, name
, def_val
);
60 int rgw_conf_get_int(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, int def_val
)
62 auto iter
= conf_map
.find(name
);
63 if (iter
== conf_map
.end())
66 const char *s
= iter
->second
.c_str();
70 int RGWEnv::get_int(const char *name
, int def_val
) const
72 return rgw_conf_get_int(env_map
, name
, def_val
);
75 bool rgw_conf_get_bool(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, bool def_val
)
77 auto iter
= conf_map
.find(name
);
78 if (iter
== conf_map
.end())
81 const char *s
= iter
->second
.c_str();
82 return rgw_str_to_bool(s
, def_val
);
85 bool RGWEnv::get_bool(const char *name
, bool def_val
)
87 return rgw_conf_get_bool(env_map
, name
, def_val
);
90 size_t RGWEnv::get_size(const char *name
, size_t def_val
) const
92 const auto iter
= env_map
.find(name
);
93 if (iter
== env_map
.end())
98 sz
= stoull(iter
->second
);
100 /* it is very unlikely that we'll ever encounter out_of_range, but let's
101 return the default eitherway */
108 bool RGWEnv::exists(const char *name
) const
110 return env_map
.find(name
)!= env_map
.end();
113 bool RGWEnv::exists_prefix(const char *prefix
) const
115 if (env_map
.empty() || prefix
== NULL
)
118 const auto iter
= env_map
.lower_bound(prefix
);
119 if (iter
== env_map
.end())
122 return (strncmp(iter
->first
.c_str(), prefix
, strlen(prefix
)) == 0);
125 void RGWEnv::remove(const char *name
)
127 map
<string
, string
, ltstr_nocase
>::iterator iter
= env_map
.find(name
);
128 if (iter
!= env_map
.end())
132 void RGWConf::init(CephContext
*cct
)
134 enable_ops_log
= cct
->_conf
->rgw_enable_ops_log
;
135 enable_usage_log
= cct
->_conf
->rgw_enable_usage_log
;
137 defer_to_bucket_acls
= 0; // default
138 if (cct
->_conf
->rgw_defer_to_bucket_acls
== "recurse") {
139 defer_to_bucket_acls
= RGW_DEFER_TO_BUCKET_ACLS_RECURSE
;
140 } else if (cct
->_conf
->rgw_defer_to_bucket_acls
== "full_control") {
141 defer_to_bucket_acls
= RGW_DEFER_TO_BUCKET_ACLS_FULL_CONTROL
;