View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  
21  package org.apache.directory.server.dns.messages;
22  
23  
24  import java.util.List;
25  
26  import org.apache.commons.lang.builder.EqualsBuilder;
27  import org.apache.commons.lang.builder.HashCodeBuilder;
28  import org.apache.commons.lang.builder.ToStringBuilder;
29  
30  
31  /**
32   * All communications inside of the domain protocol are carried in a single
33   * format called a message.  The top level format of message is divided
34   * into 5 sections (some of which are empty in certain cases) shown below:
35   *
36   *     +---------------------+
37   *     |        Header       |
38   *     +---------------------+
39   *     |       Question      | the question for the name server
40   *     +---------------------+
41   *     |        Answer       | ResourceRecords answering the question
42   *     +---------------------+
43   *     |      Authority      | ResourceRecords pointing toward an authority
44   *     +---------------------+
45   *     |      Additional     | ResourceRecords holding additional information
46   *     +---------------------+
47   * 
48   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
49   * @version $Rev: 664295 $, $Date: 2008-06-07 09:48:16 +0200 (Sa, 07 Jun 2008) $
50   */
51  public class DnsMessage
52  {
53      /**
54       * The header section is always present.  The header includes fields that
55       * specify which of the remaining sections are present, and also specify
56       * whether the message is a query or a response, a standard query or some
57       * other opcode, etc.
58       */
59      private int transactionId;
60      private MessageType messageType;
61      private OpCode opCode;
62      private boolean authoritativeAnswer;
63      private boolean truncated;
64      private boolean recursionDesired;
65      private boolean recursionAvailable;
66      private boolean reserved;
67      private boolean acceptNonAuthenticatedData;
68  
69      private ResponseCode responseCode;
70  
71      private List<QuestionRecord> questionRecords;
72      private List<ResourceRecord> answerRecords;
73      private List<ResourceRecord> authorityRecords;
74      private List<ResourceRecord> additionalRecords;
75  
76  
77      /**
78       * Creates a new instance of DnsMessage.
79       *
80       * @param transactionId
81       * @param messageType
82       * @param opCode
83       * @param authoritativeAnswer
84       * @param truncated
85       * @param recursionDesired
86       * @param recursionAvailable
87       * @param reserved
88       * @param acceptNonAuthenticatedData
89       * @param responseCode
90       * @param question
91       * @param answer
92       * @param authority
93       * @param additional
94       */
95      public DnsMessage( int transactionId, MessageType messageType, OpCode opCode, boolean authoritativeAnswer,
96          boolean truncated, boolean recursionDesired, boolean recursionAvailable, boolean reserved,
97          boolean acceptNonAuthenticatedData, ResponseCode responseCode, List<QuestionRecord> question,
98          List<ResourceRecord> answer, List<ResourceRecord> authority, List<ResourceRecord> additional )
99      {
100         this.transactionId = transactionId;
101         this.messageType = messageType;
102         this.opCode = opCode;
103         this.authoritativeAnswer = authoritativeAnswer;
104         this.truncated = truncated;
105         this.recursionDesired = recursionDesired;
106         this.recursionAvailable = recursionAvailable;
107         this.reserved = reserved;
108         this.acceptNonAuthenticatedData = acceptNonAuthenticatedData;
109         this.responseCode = responseCode;
110         this.questionRecords = question;
111         this.answerRecords = answer;
112         this.authorityRecords = authority;
113         this.additionalRecords = additional;
114     }
115 
116 
117     /**
118      * @return Returns the acceptNonAuthenticatedData.
119      */
120     public boolean isAcceptNonAuthenticatedData()
121     {
122         return acceptNonAuthenticatedData;
123     }
124 
125 
126     /**
127      * @return Returns the additional.
128      */
129     public List<ResourceRecord> getAdditionalRecords()
130     {
131         return additionalRecords;
132     }
133 
134 
135     /**
136      * @return Returns the answers.
137      */
138     public List<ResourceRecord> getAnswerRecords()
139     {
140         return answerRecords;
141     }
142 
143 
144     /**
145      * @return Returns the authoritativeAnswer.
146      */
147     public boolean isAuthoritativeAnswer()
148     {
149         return authoritativeAnswer;
150     }
151 
152 
153     /**
154      * @return Returns the authority.
155      */
156     public List<ResourceRecord> getAuthorityRecords()
157     {
158         return authorityRecords;
159     }
160 
161 
162     /**
163      * @return Returns the messageType.
164      */
165     public MessageType getMessageType()
166     {
167         return messageType;
168     }
169 
170 
171     /**
172      * @return Returns the opCode.
173      */
174     public OpCode getOpCode()
175     {
176         return opCode;
177     }
178 
179 
180     /**
181      * @return Returns the question.
182      */
183     public List<QuestionRecord> getQuestionRecords()
184     {
185         return questionRecords;
186     }
187 
188 
189     /**
190      * @return Returns the recursionAvailable.
191      */
192     public boolean isRecursionAvailable()
193     {
194         return recursionAvailable;
195     }
196 
197 
198     /**
199      * @return Returns the recursionDesired.
200      */
201     public boolean isRecursionDesired()
202     {
203         return recursionDesired;
204     }
205 
206 
207     /**
208      * @return Returns the reserved.
209      */
210     public boolean isReserved()
211     {
212         return reserved;
213     }
214 
215 
216     /**
217      * @return Returns the responseCode.
218      */
219     public ResponseCode getResponseCode()
220     {
221         return responseCode;
222     }
223 
224 
225     /**
226      * @return Returns the transactionId.
227      */
228     public int getTransactionId()
229     {
230         return transactionId;
231     }
232 
233 
234     /**
235      * @return Returns the truncated.
236      */
237     public boolean isTruncated()
238     {
239         return truncated;
240     }
241 
242 
243     /**
244      * @see java.lang.Object#equals(Object)
245      */
246     public boolean equals( Object object )
247     {
248         if ( object == this )
249         {
250             return true;
251         }
252         if ( !( object instanceof DnsMessage ) )
253         {
254             return false;
255         }
256         DnsMessage rhs = ( DnsMessage ) object;
257         return new EqualsBuilder().append( this.transactionId, rhs.transactionId ).append( this.answerRecords,
258             rhs.answerRecords ).append( this.opCode, rhs.opCode ).append( this.recursionAvailable,
259             rhs.recursionAvailable ).append( this.messageType, rhs.messageType ).append( this.additionalRecords,
260             rhs.additionalRecords ).append( this.truncated, rhs.truncated ).append( this.recursionDesired,
261             rhs.recursionDesired ).append( this.responseCode, rhs.responseCode ).append( this.authorityRecords,
262             rhs.authorityRecords ).append( this.authoritativeAnswer, rhs.authoritativeAnswer ).append( this.reserved,
263             rhs.reserved ).append( this.acceptNonAuthenticatedData, rhs.acceptNonAuthenticatedData ).append(
264             this.questionRecords, rhs.questionRecords ).isEquals();
265     }
266 
267 
268     /**
269      * @see java.lang.Object#hashCode()
270      * @return the instance's hash code 
271      */
272     public int hashCode()
273     {
274         return new HashCodeBuilder( -1805208585, -276770303 ).append( this.transactionId ).append( this.answerRecords )
275             .append( this.opCode ).append( this.recursionAvailable ).append( this.messageType ).append(
276                 this.additionalRecords ).append( this.truncated ).append( this.recursionDesired ).append(
277                 this.responseCode ).append( this.authorityRecords ).append( this.authoritativeAnswer ).append(
278                 this.reserved ).append( this.acceptNonAuthenticatedData ).append( this.questionRecords ).toHashCode();
279     }
280 
281 
282     /**
283      * @see java.lang.Object#toString()
284      */
285     public String toString()
286     {
287         return new ToStringBuilder( this ).appendSuper( super.toString() ).append( "transactionId", this.transactionId )
288             .append( "opCode", this.opCode ).append( "truncated", this.truncated ).append( "messageType",
289                 this.messageType ).append( "recursionDesired", this.recursionDesired ).append( "additionalRecords",
290                 this.additionalRecords ).append( "responseCode", this.responseCode ).append( "authorityRecords",
291                 this.authorityRecords ).append( "acceptNonAuthenticatedData", this.acceptNonAuthenticatedData ).append(
292                 "recursionAvailable", this.recursionAvailable ).append( "answerRecords", this.answerRecords ).append(
293                 "questionRecords", this.questionRecords ).append( "authoritativeAnswer", this.authoritativeAnswer )
294             .append( "reserved", this.reserved ).toString();
295     }
296 }