Kea 2.5.8
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
16namespace user_chk {
17
21
27class UserId {
28public:
30 // Use explicit values to ensure consistent numeric ordering for key
31 // comparisons.
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
116private:
118 UserIdType id_type_;
119
121 std::vector<uint8_t> id_;
122
123};
124
138std::ostream&
139operator<<(std::ostream& os, const UserId& user_id);
140
142typedef boost::shared_ptr<UserId> UserIdPtr;
143
145typedef std::map<std::string, std::string> PropertyMap;
146
150class User {
151public:
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
232private:
234 UserId user_id_;
235
237 PropertyMap properties_;
238};
239
241typedef boost::shared_ptr<User> UserPtr;
242
243} // namespace user_chk
244
245#endif
Encapsulates a unique identifier for a DHCP client.
Definition: user.h:27
const std::vector< uint8_t > & getId() const
Returns a const reference to the actual id value.
Definition: user.cc:74
bool operator!=(const UserId &other) const
Compares two UserIds for inequality.
Definition: user.cc:107
~UserId()
Destructor.
Definition: user.cc:70
static UserIdType lookupType(const std::string &type_str)
Returns the id type for a given text label.
Definition: user.cc:136
std::string toText(char delim_char=0x0) const
Returns textual representation of the id.
Definition: user.cc:84
static const char * DUID_STR
Define the text label DUID id type.
Definition: user.h:42
static std::string lookupTypeStr(UserIdType type)
Returns the text label for a given id type.
Definition: user.cc:118
bool operator==(const UserId &other) const
Compares two UserIds for equality.
Definition: user.cc:102
UserIdType getType() const
Returns the user id type.
Definition: user.cc:79
bool operator<(const UserId &other) const
Performs less than comparison of two UserIds.
Definition: user.cc:112
static const char * HW_ADDRESS_STR
Defines the text label hardware address id type.
Definition: user.h:40
UserIdType
Defines the supported types of user ids.
Definition: user.h:32
@ HW_ADDRESS
Hardware addresses (MAC) are used for IPv4 clients.
Definition: user.h:34
@ DUID
DUIDs are used for IPv6 clients.
Definition: user.h:36
Represents a unique DHCP user This class is used to represent a specific DHCP user who is identified ...
Definition: user.h:150
std::string getProperty(const std::string &name) const
Fetches the string value for a given property name.
Definition: user.cc:189
~User()
Destructor.
Definition: user.cc:166
void setProperties(const PropertyMap &properties)
Sets the user's properties from a given property map.
Definition: user.cc:175
const UserId & getUserId() const
Returns the user's id.
Definition: user.cc:210
void setProperty(const std::string &name, const std::string &value)
Sets a given property to the given value.
Definition: user.cc:179
const PropertyMap & getProperties() const
Returns a reference to the map of properties.
Definition: user.cc:170
void delProperty(const std::string &name)
Removes the given property from the property map.
Definition: user.cc:202
Defines the logger used by the user check hooks library.
Definition: user.cc:19
boost::shared_ptr< UserId > UserIdPtr
Defines a smart pointer to UserId.
Definition: user.h:142
std::map< std::string, std::string > PropertyMap
Defines a map of string values keyed by string labels.
Definition: user.h:145
boost::shared_ptr< User > UserPtr
Defines a smart pointer to a User.
Definition: user.h:241
std::ostream & operator<<(std::ostream &os, const UserId &user_id)
Outputs the UserId contents in a string to the given stream.
Definition: user.cc:147