~ubuntu-branches/ubuntu/trusty/zonecheck/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/nresolv/constants.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephane Bortzmeyer
  • Date: 2004-03-10 14:08:05 UTC
  • Revision ID: james.westby@ubuntu.com-20040310140805-ij55fso1e23bk8ye
Tags: upstream-2.0.3
ImportĀ upstreamĀ versionĀ 2.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# $Id: constants.rb,v 1.16 2003/10/16 14:24:21 sdalu Exp $
 
2
 
 
3
 
4
# AUTHOR   : Stephane D'Alu <sdalu@nic.fr>
 
5
# CREATED  : 2002/08/02 13:58:17
 
6
#
 
7
# COPYRIGHT: AFNIC (c) 2003
 
8
# CONTACT  : 
 
9
# LICENSE  : RUBY
 
10
#
 
11
# $Revision: 1.16 $ 
 
12
# $Date: 2003/10/16 14:24:21 $
 
13
#
 
14
# CONTRIBUTORS: (see also CREDITS file)
 
15
#
 
16
#
 
17
 
 
18
 
 
19
##
 
20
## See RFC 2929
 
21
##
 
22
##
 
23
class NResolv
 
24
 
 
25
    ##
 
26
    ## Objects of this class are imutable
 
27
    ##
 
28
    class ValueHolder
 
29
        attr_reader :name, :value
 
30
 
 
31
        @@maxlen        = {}
 
32
        @@hash_by_name  = {}
 
33
        @@hash_by_value = {}
 
34
 
 
35
        def initialize(name, value)
 
36
            # Sanity check
 
37
            if ! name.instance_of?(String)
 
38
                raise ArgumentError, "name should be of type #{String}"
 
39
            end
 
40
 
 
41
            # Define attributes
 
42
            @name  = name.frozen? ? name : name.dup.freeze
 
43
            @value = value
 
44
 
 
45
            # Store itself in class attribute hashes
 
46
            #  so it can easily be retrieved
 
47
            klass = self.class
 
48
 
 
49
            @@hash_by_name [klass] = {} unless @@hash_by_name [klass]
 
50
            @@hash_by_value[klass] = {} unless @@hash_by_value[klass]
 
51
            @@maxlen[klass]        =  0 unless @@maxlen[klass] 
 
52
 
 
53
            @@hash_by_name [klass][name ] = self
 
54
            @@hash_by_value[klass][value] = self
 
55
            @@maxlen[klass] = @name.length if @@maxlen[klass] < @name.length
 
56
        end
 
57
 
 
58
        #
 
59
        def to_s        ; @name                                 ; end
 
60
        def hash        ; self.value.hash                       ; end
 
61
        def eql?(other) ; (self.class == other.class) && 
 
62
                            (self.value == other.value)         ; end
 
63
        alias == eql?
 
64
 
 
65
        # Fetch a constant by name
 
66
        def self.fetch_by_name(name)
 
67
            begin
 
68
                @@hash_by_name[self].fetch(name)
 
69
            rescue IndexError
 
70
                raise IndexError, "name '#{name}' not found in #{self}"
 
71
            end
 
72
        end
 
73
        
 
74
        # Fetch a constant by value
 
75
        def self.fetch_by_value(value)
 
76
            begin
 
77
                @@hash_by_value[self].fetch(value)
 
78
            rescue IndexError
 
79
                raise IndexError, "value '#{value}' not found in #{self}"
 
80
            end
 
81
        end
 
82
        
 
83
        #
 
84
        def self.maxlen        ; @@maxlen[self]      ; end
 
85
        def self.filler(token) ; token * self.maxlen ; end
 
86
    end
 
87
 
 
88
 
 
89
    
 
90
    class DNS
 
91
        ##
 
92
        ## Op. code
 
93
        ##
 
94
        class OpCode < ValueHolder
 
95
            QUERY       = OpCode::new('Query' ,       0)        # RFC 1035
 
96
            IQUERY      = OpCode::new('IQuery',       1)        # RFC 1035
 
97
            STATUS      = OpCode::new('Status',       2)        # RFC 1035
 
98
            NOTIFY      = OpCode::new('Notidy',       4)        # RFC 1996
 
99
            UPDATE      = OpCode::new('Update',       5)        # RFC 2136
 
100
        end
 
101
 
 
102
 
 
103
        ##
 
104
        ## Return code
 
105
        ##
 
106
        class RCode < ValueHolder
 
107
            NOERROR     = RCode::new('NoError',       0)        # RFC 1035
 
108
            FORMERR     = RCode::new('FormErr',       1)        # RFC 1035
 
109
            SERVFAIL    = RCode::new('ServFail',      2)        # RFC 1035
 
110
            NXDOMAIN    = RCode::new('NXDomain',      3)        # RFC 1035
 
111
            NOTIMP      = RCode::new('NotImp',        4)        # RFC 1035
 
112
            REFUSED     = RCode::new('Refused',       5)        # RFC 1035
 
113
            YXDOMAIN    = RCode::new('YXDomain',      6)        # RFC 2136
 
114
            YXRRSET     = RCode::new('YXRRSet',       7)        # RFC 2136
 
115
            NXRRSET     = RCode::new('NXRRSet',       8)        # RFC 2136
 
116
            NOTAUTH     = RCode::new('NotAuth',       9)        # RFC 2136
 
117
            NOTZONE     = RCode::new('NotZone',      10)        # RFC 2136
 
118
            RESERVED15  = RCode::new('<reserved15>', 15)
 
119
#           BADVERS     = RCode::new('BADVERS',      16)        # RFC 2671
 
120
            BADSIG      = RCode::new('BADSIG',       16)        # RFC 2845
 
121
            BADKEY      = RCode::new('BADKEY',       17)        # RFC 2845
 
122
            BADTIME     = RCode::new('BADTIME',      18)        # RFC 2845
 
123
            BADMODE     = RCode::new('BADMODE',      19)        # RFC 2930
 
124
            BADNAME     = RCode::new('BADNAME',      20)        # RFC 2930
 
125
            BADALG      = RCode::new('BADALG',       21)        # RFC 2930
 
126
        end
 
127
 
 
128
 
 
129
        ##
 
130
        ## Resource class
 
131
        ##
 
132
        class RClass < ValueHolder
 
133
            IN          = RClass::new('IN',           1)
 
134
            CHAOS       = RClass::new('CH',           3)        # Moon 1981
 
135
            HS          = RClass::new('HS',           4)        # Dyer 1987
 
136
            NONE        = RClass::new('NONE',       254)        # RFC 2136
 
137
            ANY         = RClass::new('ANY',        255)        # RFC 1035
 
138
        end
 
139
        
 
140
 
 
141
        ##
 
142
        ## Resource type
 
143
        ##
 
144
        class RType < ValueHolder
 
145
            NONE        = RType::new('NONE',          0)
 
146
            A           = RType::new('A',             1)
 
147
            NS          = RType::new('NS',            2)
 
148
            MD          = RType::new('MD',            3)
 
149
            MF          = RType::new('MF',            4)
 
150
            CNAME       = RType::new('CNAME',         5)
 
151
            SOA         = RType::new('SOA',           6)
 
152
            MB          = RType::new('MB',            7)
 
153
            MG          = RType::new('MG',            8)
 
154
            MR          = RType::new('MR',            9)
 
155
            NULL        = RType::new('NULL',         10)
 
156
            WKS         = RType::new('WKS',          11)
 
157
            PTR         = RType::new('PTR',          12)
 
158
            HINFO       = RType::new('HINFO',        13)
 
159
            MINFO       = RType::new('MINFO',        14)
 
160
            MX          = RType::new('MX',           15)
 
161
            TXT         = RType::new('TXT',          16)
 
162
            RP          = RType::new('RP',           17)
 
163
            AFSDB       = RType::new('AFSDB',        18)
 
164
            X25         = RType::new('X25',          19)
 
165
            ISDN        = RType::new('ISDN',         20)
 
166
            RT          = RType::new('RT',           21)
 
167
            NSAP        = RType::new('NSAP',         22)
 
168
            NSAP_PTR    = RType::new('NSAP_PTR',     23)
 
169
            SIG         = RType::new('SIG',          24)
 
170
            KEY         = RType::new('KEY',          25)
 
171
            PX          = RType::new('PX',           26)
 
172
            GPOS        = RType::new('GPOS',         27)
 
173
            AAAA        = RType::new('AAAA',         28)
 
174
            LOC         = RType::new('LOC',          29)
 
175
            NXT         = RType::new('NXT',          30)
 
176
            SRV         = RType::new('SRV',          33)
 
177
            NAPTR       = RType::new('NAPTR',        35)
 
178
            KX          = RType::new('KX',           36)
 
179
            CERT        = RType::new('CERT',         37)
 
180
            A6          = RType::new('A6',           38)
 
181
            DNAME       = RType::new('DNAME',        39)
 
182
            OPT         = RType::new('OPT',          41)
 
183
            UNSPEC      = RType::new('UNSPEC',      103)
 
184
            TKEY        = RType::new('TKEY',        249)
 
185
            TSIG        = RType::new('TSIG',        250)
 
186
            IXFR        = RType::new('IXFR',        251)
 
187
            AXFR        = RType::new('AXFR',        252)
 
188
            MAILB       = RType::new('MAILB',       253)
 
189
            MAILA       = RType::new('MAILA',       254)
 
190
            ANY         = RType::new('ANY',         255)
 
191
        end
 
192
    end
 
193
end