Anope IRC Services  Version 2.0
access.h
Go to the documentation of this file.
1 /*
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  */
12 
13 #ifndef ACCESS_H
14 #define ACCESS_H
15 
16 #include "services.h"
17 #include "anope.h"
18 #include "serialize.h"
19 #include "service.h"
20 
21 enum
22 {
23  ACCESS_INVALID = -10000,
25 };
26 
27 /* A privilege, probably configured using a privilege{} block. Most
28  * commands require specific privileges to be executed. The AccessProvider
29  * backing each ChanAccess determines whether that ChanAccess has a given
30  * privilege.
31  */
33 {
36  /* Rank relative to other privileges */
37  int rank;
38 
39  Privilege(const Anope::string &name, const Anope::string &desc, int rank);
40  bool operator==(const Privilege &other) const;
41 };
42 
44 {
45  static std::vector<Privilege> Privileges;
46  public:
47  static void AddPrivilege(Privilege p);
48  static void RemovePrivilege(Privilege &p);
49  static Privilege *FindPrivilege(const Anope::string &name);
50  static std::vector<Privilege> &GetPrivileges();
51  static void ClearPrivileges();
52 };
53 
54 /* A provider of access. Only used for creating ChanAccesses, as
55  * they contain pure virtual functions.
56  */
58 {
59  public:
60  AccessProvider(Module *owner, const Anope::string &name);
61  virtual ~AccessProvider();
62 
66  virtual ChanAccess *Create() = 0;
67 
68  private:
69  static std::list<AccessProvider *> Providers;
70  public:
71  static const std::list<AccessProvider *>& GetProviders();
72 };
73 
74 /* Represents one entry of an access list on a channel. */
76 {
78  /* account this access entry is for, if any */
80 
81  public:
82  typedef std::multimap<const ChanAccess *, const ChanAccess *> Set;
83  /* shows the 'path' taken to determine if an access entry matches a user
84  * .first are access entries checked
85  * .second are access entries which match
86  */
87  typedef std::pair<Set, Set> Path;
88 
89  /* The provider that created this access entry */
91  /* Channel this access entry is on */
94  time_t last_seen;
95  time_t created;
96 
98  virtual ~ChanAccess();
99 
100  void SetMask(const Anope::string &mask, ChannelInfo *ci);
101  const Anope::string &Mask() const;
102  NickCore *GetAccount() const;
103 
104  void Serialize(Serialize::Data &data) const anope_override;
105  static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
106 
112  virtual bool Matches(const User *u, const NickCore *nc, Path &p) const;
113 
117  virtual bool HasPriv(const Anope::string &name) const = 0;
118 
123  virtual Anope::string AccessSerialize() const = 0;
124 
128  virtual void AccessUnserialize(const Anope::string &data) = 0;
129 
130  /* Comparison operators to other Access entries */
131  virtual bool operator>(const ChanAccess &other) const;
132  virtual bool operator<(const ChanAccess &other) const;
133  bool operator>=(const ChanAccess &other) const;
134  bool operator<=(const ChanAccess &other) const;
135 };
136 
137 /* A group of access entries. This is used commonly, for example with ChannelInfo::AccessFor,
138  * to show what access a user has on a channel because users can match multiple access entries.
139  */
140 class CoreExport AccessGroup : public std::vector<ChanAccess *>
141 {
142  public:
143  /* Channel these access entries are on */
144  const ChannelInfo *ci;
145  /* Path from these entries to other entries that they depend on */
147  /* Account these entries affect, if any */
148  const NickCore *nc;
149  /* super_admin always gets all privs. founder is a special case where ci->founder == nc */
150  bool super_admin, founder;
151 
152  AccessGroup();
153 
160  bool HasPriv(const Anope::string &priv) const;
161 
167  const ChanAccess *Highest() const;
168 
169  /* Comparison operators to other AccessGroups */
170  bool operator>(const AccessGroup &other) const;
171  bool operator<(const AccessGroup &other) const;
172  bool operator>=(const AccessGroup &other) const;
173  bool operator<=(const AccessGroup &other) const;
174 };
175 
176 #endif
177 
int rank
Definition: access.h:37
std::pair< Set, Set > Path
Definition: access.h:87
static std::list< AccessProvider * > Providers
Definition: access.h:69
const ChannelInfo * ci
Definition: access.h:144
Serialize::Reference< NickCore > nc
Definition: access.h:79
Definition: users.h:34
Anope::string desc
Definition: access.h:35
Anope::string creator
Definition: access.h:93
static std::vector< Privilege > Privileges
Definition: access.h:45
time_t created
Definition: access.h:95
std::multimap< const ChanAccess *, const ChanAccess * > Set
Definition: access.h:82
bool super_admin
Definition: access.h:150
time_t last_seen
Definition: access.h:94
bool operator==(const std::string &leftval, const ci::string &rightval)
Definition: hashcomp.h:171
virtual void Serialize(Serialize::Data &data) const =0
Serialize::Reference< ChannelInfo > ci
Definition: access.h:92
#define anope_override
Definition: services.h:56
AccessProvider * provider
Definition: access.h:90
Anope::string name
Definition: access.h:34
#define CoreExport
Definition: services.h:62
Anope::string mask
Definition: access.h:77
static bool HasPriv(const AccessGroup &ag, const ChanAccess *access, const Anope::string &name)
Definition: access.cpp:358
Anope::string name
Definition: access.cpp:22
const NickCore * nc
Definition: access.h:148
ChanAccess::Path path
Definition: access.h:146