NAPTR.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /*
  3. * License Information:
  4. *
  5. * Net_DNS: A resolver library for PHP
  6. * Copyright (c) 2002-2003 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. /* Net_DNS_RR_NAPTR definition {{{ */
  23. /**
  24. * A representation of a resource record of type <b>NAPTR</b>
  25. *
  26. * @package Net_DNS
  27. */
  28. class Net_DNS_RR_NAPTR extends Net_DNS_RR
  29. {
  30. /* class variable definitions {{{ */
  31. var $name;
  32. var $type;
  33. var $class;
  34. var $ttl;
  35. var $rdlength;
  36. var $rdata;
  37. var $order;
  38. var $preference;
  39. var $flags;
  40. var $services;
  41. var $regex;
  42. var $replacement;
  43. /* }}} */
  44. /* class constructor - RR(&$rro, $data, $offset = '') {{{ */
  45. function Net_DNS_RR_NAPTR(&$rro, $data, $offset = '')
  46. {
  47. $this->name = $rro->name;
  48. $this->type = $rro->type;
  49. $this->class = $rro->class;
  50. $this->ttl = $rro->ttl;
  51. $this->rdlength = $rro->rdlength;
  52. $this->rdata = $rro->rdata;
  53. if ($offset) {
  54. if ($this->rdlength > 0) {
  55. $a = unpack("@$offset/norder/npreference", $data);
  56. $offset += 4;
  57. list($flags, $offset) = Net_DNS_Packet::label_extract($data, $offset);
  58. list($services, $offset) = Net_DNS_Packet::label_extract($data, $offset);
  59. list($regex, $offset) = Net_DNS_Packet::label_extract($data, $offset);
  60. list($replacement, $offset) = Net_DNS_Packet::dn_expand($data, $offset);
  61. $this->order = $a['order'];
  62. $this->preference = $a['preference'];
  63. $this->flags = $flags;
  64. $this->services = $services;
  65. $this->regex = $regex;
  66. $this->replacement = $replacement;
  67. }
  68. } else {
  69. $data = str_replace('\\\\', chr(1) . chr(1), $data); /* disguise escaped backslash */
  70. $data = str_replace('\\"', chr(2) . chr(2), $data); /* disguise \" */
  71. ereg('([0-9]+)[ \t]+([0-9]+)[ \t]+("[^"]*"|[^ \t]*)[ \t]+("[^"]*"|[^ \t]*)[ \t]+("[^"]*"|[^ \t]*)[ \t]+(.*?)[ \t]*$', $data, $regs);
  72. $this->preference = $regs[1];
  73. $this->weight = $regs[2];
  74. foreach($regs as $idx => $value) {
  75. $value = str_replace(chr(2) . chr(2), '\\"', $value);
  76. $value = str_replace(chr(1) . chr(1), '\\\\', $value);
  77. $regs[$idx] = stripslashes($value);
  78. }
  79. $this->flags = $regs[3];
  80. $this->services = $regs[4];
  81. $this->regex = $regs[5];
  82. $this->replacement = $regs[6];
  83. }
  84. }
  85. /* }}} */
  86. /* Net_DNS_RR_NAPTR::rdatastr() {{{ */
  87. function rdatastr()
  88. {
  89. if ($this->port) {
  90. return(intval($this->order) . ' ' . intval($this->preference) . ' "' . addslashes($this->flags) . '" "' .
  91. addslashes($this->services) . '" "' . addslashes($this->regex) . '" "' . addslashes($this->replacement) . '"');
  92. } else return('; no data');
  93. }
  94. /* }}} */
  95. /* Net_DNS_RR_NAPTR::rr_rdata($packet, $offset) {{{ */
  96. function rr_rdata($packet, $offset)
  97. {
  98. if ($this->preference) {
  99. $rdata = pack('nn', $this->order, $this->preference);
  100. $rdata .= pack('C', strlen($this->flags)) . $this->flags;
  101. $rdata .= pack('C', strlen($this->services)) . $this->services;
  102. $rdata .= pack('C', strlen($this->regex)) . $this->regex;
  103. $rdata .= $packet->dn_comp($this->replacement, $offset + strlen($rdata));
  104. return($rdata);
  105. }
  106. return(NULL);
  107. }
  108. /* }}} */
  109. }
  110. /* }}} */
  111. /* VIM settings {{{
  112. * Local variables:
  113. * tab-width: 4
  114. * c-basic-offset: 4
  115. * soft-stop-width: 4
  116. * c indent on
  117. * End:
  118. * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et
  119. * vim<600: sw=4 ts=4
  120. * }}} */
  121. ?>