ConfigParser.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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 CachePeer;
23class wordlist;
24
33#define CONFIG_LINE_LIMIT 2048
34
46{
47
48public:
54
55 void destruct();
56
58 void closeDirective();
59
62
64 SBuf token(const char *expectedTokenDescription);
65
69 bool optionalKvPair(char * &key, char * &value);
70
72 bool skipOptional(const char *keyword);
73
76
78 std::unique_ptr<RegexPattern> regex(const char *expectedRegexDescription);
79
81 CachePeer &cachePeer(const char *peerNameTokenDescription);
82
83 static void ParseUShort(unsigned short *var);
84 static void ParseBool(bool *var);
85 static const char *QuoteString(const String &var);
86 static void ParseWordList(wordlist **list);
87
93 static char * strtokFile();
94
101 static char *NextToken();
102
108 static char *RegexStrtokFile();
109
114 static char *NextQuotedToken();
115
118
124 static char *NextQuotedOrToEol();
125
130 static bool NextKvPair(char * &key, char * &value);
131
138 static char *PeekAtToken();
139
141 static void SetCfgLine(char *line);
142
144 static void EnableMacros() {AllowMacros_ = true;}
145
147 static void DisableMacros() {AllowMacros_ = false;}
148
149 static SBuf CurrentLocation();
150
153
160 static bool StrictMode;
161
162protected:
168 {
169 public:
170 CfgFile(): wordFile(nullptr), parsePos(nullptr), lineNo(0) { parseBuffer[0] = '\0';}
171 ~CfgFile();
173 bool isOpen() {return wordFile != nullptr;}
174
179 bool startParse(char *path);
180
187 char *parse(TokenType &type);
188
189 private:
190 bool getFileLine();
195 char *nextElement(TokenType &type);
196 FILE *wordFile;
198 const char *parsePos;
199 public:
200 std::string filePath;
201 std::string currentLine;
202 int lineNo;
203 };
204
209 static char *UnQuote(const char *token, const char **next = nullptr);
210
218 static char *TokenParse(const char * &nextToken, TokenType &type);
219
221 static char *NextElement(TokenType &type);
222 static std::stack<CfgFile *> CfgFiles;
224 static const char *CfgLine;
225 static const char *CfgPos;
226 static std::queue<char *> CfgLineTokens_;
227 static bool AllowMacros_;
230 static bool PreviewMode_;
231 static bool ParseKvPair_;
233};
234
235int parseConfigFile(const char *file_name);
236
237#endif /* SQUID_CONFIGPARSER_H */
238
int parseConfigFile(const char *file_name)
Definition: cache_cf.cc:635
#define CONFIG_LINE_LIMIT
Definition: ConfigParser.h:33
Definition: Tree.h:21
char * nextElement(TokenType &type)
std::string currentLine
The current line to parse.
Definition: ConfigParser.h:201
std::string filePath
The file path.
Definition: ConfigParser.h:200
FILE * wordFile
Pointer to the file.
Definition: ConfigParser.h:196
char * parse(TokenType &type)
const char * parsePos
The next element position in parseBuffer string.
Definition: ConfigParser.h:198
bool getFileLine()
Read the next line from the file.
char parseBuffer[CONFIG_LINE_LIMIT]
Temporary buffer to store data to parse.
Definition: ConfigParser.h:197
bool startParse(char *path)
bool isOpen()
True if the configuration file is open.
Definition: ConfigParser.h:173
int lineNo
Current line number.
Definition: ConfigParser.h:202
bool optionalKvPair(char *&key, char *&value)
static void DisableMacros()
Do not allow macros inside quoted strings.
Definition: ConfigParser.h:147
static const char * CfgLine
The current line to parse.
Definition: ConfigParser.h:224
static TokenType LastTokenType
The type of last parsed element.
Definition: ConfigParser.h:223
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:225
static bool RecognizeQuotedPair_
The next tokens may contain quoted-pair (-escaped) characters.
Definition: ConfigParser.h:229
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:31
static char * NextQuotedOrToEol()
static bool StrictMode
Definition: ConfigParser.h:160
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:226
static bool ParseKvPair_
The next token will be handled as kv-pair token.
Definition: ConfigParser.h:231
static char * NextElement(TokenType &type)
Wrapper method for TokenParse.
static bool RecognizeQuotedValues
configuration_includes_quoted_values in squid.conf
Definition: ConfigParser.h:152
static char * PeekAtToken()
static std::stack< CfgFile * > CfgFiles
The stack of open cfg files.
Definition: ConfigParser.h:222
static bool ParseQuotedOrToEol_
The next tokens will be handled as quoted or to_eol token.
Definition: ConfigParser.h:228
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:230
static bool NextKvPair(char *&key, char *&value)
static bool AllowMacros_
Definition: ConfigParser.h:227
static bool LastTokenWasQuoted()
Definition: ConfigParser.h:117
static void ParseUShort(unsigned short *var)
Definition: cache_cf.cc:3106
CachePeer & cachePeer(const char *peerNameTokenDescription)
extracts a cache_peer name token and returns the corresponding CachePeer
static void ParseBool(bool *var)
Definition: cache_cf.cc:3112
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:144
static char * strtokFile()
Definition: ConfigParser.cc:65
SBuf token(const char *expectedTokenDescription)
extracts and returns a required token
static void ParseWordList(wordlist **list)
Definition: cache_cf.cc:3134
static const char * QuoteString(const String &var)
static char * TokenParse(const char *&nextToken, TokenType &type)
void destruct()
Definition: ConfigParser.cc:38
Definition: SBuf.h:94

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors