]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common/ConfUtils: expose parse_buffer()
authorKefu Chai <kchai@redhat.com>
Fri, 7 Aug 2020 08:49:58 +0000 (16:49 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 10 Aug 2020 14:51:17 +0000 (22:51 +0800)
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 <kchai@redhat.com>
src/common/ConfUtils.cc
src/common/ConfUtils.h

index ab41e9ead6472a456a45a57c334073337a7d34b7..2ee0848c1af199a90c848e47cb6c96b0e449dfc9 100644 (file)
@@ -136,7 +136,7 @@ int ConfFile::parse_file(const std::string &fname,
   std::ifstream ifs{fname};
   const std::string buffer{std::istreambuf_iterator<char>(ifs),
                           std::istreambuf_iterator<char>()};
-  if (load_from_buffer(buffer, warnings)) {
+  if (parse_buffer(buffer, warnings)) {
     return 0;
   } else {
     return -EINVAL;
@@ -247,8 +247,9 @@ struct IniGrammer : qi::grammar<Iterator, ConfFile(), Skipper>
 };
 }
 
-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,
index 1541d371d7bc31194cb81d78d3fbfffb8e25ba20..8e739a516edac5f341ae123c0fd9313ee89c10f6 100644 (file)
@@ -70,6 +70,7 @@ public:
   ConfFile(const std::vector<conf_section_t>& 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<std::string>& 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);