]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Adrian Chadd <adrian@creative.net.au>, Gonzalo Arana <gonzalo.arana@gmail...
authoramosjeffries <>
Fri, 11 Jan 2008 09:38:58 +0000 (09:38 +0000)
committeramosjeffries <>
Fri, 11 Jan 2008 09:38:58 +0000 (09:38 +0000)
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.1 Release notes for further details.

doc/release-notes/release-3.1.html
doc/release-notes/release-3.1.man
doc/release-notes/release-3.1.sgml
src/cache_cf.cc

index 39c4fbc5679a72a146212ca9c36f978fdb775515..5afdc230b0aff9d1f962a75e6ac847599a56cb76 100644 (file)
@@ -7,7 +7,7 @@
 <BODY>
 <H1>Squid 3.1.PRE1 release notes</H1>
 
-<H2>Squid Developers</H2>$Id: release-3.1.html,v 1.2 2008/01/11 02:33:34 amosjeffries Exp $
+<H2>Squid Developers</H2>$Id: release-3.1.html,v 1.3 2008/01/11 02:38:58 amosjeffries Exp $
 <HR>
 <EM>This document contains the release notes for version 3.1 of Squid.
 Squid is a WWW Cache application developed by the National Laboratory
@@ -165,6 +165,23 @@ Squid will follow a policy of prefering IPv6 links, keeping the IPv4 only as a s
         
 </PRE>
 </P>
+
+<DT><B>include</B><DD>
+<P>New option to import entire secondary configuration files into squid.conf.
+<PRE>
+        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
+        
+</PRE>
+</P>
+
 </DL>
 </P>
 
index 21538a86b1545e5c3fa2c49f8f7de9c473301598..2eb458621a945d0a1f7da003b485aa1c745a2efe 100644 (file)
@@ -1,4 +1,4 @@
-Squid 3.1.PRE1 release notesSquid Developers$Id: release-3.1.man,v 1.2 2008/01/11 02:33:34 amosjeffries Exp $This document contains the release notes for version 3.1 of Squid.
+Squid 3.1.PRE1 release notesSquid Developers$Id: release-3.1.man,v 1.3 2008/01/11 02:38:58 amosjeffries Exp $This document contains the release notes for version 3.1 of Squid.
 Squid is a WWW Cache application developed by the National Laboratory
 for Applied Network Research and members of the Web Caching community.Notice
 
@@ -203,6 +203,31 @@ Squid will follow a policy of prefering IPv6 links, keeping the IPv4 only as a s
 .ec
 .ft P
 .sp
+.Pp
+.IP "include"
+.nr bi 1
+.Pp
+New option to import entire secondary configuration files into squid.conf.
+.DS
+.sp 
+.ft RR
+.nf
+        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
+        
+.DE
+.fi 
+.ec
+.ft P
+.sp
+.Pp
 .if \n(ll>1 .RE
 .nr ll -1
 .Pp
index abf097784e9c7685e25c54d6bbf0cd16856ed56b..f83dd7a4992b61f34c272da93fa8ab1e14bdae29 100644 (file)
@@ -2,7 +2,7 @@
 <article>\r
 <title>Squid 3.1.PRE1 release notes</title>\r
 <author>Squid Developers</author>\r
-<date>$Id: release-3.1.sgml,v 1.2 2008/01/11 02:33:34 amosjeffries Exp $</date>\r
+<date>$Id: release-3.1.sgml,v 1.3 2008/01/11 02:38:58 amosjeffries Exp $</date>\r
 \r
 <abstract>\r
 This document contains the release notes for version 3.1 of Squid.\r
@@ -151,6 +151,21 @@ This section gives a thorough account of those changes in three categories:
                 *) Doubles the load placed by squid on the DNS network.\r
                 *) May negatively impact connection delay times.\r
         </verb>\r
+\r
+       <tag>include</tag>\r
+       <p>New option to import entire secondary configuration files into squid.conf.\r
+       <verb>\r
+       Squid will follow the files immediately and insert all their content\r
+       as if it was at that position in squid.conf. As per squid.conf some\r
+       options are order-specific within the config as a whole.\r
+\r
+       A few layers of include are allowed, but too many are confusing and\r
+       squid will enforce an include depth of 16 files.\r
+\r
+       Syntax:\r
+               include /path/to/file1 /path/to/file2\r
+       </verb>\r
+\r
 </descrip>\r
 \r
 \r
index bef3b352074dc19fca5b42f0de9536ff9b11d0de..cc8f3e559d0b13edb0930df6785b92f816e36120 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cache_cf.cc,v 1.532 2007/12/29 18:20:22 hno Exp $
+ * $Id: cache_cf.cc,v 1.533 2008/01/11 02:38:59 amosjeffries Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -151,6 +151,8 @@ static int check_null_https_port_list(const https_port_list *);
 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 @@ skip_ws(const char* s)
     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 @@ parseConfigFile(const char *file_name, CacheManager & manager)
     }
 
     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 @@ parseConfigFile(const char *file_name, CacheManager & manager)
                     *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 @@ parseConfigFile(const char *file_name, CacheManager & manager)
 
         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 @@ parseConfigFile(const char *file_name, CacheManager & manager)
         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 @@ parseConfigFile(const char *file_name, CacheManager & manager)
     return err_count;
 }
 
+
 static void
 configDoConfigure(void)
 {