Branch data Line data Source code
1 : : ///////////////
2 : : ///////////////
3 : : /////////////// THIS FILE IS AUTOMATICALLY GENERATED BY gen-rdatacode.py.
4 : : /////////////// DO NOT EDIT!
5 : : ///////////////
6 : : ///////////////
7 : :
8 : : // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
9 : : //
10 : : // Permission to use, copy, modify, and/or distribute this software for any
11 : : // purpose with or without fee is hereby granted, provided that the above
12 : : // copyright notice and this permission notice appear in all copies.
13 : : //
14 : : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
15 : : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16 : : // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
17 : : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18 : : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
19 : : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 : : // PERFORMANCE OF THIS SOFTWARE.
21 : :
22 : : #ifndef __RRTYPE_H
23 : : #define __RRTYPE_H 1
24 : :
25 : : #include <stdint.h>
26 : :
27 : : #include <string>
28 : : #include <ostream>
29 : :
30 : : #include <exceptions/exceptions.h>
31 : :
32 : : // Solaris x86 defines DS in <sys/regset.h>, which gets pulled in by Boost
33 : : #if defined(__sun) && defined(DS)
34 : : # undef DS
35 : : #endif
36 : :
37 : : namespace isc {
38 : : namespace util {
39 : : class InputBuffer;
40 : : class OutputBuffer;
41 : : }
42 : :
43 : : namespace dns {
44 : :
45 : : // forward declarations
46 : : class AbstractMessageRenderer;
47 : :
48 : : ///
49 : : /// \brief A standard DNS module exception that is thrown if an RRType object
50 : : /// is being constructed from an unrecognized string.
51 : : ///
52 : 23 : class InvalidRRType : public Exception {
53 : : public:
54 : : InvalidRRType(const char* file, size_t line, const char* what) :
55 [ + - ]: 23 : isc::Exception(file, line, what) {}
56 : : };
57 : :
58 : : ///
59 : : /// \brief A standard DNS module exception that is thrown if an RRType object
60 : : /// is being constructed from a incomplete (too short) wire-format data.
61 : : ///
62 : 2 : class IncompleteRRType : public Exception {
63 : : public:
64 : : IncompleteRRType(const char* file, size_t line, const char* what) :
65 : 4 : isc::Exception(file, line, what) {}
66 : : };
67 : :
68 : : ///
69 : : /// The \c RRType class encapsulates DNS resource record types.
70 : : ///
71 : : /// This class manages the 16-bit integer type codes in quite a straightforward
72 : : /// way. The only non trivial task is to handle textual representations of
73 : : /// RR types, such as "A", "AAAA", or "TYPE65534".
74 : : ///
75 : : /// This class consults a helper \c RRParamRegistry class, which is a registry
76 : : /// of RR related parameters and has the singleton object. This registry
77 : : /// provides a mapping between RR type codes and their "well-known" textual
78 : : /// representations.
79 : : /// Parameters of RR types defined by DNS protocol standards are automatically
80 : : /// registered at initialization time and are ensured to be always available for
81 : : /// applications unless the application explicitly modifies the registry.
82 : : ///
83 : : /// For convenience, this class defines constant class objects corresponding to
84 : : /// standard RR types. These are generally referred to as the form of
85 : : /// <code>RRType::{type-text}()</code>.
86 : : /// For example, \c RRType::NS() is an \c RRType object corresponding to the NS
87 : : /// resource record (type code 2).
88 : : /// Note that these constants are used through a "proxy" function.
89 : : /// This is because they may be used to initialize another non-local (e.g.
90 : : /// global or namespace-scope) static object as follows:
91 : : ///
92 : : /// \code
93 : : /// namespace foo {
94 : : /// const RRType default_type = RRType::A();
95 : : /// } \endcode
96 : : ///
97 : : /// In order to ensure that the constant RRType object has been initialized
98 : : /// before the initialization for \c default_type, we need help from
99 : : /// the proxy function.
100 : : ///
101 : : /// In the current implementation, the initialization of the well-known
102 : : /// static objects is not thread safe. The same consideration as the
103 : : /// \c RRParamRegistry class applies. We may extend the implementation so
104 : : /// that the initialization is ensured to be thread safe in a future version.
105 : : ///
106 : : /// Note to developers: since it's expected that some of these constant
107 : : /// \c RRType objects are frequently used in a performance sensitive path,
108 : : /// we define these proxy functions as inline. This makes sense only when
109 : : /// the corresponding static objects are defined only once even if they used
110 : : /// in different source files. Sufficiently modern compilers should meet
111 : : /// this assumption, but if we encounter memory bloat due to this problem with
112 : : /// particular compilers we need to revisit the design or think about
113 : : /// workaround.
114 : 0 : class RRType {
115 : : public:
116 : : ///
117 : : /// \name Constructors and Destructor
118 : : ///
119 : : //@{
120 : : /// Constructor from an integer type code.
121 : : ///
122 : : /// This constructor never throws an exception.
123 : : ///
124 : : /// \param typecode An 16-bit integer code corresponding to the RRType.
125 : 3836 : explicit RRType(uint16_t typecode) : typecode_(typecode) {}
126 : : /// Constructor from a string.
127 : : ///
128 : : /// A valid string is one of "well-known" textual type representations
129 : : /// such as "A", "AAAA", or "NS", or in the standard format for "unknown"
130 : : /// RR types as defined in RFC3597, i.e., "TYPEnnnn".
131 : : ///
132 : : /// More precisely, the "well-known" representations are the ones stored
133 : : /// in the \c RRParamRegistry registry (see the class description).
134 : : ///
135 : : /// As for the format of "TYPEnnnn", "nnnn" must represent a valid 16-bit
136 : : /// unsigned integer, which may contain leading 0's as long as it consists
137 : : /// of at most 5 characters (inclusive).
138 : : /// For example, "TYPE1" and "TYPE001" are valid and represent the same
139 : : /// RR type, but "TYPE65536" and "TYPE000001" are invalid.
140 : : /// A "TYPEnnnn" representation is valid even if the corresponding type code
141 : : /// is registered in the \c RRParamRegistry object. For example, both
142 : : /// "A" and "TYPE1" are valid and represent the same RR type.
143 : : ///
144 : : /// All of these representations are case insensitive; "NS" and "ns", and
145 : : /// "TYPE1" and "type1" are all valid and represent the same RR types,
146 : : /// respectively.
147 : : ///
148 : : /// If the given string is not recognized as a valid representation of
149 : : /// an RR type, an exception of class \c InvalidRRType will be thrown.
150 : : ///
151 : : /// \param typestr A string representation of the \c RRType
152 : : explicit RRType(const std::string& typestr);
153 : : /// Constructor from wire-format data.
154 : : ///
155 : : /// The \c buffer parameter normally stores a complete DNS message
156 : : /// containing the RRType to be constructed. The current read position of
157 : : /// the buffer points to the head of the type.
158 : : ///
159 : : /// If the given data does not large enough to contain a 16-bit integer,
160 : : /// an exception of class \c IncompleteRRType will be thrown.
161 : : ///
162 : : /// \param buffer A buffer storing the wire format data.
163 : : explicit RRType(isc::util::InputBuffer& buffer);
164 : : ///
165 : : /// We use the default copy constructor intentionally.
166 : : //@}
167 : : /// We use the default copy assignment operator intentionally.
168 : : ///
169 : :
170 : : ///
171 : : /// \name Converter methods
172 : : ///
173 : : //@{
174 : : /// \brief Convert the \c RRType to a string.
175 : : ///
176 : : /// If a "well known" textual representation for the type code is registered
177 : : /// in the RR parameter registry (see the class description), that will be
178 : : /// used as the return value of this method. Otherwise, this method creates
179 : : /// a new string for an "unknown" RR type in the format defined in RFC3597,
180 : : /// i.e., "TYPEnnnn", and returns it.
181 : : ///
182 : : /// If resource allocation for the string fails, a corresponding standard
183 : : /// exception will be thrown.
184 : : ///
185 : : /// \return A string representation of the \c RRType.
186 : : const std::string toText() const;
187 : : /// \brief Render the \c RRType in the wire format.
188 : : ///
189 : : /// This method renders the type code in network byte order via \c renderer,
190 : : /// which encapsulates output buffer and other rendering contexts.
191 : : ///
192 : : /// If resource allocation in rendering process fails, a corresponding
193 : : /// standard exception will be thrown.
194 : : ///
195 : : /// \param buffer An output buffer to store the wire data.
196 : : void toWire(AbstractMessageRenderer& renderer) const;
197 : : /// \brief Render the \c RRType in the wire format.
198 : : ///
199 : : /// This method renders the type code in network byte order into the
200 : : /// \c buffer.
201 : : ///
202 : : /// If resource allocation in rendering process fails, a corresponding
203 : : /// standard exception will be thrown.
204 : : ///
205 : : /// \param renderer DNS message rendering context that encapsulates the
206 : : /// output buffer in which the RRType is to be stored.
207 : : void toWire(isc::util::OutputBuffer& buffer) const;
208 : : //@}
209 : :
210 : : ///
211 : : /// \name Getter Methods
212 : : ///
213 : : //@{
214 : : /// \brief Returns the RR type code as a 16-bit unsigned integer.
215 : : ///
216 : : /// This method never throws an exception.
217 : : ///
218 : : /// \return An 16-bit integer code corresponding to the RRType.
219 : 9068 : uint16_t getCode() const { return (typecode_); }
220 : : //@}
221 : :
222 : : ///
223 : : /// \name Comparison methods
224 : : ///
225 : : //@{
226 : : /// \brief Return true iff two RRTypes are equal.
227 : : ///
228 : : /// Two RRTypes are equal iff their type codes are equal.
229 : : ///
230 : : /// This method never throws an exception.
231 : : ///
232 : : /// \param other the \c RRType object to compare against.
233 : : /// \return true if the two RRTypes are equal; otherwise false.
234 : : bool equals(const RRType& other) const
235 : 56165 : { return (typecode_ == other.typecode_); }
236 : : /// \brief Same as \c equals().
237 : : bool operator==(const RRType& other) const { return (equals(other)); }
238 : :
239 : : /// \brief Return true iff two RRTypes are not equal.
240 : : ///
241 : : /// This method never throws an exception.
242 : : ///
243 : : /// \param other the \c RRType object to compare against.
244 : : /// \return true if the two RRTypes are not equal; otherwise false.
245 : : bool nequals(const RRType& other) const
246 : 31936 : { return (typecode_ != other.typecode_); }
247 : : /// \brief Same as \c nequals().
248 : : bool operator!=(const RRType& other) const { return (nequals(other)); }
249 : :
250 : : /// \brief Less-than comparison for RRType against \c other
251 : : ///
252 : : /// We define the less-than relationship based on their type codes;
253 : : /// one RRType is less than the other iff the code of the former is less
254 : : /// than that of the other as unsigned integers.
255 : : /// The relationship is meaningless in terms of DNS protocol; the only
256 : : /// reason we define this method is that RRType objects can be stored in
257 : : /// STL containers without requiring user-defined less-than relationship.
258 : : /// We therefore don't define other comparison operators.
259 : : ///
260 : : /// This method never throws an exception.
261 : : ///
262 : : /// \param other the \c RRType object to compare against.
263 : : /// \return true if \c this RRType is less than the \c other; otherwise
264 : : /// false.
265 : : bool operator<(const RRType& other) const
266 : 386427 : { return (typecode_ < other.typecode_); }
267 : : //@}
268 : :
269 : : // BEGIN_WELL_KNOWN_TYPE_DECLARATIONS
270 : : static const RRType& DLV();
271 : : static const RRType& TSIG();
272 : : static const RRType& DNSKEY();
273 : : static const RRType& DHCID();
274 : : static const RRType& RRSIG();
275 : : static const RRType& NSEC();
276 : : static const RRType& SSHFP();
277 : : static const RRType& AAAA();
278 : : static const RRType& DS();
279 : : static const RRType& OPT();
280 : : static const RRType& A();
281 : : static const RRType& NS();
282 : : static const RRType& CNAME();
283 : : static const RRType& SOA();
284 : : static const RRType& HINFO();
285 : : static const RRType& SPF();
286 : : static const RRType& DNAME();
287 : : static const RRType& PTR();
288 : : static const RRType& MX();
289 : : static const RRType& MINFO();
290 : : static const RRType& RP();
291 : : static const RRType& TXT();
292 : : static const RRType& SRV();
293 : : static const RRType& AFSDB();
294 : : static const RRType& NSEC3PARAM();
295 : : static const RRType& NSEC3();
296 : : static const RRType& NAPTR();
297 : : // END_WELL_KNOWN_TYPE_DECLARATIONS
298 : :
299 : : static const RRType& IXFR();
300 : : static const RRType& AXFR();
301 : : static const RRType& ANY();
302 : :
303 : : private:
304 : : // \brief Meta-classes
305 : : // XXX: these should be implemented using rrparamregistry
306 : : enum {
307 : : RRTYPE_IXFR = 251,
308 : : RRTYPE_AXFR = 252,
309 : : RRTYPE_ANY = 255
310 : : };
311 : :
312 : : uint16_t typecode_;
313 : : };
314 : :
315 : : // BEGIN_WELL_KNOWN_TYPE_DEFINITIONS
316 : :
317 : : inline const RRType&
318 : : RRType::DLV() {
319 [ + - ][ + - ]: 1 : static RRType rrtype(32769);
320 : : return (rrtype);
321 : : }
322 : :
323 : : inline const RRType&
324 : 197 : RRType::TSIG() {
325 [ + + ][ + - ]: 1077 : static RRType rrtype(250);
326 : 197 : return (rrtype);
327 : : }
328 : :
329 : : inline const RRType&
330 : 13 : RRType::DNSKEY() {
331 [ + + ][ + - ]: 17 : static RRType rrtype(48);
[ - + ][ # # ]
332 : 13 : return (rrtype);
333 : : }
334 : :
335 : : inline const RRType&
336 : : RRType::DHCID() {
337 : : static RRType rrtype(49);
338 : : return (rrtype);
339 : : }
340 : :
341 : : inline const RRType&
342 : 25319 : RRType::RRSIG() {
343 [ + + ][ + - ]: 25723 : static RRType rrtype(46);
344 : 25319 : return (rrtype);
345 : : }
346 : :
347 : : inline const RRType&
348 : 5797 : RRType::NSEC() {
349 [ + + ][ + - ]: 6020 : static RRType rrtype(47);
350 : 5797 : return (rrtype);
351 : : }
352 : :
353 : : inline const RRType&
354 : : RRType::SSHFP() {
355 : : static RRType rrtype(44);
356 : : return (rrtype);
357 : : }
358 : :
359 : : inline const RRType&
360 : 601 : RRType::AAAA() {
361 [ + + ][ + - ]: 791 : static RRType rrtype(28);
[ # # ][ # # ]
[ + + ][ + - ]
362 : 601 : return (rrtype);
363 : : }
364 : :
365 : : inline const RRType&
366 : 525 : RRType::DS() {
367 [ + + ][ + - ]: 6047 : static RRType rrtype(43);
[ + - ][ + - ]
368 : 525 : return (rrtype);
369 : : }
370 : :
371 : : inline const RRType&
372 : 219 : RRType::OPT() {
373 [ + + ]: 1150 : static RRType rrtype(41);
[ + - + + ]
[ + - ]
374 : 219 : return (rrtype);
375 : : }
376 : :
377 : : inline const RRType&
378 : 1587 : RRType::A() {
379 [ + + ][ + - ]: 2065 : static RRType rrtype(1);
[ # # ][ # # ]
[ + + ][ + - ]
380 : 1587 : return (rrtype);
381 : : }
382 : :
383 : : inline const RRType&
384 : 22296 : RRType::NS() {
385 [ + + ][ + - ]: 22883 : static RRType rrtype(2);
[ - + ][ # # ]
386 : 22296 : return (rrtype);
387 : : }
388 : :
389 : : inline const RRType&
390 : 12830 : RRType::CNAME() {
391 [ + + ][ + - ]: 12864 : static RRType rrtype(5);
[ + + ][ + - ]
392 : 12830 : return (rrtype);
393 : : }
394 : :
395 : : inline const RRType&
396 : 5490 : RRType::SOA() {
397 [ + + ]: 17846 : static RRType rrtype(6);
[ + - + + ]
[ + - ]
398 : 5490 : return (rrtype);
399 : : }
400 : :
401 : : inline const RRType&
402 : : RRType::HINFO() {
403 : : static RRType rrtype(13);
404 : : return (rrtype);
405 : : }
406 : :
407 : : inline const RRType&
408 : : RRType::SPF() {
409 [ + + ][ + - ]: 5 : static RRType rrtype(99);
410 : : return (rrtype);
411 : : }
412 : :
413 : : inline const RRType&
414 : 5505 : RRType::DNAME() {
415 [ + + ][ + - ]: 5507 : static RRType rrtype(39);
416 : 5505 : return (rrtype);
417 : : }
418 : :
419 : : inline const RRType&
420 : : RRType::PTR() {
421 [ + - ][ + - ]: 2 : static RRType rrtype(12);
422 : : return (rrtype);
423 : : }
424 : :
425 : : inline const RRType&
426 : 863 : RRType::MX() {
427 [ + + ][ + - ]: 950 : static RRType rrtype(15);
[ - + ][ # # ]
428 : 863 : return (rrtype);
429 : : }
430 : :
431 : : inline const RRType&
432 : 6 : RRType::MINFO() {
433 [ + + ][ + - ]: 6 : static RRType rrtype(14);
434 : 6 : return (rrtype);
435 : : }
436 : :
437 : : inline const RRType&
438 : 6 : RRType::RP() {
439 [ + + ][ + - ]: 6 : static RRType rrtype(17);
440 : 6 : return (rrtype);
441 : : }
442 : :
443 : : inline const RRType&
444 : 627 : RRType::TXT() {
445 [ + + ][ + - ]: 673 : static RRType rrtype(16);
[ - + ][ # # ]
446 : 627 : return (rrtype);
447 : : }
448 : :
449 : : inline const RRType&
450 : : RRType::SRV() {
451 : : static RRType rrtype(33);
452 : : return (rrtype);
453 : : }
454 : :
455 : : inline const RRType&
456 : 5 : RRType::AFSDB() {
457 [ + + ][ + - ]: 5 : static RRType rrtype(18);
458 : 5 : return (rrtype);
459 : : }
460 : :
461 : : inline const RRType&
462 : 2735 : RRType::NSEC3PARAM() {
463 [ + + ][ + - ]: 2756 : static RRType rrtype(51);
[ - + ][ # # ]
464 : 2735 : return (rrtype);
465 : : }
466 : :
467 : : inline const RRType&
468 : 15427 : RRType::NSEC3() {
469 [ + + ][ + - ]: 15447 : static RRType rrtype(50);
470 : 15427 : return (rrtype);
471 : : }
472 : :
473 : : inline const RRType&
474 : : RRType::NAPTR() {
475 : : static RRType rrtype(35);
476 : : return (rrtype);
477 : : }
478 : :
479 : : // END_WELL_KNOWN_TYPE_DEFINITIONS
480 : :
481 : : inline const RRType&
482 : 5 : RRType::IXFR() {
483 [ + + ][ + - ]: 401 : static RRType rrtype(RRTYPE_IXFR);
484 : 5 : return (rrtype);
485 : : }
486 : :
487 : : inline const RRType&
488 : 11 : RRType::AXFR() {
489 [ + + ][ + - ]: 325 : static RRType rrtype(RRTYPE_AXFR);
[ + + ][ + - ]
490 : 11 : return (rrtype);
491 : : }
492 : :
493 : : inline const RRType&
494 : 2940 : RRType::ANY() {
495 [ + + ][ + - ]: 3375 : static RRType rrtype(RRTYPE_ANY);
[ + + ][ + - ]
496 : 2940 : return (rrtype);
497 : : }
498 : :
499 : : ///
500 : : /// \brief Insert the \c RRType as a string into stream.
501 : : ///
502 : : /// This method convert the \c rrtype into a string and inserts it into the
503 : : /// output stream \c os.
504 : : ///
505 : : /// This function overloads the global operator<< to behave as described in
506 : : /// ostream::operator<< but applied to \c RRType objects.
507 : : ///
508 : : /// \param os A \c std::ostream object on which the insertion operation is
509 : : /// performed.
510 : : /// \param rrtype The \c RRType object output by the operation.
511 : : /// \return A reference to the same \c std::ostream object referenced by
512 : : /// parameter \c os after the insertion operation.
513 : : std::ostream&
514 : : operator<<(std::ostream& os, const RRType& rrtype);
515 : : }
516 : : }
517 : : #endif // __RRTYPE_H
518 : :
519 : : // Local Variables:
520 : : // mode: c++
521 : : // End:
|