13 #include <boost/foreach.hpp>
35 file_.open(fname_.c_str(), std::ifstream::in);
36 int sav_error = errno;
37 if (!file_.is_open()) {
39 <<
" reason: " << strerror(sav_error));
53 file_.getline(buf,
sizeof(buf));
56 if (file_.gcount() > 0) {
77 "UserFile entry is malformed JSON: " << ex.
what());
83 std::string id_type_str;
89 std::pair<std::string, isc::data::ConstElementPtr> element_pair;
90 BOOST_FOREACH (element_pair, elements->mapValue()) {
92 std::string label = element_pair.first;
97 <<
"has non-string value for : " << label);
100 std::string value = element_pair.second->stringValue();
102 if (label ==
"type") {
104 }
else if (label ==
"id") {
109 properties[label]=value;
117 }
catch (
const std::exception& ex) {
119 << user_string <<
" " << ex.
what());
126 user.reset(
new User(id_type, id_str));
127 }
catch (
const std::exception& ex) {
129 << user_string <<
" " << ex.
what());
133 user->setProperties(properties);
139 return (file_.is_open());
145 if (file_.is_open()) {
148 }
catch (
const std::exception& ex) {
151 std::cout <<
"UserFile unexpected error closing the file: "
152 << fname_ <<
" : " << ex.what() << std::endl;
UserIdType
Defines the supported types of user ids.
Thrown a UserFile encounters an error.
virtual void close()
Closes the underlying file.
A standard Data module exception that is thrown if a parse error is encountered when constructing an ...
UserFile(const std::string &fname)
Constructor.
boost::shared_ptr< Element > ElementPtr
static ElementPtr fromJSON(const std::string &in, bool preproc=false)
These functions will parse the given string (JSON) representation of a compound element.
virtual bool isOpen() const
Returns true if the file is open.
boost::shared_ptr< User > UserPtr
Defines a smart pointer to a User.
Defines the class, UserFile, which implements the UserDataSource interface for text files...
static const size_t USER_ENTRY_MAX_LEN
Maximum length of a single user entry.
Defines the logger used by the user check hooks library.
std::map< std::string, std::string > PropertyMap
Defines a map of string values keyed by string labels.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
This file defines classes: UserId and User.
Represents a unique DHCP user This class is used to represent a specific DHCP user who is identified ...
virtual void open()
Opens the input file for reading.
UserPtr makeUser(const std::string &user_string)
Creates a new User instance from JSON text.
boost::shared_ptr< const Element > ConstElementPtr
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
static UserIdType lookupType(const std::string &type_str)
Returns the id type for a given text label.
virtual ~UserFile()
Destructor. / The destructor does call the close method.
virtual UserPtr readNextUser()
Fetches the next user from the file.