ConfigParser.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_CONFIGPARSER_H
10 #define SQUID_CONFIGPARSER_H
11 
12 #include "SquidString.h"
13 
14 #include <queue>
15 #include <stack>
16 #include <string>
17 
18 class wordlist;
27 #define CONFIG_LINE_LIMIT 2048
28 
40 {
41 
42 public:
48 
49  void destruct();
50  static void ParseUShort(unsigned short *var);
51  static void ParseBool(bool *var);
52  static const char *QuoteString(const String &var);
53  static void ParseWordList(wordlist **list);
54 
60  static char * strtokFile();
61 
68  static char *NextToken();
69 
75  static char *RegexStrtokFile();
76 
81  static char *RegexPattern();
82 
87  static char *NextQuotedToken();
88 
91 
97  static char *NextQuotedOrToEol();
98 
103  static bool NextKvPair(char * &key, char * &value);
104 
111  static char *PeekAtToken();
112 
117  static void TokenPutBack(const char *token);
118 
120  static void SetCfgLine(char *line);
121 
123  static void EnableMacros() {AllowMacros_ = true;}
124 
126  static void DisableMacros() {AllowMacros_ = false;}
127 
130 
137  static bool StrictMode;
138 
139 protected:
144  class CfgFile
145  {
146  public:
148  ~CfgFile();
150  bool isOpen() {return wordFile != NULL;}
151 
156  bool startParse(char *path);
157 
164  char *parse(TokenType &type);
165 
166  private:
167  bool getFileLine();
168 
172  char *nextElement(TokenType &type);
173  FILE *wordFile;
175  const char *parsePos;
176  public:
177  std::string filePath;
178  std::string currentLine;
179  int lineNo;
180  };
181 
183  static char *Undo();
184 
189  static char *UnQuote(const char *token, const char **next = NULL);
190 
198  static char *TokenParse(const char * &nextToken, TokenType &type);
199 
201  static char *NextElement(TokenType &type);
202  static std::stack<CfgFile *> CfgFiles;
204  static const char *CfgLine;
205  static const char *CfgPos;
206  static std::queue<char *> CfgLineTokens_;
207  static std::queue<std::string> Undo_;
208  static bool AllowMacros_;
209  static bool ParseQuotedOrToEol_;
210  static bool RecognizeQuotedPair_;
211  static bool PreviewMode_;
212  static bool ParseKvPair_;
214 };
215 
216 int parseConfigFile(const char *file_name);
217 
218 #endif /* SQUID_CONFIGPARSER_H */
219 
static bool PreviewMode_
The next token will not poped from cfg files, will just previewd.
Definition: ConfigParser.h:211
static void ParseBool(bool *var)
Definition: cache_cf.cc:3148
static std::queue< std::string > Undo_
The list with TokenPutBack() queued elements.
Definition: ConfigParser.h:207
static const char * CfgLine
The current line to parse.
Definition: ConfigParser.h:204
char * nextElement(TokenType &type)
static std::queue< char * > CfgLineTokens_
Store the list of tokens for current configuration line.
Definition: ConfigParser.h:206
static void EnableMacros()
Allow macros inside quoted strings.
Definition: ConfigParser.h:123
int type
Definition: errorpage.cc:79
static bool LastTokenWasQuoted()
Definition: ConfigParser.h:90
static bool RecognizeQuotedPair_
The next tokens may contain quoted-pair (-escaped) characters.
Definition: ConfigParser.h:210
static void ParseUShort(unsigned short *var)
Definition: cache_cf.cc:3142
static char * TokenParse(const char *&nextToken, TokenType &type)
static char * RegexStrtokFile()
static char * PeekAtToken()
static void TokenPutBack(const char *token)
Definition: ConfigParser.cc:61
static std::stack< CfgFile * > CfgFiles
The stack of open cfg files.
Definition: ConfigParser.h:202
static char * RegexPattern()
static bool AllowMacros_
Definition: ConfigParser.h:208
static void DisableMacros()
Do not allow macros inside quoted strings.
Definition: ConfigParser.h:126
static void ParseWordList(wordlist **list)
Definition: cache_cf.cc:3170
int lineNo
Current line number.
Definition: ConfigParser.h:179
static void SetCfgLine(char *line)
Set the configuration file line to parse.
int parseConfigFile(const char *file_name)
Definition: cache_cf.cc:612
char parseBuffer[CONFIG_LINE_LIMIT]
Temporary buffer to store data to parse.
Definition: ConfigParser.h:174
static char * NextQuotedToken()
std::string currentLine
The current line to parse.
Definition: ConfigParser.h:178
bool isOpen()
True if the configuration file is open.
Definition: ConfigParser.h:150
bool startParse(char *path)
static char * NextToken()
static char * NextElement(TokenType &type)
Wrapper method for TokenParse.
static enum ConfigParser::ParsingStates KvPairState_
Parsing state while parsing kv-pair tokens.
Definition: ConfigParser.cc:27
const char * parsePos
The next element position in parseBuffer string.
Definition: ConfigParser.h:175
static const char * QuoteString(const String &var)
static bool ParseQuotedOrToEol_
The next tokens will be handled as quoted or to_eol token.
Definition: ConfigParser.h:209
static bool ParseKvPair_
The next token will be handled as kv-pair token.
Definition: ConfigParser.h:212
static char * UnQuote(const char *token, const char **next=NULL)
static const char * CfgPos
Pointer to the next element in cfgLine string.
Definition: ConfigParser.h:205
#define CONFIG_LINE_LIMIT
Definition: ConfigParser.h:27
FILE * wordFile
Pointer to the file.
Definition: ConfigParser.h:173
static char * strtokFile()
Definition: ConfigParser.cc:82
static bool NextKvPair(char *&key, char *&value)
static TokenType LastTokenType
The type of last parsed element.
Definition: ConfigParser.h:203
void destruct()
Definition: ConfigParser.cc:34
char * parse(TokenType &type)
static char * NextQuotedOrToEol()
void const cache_key * key
bool getFileLine()
Read the next line from the file.
static bool RecognizeQuotedValues
configuration_includes_quoted_values in squid.conf
Definition: ConfigParser.h:129
std::string filePath
The file path.
Definition: ConfigParser.h:177
static char * Undo()
Return the last TokenPutBack() queued element or NULL if none exist.
Definition: ConfigParser.cc:68
static bool StrictMode
Definition: ConfigParser.h:137
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors