home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / SOA.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  4.5 KB  |  138 lines

  1. <?php
  2. /*
  3.  *  License Information:
  4.  *
  5.  *    Net_DNS:  A resolver library for PHP
  6.  *    Copyright (C) 2002 Eric Kilfoil eric@ypass.net
  7.  *
  8.  *    This library is free software; you can redistribute it and/or
  9.  *    modify it under the terms of the GNU Lesser General Public
  10.  *    License as published by the Free Software Foundation; either
  11.  *    version 2.1 of the License, or (at your option) any later version.
  12.  *
  13.  *    This library is distributed in the hope that it will be useful,
  14.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  *    Lesser General Public License for more details.
  17.  *
  18.  *    You should have received a copy of the GNU Lesser General Public
  19.  *    License along with this library; if not, write to the Free Software
  20.  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21.  */
  22.  
  23. /* Net_DNS_RR_SOA definition {{{ */
  24. /**
  25.  * A representation of a resource record of type <b>SOA</b>
  26.  *
  27.  * @package Net_DNS
  28.  */
  29. class Net_DNS_RR_SOA extends Net_DNS_RR
  30. {
  31.     /* class variable definitions {{{ */
  32.     var $name;
  33.     var $type;
  34.     var $class;
  35.     var $ttl;
  36.     var $rdlength;
  37.     var $rdata;
  38.     var $mname;
  39.     var $rname;
  40.     var $serial;
  41.     var $refresh;
  42.     var $retry;
  43.     var $expire;
  44.     var $minimum;
  45.  
  46.     /* }}} */
  47.     /* class constructor - RR(&$rro, $data, $offset = "") {{{ */
  48.     function Net_DNS_RR_SOA(&$rro, $data, $offset = "")
  49.     {
  50.         $this->name = $rro->name;
  51.         $this->type = $rro->type;
  52.         $this->class = $rro->class;
  53.         $this->ttl = $rro->ttl;
  54.         $this->rdlength = $rro->rdlength;
  55.         $this->rdata = $rro->rdata;
  56.  
  57.         if ($offset) {
  58.             if ($this->rdlength > 0) {
  59.                 list($mname, $offset) = Net_DNS_Packet::dn_expand($data, $offset);
  60.                 list($rname, $offset) = Net_DNS_Packet::dn_expand($data, $offset);
  61.  
  62.                 $a = unpack("@$offset/N5soavals", $data);
  63.                 $this->mname = $mname;
  64.                 $this->rname = $rname;
  65.                 $this->serial = $a["soavals1"];
  66.                 $this->refresh = $a["soavals2"];
  67.                 $this->retry = $a["soavals3"];
  68.                 $this->expire = $a["soavals4"];
  69.                 $this->minimum = $a["soavals5"];
  70.             }
  71.         } else {
  72.             if (ereg("([^ \t]+)[ \t]+([^ \t]+)[ \t]+([0-9]+)[^ \t]+([0-9]+)[^ \t]+([0-9]+)[^ \t]+([0-9]+)[^ \t]*$", $string, $regs))
  73.             {
  74.                 $this->mname = ereg_replace("(.*)\.$", "\\1", $regs[1]);
  75.                 $this->rname = ereg_replace("(.*)\.$", "\\1", $regs[2]);
  76.                 $this->serial = $regs[3];
  77.                 $this->refresh = $regs[4];
  78.                 $this->retry = $regs[5];
  79.                 $this->expire = $regs[6];
  80.                 $this->minimum = $regs[7];
  81.             }
  82.         }
  83.     }
  84.  
  85.     /* }}} */
  86.     /* Net_DNS_RR_SOA::rdatastr($pretty = 0) {{{ */
  87.     function rdatastr($pretty = 0)
  88.     {
  89.         if (strlen($this->mname)) {
  90.             if ($pretty) {
  91.                 $rdatastr  = $this->mname . ". " . $this->rname . ". (\n";
  92.                 $rdatastr .= "\t\t\t\t\t" . $this->serial . "\t; Serial\n";
  93.                 $rdatastr .= "\t\t\t\t\t" . $this->refresh . "\t; Refresh\n";
  94.                 $rdatastr .= "\t\t\t\t\t" . $this->retry . "\t; Retry\n";
  95.                 $rdatastr .= "\t\t\t\t\t" . $this->expire . "\t; Expire\n";
  96.                 $rdatastr .= "\t\t\t\t\t" . $this->minimum . " )\t; Minimum TTL";
  97.             } else {
  98.                 $rdatastr  = $this->mname . ". " . $this->rname . ". " .
  99.                     $this->serial . " " .  $this->refresh . " " .  $this->retry . " " .
  100.                     $this->expire . " " .  $this->minimum;
  101.             }
  102.             return($rdatastr);
  103.         }
  104.         return("; no data");
  105.     }
  106.  
  107.     /* }}} */
  108.     /* Net_DNS_RR_SOA::rr_rdata($packet, $offset) {{{ */
  109.     function rr_rdata($packet, $offset)
  110.     {
  111.         if (strlen($this->mname)) {
  112.             $rdata = $packet->dn_comp($this->mname, $offset);
  113.             $rdata .= $packet->dn_comp($this->rname, $offset + strlen($rdata));
  114.             $rdata .= pack("N5", $this->serial,
  115.                     $this->refresh,
  116.                     $this->retry,
  117.                     $this->expire,
  118.                     $this->minimum);
  119.             return($rdata);
  120.         }
  121.         return(NULL);
  122.     }
  123.  
  124.     /* }}} */
  125. }
  126. /* }}} */
  127. /* VIM settings {{{
  128.  * Local variables:
  129.  * tab-width: 4
  130.  * c-basic-offset: 4
  131.  * soft-stop-width: 4
  132.  * c indent on
  133.  * End:
  134.  * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et
  135.  * vim<600: sw=4 ts=4
  136.  * }}} */
  137. ?>
  138.