From: Pieter Lexis Date: Tue, 5 Jan 2016 16:14:53 +0000 (+0100) Subject: Add xfrUnquotedText() X-Git-Tag: dnsdist-1.0.0-beta1~98^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=948a927f30e687462457c0e870ed081969c1e855;p=pdns Add xfrUnquotedText() --- diff --git a/pdns/dnsparser.cc b/pdns/dnsparser.cc index 405933c83..4e28afdad 100644 --- a/pdns/dnsparser.cc +++ b/pdns/dnsparser.cc @@ -467,6 +467,22 @@ string PacketReader::getText(bool multi, bool lenField) return ret; } +string PacketReader::getUnquotedText(bool lenField) +{ + int16_t stop_at; + if(lenField) + stop_at = (uint8_t)d_content.at(d_pos) + d_pos + 1; + else + stop_at = d_recordlen; + + if(stop_at == d_pos) + return ""; + + d_pos++; + string ret(&d_content.at(d_pos), &d_content.at(stop_at)); + d_pos = stop_at; + return ret; +} void PacketReader::xfrBlob(string& blob) try diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index 96f0906c0..baf3a82a7 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -129,6 +129,10 @@ public: text=getText(multi, lenField); } + void xfrUnquotedText(string &text, bool lenField){ + text=getUnquotedText(lenField); + } + void xfrBlob(string& blob); void xfrBlobNoSpaces(string& blob, int len); void xfrBlob(string& blob, int length); @@ -142,6 +146,7 @@ public: DNSName getName(); string getText(bool multi, bool lenField); + string getUnquotedText(bool lenField); uint16_t d_pos; diff --git a/pdns/dnswriter.cc b/pdns/dnswriter.cc index 06dc3b980..a50ee77f2 100644 --- a/pdns/dnswriter.cc +++ b/pdns/dnswriter.cc @@ -172,6 +172,17 @@ void DNSPacketWriter::xfrText(const string& text, bool, bool lenField) } } +void DNSPacketWriter::xfrUnquotedText(const string& text, bool lenField) +{ + if(text.empty()) { + d_record.push_back(0); + return; + } + if(lenField) + d_record.push_back(text.length()); + d_record.insert(d_record.end(), text.c_str(), text.c_str() + text.length()); +} + /* FIXME400: check that this beats a map */ DNSPacketWriter::lmap_t::iterator find(DNSPacketWriter::lmap_t& nmap, const DNSName& name) { diff --git a/pdns/dnswriter.hh b/pdns/dnswriter.hh index 2936890e4..b4fd614e4 100644 --- a/pdns/dnswriter.hh +++ b/pdns/dnswriter.hh @@ -88,6 +88,7 @@ public: void xfrName(const DNSName& label, bool compress=false, bool noDot=false); void xfrText(const string& text, bool multi=false, bool lenField=true); + void xfrUnquotedText(const string& text, bool lenField); void xfrBlob(const string& blob, int len=-1); void xfrBlobNoSpaces(const string& blob, int len=-1); void xfrHexBlob(const string& blob, bool keepReading=false); diff --git a/pdns/rcpgenerator.cc b/pdns/rcpgenerator.cc index 495d88972..28edc95f4 100644 --- a/pdns/rcpgenerator.cc +++ b/pdns/rcpgenerator.cc @@ -372,6 +372,21 @@ void RecordTextReader::xfrText(string& val, bool multi, bool lenField) } } +void RecordTextReader::xfrUnquotedText(string& val, bool lenField) +{ + val.clear(); + val.reserve(d_end - d_pos); + + if(!val.empty()) + val.append(1, ' '); + + skipSpaces(); + val.append(1, d_string[d_pos]); + while(++d_pos < d_end && d_string[d_pos] != ' '){ + val.append(1, d_string[d_pos]); + } +} + void RecordTextReader::xfrType(uint16_t& val) { skipSpaces(); @@ -555,6 +570,12 @@ void RecordTextWriter::xfrText(const string& val, bool multi, bool lenField) d_string.append(val); } +void RecordTextWriter::xfrUnquotedText(const string& val, bool lenField) +{ + if(!d_string.empty()) + d_string.append(1,' '); + d_string.append(val); +} #ifdef TESTING diff --git a/pdns/rcpgenerator.hh b/pdns/rcpgenerator.hh index 5b33a01b4..4b78438f4 100644 --- a/pdns/rcpgenerator.hh +++ b/pdns/rcpgenerator.hh @@ -54,6 +54,7 @@ public: void xfrName(DNSName& val, bool compress=false, bool noDot=false); void xfrText(string& val, bool multi=false, bool lenField=true); + void xfrUnquotedText(string& val, bool lenField=true); void xfrHexBlob(string& val, bool keepReading=false); void xfrBase32HexBlob(string& val); @@ -85,6 +86,7 @@ public: void xfrType(const uint16_t& val); void xfrName(const DNSName& val, bool compress=false, bool noDot=false); void xfrText(const string& val, bool multi=false, bool lenField=true); + void xfrUnquotedText(const string& val, bool lenField=true); void xfrBlobNoSpaces(const string& val, int len=-1); void xfrBlob(const string& val, int len=-1); void xfrHexBlob(const string& val, bool keepReading=false);