BIND 10 trac1602, updated. 3f6b00419fb5d447a4e2e84be58397632a716abe [1602] use vector for offsets
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Feb 28 11:30:17 UTC 2012
The branch, trac1602 has been updated
via 3f6b00419fb5d447a4e2e84be58397632a716abe (commit)
via afa40133222b39078a914b0bf5780be013b8b992 (commit)
from 7ac5487d208f8b4cb9c3e2955bd7d1f03b2ad942 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 3f6b00419fb5d447a4e2e84be58397632a716abe
Author: Jelte Jansen <jelte at isc.org>
Date: Tue Feb 28 12:30:04 2012 +0100
[1602] use vector for offsets
commit afa40133222b39078a914b0bf5780be013b8b992
Author: Jelte Jansen <jelte at isc.org>
Date: Tue Feb 28 11:43:08 2012 +0100
[1602] update doxygen
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/labelsequence.cc | 59 ++++++---------------------
src/lib/dns/labelsequence.h | 89 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 100 insertions(+), 48 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/labelsequence.cc b/src/lib/dns/labelsequence.cc
index b43d8e4..10ee45e 100644
--- a/src/lib/dns/labelsequence.cc
+++ b/src/lib/dns/labelsequence.cc
@@ -15,49 +15,22 @@
#include <dns/labelsequence.h>
#include <exceptions/exceptions.h>
-/// Light-weight Accessor to Name object
-///
-/// The purpose of this class is to easily match Names and parts of Names,
-/// without needing to copy the underlying data on each split.
-///
-/// It can only work on existing Name objects, and the Name object MUST
-/// remain in scope during the entire lifetime of its associated
-/// LabelSequence(s)
-///
-/// Upon creation of a LabelSequence, it records the offsets of the
-/// labels in the wireformat data of the Name. When split() is called on
-/// the LabelSequence, no changes in the Name's data occur, but the
-/// internal pointers of the LabelSequence are modified.
-///
-/// LabelSequences can be compared to other LabelSequences, and their
-/// data can be requested (which then points to part of the original
-/// data of the associated Name object).
-///
-
+#include <iostream>
namespace isc {
namespace dns {
-/// \brief Constructs a LabelSequence for the given name
-///
-/// The associated Name MUST remain in scope during the lifetime of
-/// this LabelSequence, since getData() refers to data from the
-/// Name object (the only data the LabelSequence stores are pointers
-/// to the labels in the Name object).
LabelSequence::LabelSequence(const Name& name) : name_(name),
- first_label_(0) {
- size_t label_count_ = name.getLabelCount();
- last_label_ = label_count_ - 1;
- offsets_ = new size_t[label_count_];
+ first_label_(0), offsets_(name.getLabelCount()) {
offsets_[0] = 0;
- for (size_t i = 1; i < label_count_; ++i) {
+ last_label_ = name.getLabelCount() - 1;
+ // Walk through the wire format data and store all offsets
+ for (size_t i = 1; i < offsets_.size(); ++i) {
+ // Each offset is the previous offset plus the length of the
+ // label plus 1 (for the label length octet)
offsets_[i] = offsets_[i - 1] + name.at(offsets_[i - 1]) + 1;
}
}
-LabelSequence::~LabelSequence() {
- delete[] offsets_;
-}
-
const char*
LabelSequence::getData(size_t *len) const {
*len = offsets_[last_label_] - offsets_[first_label_];
@@ -82,20 +55,14 @@ LabelSequence::equals(const LabelSequence& other, bool case_sensitive) const {
void
LabelSequence::split(int i) {
+ if (abs(i) > getLabelCount()) {
+ isc_throw(OutOfRange, "Label " << i << " out of range (" <<
+ getLabelCount() << ")");
+ }
if (i > 0) {
- if (i > getLabelCount()) {
- isc_throw(OutOfRange, "Label " << i << " out of range (" <<
- getLabelCount() << ")");
- } else {
- first_label_ += i;
- }
+ first_label_ += i;
} else if (i < 0) {
- if (-i > getLabelCount()) {
- isc_throw(OutOfRange, "Label " << i << " out of range (" <<
- getLabelCount() << ")");
- } else {
- last_label_ += i;
- }
+ last_label_ += i;
}
}
diff --git a/src/lib/dns/labelsequence.h b/src/lib/dns/labelsequence.h
index 686442f..557dc17 100644
--- a/src/lib/dns/labelsequence.h
+++ b/src/lib/dns/labelsequence.h
@@ -21,26 +21,111 @@
namespace isc {
namespace dns {
+/// \brief Light-weight Accessor to Name object
+///
+/// The purpose of this class is to easily match Names and parts of Names,
+/// without needing to copy the underlying data on each split.
+///
+/// It can only work on existing Name objects, and the Name object MUST
+/// remain in scope during the entire lifetime of its associated
+/// LabelSequence(s).
+///
+/// Upon creation of a LabelSequence, it records the offsets of the
+/// labels in the wireformat data of the Name. When split() is called on
+/// the LabelSequence, no changes in the Name's data occur, but the
+/// internal pointers of the LabelSequence are modified.
+///
+/// \note For consistency reasons, when talking about labels and label
+/// counts, LabelSequence objects never include the root label in their
+/// calculations or return values. Wireformat data resulting from
+/// getData() is never absolute, and the result of a labelCount(),
+/// even if split() has never been called on the LabelSequence, is
+/// always smaller than the labelCount of the original Name object.
+///
+/// LabelSequences can be compared to other LabelSequences, and their
+/// data can be requested (which then points to part of the original
+/// data of the associated Name object).
+///
class LabelSequence {
public:
+ /// \brief Constructs a LabelSequence for the given name
+ ///
+ /// \note The associated Name MUST remain in scope during the lifetime
+ /// of this LabelSequence, since getData() refers to data from the
+ /// Name object (the only data the LabelSequence stores are pointers
+ /// to the labels in the Name object).
+ ///
+ /// \param name The Name to construct a LabelSequence for
LabelSequence(const Name& name);
- ~LabelSequence();
+ /// \brief Return the wire-format data for this LabelSequence
+ ///
+ /// The data, is returned as a pointer to the original wireformat
+ /// data of the original Name object, and the given len value is
+ /// set to the number of octets that match this labelsequence.
+ ///
+ /// \note The data pointed to here is never absolute (i.e. it does
+ /// not include the root label), so if this data is used anywhere
+ /// you probably need to add an empty label (one octet with value
+ /// zero).
+ ///
+ /// \note The data pointed to is only valid if the original Name
+ /// object is still in scope
+ ///
+ /// \param len Pointer to a size_t where the length of the data
+ /// is stored
+ /// \return Pointer to the wire-format data of this label sequence
const char* getData(size_t* len) const;
+ /// \brief Compares two label sequences.
+ ///
+ /// Performs a (optionally case-insensitive) comparison between this
+ /// LabelSequence and another LabelSequence.
+ ///
+ /// \param other The LabelSequence to compare with
+ /// \param case_sensitive If true, comparison is case-insensitive
+ /// \return true if The label sequences consist are the same length,
+ /// and contain the same data.
bool equals(const LabelSequence& other, bool case_sensitive = false) const;
+ /// \brief Remove one or more labels from this LabelSequence
+ ///
+ /// Removes labels from either the front or the back of the LabelSequence
+ ///
+ /// \note No actual memory is changed, this operation merely updates the
+ /// internal pointers based on the offsets at creation time.
+ ///
+ /// \exeption OutOfRange if abs(i) is greater than the number of labels
+ /// currently pointed to by this LabelSequence
+ ///
+ /// \param i When positive, removes i labels from the front of the
+ /// LabelSequence. When negative, removes i labels from the
+ /// end of it.
void split(int i);
+ /// \brief Returns the current number of labels for this LabelSequence
+ ///
+ /// \note This count does NOT include the root label
+ ///
+ /// \return The number of labels
size_t getLabelCount() const { return last_label_ - first_label_; }
+ /// \brief Returns the original Name object associated with this
+ /// LabelSequence
+ ///
+ /// While the Name should still be in scope during the lifetime of
+ /// the LabelSequence, it can still be useful to have access to it,
+ /// for instance in helper functions that are only passed the
+ /// LabelSequence itself.
+ ///
+ /// \return Reference to the original Name object
const Name& getName() const { return name_; }
private:
const Name& name_;
size_t first_label_;
size_t last_label_;
- size_t* offsets_;
+ std::vector<size_t> offsets_;
};
More information about the bind10-changes
mailing list