From 4b553f92538dc3dbc7e16c6b8aede50bd4dace4a Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 7 Aug 2020 16:49:58 +0800 Subject: [PATCH] common/ConfUtils: expose parse_buffer() so it can be used by crimson for reading settings from a conf file. crimson reads file with async read. since we already have a specialized ConfigProxy for crimson, it'd be simpler to expose the shared facility from ConfUtils instead of specializing it in ConfUtils. Signed-off-by: Kefu Chai --- src/common/ConfUtils.cc | 7 ++++--- src/common/ConfUtils.h | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/ConfUtils.cc b/src/common/ConfUtils.cc index ab41e9ead64..2ee0848c1af 100644 --- a/src/common/ConfUtils.cc +++ b/src/common/ConfUtils.cc @@ -136,7 +136,7 @@ int ConfFile::parse_file(const std::string &fname, std::ifstream ifs{fname}; const std::string buffer{std::istreambuf_iterator(ifs), std::istreambuf_iterator()}; - if (load_from_buffer(buffer, warnings)) { + if (parse_buffer(buffer, warnings)) { return 0; } else { return -EINVAL; @@ -247,8 +247,9 @@ struct IniGrammer : qi::grammar }; } -bool ConfFile::load_from_buffer(std::string_view buf, std::ostream* err) +bool ConfFile::parse_buffer(std::string_view buf, std::ostream* err) { + assert(err); if (int err_pos = check_utf8(buf.data(), buf.size()); err_pos > 0) { *err << "parse error: invalid UTF-8 found at line " << std::count(buf.begin(), std::next(buf.begin(), err_pos), '\n') + 1; @@ -271,7 +272,7 @@ int ConfFile::parse_bufferlist(ceph::bufferlist *bl, if (!warnings) { warnings = &oss; } - return load_from_buffer({bl->c_str(), bl->length()}, warnings) ? 0 : -EINVAL; + return parse_buffer({bl->c_str(), bl->length()}, warnings) ? 0 : -EINVAL; } int ConfFile::read(const std::string& section_name, diff --git a/src/common/ConfUtils.h b/src/common/ConfUtils.h index 1541d371d7b..8e739a516ed 100644 --- a/src/common/ConfUtils.h +++ b/src/common/ConfUtils.h @@ -70,6 +70,7 @@ public: ConfFile(const std::vector& sections); int parse_file(const std::string &fname, std::ostream *warnings); int parse_bufferlist(ceph::bufferlist *bl, std::ostream *warnings); + bool parse_buffer(std::string_view buf, std::ostream* warning); int read(const std::string& section, std::string_view key, std::string &val) const; static std::string normalize_key_name(std::string_view key); @@ -80,8 +81,6 @@ public: void check_old_style_section_names(const std::vector& prefixes, std::ostream& os); -private: - bool load_from_buffer(std::string_view buf, std::ostream* warning); }; std::ostream &operator<<(std::ostream& oss, const ConfFile& cf); -- 2.39.5