]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add RGWPostObj_ObjStore::get_params() to encapsulate boundary extraction.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Thu, 15 Sep 2016 12:45:31 +0000 (14:45 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Mon, 24 Apr 2017 15:32:14 +0000 (17:32 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_rest.cc
src/rgw/rgw_rest.h
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_s3.h

index c1c2ed82f1cad7794915b8b515622a401a8aa1d6..f95f3ddccf2c4c5e936e1e113ba51fe43789eb68 100644 (file)
@@ -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<std::string, std::string> 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;
index 1c99ba9dadd4cd96ab6affcbe93b8233136fed59..2b02f2125e3bd93f78511c7cf4dd1297871fc2a5 100644 (file)
@@ -234,6 +234,7 @@ public:
   };
 
 protected:
+  std::string err_msg;
   ceph::bufferlist in_data;
   std::map<std::string, post_form_part, const ltstr_nocase> 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 {}
index d93731f198909cd464f4dcdca8acb023828dd47b..d2a8850994def2eda2cffb09c44df5728398a6ca 100644 (file)
@@ -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<string, string>& 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<string, string> 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<string, string>::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<string, string>::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<string, string>& 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;
        }
       }
     }
index c26ef3e76f709f58c2c00520083b6b127c13cda2..af1c6a9f26b8c907d1272a76f8b7cf06a6f437dd 100644 (file)
@@ -199,7 +199,6 @@ class RGWPostObj_ObjStore_S3 : public RGWPostObj_ObjStore {
   string filename;
   RGWPolicyEnv env;
   RGWPolicy post_policy;
-  string err_msg;
   map<string, string> crypt_http_responses;
 
   const rgw::auth::StrategyRegistry* auth_registry_ptr = nullptr;