DNSName::DNSName(const char* pos, int len, int offset, bool uncompress, uint16_t* qtype, uint16_t* qclass, unsigned int* consumed)
{
+ if(!uncompress) {
+ if(const void * fnd=memchr(pos+offset, 0, len-offset)) {
+ d_storage.reserve(2+(const char*)fnd-(pos+offset));
+ }
+ }
+
packetParser(pos, len, offset, uncompress, qtype, qclass, consumed);
}
break;
}
if (pos + labellen < end) {
- appendRawLabel(string((const char*)pos, labellen));
+ appendRawLabel((const char*)pos, labellen);
}
else
throw std::range_error("Found an invalid label length in qname");
void DNSName::appendRawLabel(const std::string& label)
{
- if(label.empty())
+ appendRawLabel(label.c_str(), label.length());
+}
+
+void DNSName::appendRawLabel(const char* start, unsigned int length)
+{
+ if(length==0)
throw std::range_error("no such thing as an empty label to append");
- if(label.size() > 63)
+ if(length > 63)
throw std::range_error("label too long to append");
- if(d_storage.size() + label.size() > 254) // reserve two bytes, one for length and one for the root label
+ if(d_storage.size() + length > 254) // reserve two bytes, one for length and one for the root label
throw std::range_error("name too long to append");
if(d_storage.empty()) {
- d_storage.append(1, (char)label.size());
+ d_storage.append(1, (char)length);
}
else {
- *d_storage.rbegin()=(char)label.size();
+ *d_storage.rbegin()=(char)length;
}
- d_storage.append(label.c_str(), label.length());
+ d_storage.append(start, length);
d_storage.append(1, (char)0);
}
std::string toStringNoDot() const { return toString(".", false); }
std::string toDNSString() const; //!< Our representation in DNS native format
void appendRawLabel(const std::string& str); //!< Append this unescaped label
+ void appendRawLabel(const char* start, unsigned int length); //!< Append this unescaped label
void prependRawLabel(const std::string& str); //!< Prepend this unescaped label
std::vector<std::string> getRawLabels() const; //!< Individual raw unescaped labels
bool chopOff(); //!< Turn www.powerdns.com. into powerdns.com., returns false for .