Changeset 996
- Timestamp:
- 03/25/07 20:11:19 (2 years ago)
- Files:
-
- trunk/pdns/pdns/dnsparser.cc (modified) (1 diff)
- trunk/pdns/pdns/dnsparser.hh (modified) (2 diffs)
- trunk/pdns/pdns/dnsrecords.cc (modified) (2 diffs)
- trunk/pdns/pdns/dnswriter.cc (modified) (2 diffs)
- trunk/pdns/pdns/dnswriter.hh (modified) (1 diff)
- trunk/pdns/pdns/rcpgenerator.cc (modified) (2 diffs)
- trunk/pdns/pdns/rcpgenerator.hh (modified) (2 diffs)
- trunk/pdns/pdns/zoneparser-tng.cc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/pdns/pdns/dnsparser.cc
r972 r996 359 359 } 360 360 361 string PacketReader::getText() 361 static string txtEscape(const string &name) 362 { 363 string ret; 364 365 for(string::const_iterator i=name.begin();i!=name.end();++i) 366 if(*i=='"' || *i=='\\'){ 367 ret += '\\'; 368 ret += *i; 369 } 370 else 371 ret += *i; 372 return ret; 373 } 374 375 // exceptions thrown here do not result in logging in the main pdns auth server - just so you know! 376 string PacketReader::getText(bool multi) 362 377 { 363 378 string ret; 364 379 ret.reserve(40); 365 366 unsigned char labellen=d_content.at(d_pos++); 367 ret.append(&d_content.at(d_pos), &d_content.at(d_pos+labellen-1)+1); // the end is one beyond the packet 368 d_pos+=labellen; 369 return ret; 370 } 380 while(d_pos < d_startrecordpos + d_recordlen ) { 381 if(!ret.empty()) { 382 ret.append(1,' '); 383 } 384 unsigned char labellen=d_content.at(d_pos++); 385 386 ret.append(1,'"'); 387 string val(&d_content.at(d_pos), &d_content.at(d_pos+labellen-1)+1); 388 389 ret.append(txtEscape(val)); // the end is one beyond the packet 390 ret.append(1,'"'); 391 d_pos+=labellen; 392 if(!multi) 393 break; 394 } 395 396 return ret; 397 } 398 371 399 372 400 void PacketReader::getLabelFromContent(const vector<uint8_t>& content, uint16_t& frompos, string& ret, int recurs) trunk/pdns/pdns/dnsparser.hh
r972 r996 110 110 } 111 111 112 void xfrText(string &text )113 { 114 text=getText( );112 void xfrText(string &text, bool multi=false) 113 { 114 text=getText(multi); 115 115 } 116 116 … … 126 126 127 127 string getLabel(unsigned int recurs=0); 128 string getText( );128 string getText(bool multi); 129 129 130 130 uint16_t d_pos; trunk/pdns/pdns/dnsrecords.cc
r978 r996 1 1 /* 2 2 PowerDNS Versatile Database Driven Nameserver 3 Copyright (C) 2005 - 200 6PowerDNS.COM BV3 Copyright (C) 2005 - 2007 PowerDNS.COM BV 4 4 5 5 This program is free software; you can redistribute it and/or modify … … 178 178 boilerplate_conv(PTR, ns_t_ptr, conv.xfrLabel(d_content, true)); 179 179 boilerplate_conv(CNAME, ns_t_cname, conv.xfrLabel(d_content, true)); 180 boilerplate_conv(TXT, ns_t_txt, conv.xfrText(d_text ));181 boilerplate_conv(SPF, 99, conv.xfrText(d_text ));180 boilerplate_conv(TXT, ns_t_txt, conv.xfrText(d_text, true)); 181 boilerplate_conv(SPF, 99, conv.xfrText(d_text, true)); 182 182 boilerplate_conv(HINFO, ns_t_hinfo, conv.xfrText(d_cpu); conv.xfrText(d_host)); 183 183 trunk/pdns/pdns/dnswriter.cc
r962 r996 2 2 #include "misc.hh" 3 3 #include "dnsparser.hh" 4 #include <boost/tokenizer.hpp> 4 5 5 6 DNSPacketWriter::DNSPacketWriter(vector<uint8_t>& content, const string& qname, uint16_t qtype, uint16_t qclass, uint8_t opcode) … … 116 117 } 117 118 118 void DNSPacketWriter::xfrText(const string& text) 119 { 120 d_record.push_back(text.length()); 121 const uint8_t* ptr=(uint8_t*)(text.c_str()); 122 d_record.insert(d_record.end(), ptr, ptr+text.size()); 119 void DNSPacketWriter::xfrText(const string& text, bool) 120 { 121 escaped_list_separator<char> sep('\\', ' ' , '"'); 122 tokenizer<escaped_list_separator<char> > tok(text, sep); 123 124 tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin(); 125 126 if(beg==tok.end()) { 127 d_record.push_back(0); 128 } 129 else 130 for(; beg!=tok.end(); ++beg){ 131 d_record.push_back(beg->length()); 132 const uint8_t* ptr=(uint8_t*)(beg->c_str()); 133 d_record.insert(d_record.end(), ptr, ptr+beg->length()); 134 } 123 135 } 124 136 trunk/pdns/pdns/dnswriter.hh
r962 r996 84 84 85 85 void xfrLabel(const string& label, bool compress=false); 86 void xfrText(const string& text );86 void xfrText(const string& text, bool multi=false); 87 87 void xfrBlob(const string& blob); 88 88 void xfrHexBlob(const string& blob); trunk/pdns/pdns/rcpgenerator.cc
r926 r996 207 207 } 208 208 209 210 void RecordTextReader::xfrText(string& val) 211 { 212 skipSpaces(); 213 if(d_string[d_pos]!='"') 214 throw RecordTextException("Data field in DNS should start with quote (\") at position "+lexical_cast<string>(d_pos)+" of '"+d_string+"'"); 215 209 void RecordTextReader::xfrText(string& val, bool multi) 210 { 216 211 val.clear(); 217 212 val.reserve(d_end - d_pos); 218 219 while(++d_pos < d_end && d_string[d_pos]!='"') { 220 if(d_string[d_pos]=='\\' && d_pos+1!=d_end) { 221 ++d_pos; 213 214 while(d_pos != d_end) { 215 if(!val.empty()) 216 val.append(1, ' '); 217 218 skipSpaces(); 219 if(d_string[d_pos]!='"') 220 throw RecordTextException("Data field in DNS should start with quote (\") at position "+lexical_cast<string>(d_pos)+" of '"+d_string+"'"); 221 222 val.append(1, '"'); 223 while(++d_pos < d_end && d_string[d_pos]!='"') { 224 if(d_string[d_pos]=='\\' && d_pos+1!=d_end) { 225 val.append(1, d_string[d_pos++]); 226 } 227 val.append(1, d_string[d_pos]); 222 228 } 223 val.append(1, d_string[d_pos]); 224 } 225 if(d_pos == d_end) 226 throw RecordTextException("Data field in DNS should end on a quote (\") in '"+d_string+"'"); 227 d_pos++; 229 val.append(1,'"'); 230 if(d_pos == d_end) 231 throw RecordTextException("Data field in DNS should end on a quote (\") in '"+d_string+"'"); 232 d_pos++; 233 if(!multi) 234 break; 235 } 228 236 } 229 237 … … 384 392 } 385 393 386 void RecordTextWriter::xfrText(const string& val) 387 { 388 if(!d_string.empty()) 389 d_string.append(1,' '); 390 d_string.append(1,'"'); 391 392 if(val.find_first_of("\\\"") == string::npos) 393 d_string+=val; 394 else { 395 string::size_type end=val.size(); 396 397 for(string::size_type pos=0; pos < end; ++pos) { 398 if(val[pos]=='\'' || val[pos]=='"') 399 d_string.append(1,'\\'); 400 d_string.append(1, val[pos]); 401 } 402 } 403 404 d_string.append(1,'"'); 394 void RecordTextWriter::xfrText(const string& val, bool multi) 395 { 396 if(!d_string.empty()) 397 d_string.append(1,' '); 398 399 d_string.append(val); 405 400 } 406 401 trunk/pdns/pdns/rcpgenerator.hh
r802 r996 51 51 52 52 void xfrLabel(string& val, bool compress=false); 53 void xfrText(string& val );53 void xfrText(string& val, bool multi=false); 54 54 void xfrHexBlob(string& val); 55 55 void xfrBlob(string& val); … … 76 76 void xfrType(const uint16_t& val); 77 77 void xfrLabel(const string& val, bool compress=false); 78 void xfrText(const string& val );78 void xfrText(const string& val, bool multi=false); 79 79 void xfrBlob(const string& val); 80 80 void xfrHexBlob(const string& val); trunk/pdns/pdns/zoneparser-tng.cc
r989 r996 281 281 } 282 282 catch(...) { 283 cerr<<"Oops, this doesn't look like a qtype, stopping loop\n"; 284 break; 283 throw runtime_error("Parsing zone content line: '"+nextpart+"' doesn't look like a qtype, stopping loop"); 285 284 } 286 285 }