1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import struct
19
20 import dns.exception
21 import dns.rdata
22 import dns.rdatatype
23 import dns.name
24 from dns._compat import xrange
25
26 -class CSYNC(dns.rdata.Rdata):
27
28 """CSYNC record
29
30 @ivar serial: the SOA serial number
31 @type serial: int
32 @ivar flags: the CSYNC flags
33 @type flags: int
34 @ivar windows: the windowed bitmap list
35 @type windows: list of (window number, string) tuples"""
36
37 __slots__ = ['serial', 'flags', 'windows']
38
39 - def __init__(self, rdclass, rdtype, serial, flags, windows):
44
45 - def to_text(self, origin=None, relativize=True, **kw):
46 text = ''
47 for (window, bitmap) in self.windows:
48 bits = []
49 for i in xrange(0, len(bitmap)):
50 byte = bitmap[i]
51 for j in xrange(0, 8):
52 if byte & (0x80 >> j):
53 bits.append(dns.rdatatype.to_text(window * 256 +
54 i * 8 + j))
55 text += (' ' + ' '.join(bits))
56 return '%d %d%s' % (self.serial, self.flags, text)
57
58 @classmethod
59 - def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
60 serial = tok.get_uint32()
61 flags = tok.get_uint16()
62 rdtypes = []
63 while 1:
64 token = tok.get().unescape()
65 if token.is_eol_or_eof():
66 break
67 nrdtype = dns.rdatatype.from_text(token.value)
68 if nrdtype == 0:
69 raise dns.exception.SyntaxError("CSYNC with bit 0")
70 if nrdtype > 65535:
71 raise dns.exception.SyntaxError("CSYNC with bit > 65535")
72 rdtypes.append(nrdtype)
73 rdtypes.sort()
74 window = 0
75 octets = 0
76 prior_rdtype = 0
77 bitmap = bytearray(b'\0' * 32)
78 windows = []
79 for nrdtype in rdtypes:
80 if nrdtype == prior_rdtype:
81 continue
82 prior_rdtype = nrdtype
83 new_window = nrdtype // 256
84 if new_window != window:
85 windows.append((window, bitmap[0:octets]))
86 bitmap = bytearray(b'\0' * 32)
87 window = new_window
88 offset = nrdtype % 256
89 byte = offset // 8
90 bit = offset % 8
91 octets = byte + 1
92 bitmap[byte] = bitmap[byte] | (0x80 >> bit)
93
94 windows.append((window, bitmap[0:octets]))
95 return cls(rdclass, rdtype, serial, flags, windows)
96
97 - def to_wire(self, file, compress=None, origin=None):
102
103 @classmethod
104 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
127