001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020
021package org.apache.directory.server.dns.messages;
022
023
024import java.util.List;
025
026
027/**
028 * All communications inside of the domain protocol are carried in a single
029 * format called a message.  The top level format of message is divided
030 * into 5 sections (some of which are empty in certain cases) shown below:
031 *
032 *     +---------------------+
033 *     |        Header       |
034 *     +---------------------+
035 *     |       Question      | the question for the name server
036 *     +---------------------+
037 *     |        Answer       | ResourceRecords answering the question
038 *     +---------------------+
039 *     |      Authority      | ResourceRecords pointing toward an authority
040 *     +---------------------+
041 *     |      Additional     | ResourceRecords holding additional information
042 *     +---------------------+
043 * 
044 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
045 */
046public class DnsMessageModifier
047{
048    /**
049     * The header section is always present.  The header includes fields that
050     * specify which of the remaining sections are present, and also specify
051     * whether the message is a query or a response, a standard query or some
052     * other opcode, etc.
053     */
054    private int transactionId;
055    private MessageType messageType;
056    private OpCode opCode;
057    private boolean authoritativeAnswer;
058    private boolean truncated;
059    private boolean recursionDesired;
060    private boolean recursionAvailable;
061    private boolean reserved;
062    private boolean acceptNonAuthenticatedData;
063
064    private ResponseCode responseCode;
065
066    private List<QuestionRecord> questionRecords;
067    private List<ResourceRecord> answerRecords;
068    private List<ResourceRecord> authorityRecords;
069    private List<ResourceRecord> additionalRecords;
070
071
072    /**
073     * Returns the {@link DnsMessage}.
074     *
075     * @return The {@link DnsMessage}.
076     */
077    public DnsMessage getDnsMessage()
078    {
079        return new DnsMessage( transactionId, messageType, opCode, authoritativeAnswer, truncated, recursionDesired,
080            recursionAvailable, reserved, acceptNonAuthenticatedData, responseCode, questionRecords, answerRecords,
081            authorityRecords, additionalRecords );
082    }
083
084
085    /**
086     * @param acceptNonAuthenticatedData The acceptNonAuthenticatedData to set.
087     */
088    public void setAcceptNonAuthenticatedData( boolean acceptNonAuthenticatedData )
089    {
090        this.acceptNonAuthenticatedData = acceptNonAuthenticatedData;
091    }
092
093
094    /**
095     * @param additionalRecords The additional to set.
096     */
097    public void setAdditionalRecords( List<ResourceRecord> additionalRecords )
098    {
099        this.additionalRecords = additionalRecords;
100    }
101
102
103    /**
104     * @param answerRecords The answer to set.
105     */
106    public void setAnswerRecords( List<ResourceRecord> answerRecords )
107    {
108        this.answerRecords = answerRecords;
109    }
110
111
112    /**
113     * @param authoritativeAnswer The authoritativeAnswer to set.
114     */
115    public void setAuthoritativeAnswer( boolean authoritativeAnswer )
116    {
117        this.authoritativeAnswer = authoritativeAnswer;
118    }
119
120
121    /**
122     * @param authorityRecords The authority to set.
123     */
124    public void setAuthorityRecords( List<ResourceRecord> authorityRecords )
125    {
126        this.authorityRecords = authorityRecords;
127    }
128
129
130    /**
131     * @param messageType The messageType to set.
132     */
133    public void setMessageType( MessageType messageType )
134    {
135        this.messageType = messageType;
136    }
137
138
139    /**
140     * @param opCode The opCode to set.
141     */
142    public void setOpCode( OpCode opCode )
143    {
144        this.opCode = opCode;
145    }
146
147
148    /**
149     * @param questionRecords The question to set.
150     */
151    public void setQuestionRecords( List<QuestionRecord> questionRecords )
152    {
153        this.questionRecords = questionRecords;
154    }
155
156
157    /**
158     * @param recursionAvailable The recursionAvailable to set.
159     */
160    public void setRecursionAvailable( boolean recursionAvailable )
161    {
162        this.recursionAvailable = recursionAvailable;
163    }
164
165
166    /**
167     * @param recursionDesired The recursionDesired to set.
168     */
169    public void setRecursionDesired( boolean recursionDesired )
170    {
171        this.recursionDesired = recursionDesired;
172    }
173
174
175    /**
176     * @param reserved The reserved to set.
177     */
178    public void setReserved( boolean reserved )
179    {
180        this.reserved = reserved;
181    }
182
183
184    /**
185     * @param responseCode The responseCode to set.
186     */
187    public void setResponseCode( ResponseCode responseCode )
188    {
189        this.responseCode = responseCode;
190    }
191
192
193    /**
194     * @param transactionId The transactionId to set.
195     */
196    public void setTransactionId( int transactionId )
197    {
198        this.transactionId = transactionId;
199    }
200
201
202    /**
203     * @param truncated The truncated to set.
204     */
205    public void setTruncated( boolean truncated )
206    {
207        this.truncated = truncated;
208    }
209}