PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Net/DNS/RR/TXT.php

https://github.com/ldath/Sblam
PHP | 112 lines | 63 code | 7 blank | 42 comment | 9 complexity | 55004f38973d751d696c0641f6bcd237 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  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. * Maintainers:
  8. * Marco Kaiser <bate@php.net>
  9. * Florian Anderiasch <fa@php.net>
  10. *
  11. * PHP versions 4 and 5
  12. *
  13. * LICENSE: This source file is subject to version 3.01 of the PHP license
  14. * that is available through the world-wide-web at the following URI:
  15. * http://www.php.net/license/3_01.txt. If you did not receive a copy of
  16. * the PHP License and are unable to obtain it through the web, please
  17. * send a note to license@php.net so we can mail you a copy immediately.
  18. */
  19. /* Net_DNS_RR_TXT definition {{{ */
  20. /**
  21. * A representation of a resource record of type <b>TXT</b>
  22. *
  23. * @package Net_DNS
  24. */
  25. class Net_DNS_RR_TXT extends Net_DNS_RR
  26. {
  27. /* class variable definitions {{{ */
  28. var $name;
  29. var $type;
  30. var $class;
  31. var $ttl;
  32. var $rdlength;
  33. var $rdata;
  34. var $text;
  35. /* }}} */
  36. /* class constructor - RR(&$rro, $data, $offset = '') {{{ */
  37. function Net_DNS_RR_TXT(&$rro, $data, $offset = '')
  38. {
  39. $this->name = $rro->name;
  40. $this->type = $rro->type;
  41. $this->class = $rro->class;
  42. $this->ttl = $rro->ttl;
  43. $this->rdlength = $rro->rdlength;
  44. $this->rdata = $rro->rdata;
  45. if ($offset) {
  46. if ($this->rdlength > 0) {
  47. $maxoffset = $this->rdlength + $offset;
  48. while ($maxoffset > $offset) {
  49. list($text, $offset) = Net_DNS_Packet::label_extract($data, $offset);
  50. $this->text[] = $text;
  51. }
  52. }
  53. } elseif (is_array($data)) {
  54. $this->text = $data['text'];
  55. } else {
  56. $data = str_replace('\\\\', chr(1) . chr(1), $data); /* disguise escaped backslash */
  57. $data = str_replace('\\"', chr(2) . chr(2), $data); /* disguise \" */
  58. ereg('("[^"]*"|[^ \t]*)[ \t]*$', $data, $regs);
  59. $regs[1] = str_replace(chr(2) . chr(2), '\\"', $regs[1]);
  60. $regs[1] = str_replace(chr(1) . chr(1), '\\\\', $regs[1]);
  61. $regs[1] = stripslashes($regs[1]);
  62. $this->text = $regs[1];
  63. }
  64. }
  65. /* }}} */
  66. /* Net_DNS_RR_TXT::rdatastr() {{{ */
  67. function rdatastr()
  68. {
  69. if ($this->text) {
  70. if (is_array($this->text)) {
  71. $tmp = array();
  72. foreach ($this->text as $t) {
  73. $tmp[] = '"'.addslashes($t).'"';
  74. }
  75. return implode(' ',$tmp);
  76. } else {
  77. return '"' . addslashes($this->text) . '"';
  78. }
  79. } else return '; no data';
  80. }
  81. /* }}} */
  82. /* Net_DNS_RR_TXT::rr_rdata($packet, $offset) {{{ */
  83. function rr_rdata($packet, $offset)
  84. {
  85. if ($this->text) {
  86. $rdata = pack('C', strlen($this->text)) . $this->text;
  87. return $rdata;
  88. }
  89. return null;
  90. }
  91. /* }}} */
  92. }
  93. /* }}} */
  94. /* VIM settings {{{
  95. * Local variables:
  96. * tab-width: 4
  97. * c-basic-offset: 4
  98. * soft-stop-width: 4
  99. * c indent on
  100. * End:
  101. * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et
  102. * vim<600: sw=4 ts=4
  103. * }}} */
  104. ?>