pair<string, string> splitField(const string& inp, char sepa);
-inline bool isCanonical(const string& dom)
+inline bool isCanonical(const string& qname)
{
- if(dom.empty())
+ if(qname.empty())
return false;
- return dom[dom.size()-1]=='.';
+ return qname[qname.size()-1]=='.';
}
-// get rid of this?
-inline string toCanonic(const DNSName& zone, const string& domain)
+inline DNSName toCanonic(const DNSName& zone, const string& qname)
{
- return toCanonic(zone.toString(), domain);
-}
-
-// and this?
-inline string toCanonic(const string& zone, const string& domain)
-{
- if(domain.length()==1 && domain[0]=='@')
- return zone;
-
- if(isCanonical(domain))
- return domain;
- string ret=domain;
- ret.append(1,'.');
- if(!zone.empty() && zone[0]!='.')
- ret.append(zone);
- return ret;
+ if(qname.size()==1 && qname[0]=='@')
+ return zone.toString();
+ if(isCanonical(qname))
+ return DNSName(qname).toString();
+ return DNSName(qname) += zone;
}
string stripDot(const string& dom);
stackFile(fname);
}
else if(pdns_iequals(command, "$ORIGIN") && parts.size() > 1) {
- d_zonename = DNSName(toCanonic(string(""), makeString(d_line, parts[1])));
+ d_zonename = DNSName(makeString(d_line, parts[1]));
}
else if(pdns_iequals(command, "$GENERATE") && parts.size() > 2) {
// $GENERATE 1-127 $ CNAME $.0
goto retry;
}
+ bool prevqname=false;
string qname = makeString(d_line, parts[0]); // Don't use DNSName here!
- if(isspace(d_line[0]))
+ if(isspace(d_line[0])) {
rr.qname=d_prevqname;
- else {
+ prevqname=true;
+ }else {
rr.qname=qname;
parts.pop_front();
- if(!rr.qname.countLabels() || rr.qname.toString()[0]==';')
+ if(qname.empty() || qname[0]==';')
goto retry;
}
if(qname=="@")
rr.qname=d_zonename;
- else if(!isCanonical(qname))
+ else if(!prevqname && !isCanonical(qname))
rr.qname += d_zonename;
d_prevqname=rr.qname;
trim(rr.content);
if(equals(rr.content, "@"))
- rr.content=d_zonename.toString();
+ rr.content=d_zonename.toStringNoDot();
if(findAndElide(rr.content, '(')) { // have found a ( and elided it
if(!findAndElide(rr.content, ')')) {
stringtok(recparts, rr.content);
if(recparts.size()==2) {
if (recparts[1]!=".")
- recparts[1] = stripDot(toCanonic(d_zonename.toString(), recparts[1]));
+ recparts[1] = toCanonic(d_zonename, recparts[1]).toStringNoDot();
rr.content=recparts[0]+" "+recparts[1];
}
break;
case QType::RP:
stringtok(recparts, rr.content);
if(recparts.size()==2) {
- recparts[0] = stripDot(toCanonic(d_zonename.toString(), recparts[0]));
- recparts[1] = stripDot(toCanonic(d_zonename.toString(), recparts[1]));
+ recparts[0] = toCanonic(d_zonename, recparts[0]).toStringNoDot();
+ recparts[1] = toCanonic(d_zonename, recparts[1]).toStringNoDot();
rr.content=recparts[0]+" "+recparts[1];
}
break;
stringtok(recparts, rr.content);
if(recparts.size()==4) {
if(recparts[3]!=".")
- recparts[3] = stripDot(toCanonic(d_zonename.toString(), recparts[3]));
+ recparts[3] = toCanonic(d_zonename, recparts[3]).toStringNoDot();
rr.content=recparts[0]+" "+recparts[1]+" "+recparts[2]+" "+recparts[3];
}
break;
case QType::DNAME:
case QType::PTR:
case QType::AFSDB:
- rr.content=stripDot(toCanonic(d_zonename.toString(), rr.content));
+ rr.content=toCanonic(d_zonename, rr.content).toStringNoDot();
break;
case QType::SOA:
stringtok(recparts, rr.content);
if(recparts.size() > 1) {
- recparts[0]=toCanonic(d_zonename.toString(), recparts[0]);
- recparts[1]=toCanonic(d_zonename.toString(), recparts[1]);
+ recparts[0]=toCanonic(d_zonename, recparts[0]).toStringNoDot();
+ recparts[1]=toCanonic(d_zonename, recparts[1]).toStringNoDot();
}
rr.content.clear();
for(string::size_type n = 0; n < recparts.size(); ++n) {