]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Two new ACLs implemented: annotate_transaction and annotate_client part2
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Mon, 30 Jan 2017 14:00:24 +0000 (16:00 +0200)
committerChristos Tsantilas <chtsanti@users.sourceforge.net>
Mon, 30 Jan 2017 14:00:24 +0000 (16:00 +0200)
Add forgotten new files:
 src/acl/AnnotateClient.cc
 src/acl/AnnotateClient.h
 src/acl/AnnotateTransaction.cc
 src/acl/AnnotateTransaction.h
 src/acl/AnnotationData.cc
 src/acl/AnnotationData.h

src/acl/AnnotateClient.cc [new file with mode: 0644]
src/acl/AnnotateClient.h [new file with mode: 0644]
src/acl/AnnotateTransaction.cc [new file with mode: 0644]
src/acl/AnnotateTransaction.h [new file with mode: 0644]
src/acl/AnnotationData.cc [new file with mode: 0644]
src/acl/AnnotationData.h [new file with mode: 0644]

diff --git a/src/acl/AnnotateClient.cc b/src/acl/AnnotateClient.cc
new file mode 100644 (file)
index 0000000..2360486
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 1996-2016 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/AnnotateClient.h"
+#include "acl/AnnotationData.h"
+#include "client_side.h"
+#include "http/Stream.h"
+#include "Notes.h"
+
+int
+ACLAnnotateClientStrategy::match(ACLData<MatchType> * &data, ACLFilledChecklist *checklist, ACLFlags &flags)
+{
+    if (const auto conn = checklist->conn()) {
+        ACLAnnotationData *tdata = dynamic_cast<ACLAnnotationData*>(data);
+        assert(tdata);
+        tdata->annotate(conn->notes(), flags.delimiters(), checklist->al);
+        if (const auto request = checklist->request)
+            tdata->annotate(request->notes(), flags.delimiters(), checklist->al);
+        return 1;
+    }
+    return 0;
+}
+
+ACLAnnotateClientStrategy *
+ACLAnnotateClientStrategy::Instance()
+{
+    return &Instance_;
+}
+
+ACLAnnotateClientStrategy ACLAnnotateClientStrategy::Instance_;
+
diff --git a/src/acl/AnnotateClient.h b/src/acl/AnnotateClient.h
new file mode 100644 (file)
index 0000000..45fd666
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 1996-2016 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.
+ */
+
+#ifndef SQUID_ACLANNOTATECLIENT
+#define SQUID_ACLANNOTATECLIENT
+
+#include "acl/Strategised.h"
+#include "acl/Strategy.h"
+
+/// \ingroup ACLAPI
+class ACLAnnotateClientStrategy : public ACLStrategy<NotePairs::Entry *>
+{
+public:
+    static ACLAnnotateClientStrategy *Instance();
+    ACLAnnotateClientStrategy(ACLAnnotateClientStrategy const &) = delete;
+    ACLAnnotateClientStrategy& operator=(ACLAnnotateClientStrategy const &) = delete;
+
+    virtual bool requiresRequest() const { return true; }
+    virtual int match(ACLData<MatchType> * &, ACLFilledChecklist *, ACLFlags &);
+
+private:
+    static ACLAnnotateClientStrategy Instance_;
+    ACLAnnotateClientStrategy() { }
+};
+
+/// \ingroup ACLAPI
+class ACLAnnotateClient
+{
+private:
+    static ACL::Prototype RegistryProtoype;
+    static ACLStrategised<NotePairs::Entry *> RegistryEntry_;
+};
+
+#endif /* SQUID_ACLANNOTATECLIENT */
+
diff --git a/src/acl/AnnotateTransaction.cc b/src/acl/AnnotateTransaction.cc
new file mode 100644 (file)
index 0000000..e370958
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 1996-2016 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/AnnotateTransaction.h"
+#include "acl/AnnotationData.h"
+#include "acl/Checklist.h"
+#include "HttpRequest.h"
+#include "Notes.h"
+
+int
+ACLAnnotateTransactionStrategy::match(ACLData<MatchType> * &data, ACLFilledChecklist *checklist, ACLFlags &flags)
+{
+    if (const auto request = checklist->request) {
+        ACLAnnotationData *tdata = dynamic_cast<ACLAnnotationData*>(data);
+        assert(tdata);
+        tdata->annotate(request->notes(), flags.delimiters(), checklist->al);
+        return 1;
+    }
+    return 0;
+}
+
+ACLAnnotateTransactionStrategy *
+ACLAnnotateTransactionStrategy::Instance()
+{
+    return &Instance_;
+}
+
+ACLAnnotateTransactionStrategy ACLAnnotateTransactionStrategy::Instance_;
+
diff --git a/src/acl/AnnotateTransaction.h b/src/acl/AnnotateTransaction.h
new file mode 100644 (file)
index 0000000..cb91881
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 1996-2016 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.
+ */
+
+#ifndef SQUID_ACLANNOTATETRANSACTION
+#define SQUID_ACLANNOTATETRANSACTION
+
+#include "acl/Strategised.h"
+#include "acl/Strategy.h"
+
+/// \ingroup ACLAPI
+class ACLAnnotateTransactionStrategy : public ACLStrategy<NotePairs::Entry *>
+{
+public:
+    virtual int match(ACLData<MatchType> * &, ACLFilledChecklist *, ACLFlags &);
+    virtual bool requiresRequest() const { return true; }
+
+    static ACLAnnotateTransactionStrategy *Instance();
+    ACLAnnotateTransactionStrategy(ACLAnnotateTransactionStrategy const &) = delete;
+    ACLAnnotateTransactionStrategy& operator=(ACLAnnotateTransactionStrategy const &) = delete;
+
+private:
+    static ACLAnnotateTransactionStrategy Instance_;
+    ACLAnnotateTransactionStrategy() {}
+};
+
+/// \ingroup ACLAPI
+class ACLAnnotateTransaction
+{
+private:
+    static ACL::Prototype RegistryProtoype;
+    static ACLStrategised<NotePairs::Entry *> RegistryEntry_;
+};
+
+#endif /* SQUID_ACLANNOTATETRANSACTION */
+
diff --git a/src/acl/AnnotationData.cc b/src/acl/AnnotationData.cc
new file mode 100644 (file)
index 0000000..062afcd
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 1996-2016 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/AnnotationData.h"
+#include "acl/Checklist.h"
+#include "cache_cf.h"
+#include "ConfigParser.h"
+#include "Debug.h"
+#include "format/Format.h"
+#include "sbuf/Algorithms.h"
+
+const char *AnnotationBlackList[] = {
+    "user",
+    "group",
+    "password",
+    "status",
+    "message",
+    "log",
+    "tag",
+    "ttl",
+    "ha1",
+    "rewrite-url",
+    "url",
+    nullptr
+};
+
+ACLAnnotationData::ACLAnnotationData()
+    : notes(new Notes("annotation_data", AnnotationBlackList)) {}
+
+SBufList
+ACLAnnotationData::dump() const
+{
+    SBufList sl;
+    if (const char *strNotes = notes->toString())
+        sl.push_back(SBuf(strNotes));
+    return sl;
+}
+
+void
+ACLAnnotationData::parse()
+{
+    notes->parseKvPair();
+    if (char *t = ConfigParser::PeekAtToken()) {
+        debugs(29, DBG_CRITICAL, "FATAL: Unexpected argument '" << t << "' after annotation specification");
+        self_destruct();
+        return;
+    }
+}
+
+void
+ACLAnnotationData::annotate(NotePairs::Pointer pairs, const CharacterSet *delimiters, const AccessLogEntry::Pointer &al)
+{
+    notes->updateNotePairs(pairs, delimiters, al);
+}
+
+ACLData<NotePairs::Entry *> *
+ACLAnnotationData::clone() const
+{
+    return new ACLAnnotationData;
+}
+
diff --git a/src/acl/AnnotationData.h b/src/acl/AnnotationData.h
new file mode 100644 (file)
index 0000000..9c15ab3
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 1996-2016 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.
+ */
+
+#ifndef SQUID_ACLANNOTATIONDATA_H
+#define SQUID_ACLANNOTATIONDATA_H
+
+#include "AccessLogEntry.h"
+#include "acl/Data.h"
+#include "Notes.h"
+
+/// \ingroup ACLAPI
+class ACLAnnotationData : public ACLData<NotePairs::Entry *>
+{
+    MEMPROXY_CLASS(ACLAnnotationData);
+
+public:
+    ACLAnnotationData();
+
+    /* ACLData<M> API */
+    virtual bool match(NotePairs::Entry *) { return true; }
+    virtual SBufList dump() const;
+    virtual void parse();
+    virtual bool empty() const { return notes->empty(); }
+    virtual ACLData<NotePairs::Entry *> *clone() const;
+
+    /// Stores annotations into pairs.
+    void annotate(NotePairs::Pointer pairs, const CharacterSet *delimiters, const AccessLogEntry::Pointer &al);
+
+private:
+    Notes::Pointer notes;
+};
+
+#endif /* SQUID_ACLANNOTATIONDATA_H */
+