]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Added httpHeaderQuoteString() to quote strings using HTTP rules.
authorAlex Rousskov <rousskov@measurement-factory.com>
Wed, 28 Aug 2013 23:21:45 +0000 (17:21 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Wed, 28 Aug 2013 23:21:45 +0000 (17:21 -0600)
src/HttpHeaderTools.cc

index 588f1c6902ef2ef76a44bd83908b6bde96e04901..45ca24d8d2354b852c6d3a00bd45c31973f384e1 100644 (file)
@@ -299,6 +299,36 @@ httpHeaderParseQuotedString(const char *start, const int len, String *val)
     return 1;
 }
 
+// TODO: Optimize using SBuf
+String
+httpHeaderQuoteString(const char *raw)
+{
+    assert(raw);
+
+    // HTTPbis says Senders SHOULD NOT escape octets in quoted-strings that
+    // do not require escaping (i.e., except DQUOTE and the backslash octet).
+    bool needInnerQuote = false;
+    for (const char *s = raw; !needInnerQuote &&  *s; ++s)
+        needInnerQuote = *s == '"' || *s == '\\';
+
+    static String quotedStr;
+    quotedStr.clean();
+    quotedStr.append('"');
+
+    if (needInnerQuote) {
+        for (const char *s = raw; *s; ++s) {
+            if (*s == '"' || *s == '\\')
+                quotedStr.append('\\');
+            quotedStr.append(*s);
+        }
+    } else {
+        quotedStr.append(raw);
+    }
+    
+    quotedStr.append('"');
+    return quotedStr;
+}
+
 /**
  * Checks the anonymizer (header_access) configuration.
  *