]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add xfrUnquotedText()
authorPieter Lexis <pieter.lexis@powerdns.com>
Tue, 5 Jan 2016 16:14:53 +0000 (17:14 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Tue, 15 Mar 2016 13:19:11 +0000 (14:19 +0100)
pdns/dnsparser.cc
pdns/dnsparser.hh
pdns/dnswriter.cc
pdns/dnswriter.hh
pdns/rcpgenerator.cc
pdns/rcpgenerator.hh

index 405933c83aa10cbb610f611df3271da0c78af092..4e28afdad6701ba63b9d68bfc7e68ea67b98a2b3 100644 (file)
@@ -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
index 96f0906c0a790786675854770d9e97d13fc79a9f..baf3a82a7166b42c840cc27766f7bf9bfc17a777 100644 (file)
@@ -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;
 
index 06dc3b98046b00951e6eab0f8c13bc51da1cf62a..a50ee77f2671ba3f8dc6c8186fea6ddfb35a2553 100644 (file)
@@ -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)
 {
index 2936890e414bdbaa03f6d21f9a43ef06b8b10295..b4fd614e4bec33d1c6dc03fcd667a714277bf083 100644 (file)
@@ -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);
index 495d88972e696cfee6fc8fd6d25fcbb8e428f52b..28edc95f4e26f4fe8f91c3ada46f24c3d92dd07b 100644 (file)
@@ -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
 
index 5b33a01b404220b022e2e2e6600675bb38ee31f3..4b78438f46c116c702a0bbd00bae8d8802e91acf 100644 (file)
@@ -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);