Package dns :: Package rdtypes :: Package ANY :: Module SOA |
[hide private]
[frames] | no frames]

# Source Code for Module dns.rdtypes.ANY.SOA

      1  # Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
      2  #
      3  # Permission to use, copy, modify, and distribute this software and its
      4  # documentation for any purpose with or without fee is hereby granted,
      5  # provided that the above copyright notice and this permission notice
      6  # appear in all copies.
      7  #
      8  # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
      9  # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     10  # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
     11  # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     12  # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     13  # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
     14  # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     15
     16  import struct
     17
     18  import dns.exception
     19  import dns.rdata
     20  import dns.name
     21
     22
     23 -class SOA(dns.rdata.Rdata):
     24
     25      """SOA record
     26
     27      @ivar mname: the SOA MNAME (master name) field
     28      @type mname: dns.name.Name object
     29      @ivar rname: the SOA RNAME (responsible name) field
     30      @type rname: dns.name.Name object
     31      @ivar serial: The zone's serial number
     32      @type serial: int
     33      @ivar refresh: The zone's refresh value (in seconds)
     34      @type refresh: int
     35      @ivar retry: The zone's retry value (in seconds)
     36      @type retry: int
     37      @ivar expire: The zone's expiration value (in seconds)
     38      @type expire: int
     39      @ivar minimum: The zone's negative caching time (in seconds, called
     40      "minimum" for historical reasons)
     41      @type minimum: int
     42      @see: RFC 1035"""
     43
     44      __slots__ = ['mname', 'rname', 'serial', 'refresh', 'retry', 'expire',
     45                   'minimum']
     46
     47 -    def __init__(self, rdclass, rdtype, mname, rname, serial, refresh, retry,
     48                   expire, minimum):
     49          super(SOA, self).__init__(rdclass, rdtype)
     50          self.mname = mname
     51          self.rname = rname
     52          self.serial = serial
     53          self.refresh = refresh
     54          self.retry = retry
     55          self.expire = expire
     56          self.minimum = minimum
     57
     58 -    def to_text(self, origin=None, relativize=True, **kw):
     59          mname = self.mname.choose_relativity(origin, relativize)
     60          rname = self.rname.choose_relativity(origin, relativize)
     61          return '%s %s %d %d %d %d %d' % (
     62              mname, rname, self.serial, self.refresh, self.retry,
     63              self.expire, self.minimum)
     64
     65      @classmethod
     66 -    def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
     67          mname = tok.get_name()
     68          rname = tok.get_name()
     69          mname = mname.choose_relativity(origin, relativize)
     70          rname = rname.choose_relativity(origin, relativize)
     71          serial = tok.get_uint32()
     72          refresh = tok.get_ttl()
     73          retry = tok.get_ttl()
     74          expire = tok.get_ttl()
     75          minimum = tok.get_ttl()
     76          tok.get_eol()
     77          return cls(rdclass, rdtype, mname, rname, serial, refresh, retry,
     78                     expire, minimum)
     79
     80 -    def to_wire(self, file, compress=None, origin=None):
     81          self.mname.to_wire(file, compress, origin)
     82          self.rname.to_wire(file, compress, origin)
     83          five_ints = struct.pack('!IIIII', self.serial, self.refresh,
     84                                  self.retry, self.expire, self.minimum)
     85          file.write(five_ints)
     86
     87 -    def to_digestable(self, origin=None):
     88          return self.mname.to_digestable(origin) + \
     89              self.rname.to_digestable(origin) + \
     90              struct.pack('!IIIII', self.serial, self.refresh,
     91                          self.retry, self.expire, self.minimum)
     92
     93      @classmethod
     94 -    def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
     95          (mname, cused) = dns.name.from_wire(wire[: current + rdlen], current)
     96          current += cused
     97          rdlen -= cused
     98          (rname, cused) = dns.name.from_wire(wire[: current + rdlen], current)
     99          current += cused
    100          rdlen -= cused
    101          if rdlen != 20:
    102              raise dns.exception.FormError
    103          five_ints = struct.unpack('!IIIII',
    104                                    wire[current: current + rdlen])
    105          if origin is not None:
    106              mname = mname.relativize(origin)
    107              rname = rname.relativize(origin)
    108          return cls(rdclass, rdtype, mname, rname,
    109                     five_ints[0], five_ints[1], five_ints[2], five_ints[3],
    110                     five_ints[4])
    111
    112 -    def choose_relativity(self, origin=None, relativize=True):
    113          self.mname = self.mname.choose_relativity(origin, relativize)
    114          self.rname = self.rname.choose_relativity(origin, relativize)
    115