~ubuntu-branches/ubuntu/utopic/php-net-dns2/utopic-proposed

« back to all changes in this revision

Viewing changes to Net_DNS2-1.3.2/Net/DNS2/RR/CAA.php

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2014-02-21 16:59:58 UTC
  • Revision ID: package-import@ubuntu.com-20140221165958-tyc92gchfhho9660
Tags: upstream-1.3.2
ImportĀ upstreamĀ versionĀ 1.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
 
3
 
 
4
/**
 
5
 * DNS Library for handling lookups and updates.
 
6
 *
 
7
 * PHP Version 5
 
8
 *
 
9
 * Copyright (c) 2011, Mike Pultz <mike@mikepultz.com>.
 
10
 * All rights reserved.
 
11
 *
 
12
 * Redistribution and use in source and binary forms, with or without
 
13
 * modification, are permitted provided that the following conditions
 
14
 * are met:
 
15
 *
 
16
 *   * Redistributions of source code must retain the above copyright
 
17
 *     notice, this list of conditions and the following disclaimer.
 
18
 *
 
19
 *   * Redistributions in binary form must reproduce the above copyright
 
20
 *     notice, this list of conditions and the following disclaimer in
 
21
 *     the documentation and/or other materials provided with the
 
22
 *     distribution.
 
23
 *
 
24
 *   * Neither the name of Mike Pultz nor the names of his contributors
 
25
 *     may be used to endorse or promote products derived from this
 
26
 *     software without specific prior written permission.
 
27
 *
 
28
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
29
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
30
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 
31
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 
32
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 
33
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
34
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
35
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
36
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
 
37
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 
38
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
39
 * POSSIBILITY OF SUCH DAMAGE.
 
40
 *
 
41
 * @category  Networking
 
42
 * @package   Net_DNS2
 
43
 * @author    Mike Pultz <mike@mikepultz.com>
 
44
 * @copyright 2011 Mike Pultz <mike@mikepultz.com>
 
45
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
 
46
 * @version   SVN: $Id: CAA.php 179 2012-11-23 05:49:01Z mike.pultz $
 
47
 * @link      http://pear.php.net/package/Net_DNS2
 
48
 * @since     File available since Release 1.2.0
 
49
 *
 
50
 */
 
51
 
 
52
/**
 
53
 * CAA Resource Record - http://tools.ietf.org/html/draft-ietf-pkix-caa-03
 
54
 *
 
55
 *    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 
56
 *    |          FLAGS        |      TAG LENGTH       |
 
57
 *    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 
58
 *    /                      TAG                      /
 
59
 *    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 
60
 *    /                      DATA                     /
 
61
 *    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 
62
 *
 
63
 * @category Networking
 
64
 * @package  Net_DNS2
 
65
 * @author   Mike Pultz <mike@mikepultz.com>
 
66
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD License
 
67
 * @link     http://pear.php.net/package/Net_DNS2
 
68
 * @see      Net_DNS2_RR
 
69
 *
 
70
 */
 
71
class Net_DNS2_RR_CAA extends Net_DNS2_RR
 
72
{
 
73
    /*
 
74
     * The critcal flag
 
75
     */
 
76
    public $flags;
 
77
 
 
78
    /*
 
79
     * The property identifier
 
80
     */
 
81
    public $tag;
 
82
 
 
83
    /*
 
84
      * The property value
 
85
     */
 
86
    public $value;
 
87
 
 
88
    /**
 
89
     * method to return the rdata portion of the packet as a string
 
90
     *
 
91
     * @return  string
 
92
     * @access  protected
 
93
     *
 
94
     */
 
95
    protected function rrToString()
 
96
    {
 
97
        return $this->flags . ' ' . $this->tag . ' "' . 
 
98
            trim($this->cleanString($this->value), '"') . '"';
 
99
    }
 
100
 
 
101
    /**
 
102
     * parses the rdata portion from a standard DNS config line
 
103
     *
 
104
     * @param array $rdata a string split line of values for the rdata
 
105
     *
 
106
     * @return boolean
 
107
     * @access protected
 
108
     *
 
109
     */
 
110
    protected function rrFromString(array $rdata)
 
111
    {
 
112
        $this->flags    = array_shift($rdata);
 
113
        $this->tag      = array_shift($rdata);
 
114
 
 
115
        $this->value    = trim($this->cleanString(implode($rdata, ' ')), '"');
 
116
        
 
117
        return true;
 
118
    }
 
119
 
 
120
    /**
 
121
     * parses the rdata of the Net_DNS2_Packet object
 
122
     *
 
123
     * @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
 
124
     *
 
125
     * @return boolean
 
126
     * @access protected
 
127
     *
 
128
     */
 
129
    protected function rrSet(Net_DNS2_Packet &$packet)
 
130
    {
 
131
        if ($this->rdlength > 0) {
 
132
            
 
133
            //
 
134
            // unpack the flags and tag length
 
135
            //
 
136
            $x = unpack('Cflags/Ctag_length', $this->rdata);
 
137
 
 
138
            $this->flags    = $x['flags'];
 
139
            $offset         = 2;
 
140
 
 
141
            $this->tag      = substr($this->rdata, $offset, $x['tag_length']);
 
142
            $offset         += $x['tag_length'];
 
143
 
 
144
            $this->value    = substr($this->rdata, $offset);
 
145
 
 
146
            return true;
 
147
        }
 
148
 
 
149
        return false;
 
150
    }
 
151
 
 
152
    /**
 
153
     * returns the rdata portion of the DNS packet
 
154
     *
 
155
     * @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
 
156
     *                                 compressed names
 
157
     *
 
158
     * @return mixed                   either returns a binary packed
 
159
     *                                 string or null on failure
 
160
     * @access protected
 
161
     *
 
162
     */
 
163
    protected function rrGet(Net_DNS2_Packet &$packet)
 
164
    {
 
165
        if (strlen($this->value) > 0) {
 
166
 
 
167
            $data  = chr($this->flags);
 
168
            $data .= chr(strlen($this->tag)) . $this->tag . $this->value;
 
169
 
 
170
            $packet->offset += strlen($data);
 
171
 
 
172
            return $data;
 
173
        }
 
174
 
 
175
        return null;
 
176
    }
 
177
}
 
178
 
 
179
?>