From 2489cb76e31ace63c47f3ef2c0e6ec57e0f57426 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 5 Jul 2018 11:46:27 -0700 Subject: [PATCH] rgw: add args.get_int() Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_common.cc | 20 ++++++++++++++++++++ src/rgw/rgw_common.h | 1 + 2 files changed, 21 insertions(+) diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index e9913756c74..0de1dc155a5 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -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); diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index d0fdd6bfdf3..da9f8283f88 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -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; -- 2.39.5