From: Michal 'vorner' Vaner Date: Mon, 29 Oct 2012 17:18:06 +0000 (+0100) Subject: [2383] Header of the Name constructor for parser X-Git-Tag: trac2487_base~21^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a0af829c62d143ebb80f99131f7bcb2918add82;p=thirdparty%2Fkea.git [2383] Header of the Name constructor for parser The master file parser will need a special Name constructor for reasonable performance and for convenience/clarity of its code. Introduce the header for the constructor, a new exception for it and documentation. --- diff --git a/src/lib/dns/name.h b/src/lib/dns/name.h index a3e3674f93..02c868f039 100644 --- a/src/lib/dns/name.h +++ b/src/lib/dns/name.h @@ -105,6 +105,17 @@ public: NameParserException(file, line, what) {} }; +/// \brief Thrown when origin is NULL and is needed. +/// +/// The exception is thrown when the Name constructor for master file +/// is used, the provided data is relative and the origin parameter is +/// set to NULL. +class MissingNameOrigin : public NameParserException { +public: + MissingNameOrigin(const char* file, size_t line, const char* what) : + NameParserException(file, line, what) {} +}; + /// /// This is a supplemental class used only as a return value of /// Name::compare() and LabelSequence::compare(). @@ -261,6 +272,37 @@ public: /// \param namestr A string representation of the name to be constructed. /// \param downcase Whether to convert upper case alphabets to lower case. explicit Name(const std::string& namestr, bool downcase = false); + + /// \brief Constructor for master file parser + /// + /// This acts similar to the above. But the data is passed as raw C-string + /// instead of wrapped-up C++ std::string. + /// + /// Also, when the origin is non-NULL and the name_data is not ending with + /// a dot, it is considered relative and the origin is appended to it. + /// + /// If the name_data is equal to "@", the content of origin is copied. + /// + /// \param name_data The raw data of the name. + /// \param data_len How many bytes in name_data is valid and considered + /// part of the name. + /// \param origin If non-NULL, it is taken as the origin to complete + /// relative names. + /// \param downcase Whether to convert upper case letters to lower case. + /// \throw NameParserException or any of its descendants in case the + /// input data is invalid. + /// \throw isc::InvalidParameter In case name_data is NULL or data_len is + /// 0. + /// \throw std::bad_alloc In case allocation fails. + /// \note This constructor is specially designed for the use of master + /// file parser. It mimics the behaviour of names in the master file + /// and accepts raw data. It is not recommended to be used by anything + /// else. + /// \todo Should we make it private and the parser a friend, to hide the + /// constructor? + Name(const char* name_data, size_t data_len, const Name* origin, + bool downcase = false); + /// Constructor from wire-format %data. /// /// The \c buffer parameter normally stores a complete DNS message