Permalink
Browse files

Introduce xfrBlobNoSpaces

  • Loading branch information...
1 parent 32ac4fa commit 6f0d4f152e0ca1e6e75ba303428de2e7bc92414e @cmouse cmouse committed with cmouse Jan 27, 2015
Showing with 38 additions and 3 deletions.
  1. +4 −0 pdns/dnsparser.cc
  2. +1 −0 pdns/dnsparser.hh
  3. +5 −0 pdns/dnswriter.cc
  4. +1 −0 pdns/dnswriter.hh
  5. +25 −3 pdns/rcpgenerator.cc
  6. +2 −0 pdns/rcpgenerator.hh
View
@@ -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) {
View
@@ -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);
View
@@ -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);
View
@@ -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;
View
@@ -207,10 +207,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')
@@ -222,12 +222,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<size_t>(len))
+ throw RecordTextException("Record length "+lexical_cast<string>(val.size()) + " does not match expected length '"+lexical_cast<string>(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;
@@ -484,6 +501,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())
@@ -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; };

0 comments on commit 6f0d4f1

Please sign in to comment.