#include "acl/ExtUser.h"
#include "acl/FilledChecklist.h"
#include "acl/Gadgets.h"
+#include "acl/HierCodeData.h"
+#include "acl/HierCode.h"
#include "acl/HttpHeaderData.h"
#include "acl/HttpRepHeader.h"
#include "acl/HttpReqHeader.h"
ACLExtUser ACLExtUser::UserRegistryEntry_(new ACLUserData, "ext_user");
ACL::Prototype ACLExtUser::RegexRegistryProtoype(&ACLExtUser::RegexRegistryEntry_, "ext_user_regex" );
ACLExtUser ACLExtUser::RegexRegistryEntry_(new ACLRegexData, "ext_user_regex");
+ACL::Prototype ACLHierCode::RegistryProtoype(&ACLHierCode::RegistryEntry_, "hier_code");
+ACLStrategised<hier_code> ACLHierCode::RegistryEntry_(new ACLHierCodeData, ACLHierCodeStrategy::Instance(), "hier_code");
ACL::Prototype ACLHTTPRepHeader::RegistryProtoype(&ACLHTTPRepHeader::RegistryEntry_, "rep_header");
ACLStrategised<HttpHeader*> ACLHTTPRepHeader::RegistryEntry_(new ACLHTTPHeaderData, ACLHTTPRepHeaderStrategy::Instance(), "rep_header");
ACL::Prototype ACLHTTPReqHeader::RegistryProtoype(&ACLHTTPReqHeader::RegistryEntry_, "req_header");
#ifndef SQUID_HTTPHIERARCHYLOGENTRY_H
#define SQUID_HTTPHIERARCHYLOGENTRY_H
+#include "hier_code.h"
#include "rfc2181.h"
#include "PingData.h"
-/** todo Cleanup: break hier_code type out. We don't need the rest. */
+/* for lookup_t and http_status */
#include "enums.h"
class HierarchyLogEntry
gopher.cc \
helper.cc \
helper.h \
+ hier_code.h \
+ hier_code.cc \
HierarchyLogEntry.h \
$(HTCPSOURCE) \
http.cc \
fqdncache.cc \
ftp.cc \
gopher.cc \
+ hier_code.h \
+ hier_code.cc \
helper.cc \
$(HTCPSOURCE) \
http.cc \
fqdncache.cc \
ftp.cc \
gopher.cc \
+ hier_code.h \
+ hier_code.cc \
helper.cc \
$(HTCPSOURCE) \
http.cc \
ftp.cc \
gopher.cc \
helper.cc \
+ hier_code.h \
+ hier_code.cc \
$(HTCPSOURCE) \
http.cc \
HttpBody.cc \
ftp.cc \
gopher.cc \
helper.cc \
+ hier_code.h \
+ hier_code.cc \
$(HTCPSOURCE) \
http.cc \
HttpBody.cc \
ftp.cc \
gopher.cc \
helper.cc \
+ hier_code.h \
+ hier_code.cc \
$(HTCPSOURCE) \
http.cc \
HttpBody.cc \
ftp.cc \
gopher.cc \
helper.cc \
+ hier_code.h \
+ hier_code.cc \
$(HTCPSOURCE) \
http.cc \
HttpBody.cc \
#include "acl/Checklist.h"
+#include "hier_code.h"
#include "HttpReply.h"
#include "HttpRequest.h"
#include "MemBuf.h"
--- /dev/null
+#include "squid.h"
+#include "acl/HierCode.h"
+#include "acl/HierCodeData.h"
+#include "acl/Checklist.h"
+#include "HttpRequest.h"
+
+/* explicit template instantiation required for some systems */
+
+template class ACLStrategised<hier_code>;
+
+
+int
+ACLHierCodeStrategy::match (ACLData<MatchType> * &data, ACLFilledChecklist *checklist)
+{
+ return data->match (checklist->request->hier.code);
+}
+
+ACLHierCodeStrategy *
+ACLHierCodeStrategy::Instance()
+{
+ return &Instance_;
+}
+
+ACLHierCodeStrategy ACLHierCodeStrategy::Instance_;
--- /dev/null
+#ifndef SQUID_ACLHIERCODE_H
+#define SQUID_ACLHIERCODE_H
+
+#include "acl/Strategy.h"
+#include "acl/Strategised.h"
+#include "hier_code.h"
+
+/// \ingroup ACLAPI
+class ACLHierCodeStrategy : public ACLStrategy<hier_code>
+{
+
+public:
+ virtual int match (ACLData<MatchType> * &, ACLFilledChecklist *);
+ virtual bool requiresRequest() const {return true;}
+
+ static ACLHierCodeStrategy *Instance();
+
+ /**
+ * Not implemented to prevent copies of the instance.
+ \par
+ * Not private to prevent brain dead g+++ warnings about
+ * private constructors with no friends
+ */
+ ACLHierCodeStrategy(ACLHierCodeStrategy const &);
+
+private:
+ static ACLHierCodeStrategy Instance_;
+ ACLHierCodeStrategy() {}
+
+ ACLHierCodeStrategy &operator=(ACLHierCodeStrategy const &);
+};
+
+/// \ingroup ACLAPI
+class ACLHierCode
+{
+
+private:
+ static ACL::Prototype RegistryProtoype;
+ static ACLStrategised<hier_code> RegistryEntry_;
+};
+
+#endif /* SQUID_ACLHIERCODE_H */
--- /dev/null
+#include "squid.h"
+#include "acl/HierCodeData.h"
+#include "acl/Checklist.h"
+#include "hier_code.h"
+#include "wordlist.h"
+
+ACLHierCodeData::ACLHierCodeData()
+{
+ // initialize mask to NULL
+ memset(values, 0, sizeof(values));
+}
+
+ACLHierCodeData::ACLHierCodeData(ACLHierCodeData const &old)
+{
+ memcpy(values, old.values, sizeof(values) );
+}
+
+ACLHierCodeData::~ACLHierCodeData()
+{ }
+
+bool
+ACLHierCodeData::match(hier_code toFind)
+{
+ return values[toFind];
+}
+
+wordlist *
+ACLHierCodeData::dump()
+{
+ wordlist *W = NULL;
+
+ for (hier_code iter=HIER_NONE; iter<HIER_MAX; ++iter) {
+ if (!values[iter]) continue;
+ wordlistAdd(&W, hier_strings[iter]);
+ }
+
+ return W;
+}
+
+void
+ACLHierCodeData::parse()
+{
+ char *t = NULL;
+
+ while ((t = strtokFile())) {
+ for (hier_code iter = HIER_NONE; iter <= HIER_MAX; ++iter) {
+ if (iter == HIER_MAX) {
+ fatalf("ERROR: No such hier_code '%s'",t);
+ return;
+ }
+ if (strcmp(hier_strings[iter],t) == 0) {
+ values[iter] = true;
+ break; // back to while-loop
+ }
+ }
+ }
+}
+
+bool
+ACLHierCodeData::empty() const
+{
+ for (hier_code iter = HIER_NONE; iter <= HIER_MAX; ++iter) {
+ if (values[iter]) return false; // not empty.
+ }
+ return true;
+}
+
+ACLData<hier_code> *
+ACLHierCodeData::clone() const
+{
+ return new ACLHierCodeData(*this);
+}
--- /dev/null
+#ifndef SQUID_ACLHIERCODEDATA_H
+#define SQUID_ACLHIERCODEDATA_H
+
+#include "acl/Acl.h"
+#include "acl/Data.h"
+#include "CbDataList.h"
+#include "hier_code.h"
+
+/// \ingroup ACLAPI
+class ACLHierCodeData : public ACLData<hier_code>
+{
+
+public:
+ MEMPROXY_CLASS(ACLHierCodeData);
+
+ ACLHierCodeData();
+ ACLHierCodeData(ACLHierCodeData const &);
+ ACLHierCodeData &operator= (ACLHierCodeData const &);
+ virtual ~ACLHierCodeData();
+ bool match(hier_code);
+ wordlist *dump();
+ void parse();
+ bool empty() const;
+ virtual ACLData<hier_code> *clone() const;
+
+ // mask of codes this ACL might match.
+ bool values[HIER_MAX];
+};
+
+MEMPROXY_CLASS_INLINE(ACLHierCodeData);
+
+#endif /* SQUID_ACLHIERCODEDATA_H */
DomainData.h \
ExtUser.cc \
ExtUser.h \
+ HierCodeData.cc \
+ HierCodeData.h \
+ HierCode.cc \
+ HierCode.h \
HttpHeaderData.cc \
HttpHeaderData.h \
HttpRepHeader.cc \
acl aclname tag tagvalue ...
# string match on tag returned by external acl helper [slow]
+ acl aclname hier_code codename ...
+ # string match against squid hierarchy code(s); [fast]
+ # e.g., DIRECT, PARENT_HIT, NONE, etc.
+ #
+ # NOTE: This has no effect in http_access rules. It only has
+ # effect in rules that affect the reply data stream such as
+ # http_reply_access.
+
Examples:
acl macaddress arp 09:00:2b:23:45:67
acl myexample dst_as 1241
SC_ENUM_END
} http_hdr_sc_type;
-typedef enum {
- HIER_NONE,
- HIER_DIRECT,
- SIBLING_HIT,
- PARENT_HIT,
- DEFAULT_PARENT,
- SINGLE_PARENT,
- FIRSTUP_PARENT,
- FIRST_PARENT_MISS,
- CLOSEST_PARENT_MISS,
- CLOSEST_PARENT,
- CLOSEST_DIRECT,
- NO_DIRECT_FAIL,
- SOURCE_FASTEST,
- ROUNDROBIN_PARENT,
-#if USE_CACHE_DIGESTS
- CD_PARENT_HIT,
- CD_SIBLING_HIT,
-#endif
- CARP,
- ANY_OLD_PARENT,
- USERHASH_PARENT,
- SOURCEHASH_PARENT,
- HIER_MAX,
- PINNED
-} hier_code;
/// \ingroup ServerProtocolICPAPI
typedef enum {
#include "event.h"
#include "errorpage.h"
#include "fde.h"
+#include "hier_code.h"
#include "HttpReply.h"
#include "HttpRequest.h"
#include "MemObject.h"
class HttpRequest;
#include "comm.h"
+#include "hier_code.h"
#include "ip/IpAddress.h"
class FwdServer
{
-
public:
peer *_peer; /* NULL --> origin server */
hier_code code;
class FwdState : public RefCountable
{
-
public:
typedef RefCount<FwdState> Pointer;
~FwdState();
--- /dev/null
+#include "config.h"
+#include "hier_code.h"
+
+const char *hier_strings[] = {
+ "NONE", /* HIER_NONE */
+ "DIRECT", /* HIER_DIRECT */
+ "SIBLING_HIT",
+ "PARENT_HIT",
+ "DEFAULT_PARENT",
+ "SINGLE_PARENT",
+ "FIRSTUP_PARENT",
+ "FIRST_PARENT_MISS",
+ "CLOSEST_PARENT_MISS",
+ "CLOSEST_PARENT",
+ "CLOSEST_DIRECT",
+ "NO_DIRECT_FAIL",
+ "SOURCE_FASTEST",
+ "ROUNDROBIN_PARENT",
+#if USE_CACHE_DIGESTS
+ "CD_PARENT_HIT",
+ "CD_SIBLING_HIT",
+#endif
+ "CARP",
+ "ANY_PARENT",
+ "USERHASH",
+ "SOURCEHASH",
+ "PINNED",
+ "HIER_MAX"
+};
--- /dev/null
+#ifndef SQUID__HIER_CODE_H
+#define SQUID__HIER_CODE_H
+
+typedef enum {
+ HIER_NONE,
+ HIER_DIRECT,
+ SIBLING_HIT,
+ PARENT_HIT,
+ DEFAULT_PARENT,
+ SINGLE_PARENT,
+ FIRSTUP_PARENT,
+ FIRST_PARENT_MISS,
+ CLOSEST_PARENT_MISS,
+ CLOSEST_PARENT,
+ CLOSEST_DIRECT,
+ NO_DIRECT_FAIL,
+ SOURCE_FASTEST,
+ ROUNDROBIN_PARENT,
+#if USE_CACHE_DIGESTS
+ CD_PARENT_HIT,
+ CD_SIBLING_HIT,
+#endif
+ CARP,
+ ANY_OLD_PARENT,
+ USERHASH_PARENT,
+ SOURCEHASH_PARENT,
+ PINNED,
+ HIER_MAX
+} hier_code;
+
+extern const char *hier_strings[];
+
+inline const hier_code operator++(hier_code &i) { return (hier_code)(i+1); }
+
+#endif /* SQUID__HIER_CODE_H */
#include "event.h"
#include "PeerSelectState.h"
#include "Store.h"
+#include "hier_code.h"
#include "ICP.h"
#include "HttpRequest.h"
#include "acl/FilledChecklist.h"
#include "SquidTime.h"
#include "icmp/net_db.h"
-const char *hier_strings[] = {
- "NONE",
- "DIRECT",
- "SIBLING_HIT",
- "PARENT_HIT",
- "DEFAULT_PARENT",
- "SINGLE_PARENT",
- "FIRST_UP_PARENT",
- "FIRST_PARENT_MISS",
- "CLOSEST_PARENT_MISS",
- "CLOSEST_PARENT",
- "CLOSEST_DIRECT",
- "NO_DIRECT_FAIL",
- "SOURCE_FASTEST",
- "ROUNDROBIN_PARENT",
-#if USE_CACHE_DIGESTS
- "CD_PARENT_HIT",
- "CD_SIBLING_HIT",
-#endif
- "CARP",
- "ANY_PARENT",
- "USERHASH",
- "SOURCEHASH",
- "INVALID CODE"
-};
-
static struct {
int timeouts;
} PeerStats;
peerSelectInit(void)
{
memset(&PeerStats, '\0', sizeof(PeerStats));
- assert(sizeof(hier_strings) == (HIER_MAX + 1) * sizeof(char *));
}
static void