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    
021    package org.apache.directory.server.dns.io.encoder;
022    
023    
024    import org.apache.directory.server.dns.messages.ResourceRecord;
025    import org.apache.directory.server.dns.store.DnsAttribute;
026    import org.apache.mina.core.buffer.IoBuffer;
027    
028    /**
029     * 3.3.13. SOA RDATA format
030     * 
031     *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
032     *     /                     MNAME                     /
033     *     /                                               /
034     *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
035     *     /                     RNAME                     /
036     *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
037     *     |                    SERIAL                     |
038     *     |                                               |
039     *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
040     *     |                    REFRESH                    |
041     *     |                                               |
042     *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
043     *     |                     RETRY                     |
044     *     |                                               |
045     *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
046     *     |                    EXPIRE                     |
047     *     |                                               |
048     *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
049     *     |                    MINIMUM                    |
050     *     |                                               |
051     *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
052     * 
053     * where:
054     * 
055     * MNAME           The <domain-name> of the name server that was the
056     *                 original or primary source of data for this zone.
057     * 
058     * RNAME           A <domain-name> which specifies the mailbox of the
059     *                 person responsible for this zone.
060     * 
061     * SERIAL          The unsigned 32 bit version number of the original copy
062     *                 of the zone.  Zone transfers preserve this value.  This
063     *                 value wraps and should be compared using sequence space
064     *                 arithmetic.
065     * 
066     * REFRESH         A 32 bit time interval before the zone should be
067     *                 refreshed.
068     * 
069     * RETRY           A 32 bit time interval that should elapse before a
070     *                 failed refresh should be retried.
071     * 
072     * EXPIRE          A 32 bit time value that specifies the upper limit on
073     *                 the time interval that can elapse before the zone is no
074     *                 longer authoritative.
075     * 
076     * MINIMUM         The unsigned 32 bit minimum TTL field that should be
077     *                 exported with any RR from this zone.
078     * 
079     * SOA records cause no additional section processing.
080     * 
081     * All times are in units of seconds.
082     * 
083     * Most of these fields are pertinent only for name server maintenance
084     * operations.  However, MINIMUM is used in all query operations that
085     * retrieve RRs from a zone.  Whenever a RR is sent in a response to a
086     * query, the TTL field is set to the maximum of the TTL field from the RR
087     * and the MINIMUM field in the appropriate SOA.  Thus MINIMUM is a lower
088     * bound on the TTL field for all RRs in a zone.  Note that this use of
089     * MINIMUM should occur when the RRs are copied into the response and not
090     * when the zone is loaded from a master file or via a zone transfer.  The
091     * reason for this provison is to allow future dynamic update facilities to
092     * change the SOA RR with known semantics.
093     * 
094     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
095     * @version $Rev: 725712 $, $Date: 2008-12-11 16:32:04 +0100 (Thu, 11 Dec 2008) $
096     */
097    public class StartOfAuthorityRecordEncoder extends ResourceRecordEncoder
098    {
099        protected void putResourceRecordData( IoBuffer byteBuffer, ResourceRecord record )
100        {
101            String mName = record.get( DnsAttribute.SOA_M_NAME );
102            String rName = record.get( DnsAttribute.SOA_R_NAME );
103            long serial = Long.parseLong( record.get( DnsAttribute.SOA_SERIAL ) );
104            int refresh = Integer.parseInt( record.get( DnsAttribute.SOA_REFRESH ) );
105            int retry = Integer.parseInt( record.get( DnsAttribute.SOA_RETRY ) );
106            int expire = Integer.parseInt( record.get( DnsAttribute.SOA_EXPIRE ) );
107            long minimum = Long.parseLong( record.get( DnsAttribute.SOA_MINIMUM ) );
108    
109            putDomainName( byteBuffer, mName );
110            putDomainName( byteBuffer, rName );
111    
112            byteBuffer.putInt( ( int ) serial );
113    
114            byteBuffer.putInt( refresh );
115            byteBuffer.putInt( retry );
116            byteBuffer.putInt( expire );
117    
118            byteBuffer.putInt( ( int ) minimum );
119        }
120    }