Kea: user.h Source File

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