From: Aki Tuomi Date: Tue, 27 Jan 2015 09:43:53 +0000 (+0200) Subject: Introduce xfrBlobNoSpaces X-Git-Tag: dnsdist-1.0.0-alpha1~293^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2fe9d6f74bb73e1178eccb23d5e01334c1a9979e;p=thirdparty%2Fpdns.git Introduce xfrBlobNoSpaces --- diff --git a/pdns/dnsparser.cc b/pdns/dnsparser.cc index f6ca6b6b62..e06eae3409 100644 --- a/pdns/dnsparser.cc +++ b/pdns/dnsparser.cc @@ -510,6 +510,10 @@ catch(...) throw std::out_of_range("xfrBlob out of range"); } +void PacketReader::xfrBlobNoSpaces(string& blob, int length) { + xfrBlob(blob, length); +} + void PacketReader::xfrBlob(string& blob, int length) { if(length) { diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index 20436ecbab..5fda67f2ba 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -128,6 +128,7 @@ public: } void xfrBlob(string& blob); + void xfrBlobNoSpaces(string& blob, int len); void xfrBlob(string& blob, int length); void xfrHexBlob(string& blob, bool keepReading=false); diff --git a/pdns/dnswriter.cc b/pdns/dnswriter.cc index 336e8a633b..e38055ba5d 100644 --- a/pdns/dnswriter.cc +++ b/pdns/dnswriter.cc @@ -285,6 +285,11 @@ void DNSPacketWriter::xfrBlob(const string& blob, int ) d_record.insert(d_record.end(), ptr, ptr+blob.size()); } +void DNSPacketWriter::xfrBlobNoSpaces(const string& blob, int ) +{ + xfrBlob(blob); +} + void DNSPacketWriter::xfrHexBlob(const string& blob, bool keepReading) { xfrBlob(blob); diff --git a/pdns/dnswriter.hh b/pdns/dnswriter.hh index fb39c124c8..70bc50e8e8 100644 --- a/pdns/dnswriter.hh +++ b/pdns/dnswriter.hh @@ -89,6 +89,7 @@ public: void xfrLabel(const string& label, bool compress=false); void xfrText(const string& text, bool multi=false); void xfrBlob(const string& blob, int len=-1); + void xfrBlobNoSpaces(const string& blob, int len=-1); void xfrHexBlob(const string& blob, bool keepReading=false); uint16_t d_pos; diff --git a/pdns/rcpgenerator.cc b/pdns/rcpgenerator.cc index b088b100e9..a3b4354bc7 100644 --- a/pdns/rcpgenerator.cc +++ b/pdns/rcpgenerator.cc @@ -208,10 +208,10 @@ void RecordTextReader::xfrLabel(string& val, bool) } } -static bool isbase64(char c) +static bool isbase64(char c, bool acceptspace) { if(dns_isspace(c)) - return true; + return acceptspace; if(c >= '0' && c <= '9') return true; if(c >= 'a' && c <= 'z') @@ -223,12 +223,29 @@ static bool isbase64(char c) return false; } +void RecordTextReader::xfrBlobNoSpaces(string& val, int len) { + skipSpaces(); + int pos=(int)d_pos; + const char* strptr=d_string.c_str(); + while(d_pos < d_end && isbase64(strptr[d_pos], false)) + d_pos++; + + string tmp; + tmp.assign(d_string.c_str()+pos, d_string.c_str() + d_pos); + boost::erase_all(tmp," "); + val.clear(); + B64Decode(tmp, val); + + if (len>-1 && val.size() != static_cast(len)) + throw RecordTextException("Record length "+lexical_cast(val.size()) + " does not match expected length '"+lexical_cast(len)); +} + void RecordTextReader::xfrBlob(string& val, int) { skipSpaces(); int pos=(int)d_pos; const char* strptr=d_string.c_str(); - while(d_pos < d_end && isbase64(strptr[d_pos])) + while(d_pos < d_end && isbase64(strptr[d_pos], true)) d_pos++; string tmp; @@ -485,6 +502,11 @@ void RecordTextWriter::xfrLabel(const string& val, bool) d_string+=val; } +void RecordTextWriter::xfrBlobNoSpaces(const string& val, int size) +{ + xfrBlob(val, size); +} + void RecordTextWriter::xfrBlob(const string& val, int) { if(!d_string.empty()) diff --git a/pdns/rcpgenerator.hh b/pdns/rcpgenerator.hh index 040ce7f51d..fb9aac9415 100644 --- a/pdns/rcpgenerator.hh +++ b/pdns/rcpgenerator.hh @@ -56,6 +56,7 @@ public: void xfrHexBlob(string& val, bool keepReading=false); void xfrBase32HexBlob(string& val); + void xfrBlobNoSpaces(string& val, int len=-1); void xfrBlob(string& val, int len=-1); bool eof(); @@ -83,6 +84,7 @@ public: void xfrType(const uint16_t& val); void xfrLabel(const string& val, bool compress=false); void xfrText(const string& val, bool multi=false); + void xfrBlobNoSpaces(const string& val, int len=-1); void xfrBlob(const string& val, int len=-1); void xfrHexBlob(const string& val, bool keepReading=false); bool eof() { return true; };