1 /*
2  * Copyright (C) 2002-2003 Fhg Fokus
3  *
4  * This file is part of SEMS, a free SIP media server.
5  *
6  * SEMS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version. This program is released under
10  * the GPL with the additional exemption that compiling, linking,
11  * and/or using OpenSSL is allowed.
12  *
13  * For a license to use the SEMS software under conditions
14  * other than those described here, or to purchase support for this
15  * software, please contact iptel.org by e-mail at the following addresses:
16  *    info@iptel.org
17  *
18  * SEMS is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  */
27 /** @file AmConfigReader.h */
28 #ifndef AmConfigReader_h
29 #define AmConfigReader_h
30 
31 #include <string>
32 #include <map>
33 using std::string;
34 
35 
36 #define MAX_CONFIG_LINE 2048
37 #define CONFIG_FILE_SUFFIX ".conf"
38 
39 /**
40  * \brief configuration file reader
41  *
42  * Reads configuration file into internal map,
43  * which subsequently can be queried for the value of
44  * specific configuration values.
45  */
46 
47 class AmConfigReader
48 {
49   std::map<string,string> keys;
50 
51  public:
52   int  loadFile(const string& path);
53   int  loadPluginConf(const string& mod_name);
54   int  loadString(const char* cfg_lines, size_t cfg_len);
55 
56   /** get md5 hash of file contents */
57   bool getMD5(const string& path, string& md5hash, bool lowercase = true);
58   void setParameter(const string& param, const string& val);
59   void eraseParameter(const string& param);
60   bool hasParameter(const string& param) const;
61 
62   const string& getParameter(const string& param) const;
63   const string& getParameter(const string& param, const string& defval) const;
64   unsigned int getParameterInt(const string& param, unsigned int defval = 0) const;
65 
begin()66   std::map<string,string>::const_iterator begin() const
67     { return keys.begin(); }
68 
end()69   std::map<string,string>::const_iterator end() const
70     { return keys.end(); }
71 
72   void dump();
73 };
74 
75 #endif
76