ConfigParser.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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 "sbuf/forward.h"
13 #include "SquidString.h"
14 
15 #include <queue>
16 #include <stack>
17 #include <string>
18 
19 class wordlist;
20 
29 #define CONFIG_LINE_LIMIT 2048
30 
42 {
43 
44 public:
50 
51  void destruct();
52  static void ParseUShort(unsigned short *var);
53  static void ParseBool(bool *var);
54  static const char *QuoteString(const String &var);
55  static void ParseWordList(wordlist **list);
56 
62  static char * strtokFile();
63 
70  static char *NextToken();
71 
77  static char *RegexStrtokFile();
78 
83  static char *RegexPattern();
84 
89  static char *NextQuotedToken();
90 
93 
99  static char *NextQuotedOrToEol();
100 
105  static bool NextKvPair(char * &key, char * &value);
106 
113  static char *PeekAtToken();
114 
119  static void TokenPutBack(const char *token);
120 
122  static void SetCfgLine(char *line);
123 
125  static void EnableMacros() {AllowMacros_ = true;}
126 
128  static void DisableMacros() {AllowMacros_ = false;}
129 
130  static SBuf CurrentLocation();
131 
134 
141  static bool StrictMode;
142 
143 protected:
148  class CfgFile
149  {
150  public:
152  ~CfgFile();
154  bool isOpen() {return wordFile != NULL;}
155 
160  bool startParse(char *path);
161 
168  char *parse(TokenType &type);
169 
170  private:
171  bool getFileLine();
172 
176  char *nextElement(TokenType &type);
177  FILE *wordFile;
179  const char *parsePos;
180  public:
181  std::string filePath;
182  std::string currentLine;
183  int lineNo;
184  };
185 
187  static char *Undo();
188 
193  static char *UnQuote(const char *token, const char **next = NULL);
194 
202  static char *TokenParse(const char * &nextToken, TokenType &type);
203 
205  static char *NextElement(TokenType &type);
206  static std::stack<CfgFile *> CfgFiles;
208  static const char *CfgLine;
209  static const char *CfgPos;
210  static std::queue<char *> CfgLineTokens_;
211  static std::queue<std::string> Undo_;
212  static bool AllowMacros_;
213  static bool ParseQuotedOrToEol_;
214  static bool RecognizeQuotedPair_;
215  static bool PreviewMode_;
216  static bool ParseKvPair_;
218 };
219 
220 int parseConfigFile(const char *file_name);
221 
222 #endif /* SQUID_CONFIGPARSER_H */
223 
static bool PreviewMode_
The next token will not poped from cfg files, will just previewd.
Definition: ConfigParser.h:215
static void ParseBool(bool *var)
Definition: cache_cf.cc:3146
static std::queue< std::string > Undo_
The list with TokenPutBack() queued elements.
Definition: ConfigParser.h:211
static const char * CfgLine
The current line to parse.
Definition: ConfigParser.h:208
char * nextElement(TokenType &type)
static SBuf CurrentLocation()
static std::queue< char * > CfgLineTokens_
Store the list of tokens for current configuration line.
Definition: ConfigParser.h:210
static void EnableMacros()
Allow macros inside quoted strings.
Definition: ConfigParser.h:125
int type
Definition: errorpage.cc:152
static bool LastTokenWasQuoted()
Definition: ConfigParser.h:92
Definition: SBuf.h:86
static bool RecognizeQuotedPair_
The next tokens may contain quoted-pair (-escaped) characters.
Definition: ConfigParser.h:214
static void ParseUShort(unsigned short *var)
Definition: cache_cf.cc:3140
static char * TokenParse(const char *&nextToken, TokenType &type)
static char * RegexStrtokFile()
static char * PeekAtToken()
static void TokenPutBack(const char *token)
Definition: ConfigParser.cc:63
static std::stack< CfgFile * > CfgFiles
The stack of open cfg files.
Definition: ConfigParser.h:206
static char * RegexPattern()
static bool AllowMacros_
Definition: ConfigParser.h:212
static void DisableMacros()
Do not allow macros inside quoted strings.
Definition: ConfigParser.h:128
static void ParseWordList(wordlist **list)
Definition: cache_cf.cc:3168
int lineNo
Current line number.
Definition: ConfigParser.h:183
static void SetCfgLine(char *line)
Set the configuration file line to parse.
int parseConfigFile(const char *file_name)
Definition: cache_cf.cc:613
char parseBuffer[CONFIG_LINE_LIMIT]
Temporary buffer to store data to parse.
Definition: ConfigParser.h:178
static char * NextQuotedToken()
std::string currentLine
The current line to parse.
Definition: ConfigParser.h:182
bool isOpen()
True if the configuration file is open.
Definition: ConfigParser.h:154
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:29
const char * parsePos
The next element position in parseBuffer string.
Definition: ConfigParser.h:179
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:213
static bool ParseKvPair_
The next token will be handled as kv-pair token.
Definition: ConfigParser.h:216
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:209
#define CONFIG_LINE_LIMIT
Definition: ConfigParser.h:29
FILE * wordFile
Pointer to the file.
Definition: ConfigParser.h:177
static char * strtokFile()
Definition: ConfigParser.cc:84
static bool NextKvPair(char *&key, char *&value)
static TokenType LastTokenType
The type of last parsed element.
Definition: ConfigParser.h:207
void destruct()
Definition: ConfigParser.cc:36
char * parse(TokenType &type)
static char * NextQuotedOrToEol()
bool getFileLine()
Read the next line from the file.
static bool RecognizeQuotedValues
configuration_includes_quoted_values in squid.conf
Definition: ConfigParser.h:133
std::string filePath
The file path.
Definition: ConfigParser.h:181
static char * Undo()
Return the last TokenPutBack() queued element or NULL if none exist.
Definition: ConfigParser.cc:70
static bool StrictMode
Definition: ConfigParser.h:141
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors