]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/acl/NoteData.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / NoteData.cc
index cb8b0322078b523807947341522465f8be805ee3..f34ac5bf120d7407b2447e72a5d5e3f8e910a539 100644 (file)
@@ -1,13 +1,19 @@
+/*
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
 #include "squid.h"
 #include "acl/Acl.h"
 #include "acl/Checklist.h"
 #include "acl/NoteData.h"
 #include "acl/StringData.h"
-#include "cache_cf.h"
 #include "ConfigParser.h"
 #include "Debug.h"
-#include "HttpRequest.h"
-#include "Notes.h"
+#include "sbuf/StringConvert.h"
 #include "wordlist.h"
 
 ACLNoteData::ACLNoteData() : values(new ACLStringData)
@@ -19,53 +25,35 @@ ACLNoteData::~ACLNoteData()
 }
 
 bool
-ACLNoteData::matchNotes(NotePairs *note)
+ACLNoteData::match(NotePairs::Entry *entry)
 {
-    if (note == NULL)
-        return false;
-
-    debugs(28, 3, "Checking " << name);
+    if (entry->name.cmp(name.termedBuf()) != 0)
+        return false; // name mismatch
 
-    if (values->empty())
-        return (note->findFirst(name.termedBuf()) != NULL);
-
-    for (std::vector<NotePairs::Entry *>::iterator i = note->entries.begin(); i!= note->entries.end(); ++i) {
-        if ((*i)->name.cmp(name.termedBuf()) == 0) {
-            if (values->match((*i)->value.termedBuf()))
-                return true;
-        }
-    }
-    return false;
+    // a name-only note ACL matches any value; others require a values match
+    return values->empty() ||
+           values->match(entry->value.termedBuf());
 }
 
-bool
-ACLNoteData::match(HttpRequest *request)
+SBufList
+ACLNoteData::dump() const
 {
-    if (request->notes != NULL && matchNotes(request->notes.getRaw()))
-        return true;
-#if USE_ADAPTATION
-    const Adaptation::History::Pointer ah = request->adaptLogHistory();
-    if (ah != NULL && ah->metaHeaders != NULL && matchNotes(ah->metaHeaders.getRaw()))
-        return true;
+    SBufList sl;
+    sl.push_back(StringToSBuf(name));
+#if __cplusplus >= 201103L
+    sl.splice(sl.end(), values->dump());
+#else
+    // temp is needed until c++11 move constructor
+    SBufList temp = values->dump();
+    sl.splice(sl.end(), temp);
 #endif
-    return false;
-}
-
-wordlist *
-ACLNoteData::dump()
-{
-    wordlist *W = NULL;
-    wordlistAdd(&W, name.termedBuf());
-    wordlist * dumpR = values->dump();
-    wordlistAddWl(&W, dumpR);
-    wordlistDestroy(&dumpR);
-    return W;
+    return sl;
 }
 
 void
 ACLNoteData::parse()
 {
-    char* t = strtokFile();
+    char* t = ConfigParser::strtokFile();
     assert (t != NULL);
     name = t;
     values->parse();
@@ -77,11 +65,13 @@ ACLNoteData::empty() const
     return name.size() == 0;
 }
 
-ACLData<HttpRequest *> *
+ACLData<NotePairs::Entry *> *
 ACLNoteData::clone() const
 {
     ACLNoteData * result = new ACLNoteData;
-    result->values = values->clone();
+    result->values = dynamic_cast<ACLStringData*>(values->clone());
+    assert(result->values);
     result->name = name;
     return result;
 }
+