#include <ConfigParser.h>

Collaboration diagram for ConfigParser:


class  CfgFile

Public Types

enum  TokenType {

Public Member Functions

void destruct ()

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 * RegexPattern ()
static char * NextQuotedToken ()
static bool LastTokenWasQuoted ()
static char * NextQuotedOrToEol ()
static bool NextKvPair (char *&key, char *&value)
static char * PeekAtToken ()
static void TokenPutBack (const char *token)
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 {

Static Protected Member Functions

static char * Undo ()
 Return the last TokenPutBack() queued element or NULL if none exist. More...
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 std::queue< std::string > Undo_
 The list with TokenPutBack() queued elements. 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 41 of file ConfigParser.h.

Member Enumeration Documentation

◆ ParsingStates


Definition at line 217 of file ConfigParser.h.

◆ TokenType

Parsed tokens type: simple tokens, quoted tokens or function like parameters.


Definition at line 49 of file ConfigParser.h.

Member Function Documentation

◆ CurrentLocation()

SBuf ConfigParser::CurrentLocation ( )

◆ destruct()

◆ DisableMacros()

static void ConfigParser::DisableMacros ( )

◆ EnableMacros()

static void ConfigParser::EnableMacros ( )

◆ LastTokenWasQuoted()

static bool ConfigParser::LastTokenWasQuoted ( )
true if the last parsed token was quoted

Definition at line 92 of file ConfigParser.h.

References LastTokenType, and QuotedToken.

Referenced by Notes::parse(), parse_AuthSchemes(), parse_HeaderWithAclList(), and Notes::parseKvPair().

◆ NextElement()

char * ConfigParser::NextElement ( ConfigParser::TokenType type)

Definition at line 350 of file ConfigParser.cc.

References CfgPos, FunctionParameters, PreviewMode_, TokenParse(), and type.

Referenced by NextToken(), and strtokFile().

◆ NextKvPair()

bool ConfigParser::NextKvPair ( char *&  key,
char *&  value 

the next key value pair which must be separated by "="

true on success, false otherwise

Definition at line 458 of file ConfigParser.cc.

References atParseKey, atParseValue, DBG_CRITICAL, debugs, KvPairState_, NextQuotedToken(), NextToken(), NULL, and ParseKvPair_.

Referenced by Acl::OptionExtractor::advance(), parse_UrlHelperTimeout(), Notes::parseKvPair(), and MessageDelayConfig::parseResponseDelayPool().

◆ NextQuotedOrToEol()

char * ConfigParser::NextQuotedOrToEol ( )
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 440 of file ConfigParser.cc.

References CfgFiles, NextToken(), and ParseQuotedOrToEol_.

Referenced by IcmpConfig::parse(), Auth::SchemeConfig::parse(), parse_eol(), parse_http_header_replace(), parse_obsolete(), Log::LogConfig::parseFormats(), and Format::FmtConfig::parseFormats().

◆ NextQuotedToken()

char * ConfigParser::NextQuotedToken ( )

Parse the next token with support for quoted values enabled even if the configuration_includes_quoted_values is set to off

Definition at line 506 of file ConfigParser.cc.

References NextToken(), and RecognizeQuotedValues.

Referenced by NextKvPair(), Auth::SchemeConfig::parse(), Notes::parse(), parse_AuthSchemes(), parse_cachemgrpasswd(), parse_HeaderWithAclList(), parse_SBufList(), parse_TokenOrQuotedString(), and parse_wordlist().

◆ NextToken()

char * ConfigParser::NextToken ( )

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 365 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 Undo().

Referenced by aclParseAccessLine(), aclParseDenyInfoLine(), Acl::OptionExtractor::advance(), HttpUpgradeProtocolAccess::configureGuard(), testConfigParser::doParseQuotedTest(), GetInteger(), GetInteger64(), GetPercentage(), GetService(), GetShort(), NextKvPair(), NextQuotedOrToEol(), NextQuotedToken(), DelaySpec::parse(), ACLHasComponentData::parse(), ACLSquidErrorData::parse(), Adaptation::ServiceConfig::parse(), Adaptation::ServiceGroup::parse(), Store::Disks::Parse(), Notes::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(), Log::LogConfig::parseFormats(), Format::FmtConfig::parseFormats(), Store::Disk::parseOptions(), parsePortCfg(), MessageDelayConfig::parseResponseDelayPool(), MessageDelayConfig::parseResponseDelayPoolAccess(), parseTimeLine(), ParseUrlRewriteTimeout(), PeekAtToken(), RegexPattern(), and strtokFile().

◆ ParseBool()

void ConfigParser::ParseBool ( bool *  var)

Definition at line 3128 of file cache_cf.cc.

References GetInteger(), and self_destruct().

◆ ParseUShort()

◆ ParseWordList()

void ConfigParser::ParseWordList ( wordlist **  list)

Definition at line 3150 of file cache_cf.cc.

References parse_wordlist().

Referenced by Adaptation::ServiceGroup::parse().

◆ PeekAtToken()

char * ConfigParser::PeekAtToken ( )

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 431 of file ConfigParser.cc.

References NextToken(), and PreviewMode_.

Referenced by Acl::OptionExtractor::advance(), ACLHasComponentData::parse(), ACLAnnotationData::parse(), parse_access_log(), parse_ftp_epsv(), parse_pipelinePrefetch(), parseTimeLine(), and ParseUrlRewriteTimeout().

◆ QuoteString()

const char * ConfigParser::QuoteString ( const String var)

◆ RegexPattern()

char * ConfigParser::RegexPattern ( )

Parse the next token as a regex pattern. The regex patterns are non quoted tokens.

Definition at line 493 of file ConfigParser.cc.

References DBG_CRITICAL, debugs, NextToken(), RecognizeQuotedPair_, RecognizeQuotedValues, and self_destruct().

Referenced by parse_refreshpattern().

◆ RegexStrtokFile()

char * ConfigParser::RegexStrtokFile ( )

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 480 of file ConfigParser.cc.

References DBG_CRITICAL, debugs, RecognizeQuotedPair_, RecognizeQuotedValues, self_destruct(), and strtokFile().

Referenced by ACLRegexData::parse().

◆ SetCfgLine()

void ConfigParser::SetCfgLine ( char *  line)

◆ strtokFile()

◆ TokenParse()

char * ConfigParser::TokenParse ( const char *&  nextToken,
ConfigParser::TokenType type 

Does the real tokens parsing job: Ignore comments, unquote an element if required.

the next token, or NULL if there are no available tokens in the nextToken string.
nextTokenupdated to point to the pos after parsed token.
typeThe token type

Definition at line 254 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, type, UnQuote(), w_space, xstrdup, and xstrndup().

Referenced by ConfigParser::CfgFile::nextElement(), and NextElement().

◆ TokenPutBack()

void ConfigParser::TokenPutBack ( const char *  token)

The next NextToken call will return the token as next element It can be used repeatedly to add more than one tokens in a FIFO list.

Definition at line 63 of file ConfigParser.cc.

References assert, and Undo_.

Referenced by Acl::OptionsParser::parse().

◆ Undo()

char * ConfigParser::Undo ( )

Definition at line 70 of file ConfigParser.cc.

References CONFIG_LINE_LIMIT, NULL, PreviewMode_, Undo_, and xstrncpy().

Referenced by NextToken(), and strtokFile().

◆ UnQuote()

char * ConfigParser::UnQuote ( const char *  token,
const char **  next = NULL 

Unquotes the token, which must be quoted.

nextif it is not NULL, it is set after the end of token.

Definition at line 161 of file ConfigParser.cc.

References AllowMacros_, assert, CONFIG_LINE_LIMIT, DBG_CRITICAL, debugs, LOCAL_ARRAY, NULL, PreviewMode_, self_destruct(), SQUID_ERROR_TOKEN, w_space, and xstrncpy().

Referenced by TokenParse().

Member Data Documentation

◆ AllowMacros_

bool ConfigParser::AllowMacros_ = false

Definition at line 212 of file ConfigParser.h.

Referenced by DisableMacros(), EnableMacros(), and UnQuote().

◆ CfgFiles

std::stack< ConfigParser::CfgFile * > ConfigParser::CfgFiles

Definition at line 206 of file ConfigParser.h.

Referenced by destruct(), NextQuotedOrToEol(), and NextToken().

◆ CfgLine

const char * ConfigParser::CfgLine = NULL

Definition at line 208 of file ConfigParser.h.

Referenced by SetCfgLine().

◆ CfgLineTokens_

std::queue< char * > ConfigParser::CfgLineTokens_

Definition at line 210 of file ConfigParser.h.

Referenced by SetCfgLine(), and TokenParse().

◆ CfgPos

const char * ConfigParser::CfgPos = NULL

Definition at line 209 of file ConfigParser.h.

Referenced by NextElement(), and SetCfgLine().

◆ KvPairState_

ConfigParser::ParsingStates ConfigParser::KvPairState_ = ConfigParser::atParseKey

Definition at line 29 of file ConfigParser.cc.

Referenced by NextKvPair(), and TokenParse().

◆ LastTokenType

ConfigParser::TokenType ConfigParser::LastTokenType = ConfigParser::SimpleToken

Definition at line 207 of file ConfigParser.h.

Referenced by LastTokenWasQuoted(), and NextToken().

◆ ParseKvPair_

bool ConfigParser::ParseKvPair_ = false

Definition at line 216 of file ConfigParser.h.

Referenced by NextKvPair(), and TokenParse().

◆ ParseQuotedOrToEol_

bool ConfigParser::ParseQuotedOrToEol_ = false

Definition at line 213 of file ConfigParser.h.

Referenced by NextQuotedOrToEol(), and TokenParse().

◆ PreviewMode_

bool ConfigParser::PreviewMode_ = false

◆ RecognizeQuotedPair_

bool ConfigParser::RecognizeQuotedPair_ = false

Definition at line 214 of file ConfigParser.h.

Referenced by RegexPattern(), RegexStrtokFile(), and TokenParse().

◆ RecognizeQuotedValues

◆ StrictMode

bool ConfigParser::StrictMode = true

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 141 of file ConfigParser.h.

Referenced by free_configuration_includes_quoted_values(), parse_configuration_includes_quoted_values(), and TokenParse().

◆ Undo_

std::queue< std::string > ConfigParser::Undo_

Definition at line 211 of file ConfigParser.h.

Referenced by TokenPutBack(), and Undo().

The documentation for this class was generated from the following files:






Web Site Translations