LabelSequence::LabelSequence(const void* buf) {
#ifdef ENABLE_DEBUG
- // In non-debug mode, dereferencing the NULL pointer further below
+ // In non-debug mode, dereferencing the null pointer further below
// will lead to a crash, so disabling this check is not
// unsafe. Except for a programming mistake, this case should not
// happen.
using namespace master_lexer_internal;
struct MasterLexer::MasterLexerImpl {
- MasterLexerImpl() : source_(NULL), token_(MasterToken::NOT_STARTED),
+ MasterLexerImpl() : source_(0), token_(MasterToken::NOT_STARTED),
total_size_(0), popped_size_(0),
paren_count_(0), last_was_eol_(true),
has_previous_(false),
}
std::vector<InputSourcePtr> sources_;
- InputSource* source_; // current source (NULL if sources_ is empty)
+ InputSource* source_; // current source (null if sources_ is empty)
MasterToken token_; // currently recognized token (set by a state)
std::vector<char> data_; // placeholder for string data
bool
MasterLexer::pushSource(const char* filename, std::string* error) {
- if (filename == NULL) {
+ if (!filename) {
isc_throw(InvalidParameter,
- "NULL filename for MasterLexer::pushSource");
+ "null filename for MasterLexer::pushSource");
}
try {
impl_->sources_.push_back(InputSourcePtr(new InputSource(filename)));
} catch (const InputSource::OpenError& ex) {
- if (error != NULL) {
+ if (error) {
*error = ex.what();
}
return (false);
}
impl_->popped_size_ += impl_->source_->getPosition();
impl_->sources_.pop_back();
- impl_->source_ = impl_->sources_.empty() ? NULL :
+ impl_->source_ = impl_->sources_.empty() ? 0 :
impl_->sources_.back().get();
impl_->has_previous_ = false;
}
const MasterToken&
MasterLexer::getNextToken(Options options) {
- if (impl_->source_ == NULL) {
+ if (impl_->source_ == 0) {
isc_throw(isc::InvalidOperation, "No source to read tokens from");
}
// Store the current state so we can restore it in ungetToken
// This actually handles EOF internally too.
const State* state = State::start(*this, options);
- if (state != NULL) {
+ if (state) {
state->handle(*this);
}
// Make sure a token was produced. Since this Can Not Happen, we assert
if (paren_count != 0) {
lexerimpl.token_ = MasterToken(MasterToken::UNBALANCED_PAREN);
paren_count = 0; // reset to 0; this helps in lenient mode.
- return (NULL);
+ return (0);
}
lexerimpl.token_ = MasterToken(MasterToken::END_OF_FILE);
- return (NULL);
+ return (0);
} else if (c == ' ' || c == '\t') {
// If requested and we are not in (), recognize the initial space.
if (lexerimpl.last_was_eol_ && paren_count == 0 &&
(options & MasterLexer::INITIAL_WS) != 0) {
lexerimpl.last_was_eol_ = false;
lexerimpl.token_ = MasterToken(MasterToken::INITIAL_WS);
- return (NULL);
+ return (0);
}
} else if (c == '\n') {
lexerimpl.last_was_eol_ = true;
if (paren_count == 0) { // we don't recognize EOL if we are in ()
lexerimpl.token_ = MasterToken(MasterToken::END_OF_LINE);
- return (NULL);
+ return (0);
}
} else if (c == '\r') {
if (paren_count == 0) { // check if we are in () (see above)
return (&QSTRING_STATE);
} else {
lexerimpl.token_ = MasterToken(MasterToken::UNEXPECTED_QUOTES);
- return (NULL);
+ return (0);
}
} else if (c == '(') {
lexerimpl.last_was_eol_ = false;
lexerimpl.last_was_eol_ = false;
if (paren_count == 0) {
lexerimpl.token_ = MasterToken(MasterToken::UNBALANCED_PAREN);
- return (NULL);
+ return (0);
}
--paren_count;
} else if ((options & MasterLexer::NUMBER) != 0 &&isdigit(c)) {
/// beg[len] is \0. This means the application can use the bytes as a
/// validly nul-terminated C string if there is no intermediate nul
/// character. Note also that due to this property beg is always non
- /// NULL; for an empty string len will be set to 0 and beg[0] is \0.
+ /// null; for an empty string len will be set to 0 and beg[0] is \0.
struct StringRegion {
const char* beg; ///< The start address of the string
size_t len; ///< The length of the string in bytes
///
/// In the case possible system errors in opening the file (most likely
/// because of specifying a non-existent or unreadable file), it returns
- /// false, and if the optional \c error parameter is non NULL, it will be
+ /// false, and if the optional \c error parameter is non null, it will be
/// set to a description of the error (any existing content of the string
/// will be discarded). If opening the file succeeds, the given
/// \c error parameter will be intact.
/// by throwing an exception. See the note for the class description
/// about the distinction.
///
- /// \throw InvalidParameter filename is NULL
- /// \param filename A non NULL string specifying a master file
+ /// \throw InvalidParameter filename is null
+ /// \param filename A non null string specifying a master file
/// \param error If non null, a placeholder to set error description in
/// case of failure.
///
/// from the initial state.
///
/// If the whole lexer transition is completed within start(), it sets the
-/// identified token and returns NULL; otherwise it returns a pointer to
+/// identified token and returns null; otherwise it returns a pointer to
/// an object of a specific state class that completes the session
/// on the call of handle().
///
///
/// \param lexer The lexer object that holds the main context.
/// \param options The options passed to getNextToken().
- /// \return A pointer to the next state object or NULL if the transition
+ /// \return A pointer to the next state object or null if the transition
/// is completed.
static const State* start(MasterLexer& lexer,
MasterLexer::Options options);
/// start(). In the usual state transition design pattern, it would
/// return the next state. But as we noticed, we never have another
/// state, so we simplify it by not returning anything instead of
- /// returning NULL every time.
+ /// returning null every time.
///
/// \throw MasterLexer::ReadError Unexpected I/O error
/// \throw std::bad_alloc Internal resource allocation failure
///
/// \param lexer The lexer object that holds the main context.
/// \return A pointer to the implementation class object of the given
- /// lexer. This is never NULL.
+ /// lexer. This is never null.
MasterLexer::MasterLexerImpl* getLexerImpl(MasterLexer& lexer) const {
return (lexer.impl_.get());
}
MasterLoaderCallbacks callbacks_;
const AddRRCallback add_callback_;
boost::scoped_ptr<RRTTL> default_ttl_; // Default TTL of RRs used when
- // unspecified. If NULL no default
+ // unspecified. If null no default
// is known.
boost::scoped_ptr<RRTTL> current_ttl_; // The TTL used most recently.
// Initially unset. Once set
const rdata::RdataPtr rdata =
rdata::createRdata(rrtype, zone_class_, generated_rdata);
- // In case we get NULL, it means there was error creating the
+ // In case we get null, it means there was error creating the
// Rdata. The errors should have been reported by callbacks_
// already. We need to decide if we want to continue or not.
if (rdata) {
}
// This means the same name as previous.
- if (last_name_.get() == NULL) {
+ if (!last_name_) {
isc_throw(InternalException, "No previous name to use in "
"place of initial whitespace");
} else if (!previous_name_) {
rdata::createRdata(rrtype, zone_class_, lexer_,
&active_origin_, options_, callbacks_);
- // In case we get NULL, it means there was error creating
+ // In case we get null, it means there was error creating
// the Rdata. The errors should have been reported by
// callbacks_ already. We need to decide if we want to continue
// or not.
Message::Mode mode_;
qid_t qid_;
- // We want to use NULL for [op,r]code_ to mean the code being not
+ // We want to use null for [op,r]code_ to mean the code being not
// correctly parsed or set. We store the real code object in
// xxcode_placeholder_ and have xxcode_ refer to it when the object
// is valid.
MessageImpl::init() {
flags_ = 0;
qid_ = 0;
- rcode_ = NULL;
- opcode_ = NULL;
+ rcode_ = 0;
+ opcode_ = 0;
edns_ = EDNSPtr();
tsig_rr_ = ConstTSIGRecordPtr();
isc_throw(InvalidMessageOperation,
"Message rendering attempted in non render mode");
}
- if (rcode_ == NULL) {
+ if (!rcode_) {
isc_throw(InvalidMessageOperation,
"Message rendering attempted without Rcode set");
}
- if (opcode_ == NULL) {
+ if (!opcode_) {
isc_throw(InvalidMessageOperation,
"Message rendering attempted without Opcode set");
}
// case correctly later when that happens. orig_xxx variables remember
// some configured parameters of renderer in case they are needed in
// truncation processing below.
- const size_t tsig_len = (tsig_ctx != NULL) ? tsig_ctx->getTSIGLength() : 0;
+ const size_t tsig_len = (tsig_ctx ? tsig_ctx->getTSIGLength() : 0);
const size_t orig_msg_len_limit = renderer.getLengthLimit();
const AbstractMessageRenderer::CompressMode orig_compress_mode =
renderer.getCompressMode();
// If we're adding a TSIG to a truncated message, clear all RRsets
// from the message except for the question before adding the TSIG.
// If even (some of) the question doesn't fit, don't include it.
- if (tsig_ctx != NULL && renderer.isTruncated()) {
+ if (tsig_ctx && renderer.isTruncated()) {
renderer.clear();
renderer.setLengthLimit(orig_msg_len_limit - tsig_len);
renderer.setCompressMode(orig_compress_mode);
renderer.writeUint16At(arcount, header_pos);
// Add TSIG, if necessary, at the end of the message.
- if (tsig_ctx != NULL) {
+ if (tsig_ctx) {
// Release the reserved space in the renderer.
renderer.setLengthLimit(orig_msg_len_limit);
const Rcode&
Message::getRcode() const {
- if (impl_->rcode_ == NULL) {
+ if (!impl_->rcode_) {
isc_throw(InvalidMessageOperation, "getRcode attempted before set");
}
return (*impl_->rcode_);
const Opcode&
Message::getOpcode() const {
- if (impl_->opcode_ == NULL) {
+ if (!impl_->opcode_) {
isc_throw(InvalidMessageOperation, "getOpcode attempted before set");
}
return (*impl_->opcode_);
Message::addRRset(const Section section, RRsetPtr rrset) {
if (!rrset) {
isc_throw(InvalidParameter,
- "NULL RRset is given to Message::addRRset");
+ "null RRset is given to Message::addRRset");
}
if (impl_->mode_ != Message::RENDER) {
isc_throw(InvalidMessageOperation,
string
Message::toText() const {
- if (impl_->rcode_ == NULL) {
+ if (!impl_->rcode_) {
isc_throw(InvalidMessageOperation,
"Message::toText() attempted without Rcode set");
}
- if (impl_->opcode_ == NULL) {
+ if (!impl_->opcode_) {
isc_throw(InvalidMessageOperation,
"Message::toText() attempted without Opcode set");
}
lexical_cast<string>(impl_->counts_[SECTION_AUTHORITY]);
unsigned int arcount = impl_->counts_[SECTION_ADDITIONAL];
- if (impl_->edns_ != NULL) {
+ if (impl_->edns_) {
++arcount;
}
- if (impl_->tsig_rr_ != NULL) {
+ if (impl_->tsig_rr_) {
++arcount;
}
s += ", ADDITIONAL: " + lexical_cast<string>(arcount) + "\n";
- if (impl_->edns_ != NULL) {
+ if (impl_->edns_) {
s += "\n;; OPT PSEUDOSECTION:\n";
s += impl_->edns_->toText();
}
SectionFormatter<RRsetPtr>(SECTION_ADDITIONAL, s));
}
- if (impl_->tsig_rr_ != NULL) {
+ if (impl_->tsig_rr_) {
s += "\n;; TSIG PSEUDOSECTION:\n";
s += impl_->tsig_rr_->toText();
}
using pointer = T*;
using reference = T&;
- SectionIterator() : impl_(NULL) {}
+ SectionIterator() : impl_(0) {}
SectionIterator(const SectionIteratorImpl<T>& impl);
~SectionIterator();
SectionIterator(const SectionIterator<T>& source);
///
/// \exception InvalidMessageOperation Message is not in the PARSE mode.
///
- /// \return A pointer to the stored \c TSIGRecord or \c NULL.
+ /// \return A pointer to the stored \c TSIGRecord or null.
const TSIGRecord* getTSIGRecord() const;
/// \brief Returns the number of RRs contained in the given section.
/// data before inserting RRsets. The caller is responsible for
/// checking for these (see \c hasRRset() below).
///
- /// \throw InvalidParameter rrset is NULL
+ /// \throw InvalidParameter rrset is null
/// \throw InvalidMessageOperation The message is not in the \c RENDER
/// mode.
/// \throw OutOfRange \c section doesn't specify a valid \c Section value.
///
/// \param section The message section to which the rrset is to be added
- /// \param rrset The rrset to be added. Must not be NULL.
+ /// \param rrset The rrset to be added. Must not be null.
void addRRset(const Section section, RRsetPtr rrset);
/// \brief Determine whether the given section already has an RRset
/// \c Rcode must have been set beforehand; otherwise, an exception of
/// class \c InvalidMessageOperation will be thrown.
///
- /// If a non-NULL \c tsig_ctx is passed, it will also add a TSIG RR
+ /// If a non-null \c tsig_ctx is passed, it will also add a TSIG RR
/// with (in many cases) the TSIG MAC for the message along with the
/// given TSIG context (\c tsig_ctx). The TSIG RR will be placed at
/// the end of \c renderer. The \c TSIGContext at \c tsig_ctx will
void
AbstractMessageRenderer::setBuffer(OutputBuffer* buffer) {
- if (buffer != NULL && buffer_->getLength() != 0) {
+ if (buffer && buffer_->getLength() != 0) {
isc_throw(isc::InvalidParameter,
"MessageRenderer buffer cannot be set when in use");
}
- if (buffer == NULL && buffer_ == &local_buffer_) {
+ if (!buffer && buffer_ == &local_buffer_) {
isc_throw(isc::InvalidParameter,
"Default MessageRenderer buffer cannot be reset");
}
- if (buffer == NULL) {
+ if (!buffer) {
// Reset to the default buffer, then clear other internal resources.
// The order is important; we need to keep the used buffer intact.
buffer_ = &local_buffer_;
/// \brief Buffer to store data.
///
- /// Note that the class interface ensures this pointer is never NULL;
+ /// Note that the class interface ensures this pointer is never null;
/// it either refers to \c local_buffer_ or to an application-supplied
/// buffer by \c setBuffer().
///
/// This method can be used for an application that manages an output
/// buffer separately from the message renderer and wants to keep reusing
/// the renderer. When the renderer is associated with the default buffer
- /// and the given pointer is non NULL, the given buffer will be
+ /// and the given pointer is non null, the given buffer will be
/// (temporarily) used for subsequent message rendering; if the renderer
- /// is associated with a temporary buffer and the given pointer is NULL,
+ /// is associated with a temporary buffer and the given pointer is null,
/// the renderer will be reset with the default buffer. In the latter
/// case any additional resources (possibly specific to a derived renderer
/// class) will be cleared, but the temporary buffer is kept as the latest
/// that could cause disruption such as dereferencing an invalid object.
/// First, a temporary buffer must not be set when the associated buffer
/// is in use, that is, any data are stored in the buffer. Also, the
- /// default buffer cannot be "reset"; when NULL is specified a temporary
+ /// default buffer cannot be "reset"; when null is specified a temporary
/// buffer must have been set beforehand. If these conditions aren't met
/// an isc::InvalidParameter exception will be thrown. This method is
/// exception free otherwise.
/// \throw isc::InvalidParameter A restrictions of the method usage isn't
/// met.
///
- /// \param buffer A pointer to a temporary output buffer or NULL for reset
+ /// \param buffer A pointer to a temporary output buffer or null for reset
/// it.
void setBuffer(isc::util::OutputBuffer* buffer);
Name::Name(const char* namedata, size_t data_len, const Name* origin,
bool downcase) {
// Check validity of data
- if (namedata == NULL || data_len == 0) {
+ if (!namedata || data_len == 0) {
isc_throw(isc::InvalidParameter,
"No data provided to Name constructor");
}
// It is safe to check now, we know there's at least one character.
const bool absolute = (namedata[data_len - 1] == '.');
// If we are not absolute, we need the origin to complete the name.
- if (!absolute && origin == NULL) {
+ if (!absolute && !origin) {
isc_throw(MissingNameOrigin,
"No origin available and name is relative");
}
NameParserException(file, line, what) {}
};
-/// \brief Thrown when origin is NULL and is needed.
+/// \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.
+/// set to null.
class MissingNameOrigin : public NameParserException {
public:
MissingNameOrigin(const char* file, size_t line, const char* what) :
/// 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
+ /// 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
+ /// \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 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
}
error_issued = true;
- if (token == NULL) {
+ if (!token) {
callbacks.error(lexer.getSourceName(), lexer.getSourceLine(),
"createRdata from text failed: " + string(reason));
return;
// Catching all isc::Exception is too broad, but right now we don't
// have better granularity. When we complete #2518 we can make this
// finer.
- fromtextError(error_issued, lexer, callbacks, NULL, ex.what());
+ fromtextError(error_issued, lexer, callbacks, 0, ex.what());
}
// Other exceptions mean a serious implementation bug or fatal system
// error; it doesn't make sense to catch and try to recover from them
"file does not end with newline");
return (rdata);
default:
- rdata.reset(); // we'll return NULL
+ rdata.reset(); // we'll return null
fromtextError(error_issued, lexer, callbacks, &token,
"extra input text");
// Continue until we see EOL or EOF
/// cases quite differently from other versions. It internally catches
/// most of syntax and semantics errors of the input (reported as exceptions),
/// calls the corresponding callback specified by the \c callbacks parameters,
-/// and returns a NULL smart pointer. If the caller rather wants to get
+/// and returns a null smart pointer. If the caller rather wants to get
/// an exception in these cases, it can pass a callback that internally
/// throws on error. Some critical exceptions such as \c std::bad_alloc are
/// still propagated to the upper layer as it doesn't make sense to try
/// \param rrclass An \c RRClass object specifying the type/class pair.
/// \param lexer A \c MasterLexer object parsing a master file for the
/// RDATA to be created
-/// \param origin If non NULL, specifies the origin of any domain name fields
+/// \param origin If non null, specifies the origin of any domain name fields
/// of the RDATA that are non absolute.
/// \param options Master loader options controlling how to deal with errors
/// or non critical issues in the parsed RDATA.
/// \param callbacks Callback to be called when an error or non critical issue
/// is found.
/// \return An \c RdataPtr object pointing to the created
-/// \c Rdata object. Will be NULL if parsing fails.
+/// \c Rdata object. Will be null if parsing fails.
RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass,
MasterLexer& lexer, const Name* origin,
MasterLoader::Options options,
MasterLexer lexer;
lexer.pushSource(ss);
- impl_ = constructFromLexer(lexer, NULL);
+ impl_ = constructFromLexer(lexer, 0);
if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
isc_throw(InvalidRdataText,
isc_throw(OutOfRange, "TSIG Time Signed is too large: " <<
time_signed);
}
- if ((mac_size == 0 && mac != NULL) || (mac_size > 0 && mac == NULL)) {
+ if ((mac_size == 0 && mac) || (mac_size > 0 && !mac)) {
isc_throw(InvalidParameter, "TSIG MAC size and data inconsistent");
}
- if ((other_len == 0 && other_data != NULL) ||
- (other_len > 0 && other_data == NULL)) {
+ if ((other_len == 0 && other_data) || (other_len > 0 && !other_data)) {
isc_throw(InvalidParameter,
"TSIG Other data length and data inconsistent");
}
if (!impl_->mac_.empty()) {
return (&impl_->mac_[0]);
} else {
- return (NULL);
+ return (0);
}
}
if (!impl_->other_data_.empty()) {
return (&impl_->other_data_[0]);
} else {
- return (NULL);
+ return (0);
}
}
MasterLexer lexer;
lexer.pushSource(ss);
- nsname_ = createNameFromLexer(lexer, NULL);
+ nsname_ = createNameFromLexer(lexer, 0);
if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
isc_throw(InvalidRdataText, "extra input text for NS: "
///
/// The \c lexer should point to the beginning of valid textual
/// representation of an NS RDATA. The NSDNAME field can be
-/// non-absolute if \c origin is non-NULL, in which case \c origin is
+/// non-absolute if \c origin is non-null, in which case \c origin is
/// used to make it absolute. It must not be represented as a quoted
/// string.
///
///
/// \param lexer A \c MasterLexer object parsing a master file for the
/// RDATA to be created
-/// \param origin If non NULL, specifies the origin of NSDNAME when it
+/// \param origin If non null, specifies the origin of NSDNAME when it
/// is non-absolute.
NS::NS(MasterLexer& lexer, const Name* origin,
MasterLoader::Options, MasterLoaderCallbacks&) :
MasterLexer lexer;
lexer.pushSource(ss);
- ptr_name_ = createNameFromLexer(lexer, NULL);
+ ptr_name_ = createNameFromLexer(lexer, 0);
if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
isc_throw(InvalidRdataText, "extra input text for PTR: "
///
/// The \c lexer should point to the beginning of valid textual
/// representation of a PTR RDATA. The PTRDNAME field can be
-/// non-absolute if \c origin is non-NULL, in which case \c origin is
+/// non-absolute if \c origin is non-null, in which case \c origin is
/// used to make it absolute. It must not be represented as a quoted
/// string.
///
///
/// \param lexer A \c MasterLexer object parsing a master file for the
/// RDATA to be created
-/// \param origin If non NULL, specifies the origin of PTRDNAME when it
+/// \param origin If non null, specifies the origin of PTRDNAME when it
/// is non-absolute.
PTR::PTR(MasterLexer& lexer, const Name* origin,
MasterLoader::Options, MasterLoaderCallbacks&) :
MasterLexer lexer;
lexer.pushSource(iss);
- impl_ = constructFromLexer(lexer, NULL);
+ impl_ = constructFromLexer(lexer, 0);
if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
isc_throw(InvalidRdataText, "extra input text for RRSIG: "
///
/// The \c lexer should point to the beginning of valid textual representation
/// of an RRSIG RDATA. The Signer's Name fields can be non absolute if \c
-/// origin is non NULL, in which case \c origin is used to make it absolute.
+/// origin is non null, in which case \c origin is used to make it absolute.
/// This must not be represented as a quoted string.
///
/// The Original TTL field is a valid decimal representation of an unsigned
///
/// \param lexer A \c MasterLexer object parsing a master file for the
/// RDATA to be created
-/// \param origin If non NULL, specifies the origin of Signer's Name when
+/// \param origin If non null, specifies the origin of Signer's Name when
/// it is non absolute.
RRSIG::RRSIG(MasterLexer& lexer, const Name* origin,
MasterLoader::Options, MasterLoaderCallbacks&) {
MasterLexer lexer;
lexer.pushSource(ss);
- mname_ = createNameFromLexer(lexer, NULL);
- rname_ = createNameFromLexer(lexer, NULL);
+ mname_ = createNameFromLexer(lexer, 0);
+ rname_ = createNameFromLexer(lexer, 0);
fillParameters(lexer, numdata_);
if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
///
/// The \c lexer should point to the beginning of valid textual representation
/// of an SOA RDATA. The MNAME and RNAME fields can be non absolute if
-/// \c origin is non NULL, in which case \c origin is used to make them
+/// \c origin is non null, in which case \c origin is used to make them
/// absolute. These must not be represented as a quoted string.
///
/// The REFRESH, RETRY, EXPIRE, and MINIMUM fields can be either a valid
///
/// \param lexer A \c MasterLexer object parsing a master file for the
/// RDATA to be created
-/// \param origin If non NULL, specifies the origin of MNAME and RNAME when
+/// \param origin If non null, specifies the origin of MNAME and RNAME when
/// they are non absolute.
SOA::SOA(MasterLexer& lexer, const Name* origin,
MasterLoader::Options, MasterLoaderCallbacks&) :
A::toText() const {
char addr_string[sizeof("255.255.255.255")];
- if (inet_ntop(AF_INET, &addr_, addr_string, sizeof(addr_string)) == NULL) {
+ if (inet_ntop(AF_INET, &addr_, addr_string, sizeof(addr_string)) == 0) {
isc_throw(Unexpected,
"Failed to convert IN/A RDATA to textual IPv4 address");
}
AAAA::toText() const {
char addr_string[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
- if (inet_ntop(AF_INET6, &addr_, addr_string, sizeof(addr_string))
- == NULL) {
+ if (inet_ntop(AF_INET6, &addr_, addr_string, sizeof(addr_string)) == 0) {
isc_throw(Unexpected,
"Failed to convert IN/AAAA RDATA to textual IPv6 address");
}
/// otherwise, an exception of type \c OutOfRange will be thrown.
///
/// \c mac_size and \c mac correspond to the MAC Size and MAC fields,
- /// respectively. When the MAC field is empty, \c mac must be NULL.
+ /// respectively. When the MAC field is empty, \c mac must be null.
/// \c mac_size and \c mac must be consistent %in that \c mac_size is 0 if
- /// and only if \c mac is NULL; otherwise an exception of type
+ /// and only if \c mac is null; otherwise an exception of type
/// InvalidParameter will be thrown.
///
/// The same restriction applies to \c other_len and \c other_data,
/// \brief Return the value of the MAC field.
///
- /// If the MAC field is empty, it returns NULL.
+ /// If the MAC field is empty, it returns null.
/// Otherwise, the memory region beginning at the address returned by
/// this method is valid up to the bytes specified by the return value
/// of \c getMACSize().
///
/// \param lexer A \c MasterLexer object. Its next token is expected to be
/// a string that represent a domain name.
-/// \param origin If non NULL, specifies the origin of the name to be
+/// \param origin If non null, specifies the origin of the name to be
/// constructed.
///
/// \return A new Name object that corresponds to the next string token of
class_code)) {
return (new RRClass(class_code));
}
- return (NULL);
+ return (0);
}
ostream&
///
/// If the given text represents a valid RRClass, it returns a
/// pointer to a new \c RRClass object. If the given text does not
- /// represent a valid RRClass, it returns \c NULL.
+ /// represent a valid RRClass, it returns null.
///
/// One main purpose of this function is to minimize the overhead
/// when the given text does not represent a valid RR class. For
/// This function never throws the \c InvalidRRClass exception.
///
/// \param class_str A string representation of the \c RRClass.
- /// \return A new RRClass object for the given text or a \c NULL
- /// value.
+ /// \return A new RRClass object for the given text or a null value.
static RRClass* createFromText(const std::string& class_str);
///
return (genfound->second.get());
}
- return (NULL);
+ return (0);
}
}
const AbstractRdataFactory* factory =
findRdataFactory(impl_.get(), rrtype, rrclass);
- if (factory != NULL) {
+ if (factory) {
return (factory->create(rdata_string));
}
InputBuffer& buffer, size_t rdata_len) {
const AbstractRdataFactory* factory =
findRdataFactory(impl_.get(), rrtype, rrclass);
- if (factory != NULL) {
+ if (factory) {
return (factory->create(buffer, rdata_len));
}
const Rdata& source) {
const AbstractRdataFactory* factory =
findRdataFactory(impl_.get(), rrtype, rrclass);
- if (factory != NULL) {
+ if (factory) {
return (factory->create(source));
}
MasterLoaderCallbacks& callbacks) {
const AbstractRdataFactory* factory =
findRdataFactory(impl_.get(), rrtype, rrclass);
- if (factory != NULL) {
+ if (factory) {
return (factory->create(lexer, name, options, callbacks));
}
/// the Rdata; it doesn't update the lexer to reach the end of line or
/// file or doesn't care about whether there's an extra (garbage) token
/// after the textual RDATA representation. Another difference is that
- /// this method can throw on error and never returns a NULL pointer.
+ /// this method can throw on error and never returns a null pointer.
///
/// For other details and parameters, see the description of
/// \c rdata::createRdata().
bool
parseTTLString(const string& ttlstr, uint32_t& ttlval, string* error_txt) {
if (ttlstr.empty()) {
- if (error_txt != NULL) {
+ if (error_txt) {
*error_txt = "Empty TTL string";
}
return (false);
if (unit == end) {
if (units_mode) {
// We had some units before. The last one is missing unit.
- if (error_txt != NULL) {
+ if (error_txt) {
*error_txt = "Missing the last unit: " + ttlstr;
}
return (false);
}
}
if (!found) {
- if (error_txt != NULL) {
+ if (error_txt) {
*error_txt = "Unknown unit used: " +
boost::lexical_cast<string>(*unit) + " in: " + ttlstr;
}
}
// Now extract the number.
if (unit == pos) {
- if (error_txt != NULL) {
+ if (error_txt) {
*error_txt = "Missing number in TTL: " + ttlstr;
}
return (false);
const uint64_t value =
boost::lexical_cast<uint64_t>(string(pos, unit));
if (value > max_allowed) {
- if (error_txt != NULL) {
+ if (error_txt) {
*error_txt = "Part of TTL out of range: " + ttlstr;
}
return (false);
// grow, so if we get out of range now, it won't get better, so
// there's no need to continue).
if (val < seconds || val > 0xffffffff) {
- if (error_txt != NULL) {
+ if (error_txt) {
*error_txt = "Part of TTL out of range: " + ttlstr;
}
return (false);
pos = unit + 1;
}
} catch (const boost::bad_lexical_cast&) {
- if (error_txt != NULL) {
+ if (error_txt) {
*error_txt = "invalid TTL: " + ttlstr;
}
return (false);
ttlval = val;
} else {
// This could be due to negative numbers in input, etc.
- if (error_txt != NULL) {
+ if (error_txt) {
*error_txt = "TTL out of range: " + ttlstr;
}
return (false);
RRTTL*
RRTTL::createFromText(const string& ttlstr) {
uint32_t ttlval;
- if (parseTTLString(ttlstr, ttlval, NULL)) {
+ if (parseTTLString(ttlstr, ttlval, 0)) {
return (new RRTTL(ttlval));
}
- return (NULL);
+ return (0);
}
RRTTL::RRTTL(InputBuffer& buffer) {
///
/// If the given text represents a valid RRTTL, it returns a pointer
/// to a new RRTTL object. If the given text does not represent a
- /// valid RRTTL, it returns \c NULL..
+ /// valid RRTTL, it returns null..
///
/// One main purpose of this function is to minimize the overhead
/// when the given text does not represent a valid RR TTL. For this
/// This function never throws the \c InvalidRRTTL exception.
///
/// \param ttlstr A string representation of the \c RRTTL.
- /// \return A new RRTTL object for the given text or a \c NULL value.
+ /// \return A new RRTTL object for the given text or a null value.
static RRTTL* createFromText(const std::string& ttlstr);
///
//@}
namespace {
class EDNSTest : public ::testing::Test {
protected:
- EDNSTest() : rrtype(RRType::OPT()), buffer(NULL, 0), obuffer(0), rcode(0) {
+ EDNSTest() : rrtype(RRType::OPT()), buffer(0, 0), obuffer(0), rcode(0) {
opt_rdata = ConstRdataPtr(new generic::OPT());
edns_base.setUDPSize(4096);
}
"d.root-servers.net", "e.root-servers.net", "f.root-servers.net",
"g.root-servers.net", "h.root-servers.net", "i.root-servers.net",
"j.root-servers.net", "k.root-servers.net", "l.root-servers.net",
- "m.root-servers.net", NULL
+ "m.root-servers.net", 0
};
const char* const jp_servers[] = {
"a.dns.jp", "b.dns.jp", "c.dns.jp", "d.dns.jp", "e.dns.jp",
- "f.dns.jp", "g.dns.jp", NULL
+ "f.dns.jp", "g.dns.jp", 0
};
const char* const cn_servers[] = {
"a.dns.cn", "b.dns.cn", "c.dns.cn", "d.dns.cn", "e.dns.cn",
- "ns.cernet.net", NULL
+ "ns.cernet.net", 0
};
const char* const ca_servers[] = {
"k.ca-servers.ca", "e.ca-servers.ca", "a.ca-servers.ca", "z.ca-servers.ca",
"tld.isc-sns.net", "c.ca-servers.ca", "j.ca-servers.ca", "l.ca-servers.ca",
- "sns-pb.isc.org", "f.ca-servers.ca", NULL
+ "sns-pb.isc.org", "f.ca-servers.ca", 0
};
// A helper function used in the getHash test below.
// Store all test names and their super domain names (excluding the
// "root" label) in the set, calculates their hash values, and increments
// the counter for the corresponding hash "bucket".
- for (size_t i = 0; servers[i] != NULL; ++i) {
+ for (size_t i = 0; servers[i]; ++i) {
const Name name(servers[i]);
for (size_t l = 0; l < name.getLabelCount() - 1; ++l) {
pair<set<Name>::const_iterator, bool> ret =
// These checks are enabled only in debug mode in the LabelSequence
// class.
TEST_F(LabelSequenceTest, badDeserialize) {
- EXPECT_THROW(LabelSequence(NULL), isc::BadValue);
+ EXPECT_THROW(LabelSequence(0), isc::BadValue);
const uint8_t zero_offsets[] = { 0 };
EXPECT_THROW(LabelSequence ls(zero_offsets), isc::BadValue);
const uint8_t toomany_offsets[] = { Name::MAX_LABELS + 1 };
class MasterLexerStateTest : public ::testing::Test {
protected:
MasterLexerStateTest() : common_options(MasterLexer::INITIAL_WS),
- s_null(NULL),
+ s_null(0),
s_crlf(State::getInstance(State::CRLF)),
s_string(State::getInstance(State::String)),
s_qstring(State::getInstance(State::QString)),
EXPECT_EQ(expected, actual);
// There should be "hidden" nul-terminator after the string data.
- ASSERT_NE(static_cast<const char*>(NULL), token.getStringRegion().beg);
+ ASSERT_NE(static_cast<const char*>(0), token.getStringRegion().beg);
EXPECT_EQ(0, *(token.getStringRegion().beg + token.getStringRegion().len));
}
EXPECT_EQ(0, lexer.getSourceCount());
EXPECT_EQ(143, lexer.getTotalSourceSize()); // this shouldn't change
- // If we give a non NULL string pointer, its content will be intact
+ // If we give a non null string pointer, its content will be intact
// if pushSource succeeds.
std::string error_txt = "dummy";
EXPECT_TRUE(lexer.pushSource(TEST_DATA_SRCDIR "/masterload.txt",
}
TEST_F(MasterLexerTest, pushBadFileName) {
- EXPECT_THROW(lexer.pushSource(NULL), isc::InvalidParameter);
+ EXPECT_THROW(lexer.pushSource(0), isc::InvalidParameter);
}
TEST_F(MasterLexerTest, pushFileFail) {
EXPECT_FALSE(lexer.pushSource("no-such-file", &error_txt));
EXPECT_FALSE(error_txt.empty());
- // It's safe to pass NULL error_txt (either explicitly or implicitly as
+ // It's safe to pass null error_txt (either explicitly or implicitly as
// the default)
- EXPECT_FALSE(lexer.pushSource("no-such-file", NULL));
+ EXPECT_FALSE(lexer.pushSource("no-such-file", 0));
EXPECT_FALSE(lexer.pushSource("no-such-file"));
}
"$Include",
"$InCluDe",
"\"$INCLUDE\"",
- NULL
+ 0
};
- for (const char** include = includes; *include != NULL; ++include) {
+ for (const char** include = includes; *include != 0; ++include) {
SCOPED_TRACE(*include);
clear();
"$Origin",
"$OrigiN",
"\"$ORIGIN\"",
- NULL
+ 0
};
- for (const char** origin = origins; *origin != NULL; ++origin) {
+ for (const char** origin = origins; *origin != 0; ++origin) {
SCOPED_TRACE(*origin);
clear();
"$Generate",
"$GeneratE",
"\"$GENERATE\"",
- NULL
+ 0
};
- for (const char** generate = generates; *generate != NULL; ++generate) {
+ for (const char** generate = generates; *generate != 0; ++generate) {
SCOPED_TRACE(*generate);
clear();
struct ErrorCase {
const char* const line; // The broken line in master file
- const char* const reason; // If non NULL, the reason string
+ const char* const reason; // If non null, the reason string
const char* const problem; // Description of the problem for SCOPED_TRACE
} const error_cases[] = {
- { "www... 3600 IN A 192.0.2.1", NULL, "Invalid name" },
- { "www FORTNIGHT IN A 192.0.2.1", NULL, "Invalid TTL" },
- { "www 3600 XX A 192.0.2.1", NULL, "Invalid class" },
- { "www 3600 IN A bad_ip", NULL, "Invalid Rdata" },
+ { "www... 3600 IN A 192.0.2.1", 0, "Invalid name" },
+ { "www FORTNIGHT IN A 192.0.2.1", 0, "Invalid TTL" },
+ { "www 3600 XX A 192.0.2.1", 0, "Invalid class" },
+ { "www 3600 IN A bad_ip", 0, "Invalid Rdata" },
// Parameter ordering errors
{ "www IN A 3600 192.168.2.7",
"createRdata from text failed: unexpected end of input",
"Missing Rdata" },
- { "www 3600 IN", NULL, "Unexpected EOLN" },
+ { "www 3600 IN", 0, "Unexpected EOLN" },
{ "www 3600 CH TXT nothing", "Class mismatch: CH vs. IN",
"Class mismatch" },
- { "www \"3600\" IN A 192.0.2.1", NULL, "Quoted TTL" },
- { "www 3600 \"IN\" A 192.0.2.1", NULL, "Quoted class" },
- { "www 3600 IN \"A\" 192.0.2.1", NULL, "Quoted type" },
- { "unbalanced)paren 3600 IN A 192.0.2.1", NULL, "Token error 1" },
- { "www 3600 unbalanced)paren A 192.0.2.1", NULL,
+ { "www \"3600\" IN A 192.0.2.1", 0, "Quoted TTL" },
+ { "www 3600 \"IN\" A 192.0.2.1", 0, "Quoted class" },
+ { "www 3600 IN \"A\" 192.0.2.1", 0, "Quoted type" },
+ { "unbalanced)paren 3600 IN A 192.0.2.1", 0, "Token error 1" },
+ { "www 3600 unbalanced)paren A 192.0.2.1", 0,
"Token error 2" },
// Check the unknown directive. The rest looks like ordinary RR,
// so we see the $ is actually special.
- { "$UNKNOWN 3600 IN A 192.0.2.1", NULL, "Unknown $ directive" },
+ { "$UNKNOWN 3600 IN A 192.0.2.1", 0, "Unknown $ directive" },
{ "$INCLUD " TEST_DATA_SRCDIR "/example.org", "Unknown directive 'INCLUD'",
"Include too short" },
{ "$INCLUDES " TEST_DATA_SRCDIR "/example.org",
"Unknown directive 'INCLUDES'", "Include too long" },
{ "$INCLUDE", "unexpected end of input", "Missing include path" },
// The following two error messages are system dependent, omitting
- { "$INCLUDE /file/not/found", NULL, "Include file not found" },
+ { "$INCLUDE /file/not/found", 0, "Include file not found" },
{ "$INCLUDE /file/not/found example.org. and here goes bunch of garbage",
- NULL, "Include file not found and garbage at the end of line" },
+ 0, "Include file not found and garbage at the end of line" },
{ "$ORIGIN", "unexpected end of input", "Missing origin name" },
{ "$ORIGIN invalid...name", "duplicate period in invalid...name",
"Invalid name for origin" },
{ "$TTL \"100\"", "unexpected quotes", "bad TTL, quoted" },
{ "$TT 100", "Unknown directive 'TT'", "bad directive, too short" },
{ "$TTLLIKE 100", "Unknown directive 'TTLLIKE'", "bad directive, extra" },
- { NULL, NULL, NULL }
+ { 0, 0, 0 }
};
// Test a broken zone is handled properly. We test several problems,
// both in strict and lenient mode.
TEST_F(MasterLoaderTest, brokenZone) {
- for (const ErrorCase* ec = error_cases; ec->line != NULL; ++ec) {
+ for (const ErrorCase* ec = error_cases; ec->line; ++ec) {
SCOPED_TRACE(ec->problem);
const string zone(prepareZone(ec->line, true));
EXPECT_THROW(loader_->load(), MasterLoaderError);
EXPECT_FALSE(loader_->loadedSuccessfully());
EXPECT_EQ(1, errors_.size());
- if (ec->reason != NULL) {
+ if (ec->reason) {
checkCallbackMessage(errors_.at(0), ec->reason, 2);
}
EXPECT_TRUE(warnings_.empty());
TEST_F(MessageTest, fromWireWithTSIG) {
// Initially there should be no TSIG
- EXPECT_EQ(static_cast<void*>(NULL), message_parse.getTSIGRecord());
+ EXPECT_FALSE(message_parse.getTSIGRecord());
// getTSIGRecord() is only valid in the parse mode.
EXPECT_THROW(message_render.getTSIGRecord(), InvalidMessageOperation);
0x21, 0xce, 0x6c, 0x6f, 0xff, 0x1e, 0x9e, 0xf3
};
const TSIGRecord* tsig_rr = message_parse.getTSIGRecord();
- ASSERT_NE(static_cast<void*>(NULL), tsig_rr);
+ ASSERT_TRUE(tsig_rr);
EXPECT_EQ(Name("www.example.com"), tsig_rr->getName());
EXPECT_EQ(85, tsig_rr->getLength()); // see TSIGRecordTest.getLength
EXPECT_EQ(TSIGKey::HMACMD5_NAME(), tsig_rr->getRdata().getAlgorithm());
tsig_rr->getRdata().getMACSize());
EXPECT_EQ(0, tsig_rr->getRdata().getError());
EXPECT_EQ(0, tsig_rr->getRdata().getOtherLen());
- EXPECT_EQ(static_cast<void*>(NULL), tsig_rr->getRdata().getOtherData());
+ EXPECT_FALSE(tsig_rr->getRdata().getOtherData());
// If we clear the message for reuse, the recorded TSIG will be cleared.
message_parse.clear(Message::PARSE);
- EXPECT_EQ(static_cast<void*>(NULL), message_parse.getTSIGRecord());
+ EXPECT_FALSE(message_parse.getTSIGRecord());
}
TEST_F(MessageTest, fromWireWithTSIGCompressed) {
// Mostly same as fromWireWithTSIG, but the TSIG owner name is compressed.
factoryFromFile(message_parse, "message_fromWire12.wire");
const TSIGRecord* tsig_rr = message_parse.getTSIGRecord();
- ASSERT_NE(static_cast<void*>(NULL), tsig_rr);
+ ASSERT_TRUE(tsig_rr);
EXPECT_EQ(Name("www.example.com"), tsig_rr->getName());
// len(www.example.com) = 17, but when fully compressed, the length is
// 2 bytes. So the length of the record should be 15 bytes shorter.
// Reset the buffer to the default again. Other internal states and
// resources should be cleared. The used buffer should be intact.
- renderer.setBuffer(NULL);
+ renderer.setBuffer(0);
EXPECT_EQ(sizeof(uint32_t), new_buffer.getLength());
EXPECT_EQ(0, renderer.getLength());
EXPECT_EQ(512, renderer.getLengthLimit());
EXPECT_THROW(renderer.setBuffer(&new_buffer), isc::InvalidParameter);
// Resetting the buffer isn't allowed for the default buffer.
- renderer.setBuffer(NULL);
- EXPECT_THROW(renderer.setBuffer(NULL), isc::InvalidParameter);
+ renderer.setBuffer(0);
+ EXPECT_THROW(renderer.setBuffer(0), isc::InvalidParameter);
// It's okay to reset a temporary buffer without using it.
renderer.setBuffer(&new_buffer);
- EXPECT_NO_THROW(renderer.setBuffer(NULL));
+ EXPECT_NO_THROW(renderer.setBuffer(0));
}
TEST_F(MessageRendererTest, manyRRs) {
EXPECT_EQ(origin_name, Name("@", 1, &origin_name_upper, true));
EXPECT_EQ(origin_name_upper, Name("@", 1, &origin_name_upper, true));
// If we don't provide the origin, it throws
- EXPECT_THROW(Name("@", 1, NULL), MissingNameOrigin);
+ EXPECT_THROW(Name("@", 1, 0), MissingNameOrigin);
}
// Test the master-file constructor does not append the origin when the
EXPECT_EQ(example_name, Name("WWW.EXAMPLE.COM.", 16, &origin_name, true));
EXPECT_EQ(example_name_upper, Name("WWW.EXAMPLE.COM.", 16, &origin_name));
// And it does not require the origin to be provided
- EXPECT_NO_THROW(Name("www.example.com.", 16, NULL));
+ EXPECT_NO_THROW(Name("www.example.com.", 16, 0));
}
// Test the master-file constructor properly appends the origin when
// Check we can prepend more than one label
EXPECT_EQ(Name("a.b.c.d.example.com."), Name("a.b.c.d", 7, &origin_name));
// When the name is relative, we throw.
- EXPECT_THROW(Name("www", 3, NULL), MissingNameOrigin);
+ EXPECT_THROW(Name("www", 3, 0), MissingNameOrigin);
}
// When we don't provide the data, it throws
TEST_F(NameTest, noDataProvided) {
- EXPECT_THROW(Name(NULL, 10, NULL), isc::InvalidParameter);
- EXPECT_THROW(Name(NULL, 10, &origin_name), isc::InvalidParameter);
- EXPECT_THROW(Name("www", 0, NULL), isc::InvalidParameter);
+ EXPECT_THROW(Name(0, 10, 0), isc::InvalidParameter);
+ EXPECT_THROW(Name(0, 10, &origin_name), isc::InvalidParameter);
+ EXPECT_THROW(Name("www", 0, 0), isc::InvalidParameter);
EXPECT_THROW(Name("www", 0, &origin_name), isc::InvalidParameter);
}
TEST_F(NameTest, atSign) {
// If it is alone, it is the origin
EXPECT_EQ(origin_name, Name("@", 1, &origin_name));
- EXPECT_THROW(Name("@", 1, NULL), MissingNameOrigin);
+ EXPECT_THROW(Name("@", 1, 0), MissingNameOrigin);
EXPECT_EQ(Name::ROOT_NAME(), Name("@"));
// It is not alone. It is taken verbatim. We check the name converted
// may be wrong -- if we create it wrong the same way as the tested
// object.
EXPECT_EQ("\\@.", Name("@.").toText());
- EXPECT_EQ("\\@.", Name("@.", 2, NULL).toText());
+ EXPECT_EQ("\\@.", Name("@.", 2, 0).toText());
EXPECT_EQ("\\@something.", Name("@something").toText());
EXPECT_EQ("something\\@.", Name("something@").toText());
EXPECT_EQ("\\@x.example.com.", Name("@x", 2, &origin_name).toText());
{"Test\x1fTest", "Test\\031Test"},
{"Test ~ Test", "Test ~ Test"},
{"Test\x7fTest", "Test\\127Test"},
- {NULL, NULL}
+ {0, 0}
};
TEST_F(CharStringDataTest, charStringDataToString) {
- for (const TestData* cur = conversion_data; cur->data != NULL; ++cur) {
+ for (const TestData* cur = conversion_data; cur->data; ++cur) {
uint8_t idata[32];
size_t length = std::strlen(cur->data);
ASSERT_LT(length, sizeof(idata));
{"Test\x1fTest", "Test\\031Test"},
{"Test ~ Test", "Test ~ Test"},
{"Test\x7fTest", "Test\\127Test"},
- {NULL, NULL}
+ {0, 0}
};
TEST_F(CharStringTest, charStringToString) {
- for (const TestData* cur = conversion_data; cur->data != NULL; ++cur) {
+ for (const TestData* cur = conversion_data; cur->data; ++cur) {
uint8_t idata[32];
size_t length = std::strlen(cur->data);
// length (1 byte) + string (length bytes)
*rdataFactoryFromFile(RRType("DHCID"), RRClass("IN"),
"rdata_dhcid_fromWire")));
- InputBuffer buffer(NULL, 0);
+ InputBuffer buffer(0, 0);
EXPECT_THROW(in::DHCID(buffer, 0), InvalidRdataLength);
// TBD: more tests
*test::createRdataUsingLexer(RRType::NS(), RRClass::IN(),
"ns8")));
- // Exceptions cause NULL to be returned.
+ // Exceptions cause null to be returned.
EXPECT_FALSE(test::createRdataUsingLexer(RRType::NS(), RRClass::IN(),
""));
}
TEST_F(Rdata_OPT_Test, createFromLexer) {
- // OPT RR cannot be created from text. Exceptions cause NULL to be
+ // OPT RR cannot be created from text. Exceptions cause null to be
// returned.
EXPECT_FALSE(test::createRdataUsingLexer(RRType::OPT(), RRClass::IN(),
"this does not matter"));
generic::OPT rdata_opt;
// Append empty option data
- rdata_opt.appendPseudoRR(0x0042, NULL, 0);
+ rdata_opt.appendPseudoRR(0x0042, 0, 0);
// Append simple option data
const uint8_t option_data[] = {'H', 'e', 'l', 'l', 'o'};
*test::createRdataUsingLexer(RRType::RRSIG(), RRClass::IN(),
rrsig_txt)));
- // Exceptions cause NULL to be returned.
+ // Exceptions cause null to be returned.
EXPECT_FALSE(test::createRdataUsingLexer(RRType::RRSIG(), RRClass::IN(),
"INVALIDINPUT"));
}
// A simple case.
checkFromTextSOA<isc::Exception, isc::Exception>(
"ns.example.com. root.example.com. 2010012601 3600 300 3600000 1200",
- NULL, false, false);
+ 0, false, false);
// Beginning and trailing space are ignored.
checkFromTextSOA<isc::Exception, isc::Exception>(
" ns.example.com. root.example.com. "
- "2010012601 3600 300 3600000 1200 ", NULL, false, false);
+ "2010012601 3600 300 3600000 1200 ", 0, false, false);
// using extended TTL-like form for some parameters.
checkFromTextSOA<isc::Exception, isc::Exception>(
"ns.example.com. root.example.com. 2010012601 1H 5M 1000H 20M",
- NULL, false, false);
+ 0, false, false);
// multi-line.
checkFromTextSOA<isc::Exception, isc::Exception>(
"ns.example.com. (root.example.com.\n"
- "2010012601 1H 5M 1000H) 20M", NULL, false, false);
+ "2010012601 1H 5M 1000H) 20M", 0, false, false);
// relative names for MNAME and RNAME with a separate origin (lexer
// version only)
// the lexer expects a string excluding newline and EOF).
checkFromTextSOA<InvalidRdataText, isc::Exception>(
"ns.example.com. root.example.com. 2010012601 1H 5M 1000H 20M\n",
- NULL, true, false);
+ 0, true, false);
checkFromTextSOA<InvalidRdataText, MasterLexer::LexerError>(
"\nns.example.com. root.example.com. 2010012601 1H 5M 1000H 20M",
- NULL, true, true);
+ 0, true, true);
}
TEST_F(Rdata_SOA_Test, createFromWire) {
EXPECT_EQ(3, rdata_tkey.getMode());
EXPECT_EQ(0, rdata_tkey.getError());
EXPECT_EQ(0, rdata_tkey.getKeyLen());
- EXPECT_EQ(static_cast<void*>(0), rdata_tkey.getKey());
+ EXPECT_FALSE(rdata_tkey.getKey());
EXPECT_EQ(0, rdata_tkey.getOtherLen());
- EXPECT_EQ(static_cast<void*>(0), rdata_tkey.getOtherData());
+ EXPECT_FALSE(rdata_tkey.getOtherData());
generic::TKEY tkey2(valid_text2);
EXPECT_EQ(12, tkey2.getKeyLen());
tkey.getKey(), tkey.getKeyLen());
EXPECT_EQ(0, tkey.getOtherLen());
- EXPECT_EQ(static_cast<const void*>(0), tkey.getOtherData());
+ EXPECT_FALSE(tkey.getOtherData());
}
TEST_F(Rdata_TKEY_Test, createFromWire) {
"rdata_tkey_fromWire3.wire"));
const generic::TKEY& tkey(dynamic_cast<generic::TKEY&>(*rdata));
EXPECT_EQ(0, tkey.getKeyLen());
- EXPECT_EQ(static_cast<const void*>(0), tkey.getKey());
+ EXPECT_FALSE(tkey.getKey());
vector<uint8_t> expect_data = { 'a', 'b', 'c', 'd', '0', '1', '2', '3' };
matchWireData(&expect_data[0], expect_data.size(),
EXPECT_EQ(1286779327, rdata_tsig.getTimeSigned());
EXPECT_EQ(300, rdata_tsig.getFudge());
EXPECT_EQ(0, rdata_tsig.getMACSize());
- EXPECT_EQ(static_cast<void*>(NULL), rdata_tsig.getMAC());
+ EXPECT_FALSE(rdata_tsig.getMAC());
EXPECT_EQ(16020, rdata_tsig.getOriginalID());
EXPECT_EQ(TSIGError::BAD_KEY_CODE, rdata_tsig.getError());
EXPECT_EQ(0, rdata_tsig.getOtherLen());
- EXPECT_EQ(static_cast<void*>(NULL), rdata_tsig.getOtherData());
+ EXPECT_FALSE(rdata_tsig.getOtherData());
TSIG tsig2(valid_text2);
EXPECT_EQ(12, tsig2.getMACSize());
EXPECT_EQ(2845, tsig.getOriginalID());
EXPECT_EQ(0, tsig.getOtherLen());
- EXPECT_EQ(static_cast<const void*>(NULL), tsig.getOtherData());
+ EXPECT_FALSE(tsig.getOtherData());
}
TEST_F(Rdata_TSIG_Test, createFromWire) {
const TSIG& tsig(dynamic_cast<TSIG&>(*rdata));
EXPECT_EQ(16, tsig.getError());
EXPECT_EQ(0, tsig.getMACSize());
- EXPECT_EQ(static_cast<const void*>(NULL), tsig.getMAC());
+ EXPECT_FALSE(tsig.getMAC());
}
TEST_F(Rdata_TSIG_Test, createFromWireWithCompression) {
TEST_F(Rdata_TSIG_Test, createFromParams) {
EXPECT_EQ(0, rdata_tsig.compare(TSIG(Name("hmac-md5.sig-alg.reg.int"),
- 1286779327, 300, 0, NULL, 16020, 17, 0, NULL)));
+ 1286779327, 300, 0, 0, 16020, 17, 0, 0)));
const uint8_t fake_data[] = { 0x14, 0x02, 0x84, 0x14, 0x02, 0x84,
0x14, 0x02, 0x84, 0x14, 0x02, 0x84 };
EXPECT_EQ(0, TSIG(valid_text2).compare(TSIG(Name("hmac-sha256"), 1286779327, 300, 12,
- fake_data, 16020, 16, 0, NULL)));
+ fake_data, 16020, 16, 0, 0)));
const uint8_t fake_data2[] = { 0x14, 0x02, 0x84, 0x14, 0x02, 0x84 };
EXPECT_EQ(0, TSIG(valid_text3).compare(TSIG(Name("hmac-sha1"), 1286779327, 300, 12,
EXPECT_THROW(TSIG(Name("hmac-sha256"), 1ULL << 48, 300, 12, fake_data, 16020, 18, 6, fake_data2),
isc::OutOfRange);
- EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, fake_data, 16020, 18, 0, NULL),
+ EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, fake_data, 16020, 18, 0, 0),
isc::InvalidParameter);
- EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 12, NULL, 16020, 18, 0, NULL),
+ EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 12, 0, 16020, 18, 0, 0),
isc::InvalidParameter);
- EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, NULL, 16020, 18, 0, fake_data),
+ EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, 0, 16020, 18, 0, fake_data),
isc::InvalidParameter);
- EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, NULL, 16020, 18, 6, NULL),
+ EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, 0, 16020, 18, 6, 0),
isc::InvalidParameter);
}
// case, then with MasterLexer. For the latter, we need to read and skip
// '\n'. These apply to most of the other cases below.
EXPECT_EQ(0, this->rdata_txt_like.compare(*rdata));
- EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS,
+ EXPECT_EQ(0, TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS,
this->loader_cb).compare(*rdata));
EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType());
// surrounding double-quotes shouldn't change the result.
EXPECT_EQ(0, this->rdata_txt_like_quoted.compare(*rdata));
- EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS,
+ EXPECT_EQ(0, TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS,
this->loader_cb).compare(*rdata));
EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType());
// multi-line input with ()
EXPECT_EQ(0, TypeParam(multi_line).compare(*rdata));
- EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS,
+ EXPECT_EQ(0, TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS,
this->loader_cb).compare(*rdata));
EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType());
// for the same data using escape
EXPECT_EQ(0, TypeParam(escaped_txt).compare(*rdata));
- EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS,
+ EXPECT_EQ(0, TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS,
this->loader_cb).compare(*rdata));
EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType());
this->obuffer.getData(), this->obuffer.getLength());
this->obuffer.clear();
- TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, this->loader_cb).
+ TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS, this->loader_cb).
toWire(this->obuffer);
matchWireData(wiredata_nulltxt, sizeof(wiredata_nulltxt),
this->obuffer.getData(), this->obuffer.getLength());
this->obuffer.getData(), this->obuffer.getLength());
this->obuffer.clear();
- TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, this->loader_cb).
+ TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS, this->loader_cb).
toWire(this->obuffer);
matchWireData(&this->wiredata_longesttxt[0],
this->wiredata_longesttxt.size(),
// Too long text for a valid character-string.
EXPECT_THROW(TypeParam(string(256, 'a')), CharStringTooLong);
- EXPECT_THROW(TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS,
+ EXPECT_THROW(TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS,
this->loader_cb), CharStringTooLong);
EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType());
// The escape character makes the double quote a part of character-string,
// so this is invalid input and should be rejected.
EXPECT_THROW(TypeParam("\"Test-String\\\""), InvalidRdataText);
- EXPECT_THROW(TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS,
+ EXPECT_THROW(TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS,
this->loader_cb), MasterLexer::LexerError);
EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType());
}
SCOPED_TRACE(it);
EXPECT_EQ(0, TypeParam(it).compare(*rdata));
- EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS,
+ EXPECT_EQ(0, TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS,
this->loader_cb).compare(*rdata));
EXPECT_EQ(MasterToken::END_OF_LINE,
this->lexer.getNextToken().getType());
// Valid case.
++line;
ConstRdataPtr rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer,
- NULL, MasterLoader::MANY_ERRORS,
+ 0, MasterLoader::MANY_ERRORS,
callbacks);
EXPECT_EQ(0, aaaa_rdata.compare(*rdata));
EXPECT_FALSE(callback.isCalled());
// It should cause any confusion.
++line;
callback.clear();
- rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL,
+ rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, 0,
MasterLoader::MANY_ERRORS, callbacks);
EXPECT_EQ(0, aaaa_rdata.compare(*rdata));
EXPECT_FALSE(callback.isCalled());
- // Broken RDATA text: extra token. createRdata() returns NULL, error
+ // Broken RDATA text: extra token. createRdata() returns null, error
// callback is called.
++line;
callback.clear();
- EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL,
+ EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, 0,
MasterLoader::MANY_ERRORS, callbacks));
callback.check(src_name, line, CreateRdataCallback::ERROR,
"createRdata from text failed near 'extra-token': "
// callback.
++line;
callback.clear();
- EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL,
+ EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, 0,
MasterLoader::MANY_ERRORS, callbacks));
callback.check(src_name, line, CreateRdataCallback::ERROR,
"createRdata from text failed near 'extra': "
// Lexer error will happen, corresponding error callback will be triggered.
++line;
callback.clear();
- EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL,
+ EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, 0,
MasterLoader::MANY_ERRORS, callbacks));
callback.check(src_name, line, CreateRdataCallback::ERROR,
"createRdata from text failed: unbalanced parentheses");
// triggered.
++line;
callback.clear();
- EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL,
+ EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, 0,
MasterLoader::MANY_ERRORS, callbacks));
callback.check(src_name, line, CreateRdataCallback::ERROR,
"createRdata from text failed: Bad IN/AAAA RDATA text: "
// file is not ended with a newline.
++line;
callback.clear();
- rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL,
+ rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, 0,
MasterLoader::MANY_ERRORS, callbacks);
EXPECT_EQ(0, aaaa_rdata.compare(*rdata));
callback.check(src_name, line, CreateRdataCallback::WARN,
// ExForString for the string version, and ExForLexer for the lexer
// version. throw_str_version and throw_lexer_version are set to true
// iff the string/lexer version is expected to throw, respectively.
- // Parameter origin can be set to non NULL for the origin parameter of
+ // Parameter origin can be set to non null for the origin parameter of
// the lexer version of Rdata constructor.
template <typename RdataType, typename ExForString, typename ExForLexer>
void checkFromText(const std::string& rdata_txt,
const uint16_t code; // 1, 3, etc
const RRClass& (*obj)(); // RRClass::IN(), RRClass::CH(), etc
} known_classes[] = {
- {"IN", 1, RRClass::IN}, {"CH", 3, RRClass::CH},
- {"NONE", 254, RRClass::NONE}, {"ANY", 255, RRClass::ANY},
- {NULL, 0, NULL}
+ {"IN", 1, RRClass::IN},
+ {"CH", 3, RRClass::CH},
+ {"NONE", 254, RRClass::NONE},
+ {"ANY", 255, RRClass::ANY},
+ {0, 0, 0}
};
TEST(RRClassConstTest, wellKnowns) {
TEST_F(RRsetRRSIGTest, getRRsig) {
RRsetPtr sp = rrset_a->getRRsig();
- EXPECT_EQ(static_cast<void*>(NULL), sp.get());
+ EXPECT_FALSE(sp);
sp = rrset_aaaa->getRRsig();
- EXPECT_NE(static_cast<void*>(NULL), sp.get());
+ EXPECT_TRUE(sp);
}
TEST_F(RRsetRRSIGTest, addRRsig) {
RRsetPtr sp = rrset_a->getRRsig();
- EXPECT_EQ(static_cast<void*>(NULL), sp.get());
+ EXPECT_FALSE(sp);
rrset_rrsig = RRsetPtr(new RRset(test_name, RRClass::IN(),
RRType::RRSIG(), RRTTL(3600)));
rrset_a->addRRsig(rrset_rrsig);
sp = rrset_a->getRRsig();
- EXPECT_NE(static_cast<void*>(NULL), sp.get());
+ EXPECT_TRUE(sp);
EXPECT_EQ(2, sp->getRdataCount());
// add to existing RRSIG
// Unassigned 262-32767
{"TA", 32768, []() -> const RRType& {static const RRType r("TA"); return (r);}},
{"DLV", 32769, []() -> const RRType& {static const RRType r("DLV"); return (r);}},
- {NULL, 0, NULL}
+ {0, 0, 0}
};
TEST(RRTypeConstTest, wellKnowns) {
class TSIGTest : public ::testing::Test {
protected:
TSIGTest() :
- tsig_ctx(NULL), qid(0x2d65), test_name("www.example.com"),
+ tsig_ctx(0), qid(0x2d65), test_name("www.example.com"),
badkey_name("badkey.example.com"), test_class(RRClass::IN()),
test_ttl(86400), message(Message::RENDER),
dummy_data(1024, 0xdd), // should be sufficiently large for all tests
dummy_record(badkey_name, TSIG(TSIGKey::HMACMD5_NAME(), 0x4da8877a,
- TSIGContext::DEFAULT_FUDGE, 0, NULL, qid, 0, 0, NULL)) {
+ TSIGContext::DEFAULT_FUDGE, 0, 0, qid, 0, 0, 0)) {
// Make sure we use the system time by default so that we won't be
// confused due to other tests that tweak the time.
- isc::util::detail::gettimeFunction = NULL;
+ isc::util::detail::gettimeFunction = 0;
decodeBase64("SFuWd/q99SzF8Yzd1QbB9g==", secret);
tsig_ctx.reset(new TestTSIGContext(TSIGKey(test_name,
secret.size())));
}
~TSIGTest() {
- isc::util::detail::gettimeFunction = NULL;
+ isc::util::detail::gettimeFunction = 0;
}
// Many of the tests below create some DNS message and sign it under
unsigned int message_flags =
RD_FLAG,
RRType qtype = RRType::A(),
- const char* answer_data = NULL,
- const RRType* answer_type = NULL,
+ const char* answer_data = 0,
+ const RRType* answer_type = 0,
bool add_question = true,
Rcode rcode = Rcode::NOERROR());
if (add_question) {
message.addQuestion(Question(qname, test_class, qtype));
}
- if (answer_data != NULL) {
- if (answer_type == NULL) {
+ if (answer_data) {
+ if (!answer_type) {
answer_type = &qtype;
}
RRsetPtr answer_rrset(new RRset(qname, test_class, *answer_type,
if (last_should_throw) {
EXPECT_THROW(ctx.lastHadSignature(), TSIGContextError);
} else {
- EXPECT_EQ(record != NULL, ctx.lastHadSignature());
+ EXPECT_EQ(record != 0, ctx.lastHadSignature());
}
}
// Add a matching key (we don't use the secret so leave it empty), and
// construct it again. This time it should be constructed with a valid
// key.
- keyring.add(TSIGKey(test_name, TSIGKey::HMACMD5_NAME(), NULL, 0));
+ keyring.add(TSIGKey(test_name, TSIGKey::HMACMD5_NAME(), 0, 0));
TSIGContext ctx2(test_name, TSIGKey::HMACMD5_NAME(), keyring);
EXPECT_EQ(TSIGContext::INIT, ctx2.getState());
EXPECT_EQ(TSIGError::NOERROR(), ctx2.getError());
// Sign the message using the actual time, and check the accuracy of it.
// We cannot reasonably predict the expected MAC, so don't bother to
// check it.
- const uint64_t now = static_cast<uint64_t>(time(NULL));
+ const uint64_t now = static_cast<uint64_t>(time(0));
{
SCOPED_TRACE("Sign test for query at actual time");
TEST_F(TSIGTest, signBadData) {
// some specific bad data should be rejected proactively.
const unsigned char dummy_data = 0;
- EXPECT_THROW(tsig_ctx->sign(0, NULL, 10), InvalidParameter);
+ EXPECT_THROW(tsig_ctx->sign(0, 0, 10), InvalidParameter);
EXPECT_THROW(tsig_ctx->sign(0, &dummy_data, 0), InvalidParameter);
}
// Still nothing verified
EXPECT_THROW(tsig_ctx->lastHadSignature(), TSIGContextError);
- // And the data must not be NULL.
- EXPECT_THROW(tsig_ctx->verify(&dummy_record, NULL,
+ // And the data must not be null.
+ EXPECT_THROW(tsig_ctx->verify(&dummy_record, 0,
12 + dummy_record.getLength()),
InvalidParameter);
SCOPED_TRACE("Sign test using HMAC-SHA1");
commonSignChecks(createMessageAndSign(sha1_qid, test_name, &sha1_ctx),
sha1_qid, 0x4dae7d5f, expected_mac,
- sizeof(expected_mac), 0, 0, NULL,
+ sizeof(expected_mac), 0, 0, 0,
TSIGKey::HMACSHA1_NAME());
}
}
SCOPED_TRACE("Sign test using HMAC-SHA224");
commonSignChecks(createMessageAndSign(sha1_qid, test_name, &sha1_ctx),
sha1_qid, 0x4dae7d5f, expected_mac,
- sizeof(expected_mac), 0, 0, NULL,
+ sizeof(expected_mac), 0, 0, 0,
TSIGKey::HMACSHA224_NAME());
}
}
// make and sign a response in the context of TSIG error.
tsig = createMessageAndSign(test_qid, test_name, tsig_verify_ctx.get(),
- QR_FLAG, RRType::SOA(), NULL, NULL,
+ QR_FLAG, RRType::SOA(), 0, 0,
true, Rcode::NOTAUTH());
const uint8_t expected_otherdata[] = { 0, 0, 0x4d, 0xa8, 0xbe, 0x86 };
const uint8_t expected_mac[] = {
{
SCOPED_TRACE("Sign test for response with BADSIG error");
commonSignChecks(createMessageAndSign(qid, test_name, &bad_ctx),
- message.getQid(), 0x4da8877a, NULL, 0,
+ message.getQid(), 0x4da8877a, 0, 0,
16); // 16: BADSIG
}
}
ConstTSIGRecordPtr sig = createMessageAndSign(qid, test_name,
tsig_ctx.get());
EXPECT_EQ(badkey_name, sig->getName());
- commonSignChecks(sig, qid, 0x4da8877a, NULL, 0, 17); // 17: BADKEY
+ commonSignChecks(sig, qid, 0x4da8877a, 0, 0, 17); // 17: BADKEY
}
}
const TSIGRecord dummy_record2(test_name, TSIG(TSIGKey::HMACSHA1_NAME(),
0x4da8877a,
TSIGContext::DEFAULT_FUDGE,
- 0, NULL, qid, 0, 0, NULL));
+ 0, 0, qid, 0, 0, 0));
{
SCOPED_TRACE("Verify a response resulting in BADKEY due to bad alg");
commonVerifyChecks(*tsig_ctx, &dummy_record2, &dummy_data[0],
{
SCOPED_TRACE("Verify a response without TSIG that should exist");
- commonVerifyChecks(*tsig_ctx, NULL, &dummy_data[0],
+ commonVerifyChecks(*tsig_ctx, 0, &dummy_data[0],
dummy_data.size(), TSIGError::FORMERR(),
TSIGContext::SENT_REQUEST, true);
}
// internals here a little bit to generate correct test data
tsig_ctx->update(renderer.getData(), renderer.getLength());
- commonVerifyChecks(*tsig_verify_ctx, NULL,
+ commonVerifyChecks(*tsig_verify_ctx, 0,
renderer.getData(), renderer.getLength(),
TSIGError(Rcode::NOERROR()),
TSIGContext::VERIFIED_RESPONSE);
// 99 unsigned messages is OK. But the 100th must be signed, according
// to the RFC2845, section 4.4
- commonVerifyChecks(*tsig_verify_ctx, NULL,
+ commonVerifyChecks(*tsig_verify_ctx, 0,
renderer.getData(), renderer.getLength(),
i == 99 ? TSIGError::FORMERR() :
TSIGError(Rcode::NOERROR()),
// Also check conversion to cryptolink definitions
EXPECT_EQ(isc::cryptolink::MD5, TSIGKey(key_name, TSIGKey::HMACMD5_NAME(),
- NULL, 0).getAlgorithm());
+ 0, 0).getAlgorithm());
EXPECT_EQ(isc::cryptolink::MD5,
TSIGKey(key_name, TSIGKey::HMACMD5_SHORT_NAME(),
- NULL, 0).getAlgorithm());
+ 0, 0).getAlgorithm());
EXPECT_EQ(isc::cryptolink::SHA1, TSIGKey(key_name, TSIGKey::HMACSHA1_NAME(),
- NULL, 0).getAlgorithm());
+ 0, 0).getAlgorithm());
EXPECT_EQ(isc::cryptolink::SHA256, TSIGKey(key_name,
TSIGKey::HMACSHA256_NAME(),
- NULL, 0).getAlgorithm());
+ 0, 0).getAlgorithm());
EXPECT_EQ(isc::cryptolink::SHA224, TSIGKey(key_name,
TSIGKey::HMACSHA224_NAME(),
- NULL, 0).getAlgorithm());
+ 0, 0).getAlgorithm());
EXPECT_EQ(isc::cryptolink::SHA384, TSIGKey(key_name,
TSIGKey::HMACSHA384_NAME(),
- NULL, 0).getAlgorithm());
+ 0, 0).getAlgorithm());
EXPECT_EQ(isc::cryptolink::SHA512, TSIGKey(key_name,
TSIGKey::HMACSHA512_NAME(),
- NULL, 0).getAlgorithm());
+ 0, 0).getAlgorithm());
}
TEST_F(TSIGKeyTest, construct) {
EXPECT_THROW(TSIGKey(key_name, Name("unknown-alg"),
secret.c_str(), secret.size()),
isc::InvalidParameter);
- TSIGKey key2(key_name, Name("unknown-alg"), NULL, 0);
+ TSIGKey key2(key_name, Name("unknown-alg"), 0, 0);
EXPECT_EQ(key_name, key2.getKeyName());
EXPECT_EQ(Name("unknown-alg"), key2.getAlgorithmName());
// Invalid combinations of secret and secret_len:
EXPECT_THROW(TSIGKey(key_name, TSIGKey::HMACSHA1_NAME(), secret.c_str(), 0),
isc::InvalidParameter);
- EXPECT_THROW(TSIGKey(key_name, TSIGKey::HMACSHA256_NAME(), NULL, 16),
+ EXPECT_THROW(TSIGKey(key_name, TSIGKey::HMACSHA256_NAME(), 0, 16),
isc::InvalidParameter);
// Empty secret
- TSIGKey keye = TSIGKey(key_name, TSIGKey::HMACSHA256_NAME(), NULL, 0);
+ TSIGKey keye = TSIGKey(key_name, TSIGKey::HMACSHA256_NAME(), 0, 0);
EXPECT_EQ(keye.getSecretLength(), 0);
EXPECT_EQ(keye.getSecret(), (const void*)0);
}
TEST_F(TSIGKeyRingTest, find) {
// If the keyring is empty the search should fail.
EXPECT_EQ(TSIGKeyRing::NOTFOUND, keyring.find(key_name, md5_name).code);
- EXPECT_EQ(static_cast<const TSIGKey*>(NULL),
- keyring.find(key_name, md5_name).key);
+ EXPECT_FALSE(keyring.find(key_name, md5_name).key);
// Add a key and try to find it. Should succeed.
EXPECT_EQ(TSIGKeyRing::SUCCESS, keyring.add(TSIGKey(key_name, sha256_name,
const TSIGKeyRing::FindResult result2 =
keyring.find(Name("different-key.example"), sha256_name);
EXPECT_EQ(TSIGKeyRing::NOTFOUND, result2.code);
- EXPECT_EQ(static_cast<const TSIGKey*>(NULL), result2.key);
+ EXPECT_FALSE(result2.key);
const TSIGKeyRing::FindResult result3 = keyring.find(key_name, md5_name);
EXPECT_EQ(TSIGKeyRing::NOTFOUND, result3.code);
- EXPECT_EQ(static_cast<const TSIGKey*>(NULL), result3.key);
+ EXPECT_FALSE(result3.key);
// But with just the name it should work
const TSIGKeyRing::FindResult result4(keyring.find(key_name));
EXPECT_EQ(TSIGKeyRing::NOTFOUND,
keyring.find(Name("noexist.example"), sha1_name).code);
- EXPECT_EQ(static_cast<const TSIGKey*>(NULL),
- keyring.find(Name("noexist.example"), sha256_name).key);
+ EXPECT_FALSE(keyring.find(Name("noexist.example"), sha256_name).key);
EXPECT_EQ(TSIGKeyRing::NOTFOUND,
keyring.find(Name("another.example"), sha1_name).code);
- EXPECT_EQ(static_cast<const TSIGKey*>(NULL),
- keyring.find(Name("another.example"), sha256_name).key);
+ EXPECT_FALSE(keyring.find(Name("another.example"), sha256_name).key);
}
TEST(TSIGStringTest, TSIGKeyFromToString) {
TSIGKey k2 = TSIGKey("test.example.:MSG6Ng==:hmac-md5.sig-alg.reg.int.");
TSIGKey k3 = TSIGKey("test.example:MSG6Ng==");
TSIGKey k4 = TSIGKey("test.example.:MSG6Ng==:hmac-md5.sig-alg.reg.int.:120");
- TSIGKey k5 = TSIGKey(Name("test.example."), Name("hmac-sha1."), NULL, 0);
+ TSIGKey k5 = TSIGKey(Name("test.example."), Name("hmac-sha1."), 0, 0);
// "Unknown" key with empty secret is okay
TSIGKey k6 = TSIGKey("test.example.::unknown");
TSIGRecordTest() :
test_name("www.example.com"), test_mac(16, 0xda),
test_rdata(TSIG(TSIGKey::HMACMD5_NAME(), 0x4da8877a, TSIGContext::DEFAULT_FUDGE,
- test_mac.size(), &test_mac[0], 0x2d65, 0, 0, NULL)),
+ test_mac.size(), &test_mac[0], 0x2d65, 0, 0, 0)),
test_record(test_name, test_rdata),
buffer(0) {
}
} else if (state_ == SENT_REQUEST && error == TSIGError::NOERROR()) {
state_ = VERIFIED_RESPONSE;
}
- if (digest != NULL) {
+ if (digest) {
previous_digest_.assign(static_cast<const uint8_t*>(digest),
static_cast<const uint8_t*>(digest) +
digest_len);
}
TSIGContext::TSIGContext(const Name& key_name, const Name& algorithm_name,
- const TSIGKeyRing& keyring) : impl_(NULL) {
+ const TSIGKeyRing& keyring) : impl_(0) {
const TSIGKeyRing::FindResult result(keyring.find(key_name,
algorithm_name));
if (result.code == TSIGKeyRing::NOTFOUND) {
// parameters and empty secret. In the common scenario this will
// be used in subsequent response with a TSIG indicating a BADKEY
// error.
- impl_.reset(new TSIGContextImpl(TSIGKey(key_name, algorithm_name,
- NULL, 0), TSIGError::BAD_KEY()));
+ impl_.reset(new TSIGContextImpl(TSIGKey(key_name, algorithm_name, 0, 0),
+ TSIGError::BAD_KEY()));
} else {
impl_.reset(new TSIGContextImpl(*result.key));
}
"TSIG sign attempt after verifying a response");
}
- if (data == NULL || data_len == 0) {
+ if (!data || data_len == 0) {
isc_throw(InvalidParameter, "TSIG sign error: empty data is given");
}
ConstTSIGRecordPtr tsig(new TSIGRecord(
impl_->key_.getKeyName(),
any::TSIG(impl_->key_.getAlgorithmName(),
- now, DEFAULT_FUDGE, 0, NULL,
- qid, error.getCode(), 0, NULL)));
+ now, DEFAULT_FUDGE, 0, 0,
+ qid, error.getCode(), 0, 0)));
impl_->previous_digest_.clear();
impl_->state_ = SENT_RESPONSE;
return (tsig);
otherdatabuf.writeUint32(now & 0xffffffff);
}
const void* const otherdata =
- (otherlen == 0) ? NULL : otherdatabuf.getData();
+ (otherlen == 0) ? 0 : otherdatabuf.getData();
// Then calculate the digest. If state_ is SENT_RESPONSE we are sending
// a continued message in the same TCP stream so skip digesting
// variables except for time related variables (RFC2845 4.4).
"TSIG verify attempt after sending a response");
}
- if (record == NULL) {
+ if (!record) {
if (impl_->last_sig_dist_ >= 0 && impl_->last_sig_dist_ < 99) {
// It is not signed, but in the middle of TCP stream. We just
// update the HMAC state and consider this message OK.
// now.
impl_->last_sig_dist_++;
// No digest to return now. Just say it's OK.
- return (impl_->postVerifyUpdate(TSIGError::NOERROR(), NULL, 0));
+ return (impl_->postVerifyUpdate(TSIGError::NOERROR(), 0, 0));
}
// This case happens when we sent a signed request and have received an
// unsigned response. According to RFC2845 Section 4.6 this case should be
// considered a "format error" (although the specific error code
// wouldn't matter much for the caller).
- return (impl_->postVerifyUpdate(TSIGError::FORMERR(), NULL, 0));
+ return (impl_->postVerifyUpdate(TSIGError::FORMERR(), 0, 0));
}
const any::TSIG& tsig_rdata = record->getRdata();
isc_throw(InvalidParameter,
"TSIG verify: data length is invalid: " << data_len);
}
- if (data == NULL) {
+ if (!data) {
isc_throw(InvalidParameter, "TSIG verify: empty data is invalid");
}
// it using the consistent key in the context. If the check fails we are
// done with BADKEY.
if (impl_->state_ == INIT && impl_->error_ == TSIGError::BAD_KEY()) {
- return (impl_->postVerifyUpdate(TSIGError::BAD_KEY(), NULL, 0));
+ return (impl_->postVerifyUpdate(TSIGError::BAD_KEY(), 0, 0));
}
if (impl_->key_.getKeyName() != record->getName() ||
impl_->key_.getAlgorithmName() != tsig_rdata.getAlgorithm()) {
- return (impl_->postVerifyUpdate(TSIGError::BAD_KEY(), NULL, 0));
+ return (impl_->postVerifyUpdate(TSIGError::BAD_KEY(), 0, 0));
}
// Check time: the current time must be in the range of
const uint64_t now = getTSIGTime();
if (tsig_rdata.getTimeSigned() + DEFAULT_FUDGE < now ||
tsig_rdata.getTimeSigned() - DEFAULT_FUDGE > now) {
- const void* digest = NULL;
+ const void* digest = 0;
size_t digest_len = 0;
if (impl_->state_ == INIT) {
digest = tsig_rdata.getMAC();
if (error != TSIGError::BAD_SIG() && error != TSIGError::BAD_KEY()) {
error = TSIGError::BAD_SIG();
}
- return (impl_->postVerifyUpdate(error, NULL, 0));
+ return (impl_->postVerifyUpdate(error, 0, 0));
}
HMACPtr hmac(impl_->createHMAC());
// Signature length check based on RFC 4635 3.1
if (tsig_rdata.getMACSize() > hmac->getOutputLength()) {
// signature length too big
- return (impl_->postVerifyUpdate(TSIGError::FORMERR(), NULL, 0));
+ return (impl_->postVerifyUpdate(TSIGError::FORMERR(), 0, 0));
}
if ((tsig_rdata.getMACSize() < 10) ||
(tsig_rdata.getMACSize() < (hmac->getOutputLength() / 2))) {
// signature length below minimum
- return (impl_->postVerifyUpdate(TSIGError::FORMERR(), NULL, 0));
+ return (impl_->postVerifyUpdate(TSIGError::FORMERR(), 0, 0));
}
if (tsig_rdata.getMACSize() < impl_->digest_len_) {
// (truncated) signature length too small
- return (impl_->postVerifyUpdate(TSIGError::BAD_TRUNC(), NULL, 0));
+ return (impl_->postVerifyUpdate(TSIGError::BAD_TRUNC(), 0, 0));
}
//
tsig_rdata.getMACSize()));
}
- return (impl_->postVerifyUpdate(TSIGError::BAD_SIG(), NULL, 0));
+ return (impl_->postVerifyUpdate(TSIGError::BAD_SIG(), 0, 0));
}
bool
TSIGKey::TSIGKey(const Name& key_name, const Name& algorithm_name,
const void* secret, size_t secret_len,
- size_t digestbits /*= 0*/) : impl_(NULL) {
+ size_t digestbits /*= 0*/) : impl_(0) {
const HashAlgorithm algorithm = convertAlgorithmName(algorithm_name);
- if ((secret != NULL && secret_len == 0) ||
- (secret == NULL && secret_len != 0)) {
+ if ((secret && secret_len == 0) ||
+ (!secret && secret_len != 0)) {
isc_throw(InvalidParameter,
"TSIGKey secret and its length are inconsistent: " <<
key_name << ":" << algorithm_name);
"TSIGKey with unknown algorithm has non empty secret: " <<
key_name << ":" << algorithm_name);
}
- if (secret == NULL) {
+ if (!secret) {
impl_.reset(new TSIGKey::TSIGKeyImpl(key_name, algorithm_name, algorithm,
digestbits));
} else {
}
}
-TSIGKey::TSIGKey(const std::string& str) : impl_(NULL) {
+TSIGKey::TSIGKey(const std::string& str) : impl_(0) {
try {
istringstream iss(str);
const void*
TSIGKey::getSecret() const {
- return ((impl_->secret_.size() > 0) ? &impl_->secret_[0] : NULL);
+ return ((impl_->secret_.size() > 0) ? &impl_->secret_[0] : 0);
}
size_t
TSIGKeyRingImpl::TSIGKeyMap::const_iterator found =
impl_->keys.find(key_name);
if (found == impl_->keys.end()) {
- return (FindResult(NOTFOUND, NULL));
+ return (FindResult(NOTFOUND, 0));
}
return (FindResult(SUCCESS, &((*found).second)));
}
impl_->keys.find(key_name);
if (found == impl_->keys.end() ||
(*found).second.getAlgorithmName() != algorithm_name) {
- return (FindResult(NOTFOUND, NULL));
+ return (FindResult(NOTFOUND, 0));
}
return (FindResult(SUCCESS, &((*found).second)));
}
/// <code>static const</code> member functions.
///
/// Other names are still accepted as long as the secret is empty
- /// (\c secret is \c NULL and \c secret_len is 0), however; in some cases
+ /// (\c secret is null and \c secret_len is 0), however; in some cases
/// we might want to treat just the pair of key name and algorithm name
/// opaquely, e.g., when generating a response TSIG with a BADKEY error
/// because the algorithm is unknown as specified in Section 3.2 of
/// specified, an exception of type \c InvalidParameter will be thrown.
///
/// \c secret and \c secret_len must be consistent in that the latter
- /// is 0 if and only if the former is \c NULL;
+ /// is 0 if and only if the former is null;
/// otherwise an exception of type \c InvalidParameter will be thrown.
///
/// \c digestbits is the truncated length in bits or 0 which means no
/// form of domain name. For example, it can be
/// \c TSIGKey::HMACSHA256_NAME() for HMAC-SHA256.
/// \param secret Point to a binary sequence of the shared secret to be
- /// used for this key, or \c NULL if the secret is empty.
+ /// used for this key, or null if the secret is empty.
/// \param secret_len The size of the binary %data (\c secret) in bytes.
/// \param digestbits The number of bits to include in the digest
/// (0 means to include all)
/// Return the value of the TSIG secret.
///
- /// If it returns a non NULL pointer, the memory region beginning at the
+ /// If it returns a non null pointer, the memory region beginning at the
/// address returned by this method is valid up to the bytes specified
/// by the return value of \c getSecretLength().
///
/// to the found key to represent the result of \c find().
/// We use this in order to avoid overloading the return value for both
/// the result code ("success" or "not found") and the found object,
- /// i.e., avoid using \c NULL to mean "not found", etc.
+ /// i.e., avoid using null to mean "not found", etc.
///
/// This is a simple value class with no internal state, so for
/// convenience we allow the applications to refer to the members
/// object as follows:
/// - \c code: \c SUCCESS if a key is found; otherwise \c NOTFOUND.
/// - \c key: A pointer to the found \c TSIGKey object if one is found;
- /// otherwise \c NULL.
+ /// otherwise null.
///
/// The pointer returned in the \c FindResult object is only valid until
/// the corresponding key is removed from the key ring.
/// object as follows:
/// - \c code: \c SUCCESS if a key is found; otherwise \c NOTFOUND.
/// - \c key: A pointer to the found \c TSIGKey object if one is found;
- /// otherwise \c NULL.
+ /// otherwise null.
///
/// The pointer returned in the \c FindResult object is only valid until
/// the corresponding key is removed from the key ring.