1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef CEPH_CONFUTILS_H
16 #define CEPH_CONFUTILS_H
23 #include "include/buffer_fwd.h"
26 * Ceph configuration file support.
28 * This class loads an INI-style configuration from a file or bufferlist, and
29 * holds it in memory. In general, an INI configuration file is composed of
30 * sections, which contain key/value pairs. You can put comments on the end of
31 * lines by using either a hash mark (#) or the semicolon (;).
33 * You can get information out of ConfFile by calling get_key or by examining
34 * individual sections.
36 * This class could be extended to support modifying configuration files and
37 * writing them back out without too much difficulty. Currently, this is not
38 * implemented, and the file is read-only.
42 ConfLine(const std::string &key_, const std::string &val_,
43 const std::string &newsection_, const std::string &comment_, int line_no_);
44 bool operator<(const ConfLine &rhs) const;
45 friend std::ostream &operator<<(std::ostream& oss, const ConfLine &l);
47 std::string key, val, newsection;
52 typedef std::set <ConfLine>::const_iterator const_line_iter_t;
54 std::set <ConfLine> lines;
59 typedef std::map <std::string, ConfSection>::iterator section_iter_t;
60 typedef std::map <std::string, ConfSection>::const_iterator const_section_iter_t;
65 int parse_file(const std::string &fname, std::deque<std::string> *errors, std::ostream *warnings);
66 int parse_bufferlist(ceph::bufferlist *bl, std::deque<std::string> *errors, std::ostream *warnings);
67 int read(const std::string §ion, const std::string &key,
68 std::string &val) const;
70 const_section_iter_t sections_begin() const;
71 const_section_iter_t sections_end() const;
73 static void trim_whitespace(std::string &str, bool strip_internal);
74 static std::string normalize_key_name(const std::string &key);
75 friend std::ostream &operator<<(std::ostream &oss, const ConfFile &cf);
78 void load_from_buffer(const char *buf, size_t sz,
79 std::deque<std::string> *errors, std::ostream *warnings);
80 static ConfLine* process_line(int line_no, const char *line,
81 std::deque<std::string> *errors);
83 std::map <std::string, ConfSection> sections;