]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: add args.get_int()
authorYehuda Sadeh <yehuda@redhat.com>
Thu, 5 Jul 2018 18:46:27 +0000 (11:46 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 11 Dec 2018 08:10:42 +0000 (00:10 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_common.cc
src/rgw/rgw_common.h

index e9913756c7427ea3ff2f827b0d767883c4d4e175..0de1dc155a5ee0a51d9f056f1ab0873a1fc16637 100644 (file)
@@ -1030,6 +1030,26 @@ void RGWHTTPArgs::get_bool(const char *name, bool *val, bool def_val)
   }
 }
 
+int RGWHTTPArgs::get_int(const char *name, int *val, int def_val)
+{
+  bool exists = false;
+  string val_str;
+  val_str = get(name, &exists);
+  if (!exists) {
+    *val = def_val;
+    return 0;
+  }
+
+  string err;
+
+  *val = (int)strict_strtol(val_str.c_str(), 10, &err);
+  if (!err.empty()) {
+    *val = def_val;
+    return -EINVAL;
+  }
+  return 0;
+}
+
 string RGWHTTPArgs::sys_get(const string& name, bool * const exists) const
 {
   const auto iter = sys_val_map.find(name);
index d0fdd6bfdf3343a817b58dbe577f6160b80c793c..da9f8283f88489d92408c42916a9856896a43947 100644 (file)
@@ -356,6 +356,7 @@ class RGWHTTPArgs {
   int get_bool(const string& name, bool *val, bool *exists);
   int get_bool(const char *name, bool *val, bool *exists);
   void get_bool(const char *name, bool *val, bool def_val);
+  int get_int(const char *name, int *val, int def_val);
 
   /** Get the value for specific system argument parameter */
   std::string sys_get(const string& name, bool *exists = nullptr) const;