};
-DNSName::string_t segmentDNSNameRaw(const char* realinput)
+DNSName::string_t segmentDNSNameRaw(const char* realinput, size_t inputlen)
{
%%{
machine dnsnameraw;
return ret;
}
- unsigned int inputlen=strlen(realinput);
ret.reserve(inputlen+1);
const char *p = realinput, *pe = realinput + inputlen;
return os <<d.toLogString();
}
-DNSName::DNSName(const char* p)
+DNSName::DNSName(const char* p, size_t length)
{
if(p[0]==0 || (p[0]=='.' && p[1]==0)) {
d_storage.assign(1, (char)0);
if(!strchr(p, '\\')) {
unsigned char lenpos=0;
unsigned char labellen=0;
- size_t plen=strlen(p);
+ size_t plen=length;
const char* const pbegin=p, *pend=p+plen;
d_storage.reserve(plen+1);
for(auto iter = pbegin; iter != pend; ) {
d_storage.append(1, (char)0);
}
else {
- d_storage=segmentDNSNameRaw(p);
+ d_storage=segmentDNSNameRaw(p, length);
if(d_storage.size() > 255) {
throw std::range_error("name too long");
}
{
public:
DNSName() {} //!< Constructs an *empty* DNSName, NOT the root!
- explicit DNSName(const char* p); //!< Constructs from a human formatted, escaped presentation
- explicit DNSName(const std::string& str) : DNSName(str.c_str()) {}; //!< Constructs from a human formatted, escaped presentation
+ explicit DNSName(const char* p): DNSName(p, strlen(p)) {} //!< Constructs from a human formatted, escaped presentation
+ explicit DNSName(const char* p, size_t len); //!< Constructs from a human formatted, escaped presentation
+ explicit DNSName(const std::string& str) : DNSName(str.c_str(), str.length()) {}; //!< Constructs from a human formatted, escaped presentation
DNSName(const char* p, int len, int offset, bool uncompress, uint16_t* qtype=nullptr, uint16_t* qclass=nullptr, unsigned int* consumed=nullptr, uint16_t minOffset=0); //!< Construct from a DNS Packet, taking the first question if offset=12. If supplied, consumed is set to the number of bytes consumed from the packet, which will not be equal to the wire length of the resulting name in case of compression.
bool isPartOf(const DNSName& rhs) const; //!< Are we part of the rhs name?
};
}
-DNSName::string_t segmentDNSNameRaw(const char* input); // from ragel
+DNSName::string_t segmentDNSNameRaw(const char* input, size_t inputlen); // from ragel
bool DNSName::operator==(const DNSName& rhs) const
{
if(rhs.empty() != empty() || rhs.d_storage.size() != d_storage.size())
typedef vector<pair<string::size_type, string::size_type> > labelparts_t;
// bool labeltokUnescape(labelparts_t& parts, const DNSName& label);
std::vector<string> segmentDNSText(const string& text); // from dnslabeltext.rl
-std::deque<string> segmentDNSName(const string& input ); // from dnslabeltext.rl
#endif