1 /*
2  * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_SRC_XACTION_INITIATOR_H
10 #define SQUID_SRC_XACTION_INITIATOR_H
11 
12 /// identifies a protocol agent or Squid feature initiating transactions
13 class XactionInitiator {
14 public:
15     /// transaction triggers
16     enum Initiator {
17         initUnknown = 0,
18         initClient = 1 << 0, ///< HTTP or FTP client
19         initPeerPool = 1 << 1, ///< PeerPool manager
20         initCertFetcher = 1 << 2, ///< Missing intermediate certificates fetching code
21         initEsi = 1 << 3, ///< ESI processing code
22         initCacheDigest = 1 << 4, ///< Cache Digest fetching code
23         initHtcp = 1<< 5, ///< HTCP client
24         initIcp = 1 << 6, ///< the ICP/neighbors subsystem
25         initIcmp = 1 << 7, ///< the ICMP RTT database (NetDB) neighbors exchange subsystem
26         initAsn = 1 << 8, ///< the ASN db subsystem
27         initIpc = 1 << 9, ///< the IPC subsystem
28         initAdaptation = 1 << 10,  ///< ICAP/ECAP requests generated by Squid
29         initIcon = 1 << 11, ///< internal icons
30         initPeerMcast = 1 << 12, ///< neighbor multicast
31         initServer = 1 << 13, ///< HTTP/2 push request (not yet supported by Squid)
32 
33         initAdaptationOrphan_ = 1 << 31 ///< eCAP-created HTTP message w/o an associated HTTP transaction (not ACL-detectable)
34     };
35 
36     typedef uint32_t Initiators; ///< Initiator set
37 
38     // this class is a just a trivial wrapper so we allow explicit conversions
XactionInitiator(Initiator i)39     XactionInitiator(Initiator i) : initiator(i) {}
40 
41     /// whether this initiator belongs to the given set
in(Initiators setOfInitiators)42     bool in(Initiators setOfInitiators) const {return (initiator & setOfInitiators) != 0;}
43 
44     /// whether the transaction was initiated by an internal subsystem
internalClient()45     bool internalClient() const {
46         return (initiator & InternalInitiators()) != 0;
47     }
48 
49     /// internally generated requests
InternalInitiators()50     static Initiators InternalInitiators() {
51         return initPeerPool | initCertFetcher | initEsi | initCacheDigest | initIcp | initIcmp | initIpc | initAdaptation | initIcon | initPeerMcast;
52     }
53 
54     /// all initiators
AllInitiators()55     static Initiators AllInitiators() {
56         return 0xFFFFFFFF;
57     }
58 
59     static Initiators ParseInitiators(const char *name);
60 
61 private:
XactionInitiator()62     XactionInitiator() {}
63 
64     Initiator initiator;
65 };
66 
67 #endif // SQUID_SRC_XACTION_INITIATOR_H
68 
69