From: Yehuda Sadeh Date: Thu, 5 Jul 2018 18:46:27 +0000 (-0700) Subject: rgw: add args.get_int() X-Git-Tag: v14.1.0~616^2~45 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=2489cb76e31ace63c47f3ef2c0e6ec57e0f57426;p=ceph-ci.git rgw: add args.get_int() Signed-off-by: Yehuda Sadeh --- 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;