#include <ConfigParser.h>

Classes | |
class | CfgFile |
Public Types | |
enum | TokenType { SimpleToken, QuotedToken, FunctionParameters } |
Public Member Functions | |
void | destruct () |
void | closeDirective () |
stops parsing the current configuration directive More... | |
void | rejectDuplicateDirective () |
rejects configuration due to a repeated directive More... | |
SBuf | token (const char *expectedTokenDescription) |
extracts and returns a required token More... | |
bool | optionalKvPair (char *&key, char *&value) |
bool | skipOptional (const char *keyword) |
either extracts the given (optional) token or returns false More... | |
Acl::Tree * | optionalAclList () |
parses an [if [!]<acl>...] construct More... | |
std::unique_ptr< RegexPattern > | regex (const char *expectedRegexDescription) |
extracts and returns a regex (including any optional flags) More... | |
Static Public Member Functions | |
static void | ParseUShort (unsigned short *var) |
static void | ParseBool (bool *var) |
static const char * | QuoteString (const String &var) |
static void | ParseWordList (wordlist **list) |
static char * | strtokFile () |
static char * | NextToken () |
static char * | RegexStrtokFile () |
static char * | NextQuotedToken () |
static bool | LastTokenWasQuoted () |
static char * | NextQuotedOrToEol () |
static bool | NextKvPair (char *&key, char *&value) |
static char * | PeekAtToken () |
static void | SetCfgLine (char *line) |
Set the configuration file line to parse. More... | |
static void | EnableMacros () |
Allow macros inside quoted strings. More... | |
static void | DisableMacros () |
Do not allow macros inside quoted strings. More... | |
static SBuf | CurrentLocation () |
Static Public Attributes | |
static bool | RecognizeQuotedValues = true |
configuration_includes_quoted_values in squid.conf More... | |
static bool | StrictMode = true |
Protected Types | |
enum | ParsingStates { atParseKey, atParseValue } |
Static Protected Member Functions | |
static char * | UnQuote (const char *token, const char **next=NULL) |
static char * | TokenParse (const char *&nextToken, TokenType &type) |
static char * | NextElement (TokenType &type) |
Wrapper method for TokenParse. More... | |
Static Protected Attributes | |
static std::stack< CfgFile * > | CfgFiles |
The stack of open cfg files. More... | |
static TokenType | LastTokenType = ConfigParser::SimpleToken |
The type of last parsed element. More... | |
static const char * | CfgLine = NULL |
The current line to parse. More... | |
static const char * | CfgPos = NULL |
Pointer to the next element in cfgLine string. More... | |
static std::queue< char * > | CfgLineTokens_ |
Store the list of tokens for current configuration line. More... | |
static bool | AllowMacros_ = false |
static bool | ParseQuotedOrToEol_ = false |
The next tokens will be handled as quoted or to_eol token. More... | |
static bool | RecognizeQuotedPair_ = false |
The next tokens may contain quoted-pair (-escaped) characters. More... | |
static bool | PreviewMode_ = false |
The next token will not popped from cfg files, will just previewd. More... | |
static bool | ParseKvPair_ = false |
The next token will be handled as kv-pair token. More... | |
static enum ConfigParser::ParsingStates | KvPairState_ = ConfigParser::atParseKey |
Parsing state while parsing kv-pair tokens. More... | |
Detailed Description
A configuration file Parser. Instances of this class track parsing state and perform tokenisation. Syntax is currently taken care of outside this class.
One reason for this class is to allow testing of configuration using modules without linking cache_cf.o in - because that drags in all of squid by reference. Instead the tokeniser only is brought in.
Definition at line 44 of file ConfigParser.h.
Member Enumeration Documentation
◆ ParsingStates
|
protected |
Enumerator | |
---|---|
atParseKey | |
atParseValue |
Definition at line 228 of file ConfigParser.h.
◆ TokenType
Parsed tokens type: simple tokens, quoted tokens or function like parameters.
Enumerator | |
---|---|
SimpleToken | |
QuotedToken | |
FunctionParameters |
Definition at line 52 of file ConfigParser.h.
Member Function Documentation
◆ closeDirective()
void ConfigParser::closeDirective | ( | ) |
Definition at line 548 of file ConfigParser.cc.
References assert, cfg_directive, Here, PeekAtToken(), and ToSBuf().
Referenced by ParseDirective().
◆ CurrentLocation()
|
static |
Definition at line 215 of file ConfigParser.cc.
References cfg_directive, cfg_filename, config_lineno, and ToSBuf().
Referenced by aclParseDenyInfoLine(), parseOneConfigFile(), parseTimeLine(), ParseUrlRewriteTimeout(), and token().
◆ destruct()
void ConfigParser::destruct | ( | ) |
Definition at line 37 of file ConfigParser.cc.
References cfg_filename, CfgFiles, config_input_line, config_lineno, ConfigParser::CfgFile::currentLine, fatalf(), ConfigParser::CfgFile::filePath, ConfigParser::CfgFile::lineNo, and shutting_down.
Referenced by ACL::ParseAclLine(), and self_destruct().
◆ DisableMacros()
|
inlinestatic |
Definition at line 143 of file ConfigParser.h.
References AllowMacros_.
Referenced by Notes::parse(), parse_externalAclHelper(), parse_HeaderWithAclList(), and Log::LogConfig::parseFormats().
◆ EnableMacros()
|
inlinestatic |
Definition at line 140 of file ConfigParser.h.
References AllowMacros_.
Referenced by Notes::parse(), parse_externalAclHelper(), parse_HeaderWithAclList(), and Log::LogConfig::parseFormats().
◆ LastTokenWasQuoted()
|
inlinestatic |
- Returns
- true if the last parsed token was quoted
Definition at line 113 of file ConfigParser.h.
References LastTokenType, and QuotedToken.
Referenced by Notes::parse(), parse_AuthSchemes(), parse_HeaderWithAclList(), and Notes::parseKvPair().
◆ NextElement()
|
staticprotected |
Definition at line 317 of file ConfigParser.cc.
References CfgPos, FunctionParameters, PreviewMode_, token(), TokenParse(), and type.
Referenced by NextToken(), and strtokFile().
◆ NextKvPair()
|
static |
the next key value pair which must be separated by "="
- Returns
- true on success, false otherwise
Definition at line 447 of file ConfigParser.cc.
References atParseKey, atParseValue, DBG_CRITICAL, debugs, KvPairState_, NextQuotedToken(), NextToken(), NULL, and ParseKvPair_.
Referenced by Acl::OptionExtractor::advance(), optionalKvPair(), parse_cache_log_message(), parse_UrlHelperTimeout(), Notes::parseKvPair(), and MessageDelayConfig::parseResponseDelayPool().
◆ NextQuotedOrToEol()
|
static |
- Returns
- the next quoted string or the raw string data until the end of line. This method allows macros in unquoted strings to keep compatibility for the logformat option.
Definition at line 403 of file ConfigParser.cc.
References CfgFiles, NextToken(), ParseQuotedOrToEol_, and token().
Referenced by IcmpConfig::parse(), Auth::SchemeConfig::parse(), parse_eol(), parse_http_header_replace(), parse_obsolete(), Format::FmtConfig::parseFormats(), and Log::LogConfig::parseFormats().
◆ NextQuotedToken()
|
static |
Parse the next token with support for quoted values enabled even if the configuration_includes_quoted_values is set to off
Definition at line 507 of file ConfigParser.cc.
References NextToken(), RecognizeQuotedValues, and token().
Referenced by NextKvPair(), Notes::parse(), Auth::SchemeConfig::parse(), parse_AuthSchemes(), parse_cachemgrpasswd(), parse_HeaderWithAclList(), parse_SBufList(), parse_TokenOrQuotedString(), and parse_wordlist().
◆ NextToken()
|
static |
Returns the body of the next element. The element is either a token or a quoted string with optional escape sequences and/or macros. The body of a quoted string element does not include quotes or escape sequences. Future code will want to see Elements and not just their bodies.
Definition at line 332 of file ConfigParser.cc.
References assert, CfgFiles, DBG_CRITICAL, debugs, ConfigParser::CfgFile::filePath, FunctionParameters, ConfigParser::CfgFile::isOpen(), LastTokenType, NextElement(), NULL, ConfigParser::CfgFile::parse(), PreviewMode_, QuotedToken, self_destruct(), SimpleToken, ConfigParser::CfgFile::startParse(), and token().
Referenced by aclParseAccessLine(), aclParseDenyInfoLine(), Acl::OptionExtractor::advance(), HttpUpgradeProtocolAccess::configureGuard(), testConfigParser::doParseQuotedTest(), GetInteger(), GetInteger64(), GetPercentage(), GetService(), GetShort(), NextKvPair(), NextQuotedOrToEol(), NextQuotedToken(), Adaptation::ServiceConfig::parse(), Adaptation::ServiceGroup::parse(), DelaySpec::parse(), Notes::parse(), Store::Disks::Parse(), parse_access_log(), parse_acl_tos(), parse_address(), parse_authparam(), parse_CpuAffinityMap(), parse_externalAclHelper(), parse_ftp_epsv(), parse_HeaderWithAclList(), parse_hostdomaintype(), parse_http_header_access(), parse_http_header_replace(), parse_icap_service_failure_limit(), parse_IpAddress_list(), parse_memcachemode(), parse_on_unsupported_protocol(), parse_onoff(), parse_peer(), parse_peer_access(), parse_pipelinePrefetch(), parse_refreshpattern(), parse_securePeerOptions(), parse_sslproxy_cert_adapt(), parse_sslproxy_cert_sign(), parse_sslproxy_ssl_bump(), parse_string(), parse_tristate(), parse_uri_whitespace(), parse_wccp2_amethod(), parse_wccp2_method(), parse_wccp2_service(), parse_wccp2_service_info(), Adaptation::Config::ParseAccess(), ACL::ParseAclLine(), parseBytesLine(), parseBytesLine64(), parseBytesLineSigned(), Helper::ChildConfig::parseConfig(), Ip::Qos::Config::parseConfigLine(), Format::FmtConfig::parseFormats(), Log::LogConfig::parseFormats(), Store::Disk::parseOptions(), parsePortCfg(), MessageDelayConfig::parseResponseDelayPool(), MessageDelayConfig::parseResponseDelayPoolAccess(), parseTimeLine(), ParseUrlRewriteTimeout(), PeekAtToken(), skipOptional(), strtokFile(), and token().
◆ optionalAclList()
Acl::Tree * ConfigParser::optionalAclList | ( | ) |
Definition at line 581 of file ConfigParser.cc.
References aclParseAclList(), assert, cfg_directive, Here, and skipOptional().
Referenced by Security::KeyLog::KeyLog().
◆ optionalKvPair()
bool ConfigParser::optionalKvPair | ( | char *& | key, |
char *& | value | ||
) |
extracts an optional key=value token or returns false rejects configurations with empty keys or empty values key and value have lifetime of the current line/directive
Definition at line 421 of file ConfigParser.cc.
References Here, NextKvPair(), PeekAtToken(), and ToSBuf().
Referenced by FormattedLog::parseOptions().
◆ ParseBool()
|
static |
Definition at line 3140 of file cache_cf.cc.
References GetInteger(), and self_destruct().
◆ ParseUShort()
|
static |
Definition at line 3134 of file cache_cf.cc.
References GetShort().
Referenced by parse_u_short(), DelayConfig::parsePoolAccess(), DelayConfig::parsePoolClass(), ClientDelayConfig::parsePoolCount(), DelayConfig::parsePoolCount(), ClientDelayConfig::parsePoolId(), and DelayConfig::parsePoolRates().
◆ ParseWordList()
|
static |
Definition at line 3162 of file cache_cf.cc.
References parse_wordlist().
Referenced by Adaptation::ServiceGroup::parse().
◆ PeekAtToken()
|
static |
Preview the next token. The next NextToken() and strtokFile() call will return the same token. On parse error (eg invalid characters in token) will return an error message as token.
Definition at line 394 of file ConfigParser.cc.
References NextToken(), PreviewMode_, and token().
Referenced by Acl::OptionExtractor::advance(), closeDirective(), optionalKvPair(), ACLAnnotationData::parse(), parse_access_log(), parse_ftp_epsv(), parse_pipelinePrefetch(), parseTimeLine(), ParseUrlRewriteTimeout(), and skipOptional().
◆ QuoteString()
|
static |
Definition at line 517 of file ConfigParser.cc.
References String::append(), String::clean(), and String::termedBuf().
Referenced by testConfigParser::doParseQuotedTest(), and Note::dump().
◆ regex()
std::unique_ptr< RegexPattern > ConfigParser::regex | ( | const char * | expectedRegexDescription | ) |
Definition at line 482 of file ConfigParser.cc.
References Here, RecognizeQuotedPair_, RecognizeQuotedValues, REG_EXTENDED, REG_ICASE, REG_NOSUB, and token().
Referenced by parse_refreshpattern().
◆ RegexStrtokFile()
|
static |
Backward compatibility wrapper for ConfigParser::RegexPattern method. If the configuration_includes_quoted_values configuration parameter is set to 'off' this interprets the quoted tokens as filenames.
Definition at line 469 of file ConfigParser.cc.
References DBG_CRITICAL, debugs, RecognizeQuotedPair_, RecognizeQuotedValues, self_destruct(), strtokFile(), and token().
Referenced by ACLRegexData::parse().
◆ rejectDuplicateDirective()
void ConfigParser::rejectDuplicateDirective | ( | ) |
Definition at line 541 of file ConfigParser.cc.
References assert, cfg_directive, and Here.
Referenced by ParseDirective().
◆ SetCfgLine()
|
static |
Definition at line 203 of file ConfigParser.cc.
References CfgLine, CfgLineTokens_, CfgPos, and token().
Referenced by testConfigParser::doParseQuotedTest(), testRock::setUp(), setup_scheme(), testACLMaxUserIP::testParseLine(), testUfs::testUfsDefaultEngine(), and testUfs::testUfsSearch().
◆ skipOptional()
bool ConfigParser::skipOptional | ( | const char * | keyword | ) |
Definition at line 567 of file ConfigParser.cc.
References assert, NextToken(), and PeekAtToken().
Referenced by optionalAclList().
◆ strtokFile()
|
static |
Backward compatibility wrapper for the ConfigParser::NextToken method. If the configuration_includes_quoted_values configuration parameter is set to 'off' this interprets the quoted tokens as filenames.
Definition at line 64 of file ConfigParser.cc.
References CONFIG_LINE_LIMIT, DBG_CRITICAL, debugs, NextElement(), NextToken(), NULL, O_TEXT, RecognizeQuotedValues, and w_space.
Referenced by aclParseHTTPStatusList(), Acl::InnerNode::lineParse(), ACLAdaptationServiceData::parse(), ACLARP::parse(), ACLASN::parse(), ACLAtStepData::parse(), ACLCertificateData::parse(), Acl::ConnectionsEncrypted::parse(), ACLDomainData::parse(), ACLEui64::parse(), ACLHierCodeData::parse(), ACLHTTPHeaderData::parse(), ACLIntRange::parse(), ACLIP::parse(), ACLMaxConnection::parse(), ACLMethodData::parse(), ACLNoteData::parse(), ACLProtocolData::parse(), ACLRandom::parse(), ACLSquidErrorData::parse(), ACLSslErrorData::parse(), ACLStringData::parse(), ACLTimeData::parse(), Acl::TransactionInitiator::parse(), ACLUserData::parse(), ACLMaxUserIP::parse(), ACLExternal::parse(), Acl::ConnMark::parse(), ACLHasComponentData::parse(), and RegexStrtokFile().
◆ token()
SBuf ConfigParser::token | ( | const char * | expectedTokenDescription | ) |
Definition at line 557 of file ConfigParser.cc.
References CurrentLocation(), debugs, Here, NextToken(), and ToSBuf().
Referenced by Security::KeyLog::KeyLog(), ConfigParser::CfgFile::nextElement(), NextElement(), NextQuotedOrToEol(), NextQuotedToken(), NextToken(), ConfigParser::CfgFile::parse(), PeekAtToken(), regex(), RegexStrtokFile(), SetCfgLine(), TokenParse(), and UnQuote().
◆ TokenParse()
|
staticprotected |
Does the real tokens parsing job: Ignore comments, unquote an element if required.
- Returns
- the next token, or NULL if there are no available tokens in the nextToken string.
- Parameters
-
nextToken updated to point to the pos after parsed token. type The token type
Definition at line 221 of file ConfigParser.cc.
References atParseKey, CfgLineTokens_, DBG_CRITICAL, debugs, FunctionParameters, KvPairState_, NULL, ParseKvPair_, ParseQuotedOrToEol_, PreviewMode_, QuotedToken, RecognizeQuotedPair_, RecognizeQuotedValues, self_destruct(), SimpleToken, SQUID_ERROR_TOKEN, StrictMode, token(), type, UnQuote(), w_space, xstrdup, and xstrndup().
Referenced by ConfigParser::CfgFile::nextElement(), and NextElement().
◆ UnQuote()
|
staticprotected |
Unquotes the token, which must be quoted.
- Parameters
-
next if it is not NULL, it is set after the end of token.
Definition at line 138 of file ConfigParser.cc.
References assert, CONFIG_LINE_LIMIT, DBG_CRITICAL, debugs, LOCAL_ARRAY, NULL, PreviewMode_, self_destruct(), SQUID_ERROR_TOKEN, token(), w_space, and xstrncpy().
Referenced by TokenParse().
Member Data Documentation
◆ AllowMacros_
|
staticprotected |
Definition at line 223 of file ConfigParser.h.
Referenced by DisableMacros(), and EnableMacros().
◆ CfgFiles
|
staticprotected |
Definition at line 218 of file ConfigParser.h.
Referenced by destruct(), NextQuotedOrToEol(), and NextToken().
◆ CfgLine
|
staticprotected |
Definition at line 220 of file ConfigParser.h.
Referenced by SetCfgLine().
◆ CfgLineTokens_
|
staticprotected |
Definition at line 222 of file ConfigParser.h.
Referenced by SetCfgLine(), and TokenParse().
◆ CfgPos
|
staticprotected |
Definition at line 221 of file ConfigParser.h.
Referenced by NextElement(), and SetCfgLine().
◆ KvPairState_
|
staticprotected |
Definition at line 30 of file ConfigParser.cc.
Referenced by NextKvPair(), and TokenParse().
◆ LastTokenType
|
staticprotected |
Definition at line 219 of file ConfigParser.h.
Referenced by LastTokenWasQuoted(), and NextToken().
◆ ParseKvPair_
|
staticprotected |
Definition at line 227 of file ConfigParser.h.
Referenced by NextKvPair(), and TokenParse().
◆ ParseQuotedOrToEol_
|
staticprotected |
Definition at line 224 of file ConfigParser.h.
Referenced by NextQuotedOrToEol(), and TokenParse().
◆ PreviewMode_
|
staticprotected |
Definition at line 226 of file ConfigParser.h.
Referenced by ConfigParser::CfgFile::nextElement(), NextElement(), NextToken(), PeekAtToken(), TokenParse(), and UnQuote().
◆ RecognizeQuotedPair_
|
staticprotected |
Definition at line 225 of file ConfigParser.h.
Referenced by regex(), RegexStrtokFile(), and TokenParse().
◆ RecognizeQuotedValues
|
static |
Definition at line 148 of file ConfigParser.h.
Referenced by dump_configuration_includes_quoted_values(), free_configuration_includes_quoted_values(), NextQuotedToken(), parse_configuration_includes_quoted_values(), regex(), RegexStrtokFile(), strtokFile(), and TokenParse().
◆ StrictMode
|
static |
Strict syntax mode. Does not allow not alphanumeric characters in unquoted tokens. Controlled by the configuration_includes_quoted_values in squid.conf but remains false when the the legacy ConfigParser::NextQuotedToken() call forces RecognizeQuotedValues to be temporary true.
Definition at line 156 of file ConfigParser.h.
Referenced by free_configuration_includes_quoted_values(), parse_configuration_includes_quoted_values(), and TokenParse().
The documentation for this class was generated from the following files:
- src/ConfigParser.h
- src/cache_cf.cc
- src/ConfigParser.cc