]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix log escape selection mechanism to properly handle quoting of
authorhno <>
Fri, 2 Sep 2005 01:34:46 +0000 (01:34 +0000)
committerhno <>
Fri, 2 Sep 2005 01:34:46 +0000 (01:34 +0000)
multiple format elements.

src/access_log.cc
src/cf.data.pre

index 14c054ba055e7e5b3e2a532b753184dfcfa6a6c4..b41d4fc59da65e5ed4db07e60b0c058da61a0b48 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: access_log.cc,v 1.102 2005/08/31 19:15:35 wessels Exp $
+ * $Id: access_log.cc,v 1.103 2005/09/01 19:34:46 hno Exp $
  *
  * DEBUG: section 46    Access Log
  * AUTHOR: Duane Wessels
@@ -881,7 +881,7 @@ accessLogCustom(AccessLogEntry * al, customlog * log)
  * def is for sure null-terminated
  */
 static int
-accessLogGetNewLogFormatToken(logformat_token * lt, char *def, char *last)
+accessLogGetNewLogFormatToken(logformat_token * lt, char *def, enum log_quote *quote)
 {
     char *cur = def;
 
@@ -898,8 +898,36 @@ accessLogGetNewLogFormatToken(logformat_token * lt, char *def, char *last)
         xstrncpy(cp, cur, l + 1);
         lt->type = LFT_STRING;
         lt->data.string = cp;
-        *last = cur[l - 1];
-        cur += l;
+
+        while (l > 0) {
+            switch(*cur) {
+
+            case '"':
+
+                if (*quote == LOG_QUOTE_NONE)
+                    *quote = LOG_QUOTE_QUOTES;
+                else if (*quote == LOG_QUOTE_QUOTES)
+                    *quote = LOG_QUOTE_NONE;
+
+                break;
+
+            case '[':
+                if (*quote == LOG_QUOTE_NONE)
+                    *quote = LOG_QUOTE_BRAKETS;
+
+                break;
+
+            case ']':
+                if (*quote == LOG_QUOTE_BRAKETS)
+                    *quote = LOG_QUOTE_NONE;
+
+                break;
+            }
+
+            cur++;
+            l--;
+        }
+
         goto done;
     }
 
@@ -929,6 +957,10 @@ accessLogGetNewLogFormatToken(logformat_token * lt, char *def, char *last)
         lt->quote = LOG_QUOTE_URL;
         cur++;
         break;
+
+    default:
+        lt->quote = *quote;
+        break;
     }
 
     if (*cur == '-') {
@@ -975,13 +1007,6 @@ accessLogGetNewLogFormatToken(logformat_token * lt, char *def, char *last)
                def);
     }
 
-    if (!lt->quote) {
-        if (*last == '"' && *cur == '"')
-            lt->quote = LOG_QUOTE_QUOTES;
-        else if (*last == '[' && *cur == ']')
-            lt->quote = LOG_QUOTE_BRAKETS;
-    }
-
     if (*cur == ' ') {
         lt->space = 1;
         cur++;
@@ -1056,7 +1081,7 @@ accessLogParseLogFormat(logformat_token ** fmt, char *def)
 {
     char *cur, *eos;
     logformat_token *new_lt, *last_lt;
-    char last = '\0';
+    enum log_quote quote = LOG_QUOTE_NONE;
 
     debug(46, 1) ("accessLogParseLogFormat: got definition '%s'\n", def);
 
@@ -1067,13 +1092,13 @@ accessLogParseLogFormat(logformat_token ** fmt, char *def)
     cur = def;
     eos = def + strlen(def);
     *fmt = new_lt = last_lt = (logformat_token *)xmalloc(sizeof(logformat_token));
-    cur += accessLogGetNewLogFormatToken(new_lt, cur, &last);
+    cur += accessLogGetNewLogFormatToken(new_lt, cur, &quote);
 
     while (cur < eos) {
         new_lt = (logformat_token *)xmalloc(sizeof(logformat_token));
         last_lt->next = new_lt;
         last_lt = new_lt;
-        cur += accessLogGetNewLogFormatToken(new_lt, cur, &last);
+        cur += accessLogGetNewLogFormatToken(new_lt, cur, &quote);
     }
 
     return 1;
index a05b570d43bf24dd7bcf6c966fefdcd9bca9ad89..f774fc258444dbf364acb53ce8938e20a349536e 100644 (file)
@@ -1,6 +1,6 @@
 
 #
-# $Id: cf.data.pre,v 1.392 2005/08/14 18:43:40 serassio Exp $
+# $Id: cf.data.pre,v 1.393 2005/09/01 19:34:46 hno Exp $
 #
 #
 # SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -1181,17 +1181,18 @@ DOC_START
        The <format specification> is a string with embedded % format codes
 
        % format codes all follow the same basic structure where all but
-       the formatcode is optional. Output strings are automatically quoted
+       the formatcode is optional. Output strings are automatically escaped
        as required according to their context and the output format
-       modifiers are usually unneeded but can be specified if an explicit
-       quoting format is desired.
+       modifiers are usually not needed, but can be specified if an explicit
+       output format is desired.
 
                % ["|[|'|#] [-] [[0]width] [{argument}] formatcode
 
-               "       quoted string output format
-               [       squid log quoted format as used by log_mime_hdrs
-               #       URL quoted output format
-               '       No automatic quoting
+               "       output in quoted string format
+               [       output in squid text log format as used by log_mime_hdrs
+               #       output in URL quoted format
+               '       output as-is
+
                -       left aligned
                width   field width. If starting with 0 the
                        output is zero padded