From cf1b84195ebb8b0abf733889a3fa994a341be1b1 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Tue, 23 Jan 2018 13:21:11 -0500 Subject: [PATCH] rgw: frontend config uses multimap this allows us to configure multiple values for a given key without resorting to string formatting to cram them into a single key/value pair ex. port=80 port=443s instead of port=80+443s Signed-off-by: Casey Bodley --- src/rgw/rgw_civetweb_frontend.cc | 4 ++-- src/rgw/rgw_frontend.cc | 15 +++++---------- src/rgw/rgw_frontend.h | 10 +++++----- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/rgw/rgw_civetweb_frontend.cc b/src/rgw/rgw_civetweb_frontend.cc index 9b405760feb..d0d49429439 100644 --- a/src/rgw/rgw_civetweb_frontend.cc +++ b/src/rgw/rgw_civetweb_frontend.cc @@ -61,13 +61,13 @@ int RGWCivetWebFrontend::run() set_conf_default(conf_map, "enable_auth_domain_check", "no"); conf->get_val("port", "80", &port_str); std::replace(port_str.begin(), port_str.end(), '+', ','); - conf_map["listening_ports"] = port_str; + conf_map.emplace("listening_ports", std::move(port_str)); /* Set run_as_user. This will cause civetweb to invoke setuid() and setgid() * based on pw_uid and pw_gid obtained from pw_name. */ std::string uid_string = g_ceph_context->get_set_uid_string(); if (! uid_string.empty()) { - conf_map["run_as_user"] = std::move(uid_string); + conf_map.emplace("run_as_user", std::move(uid_string)); } /* Prepare options for CivetWeb. */ diff --git a/src/rgw/rgw_frontend.cc b/src/rgw/rgw_frontend.cc index a047bcd3780..23cf115a47e 100644 --- a/src/rgw/rgw_frontend.cc +++ b/src/rgw/rgw_frontend.cc @@ -13,14 +13,9 @@ #define dout_subsys ceph_subsys_rgw int RGWFrontendConfig::parse_config(const string& config, - map& config_map) + std::multimap& config_map) { - list config_list; - get_str_list(config, " ", config_list); - - list::iterator iter; - for (iter = config_list.begin(); iter != config_list.end(); ++iter) { - string& entry = *iter; + for (auto& entry : get_str_vec(config, " ")) { string key; string val; @@ -33,7 +28,7 @@ int RGWFrontendConfig::parse_config(const string& config, ssize_t pos = entry.find('='); if (pos < 0) { dout(0) << "framework conf key: " << entry << dendl; - config_map[entry] = ""; + config_map.emplace(std::move(entry), ""); continue; } @@ -44,7 +39,7 @@ int RGWFrontendConfig::parse_config(const string& config, } dout(0) << "framework conf key: " << key << ", val: " << val << dendl; - config_map[key] = val; + config_map.emplace(std::move(key), std::move(val)); } return 0; @@ -53,7 +48,7 @@ int RGWFrontendConfig::parse_config(const string& config, bool RGWFrontendConfig::get_val(const string& key, const string& def_val, string *out) { - map::iterator iter = config_map.find(key); + auto iter = config_map.find(key); if (iter == config_map.end()) { *out = def_val; return false; diff --git a/src/rgw/rgw_frontend.h b/src/rgw/rgw_frontend.h index 76225e91ab6..c5d9613536d 100644 --- a/src/rgw/rgw_frontend.h +++ b/src/rgw/rgw_frontend.h @@ -22,11 +22,11 @@ class RGWFrontendConfig { std::string config; - std::map config_map; + std::multimap config_map; std::string framework; int parse_config(const std::string& config, - std::map& config_map); + std::multimap& config_map); public: RGWFrontendConfig(const std::string& config) @@ -54,7 +54,7 @@ public: return config; } - std::map& get_config_map() { + std::multimap& get_config_map() { return config_map; } @@ -97,11 +97,11 @@ class RGWCivetWebFrontend : public RGWFrontend { struct mg_context* ctx; RGWMongooseEnv env; - void set_conf_default(std::map& m, + void set_conf_default(std::multimap& m, const std::string& key, const std::string& def_val) { if (m.find(key) == std::end(m)) { - m[key] = def_val; + m.emplace(key, def_val); } }