--------------------- PatchSet 11501 Date: 2008/02/25 23:25:24 Author: Amos Jeffries Branch: SQUID_3_0 Tag: (none) Log: Author: Adrian Chadd Author: Gonzalo Arana include directive for squid.conf This patch adds an 'include' option to squid.conf for the purpose of importing configuration details external to the squid.conf file itself see Squid 3.0 Release notes for further details. Members: doc/release-notes/release-3.0.sgml:1.30.2.1->1.30.2.2 src/cache_cf.cc:1.528.2.1->1.528.2.2 Index: squid3/doc/release-notes/release-3.0.sgml =================================================================== RCS file: /cvsroot/squid/squid3/doc/release-notes/release-3.0.sgml,v retrieving revision 1.30.2.1 retrieving revision 1.30.2.2 diff -u -r1.30.2.1 -r1.30.2.2 --- squid3/doc/release-notes/release-3.0.sgml 24 Feb 2008 10:58:12 -0000 1.30.2.1 +++ squid3/doc/release-notes/release-3.0.sgml 25 Feb 2008 23:25:24 -0000 1.30.2.2 @@ -2,7 +2,7 @@
Squid 3.0.RC1 release notes Squid Developers -$Id: release-3.0.sgml,v 1.30.2.1 2008/02/24 10:58:12 amosjeffries Exp $ +$Id: release-3.0.sgml,v 1.30.2.2 2008/02/25 23:25:24 amosjeffries Exp $ This document contains the release notes for version 3.0 of Squid. @@ -326,6 +326,21 @@ to Squid until a full HTTP request has been received. See the accf_http(9) man page. + + include +

New option to import entire secondary configuration files into squid.conf. + + Squid will follow the files immediately and insert all their content + as if it was at that position in squid.conf. As per squid.conf some + options are order-specific within the config as a whole. + + A few layers of include are allowed, but too many are confusing and + squid will enforce an include depth of 16 files. + + Syntax: + include /path/to/file1 /path/to/file2 + + Index: squid3/src/cache_cf.cc =================================================================== RCS file: /cvsroot/squid/squid3/src/cache_cf.cc,v retrieving revision 1.528.2.1 retrieving revision 1.528.2.2 diff -u -r1.528.2.1 -r1.528.2.2 --- squid3/src/cache_cf.cc 25 Feb 2008 03:01:00 -0000 1.528.2.1 +++ squid3/src/cache_cf.cc 25 Feb 2008 23:25:25 -0000 1.528.2.2 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.528.2.1 2008/02/25 03:01:00 amosjeffries Exp $ + * $Id: cache_cf.cc,v 1.528.2.2 2008/02/25 23:25:25 amosjeffries Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -151,6 +151,8 @@ static void parse_b_size_t(size_t * var); static void parse_b_int64_t(int64_t * var); +static int parseOneConfigFile(const char *file_name, unsigned int depth); + /* * LegacyParser is a parser for legacy code that uses the global * approach. This is static so that it is only exposed to cache_cf. @@ -203,17 +205,37 @@ return s; } -int -parseConfigFile(const char *file_name, CacheManager & manager) +static int +parseManyConfigFiles(char* files, int depth) +{ + int error_count = 0; + char* tmp = files; + char* file = strtok(tmp, w_space); + while (file != NULL) { + tmp += strlen(file) +1; + error_count += parseOneConfigFile(file, depth); + file = strtok(tmp, w_space); + } + return error_count; +} + +static int +parseOneConfigFile(const char *file_name, unsigned int depth) { FILE *fp = NULL; + const char *orig_cfg_filename = cfg_filename; + const int orig_config_lineno = config_lineno; char *token = NULL; char *tmp_line = NULL; int tmp_line_len = 0; int err_count = 0; int is_pipe = 0; - configFreeMemory(); - default_all(); + + debugs(3, 1, "Processing Configuration File: " << file_name << " (depth " << depth << ")"); + if (depth > 16) { + fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name); + return 1; + } if (file_name[0] == '!' || file_name[0] == '|') { fp = popen(file_name + 1, "r"); @@ -223,8 +245,7 @@ } if (fp == NULL) - fatalf("Unable to open configuration file: %s: %s", - file_name, xstrerror()); + fatalf("Unable to open configuration file: %s: %s", file_name, xstrerror()); #ifdef _SQUID_WIN32_ @@ -270,13 +291,6 @@ *token = '\0'; cfg_filename = new_file_name; - -#if PROBABLY_NOT_WANTED_HERE - - SetConfigFilename(cfg_filename, false); - -#endif - } config_lineno = new_lineno; @@ -306,11 +320,13 @@ debugs(3, 5, "Processing: '" << tmp_line << "'"); - if (!parse_line(tmp_line)) { - debugs(3, 0, "parseConfigFile: '" << cfg_filename << "' line " << - config_lineno << " unrecognized: '" << config_input_line << "'"); - err_count++; - } + /* Handle includes here */ + if (tmp_line_len >= 9 && strncmp(tmp_line, "include", 7) == 0 && xisspace(tmp_line[7])) { + err_count += parseManyConfigFiles(tmp_line + 8, depth + 1); + } else if (!parse_line(tmp_line)) { + debugs(3, 0, HERE << cfg_filename << ":" << config_lineno << " unrecognized: '" << tmp_line << "'"); + err_count++; + } safe_free(tmp_line); tmp_line_len = 0; @@ -326,6 +342,23 @@ fclose(fp); } + cfg_filename = orig_cfg_filename; + config_lineno = orig_config_lineno; + + return err_count; +} + +int +parseConfigFile(const char *file_name, CacheManager & manager) +{ + int err_count = 0; + + configFreeMemory(); + + default_all(); + + err_count = parseOneConfigFile(file_name, 0); + defaults_if_none(); /* @@ -351,6 +384,7 @@ return err_count; } + static void configDoConfigure(void) {