vendor/bundle/ruby/2.7.0/gems/dnsruby-1.61.5/lib/dnsruby/zone_reader.rb
#  Take a line from the input zone file, and return the normalised form
#  do_prefix_hack should always be false
Take a line from the input zone file, and return the normalised form
do_prefix_hack should always be false
Take a line from the input zone file and return the normalised form do_prefix_hack should always be false
def normalise_line(line, do_prefix_hack = false)
      stored_line = "";
      if (line.index('"') != nil)
          stored_line = line[line.index('"'), line.length];
          line = line [0, line.index('"')]
      end
      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.strip
      if (stored_line && stored_line != "")
        line += " " + stored_line.strip
      end
      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
def normalise_line ( line , do_prefix_hack = false ) stored_line = "" ; if ( line . index ( '"' ) != nil ) stored_line = line [ line . index ( '"' ) , line . length ] ; line = line [ 0 , line . index ( '"' ) ] end 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 . strip if ( stored_line && stored_line != "" ) line += " " + stored_line . strip end 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
Take a line from the input zone file, and return the normalised form
do_prefix_hack should always be false
Take a line from the input zone file and return the normalised form do_prefix_hack should always be false
#  Note that a freestanding "@" is used to denote the current origin - we can simply replace that straight away #  Remove the ( and ) #  Note that no domain name may be specified in the RR - in that case, last_name should be used. How do we tell? Tab or space at start of line. #  If we have text in the record, then ignore that in the parsing, and stick it on again at the end # IN CNAME @ # IN CNAME @ #  o We need to identify the domain name in the record, and then # split on whitespace #  o add $ORIGIN to it if it is not absolute #  If the second field is not a number, then we should add the TTL to the line #  Remember we can get "m" "w" "y" here! So need to check for appropriate regexp... #  Replace the formatted ttl with an actual number #  Add the TTL #  If this is the SOA record, and no @last_explicit_ttl is defined, #  then we need to try the SOA TTL element from the config. Otherwise, #  find the SOA Minimum field, and use that. #  We should also generate a warning to that effect #  How do we know if it is an SOA record at this stage? It must be, or #  else @last_explicit_ttl should be defined #  We could put a marker in the RR for now - and replace it once we know #  the actual type. If the type is not SOA then, then we can raise an error #  Now see if the clas is included. If not, then we should default to the last class used. #  Wasn't a CLASS #  So add the last explicit class in #  Add the type so we can load the zone one RRSet at a time. #  If this is an RRSIG record, then add the TYPE COVERED rather than the type - this allows us to load a complete RRSet at a time #  Replace the %MISSING_TTL% text with the SOA TTL from the config #  Can we try the @last_explicit_ttl? #  We need to fix up any non-absolute names in the RR #  Some RRs have a single name, at the end of the string - #    to do these, we can just check the last character for "." and add the #    "." + origin string if necessary #         if (line[line.length-1, 1] != ".") #  Other RRs have several names. These should be parsed by Dnsruby, #    and the names adjusted there.
line
<not_specific>
do_prefix_hack
<not_specific>