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
24 * Ceph configuration file support.
26 * This class loads an INI-style configuration from a file or bufferlist, and
27 * holds it in memory. In general, an INI configuration file is composed of
28 * sections, which contain key/value pairs. You can put comments on the end of
29 * lines by using either a hash mark (#) or the semicolon (;).
31 * You can get information out of ConfFile by calling get_key or by examining
32 * individual sections.
34 * This class could be extended to support modifying configuration files and
35 * writing them back out without too much difficulty. Currently, this is not
36 * implemented, and the file is read-only.
40 ConfLine(const std::string
&key_
, const std::string
&val_
,
41 const std::string
&newsection_
, const std::string
&comment_
, int line_no_
);
42 bool operator<(const ConfLine
&rhs
) const;
43 friend std::ostream
&operator<<(std::ostream
& oss
, const ConfLine
&l
);
45 std::string key
, val
, newsection
;
50 typedef std::set
<ConfLine
>::const_iterator const_line_iter_t
;
52 std::set
<ConfLine
> lines
;
57 typedef std::map
<std::string
, ConfSection
>::iterator section_iter_t
;
58 typedef std::map
<std::string
, ConfSection
>::const_iterator const_section_iter_t
;
63 int parse_file(const std::string
&fname
, std::deque
<std::string
> *errors
, std::ostream
*warnings
);
64 int read(const std::string
§ion
, const std::string
&key
,
65 std::string
&val
) const;
67 const_section_iter_t
sections_begin() const;
68 const_section_iter_t
sections_end() const;
70 static void trim_whitespace(std::string
&str
, bool strip_internal
);
71 static std::string
normalize_key_name(const std::string
&key
);
72 friend std::ostream
&operator<<(std::ostream
&oss
, const ConfFile
&cf
);
75 void load_from_buffer(const char *buf
, size_t sz
,
76 std::deque
<std::string
> *errors
, std::ostream
*warnings
);
77 static ConfLine
* process_line(int line_no
, const char *line
,
78 std::deque
<std::string
> *errors
);
80 std::map
<std::string
, ConfSection
> sections
;