Kea 2.5.8
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
18namespace user_chk {
19
23public:
24 UserFileError(const char* file, size_t line, const char* what) :
25 UserDataSourceError(file, line, what)
26 {}
27};
28
58class UserFile : public UserDataSource {
59public:
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
116private:
118 std::string fname_;
119
121 std::ifstream file_;
122
123};
124
126typedef boost::shared_ptr<UserFile> UserFilePtr;
127
128} // namespace user_chk
129
130#endif
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Thrown if UserDataSource encounters an error.
Defines an interface for reading user data into a registry.
Thrown a UserFile encounters an error.
Definition: user_file.h:22
UserFileError(const char *file, size_t line, const char *what)
Definition: user_file.h:24
Provides a UserDataSource implementation for JSON text files.
Definition: user_file.h:58
static const size_t USER_ENTRY_MAX_LEN
Maximum length of a single user entry.
Definition: user_file.h:63
virtual UserPtr readNextUser()
Fetches the next user from the file.
Definition: user_file.cc:43
virtual void close()
Closes the underlying file.
Definition: user_file.cc:142
UserPtr makeUser(const std::string &user_string)
Creates a new User instance from JSON text.
Definition: user_file.cc:65
virtual bool isOpen() const
Returns true if the file is open.
Definition: user_file.cc:137
virtual ~UserFile()
Destructor. / The destructor does call the close method.
Definition: user_file.cc:24
virtual void open()
Opens the input file for reading.
Definition: user_file.cc:29
Defines the logger used by the user check hooks library.
Definition: user.cc:19
boost::shared_ptr< User > UserPtr
Defines a smart pointer to a User.
Definition: user.h:241
boost::shared_ptr< UserFile > UserFilePtr
Defines a smart pointer to a UserFile.
Definition: user_file.h:126
This file defines classes: UserId and User.
Defines the base class, UserDataSource.