From 7aa1fbeec3a4e083603ce76479c66884d9152a0c Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Thu, 15 Sep 2016 14:45:31 +0200 Subject: [PATCH] rgw: add RGWPostObj_ObjStore::get_params() to encapsulate boundary extraction. Signed-off-by: Radoslaw Zarzynski --- src/rgw/rgw_rest.cc | 46 +++++++++++++++++++++++ src/rgw/rgw_rest.h | 4 ++ src/rgw/rgw_rest_s3.cc | 83 +++--------------------------------------- src/rgw/rgw_rest_s3.h | 1 - 4 files changed, 56 insertions(+), 78 deletions(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index c1c2ed82f1cad..f95f3ddccf2c4 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -1511,6 +1511,7 @@ bool RGWPostObj_ObjStore::part_bl(const std::string& name, *pbl = iter->second.data; return true; } + int RGWPostObj_ObjStore::verify_params() { /* check that we have enough memory to store the object @@ -1527,6 +1528,51 @@ int RGWPostObj_ObjStore::verify_params() return 0; } +int RGWPostObj_ObjStore::get_params() +{ + if (s->expect_cont) { + /* OK, here it really gets ugly. With POST, the params are embedded in the + * request body, so we need to continue before being able to actually look + * at them. This diverts from the usual request flow. */ + dump_continue(s); + s->expect_cont = false; + } + + std::string req_content_type_str = s->info.env->get("CONTENT_TYPE", ""); + std::string req_content_type; + std::map params; + parse_params(req_content_type_str, req_content_type, params); + + if (req_content_type.compare("multipart/form-data") != 0) { + err_msg = "Request Content-Type is not multipart/form-data"; + return -EINVAL; + } + + if (s->cct->_conf->subsys.should_gather(ceph_subsys_rgw, 20)) { + ldout(s->cct, 20) << "request content_type_str=" + << req_content_type_str << dendl; + ldout(s->cct, 20) << "request content_type params:" << dendl; + + for (const auto& pair : params) { + ldout(s->cct, 20) << " " << pair.first << " -> " << pair.second + << dendl; + } + } + + const auto iter = params.find("boundary"); + if (std::end(params) == iter) { + err_msg = "Missing multipart boundary specification"; + return -EINVAL; + } + + /* Create the boundary. */ + boundary = "--"; + boundary.append(iter->second); + + return 0; +} + + int RGWPutACLs_ObjStore::get_params() { const auto max_size = s->cct->_conf->rgw_max_put_param_size; diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h index 1c99ba9dadd4c..2b02f2125e3bd 100644 --- a/src/rgw/rgw_rest.h +++ b/src/rgw/rgw_rest.h @@ -234,6 +234,7 @@ public: }; protected: + std::string err_msg; ceph::bufferlist in_data; std::map parts; @@ -261,6 +262,9 @@ protected: static int parse_part_field(const std::string& line, std::string& field_name, /* out */ post_part_field& field); /* out */ + + int get_params() override; + public: RGWPostObj_ObjStore() {} ~RGWPostObj_ObjStore() override {} diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index d93731f198909..d2a8850994def 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -1494,40 +1494,6 @@ int RGWPutObj_ObjStore_S3::get_encrypt_filter( } return res; } -/* - * parses params in the format: 'first; param1=foo; param2=bar' - */ -static void parse_params(const string& params_str, string& first, - map& params) -{ - size_t pos = params_str.find(';'); - if (pos == string::npos) { - first = rgw_trim_whitespace(params_str); - return; - } - - first = rgw_trim_whitespace(params_str.substr(0, pos)); - - pos++; - - while (pos < params_str.size()) { - size_t end = params_str.find(';', pos); - if (end == string::npos) - end = params_str.size(); - - string param = params_str.substr(pos, end - pos); - - size_t eqpos = param.find('='); - if (eqpos != string::npos) { - params[rgw_trim_whitespace(param.substr(0, eqpos))] = - rgw_trim_quotes(param.substr(eqpos + 1)); - } else { - params[rgw_trim_whitespace(param)] = ""; - } - - pos = end + 1; - } -} void RGWPostObj_ObjStore_S3::rebuild_key(string& key) { @@ -1550,52 +1516,15 @@ std::string RGWPostObj_ObjStore_S3::get_current_filename() const int RGWPostObj_ObjStore_S3::get_params() { - // get the part boundary - string req_content_type_str = s->info.env->get("CONTENT_TYPE", ""); - string req_content_type; - map params; - - if (s->expect_cont) { - /* ok, here it really gets ugly. With POST, the params are embedded in the - * request body, so we need to continue before being able to actually look - * at them. This diverts from the usual request flow. - */ - dump_continue(s); - s->expect_cont = false; - } - - parse_params(req_content_type_str, req_content_type, params); - - if (req_content_type.compare("multipart/form-data") != 0) { - err_msg = "Request Content-Type is not multipart/form-data"; - return -EINVAL; - } - - if (s->cct->_conf->subsys.should_gather(ceph_subsys_rgw, 20)) { - ldout(s->cct, 20) << "request content_type_str=" - << req_content_type_str << dendl; - ldout(s->cct, 20) << "request content_type params:" << dendl; - map::iterator iter; - for (iter = params.begin(); iter != params.end(); ++iter) { - ldout(s->cct, 20) << " " << iter->first << " -> " << iter->second - << dendl; - } + op_ret = RGWPostObj_ObjStore::get_params(); + if (op_ret < 0) { + return op_ret; } ldout(s->cct, 20) << "adding bucket to policy env: " << s->bucket.name << dendl; env.add_var("bucket", s->bucket.name); - map::iterator iter = params.find("boundary"); - if (iter == params.end()) { - err_msg = "Missing multipart boundary specification"; - return -EINVAL; - } - - // create the boundary - boundary = "--"; - boundary.append(iter->second); - bool done; do { struct post_form_part part; @@ -1612,9 +1541,9 @@ int RGWPostObj_ObjStore_S3::get_params() ldout(s->cct, 20) << "val=" << piter->second.val << dendl; ldout(s->cct, 20) << "params:" << dendl; map& params = piter->second.params; - for (iter = params.begin(); iter != params.end(); ++iter) { - ldout(s->cct, 20) << " " << iter->first << " -> " << iter->second - << dendl; + for (const auto& pair : params) { + ldout(s->cct, 20) << " " << pair.first << " -> " << pair.second + << dendl; } } } diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index c26ef3e76f709..af1c6a9f26b8c 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -199,7 +199,6 @@ class RGWPostObj_ObjStore_S3 : public RGWPostObj_ObjStore { string filename; RGWPolicyEnv env; RGWPolicy post_policy; - string err_msg; map crypt_http_responses; const rgw::auth::StrategyRegistry* auth_registry_ptr = nullptr; -- 2.39.5