ConfigParser.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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 "sbuf/forward.h"
14 #include "SquidString.h"
15 
16 #include <queue>
17 #include <stack>
18 #include <string>
19 
20 class wordlist;
21 
30 #define CONFIG_LINE_LIMIT 2048
31 
43 {
44 
45 public:
51 
52  void destruct();
53 
55  void closeDirective();
56 
59 
61  SBuf token(const char *expectedTokenDescription);
62 
66  bool optionalKvPair(char * &key, char * &value);
67 
69  bool skipOptional(const char *keyword);
70 
73 
74  static void ParseUShort(unsigned short *var);
75  static void ParseBool(bool *var);
76  static const char *QuoteString(const String &var);
77  static void ParseWordList(wordlist **list);
78 
84  static char * strtokFile();
85 
92  static char *NextToken();
93 
99  static char *RegexStrtokFile();
100 
105  static char *RegexPattern();
106 
111  static char *NextQuotedToken();
112 
115 
121  static char *NextQuotedOrToEol();
122 
127  static bool NextKvPair(char * &key, char * &value);
128 
135  static char *PeekAtToken();
136 
141  static void TokenPutBack(const char *token);
142 
144  static void SetCfgLine(char *line);
145 
147  static void EnableMacros() {AllowMacros_ = true;}
148 
150  static void DisableMacros() {AllowMacros_ = false;}
151 
152  static SBuf CurrentLocation();
153 
156 
163  static bool StrictMode;
164 
165 protected:
170  class CfgFile
171  {
172  public:
174  ~CfgFile();
176  bool isOpen() {return wordFile != NULL;}
177 
182  bool startParse(char *path);
183 
190  char *parse(TokenType &type);
191 
192  private:
193  bool getFileLine();
194 
198  char *nextElement(TokenType &type);
199  FILE *wordFile;
201  const char *parsePos;
202  public:
203  std::string filePath;
204  std::string currentLine;
205  int lineNo;
206  };
207 
209  static char *Undo();
210 
215  static char *UnQuote(const char *token, const char **next = NULL);
216 
224  static char *TokenParse(const char * &nextToken, TokenType &type);
225 
227  static char *NextElement(TokenType &type);
228  static std::stack<CfgFile *> CfgFiles;
230  static const char *CfgLine;
231  static const char *CfgPos;
232  static std::queue<char *> CfgLineTokens_;
233  static std::queue<std::string> Undo_;
234  static bool AllowMacros_;
235  static bool ParseQuotedOrToEol_;
236  static bool RecognizeQuotedPair_;
237  static bool PreviewMode_;
238  static bool ParseKvPair_;
240 };
241 
242 int parseConfigFile(const char *file_name);
243 
244 #endif /* SQUID_CONFIGPARSER_H */
245 
static SBuf CurrentLocation()
const char * parsePos
The next element position in parseBuffer string.
Definition: ConfigParser.h:201
static char * NextQuotedToken()
static char * strtokFile()
Definition: ConfigParser.cc:85
static bool RecognizeQuotedPair_
The next tokens may contain quoted-pair (-escaped) characters.
Definition: ConfigParser.h:236
static void EnableMacros()
Allow macros inside quoted strings.
Definition: ConfigParser.h:147
int parseConfigFile(const char *file_name)
Definition: cache_cf.cc:633
static bool PreviewMode_
The next token will not popped from cfg files, will just previewd.
Definition: ConfigParser.h:237
static void ParseBool(bool *var)
Definition: cache_cf.cc:3177
static bool StrictMode
Definition: ConfigParser.h:163
FILE * wordFile
Pointer to the file.
Definition: ConfigParser.h:199
static bool LastTokenWasQuoted()
Definition: ConfigParser.h:114
Definition: SBuf.h:87
static bool RecognizeQuotedValues
configuration_includes_quoted_values in squid.conf
Definition: ConfigParser.h:155
static char * PeekAtToken()
static void TokenPutBack(const char *token)
Definition: ConfigParser.cc:64
int type
Definition: errorpage.cc:153
static bool AllowMacros_
Definition: ConfigParser.h:234
char * parse(TokenType &type)
std::string filePath
The file path.
Definition: ConfigParser.h:203
bool getFileLine()
Read the next line from the file.
#define CONFIG_LINE_LIMIT
Definition: ConfigParser.h:30
static TokenType LastTokenType
The type of last parsed element.
Definition: ConfigParser.h:229
static void DisableMacros()
Do not allow macros inside quoted strings.
Definition: ConfigParser.h:150
#define NULL
Definition: types.h:166
static char * RegexPattern()
static std::queue< char * > CfgLineTokens_
Store the list of tokens for current configuration line.
Definition: ConfigParser.h:232
static bool ParseQuotedOrToEol_
The next tokens will be handled as quoted or to_eol token.
Definition: ConfigParser.h:235
static bool ParseKvPair_
The next token will be handled as kv-pair token.
Definition: ConfigParser.h:238
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 char * Undo()
Return the last TokenPutBack() queued element or NULL if none exist.
Definition: ConfigParser.cc:71
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:3199
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:230
bool skipOptional(const char *keyword)
either extracts the given (optional) token or returns false
static char * NextQuotedOrToEol()
static std::queue< std::string > Undo_
The list with TokenPutBack() queued elements.
Definition: ConfigParser.h:233
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:231
char parseBuffer[CONFIG_LINE_LIMIT]
Temporary buffer to store data to parse.
Definition: ConfigParser.h:200
std::string currentLine
The current line to parse.
Definition: ConfigParser.h:204
static char * UnQuote(const char *token, const char **next=NULL)
static std::stack< CfgFile * > CfgFiles
The stack of open cfg files.
Definition: ConfigParser.h:228
static void ParseUShort(unsigned short *var)
Definition: cache_cf.cc:3171
bool startParse(char *path)
int lineNo
Current line number.
Definition: ConfigParser.h:205
static char * TokenParse(const char *&nextToken, TokenType &type)
bool isOpen()
True if the configuration file is open.
Definition: ConfigParser.h:176
Acl::Tree * optionalAclList()
parses an [if [!]<acl>...] construct

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors