Changeset 1056
- Timestamp:
- 06/07/07 23:10:21 (1 year ago)
- Files:
-
- trunk/pdns/pdns/zoneparser-tng.cc (modified) (9 diffs)
- trunk/pdns/pdns/zoneparser-tng.hh (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/pdns/pdns/zoneparser-tng.cc
r1030 r1056 41 41 if(!fp) 42 42 throw runtime_error("Unable to open file '"+fname+"': "+stringerror()); 43 d_fps.push(fp); 43 44 filestate fs(fp, fname); 45 d_filestates.push(fs); 44 46 } 45 47 46 48 ZoneParserTNG::~ZoneParserTNG() 47 49 { 48 while(!d_f ps.empty()) {49 fclose(d_f ps.top());50 d_f ps.pop();50 while(!d_filestates.empty()) { 51 fclose(d_filestates.top().d_fp); 52 d_filestates.pop(); 51 53 } 52 54 } … … 57 59 } 58 60 59 static unsigned int makeTTLFromZone(const string& str) 61 static bool isTimeSpec(const string& nextpart) 62 { 63 if(nextpart.empty()) 64 return false; 65 for(string::const_iterator iter = nextpart.begin(); iter != nextpart.end(); ++iter) { 66 if(isdigit(*iter)) 67 continue; 68 if(iter+1 != nextpart.end()) 69 return false; 70 char c=tolower(*iter); 71 return (c=='m' || c=='h' || c=='d' || c=='w' || c=='y'); 72 } 73 return true; 74 } 75 76 77 unsigned int ZoneParserTNG::makeTTLFromZone(const string& str) 60 78 { 61 79 if(str.empty()) … … 81 99 val*=3600*24*365; 82 100 break; 101 83 102 default: 84 throw ZoneParserTNG::exception("Unable to parse time specification '"+str+"'"); 103 throw ZoneParserTNG::exception("Unable to parse time specification '"+str+"' on line "+ 104 lexical_cast<string>(d_filestates.top().d_lineno)+" of file '"+ 105 d_filestates.top().d_filename+"'"); 85 106 } 86 107 return val; … … 199 220 200 221 222 201 223 bool ZoneParserTNG::get(DNSResourceRecord& rr) 202 224 { … … 215 237 if(d_line[0]=='$') { 216 238 string command=makeString(d_line, parts[0]); 217 if( command=="$TTL"&& parts.size() > 1)218 d_defaultttl=makeTTLFromZone( makeString(d_line,parts[1]));239 if(iequals(command,"$TTL") && parts.size() > 1) 240 d_defaultttl=makeTTLFromZone(trim_right_copy_if(makeString(d_line, parts[1]), is_any_of(";"))); 219 241 else if(iequals(command,"$INCLUDE") && parts.size() > 1) { 220 242 string fname=unquotify(makeString(d_line, parts[1])); … … 240 262 } 241 263 else 242 throw exception("Can't parse zone line '"+d_line+"'"); 264 throw exception("Can't parse zone line '"+d_line+"' on line "+lexical_cast<string>(d_filestates.top().d_lineno)+ 265 " of file '"+d_filestates.top().d_filename); 243 266 goto retry; 244 267 } … … 285 308 continue; 286 309 } 287 if(!haveTTL && !haveQTYPE && all(nextpart, is_digit())) {310 if(!haveTTL && !haveQTYPE && isTimeSpec(nextpart)) { 288 311 rr.ttl=makeTTLFromZone(nextpart); 289 312 haveTTL=true; … … 301 324 } 302 325 catch(...) { 303 throw runtime_error("Parsing zone content line: '"+nextpart+"' doesn't look like a qtype, stopping loop"); 326 throw runtime_error("Parsing zone content on line "+ 327 lexical_cast<string>(d_filestates.top().d_lineno)+ 328 " of file '"+d_filestates.top().d_filename+"': '"+nextpart+ 329 "' doesn't look like a qtype, stopping loop"); 304 330 } 305 331 } … … 365 391 bool ZoneParserTNG::getLine() 366 392 { 367 while(!d_f ps.empty()) {393 while(!d_filestates.empty()) { 368 394 char buffer[1024]; 369 if(fgets(buffer, 1024, d_fps.top())) { 395 if(fgets(buffer, 1024, d_filestates.top().d_fp)) { 396 d_filestates.top().d_lineno++; 370 397 d_line=buffer; 371 398 return true; 372 399 } 373 fclose(d_f ps.top());374 d_f ps.pop();400 fclose(d_filestates.top().d_fp); 401 d_filestates.pop(); 375 402 } 376 403 return false; trunk/pdns/pdns/zoneparser-tng.hh
r953 r1056 40 40 bool getTemplateLine(); 41 41 void stackFile(const std::string& fname); 42 stack<FILE *> d_fps;42 unsigned makeTTLFromZone(const std::string& str); 43 43 string d_reldir; 44 44 string d_line; … … 49 49 string d_templateline; 50 50 parts_t d_templateparts; 51 52 struct filestate { 53 filestate(FILE* fp, string filename) : d_fp(fp), d_filename(filename), d_lineno(0){} 54 FILE *d_fp; 55 string d_filename; 56 int d_lineno; 57 }; 58 stack<filestate> d_filestates; 51 59 }; 52 60