20 isc_throw(UserFileError,
"file name cannot be blank");
34 file_.open(fname_.c_str(), std::ifstream::in);
35 int sav_error = errno;
36 if (!file_.is_open()) {
38 <<
" reason: " << strerror(sav_error));
52 file_.getline(buf,
sizeof(buf));
55 if (file_.gcount() > 0) {
76 "UserFile entry is malformed JSON: " << ex.
what());
82 std::string id_type_str;
88 for (
auto const& element_pair : elements->mapValue()) {
90 std::string label = element_pair.first;
95 <<
"has non-string value for : " << label);
98 std::string value = element_pair.second->stringValue();
100 if (label ==
"type") {
102 }
else if (label ==
"id") {
107 properties[label]=value;
115 }
catch (
const std::exception& ex) {
117 << user_string <<
" " << ex.
what());
124 user.reset(
new User(id_type, id_str));
125 }
catch (
const std::exception& ex) {
127 << user_string <<
" " << ex.
what());
131 user->setProperties(properties);
137 return (file_.is_open());
143 if (file_.is_open()) {
146 }
catch (
const std::exception& ex) {
149 std::cout <<
"UserFile unexpected error closing the file: "
150 << fname_ <<
" : " << ex.what() << std::endl;
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
static ElementPtr fromJSON(const std::string &in, bool preproc=false)
These functions will parse the given string (JSON) representation of a compound element.
A standard Data module exception that is thrown if a parse error is encountered when constructing an ...
Thrown a UserFile encounters an error.
static const size_t USER_ENTRY_MAX_LEN
Maximum length of a single user entry.
virtual UserPtr readNextUser()
Fetches the next user from the file.
virtual void close()
Closes the underlying file.
UserFile(const std::string &fname)
Constructor.
UserPtr makeUser(const std::string &user_string)
Creates a new User instance from JSON text.
virtual bool isOpen() const
Returns true if the file is open.
virtual ~UserFile()
Destructor. / The destructor does call the close method.
virtual void open()
Opens the input file for reading.
static UserIdType lookupType(const std::string &type_str)
Returns the id type for a given text label.
UserIdType
Defines the supported types of user ids.
Represents a unique DHCP user This class is used to represent a specific DHCP user who is identified ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
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.
boost::shared_ptr< User > UserPtr
Defines a smart pointer to a User.
This file defines classes: UserId and User.
Defines the class, UserFile, which implements the UserDataSource interface for text files.