MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InitConfigFileParser.hpp
1 /*
2  Copyright (C) 2003-2006, 2008 MySQL AB, 2009 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef InitConfigFileParser_H
20 #define InitConfigFileParser_H
21 
22 #include <ndb_global.h>
23 
24 #include <Properties.hpp>
25 #include <ConfigValues.hpp>
26 
27 class Config;
28 class ConfigInfo;
29 
39 public:
45 
53  Config * parseConfig(FILE * file);
54  Config * parseConfig(const char * filename);
55  Config * parse_mycnf();
56 
60  enum ContextSectionType { Undefined, Section, DefaultSection };
61 
65  struct Context {
66  Context(const ConfigInfo *);
67  ~Context();
68 
70  char fname[256];
71  char pname[256];
72  Uint32 m_lineno;
73  Uint32 m_sectionLineno;
74 
75  const ConfigInfo * m_info; // The config info
76  Properties * m_config; // The config object
77  Properties * m_defaults; // The user defaults
78 
79  Properties * m_currentSection; // The current section I'm in
80  const Properties * m_userDefaults; // The defaults of this section
81  const Properties * m_systemDefaults; // The syst. defaults for this section
82  const Properties * m_currentInfo; // The "info" for this section
83 
84  Properties m_userProperties; // User properties (temporary values)
85  ConfigValuesFactory m_configValues; //
86 
87  public:
88  void reportError(const char * msg, ...)
89  ATTRIBUTE_FORMAT(printf, 2, 3);
90  void reportWarning(const char * msg, ...)
91  ATTRIBUTE_FORMAT(printf, 2, 3);
92  };
93 
94  static bool convertStringToUint64(const char* s, Uint64& val, Uint32 log10base = 0);
95  static bool convertStringToBool(const char* s, bool& val);
96 
97 private:
103  bool isEmptyLine(const char* line) const;
104 
110  char* parseSectionHeader(const char* line) const;
111 
117  char* parseDefaultSectionHeader(const char* line) const;
118 
119  bool parseNameValuePair(Context&, const char* line);
120  bool storeNameValuePair(Context&, const char* fname, const char* value);
121 
122  bool storeSection(Context&);
123 
124  const Properties* getSection(const char * name, const Properties* src);
125 
129  ConfigInfo* m_info;
130 
131  bool handle_mycnf_defaults(Vector<struct my_option>& options,
132  InitConfigFileParser::Context& ctx,
133  const char * name);
134 
135  bool load_mycnf_groups(Vector<struct my_option> & options,
136  InitConfigFileParser::Context& ctx,
137  const char * name,
138  const char *groups[]);
139 
140  bool store_in_properties(Vector<struct my_option>& options,
141  InitConfigFileParser::Context& ctx,
142  const char * name);
143 
144  Config* run_config_rules(Context& ctx);
145 };
146 
147 #endif // InitConfigFileParser_H