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
22class wordlist;
23
32#define CONFIG_LINE_LIMIT 2048
33
45{
46
47public:
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
158protected:
164 {
165 public:
166 CfgFile(): wordFile(nullptr), parsePos(nullptr), lineNo(0) { parseBuffer[0] = '\0';}
167 ~CfgFile();
169 bool isOpen() {return wordFile != nullptr;}
170
175 bool startParse(char *path);
176
183 char *parse(TokenType &type);
184
185 private:
186 bool getFileLine();
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 = nullptr);
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_;
226 static bool PreviewMode_;
227 static bool ParseKvPair_;
229};
230
231int parseConfigFile(const char *file_name);
232
233#endif /* SQUID_CONFIGPARSER_H */
234
int parseConfigFile(const char *file_name)
Definition: cache_cf.cc:634
#define CONFIG_LINE_LIMIT
Definition: ConfigParser.h:32
Definition: Tree.h:21
char * nextElement(TokenType &type)
std::string currentLine
The current line to parse.
Definition: ConfigParser.h:197
std::string filePath
The file path.
Definition: ConfigParser.h:196
FILE * wordFile
Pointer to the file.
Definition: ConfigParser.h:192
char * parse(TokenType &type)
const char * parsePos
The next element position in parseBuffer string.
Definition: ConfigParser.h:194
bool getFileLine()
Read the next line from the file.
char parseBuffer[CONFIG_LINE_LIMIT]
Temporary buffer to store data to parse.
Definition: ConfigParser.h:193
bool startParse(char *path)
bool isOpen()
True if the configuration file is open.
Definition: ConfigParser.h:169
int lineNo
Current line number.
Definition: ConfigParser.h:198
bool optionalKvPair(char *&key, char *&value)
static void DisableMacros()
Do not allow macros inside quoted strings.
Definition: ConfigParser.h:143
static const char * CfgLine
The current line to parse.
Definition: ConfigParser.h:220
static TokenType LastTokenType
The type of last parsed element.
Definition: ConfigParser.h:219
static SBuf CurrentLocation()
Acl::Tree * optionalAclList()
parses an [if [!]<acl>...] construct
static char * RegexStrtokFile()
static const char * CfgPos
Pointer to the next element in cfgLine string.
Definition: ConfigParser.h:221
static bool RecognizeQuotedPair_
The next tokens may contain quoted-pair (-escaped) characters.
Definition: ConfigParser.h:225
void rejectDuplicateDirective()
rejects configuration due to a repeated directive
static char * NextQuotedToken()
static enum ConfigParser::ParsingStates KvPairState_
Parsing state while parsing kv-pair tokens.
Definition: ConfigParser.cc:30
static char * NextQuotedOrToEol()
static bool StrictMode
Definition: ConfigParser.h:156
std::unique_ptr< RegexPattern > regex(const char *expectedRegexDescription)
extracts and returns a regex (including any optional flags)
static std::queue< char * > CfgLineTokens_
Store the list of tokens for current configuration line.
Definition: ConfigParser.h:222
static bool ParseKvPair_
The next token will be handled as kv-pair token.
Definition: ConfigParser.h:227
static char * NextElement(TokenType &type)
Wrapper method for TokenParse.
static bool RecognizeQuotedValues
configuration_includes_quoted_values in squid.conf
Definition: ConfigParser.h:148
static char * PeekAtToken()
static std::stack< CfgFile * > CfgFiles
The stack of open cfg files.
Definition: ConfigParser.h:218
static bool ParseQuotedOrToEol_
The next tokens will be handled as quoted or to_eol token.
Definition: ConfigParser.h:224
bool skipOptional(const char *keyword)
either extracts the given (optional) token or returns false
void closeDirective()
stops parsing the current configuration directive
static char * UnQuote(const char *token, const char **next=nullptr)
static bool PreviewMode_
The next token will not popped from cfg files, will just previewd.
Definition: ConfigParser.h:226
static bool NextKvPair(char *&key, char *&value)
static bool AllowMacros_
Definition: ConfigParser.h:223
static bool LastTokenWasQuoted()
Definition: ConfigParser.h:113
static void ParseUShort(unsigned short *var)
Definition: cache_cf.cc:3127
static void ParseBool(bool *var)
Definition: cache_cf.cc:3133
static void SetCfgLine(char *line)
Set the configuration file line to parse.
static char * NextToken()
static void EnableMacros()
Allow macros inside quoted strings.
Definition: ConfigParser.h:140
static char * strtokFile()
Definition: ConfigParser.cc:64
SBuf token(const char *expectedTokenDescription)
extracts and returns a required token
static void ParseWordList(wordlist **list)
Definition: cache_cf.cc:3155
static const char * QuoteString(const String &var)
static char * TokenParse(const char *&nextToken, TokenType &type)
void destruct()
Definition: ConfigParser.cc:37
Definition: SBuf.h:94
int type
Definition: errorpage.cc:152

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors