Properly handle multiple lines targets (TXT, DKIM).
parent
8bef46803e
commit
407cfc874a
|
@ -212,6 +212,15 @@ class DNSManager::Storage::Zone
|
|||
|
||||
errors
|
||||
end
|
||||
|
||||
def to_s(io : IO)
|
||||
io << "(#{ "%4d" % @rrid }) "
|
||||
io << "#{ "%30s" % @name} #{ "%6d" % @ttl} #{ "%10s" % @rrtype } #{quoted_string @target}\n"
|
||||
end
|
||||
|
||||
def to_bind9(io : IO)
|
||||
io << "#{@name} #{@ttl} IN #{@rrtype} #{split_line @target}\n"
|
||||
end
|
||||
end
|
||||
|
||||
class PTR < ResourceRecord
|
||||
|
@ -523,17 +532,11 @@ class DNSManager::Storage::Zone
|
|||
|
||||
def to_s(io : IO)
|
||||
io << "(#{ "%4d" % @rrid }) "
|
||||
io << "#{ "%30s" % @name} #{ "%6d" % @ttl} DKIM "
|
||||
io << "( "
|
||||
io << split_line dkim.to_s
|
||||
io << " )\n"
|
||||
io << "#{ "%30s" % @name} #{ "%6d" % @ttl} DKIM #{split_line dkim.to_s}\n"
|
||||
end
|
||||
|
||||
def to_bind9(io : IO)
|
||||
io << "#{@name} #{@ttl} IN TXT "
|
||||
io << "( "
|
||||
io << split_line dkim.to_s
|
||||
io << " )\n"
|
||||
io << "#{@name} #{@ttl} IN TXT #{split_line dkim.to_s}\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -832,16 +835,30 @@ def qualifier_to_string(qualifier : DNSManager::Storage::Zone::SPF::Qualifier) :
|
|||
end
|
||||
|
||||
def split_line(line : String) : String
|
||||
max_char_per_line = 50
|
||||
|
||||
iostr = IO::Memory.new line
|
||||
slice = Bytes.new(50)
|
||||
slice = Bytes.new(max_char_per_line)
|
||||
lines = ""
|
||||
first_time = true
|
||||
while rbytes = iostr.read slice
|
||||
break if rbytes == 0
|
||||
lines += '"'
|
||||
lines += String.new slice[0..rbytes -1]
|
||||
lines += '"'
|
||||
lines += "\n\t"
|
||||
if first_time
|
||||
first_time = false
|
||||
else
|
||||
lines += "\n\t"
|
||||
end
|
||||
lines += quoted_string (String.new slice[0..rbytes -1])
|
||||
end
|
||||
|
||||
lines = "( #{lines} )" if lines.size > max_char_per_line
|
||||
lines
|
||||
end
|
||||
|
||||
def quoted_string(value : String) : String
|
||||
String.build do |io|
|
||||
io << '"'
|
||||
io << value
|
||||
io << '"'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue