2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-06 08:55:13 +00:00
Files
kea/src/lib/dns/labelsequence.cc

78 lines
2.6 KiB
C++
Raw Normal View History

// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
2012-02-20 23:29:31 +01:00
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <dns/labelsequence.h>
#include <exceptions/exceptions.h>
2012-02-28 12:30:04 +01:00
#include <iostream>
2012-02-20 23:29:31 +01:00
namespace isc {
namespace dns {
const char*
LabelSequence::getData(size_t *len) const {
// If the labelsequence is absolute, the current last_label_ falls
// out of the vector (since it points to the 'label' after the
// root label, which doesn't exist; in that case, return
// the length for the 'previous' label (the root label) plus
// one (for the root label zero octet)
if (isAbsolute()) {
*len = name_.offsets_[last_label_ - 1] - name_.offsets_[first_label_] + 1;
} else {
*len = name_.offsets_[last_label_] - name_.offsets_[first_label_];
}
return (&name_.ndata_[name_.offsets_[first_label_]]);
2012-02-20 23:29:31 +01:00
}
bool
LabelSequence::equals(const LabelSequence& other, bool case_sensitive) const {
2012-02-21 12:37:07 +01:00
size_t len, other_len;
const char* data = getData(&len);
const char* other_data = other.getData(&other_len);
if (len != other_len) {
return (false);
}
2012-02-20 23:29:31 +01:00
if (case_sensitive) {
2012-02-21 12:37:07 +01:00
return (strncasecmp(data, other_data, len) == 0);
2012-02-20 23:29:31 +01:00
} else {
2012-02-21 12:37:07 +01:00
return (strncmp(data, other_data, len) == 0);
2012-02-20 23:29:31 +01:00
}
}
void
LabelSequence::leftSplit(size_t i) {
if (i >= getLabelCount()) {
isc_throw(OutOfRange, "Cannot split to zero or less labels; " << i <<
" (labelcount: " << getLabelCount() << ")");
2012-02-28 12:30:04 +01:00
}
first_label_ += i;
}
void
LabelSequence::rightSplit(size_t i) {
if (i >= getLabelCount()) {
isc_throw(OutOfRange, "Cannot split to zero or less labels; " << i <<
" (labelcount: " << getLabelCount() << ")");
2012-02-20 23:29:31 +01:00
}
last_label_ -= i;
2012-02-20 23:29:31 +01:00
}
bool
LabelSequence::isAbsolute() const {
return (last_label_ == name_.offsets_.size());
}
2012-02-20 23:29:31 +01:00
} // end namespace dns
} // end namespace isc