PageRenderTime 25ms CodeModel.GetById 13ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Net/DNS/RR/HINFO.php

https://github.com/ldath/Sblam
PHP | 110 lines | 60 code | 8 blank | 42 comment | 6 complexity | 24699fe824bec5c66ed0a777dd242d51 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_HINFO definition {{{ */
 21/**
 22 * A representation of a resource record of type <b>HINFO</b>
 23 *
 24 * @package Net_DNS
 25 */
 26class Net_DNS_RR_HINFO 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 $cpu;
 36    var $os;
 37
 38    /* }}} */
 39    /* class constructor - RR(&$rro, $data, $offset = '') {{{ */
 40    function Net_DNS_RR_HINFO(&$rro, $data, $offset = '')
 41    {
 42        $this->name = $rro->name;
 43        $this->type = $rro->type;
 44        $this->class = $rro->class;
 45        $this->ttl = $rro->ttl;
 46        $this->rdlength = $rro->rdlength;
 47        $this->rdata = $rro->rdata;
 48
 49        if ($offset) {
 50            if ($this->rdlength > 0) {
 51                list($cpu, $offset) = Net_DNS_Packet::label_extract($data, $offset);
 52                list($os,  $offset) = Net_DNS_Packet::label_extract($data, $offset);
 53
 54                $this->cpu = $cpu;
 55                $this->os  = $os;
 56            }
 57        } elseif (is_array($data)) {
 58            $this->cpu = $data['cpu'];
 59            $this->os = $data['os'];
 60        } else {
 61            $data = str_replace('\\\\', chr(1) . chr(1), $data); /* disguise escaped backslash */
 62            $data = str_replace('\\"', chr(2) . chr(2), $data); /* disguise \" */
 63
 64            preg_match('/("[^"]*"|[^ \t]*)[ \t]+("[^"]*"|[^ \t]*)[ \t]*$/', $data, $regs);
 65            foreach($regs as $idx => $value) {
 66                $value = str_replace(chr(2) . chr(2), '\\"', $value);
 67                $value = str_replace(chr(1) . chr(1), '\\\\', $value);
 68                $regs[$idx] = stripslashes($value);
 69            }
 70
 71            $this->cpu = $regs[1];
 72            $this->os = $regs[2];
 73        }
 74    }
 75
 76    /* }}} */
 77    /* Net_DNS_RR_HINFO::rdatastr() {{{ */
 78    function rdatastr()
 79    {
 80        if ($this->text) {
 81            return '"' . addslashes($this->cpu) . '" "' . addslashes($this->os) . '"';
 82        } else return '; no data';
 83    }
 84
 85    /* }}} */
 86    /* Net_DNS_RR_HINFO::rr_rdata($packet, $offset) {{{ */
 87    function rr_rdata($packet, $offset)
 88    {
 89        if ($this->text) {
 90            $rdata  = pack('C', strlen($this->cpu)) . $this->cpu;
 91            $rdata .= pack('C', strlen($this->os))  . $this->os;
 92            return $rdata;
 93        }
 94        return null;
 95    }
 96
 97    /* }}} */
 98}
 99/* }}} */
100/* VIM settings {{{
101 * Local variables:
102 * tab-width: 4
103 * c-basic-offset: 4
104 * soft-stop-width: 4
105 * c indent on
106 * End:
107 * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et
108 * vim<600: sw=4 ts=4
109 * }}} */
110?>