[squid-dev] How Squid parse the configuration file?
Alex Rousskov
rousskov at measurement-factory.com
Wed Feb 22 04:46:15 UTC 2017
On 02/21/2017 08:22 PM, 周书林 wrote:
> And one more question, is there any checking mechanism for validity of
> config value?
Sure, most parsers check the tokens/strings they parse. The checks are
specific to the directive type and are often not comprehensive (e.g.,
may miss garbage after a valid token).
> For example, if config option "maximum_object_size_in_memory" is set as
> 10000, how to check if this value is valid?
Sorry, I do not understand the question. To find how existing parsers
check values, just examine the corresponding parser code.
For example, my previous email shows how to find the
maximum_object_size_in_memory parsing function (called parse_b_size_t).
Examining that function will lead you to parseBytesLine() and the
functions/methods it calls, including syntax checking code.
HTH,
Alex.
> 2017-02-22 0:52 GMT+08:00 Alex Rousskov:
>
> On 02/21/2017 01:15 AM, 周书林 wrote:
> > I found the src/cf.data.pre file, and read the content. But I still want
> > to know how squid use this file to build the connection between the
> > config file and the source code.
>
> As you already know, the parser is generated. The generated code either
> places parsed values directly into the global Config object or calls
> some helper functions that update the global state. (Updating global
> state during parsing is very wrong but that is a different story.)
>
> If you want to see the actual generated parsing code for a given
> squid.conf directive, just grep for it! For example,
>
> $ fgrep -A5 -RI maximum_object_size_in_memory src
>
> will point you to the following code in src/cf_parser.cci:
>
> > src/cf_parser.cci: if (!strcmp(token,
> "maximum_object_size_in_memory")) {
> > src/cf_parser.cci: cfg_directive =
> "maximum_object_size_in_memory";
> > src/cf_parser.cci-
> parse_b_size_t(&Config.Store.maxInMemObjSize);
> > src/cf_parser.cci- cfg_directive = NULL;
> > src/cf_parser.cci- return 1;
>
>
> How was that code generated? Search for "cfg_directive = NULL" to find
> the parser generator code in the repository:
>
> $ bzr grep 'cfg_directive = NULL'
>
> > src/cf_gen.cc: fout << " cfg_directive = NULL;" <<
> std::endl;
>
> which will point you to the Entry::genParseAlias() method.
>
>
> HTH,
>
> Alex.
>
>
>
> > 2017-01-13 22:14 GMT+08:00 Stuart Henderson:
> >
> > On 2017-01-13, 周书林 <zhoushulin1992 at gmail.com
> <mailto:zhoushulin1992 at gmail.com>
> > <mailto:zhoushulin1992 at gmail.com <mailto:zhoushulin1992 at gmail.com>>> wrote:
> > > Why some of the configuration directives in official website cannot find in
> > > the source code? Some could find a relevant program variable in Class
> > > SquidConfig, while majority of the configuration directives cannot be found
> > > in the source code, for example , directive "announce_port".
> > > So how does Squid parse the configuration file of Users, and use them in
> > > the source code?
> >
> > The parser, sample config, etc, are all generated from src/cf.data.pre.
> >
More information about the squid-dev
mailing list