]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Logformat annotation fixes
authorChristos Tsantilas <chtsanti@users.sourceforge.net>
Wed, 30 Apr 2014 09:41:25 +0000 (12:41 +0300)
committerChristos Tsantilas <chtsanti@users.sourceforge.net>
Wed, 30 Apr 2014 09:41:25 +0000 (12:41 +0300)
Currently note values printed with "%note" formating code, which contain non
alphanumeric characters, were quoted and quotes were then escaped, resulting
in bizarre logged rendition of empty or simple values (often received from
various helpers):
      %22-%22
      %22Default_Google%22
      %22pg13,US%22

This patch:
- does not use quotes to print annotations

- allow system admin to define a separator to use for logged
  annotations. The %note logformat accepts the following argument:
     [name][:separator]
  The separator can be one of the ',' ';' or ':'.
  By default, multiple note values are separated with "," and multiple
  notes are separated with "\r\n". When logging named notes with
  %{name}note, the explicitly configured separator is used between note
  values. When logging all notes with %note, the explicitly configured
  separator is used between individual notes. There is currently no way to
  specify both value and notes separators when logging all notes with %note.

- makes the Format::Token::data a struct (now is a union) and initialize
  Format::Token::data data members in Format::Token::Token constructor.

This is a Measurement Factory project

src/Notes.cc
src/Notes.h
src/cf.data.pre
src/format/Format.cc
src/format/Token.cc
src/format/Token.h

index 3a93ee3e5c49814f7eecad530e7e9029cf0121bf..15e4defc8ab6d30de0b341e3801893f47d6714e7 100644 (file)
@@ -158,15 +158,15 @@ NotePairs::~NotePairs()
 }
 
 const char *
-NotePairs::find(const char *noteKey) const
+NotePairs::find(const char *noteKey, const char *sep) const
 {
     static String value;
     value.clean();
     for (std::vector<NotePairs::Entry *>::const_iterator  i = entries.begin(); i != entries.end(); ++i) {
         if ((*i)->name.cmp(noteKey) == 0) {
             if (value.size())
-                value.append(", ");
-            value.append(ConfigParser::QuoteString((*i)->value));
+                value.append(sep);
+            value.append((*i)->value);
         }
     }
     return value.size() ? value.termedBuf() : NULL;
@@ -180,7 +180,7 @@ NotePairs::toString(const char *sep) const
     for (std::vector<NotePairs::Entry *>::const_iterator  i = entries.begin(); i != entries.end(); ++i) {
         value.append((*i)->name);
         value.append(": ");
-        value.append(ConfigParser::QuoteString((*i)->value));
+        value.append((*i)->value);
         value.append(sep);
     }
     return value.size() ? value.termedBuf() : NULL;
index 274d3bb145e72cfe4c993eca10cf0978aeeb6f90..6fc0c71538434f8e690cf7db8bc0912f352e22bb 100644 (file)
@@ -145,7 +145,7 @@ public:
      * Returns a comma separated list of notes with key 'noteKey'.
      * Use findFirst instead when a unique kv-pair is needed.
      */
-    const char *find(const char *noteKey) const;
+    const char *find(const char *noteKey, const char *sep = ",") const;
 
     /**
      * Returns the first note value for this key or an empty string.
index 42ac0fbcfbb56b4045f8f64c41c77802b5fb5686..41e68db95081bbea85644bc239feb541fc2beb5e 100644 (file)
@@ -3739,10 +3739,22 @@ DOC_START
                err_code    The ID of an error response served by Squid or
                                a similar internal error identifier.
                err_detail  Additional err_code-dependent error information.
-               note    The meta header specified by the argument. Also
+               note    The annotation specified by the argument. Also
                        logs the adaptation meta headers set by the
                        adaptation_meta configuration parameter.
-                       If no argument given all meta headers logged.
+                       If no argument given all annotations logged.
+                       The argument may include a separator to use with
+                       annotation values:
+                            name[:separator]
+                       By default, multiple note values are separated with ","
+                       and multiple notes are separated with "\r\n".
+                       When logging named notes with %{name}note, the
+                       explicitly configured separator is used between note
+                       values. When logging all notes with %note, the
+                       explicitly configured separator is used between
+                       individual notes. There is currently no way to
+                       specify both value and notes separators when logging
+                       all notes with %note.
 
        Connection related format codes:
 
index 2cc39d07788aa00b823eefe3910f6b09e612fec0..3102da07e8948da0646b5e788aa5944378445653 100644 (file)
@@ -1102,31 +1102,36 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS
 #endif
 
         case LFT_NOTE:
-            if (fmt->data.string) {
+            tmp[0] = fmt->data.header.separator;
+            tmp[1] = '\0';
+            if (fmt->data.header.header && *fmt->data.header.header) {
+                const char *separator = tmp;
 #if USE_ADAPTATION
                 Adaptation::History::Pointer ah = al->request ? al->request->adaptHistory() : Adaptation::History::Pointer();
                 if (ah != NULL && ah->metaHeaders != NULL) {
-                    if (const char *meta = ah->metaHeaders->find(fmt->data.string))
+                    if (const char *meta = ah->metaHeaders->find(fmt->data.header.header, separator))
                         sb.append(meta);
                 }
 #endif
                 if (al->notes != NULL) {
-                    if (const char *note = al->notes->find(fmt->data.string)) {
+                    if (const char *note = al->notes->find(fmt->data.header.header, separator)) {
                         if (sb.size())
-                            sb.append(", ");
+                            sb.append(separator);
                         sb.append(note);
                     }
                 }
                 out = sb.termedBuf();
                 quote = 1;
             } else {
+                // if no argument given use default "\r\n" as notes separator
+                const char *separator = fmt->data.string ? tmp : "\r\n";
 #if USE_ADAPTATION
                 Adaptation::History::Pointer ah = al->request ? al->request->adaptHistory() : Adaptation::History::Pointer();
                 if (ah != NULL && ah->metaHeaders != NULL && !ah->metaHeaders->empty())
-                    sb.append(ah->metaHeaders->toString());
+                    sb.append(ah->metaHeaders->toString(separator));
 #endif
                 if (al->notes != NULL && !al->notes->empty())
-                    sb.append(al->notes->toString());
+                    sb.append(al->notes->toString(separator));
 
                 out = sb.termedBuf();
                 quote = 1;
index 8799769a453b996becae59fb45bc613c40978ed8..cc831a9f532b1470120a5aac16b12ae8f667fb98 100644 (file)
@@ -407,6 +407,8 @@ done:
 
     case LFT_REPLY_HEADER:
 
+    case LFT_NOTE:
+
         if (data.string) {
             char *header = data.string;
             char *cp = strchr(header, ':');
@@ -541,6 +543,25 @@ done:
     return (cur - def);
 }
 
+Format::Token::Token() : type(LFT_NONE),
+                         label(NULL),
+                         widthMin(-1),
+                         widthMax(-1),
+                         quote(LOG_QUOTE_NONE),
+                         left(false),
+                         space(false),
+                         zero(false),
+                         divisor(1),
+                         next(NULL)
+{
+    data.string = NULL;
+    data.header.header = NULL; 
+    data.header.element = NULL;
+    data.header.separator = ',';
+}
+
+
+
 Format::Token::~Token()
 {
     label = NULL; // drop reference to global static.
index f8b3c6226490c8acefac0b08491e3ccc2b4f04e4..a50c38a722e10e3eb17aeff52924d80fca7d72e6 100644 (file)
@@ -27,18 +27,7 @@ class TokenTableEntry;
 class Token
 {
 public:
-    Token() : type(LFT_NONE),
-            label(NULL),
-            widthMin(-1),
-            widthMax(-1),
-            quote(LOG_QUOTE_NONE),
-            left(false),
-            space(false),
-            zero(false),
-            divisor(1),
-            next(NULL)
-    { data.string = NULL; }
-
+    Token();
     ~Token();
 
     /// Initialize the format token registrations
@@ -52,7 +41,7 @@ public:
 
     ByteCode_t type;
     const char *label;
-    union {
+    struct {
         char *string;
 
         struct {