[squid-dev] How Squid parse the configuration file?

Alex Rousskov rousskov at measurement-factory.com
Tue Feb 21 16:52:09 UTC 2017


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>> 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.
> 
> 
>     _______________________________________________
>     squid-dev mailing list
>     squid-dev at lists.squid-cache.org <mailto:squid-dev at lists.squid-cache.org>
>     http://lists.squid-cache.org/listinfo/squid-dev
>     <http://lists.squid-cache.org/listinfo/squid-dev>
> 
> 
> 
> 
> _______________________________________________
> squid-dev mailing list
> squid-dev at lists.squid-cache.org
> http://lists.squid-cache.org/listinfo/squid-dev
> 



More information about the squid-dev mailing list