On 7/08/2013 9:11 p.m., Tsantilas Christos wrote:
Hi all,

I am attaching a new patch which try to handle the reported problems.

Just adding a new method which do special parsing for tokens like the
regex has many effects, for example the ConfigParser::TokenUndo
mechanism can not work.

This patch:
   1) By default disables quoted tokens
("configuration_includes_quoted_values off")

   2) If configuration_includes_quoted_values is off the quoted tokens
parsed using the ConfigParser::NextToken include the quotes, to keep
compatibility with older releases.

  3) For the cases where quoted strings are required (wordlists, Notes
parsing, Headers with acl), the new ConfigParser::NextQuotedToken method
added.
    The old wordlists parser allowed escaping any character, this patch
will return an error if you try to escape alphanumeric characters. The
\r \n and \t have the C semantics.

  4) Add the ConfigParser::RegexPattern() to get the next regex token

  5) Add the ConfigParser::RegexStrtokFile() to get the next regex token
which is compatible with the old strtokFile

  6) Removes the ConfigParser::TokenUndo method. The new method
ConfigParser::NextTokenPreview() which can be used to preview the next
token is added. This method if the next token is invalid (eg unquoted
with special characters) return as token the "SQUID_ERROR_TOKEN" (we do
not want to call self_destruct while previewing next element).

  7) In this patch I kept the ConfigParser::TokenPutBack method which is
used in only one place (acl regex). However this method should removed
in the future, with the ConfigParser::Undo_ member and the
ConfigParser::Undo() method


Notes
======
1) The current trunk parser read a line, and the tokens stored in this
line and the line modified while parsed. This patch consider the line we
are parsing as const and stores parsed tokens to
ConfigParser::CfgLineTokens_ std::queue:
   - we may need to parse again the line (NextTokenPreview/NextToken) so
we do not want to modify it
   - The current line tokens must stored somewhere to support the following:
    char *name = ConfigParser::NextToken();
    char *value = ConfigParser::NextToken();
The ConfigParser::CfgLineTokens_ emptied every time new config line is read.

2) A set of new flags defined under ConfigParser class to define the
type of parsing: ParseRegex_ (next token is regex)  ParseQuotedOrToEOL_
(next token is quoted or to-EOL), PreviewMode_ (just do preview do not
pop token)
This method is not the best, but it is not so bad....

3) The goal of new parser was to have a small and simple parser, but now
looks very complex. But it very is difficult to keep compatibility with
a simple parser.
Probably we will need to re-implement it after the old configuration
file style support removed from squid.


Audit results:

* the "Bungled (#1)" and "Bungled (#2)" are still there. Please remove the "(#1)" and "(#2)" first thing.


I got about halfway through today. I hopefully will have some more time tomorrow.

Amos

Reply via email to