--------------------- PatchSet 6463 Date: 2008/01/08 07:11:21 Author: amosjeffries Branch: ayjwork Tag: (none) Log: Author: Adrian Chadd Port include squid.conf directive from squid2-HEAD Adrian has coded a sub-file 'include' directive for use in squid2. It was planned for inclusion in squid 3.1 later, but now is good if it works. Members: src/cache_cf.cc:1.79.2.12->1.79.2.13 Index: squid3/src/cache_cf.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/cache_cf.cc,v retrieving revision 1.79.2.12 retrieving revision 1.79.2.13 diff -u -r1.79.2.12 -r1.79.2.13 --- squid3/src/cache_cf.cc 8 Jan 2008 06:08:54 -0000 1.79.2.12 +++ squid3/src/cache_cf.cc 8 Jan 2008 07:11:21 -0000 1.79.2.13 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.79.2.12 2008/01/08 06:08:54 amosjeffries Exp $ + * $Id: cache_cf.cc,v 1.79.2.13 2008/01/08 07:11:21 amosjeffries Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -204,16 +204,22 @@ } int -parseConfigFile(const char *file_name, CacheManager & manager) +parseOneConfigFile(const char *file_name, unsigned int depth, CacheManager & manager) { FILE *fp = NULL; + const char *orig_cfg_filename = cfg_filename; + int orig_config_line = 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(); + + debug(3, 1) ("Including Configuration File: %s (depth %d)\n", file_name, depth); + if (depth > 16) { + debug(0, 0) ("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 +229,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 +275,6 @@ *token = '\0'; cfg_filename = new_file_name; - -#if PROBABLY_NOT_WANTED_HERE - - SetConfigFilename(cfg_filename, false); - -#endif - } config_lineno = new_lineno; @@ -288,6 +286,17 @@ if (config_input_line[0] == '\0') continue; + /* Handle includes here */ + if (strlen(config_input_line) >= 9 && strncmp(config_input_line, "include", 7) == 0 && (config_input_line[8] == ' ' || config_input_line[8] == '\t')) { + for (i = 8; i < strlen(config_input_line) && (config_input_line[i] == ' ' || config_input_line[i] == '\t'); i++); + if (i >= strlen(config_input_line)) { + debug(3, 1) ("WARNING: include at %s:%d is bad\n", file_name, config_lineno); + continue; + } + err_count += parseOneConfigFile(config_input_line + i, depth + 1); + continue; + } + const char* append = tmp_line_len ? skip_ws(config_input_line) : config_input_line; size_t append_len = strlen(append); @@ -326,6 +335,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, 1, manager); + defaults_if_none(); /* @@ -351,6 +377,7 @@ return err_count; } + static void configDoConfigure(void) {