def normalise_line(line, do_prefix_hack = false)
if ((line[0,1] == " ") || (line[0,1] == "\t"))
line = @last_name + " " + line
end
line.chomp!
line.sub!(/\s+@$/, " #{@origin}")
line.sub!(/^@\s+/, "#{@origin} ")
line.sub!(/\s+@\s+/, " #{@origin} ")
line.strip!
split = line.split(' ')
name = split[0].strip
if (name.index"\\")
ls =[]
Name.create(name).labels.each {|el| ls.push(Name.decode(el.to_s))}
new_name = ls.join('.')
if (!(/\.\z/ =~ name))
new_name += "." + @origin
else
new_name += "."
end
line = new_name + " "
(split.length - 1).times {|i| line += "#{split[i+1]} "}
line += "\n"
name = new_name
split = line.split
elsif !(/\.\z/ =~ name)
new_name = name + "." + @origin
line.sub!(name, new_name)
name = new_name
split = line.split
end
found_ttl_regexp = (split[1]=~/^[0-9]+[smhdwSMHDW]/)
if (found_ttl_regexp == 0)
ttl = get_ttl(split[1])
line = name + " #{ttl} "
@last_explicit_ttl = ttl
(split.length - 2).times {|i| line += "#{split[i+2]} "}
line += "\n"
split = line.split
elsif (((split[1]).to_i == 0) && (split[1] != "0"))
if (!@last_explicit_ttl)
line = name + " %MISSING_TTL% "
else
line = name + " #{@last_explicit_ttl} "
end
(split.length - 1).times {|i| line += "#{split[i+1]} "}
line += "\n"
split = line.split
else
@last_explicit_ttl = split[1].to_i
end
begin
klass = Classes.new(split[2])
@last_explicit_class = klass
rescue ArgumentError
line = ""
(2).times {|i| line += "#{split[i]} "}
line += " #{@last_explicit_class} "
(split.length - 2).times {|i| line += "#{split[i+2]} "}
line += "\n"
split = line.split
rescue Error => e
end
type = Types.new(split[3].strip)
is_soa = (type == Types::SOA)
type_was = type
if (type == Types.RRSIG)
type = Types.new(split[4].strip)
end
type_string=prefix_for_rrset_order(type, type_was)
@last_name = name
if !([Types::NAPTR, Types::TXT].include?type_was)
line.sub!("(", "")
line.sub!(")", "")
end
if (is_soa)
if (@soa_ttl)
line.sub!(" %MISSING_TTL% ", " #{@soa_ttl} ")
else
if (@last_explicit_ttl)
line.sub!(" %MISSING_TTL% ", " #{@last_explicit_ttl} ")
end
end
line = replace_soa_ttl_fields(line)
if (!@last_explicit_ttl)
soa_rr = Dnsruby::RR.create(line)
@last_explicit_ttl = soa_rr.minimum
end
end
line = line.split.join(' ').strip
if ([Types::MX, Types::NS, Types::AFSDB, Types::NAPTR, Types::RT,
Types::SRV, Types::CNAME, Types::MB, Types::MG, Types::MR,
Types::PTR, Types::DNAME].include?type_was)
if (!(/\.\z/ =~ line))
line = line + "." + @origin.to_s + "."
end
end
if ([Types::MINFO, Types::PX, Types::RP].include?type_was)
parsed_rr = Dnsruby::RR.create(line)
case parsed_rr.type
when Types::MINFO
if (!parsed_rr.rmailbx.absolute?)
parsed_rr.rmailbx = parsed_rr.rmailbx.to_s + "." + @origin.to_s
end
if (!parsed_rr.emailbx.absolute?)
parsed_rr.emailbx = parsed_rr.emailbx.to_s + "." + @origin.to_s
end
when Types::PX
if (!parsed_rr.map822.absolute?)
parsed_rr.map822 = parsed_rr.map822.to_s + "." + @origin.to_s
end
if (!parsed_rr.mapx400.absolute?)
parsed_rr.mapx400 = parsed_rr.mapx400.to_s + "." + @origin.to_s
end
when Types::RP
if (!parsed_rr.mailbox.absolute?)
parsed_rr.mailbox = parsed_rr.mailbox.to_s + "." + @origin.to_s
end
if (!parsed_rr.txtdomain.absolute?)
parsed_rr.txtdomain = parsed_rr.txtdomain.to_s + "." + @origin.to_s
end
end
line = parsed_rr.to_s
end
if (do_prefix_hack)
return line + "\n", type_string, @last_name
end
return line+"\n"
end