Kea  2.3.5-git
user.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef USER_H
8 #define USER_H
9 
10 #include <boost/shared_ptr.hpp>
11 
12 #include <map>
13 #include <stdint.h>
14 #include <vector>
15 
16 namespace user_chk {
17 
21 
27 class UserId {
28 public:
30  // Use explicit values to ensure consistent numeric ordering for key
31  // comparisons.
32  enum UserIdType {
36  DUID = 1
37  };
38 
40  static const char* HW_ADDRESS_STR;
42  static const char* DUID_STR;
43 
52  UserId(UserIdType id_type, const std::vector<uint8_t>& id);
53 
66  UserId(UserIdType id_type, const std::string& id_str);
67 
69  ~UserId();
70 
72  const std::vector<uint8_t>& getId() const;
73 
75  UserIdType getType() const;
76 
91  std::string toText(char delim_char=0x0) const;
92 
94  bool operator ==(const UserId & other) const;
95 
97  bool operator !=(const UserId & other) const;
98 
100  bool operator <(const UserId & other) const;
101 
107  static std::string lookupTypeStr(UserIdType type);
108 
114  static UserIdType lookupType(const std::string& type_str);
115 
116 private:
118  UserIdType id_type_;
119 
121  std::vector<uint8_t> id_;
122 
123 };
124 
138 std::ostream&
139 operator<<(std::ostream& os, const UserId& user_id);
140 
142 typedef boost::shared_ptr<UserId> UserIdPtr;
143 
145 typedef std::map<std::string, std::string> PropertyMap;
146 
150 class User {
151 public:
159  User(const UserId & user_id);
160 
170  User(UserId::UserIdType id_type, const std::vector<uint8_t>& id);
171 
181  User(UserId::UserIdType id_type, const std::string& id_str);
182 
184  ~User();
185 
190  const PropertyMap& getProperties() const;
191 
198  void setProperties(const PropertyMap& properties);
199 
208  void setProperty(const std::string& name, const std::string& value);
209 
216  std::string getProperty(const std::string& name) const;
217 
224  void delProperty(const std::string& name);
225 
230  const UserId& getUserId() const;
231 
232 private:
234  UserId user_id_;
235 
237  PropertyMap properties_;
238 };
239 
241 typedef boost::shared_ptr<User> UserPtr;
242 
243 } // namespace user_chk
244 
245 #endif
UserIdType
Defines the supported types of user ids.
Definition: user.h:32
static std::string lookupTypeStr(UserIdType type)
Returns the text label for a given id type.
Definition: user.cc:119
static const char * DUID_STR
Define the text label DUID id type.
Definition: user.h:42
Encapsulates a unique identifier for a DHCP client.
Definition: user.h:27
bool operator<(const UserId &other) const
Performs less than comparison of two UserIds.
Definition: user.cc:113
boost::shared_ptr< UserId > UserIdPtr
Defines a smart pointer to UserId.
Definition: user.h:142
boost::shared_ptr< User > UserPtr
Defines a smart pointer to a User.
Definition: user.h:241
Defines the logger used by the user check hooks library.
Definition: user.cc:19
std::map< std::string, std::string > PropertyMap
Defines a map of string values keyed by string labels.
Definition: user.h:145
bool operator!=(const UserId &other) const
Compares two UserIds for inequality.
Definition: user.cc:108
Represents a unique DHCP user This class is used to represent a specific DHCP user who is identified ...
Definition: user.h:150
static UserIdType lookupType(const std::string &type_str)
Returns the id type for a given text label.
Definition: user.cc:137
UserId(UserIdType id_type, const std::vector< uint8_t > &id)
Constructor.
Definition: user.cc:26
UserIdType getType() const
Returns the user id type.
Definition: user.cc:79
Hardware addresses (MAC) are used for IPv4 clients.
Definition: user.h:34
~UserId()
Destructor.
Definition: user.cc:70
std::ostream & operator<<(std::ostream &os, const UserId &user_id)
Outputs the UserId contents in a string to the given stream.
Definition: user.cc:148
static const char * HW_ADDRESS_STR
Defines the text label hardware address id type.
Definition: user.h:40
bool operator==(const UserId &other) const
Compares two UserIds for equality.
Definition: user.cc:103
const std::vector< uint8_t > & getId() const
Returns a const reference to the actual id value.
Definition: user.cc:74
DUIDs are used for IPv6 clients.
Definition: user.h:36
std::string toText(char delim_char=0x0) const
Returns textual representation of the id.
Definition: user.cc:84