~edb/quam-plures/cronjob_stuff

« back to all changes in this revision

Viewing changes to qp_plugins/basic_antispam_plugin/Net/DNS/RR/AAAA.php

  • Committer: EdB
  • Date: 2011-03-08 04:39:47 UTC
  • mfrom: (7592.1.1 quam-plures)
  • Revision ID: 1912webworks@gmail.com-20110308043947-apiklf384cgnwb7s
new stuff in core now here - woohoo!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_AAAA object definition {{{ */
 
21
/**
 
22
 * A representation of a resource record of type <b>AAAA</b>
 
23
 *
 
24
 * @package Net_DNS
 
25
 */
 
26
class Net_DNS_RR_AAAA 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 $address;
 
36
 
 
37
    /* }}} */
 
38
    /* class constructor - Net_DNS_RR_AAAA(&$rro, $data, $offset = '') {{{ */
 
39
    function Net_DNS_RR_AAAA(&$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
            $this->address = Net_DNS_RR_AAAA::ipv6_decompress(substr($this->rdata, 0, $this->rdlength));
 
50
        } elseif (is_array($data)) {
 
51
            $this->address = $data['address'];
 
52
        } else {
 
53
            if (strlen($data)) {
 
54
                if (count($adata = explode(':', $data, 8)) >= 3) {
 
55
                    foreach($adata as $addr)
 
56
                        if (!preg_match('/^[0-9A-F]{0,4}$/i', $addr)) return;
 
57
                    $this->address = trim($data);
 
58
                }
 
59
            }
 
60
        }
 
61
    }
 
62
 
 
63
    /* }}} */
 
64
    /* Net_DNS_RR_AAAA::rdatastr() {{{ */
 
65
    function rdatastr()
 
66
    {
 
67
        if (strlen($this->address)) {
 
68
            return $this->address;
 
69
        }
 
70
        return '; no data';
 
71
    }
 
72
    /* }}} */
 
73
    /* Net_DNS_RR_AAAA::rr_rdata($packet, $offset) {{{ */
 
74
    function rr_rdata($packet, $offset)
 
75
    {
 
76
        return Net_DNS_RR_AAAA::ipv6_compress($this->address);
 
77
    }
 
78
 
 
79
    /* }}} */
 
80
    /* Net_DNS_RR_AAAA::ipv6_compress($addr) {{{ */
 
81
    function ipv6_compress($addr)
 
82
    {
 
83
        $numparts = count(explode(':', $addr));
 
84
                if ($numparts < 3 || $numparts > 8 ) {
 
85
            /* Non-sensical IPv6 address */
 
86
            return pack('n8', 0, 0, 0, 0, 0, 0, 0, 0);
 
87
        }
 
88
        if (strpos($addr, '::') !== false) {
 
89
                        if (!preg_match('/^([0-9A-F]{0,4}:){0,7}(:[0-9A-F]{0,4}){0,7}$/i', $addr)) {
 
90
                                return pack('n8', 0, 0, 0, 0, 0, 0, 0, 0);
 
91
                        }
 
92
            /* First we have to normalize the address, turn :: into :0:0:0:0: */
 
93
            $filler = str_repeat(':0', 9 - $numparts) . ':';
 
94
            if (substr($addr, 0, 2) == '::') {
 
95
                $filler = "0$filler";
 
96
            }
 
97
            if (substr($addr, -2, 2) == '::') {
 
98
                $filler .= '0';
 
99
            }
 
100
            $addr = str_replace('::', $filler, $addr);
 
101
        } elseif (!preg_match('/^([0-9A-F]{0,4}:){7}[0-9A-F]{0,4}$/i', $addr)) {
 
102
                        return pack('n8', 0, 0, 0, 0, 0, 0, 0, 0);
 
103
                }
 
104
 
 
105
        $aparts = explode(':', $addr);
 
106
        return pack('n8', hexdec($aparts[0]), hexdec($aparts[1]), hexdec($aparts[2]), hexdec($aparts[3]),
 
107
                          hexdec($aparts[4]), hexdec($aparts[5]), hexdec($aparts[6]), hexdec($aparts[7]));
 
108
    }
 
109
    /* }}} */
 
110
 
 
111
    /* Net_DNS_RR_AAAA::ipv6_decompress($pack) {{{ */
 
112
    function ipv6_decompress($pack)
 
113
    {
 
114
        if (strlen($pack) != 16) {
 
115
            /* Must be 8 shorts long */
 
116
            return '::';
 
117
        }
 
118
        $a = unpack('n8', $pack);
 
119
        $addr = vsprintf("%x:%x:%x:%x:%x:%x:%x:%x", $a);
 
120
        /* Shorthand the first :0:0: set into a :: */
 
121
        /* TODO: Make this is a single replacement pattern */
 
122
        if (substr($addr, -4) == ':0:0') {
 
123
            return preg_replace('/((:0){2,})$/', '::', $addr);
 
124
        } elseif (substr($addr, 0, 4) == '0:0:') {
 
125
            return '0:0:'. substr($addr, 4);
 
126
        } else {
 
127
            return preg_replace('/(:(0:){2,})/', '::', $addr);
 
128
        }
 
129
    }
 
130
 
 
131
    /* }}} */
 
132
}
 
133
/* }}} */
 
134
/* VIM settings {{{
 
135
 * Local variables:
 
136
 * tab-width: 4
 
137
 * c-basic-offset: 4
 
138
 * soft-stop-width: 4
 
139
 * c indent on
 
140
 * End:
 
141
 * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et
 
142
 * vim<600: sw=4 ts=4
 
143
 * }}} */
 
144
?>
 
 
b'\\ No newline at end of file'