Kea 2.7.5
|
A class able to load DNS master files. More...
#include <master_loader.h>
Classes | |
class | MasterLoaderImpl |
Private implementation class for the MasterLoader . More... | |
Public Types | |
enum | Options { DEFAULT = 0 , MANY_ERRORS = 1 } |
Options how the parsing should work. More... | |
Public Member Functions | |
MasterLoader (const char *master_file, const Name &zone_origin, const RRClass &zone_class, const MasterLoaderCallbacks &callbacks, const AddRRCallback &add_callback, Options options=DEFAULT) | |
Constructor. | |
MasterLoader (std::istream &input, const Name &zone_origin, const RRClass &zone_class, const MasterLoaderCallbacks &callbacks, const AddRRCallback &add_callback, Options options=DEFAULT) | |
Constructor from a stream. | |
~MasterLoader () | |
Destructor. | |
size_t | getPosition () const |
Return the position of the loader in zone. | |
size_t | getSize () const |
Return the total size of the zone files and streams. | |
void | load () |
Load everything. | |
bool | loadedSuccessfully () const |
Was the loading successful? | |
bool | loadIncremental (size_t count_limit) |
Load some RRs. | |
A class able to load DNS master files.
This class is able to produce a stream of RRs from a master file. It is able to load all of the master file at once, or by blocks incrementally.
It reports the loaded RRs and encountered errors by callbacks.
Definition at line 39 of file master_loader.h.
Options how the parsing should work.
Enumerator | |
---|---|
DEFAULT | Nothing special. |
MANY_ERRORS | Lenient mode (see documentation of MasterLoader constructor). |
Definition at line 42 of file master_loader.h.
isc::dns::MasterLoader::MasterLoader | ( | const char * | master_file, |
const Name & | zone_origin, | ||
const RRClass & | zone_class, | ||
const MasterLoaderCallbacks & | callbacks, | ||
const AddRRCallback & | add_callback, | ||
Options | options = DEFAULT ) |
Constructor.
This creates a master loader and provides it with all relevant information.
Except for the exceptions listed below, the constructor doesn't throw. Most errors (like non-existent master file) are reported by the callbacks during load() or loadIncremental().
master_file | Path to the file to load. |
zone_origin | The origin of zone to be expected inside the master file. Currently unused, but it is expected to be used for some validation. |
zone_class | The class of zone to be expected inside the master file. |
callbacks | The callbacks by which it should report problems. Usually, the callback carries a filename and line number of the input where the problem happens. There's a special case of empty filename and zero line in case the opening of the top-level master file fails. |
add_callback | The callback which would be called with each loaded RR. |
options | Options for the parsing, which is bitwise-or of the Options values or DEFAULT. If the MANY_ERRORS option is included, the parser tries to continue past errors. If it is not included, it stops at first encountered error. |
std::bad_alloc | when there's not enough memory. |
isc::InvalidParameter | if add_callback is empty. |
Definition at line 689 of file master_loader.cc.
References isc_throw.
isc::dns::MasterLoader::MasterLoader | ( | std::istream & | input, |
const Name & | zone_origin, | ||
const RRClass & | zone_class, | ||
const MasterLoaderCallbacks & | callbacks, | ||
const AddRRCallback & | add_callback, | ||
Options | options = DEFAULT ) |
Constructor from a stream.
This is a constructor very similar to the previous one. The only difference is it doesn't take a filename, but an input stream to read the data from. It is expected to be mostly used in tests, but it is public as it may possibly be useful for other currently unknown purposes.
Definition at line 702 of file master_loader.cc.
References isc_throw.
isc::dns::MasterLoader::~MasterLoader | ( | ) |
Destructor.
Definition at line 716 of file master_loader.cc.
size_t isc::dns::MasterLoader::getPosition | ( | ) | const |
Return the position of the loader in zone.
This method returns a conceptual "position" of the loader in the zone to be loaded. Specifically, it returns the total number of characters contained in the zone files and streams and recognized by the loader. Before starting the load it returns 0; on successful completion it will be equal to the return value of getSize()
(unless the latter returns MasterLexer::SOURCE_SIZE_UNKNOWN
).
None |
Definition at line 737 of file master_loader.cc.
size_t isc::dns::MasterLoader::getSize | ( | ) | const |
Return the total size of the zone files and streams.
This method returns the size of the source of the zone to be loaded (master zone files or streams) that is known at the time of the call. For a zone file, it's the size of the file; for a stream, it's the size of the data (in bytes) available at the start of the load. If separate zone files are included via the $INCLUDE directive, the sum of the sizes of these files are added.
If the loader is constructed with a stream, the size can be "unknown" as described for MasterLexer::getTotalSourceSize()
. In this case this method always returns MasterLexer::SOURCE_SIZE_UNKNOWN
.
If the loader is constructed with a zone file, this method initially returns 0. So until either load()
or loadIncremental()
is called, the value is meaningless.
Note that when the source includes separate files, this method cannot take into account the included files that the loader has not recognized at the time of call. So it's possible that this method returns different values at different times of call.
None |
Definition at line 732 of file master_loader.cc.
|
inline |
Load everything.
This simply calls loadIncremental until the loading is done.
isc::InvalidOperation | when called after loading was done already. |
MasterLoaderError | when there's an error in the input master file and the MANY_ERRORS is not specified. It never throws this in case MANY_ERRORS is specified. |
Definition at line 124 of file master_loader.h.
References loadIncremental().
bool isc::dns::MasterLoader::loadedSuccessfully | ( | ) | const |
Was the loading successful?
Definition at line 727 of file master_loader.cc.
bool isc::dns::MasterLoader::loadIncremental | ( | size_t | count_limit | ) |
Load some RRs.
This method loads at most count_limit RRs and reports them. In case an error (either fatal or without MANY_ERRORS) or end of file is encountered, they may be less.
count_limit | Upper limit on the number of RRs loaded. |
isc::InvalidOperation | when called after loading was done already. |
MasterLoaderError | when there's an error in the input master file and the MANY_ERRORS is not specified. It never throws this in case MANY_ERRORS is specified. |
Definition at line 720 of file master_loader.cc.
Referenced by load().