1212
1313public final class Rcode {
1414
15- private static StringValueTable rcodes = new StringValueTable ();
16- private static StringValueTable tsigrcodes = new StringValueTable ();
15+ private static Mnemonic rcodes = new Mnemonic ("DNS Rcode" ,
16+ Mnemonic .CASE_UPPER );
17+
18+ private static Mnemonic tsigrcodes = new Mnemonic ("TSIG rcode" ,
19+ Mnemonic .CASE_UPPER );
1720
1821/** No error */
19- public static final byte NOERROR = 0 ;
22+ public static final int NOERROR = 0 ;
2023
2124/** Format error */
22- public static final byte FORMERR = 1 ;
25+ public static final int FORMERR = 1 ;
2326
2427/** Server failure */
25- public static final byte SERVFAIL = 2 ;
28+ public static final int SERVFAIL = 2 ;
2629
2730/** The name does not exist */
28- public static final byte NXDOMAIN = 3 ;
31+ public static final int NXDOMAIN = 3 ;
2932
3033/** The operation requested is not implemented */
31- public static final byte NOTIMPL = 4 ;
34+ public static final int NOTIMPL = 4 ;
3235
3336/** The operation was refused by the server */
34- public static final byte REFUSED = 5 ;
37+ public static final int REFUSED = 5 ;
3538
3639/** The name exists */
37- public static final byte YXDOMAIN = 6 ;
40+ public static final int YXDOMAIN = 6 ;
3841
3942/** The RRset (name, type) exists */
40- public static final byte YXRRSET = 7 ;
43+ public static final int YXRRSET = 7 ;
4144
4245/** The RRset (name, type) does not exist */
43- public static final byte NXRRSET = 8 ;
46+ public static final int NXRRSET = 8 ;
4447
4548/** The requestor is not authorized to perform this operation */
46- public static final byte NOTAUTH = 9 ;
49+ public static final int NOTAUTH = 9 ;
4750
4851/** The zone specified is not a zone */
49- public static final byte NOTZONE = 10 ;
52+ public static final int NOTZONE = 10 ;
5053
5154/* EDNS extended rcodes */
5255/** Unsupported EDNS level */
53- public static final byte BADVERS = 16 ;
56+ public static final int BADVERS = 16 ;
5457
5558/* TSIG/TKEY only rcodes */
5659/** The signature is invalid (TSIG/TKEY extended error) */
57- public static final byte BADSIG = 16 ;
60+ public static final int BADSIG = 16 ;
5861
5962/** The key is invalid (TSIG/TKEY extended error) */
60- public static final byte BADKEY = 17 ;
63+ public static final int BADKEY = 17 ;
6164
6265/** The time is out of range (TSIG/TKEY extended error) */
63- public static final byte BADTIME = 18 ;
66+ public static final int BADTIME = 18 ;
6467
6568/** The mode is invalid (TKEY extended error) */
66- public static final byte BADMODE = 19 ;
69+ public static final int BADMODE = 19 ;
6770
6871static {
69- rcodes .put2 (NOERROR , "NOERROR" );
70- rcodes .put2 (FORMERR , "FORMERR" );
71- rcodes .put2 (SERVFAIL , "SERVFAIL" );
72- rcodes .put2 (NXDOMAIN , "NXDOMAIN" );
73- rcodes .put2 (NOTIMPL , "NOTIMPL" );
74- rcodes .put2 (REFUSED , "REFUSED" );
75- rcodes .put2 (YXDOMAIN , "YXDOMAIN" );
76- rcodes .put2 (YXRRSET , "YXRRSET" );
77- rcodes .put2 (NXRRSET , "NXRRSET" );
78- rcodes .put2 (NOTAUTH , "NOTAUTH" );
79- rcodes .put2 (NOTZONE , "NOTZONE" );
80- rcodes .put2 (BADVERS , "BADVERS" );
81-
82- tsigrcodes .put2 (BADSIG , "BADSIG" );
83- tsigrcodes .put2 (BADKEY , "BADKEY" );
84- tsigrcodes .put2 (BADTIME , "BADTIME" );
85- tsigrcodes .put2 (BADMODE , "BADMODE" );
72+ rcodes .setMaximum (0xFFF );
73+ rcodes .setPrefix ("RESERVED" );
74+
75+ rcodes .add (NOERROR , "NOERROR" );
76+ rcodes .add (FORMERR , "FORMERR" );
77+ rcodes .add (SERVFAIL , "SERVFAIL" );
78+ rcodes .add (NXDOMAIN , "NXDOMAIN" );
79+ rcodes .add (NOTIMPL , "NOTIMPL" );
80+ rcodes .add (REFUSED , "REFUSED" );
81+ rcodes .add (YXDOMAIN , "YXDOMAIN" );
82+ rcodes .add (YXRRSET , "YXRRSET" );
83+ rcodes .add (NXRRSET , "NXRRSET" );
84+ rcodes .add (NOTAUTH , "NOTAUTH" );
85+ rcodes .add (NOTZONE , "NOTZONE" );
86+ rcodes .add (BADVERS , "BADVERS" );
87+
88+ tsigrcodes .setMaximum (0xFFFF );
89+ tsigrcodes .setPrefix ("RESERVED" );
90+ tsigrcodes .addAll (rcodes );
91+
92+ tsigrcodes .add (BADSIG , "BADSIG" );
93+ tsigrcodes .add (BADKEY , "BADKEY" );
94+ tsigrcodes .add (BADTIME , "BADTIME" );
95+ tsigrcodes .add (BADMODE , "BADMODE" );
8696}
8797
8898private
@@ -91,32 +101,19 @@ public final class Rcode {
91101/** Converts a numeric Rcode into a String */
92102public static String
93103string (int i ) {
94- String s = rcodes .getString (i );
95- return (s != null ) ? s : Integer .toString (i );
104+ return rcodes .getText (i );
96105}
97106
98107/** Converts a numeric TSIG extended Rcode into a String */
99108public static String
100109TSIGstring (int i ) {
101- String s = tsigrcodes .getString (i );
102- if (s != null )
103- return s ;
104- s = rcodes .getString (i );
105- return (s != null ) ? s : Integer .toString (i );
110+ return tsigrcodes .getText (i );
106111}
107112
108113/** Converts a String representation of an Rcode into its numeric value */
109- public static byte
114+ public static int
110115value (String s ) {
111- byte i = (byte ) rcodes .getValue (s .toUpperCase ());
112- if (i >= 0 )
113- return i ;
114- try {
115- return Byte .parseByte (s );
116- }
117- catch (Exception e ) {
118- return (-1 );
119- }
116+ return rcodes .getValue (s );
120117}
121118
122119}
0 commit comments