ConfigParser.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 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 "acl/forward.h"
13 #include "base/forward.h"
14 #include "sbuf/forward.h"
15 #include "SquidString.h"
16 
17 #include <memory>
18 #include <queue>
19 #include <stack>
20 #include <string>
21 
22 class wordlist;
23 
32 #define CONFIG_LINE_LIMIT 2048
33 
45 {
46 
47 public:
53 
54  void destruct();
55 
57  void closeDirective();
58 
61 
63  SBuf token(const char *expectedTokenDescription);
64 
68  bool optionalKvPair(char * &key, char * &value);
69 
71  bool skipOptional(const char *keyword);
72 
75 
77  std::unique_ptr<RegexPattern> regex(const char *expectedRegexDescription);
78 
79  static void ParseUShort(unsigned short *var);
80  static void ParseBool(bool *var);
81  static const char *QuoteString(const String &var);
82  static void ParseWordList(wordlist **list);
83 
89  static char * strtokFile();
90 
97  static char *NextToken();
98 
104  static char *RegexStrtokFile();
105 
110  static char *NextQuotedToken();
111 
114 
120  static char *NextQuotedOrToEol();
121 
126  static bool NextKvPair(char * &key, char * &value);
127 
134  static char *PeekAtToken();
135 
137  static void SetCfgLine(char *line);
138 
140  static void EnableMacros() {AllowMacros_ = true;}
141 
143  static void DisableMacros() {AllowMacros_ = false;}
144 
145  static SBuf CurrentLocation();
146 
149 
156  static bool StrictMode;
157 
158 protected:
163  class CfgFile
164  {
165  public:
167  ~CfgFile();
169  bool isOpen() {return wordFile != NULL;}
170 
175  bool startParse(char *path);
176 
183  char *parse(TokenType &type);
184 
185  private:
186  bool getFileLine();
187 
191  char *nextElement(TokenType &type);
192  FILE *wordFile;
194  const char *parsePos;
195  public:
196  std::string filePath;
197  std::string currentLine;
198  int lineNo;
199  };
200 
205  static char *UnQuote(const char *token, const char **next = NULL);
206 
214  static char *TokenParse(const char * &nextToken, TokenType &type);
215 
217  static char *NextElement(TokenType &type);
218  static std::stack<CfgFile *> CfgFiles;
220  static const char *CfgLine;
221  static const char *CfgPos;
222  static std::queue<char *> CfgLineTokens_;
223  static bool AllowMacros_;
224  static bool ParseQuotedOrToEol_;
225  static bool RecognizeQuotedPair_;
226  static bool PreviewMode_;
227  static bool ParseKvPair_;
229 };
230 
231 int parseConfigFile(const char *file_name);
232 
233 #endif /* SQUID_CONFIGPARSER_H */
234 
static SBuf CurrentLocation()
const char * parsePos
The next element position in parseBuffer string.
Definition: ConfigParser.h:194
static char * NextQuotedToken()
static char * strtokFile()
Definition: ConfigParser.cc:64
static bool RecognizeQuotedPair_
The next tokens may contain quoted-pair (-escaped) characters.
Definition: ConfigParser.h:225
static void EnableMacros()
Allow macros inside quoted strings.
Definition: ConfigParser.h:140
int parseConfigFile(const char *file_name)
Definition: cache_cf.cc:634
static bool PreviewMode_
The next token will not popped from cfg files, will just previewd.
Definition: ConfigParser.h:226
static void ParseBool(bool *var)
Definition: cache_cf.cc:3140
static bool StrictMode
Definition: ConfigParser.h:156
FILE * wordFile
Pointer to the file.
Definition: ConfigParser.h:192
static bool LastTokenWasQuoted()
Definition: ConfigParser.h:113
Definition: SBuf.h:87
static bool RecognizeQuotedValues
configuration_includes_quoted_values in squid.conf
Definition: ConfigParser.h:148
static char * PeekAtToken()
int type
Definition: errorpage.cc:152
static bool AllowMacros_
Definition: ConfigParser.h:223
char * parse(TokenType &type)
std::unique_ptr< RegexPattern > regex(const char *expectedRegexDescription)
extracts and returns a regex (including any optional flags)
std::string filePath
The file path.
Definition: ConfigParser.h:196
bool getFileLine()
Read the next line from the file.
#define CONFIG_LINE_LIMIT
Definition: ConfigParser.h:32
static TokenType LastTokenType
The type of last parsed element.
Definition: ConfigParser.h:219
static void DisableMacros()
Do not allow macros inside quoted strings.
Definition: ConfigParser.h:143
#define NULL
Definition: types.h:166
static std::queue< char * > CfgLineTokens_
Store the list of tokens for current configuration line.
Definition: ConfigParser.h:222
static bool ParseQuotedOrToEol_
The next tokens will be handled as quoted or to_eol token.
Definition: ConfigParser.h:224
static bool ParseKvPair_
The next token will be handled as kv-pair token.
Definition: ConfigParser.h:227
SBuf token(const char *expectedTokenDescription)
extracts and returns a required token
void rejectDuplicateDirective()
rejects configuration due to a repeated directive
void destruct()
Definition: ConfigParser.cc:37
bool optionalKvPair(char *&key, char *&value)
Definition: Tree.h:21
char * nextElement(TokenType &type)
static char * RegexStrtokFile()
static bool NextKvPair(char *&key, char *&value)
void closeDirective()
stops parsing the current configuration directive
static char * NextToken()
static void ParseWordList(wordlist **list)
Definition: cache_cf.cc:3162
static const char * QuoteString(const String &var)
static char * NextElement(TokenType &type)
Wrapper method for TokenParse.
static const char * CfgLine
The current line to parse.
Definition: ConfigParser.h:220
bool skipOptional(const char *keyword)
either extracts the given (optional) token or returns false
static char * NextQuotedOrToEol()
static void SetCfgLine(char *line)
Set the configuration file line to parse.
static enum ConfigParser::ParsingStates KvPairState_
Parsing state while parsing kv-pair tokens.
Definition: ConfigParser.cc:30
static const char * CfgPos
Pointer to the next element in cfgLine string.
Definition: ConfigParser.h:221
char parseBuffer[CONFIG_LINE_LIMIT]
Temporary buffer to store data to parse.
Definition: ConfigParser.h:193
std::string currentLine
The current line to parse.
Definition: ConfigParser.h:197
static char * UnQuote(const char *token, const char **next=NULL)
static std::stack< CfgFile * > CfgFiles
The stack of open cfg files.
Definition: ConfigParser.h:218
static void ParseUShort(unsigned short *var)
Definition: cache_cf.cc:3134
bool startParse(char *path)
int lineNo
Current line number.
Definition: ConfigParser.h:198
static char * TokenParse(const char *&nextToken, TokenType &type)
bool isOpen()
True if the configuration file is open.
Definition: ConfigParser.h:169
Acl::Tree * optionalAclList()
parses an [if [!]<acl>...] construct

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors