Anope IRC Services  Version 2.0
ldap.h
Go to the documentation of this file.
1 #ifndef ANOPE_LDAP_H
2 #define ANOPE_LDAP_H
3 
4 typedef int LDAPQuery;
5 
7 {
8  public:
9  LDAPException(const Anope::string &reason) : ModuleException(reason) { }
10 
11  virtual ~LDAPException() throw() { }
12 };
13 
15 {
17  {
21  };
22 
25  std::vector<Anope::string> values;
26 };
27 typedef std::vector<LDAPModification> LDAPMods;
28 
29 struct LDAPAttributes : public std::map<Anope::string, std::vector<Anope::string> >
30 {
31  size_t size(const Anope::string &attr) const
32  {
33  const std::vector<Anope::string>& array = this->getArray(attr);
34  return array.size();
35  }
36 
37  const std::vector<Anope::string> keys() const
38  {
39  std::vector<Anope::string> k;
40  for (const_iterator it = this->begin(), it_end = this->end(); it != it_end; ++it)
41  k.push_back(it->first);
42  return k;
43  }
44 
45  const Anope::string &get(const Anope::string &attr) const
46  {
47  const std::vector<Anope::string>& array = this->getArray(attr);
48  if (array.empty())
49  throw LDAPException("Empty attribute " + attr + " in LDAPResult::get");
50  return array[0];
51  }
52 
53  const std::vector<Anope::string>& getArray(const Anope::string &attr) const
54  {
55  const_iterator it = this->find(attr);
56  if (it == this->end())
57  throw LDAPException("Unknown attribute " + attr + " in LDAPResult::getArray");
58  return it->second;
59  }
60 };
61 
62 struct LDAPResult
63 {
64  std::vector<LDAPAttributes> messages;
66 
67  enum QueryType
68  {
75  };
76 
79 
81  {
82  this->type = QUERY_UNKNOWN;
83  this->id = -1;
84  }
85 
86  size_t size() const
87  {
88  return this->messages.size();
89  }
90 
91  bool empty() const
92  {
93  return this->messages.empty();
94  }
95 
96  const LDAPAttributes &get(size_t sz) const
97  {
98  if (sz >= this->messages.size())
99  throw LDAPException("Index out of range");
100  return this->messages[sz];
101  }
102 
103  const Anope::string &getError() const
104  {
105  return this->error;
106  }
107 };
108 
110 {
111  public:
113 
114  LDAPInterface(Module *m) : owner(m) { }
115  virtual ~LDAPInterface() { }
116 
117  virtual void OnResult(const LDAPResult &r) = 0;
118  virtual void OnError(const LDAPResult &err) = 0;
119  virtual void OnDelete() { }
120 };
121 
122 class LDAPProvider : public Service
123 {
124  public:
125  LDAPProvider(Module *c, const Anope::string &n) : Service(c, "LDAPProvider", n) { }
126 
131  virtual LDAPQuery BindAsAdmin(LDAPInterface *i) = 0;
132 
139  virtual LDAPQuery Bind(LDAPInterface *i, const Anope::string &who, const Anope::string &pass) = 0;
140 
147  virtual LDAPQuery Search(LDAPInterface *i, const Anope::string &base, const Anope::string &filter) = 0;
148 
155  virtual LDAPQuery Add(LDAPInterface *i, const Anope::string &dn, LDAPMods &attributes) = 0;
156 
162  virtual LDAPQuery Del(LDAPInterface *i, const Anope::string &dn) = 0;
163 
170  virtual LDAPQuery Modify(LDAPInterface *i, const Anope::string &base, LDAPMods &attributes) = 0;
171 };
172 
173 #endif // ANOPE_LDAP_H
virtual ~LDAPInterface()
Definition: ldap.h:115
std::vector< Anope::string > values
Definition: ldap.h:25
virtual LDAPQuery BindAsAdmin(LDAPInterface *i)=0
LDAPException(const Anope::string &reason)
Definition: ldap.h:9
bool empty() const
Definition: ldap.h:91
size_t size(const Anope::string &attr) const
Definition: ldap.h:31
virtual void OnDelete()
Definition: ldap.h:119
virtual void OnResult(const LDAPResult &r)=0
std::vector< LDAPAttributes > messages
Definition: ldap.h:64
virtual LDAPQuery Del(LDAPInterface *i, const Anope::string &dn)=0
virtual LDAPQuery Bind(LDAPInterface *i, const Anope::string &who, const Anope::string &pass)=0
int LDAPQuery
Definition: ldap.h:4
const std::vector< Anope::string > keys() const
Definition: ldap.h:37
LDAPQuery id
Definition: ldap.h:78
std::vector< LDAPModification > LDAPMods
Definition: ldap.h:27
QueryType type
Definition: ldap.h:77
Module * owner
Definition: ldap.h:112
QueryType
Definition: ldap.h:67
Anope::string error
Definition: ldap.h:65
Anope::string name
Definition: ldap.h:24
LDAPInterface(Module *m)
Definition: ldap.h:114
virtual LDAPQuery Search(LDAPInterface *i, const Anope::string &base, const Anope::string &filter)=0
virtual LDAPQuery Modify(LDAPInterface *i, const Anope::string &base, LDAPMods &attributes)=0
LDAPResult()
Definition: ldap.h:80
LDAPProvider(Module *c, const Anope::string &n)
Definition: ldap.h:125
size_t size() const
Definition: ldap.h:86
virtual ~LDAPException()
Definition: ldap.h:11
virtual void OnError(const LDAPResult &err)=0
virtual LDAPQuery Add(LDAPInterface *i, const Anope::string &dn, LDAPMods &attributes)=0
const Anope::string & getError() const
Definition: ldap.h:103
LDAPOperation op
Definition: ldap.h:23
const std::vector< Anope::string > & getArray(const Anope::string &attr) const
Definition: ldap.h:53