Commit 39e41072 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[2148] cleanup and documentation

parent 3a5fcdca
......@@ -345,7 +345,7 @@ LabelSequence::extend(const LabelSequence& labels,
bool absolute = isAbsolute();
size_t label_count = last_label_ + 1;
// Since we may have been stripped, do not use getDataLength(), but
// calculate actual data size we use
// calculate actual data size this labelsequence currently uses
size_t data_pos = offsets_[last_label_] + data_[offsets_[last_label_]] + 1;
// If this labelsequence is absolute, virtually strip the root label.
......@@ -378,7 +378,7 @@ LabelSequence::extend(const LabelSequence& labels,
// case we'd be copying overlapping data (overwriting the current last
// label if this LabelSequence is absolute). Therefore we do this
// manually, and more importantly, backwards.
// (note2 obviously this destroys data_len, don't use below,
// (note2: obviously this destroys data_len, don't use below,
// or reset it)
while (--data_len) {
buf[data_pos + data_len] = data[data_len];
......@@ -387,9 +387,9 @@ LabelSequence::extend(const LabelSequence& labels,
for (size_t i = 0; i < append_label_count; ++i) {
buf[Name::MAX_WIRE + label_count + i] =
offsets_[label_count] +
labels.offsets_[i + labels.first_label_] -
labels.offsets_[labels.first_label_];
offsets_[label_count] +
labels.offsets_[i + labels.first_label_] -
labels.offsets_[labels.first_label_];
}
last_label_ = label_count + append_label_count - 1;
}
......@@ -400,30 +400,5 @@ operator<<(std::ostream& os, const LabelSequence& label_sequence) {
return (os);
}
void
LabelSequence::dump() const {
std::cout << "[XX] serialized data: ";
for (size_t i = 0; i < getDataLength(); ++i) {
std::cout << (int)data_[i] << " ";
}
std::cout << std::endl;
std::cout << "[XX] offsets: ";
size_t cur_offset = 0;
uint8_t cur_ll = data_[offsets_[cur_offset]];
while(cur_ll != 0) {
std::cout << (int)offsets_[cur_offset] << " ";
cur_offset++;
cur_ll = data_[offsets_[cur_offset]];
}
std::cout << std::endl;
std::cout << "[XX] first label: " << first_label_ << std::endl;
std::cout << "[XX] last label: " << last_label_ << std::endl;
if (isAbsolute()) {
std::cout << "[XX] absolute" << std::endl;
} else {
std::cout << "[XX] not absolute" << std::endl;
}
}
} // end namespace dns
} // end namespace isc
......@@ -268,12 +268,20 @@ public:
/// \brief Extend this LabelSequence with the given labelsequence
///
/// The given labels are added to the name data, and internal data
/// is updated accordingly.
/// The given labels are added to the name data, and internal offset
/// data is updated accordingly.
///
/// The data from the given LabelSequence is copied into the buffer
/// associated with this LabelSequence; the appended LabelSequence
/// can be released if it is not needed for other operations anymore.
///
/// If this LabelSequence is absolute, its root label will be stripped
/// before the given LabelSequence is appended; after extend(),
/// this LabelSequence will be absolute if, and only if, the appended
/// LabelSequence was. A side-effect of this property is that adding
/// the root label to an absolute LabelSequence has no effect (the
/// root label is stripped, then added again).
///
/// Some minimal checking is done on the data, but internal integrity
/// is not assumed. Do NOT modify the given buffer except through calls
/// to this method, and do NOT call this method if the buffer is
......
......@@ -1053,17 +1053,15 @@ TEST(LabelSequence, extendBadData) {
els.extend(LabelSequence(Name("123456789")), buf);
// But now, even the shortest extension should fail
EXPECT_THROW(els.extend(LabelSequence(Name("1")), buf), isc::BadValue);
/*
// Also check that extending past MAX_LABELS is not possible
Name shortname("1.");
LabelSequence short_ls(shortname);
els = LabelSequence(short_ls, buf);
for (size_t i=0; i < 125; ++i) {
for (size_t i=0; i < 126; ++i) {
els.extend(short_ls, buf);
}
EXPECT_THROW(els.extend(short_ls, buf), isc::BadValue);
*/
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment