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.io.encoder;
22  
23  
24  import org.apache.directory.server.dns.messages.ResourceRecord;
25  import org.apache.directory.server.dns.store.DnsAttribute;
26  import org.apache.mina.common.ByteBuffer;
27  
28  /**
29   * 3.3.13. SOA RDATA format
30   * 
31   *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
32   *     /                     MNAME                     /
33   *     /                                               /
34   *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
35   *     /                     RNAME                     /
36   *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
37   *     |                    SERIAL                     |
38   *     |                                               |
39   *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
40   *     |                    REFRESH                    |
41   *     |                                               |
42   *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
43   *     |                     RETRY                     |
44   *     |                                               |
45   *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
46   *     |                    EXPIRE                     |
47   *     |                                               |
48   *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
49   *     |                    MINIMUM                    |
50   *     |                                               |
51   *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
52   * 
53   * where:
54   * 
55   * MNAME           The <domain-name> of the name server that was the
56   *                 original or primary source of data for this zone.
57   * 
58   * RNAME           A <domain-name> which specifies the mailbox of the
59   *                 person responsible for this zone.
60   * 
61   * SERIAL          The unsigned 32 bit version number of the original copy
62   *                 of the zone.  Zone transfers preserve this value.  This
63   *                 value wraps and should be compared using sequence space
64   *                 arithmetic.
65   * 
66   * REFRESH         A 32 bit time interval before the zone should be
67   *                 refreshed.
68   * 
69   * RETRY           A 32 bit time interval that should elapse before a
70   *                 failed refresh should be retried.
71   * 
72   * EXPIRE          A 32 bit time value that specifies the upper limit on
73   *                 the time interval that can elapse before the zone is no
74   *                 longer authoritative.
75   * 
76   * MINIMUM         The unsigned 32 bit minimum TTL field that should be
77   *                 exported with any RR from this zone.
78   * 
79   * SOA records cause no additional section processing.
80   * 
81   * All times are in units of seconds.
82   * 
83   * Most of these fields are pertinent only for name server maintenance
84   * operations.  However, MINIMUM is used in all query operations that
85   * retrieve RRs from a zone.  Whenever a RR is sent in a response to a
86   * query, the TTL field is set to the maximum of the TTL field from the RR
87   * and the MINIMUM field in the appropriate SOA.  Thus MINIMUM is a lower
88   * bound on the TTL field for all RRs in a zone.  Note that this use of
89   * MINIMUM should occur when the RRs are copied into the response and not
90   * when the zone is loaded from a master file or via a zone transfer.  The
91   * reason for this provison is to allow future dynamic update facilities to
92   * change the SOA RR with known semantics.
93   * 
94   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
95   * @version $Rev: 507388 $, $Date: 2007-02-14 05:55:05 +0100 (Mi, 14 Feb 2007) $
96   */
97  public class StartOfAuthorityRecordEncoder extends ResourceRecordEncoder
98  {
99      protected void putResourceRecordData( ByteBuffer 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 }