]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: accommodate the multipart-boundary parsing in RGWPostObj_ObjStore.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Thu, 15 Sep 2016 10:52:27 +0000 (12:52 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Mon, 24 Apr 2017 15:21:04 +0000 (17:21 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_rest.cc
src/rgw/rgw_rest.h
src/rgw/rgw_rest_s3.h

index 79ed7b20867d8fe34990c542f33267ed8fbdb354..c1c2ed82f1cad7794915b8b515622a401a8aa1d6 100644 (file)
@@ -1272,8 +1272,9 @@ static void parse_params(const string& params_str, string& first,
   }
 }
 
-static int parse_part_field(const string& line, string& field_name,
-                           struct post_part_field& field)
+int RGWPostObj_ObjStore::parse_part_field(const std::string& line,
+                                          std::string& field_name,  /* out */
+                                          post_part_field& field)   /* out */
 {
   size_t pos = line.find(':');
   if (pos == string::npos)
@@ -1288,7 +1289,7 @@ static int parse_part_field(const string& line, string& field_name,
   return 0;
 }
 
-bool is_crlf(const char *s)
+static bool is_crlf(const char *s)
 {
   return (*s == '\r' && *(s + 1) == '\n');
 }
@@ -1344,10 +1345,11 @@ static int index_of(bufferlist& bl, int max_len, const string& str,
   return -1;
 }
 
-int RGWPostObj_ObjStore_S3::read_with_boundary(bufferlist& bl, uint64_t max,
-                                              bool check_crlf,
-                                              bool *reached_boundary,
-                                              bool *done)
+int RGWPostObj_ObjStore::read_with_boundary(ceph::bufferlist& bl,
+                                            uint64_t max,
+                                            const bool check_crlf,
+                                            bool* const reached_boundary,
+                                            bool* const done)
 {
   uint64_t cl = max + 2 + boundary.size();
 
@@ -1364,15 +1366,17 @@ int RGWPostObj_ObjStore_S3::read_with_boundary(bufferlist& bl, uint64_t max,
   int skip;
   int index = index_of(in_data, cl, boundary, check_crlf, reached_boundary,
                       &skip);
-  if (index >= 0)
+  if (index >= 0) {
     max = index;
+  }
 
-  if (max > in_data.length())
+  if (max > in_data.length()) {
     max = in_data.length();
+  }
 
   bl.substr_of(in_data, 0, max);
 
-  bufferlist new_read_data;
+  ceph::bufferlist new_read_data;
 
   /*
    * now we need to skip boundary for next time, also skip any crlf, or
@@ -1407,28 +1411,33 @@ int RGWPostObj_ObjStore_S3::read_with_boundary(bufferlist& bl, uint64_t max,
   return 0;
 }
 
-int RGWPostObj_ObjStore_S3::read_line(bufferlist& bl, uint64_t max,
-                                 bool *reached_boundary, bool *done)
+int RGWPostObj_ObjStore::read_line(ceph::bufferlist& bl,
+                                   const uint64_t max,
+                                   bool* const reached_boundary,
+                                   bool* const done)
 {
   return read_with_boundary(bl, max, true, reached_boundary, done);
 }
 
-int RGWPostObj_ObjStore_S3::read_data(bufferlist& bl, uint64_t max,
-                                 bool *reached_boundary, bool *done)
+int RGWPostObj_ObjStore::read_data(ceph::bufferlist& bl,
+                                   const uint64_t max,
+                                   bool* const reached_boundary,
+                                   bool* const done)
 {
   return read_with_boundary(bl, max, false, reached_boundary, done);
 }
 
 
-int RGWPostObj_ObjStore_S3::read_form_part_header(struct post_form_part *part,
-                                                 bool *done)
+int RGWPostObj_ObjStore::read_form_part_header(struct post_form_part* const part,
+                                               bool* const done)
 {
   bufferlist bl;
   bool reached_boundary;
   uint64_t chunk_size = s->cct->_conf->rgw_max_chunk_size;
   int r = read_line(bl, chunk_size, &reached_boundary, done);
-  if (r < 0)
+  if (r < 0) {
     return r;
+  }
 
   if (*done) {
     return 0;
@@ -1436,27 +1445,30 @@ int RGWPostObj_ObjStore_S3::read_form_part_header(struct post_form_part *part,
 
   if (reached_boundary) { // skip the first boundary
     r = read_line(bl, chunk_size, &reached_boundary, done);
-    if (r < 0)
+    if (r < 0) {
       return r;
-    if (*done)
+    } else if (*done) {
       return 0;
+    }
   }
 
   while (true) {
   /*
    * iterate through fields
    */
-    string line = rgw_trim_whitespace(string(bl.c_str(), bl.length()));
+    std::string line = rgw_trim_whitespace(string(bl.c_str(), bl.length()));
 
-    if (line.empty())
+    if (line.empty()) {
       break;
+    }
 
     struct post_part_field field;
 
     string field_name;
     r = parse_part_field(line, field_name, field);
-    if (r < 0)
+    if (r < 0) {
       return r;
+    }
 
     part->fields[field_name] = field;
 
@@ -1464,8 +1476,9 @@ int RGWPostObj_ObjStore_S3::read_form_part_header(struct post_form_part *part,
       part->name = field.params["name"];
     }
 
-    if (reached_boundary)
+    if (reached_boundary) {
       break;
+    }
 
     r = read_line(bl, chunk_size, &reached_boundary, done);
   }
@@ -1473,25 +1486,27 @@ int RGWPostObj_ObjStore_S3::read_form_part_header(struct post_form_part *part,
   return 0;
 }
 
-bool RGWPostObj_ObjStore_S3::part_str(const string& name, string *val)
+bool RGWPostObj_ObjStore::part_str(const std::string& name,
+                                   std::string* val)
 {
-  map<string, struct post_form_part, ltstr_nocase>::iterator iter
-    = parts.find(name);
-  if (iter == parts.end())
+  const auto iter = parts.find(name);
+  if (std::end(parts) == iter) {
     return false;
+  }
 
-  bufferlist& data = iter->second.data;
-  string str = string(data.c_str(), data.length());
+  ceph::bufferlist& data = iter->second.data;
+  std::string str = string(data.c_str(), data.length());
   *val = rgw_trim_whitespace(str);
   return true;
 }
 
-bool RGWPostObj_ObjStore_S3::part_bl(const string& name, bufferlist *pbl)
+bool RGWPostObj_ObjStore::part_bl(const std::string& name,
+                                  ceph::bufferlist* pbl)
 {
-  map<string, struct post_form_part, ltstr_nocase>::iterator iter =
-    parts.find(name);
-  if (iter == parts.end())
+  const auto iter = parts.find(name);
+  if (std::end(parts) == iter) {
     return false;
+  }
 
   *pbl = iter->second.data;
   return true;
index 18ec59be4e418f231c15b532349846234ecd2efc..15d3e3077f3a4c1cabb2d65b458cd46a4fe683b2 100644 (file)
@@ -216,39 +216,50 @@ public:
   int get_padding_last_aws4_chunk_encoded(bufferlist &bl, uint64_t chunk_size);
 };
 
-struct post_part_field {
-  string val;
-  map<string, string> params;
-};
-
-struct post_form_part {
-  string name;
-  string content_type;
-  map<string, struct post_part_field, ltstr_nocase> fields;
-  bufferlist data;
-};
-
 class RGWPostObj_ObjStore : public RGWPostObj
 {
-protected:
-  bufferlist in_data;
-  map<string, post_form_part, const ltstr_nocase> parts;
+  std::string boundary;
 
-  int read_with_boundary(bufferlist& bl, uint64_t max, bool check_eol,
-                         bool *reached_boundary,
-                        bool *done);
-
-  int read_line(bufferlist& bl, uint64_t max,
-                bool *reached_boundary, bool *done);
-
-  int read_data(bufferlist& bl, uint64_t max, bool *reached_boundary, bool *done);
-  string boundary;
+protected:
+  struct post_part_field {
+    std::string val;
+    std::map<std::string, std::string> params;
+  };
+
+  struct post_form_part {
+    std::string name;
+    std::string content_type;
+    std::map<std::string, post_part_field, ltstr_nocase> fields;
+    ceph::bufferlist data;
+  };
+
+  ceph::bufferlist in_data;
+  std::map<std::string, post_form_part, const ltstr_nocase> parts;
+
+  int read_with_boundary(ceph::bufferlist& bl,
+                         uint64_t max,
+                         bool check_eol,
+                         bool* reached_boundary,
+                         bool* done);
+
+  int read_line(ceph::bufferlist& bl,
+                uint64_t max,
+                bool* reached_boundary,
+                bool* done);
+
+  int read_data(ceph::bufferlist& bl,
+                uint64_t max,
+                bool* reached_boundary,
+                bool* done);
 
   int read_form_part_header(struct post_form_part *part,
                             bool *done);
   bool part_str(const string& name, string *val);
   bool part_bl(const string& name, bufferlist *pbl);
 
+  static int parse_part_field(const std::string& line,
+                              std::string& field_name, /* out */
+                              post_part_field& field); /* out */
 public:
   RGWPostObj_ObjStore() {}
   ~RGWPostObj_ObjStore() override {}
@@ -256,6 +267,7 @@ public:
   int verify_params() override;
 };
 
+
 class RGWPutMetadataAccount_ObjStore : public RGWPutMetadataAccount
 {
 public:
index 2431df893ddcf6cc2cfa71cef5a0f2fe7be8cbb7..c26ef3e76f709f58c2c00520083b6b127c13cda2 100644 (file)
@@ -204,20 +204,6 @@ class RGWPostObj_ObjStore_S3 : public RGWPostObj_ObjStore {
 
   const rgw::auth::StrategyRegistry* auth_registry_ptr = nullptr;
 
-  int read_with_boundary(bufferlist& bl, uint64_t max, bool check_eol,
-                         bool *reached_boundary,
-                        bool *done);
-
-  int read_line(bufferlist& bl, uint64_t max,
-                bool *reached_boundary, bool *done);
-
-  int read_data(bufferlist& bl, uint64_t max, bool *reached_boundary, bool *done);
-
-  int read_form_part_header(struct post_form_part *part,
-                            bool *done);
-  bool part_str(const string& name, string *val);
-  bool part_bl(const string& name, bufferlist *pbl);
-
   int get_policy();
   void rebuild_key(string& key);