Kea  1.9.9-git
user_file.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2015,2017 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 #ifndef _USER_FILE_H
7 #define _USER_FILE_H
8 
10 
11 #include <user_data_source.h>
12 #include <user.h>
13 
14 #include <boost/shared_ptr.hpp>
15 #include <fstream>
16 #include <string>
17 
18 namespace user_chk {
19 
23 public:
24  UserFileError(const char* file, size_t line, const char* what) :
25  UserDataSourceError(file, line, what)
26  {}
27 };
28 
58 class UserFile : public UserDataSource {
59 public:
63  static const size_t USER_ENTRY_MAX_LEN = 4096;
64 
71  UserFile(const std::string& fname);
72 
76  virtual ~UserFile();
77 
84  virtual void open();
85 
95  virtual UserPtr readNextUser();
96 
100  virtual void close();
101 
105  virtual bool isOpen() const;
106 
114  UserPtr makeUser(const std::string& user_string);
115 
116 private:
118  std::string fname_;
119 
121  std::ifstream file_;
122 
123 };
124 
126 typedef boost::shared_ptr<UserFile> UserFilePtr;
127 
128 } // namespace user_chk
129 
130 #endif
Thrown a UserFile encounters an error.
Definition: user_file.h:22
virtual void close()
Closes the underlying file.
Definition: user_file.cc:143
UserFile(const std::string &fname)
Constructor.
Definition: user_file.cc:19
virtual bool isOpen() const
Returns true if the file is open.
Definition: user_file.cc:138
Provides a UserDataSource implementation for JSON text files.
Definition: user_file.h:58
boost::shared_ptr< User > UserPtr
Defines a smart pointer to a User.
Definition: user.h:241
Thrown if UserDataSource encounters an error.
static const size_t USER_ENTRY_MAX_LEN
Maximum length of a single user entry.
Definition: user_file.h:63
Defines the logger used by the user check hooks library.
Definition: user.cc:19
This file defines classes: UserId and User.
virtual void open()
Opens the input file for reading.
Definition: user_file.cc:30
UserPtr makeUser(const std::string &user_string)
Creates a new User instance from JSON text.
Definition: user_file.cc:66
UserFileError(const char *file, size_t line, const char *what)
Definition: user_file.h:24
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
virtual ~UserFile()
Destructor. / The destructor does call the close method.
Definition: user_file.cc:25
Defines the base class, UserDataSource.
boost::shared_ptr< UserFile > UserFilePtr
Defines a smart pointer to a UserFile.
Definition: user_file.h:126
virtual UserPtr readNextUser()
Fetches the next user from the file.
Definition: user_file.cc:44
Defines an interface for reading user data into a registry.