PageRenderTime 27ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Net/DNS2/RR/AFSDB.php

http://netdns2.googlecode.com/
PHP | 174 lines | 38 code | 18 blank | 118 comment | 2 complexity | 9c324b133c3fcc0bb4617ebf05816229 MD5 | raw file
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * DNS Library for handling lookups and updates.
  5. *
  6. * PHP Version 5
  7. *
  8. * Copyright (c) 2010, Mike Pultz <mike@mikepultz.com>.
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * * Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. *
  18. * * Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in
  20. * the documentation and/or other materials provided with the
  21. * distribution.
  22. *
  23. * * Neither the name of Mike Pultz nor the names of his contributors
  24. * may be used to endorse or promote products derived from this
  25. * software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  30. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  31. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  33. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  35. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * @category Networking
  41. * @package Net_DNS2
  42. * @author Mike Pultz <mike@mikepultz.com>
  43. * @copyright 2010 Mike Pultz <mike@mikepultz.com>
  44. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  45. * @version SVN: $Id: AFSDB.php 127 2011-12-03 03:29:39Z mike.pultz $
  46. * @link http://pear.php.net/package/Net_DNS2
  47. * @since File available since Release 0.6.0
  48. *
  49. */
  50. /**
  51. * AFSDB Resource Record - RFC1183 section 1
  52. *
  53. * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  54. * | SUBTYPE |
  55. * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  56. * / HOSTNAME /
  57. * / /
  58. * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  59. *
  60. * @category Networking
  61. * @package Net_DNS2
  62. * @author Mike Pultz <mike@mikepultz.com>
  63. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  64. * @link http://pear.php.net/package/Net_DNS2
  65. * @see Net_DNS2_RR
  66. *
  67. */
  68. class Net_DNS2_RR_AFSDB extends Net_DNS2_RR
  69. {
  70. /*
  71. * The AFSDB sub type
  72. */
  73. public $subtype;
  74. /*
  75. * The AFSDB hostname
  76. */
  77. public $hostname;
  78. /**
  79. * method to return the rdata portion of the packet as a string
  80. *
  81. * @return string
  82. * @access protected
  83. *
  84. */
  85. protected function rrToString()
  86. {
  87. return $this->subtype . ' ' . $this->cleanString($this->hostname) . '.';
  88. }
  89. /**
  90. * parses the rdata portion from a standard DNS config line
  91. *
  92. * @param array $rdata a string split line of values for the rdata
  93. *
  94. * @return boolean
  95. * @access protected
  96. *
  97. */
  98. protected function rrFromString(array $rdata)
  99. {
  100. $this->subtype = array_shift($rdata);
  101. $this->hostname = $this->cleanString(array_shift($rdata));
  102. return true;
  103. }
  104. /**
  105. * parses the rdata of the Net_DNS2_Packet object
  106. *
  107. * @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
  108. *
  109. * @return boolean
  110. * @access protected
  111. *
  112. */
  113. protected function rrSet(Net_DNS2_Packet &$packet)
  114. {
  115. if ($this->rdlength > 0) {
  116. //
  117. // unpack the subtype
  118. //
  119. $x = unpack('nsubtype', $this->rdata);
  120. $this->subtype = $x['subtype'];
  121. $offset = $packet->offset + 2;
  122. $this->hostname = Net_DNS2_Packet::expand($packet, $offset);
  123. return true;
  124. }
  125. return false;
  126. }
  127. /**
  128. * returns the rdata portion of the DNS packet
  129. *
  130. * @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
  131. * compressed names
  132. *
  133. * @return mixed either returns a binary packed
  134. * string or null on failure
  135. * @access protected
  136. *
  137. */
  138. protected function rrGet(Net_DNS2_Packet &$packet)
  139. {
  140. if (strlen($this->hostname) > 0) {
  141. $data = pack('n', $this->subtype);
  142. $packet->offset += 2;
  143. $data .= $packet->compress($this->hostname, $packet->offset);
  144. return $data;
  145. }
  146. return null;
  147. }
  148. }
  149. /*
  150. * Local variables:
  151. * tab-width: 4
  152. * c-basic-offset: 4
  153. * c-hanging-comment-ender-p: nil
  154. * End:
  155. */
  156. ?>