]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: refactor the expiration checking in FormPost of Swift API.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Wed, 21 Sep 2016 11:39:25 +0000 (13:39 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Mon, 24 Apr 2017 15:32:15 +0000 (17:32 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_rest_swift.cc
src/rgw/rgw_rest_swift.h

index 069962319dadc48f5f1a4393c7b4988d1eaeb335..86ab012632bad9e547c904a34d322e894b275f72 100644 (file)
@@ -1724,23 +1724,27 @@ void RGWFormPost::init(RGWRados* const store,
   return RGWPostObj_ObjStore::init(store, s, dialect_handler);
 }
 
-bool RGWFormPost::is_expired(const std::string& expires)
+bool RGWFormPost::is_non_expired()
 {
-  string err;
-  const utime_t now = ceph_clock_now(g_ceph_context);
-  const uint64_t expiration = (uint64_t)strict_strtoll(expires.c_str(),
-                                                       10, &err);
-  if (!err.empty()) {
-    dout(5) << "failed to parse temp_url_expires: " << err << dendl;
-    return true;
+  std::string expires = get_part_str(ctrl_parts, "expires", "0");
+
+  std::string err;
+  const uint64_t expires_timestamp =
+    static_cast<uint64_t>(strict_strtoll(expires.c_str(), 10, &err));
+
+  if (! err.empty()) {
+    dout(5) << "failed to parse FormPost's expires: " << err << dendl;
+    return false;
   }
 
-  if (expiration <= (uint64_t)now.sec()) {
-    dout(5) << "temp url expired: " << expiration << " <= " << now.sec() << dendl;
-    return true;
+  const utime_t now = ceph_clock_now();
+  if (expires_timestamp <= static_cast<uint64_t>(now.sec())) {
+    dout(5) << "FormPost form expired: "
+            << expires_timestamp << " <= " << now.sec() << dendl;
+    return false;
   }
 
-  return false;
+  return true;
 }
 
 bool RGWFormPost::is_integral()
@@ -1846,8 +1850,7 @@ int RGWFormPost::get_params()
     }
   } while (! stream_done);
 
-  std::string expires;
-  if (part_str(ctrl_parts, "expires", &expires) && is_expired(expires)) {
+  if (! is_non_expired()) {
     err_msg = "FormPost: Form Expired";
     return -EACCES;
   }
index e67620296219fe6b1e5fde6639df72cea0c2c35c..c6029350146266e44539fafb8edf3d7167084d9e 100644 (file)
@@ -244,7 +244,7 @@ class RGWFormPost : public RGWPostObj_ObjStore {
   std::string get_current_filename() const override;
   bool is_next_file_to_upload() override;
   bool is_integral();
-  static bool is_expired(const std::string& expires);
+  bool is_non_expired();
 
   parts_collection_t ctrl_parts;
   boost::optional<post_form_part> current_data_part;