Updated patch attached

ons 2011-11-09 klockan 16:03 +0100 skrev Henrik Nordström:
> sön 2011-11-06 klockan 00:39 +0000 skrev Andrew Beverley:
> 
> > Understandably, the file only appears to be read when the configuration
> > file is parsed, rather than each time the ACL is checked. However, I
> > need it to be checked more often, as I have a system configuration
> > interface that writes a day of the week to the file, which subsequently
> > causes a splash page to be shown on a particular day. I would like
> > configuration to be done without having to reload the Squid
> > configuration file.
> 
> I had a patch to squid-2 to selectively reload specific acls only to
> have them refresh their included content, reevaluate ip lookups etc.
> Never got applied as it was using the cachemgr interface and we did not
> want to add more active actions to cachemgr. But this should be
> revisited when we have a better control channel.
> 
> Regarding making FORMAT optional to external_acl_type, this is a trivial
> change, just didn't think there was any valid use of it when the
> directive was implemented. Please try the attached trunk patch which
> also adds %%{statictext} just in case someone needs to fake format
> arguments to some helper.
> 
> Regards
> Henrik

=== modified file 'src/cf.data.pre'
--- src/cf.data.pre	2011-11-08 13:40:26 +0000
+++ src/cf.data.pre	2011-11-09 14:58:06 +0000
@@ -521,7 +521,7 @@
 	This option defines external acl classes using a helper program
 	to look up the status
 
-	  external_acl_type name [options] FORMAT.. /path/to/helper [helper arguments..]
+	  external_acl_type name [options] [FORMAT..] /path/to/helper [helper arguments..]
 
 	Options:
 
@@ -593,7 +593,8 @@
 			character.
 
 	  %%		The percent sign. Useful for helpers which need
-			an unchanging input format.
+			an unchanging but not blank input format.
+	  %%{..}	Staic text
 
 	In addition to the above, any string specified in the referencing
 	acl will also be included in the helper request line, after the

=== modified file 'src/external_acl.cc'
--- src/external_acl.cc	2011-11-06 22:52:18 +0000
+++ src/external_acl.cc	2011-11-09 15:16:47 +0000
@@ -190,7 +190,7 @@
 #endif
         EXT_ACL_EXT_LOG,
         EXT_ACL_TAG,
-        EXT_ACL_PERCENT,
+        EXT_ACL_STATIC,
         EXT_ACL_END
     } type;
     external_acl_format *next;
@@ -247,7 +247,7 @@
  \param type     - format enum identifier for this element, pulled from identifying prefix
  \param format   - structure to contain all the info about this format element.
  */
-void
+static void
 parse_header_token(external_acl_format *format, char *header, const _external_acl_format::format_type type)
 {
     /* header format */
@@ -299,6 +299,27 @@
     }
 }
 
+/**
+ * Parse the External ACL format %%{.*} static token
+ *
+ \param header   - the token being parsed (without the identifying prefix)
+ \param type     - format enum identifier for this element, pulled from identifying prefix
+ \param format   - structure to contain all the info about this format element.
+ */
+static void
+parse_static_token(external_acl_format *format, char *header, const _external_acl_format::format_type type)
+{
+    /** Cut away the closing brace */
+    char *end = strchr(header, '}');
+    if (end && strlen(end) == 1)
+        *end = '\0';
+    else
+        self_destruct();
+
+    format->type = type;
+    format->header = xstrdup(header);
+}
+
 void
 parse_externalAclHelper(external_acl ** list)
 {
@@ -473,7 +494,9 @@
         else if (strcmp(token, "%TAG") == 0)
             format->type = _external_acl_format::EXT_ACL_TAG;
         else if (strcmp(token, "%%") == 0)
-            format->type = _external_acl_format::EXT_ACL_PERCENT;
+            format->type = _external_acl_format::EXT_ACL_STATIC;
+        else if (strncmp(token, "%%{", 3) == 0)
+            parse_static_token(format, (token+3), _external_acl_format::EXT_ACL_STATIC);
         else {
             debugs(0,0, "ERROR: Unknown Format token " << token);
             self_destruct();
@@ -484,10 +507,6 @@
         token = strtok(NULL, w_space);
     }
 
-    /* There must be at least one format token */
-    if (!a->format)
-        self_destruct();
-
     /* helper */
     if (!token)
         self_destruct();
@@ -1099,8 +1118,10 @@
         case _external_acl_format::EXT_ACL_TAG:
             str = request->tag.termedBuf();
             break;
-        case _external_acl_format::EXT_ACL_PERCENT:
+        case _external_acl_format::EXT_ACL_STATIC:
             str = "%";
+            if (format->header)
+                str = format->header;
             break;
         case _external_acl_format::EXT_ACL_UNKNOWN:
 

Reply via email to