PageRenderTime 40ms CodeModel.GetById 31ms app.highlight 6ms RepoModel.GetById 1ms 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
  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
 20/* Net_DNS_RR_TXT definition {{{ */
 21/**
 22 * A representation of a resource record of type <b>TXT</b>
 23 *
 24 * @package Net_DNS
 25 */
 26class Net_DNS_RR_TXT extends Net_DNS_RR
 27{
 28    /* class variable definitions {{{ */
 29    var $name;
 30    var $type;
 31    var $class;
 32    var $ttl;
 33    var $rdlength;
 34    var $rdata;
 35    var $text;
 36
 37    /* }}} */
 38    /* class constructor - RR(&$rro, $data, $offset = '') {{{ */
 39    function Net_DNS_RR_TXT(&$rro, $data, $offset = '')
 40    {
 41        $this->name = $rro->name;
 42        $this->type = $rro->type;
 43        $this->class = $rro->class;
 44        $this->ttl = $rro->ttl;
 45        $this->rdlength = $rro->rdlength;
 46        $this->rdata = $rro->rdata;
 47
 48        if ($offset) {
 49            if ($this->rdlength > 0) {
 50                $maxoffset = $this->rdlength + $offset;
 51                while ($maxoffset > $offset) {
 52                    list($text, $offset) = Net_DNS_Packet::label_extract($data, $offset);
 53                    $this->text[] = $text;
 54                }
 55            }
 56        } elseif (is_array($data)) {
 57            $this->text = $data['text'];
 58        } else {
 59            $data = str_replace('\\\\', chr(1) . chr(1), $data); /* disguise escaped backslash */
 60            $data = str_replace('\\"', chr(2) . chr(2), $data); /* disguise \" */
 61
 62            ereg('("[^"]*"|[^ \t]*)[ \t]*$', $data, $regs);
 63            $regs[1] = str_replace(chr(2) . chr(2), '\\"', $regs[1]);
 64            $regs[1] = str_replace(chr(1) . chr(1), '\\\\', $regs[1]);
 65            $regs[1] = stripslashes($regs[1]);
 66
 67            $this->text = $regs[1];
 68        }
 69    }
 70
 71    /* }}} */
 72    /* Net_DNS_RR_TXT::rdatastr() {{{ */
 73    function rdatastr()
 74    {
 75        if ($this->text) {
 76             if (is_array($this->text)) {
 77                 $tmp = array();
 78                 foreach ($this->text as $t) {
 79                     $tmp[] = '"'.addslashes($t).'"';
 80                 }
 81                 return implode(' ',$tmp);
 82             } else {
 83                 return '"' . addslashes($this->text) . '"';
 84             }
 85        } else return '; no data';
 86    }
 87
 88    /* }}} */
 89    /* Net_DNS_RR_TXT::rr_rdata($packet, $offset) {{{ */
 90    function rr_rdata($packet, $offset)
 91    {
 92        if ($this->text) {
 93            $rdata  = pack('C', strlen($this->text)) . $this->text;
 94            return $rdata;
 95        }
 96        return null;
 97    }
 98
 99    /* }}} */
100}
101/* }}} */
102/* VIM settings {{{
103 * Local variables:
104 * tab-width: 4
105 * c-basic-offset: 4
106 * soft-stop-width: 4
107 * c indent on
108 * End:
109 * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et
110 * vim<600: sw=4 ts=4
111 * }}} */
112?>