You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2005/09/18 21:48:12 UTC
svn commit: r289962 [2/3] - in /directory/protocol-providers/dns/trunk/src:
java/org/apache/dns/io/ java/org/apache/dns/io/decoder/
java/org/apache/dns/io/encoder/ java/org/apache/dns/messages/
java/org/apache/dns/protocol/ java/org/apache/dns/service/...
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/ServerSelectionRecordEncoder.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/ServerSelectionRecordEncoder.java?rev=289962&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/ServerSelectionRecordEncoder.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/ServerSelectionRecordEncoder.java Sun Sep 18 12:47:47 2005
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.dns.io.encoder;
+
+/**
+ * The format of the SRV RR
+ *
+ * Here is the format of the SRV RR, whose DNS type code is 33:
+ *
+ * _Service._Proto.Name TTL Class SRV Priority Weight Port Target
+ *
+ * (There is an example near the end of this document.)
+ *
+ * Service
+ * The symbolic name of the desired service, as defined in Assigned
+ * Numbers [STD 2] or locally. An underscore (_) is prepended to
+ * the service identifier to avoid collisions with DNS labels that
+ * occur in nature.
+ *
+ * Some widely used services, notably POP, don't have a single
+ * universal name. If Assigned Numbers names the service
+ * indicated, that name is the only name which is legal for SRV
+ * lookups. The Service is case insensitive.
+ *
+ * Proto
+ * The symbolic name of the desired protocol, with an underscore
+ * (_) prepended to prevent collisions with DNS labels that occur
+ * in nature. _TCP and _UDP are at present the most useful values
+ * for this field, though any name defined by Assigned Numbers or
+ * locally may be used (as for Service). The Proto is case
+ * insensitive.
+ *
+ * Name
+ * The domain this RR refers to. The SRV RR is unique in that the
+ * name one searches for is not this name; the example near the end
+ * shows this clearly.
+ *
+ * TTL
+ * Standard DNS meaning [RFC 1035].
+ *
+ * Class
+ * Standard DNS meaning [RFC 1035]. SRV records occur in the IN
+ * Class.
+ *
+ * Priority
+ * The priority of this target host. A client MUST attempt to
+ * contact the target host with the lowest-numbered priority it can
+ * reach; target hosts with the same priority SHOULD be tried in an
+ * order defined by the weight field. The range is 0-65535. This
+ * is a 16 bit unsigned integer in network byte order.
+ *
+ * Weight
+ * A server selection mechanism. The weight field specifies a
+ * relative weight for entries with the same priority. Larger
+ * weights SHOULD be given a proportionately higher probability of
+ * being selected. The range of this number is 0-65535. This is a
+ * 16 bit unsigned integer in network byte order. Domain
+ * administrators SHOULD use Weight 0 when there isn't any server
+ * selection to do, to make the RR easier to read for humans (less
+ * noisy). In the presence of records containing weights greater
+ * than 0, records with weight 0 should have a very small chance of
+ * being selected.
+ *
+ * In the absence of a protocol whose specification calls for the
+ * use of other weighting information, a client arranges the SRV
+ * RRs of the same Priority in the order in which target hosts,
+ * specified by the SRV RRs, will be contacted. The following
+ * algorithm SHOULD be used to order the SRV RRs of the same
+ * priority:
+ *
+ * To select a target to be contacted next, arrange all SRV RRs
+ * (that have not been ordered yet) in any order, except that all
+ * those with weight 0 are placed at the beginning of the list.
+ *
+ * Compute the sum of the weights of those RRs, and with each RR
+ * associate the running sum in the selected order. Then choose a
+ * uniform random number between 0 and the sum computed
+ * (inclusive), and select the RR whose running sum value is the
+ * first in the selected order which is greater than or equal to
+ * the random number selected. The target host specified in the
+ * selected SRV RR is the next one to be contacted by the client.
+ * Remove this SRV RR from the set of the unordered SRV RRs and
+ * apply the described algorithm to the unordered SRV RRs to select
+ * the next target host. Continue the ordering process until there
+ * are no unordered SRV RRs. This process is repeated for each
+ * Priority.
+ *
+ * Port
+ * The port on this target host of this service. The range is 0-
+ * 65535. This is a 16 bit unsigned integer in network byte order.
+ * This is often as specified in Assigned Numbers but need not be.
+ *
+ * Target
+ * The domain name of the target host. There MUST be one or more
+ * address records for this name, the name MUST NOT be an alias (in
+ * the sense of RFC 1034 or RFC 2181). Implementors are urged, but
+ * not required, to return the address record(s) in the Additional
+ * Data section. Unless and until permitted by future standards
+ * action, name compression is not to be used for this field.
+ *
+ * A Target of "." means that the service is decidedly not
+ * available at this domain.
+ */
+public class ServerSelectionRecordEncoder
+{
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/ServerSelectionRecordEncoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/ServerSelectionRecordEncoder.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/SignatureRecordEncoder.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/SignatureRecordEncoder.java?rev=289962&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/SignatureRecordEncoder.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/SignatureRecordEncoder.java Sun Sep 18 12:47:47 2005
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.dns.io.encoder;
+
+/**
+ * 4.1 SIG RDATA Format
+ *
+ * The RDATA portion of a SIG RR is as shown below. The integrity of
+ * the RDATA information is protected by the signature field.
+ *
+ * 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | type covered | algorithm | labels |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | original TTL |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | signature expiration |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | signature inception |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | key tag | |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ signer's name +
+ * | /
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-/
+ * / /
+ * / signature /
+ * / /
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ * 4.1.1 Type Covered Field
+ *
+ * The "type covered" is the type of the other RRs covered by this SIG.
+ *
+ * 4.1.2 Algorithm Number Field
+ *
+ * This octet is as described in section 3.2.
+ *
+ * 4.1.3 Labels Field
+ *
+ * The "labels" octet is an unsigned count of how many labels there are
+ * in the original SIG RR owner name not counting the null label for
+ * root and not counting any initial "*" for a wildcard. If a secured
+ * retrieval is the result of wild card substitution, it is necessary
+ * for the resolver to use the original form of the name in verifying
+ * the digital signature. This field makes it easy to determine the
+ * original form.
+ *
+ * If, on retrieval, the RR appears to have a longer name than indicated
+ * by "labels", the resolver can tell it is the result of wildcard
+ * substitution. If the RR owner name appears to be shorter than the
+ * labels count, the SIG RR must be considered corrupt and ignored. The
+ * maximum number of labels allowed in the current DNS is 127 but the
+ * entire octet is reserved and would be required should DNS names ever
+ * be expanded to 255 labels. The following table gives some examples.
+ * The value of "labels" is at the top, the retrieved owner name on the
+ * left, and the table entry is the name to use in signature
+ * verification except that "bad" means the RR is corrupt.
+ *
+ * labels= | 0 | 1 | 2 | 3 | 4 |
+ * --------+-----+------+--------+----------+----------+
+ * .| . | bad | bad | bad | bad |
+ * d.| *. | d. | bad | bad | bad |
+ * c.d.| *. | *.d. | c.d. | bad | bad |
+ * b.c.d.| *. | *.d. | *.c.d. | b.c.d. | bad |
+ * a.b.c.d.| *. | *.d. | *.c.d. | *.b.c.d. | a.b.c.d. |
+ *
+ * 4.1.4 Original TTL Field
+ *
+ * The "original TTL" field is included in the RDATA portion to avoid
+ * (1) authentication problems that caching servers would otherwise
+ * cause by decrementing the real TTL field and (2) security problems
+ * that unscrupulous servers could otherwise cause by manipulating the
+ * real TTL field. This original TTL is protected by the signature
+ * while the current TTL field is not.
+ *
+ * NOTE: The "original TTL" must be restored into the covered RRs when
+ * the signature is verified (see Section 8). This generaly implies
+ * that all RRs for a particular type, name, and class, that is, all the
+ * RRs in any particular RRset, must have the same TTL to start with.
+ *
+ * 4.1.5 Signature Expiration and Inception Fields
+ *
+ * The SIG is valid from the "signature inception" time until the
+ * "signature expiration" time. Both are unsigned numbers of seconds
+ * since the start of 1 January 1970, GMT, ignoring leap seconds. (See
+ * also Section 4.4.) Ring arithmetic is used as for DNS SOA serial
+ * numbers [RFC 1982] which means that these times can never be more
+ * than about 68 years in the past or the future. This means that these
+ * times are ambiguous modulo ~136.09 years. However there is no
+ * security flaw because keys are required to be changed to new random
+ * keys by [RFC 2541] at least every five years. This means that the
+ * probability that the same key is in use N*136.09 years later should
+ * be the same as the probability that a random guess will work.
+ *
+ * A SIG RR may have an expiration time numerically less than the
+ * inception time if the expiration time is near the 32 bit wrap around
+ * point and/or the signature is long lived.
+ *
+ * (To prevent misordering of network requests to update a zone
+ * dynamically, monotonically increasing "signature inception" times may
+ * be necessary.)
+ *
+ * A secure zone must be considered changed for SOA serial number
+ * purposes not only when its data is updated but also when new SIG RRs
+ * are inserted (ie, the zone or any part of it is re-signed).
+ *
+ * 4.1.6 Key Tag Field
+ *
+ * The "key Tag" is a two octet quantity that is used to efficiently
+ * select between multiple keys which may be applicable and thus check
+ * that a public key about to be used for the computationally expensive
+ * effort to check the signature is possibly valid. For algorithm 1
+ * (MD5/RSA) as defined in [RFC 2537], it is the next to the bottom two
+ * octets of the public key modulus needed to decode the signature
+ * field. That is to say, the most significant 16 of the least
+ * significant 24 bits of the modulus in network (big endian) order. For
+ * all other algorithms, including private algorithms, it is calculated
+ * as a simple checksum of the KEY RR as described in Appendix C.
+ *
+ * 4.1.7 Signer's Name Field
+ *
+ * The "signer's name" field is the domain name of the signer generating
+ * the SIG RR. This is the owner name of the public KEY RR that can be
+ * used to verify the signature. It is frequently the zone which
+ * contained the RRset being authenticated. Which signers should be
+ * authorized to sign what is a significant resolver policy question as
+ * discussed in Section 6. The signer's name may be compressed with
+ * standard DNS name compression when being transmitted over the
+ * network.
+ *
+ * 4.1.8 Signature Field
+ *
+ * The actual signature portion of the SIG RR binds the other RDATA
+ * fields to the RRset of the "type covered" RRs with that owner name
+ * and class. This covered RRset is thereby authenticated. To
+ * accomplish this, a data sequence is constructed as follows:
+ *
+ * data = RDATA | RR(s)...
+ *
+ * where "|" is concatenation,
+ *
+ * RDATA is the wire format of all the RDATA fields in the SIG RR itself
+ * (including the canonical form of the signer's name) before but not
+ * including the signature, and
+ *
+ * RR(s) is the RRset of the RR(s) of the type covered with the same
+ * owner name and class as the SIG RR in canonical form and order as
+ * defined in Section 8.
+ *
+ * How this data sequence is processed into the signature is algorithm
+ * dependent. These algorithm dependent formats and procedures are
+ * described in separate documents (Section 3.2).
+ *
+ * SIGs SHOULD NOT be included in a zone for any "meta-type" such as
+ * ANY, AXFR, etc. (but see section 5.6.2 with regard to IXFR).
+ */
+public class SignatureRecordEncoder
+{
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/SignatureRecordEncoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/SignatureRecordEncoder.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/StartOfAuthorityRecordEncoder.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/StartOfAuthorityRecordEncoder.java?rev=289962&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/StartOfAuthorityRecordEncoder.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/StartOfAuthorityRecordEncoder.java Sun Sep 18 12:47:47 2005
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.dns.io.encoder;
+
+import org.apache.dns.messages.ResourceRecord;
+import org.apache.dns.store.DnsAttribute;
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * 3.3.13. SOA RDATA format
+ *
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * / MNAME /
+ * / /
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * / RNAME /
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * | SERIAL |
+ * | |
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * | REFRESH |
+ * | |
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * | RETRY |
+ * | |
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * | EXPIRE |
+ * | |
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * | MINIMUM |
+ * | |
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ *
+ * where:
+ *
+ * MNAME The <domain-name> of the name server that was the
+ * original or primary source of data for this zone.
+ *
+ * RNAME A <domain-name> which specifies the mailbox of the
+ * person responsible for this zone.
+ *
+ * SERIAL The unsigned 32 bit version number of the original copy
+ * of the zone. Zone transfers preserve this value. This
+ * value wraps and should be compared using sequence space
+ * arithmetic.
+ *
+ * REFRESH A 32 bit time interval before the zone should be
+ * refreshed.
+ *
+ * RETRY A 32 bit time interval that should elapse before a
+ * failed refresh should be retried.
+ *
+ * EXPIRE A 32 bit time value that specifies the upper limit on
+ * the time interval that can elapse before the zone is no
+ * longer authoritative.
+ *
+ * MINIMUM The unsigned 32 bit minimum TTL field that should be
+ * exported with any RR from this zone.
+ *
+ * SOA records cause no additional section processing.
+ *
+ * All times are in units of seconds.
+ *
+ * Most of these fields are pertinent only for name server maintenance
+ * operations. However, MINIMUM is used in all query operations that
+ * retrieve RRs from a zone. Whenever a RR is sent in a response to a
+ * query, the TTL field is set to the maximum of the TTL field from the RR
+ * and the MINIMUM field in the appropriate SOA. Thus MINIMUM is a lower
+ * bound on the TTL field for all RRs in a zone. Note that this use of
+ * MINIMUM should occur when the RRs are copied into the response and not
+ * when the zone is loaded from a master file or via a zone transfer. The
+ * reason for this provison is to allow future dynamic update facilities to
+ * change the SOA RR with known semantics.
+ */
+public class StartOfAuthorityRecordEncoder extends ResourceRecordEncoder
+{
+ protected byte[] encodeResourceData( ResourceRecord record )
+ {
+ String mName = record.get( DnsAttribute.SOA_M_NAME );
+ String rName = record.get( DnsAttribute.SOA_R_NAME );
+ long serial = Long.parseLong( record.get( DnsAttribute.SOA_SERIAL ) );
+ int refresh = Integer.parseInt( record.get( DnsAttribute.SOA_REFRESH ) );
+ int retry = Integer.parseInt( record.get( DnsAttribute.SOA_RETRY ) );
+ int expire = Integer.parseInt( record.get( DnsAttribute.SOA_EXPIRE ) );
+ long minimum = Long.parseLong( record.get( DnsAttribute.SOA_MINIMUM ) );
+
+ ByteBuffer byteBuffer = ByteBuffer.allocate( 256 );
+
+ byteBuffer.put( encodeDomainName( mName ) );
+ byteBuffer.put( encodeDomainName( rName ) );
+
+ putUnsignedInt( byteBuffer, serial );
+
+ byteBuffer.putInt( refresh );
+ byteBuffer.putInt( retry );
+ byteBuffer.putInt( expire );
+
+ putUnsignedInt( byteBuffer, minimum );
+
+ byteBuffer.flip();
+ byte[] bytes = new byte[ byteBuffer.remaining() ];
+ byteBuffer.get( bytes, 0, bytes.length );
+
+ return bytes;
+ }
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/StartOfAuthorityRecordEncoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/TextRecordEncoder.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/TextRecordEncoder.java?rev=289962&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/TextRecordEncoder.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/TextRecordEncoder.java Sun Sep 18 12:47:47 2005
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.dns.io.encoder;
+
+import org.apache.dns.messages.ResourceRecord;
+import org.apache.dns.store.DnsAttribute;
+
+/**
+ * 3.3.14. TXT RDATA format
+ *
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * / TXT-DATA /
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ *
+ * where:
+ *
+ * TXT-DATA One or more <character-string>s.
+ *
+ * TXT RRs are used to hold descriptive text. The semantics of the text
+ * depends on the domain where it is found.
+ */
+public class TextRecordEncoder extends ResourceRecordEncoder
+{
+ protected byte[] encodeResourceData( ResourceRecord record )
+ {
+ return encodeCharacterString( record.get( DnsAttribute.CHARACTER_STRING ) );
+ }
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/TextRecordEncoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/WellKnownServicesRecordEncoder.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/WellKnownServicesRecordEncoder.java?rev=289962&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/WellKnownServicesRecordEncoder.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/WellKnownServicesRecordEncoder.java Sun Sep 18 12:47:47 2005
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.dns.io.encoder;
+
+/**
+ * 3.4.2. WKS RDATA format
+ *
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * | ADDRESS |
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * | PROTOCOL | |
+ * +--+--+--+--+--+--+--+--+ |
+ * | |
+ * / <BIT MAP> /
+ * / /
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ *
+ * where:
+ *
+ * ADDRESS An 32 bit Internet address
+ *
+ * PROTOCOL An 8 bit IP protocol number
+ *
+ * <BIT MAP> A variable length bit map. The bit map must be a
+ * multiple of 8 bits long.
+ *
+ * The WKS record is used to describe the well known services supported by
+ * a particular protocol on a particular internet address. The PROTOCOL
+ * field specifies an IP protocol number, and the bit map has one bit per
+ * port of the specified protocol. The first bit corresponds to port 0,
+ * the second to port 1, etc. If the bit map does not include a bit for a
+ * protocol of interest, that bit is assumed zero. The appropriate values
+ * and mnemonics for ports and protocols are specified in [RFC-1010].
+ *
+ * For example, if PROTOCOL=TCP (6), the 26th bit corresponds to TCP port
+ * 25 (SMTP). If this bit is set, a SMTP server should be listening on TCP
+ * port 25; if zero, SMTP service is not supported on the specified
+ * address.
+ *
+ * The purpose of WKS RRs is to provide availability information for
+ * servers for TCP and UDP. If a server supports both TCP and UDP, or has
+ * multiple Internet addresses, then multiple WKS RRs are used.
+ *
+ * WKS RRs cause no additional section processing.
+ *
+ * In master files, both ports and protocols are expressed using mnemonics
+ * or decimal numbers.
+ */
+public class WellKnownServicesRecordEncoder
+{
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/WellKnownServicesRecordEncoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/io/encoder/WellKnownServicesRecordEncoder.java
------------------------------------------------------------------------------
svn:executable = *
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/DnsMessage.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/DnsMessage.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/DnsMessage.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/DnsMessage.java Sun Sep 18 12:47:47 2005
@@ -17,9 +17,6 @@
package org.apache.dns.messages;
-import org.apache.dns.records.QuestionRecord;
-import org.apache.dns.records.ResourceRecord;
-
/**
* All communications inside of the domain protocol are carried in a single
* format called a message. The top level format of message is divided
@@ -57,15 +54,15 @@
private ResponseCode responseCode;
- private QuestionRecord[] questionRecords;
- private ResourceRecord[] answerRecords;
- private ResourceRecord[] authorityRecords;
- private ResourceRecord[] additionalRecords;
+ private QuestionRecords questionRecords;
+ private ResourceRecords answerRecords;
+ private ResourceRecords authorityRecords;
+ private ResourceRecords additionalRecords;
public DnsMessage( short transactionId, MessageType messageType, OpCode opCode, boolean authoritativeAnswer,
boolean truncated, boolean recursionDesired, boolean recursionAvailable, boolean reserved,
- boolean acceptNonAuthenticatedData, ResponseCode responseCode, QuestionRecord[] question,
- ResourceRecord[] answer, ResourceRecord[] authority, ResourceRecord[] additional )
+ boolean acceptNonAuthenticatedData, ResponseCode responseCode, QuestionRecords question,
+ ResourceRecords answer, ResourceRecords authority, ResourceRecords additional )
{
this.transactionId = transactionId;
this.messageType = messageType;
@@ -94,15 +91,15 @@
/**
* @return Returns the additional.
*/
- public ResourceRecord[] getAdditionalRecords()
+ public ResourceRecords getAdditionalRecords()
{
return additionalRecords;
}
/**
- * @return Returns the answer.
+ * @return Returns the answers.
*/
- public ResourceRecord[] getAnswerRecords()
+ public ResourceRecords getAnswerRecords()
{
return answerRecords;
}
@@ -118,7 +115,7 @@
/**
* @return Returns the authority.
*/
- public ResourceRecord[] getAuthorityRecords()
+ public ResourceRecords getAuthorityRecords()
{
return authorityRecords;
}
@@ -142,7 +139,7 @@
/**
* @return Returns the question.
*/
- public QuestionRecord[] getQuestionRecords()
+ public QuestionRecords getQuestionRecords()
{
return questionRecords;
}
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/DnsMessageModifier.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/DnsMessageModifier.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/DnsMessageModifier.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/DnsMessageModifier.java Sun Sep 18 12:47:47 2005
@@ -17,8 +17,6 @@
package org.apache.dns.messages;
-import org.apache.dns.records.QuestionRecord;
-import org.apache.dns.records.ResourceRecord;
/**
* All communications inside of the domain protocol are carried in a single
@@ -57,10 +55,10 @@
private ResponseCode responseCode;
- private QuestionRecord[] questionRecords;
- private ResourceRecord[] answerRecords;
- private ResourceRecord[] authorityRecords;
- private ResourceRecord[] additionalRecords;
+ private QuestionRecords questionRecords;
+ private ResourceRecords answerRecords;
+ private ResourceRecords authorityRecords;
+ private ResourceRecords additionalRecords;
public DnsMessage getDnsMessage()
{
@@ -80,7 +78,7 @@
/**
* @param additionalRecords The additional to set.
*/
- public void setAdditionalRecords( ResourceRecord[] additionalRecords )
+ public void setAdditionalRecords( ResourceRecords additionalRecords )
{
this.additionalRecords = additionalRecords;
}
@@ -88,7 +86,7 @@
/**
* @param answerRecords The answer to set.
*/
- public void setAnswerRecords( ResourceRecord[] answerRecords )
+ public void setAnswerRecords( ResourceRecords answerRecords )
{
this.answerRecords = answerRecords;
}
@@ -104,7 +102,7 @@
/**
* @param authorityRecords The authority to set.
*/
- public void setAuthorityRecords( ResourceRecord[] authorityRecords )
+ public void setAuthorityRecords( ResourceRecords authorityRecords )
{
this.authorityRecords = authorityRecords;
}
@@ -128,7 +126,7 @@
/**
* @param questionRecords The question to set.
*/
- public void setQuestionRecords( QuestionRecord[] questionRecords )
+ public void setQuestionRecords( QuestionRecords questionRecords )
{
this.questionRecords = questionRecords;
}
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/QuestionRecords.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/QuestionRecords.java?rev=289962&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/QuestionRecords.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/QuestionRecords.java Sun Sep 18 12:47:47 2005
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.dns.messages;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class QuestionRecords
+{
+ private List questionRecords;
+
+ public QuestionRecords()
+ {
+ this.questionRecords = new ArrayList();
+ }
+
+ public QuestionRecords( int initialCapacity )
+ {
+ this.questionRecords = new ArrayList( initialCapacity );
+ }
+
+ public void add( QuestionRecord question )
+ {
+ questionRecords.add( question );
+ }
+
+ public int size()
+ {
+ return questionRecords.size();
+ }
+
+ public Iterator iterator()
+ {
+ return questionRecords.iterator();
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+
+ Iterator it = iterator();
+
+ while ( it.hasNext() )
+ {
+ QuestionRecord question = (QuestionRecord) it.next();
+ sb.append( "\n\t" + "dnsName " + question.getDomainName() );
+ sb.append( "\n\t" + "dnsType " + question.getRecordType() );
+ sb.append( "\n\t" + "dnsClass " + question.getRecordClass() );
+ }
+
+ return sb.toString();
+ }
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/QuestionRecords.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecord.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecord.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecord.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecord.java Sun Sep 18 12:47:47 2005
@@ -17,123 +17,30 @@
package org.apache.dns.messages;
-/**
- * The answer, authority, and additional sections all share the same
- * format: a variable number of resource records, where the number of
- * records is specified in the corresponding count field in the header.
- * Each resource record has the following format:
- * 1 1 1 1 1 1
- * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
- * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
- * | |
- * / /
- * / NAME /
- * | |
- * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
- * | TYPE |
- * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
- * | CLASS |
- * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
- * | TTL |
- * | |
- * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
- * | RDLENGTH |
- * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
- * / RDATA /
- * / /
- * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
- */
-public class ResourceRecord
+public interface ResourceRecord
{
/**
- * An owner name, i.e., the name of the node to which this
- * resource record pertains.
- */
- private String domainName;
-
- /**
- * Two octets containing one of the resource record TYPE codes.
- */
- private RecordType recordType;
-
- /**
- * Two octets containing one of the resource record CLASS codes.
- * For example, the CLASS field is IN for the Internet.
- */
- private RecordClass recordClass;
-
- /**
- * A 32 bit signed integer that specifies the time interval
- * that the resource record may be cached before the source
- * of the information should again be consulted. Zero
- * values are interpreted to mean that the resource record can only be
- * used for the transaction in progress, and should not be
- * cached. For example, SOA records are always distributed
- * with a zero TTL to prohibit caching. Zero values can
- * also be used for extremely volatile data.
- */
- private int timeToLive;
-
- /**
- * A variable length string of octets that describes the
- * resource. The format of this information varies
- * according to the TYPE and CLASS of the resource record.
- */
- private byte[] resourceData;
-
- public ResourceRecord( String domainName, RecordType recordType, RecordClass recordClass, int timeToLive,
- byte[] resourceData )
- {
- this.domainName = domainName;
- this.recordType = recordType;
- this.recordClass = recordClass;
- this.timeToLive = timeToLive;
- this.resourceData = resourceData;
- }
-
- /**
* @return Returns the domainName.
*/
- public String getDomainName()
- {
- return domainName;
- }
-
- /**
- * @return Returns the recordClass.
- */
- public RecordClass getRecordClass()
- {
- return recordClass;
- }
+ public String getDomainName();
/**
* @return Returns the recordType.
*/
- public RecordType getRecordType()
- {
- return recordType;
- }
+ public RecordType getRecordType();
/**
- * @return Returns the resourceData.
+ * @return Returns the recordClass.
*/
- public byte[] getResourceData()
- {
- return resourceData;
- }
+ public RecordClass getRecordClass();
/**
* @return Returns the timeToLive.
*/
- public int getTimeToLive()
- {
- return timeToLive;
- }
+ public int getTimeToLive();
- public String toString()
- {
- return getClass().getName() + " [ " + domainName + " ( " + recordClass + " " + recordType + " " + timeToLive
- + " " + resourceData.length + " ) ]";
- }
+ /**
+ * @return Returns the value for an id.
+ */
+ public String get( String id );
}
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecordImpl.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecordImpl.java?rev=289962&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecordImpl.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecordImpl.java Sun Sep 18 12:47:47 2005
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.dns.messages;
+
+import java.util.Map;
+
+/**
+ * The answer, authority, and additional sections all share the same
+ * format: a variable number of resource records, where the number of
+ * records is specified in the corresponding count field in the header.
+ * Each resource record has the following format:
+ * 1 1 1 1 1 1
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * | |
+ * / /
+ * / NAME /
+ * | |
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * | TYPE |
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * | CLASS |
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * | TTL |
+ * | |
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * | RDLENGTH |
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
+ * / RDATA /
+ * / /
+ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ */
+public class ResourceRecordImpl implements ResourceRecord
+{
+ /**
+ * An owner name, i.e., the name of the node to which this
+ * resource record pertains.
+ */
+ private String domainName;
+
+ /**
+ * Two octets containing one of the resource record TYPE codes.
+ */
+ private RecordType recordType;
+
+ /**
+ * Two octets containing one of the resource record CLASS codes.
+ * For example, the CLASS field is IN for the Internet.
+ */
+ private RecordClass recordClass;
+
+ /**
+ * A 32 bit signed integer that specifies the time interval
+ * that the resource record may be cached before the source
+ * of the information should again be consulted. Zero
+ * values are interpreted to mean that the resource record can only be
+ * used for the transaction in progress, and should not be
+ * cached. For example, SOA records are always distributed
+ * with a zero TTL to prohibit caching. Zero values can
+ * also be used for extremely volatile data.
+ */
+ private int timeToLive;
+
+ /**
+ * A variable length string of octets that describes the
+ * resource. The format of this information varies
+ * according to the TYPE and CLASS of the resource record.
+ */
+ private Map attributes;
+
+ public ResourceRecordImpl( String domainName, RecordType recordType, RecordClass recordClass, int timeToLive,
+ Map attributes )
+ {
+ this.domainName = domainName;
+ this.recordType = recordType;
+ this.recordClass = recordClass;
+ this.timeToLive = timeToLive;
+ this.attributes = attributes;
+ }
+
+ /**
+ * @return Returns the domainName.
+ */
+ public String getDomainName()
+ {
+ return domainName;
+ }
+
+ /**
+ * @return Returns the recordType.
+ */
+ public RecordType getRecordType()
+ {
+ return recordType;
+ }
+
+ /**
+ * @return Returns the recordClass.
+ */
+ public RecordClass getRecordClass()
+ {
+ return recordClass;
+ }
+
+ /**
+ * @return Returns the timeToLive.
+ */
+ public int getTimeToLive()
+ {
+ return timeToLive;
+ }
+
+ /**
+ * @return Returns the value for the id.
+ */
+ public String get( String id )
+ {
+ return (String) attributes.get( id );
+ }
+
+ public String toString()
+ {
+ return getClass().getName() + " [ " + domainName + " ( " + recordType + " " + recordClass + " " + timeToLive
+ + " " + attributes.size() + " ) ]";
+ }
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecordImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecordImpl.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecordModifier.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecordModifier.java?rev=289962&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecordModifier.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecordModifier.java Sun Sep 18 12:47:47 2005
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.dns.messages;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.dns.messages.RecordClass;
+import org.apache.dns.messages.RecordType;
+import org.apache.dns.messages.ResourceRecord;
+import org.apache.dns.messages.ResourceRecordImpl;
+
+public class ResourceRecordModifier
+{
+ private String dnsName;
+ private RecordType dnsType;
+ private RecordClass dnsClass;
+ private int dnsTtl;
+ private Map attributes = new HashMap();
+
+ public ResourceRecord getEntry()
+ {
+ return new ResourceRecordImpl( dnsName, dnsType, dnsClass, dnsTtl, attributes );
+ }
+
+ /**
+ * @param dnsName The dnsName to set.
+ */
+ public void setDnsName( String dnsName )
+ {
+ this.dnsName = dnsName;
+ }
+
+ /**
+ * @param dnsType The dnsType to set.
+ */
+ public void setDnsType( RecordType dnsType )
+ {
+ this.dnsType = dnsType;
+ }
+
+ /**
+ * @param dnsClass The dnsClass to set.
+ */
+ public void setDnsClass( RecordClass dnsClass )
+ {
+ this.dnsClass = dnsClass;
+ }
+
+ /**
+ * @param dnsTtl The dnsTtl to set.
+ */
+ public void setDnsTtl( int dnsTtl )
+ {
+ this.dnsTtl = dnsTtl;
+ }
+
+ /**
+ * @param id The id to set
+ * @param value The value to set
+ */
+ public void put( String id, String value )
+ {
+ attributes.put( id, value );
+ }
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecordModifier.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecords.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecords.java?rev=289962&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecords.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecords.java Sun Sep 18 12:47:47 2005
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.dns.messages;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class ResourceRecords
+{
+ private List resourceRecords;
+
+ public ResourceRecords()
+ {
+ this.resourceRecords = new ArrayList();
+ }
+
+ public ResourceRecords( int initialCapacity )
+ {
+ this.resourceRecords = new ArrayList( initialCapacity );
+ }
+
+ public void add( ResourceRecord record )
+ {
+ resourceRecords.add( record );
+ }
+
+ public int size()
+ {
+ return resourceRecords.size();
+ }
+
+ public Iterator iterator()
+ {
+ return resourceRecords.iterator();
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+
+ Iterator it = iterator();
+
+ while ( it.hasNext() )
+ {
+ ResourceRecord record = (ResourceRecord) it.next();
+ sb.append( "\n\t" + "dnsName " + record.getDomainName() );
+ sb.append( "\n\t" + "dnsType " + record.getRecordType() );
+ sb.append( "\n\t" + "dnsClass " + record.getRecordClass() );
+ sb.append( "\n\t" + "dnsTtl " + record.getTimeToLive() );
+ }
+
+ return sb.toString();
+ }
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/messages/ResourceRecords.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/protocol/DnsDecoder.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/protocol/DnsDecoder.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/protocol/DnsDecoder.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/protocol/DnsDecoder.java Sun Sep 18 12:47:47 2005
@@ -17,19 +17,228 @@
package org.apache.dns.protocol;
-import org.apache.dns.io.DnsMessageDecoder;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.dns.io.decoder.Decoder;
+import org.apache.dns.messages.DnsMessage;
+import org.apache.dns.messages.DnsMessageModifier;
+import org.apache.dns.messages.MessageType;
+import org.apache.dns.messages.OpCode;
+import org.apache.dns.messages.QuestionRecord;
+import org.apache.dns.messages.QuestionRecords;
+import org.apache.dns.messages.RecordClass;
+import org.apache.dns.messages.RecordType;
+import org.apache.dns.messages.ResourceRecordImpl;
+import org.apache.dns.messages.ResourceRecords;
+import org.apache.dns.messages.ResponseCode;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.protocol.ProtocolDecoder;
import org.apache.mina.protocol.ProtocolDecoderOutput;
import org.apache.mina.protocol.ProtocolSession;
import org.apache.mina.protocol.ProtocolViolationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class DnsDecoder implements ProtocolDecoder
{
+ /** the log for this class */
+ private static final Logger log = LoggerFactory.getLogger( DnsDecoder.class );
+
+ /**
+ * A Hashed Adapter mapping record types to their encoders.
+ */
+ private static final Map DEFAULT_DECODERS;
+
+ static
+ {
+ Map map = new HashMap();
+
+ // map.put( RecordType.SOA, new StartOfAuthorityRecordEncoder() );
+
+ DEFAULT_DECODERS = Collections.unmodifiableMap( map );
+ }
+
public void decode( ProtocolSession session, ByteBuffer in, ProtocolDecoderOutput out )
throws ProtocolViolationException
{
- DnsMessageDecoder decoder = new DnsMessageDecoder();
- out.write( decoder.decode( in.buf() ) );
+ out.write( decode( in ) );
+ }
+
+ DnsMessage decode( ByteBuffer in )
+ {
+ DnsMessageModifier modifier = new DnsMessageModifier();
+
+ modifier.setTransactionId( in.getShort() );
+
+ byte header = in.get();
+ modifier.setMessageType( decodeMessageType( header ) );
+ modifier.setOpCode( decodeOpCode( header ) );
+ modifier.setAuthoritativeAnswer( decodeAuthoritativeAnswer( header ) );
+ modifier.setTruncated( decodeTruncated( header ) );
+ modifier.setRecursionDesired( decodeRecursionDesired( header ) );
+
+ header = in.get();
+ modifier.setRecursionAvailable( decodeRecursionAvailable( header ) );
+ modifier.setResponseCode( decodeResponseCode( header ) );
+
+ short questionCount = in.getShort();
+ short answerCount = in.getShort();
+ short authorityCount = in.getShort();
+ short additionalCount = in.getShort();
+
+ modifier.setQuestionRecords( decodeQuestions( questionCount, in ) );
+ modifier.setAnswerRecords( decodeRecords( answerCount, in ) );
+ modifier.setAuthorityRecords( decodeRecords( authorityCount, in ) );
+ modifier.setAdditionalRecords( decodeRecords( additionalCount, in ) );
+
+ return modifier.getDnsMessage();
+ }
+
+ private ResourceRecords decodeRecords( short recordCount, ByteBuffer byteBuffer )
+ {
+ ResourceRecords records = new ResourceRecords( recordCount );
+
+ for ( int ii = 0; ii < recordCount; ii++ )
+ {
+ String domainName = decodeDomainName( byteBuffer );
+
+ RecordType recordType = RecordType.getTypeByOrdinal( byteBuffer.getShort() );
+ RecordClass recordClass = RecordClass.getTypeByOrdinal( byteBuffer.getShort() );
+
+ int timeToLive = byteBuffer.getInt();
+ short dataLength = byteBuffer.getShort();
+
+ byte[] data = new byte[ dataLength ];
+ byteBuffer.get( data );
+
+ try
+ {
+ Map attributes = decode( recordType, data );
+ records.add( new ResourceRecordImpl( domainName, recordType, recordClass, timeToLive, attributes ) );
+ }
+ catch ( IOException ioe )
+ {
+ log.error( ioe.getMessage(), ioe );
+ }
+ }
+
+ return records;
+ }
+
+ private Map decode( RecordType type, byte[] resourceData ) throws IOException
+ {
+ Decoder decoder = (Decoder) DEFAULT_DECODERS.get( type );
+
+ if ( decoder == null )
+ {
+ throw new IOException( "Decoder unavailable for " + type );
+ }
+
+ return decoder.decode( resourceData );
+ }
+
+ private QuestionRecords decodeQuestions( short questionCount, ByteBuffer byteBuffer )
+ {
+ QuestionRecords questions = new QuestionRecords( questionCount );
+
+ for ( int ii = 0; ii < questionCount; ii++ )
+ {
+ String domainName = decodeDomainName( byteBuffer );
+
+ RecordType recordType = RecordType.getTypeByOrdinal( byteBuffer.getShort() );
+ RecordClass recordClass = RecordClass.getTypeByOrdinal( byteBuffer.getShort() );
+
+ questions.add( new QuestionRecord( domainName, recordType, recordClass ) );
+ }
+
+ return questions;
+ }
+
+ private String decodeDomainName( ByteBuffer byteBuffer )
+ {
+ StringBuffer domainName = new StringBuffer();
+ recurseDomainName( domainName, byteBuffer );
+
+ return domainName.toString();
+ }
+
+ private void recurseDomainName( StringBuffer domainName, ByteBuffer byteBuffer )
+ {
+ byte currentByte = byteBuffer.get();
+
+ boolean isCompressed = ( ( currentByte & (byte) 0xc0 ) == (byte) 0xc0 );
+ boolean isLabelLength = ( ( currentByte != 0 ) && !isCompressed );
+
+ if ( isCompressed )
+ {
+ int position = byteBuffer.get();
+ int originalPosition = byteBuffer.position();
+ byteBuffer.position( position );
+
+ int labelLength = byteBuffer.get();
+ getLabel( labelLength, byteBuffer, domainName );
+ recurseDomainName( domainName, byteBuffer );
+
+ byteBuffer.position( originalPosition );
+ }
+
+ if ( isLabelLength )
+ {
+ int labelLength = currentByte;
+ getLabel( labelLength, byteBuffer, domainName );
+ recurseDomainName( domainName, byteBuffer );
+ }
+ }
+
+ private void getLabel( int labelLength, ByteBuffer byteBuffer, StringBuffer domainName )
+ {
+ for ( int jj = 0; jj < labelLength; jj++ )
+ {
+ char character = (char) byteBuffer.get();
+ domainName.append( character );
+ }
+
+ if ( byteBuffer.get( byteBuffer.position() ) != 0 )
+ {
+ domainName.append( "." );
+ }
+ }
+
+ private MessageType decodeMessageType( byte header )
+ {
+ return MessageType.getTypeByOrdinal( ( header & 0x80 ) >>> 7 );
+ }
+
+ private OpCode decodeOpCode( byte header )
+ {
+ return OpCode.getTypeByOrdinal( ( header & 0x78 ) >>> 3 );
+ }
+
+ private boolean decodeAuthoritativeAnswer( byte header )
+ {
+ return ( ( header & 0x04 ) >>> 2 ) == 1;
+ }
+
+ private boolean decodeTruncated( byte header )
+ {
+ return ( ( header & 0x02 ) >>> 1 ) == 1;
+ }
+
+ private boolean decodeRecursionDesired( byte header )
+ {
+ return ( ( header & 0x01 ) ) == 1;
+ }
+
+ private boolean decodeRecursionAvailable( byte header )
+ {
+ return ( ( header & 0x80 ) >>> 7 ) == 1;
+ }
+
+ private ResponseCode decodeResponseCode( byte header )
+ {
+ return ResponseCode.getTypeByOrdinal( header & 0x0F );
}
}
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/protocol/DnsEncoder.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/protocol/DnsEncoder.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/protocol/DnsEncoder.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/protocol/DnsEncoder.java Sun Sep 18 12:47:47 2005
@@ -17,26 +17,197 @@
package org.apache.dns.protocol;
-import org.apache.dns.io.DnsMessageEncoder;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.dns.io.encoder.AddressRecordEncoder;
+import org.apache.dns.io.encoder.CanonicalNameRecordEncoder;
+import org.apache.dns.io.encoder.MailExchangeRecordEncoder;
+import org.apache.dns.io.encoder.NameServerRecordEncoder;
+import org.apache.dns.io.encoder.PointerRecordEncoder;
+import org.apache.dns.io.encoder.QuestionRecordEncoder;
+import org.apache.dns.io.encoder.RecordEncoder;
+import org.apache.dns.io.encoder.StartOfAuthorityRecordEncoder;
import org.apache.dns.messages.DnsMessage;
+import org.apache.dns.messages.MessageType;
+import org.apache.dns.messages.OpCode;
+import org.apache.dns.messages.QuestionRecord;
+import org.apache.dns.messages.QuestionRecords;
+import org.apache.dns.messages.RecordType;
+import org.apache.dns.messages.ResourceRecord;
+import org.apache.dns.messages.ResourceRecords;
+import org.apache.dns.messages.ResponseCode;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.protocol.ProtocolEncoder;
import org.apache.mina.protocol.ProtocolEncoderOutput;
import org.apache.mina.protocol.ProtocolSession;
import org.apache.mina.protocol.ProtocolViolationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class DnsEncoder implements ProtocolEncoder
{
+ /** the log for this class */
+ private static final Logger log = LoggerFactory.getLogger( DnsEncoder.class );
+
+ /**
+ * A Hashed Adapter mapping record types to their encoders.
+ */
+ private static final Map DEFAULT_ENCODERS;
+
+ static
+ {
+ Map map = new HashMap();
+
+ map.put( RecordType.SOA, new StartOfAuthorityRecordEncoder() );
+ map.put( RecordType.A, new AddressRecordEncoder() );
+ map.put( RecordType.NS, new NameServerRecordEncoder() );
+ map.put( RecordType.CNAME, new CanonicalNameRecordEncoder() );
+ map.put( RecordType.PTR, new PointerRecordEncoder() );
+ map.put( RecordType.MX, new MailExchangeRecordEncoder() );
+
+ DEFAULT_ENCODERS = Collections.unmodifiableMap( map );
+ }
+
public void encode( ProtocolSession session, Object message, ProtocolEncoderOutput out )
throws ProtocolViolationException
{
- DnsMessageEncoder encoder = new DnsMessageEncoder();
-
ByteBuffer buf = ByteBuffer.allocate( 1024 );
- encoder.encode( buf.buf(), (DnsMessage) message );
+ encode( buf, (DnsMessage) message );
buf.flip();
out.write( buf );
+ }
+
+ public void encode( ByteBuffer byteBuffer, DnsMessage message )
+ {
+ byteBuffer.putShort( message.getTransactionId() );
+
+ byte header = (byte) 0x00;
+ header = encodeMessageType( message.getMessageType(), header );
+ header = encodeOpCode( message.getOpCode(), header );
+ header = encodeAuthoritativeAnswer( message.isAuthoritativeAnswer(), header );
+ header = encodeTruncated( message.isTruncated(), header );
+ header = encodeRecursionDesired( message.isRecursionDesired(), header );
+ byteBuffer.put( header );
+
+ header = (byte) 0x00;
+ header = encodeRecursionAvailable( message.isRecursionAvailable(), header );
+ header = encodeResponseCode( message.getResponseCode(), header );
+ byteBuffer.put( header );
+
+ byteBuffer.putShort( (short) message.getQuestionRecords().size() );
+ byteBuffer.putShort( (short) message.getAnswerRecords().size() );
+ byteBuffer.putShort( (short) message.getAuthorityRecords().size() );
+ byteBuffer.putShort( (short) message.getAdditionalRecords().size() );
+
+ encodeRecords( message.getQuestionRecords(), byteBuffer );
+ encodeRecords( message.getAnswerRecords(), byteBuffer );
+ encodeRecords( message.getAuthorityRecords(), byteBuffer );
+ encodeRecords( message.getAdditionalRecords(), byteBuffer );
+ }
+
+ private void encodeRecords( QuestionRecords questions, ByteBuffer byteBuffer )
+ {
+ QuestionRecordEncoder encoder = new QuestionRecordEncoder();
+
+ Iterator it = questions.iterator();
+
+ while ( it.hasNext() )
+ {
+ QuestionRecord question = (QuestionRecord) it.next();
+ encoder.encode( byteBuffer, question );
+ }
+ }
+
+ private void encodeRecords( ResourceRecords records, ByteBuffer byteBuffer )
+ {
+ Iterator it = records.iterator();
+
+ while ( it.hasNext() )
+ {
+ ResourceRecord record = (ResourceRecord) it.next();
+
+ try
+ {
+ encode( byteBuffer, record );
+ }
+ catch ( IOException ioe )
+ {
+ log.error( ioe.getMessage(), ioe );
+ }
+ }
+ }
+
+ private void encode( ByteBuffer out, ResourceRecord record ) throws IOException
+ {
+ RecordType type = record.getRecordType();
+
+ RecordEncoder encoder = (RecordEncoder) DEFAULT_ENCODERS.get( type );
+
+ if ( encoder == null )
+ {
+ throw new IOException( "Encoder unavailable for " + type );
+ }
+
+ encoder.encode( out, record );
+ }
+
+ private byte encodeMessageType( MessageType messageType, byte header )
+ {
+ byte oneBit = (byte) ( messageType.getOrdinal() & 0x01 );
+ return (byte) ( ( oneBit << 7 ) | header );
+ }
+
+ private byte encodeOpCode( OpCode opCode, byte header )
+ {
+ byte fourBits = (byte) ( opCode.getOrdinal() & 0x0F );
+ return (byte) ( ( fourBits << 3 ) | header );
+ }
+
+ private byte encodeAuthoritativeAnswer( boolean authoritative, byte header )
+ {
+ if ( authoritative )
+ {
+ header = (byte) ( ( (byte) 0x01 << 2 ) | header );
+ }
+ return header;
+ }
+
+ private byte encodeTruncated( boolean truncated, byte header )
+ {
+ if ( truncated )
+ {
+ header = (byte) ( ( (byte) 0x01 << 1 ) | header );
+ }
+ return header;
+ }
+
+ private byte encodeRecursionDesired( boolean recursionDesired, byte header )
+ {
+ if ( recursionDesired )
+ {
+ header = (byte) ( ( (byte) 0x01 ) | header );
+ }
+ return header;
+ }
+
+ private byte encodeRecursionAvailable( boolean recursionAvailable, byte header )
+ {
+ if ( recursionAvailable )
+ {
+ header = (byte) ( ( (byte) 0x01 << 7 ) | header );
+ }
+ return header;
+ }
+
+ private byte encodeResponseCode( ResponseCode responseCode, byte header )
+ {
+ byte fourBits = (byte) ( responseCode.getOrdinal() & 0x0F );
+ return (byte) ( fourBits | header );
}
}
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/protocol/DnsProtocolHandler.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/protocol/DnsProtocolHandler.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/protocol/DnsProtocolHandler.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/protocol/DnsProtocolHandler.java Sun Sep 18 12:47:47 2005
@@ -106,7 +106,7 @@
}
catch ( Exception e )
{
- log.error( e.getMessage() );
+ log.error( e.getMessage(), e );
}
}
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/BuildReply.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/BuildReply.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/BuildReply.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/BuildReply.java Sun Sep 18 12:47:47 2005
@@ -16,25 +16,21 @@
*/
package org.apache.dns.service;
-import java.net.InetAddress;
-
import org.apache.dns.chain.Context;
import org.apache.dns.chain.impl.CommandBase;
import org.apache.dns.messages.DnsMessage;
import org.apache.dns.messages.DnsMessageModifier;
import org.apache.dns.messages.MessageType;
import org.apache.dns.messages.OpCode;
+import org.apache.dns.messages.ResourceRecords;
import org.apache.dns.messages.ResponseCode;
-import org.apache.dns.records.ResourceRecord;
-import org.apache.dns.records.internet.AddressRecord;
-import org.apache.dns.store.RecordStoreEntry;
public class BuildReply extends CommandBase
{
public boolean execute( Context context ) throws Exception
{
DnsContext dnsContext = (DnsContext) context;
- RecordStoreEntry entry = dnsContext.getRecordEntry();
+ ResourceRecords records = dnsContext.getResourceRecords();
DnsMessage request = dnsContext.getRequest();
DnsMessageModifier modifier = new DnsMessageModifier();
@@ -51,18 +47,9 @@
modifier.setResponseCode( ResponseCode.NO_ERROR );
modifier.setQuestionRecords( request.getQuestionRecords() );
- String dnsName = entry.getDnsName();
- int dnsTtl = Integer.parseInt( entry.getDnsTtl() );
- byte[] dnsIpAddress = InetAddress.getByName( entry.getDnsIpAddress() ).getAddress();
-
- AddressRecord address = new AddressRecord( dnsName, dnsTtl, dnsIpAddress );
-
- ResourceRecord[] records = new ResourceRecord[ 1 ];
- records[ 0 ] = address;
-
modifier.setAnswerRecords( records );
- modifier.setAuthorityRecords( new ResourceRecord[0] );
- modifier.setAdditionalRecords( new ResourceRecord[0] );
+ modifier.setAuthorityRecords( new ResourceRecords() );
+ modifier.setAdditionalRecords( new ResourceRecords() );
dnsContext.setReply( modifier.getDnsMessage() );
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DnsContext.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DnsContext.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DnsContext.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DnsContext.java Sun Sep 18 12:47:47 2005
@@ -18,8 +18,9 @@
import org.apache.dns.chain.impl.ContextBase;
import org.apache.dns.messages.DnsMessage;
+import org.apache.dns.messages.ResourceRecord;
+import org.apache.dns.messages.ResourceRecords;
import org.apache.dns.store.RecordStore;
-import org.apache.dns.store.RecordStoreEntry;
public class DnsContext extends ContextBase
{
@@ -27,22 +28,22 @@
private RecordStore store;
private DnsMessage request;
private DnsMessage reply;
- private RecordStoreEntry recordEntry;
+ private ResourceRecords records = new ResourceRecords();
/**
* @return Returns the recordEntry.
*/
- public RecordStoreEntry getRecordEntry()
+ public ResourceRecords getResourceRecords()
{
- return recordEntry;
+ return records;
}
/**
- * @param recordEntry The recordEntry to set.
+ * @param resourceRecord The resourceRecord to add.
*/
- public void setRecordEntry( RecordStoreEntry recordEntry )
+ public void addResourceRecord( ResourceRecord resourceRecord )
{
- this.recordEntry = recordEntry;
+ this.records.add( resourceRecord );
}
/**
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DnsExceptionHandler.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DnsExceptionHandler.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DnsExceptionHandler.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DnsExceptionHandler.java Sun Sep 18 12:47:47 2005
@@ -24,8 +24,8 @@
import org.apache.dns.messages.DnsMessageModifier;
import org.apache.dns.messages.MessageType;
import org.apache.dns.messages.OpCode;
+import org.apache.dns.messages.ResourceRecords;
import org.apache.dns.messages.ResponseCode;
-import org.apache.dns.records.ResourceRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,7 +50,14 @@
DnsException de = (DnsException) exception;
DnsMessage message = dnsContext.getRequest();
- log.debug( de.getMessage() );
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( de.getMessage(), de );
+ }
+ else
+ {
+ log.info( de.getMessage() );
+ }
DnsMessageModifier modifier = new DnsMessageModifier();
@@ -65,9 +72,9 @@
modifier.setAcceptNonAuthenticatedData( false );
modifier.setResponseCode( ResponseCode.getTypeByOrdinal( de.getResponseCode() ) );
modifier.setQuestionRecords( message.getQuestionRecords() );
- modifier.setAnswerRecords( new ResourceRecord[ 0 ] );
- modifier.setAuthorityRecords( new ResourceRecord[ 0 ] );
- modifier.setAdditionalRecords( new ResourceRecord[ 0 ] );
+ modifier.setAnswerRecords( new ResourceRecords() );
+ modifier.setAuthorityRecords( new ResourceRecords() );
+ modifier.setAdditionalRecords( new ResourceRecords() );
dnsContext.setReply( modifier.getDnsMessage() );
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DomainNameServiceChain.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DomainNameServiceChain.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DomainNameServiceChain.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DomainNameServiceChain.java Sun Sep 18 12:47:47 2005
@@ -30,7 +30,6 @@
public DomainNameServiceChain()
{
- super();
addCommand( new DnsExceptionHandler() );
if ( log.isDebugEnabled() )
@@ -38,7 +37,7 @@
addCommand( new MonitorRequest() );
}
- addCommand( new GetRecordEntry() );
+ addCommand( new GetResourceRecords() );
if ( log.isDebugEnabled() )
{
Copied: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/GetResourceRecords.java (from r289702, directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/GetRecordEntry.java)
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/GetResourceRecords.java?p2=directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/GetResourceRecords.java&p1=directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/GetRecordEntry.java&r1=289702&r2=289962&rev=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/GetRecordEntry.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/GetResourceRecords.java Sun Sep 18 12:47:47 2005
@@ -16,48 +16,55 @@
*/
package org.apache.dns.service;
+import java.util.Iterator;
+
import org.apache.dns.DnsException;
import org.apache.dns.chain.Context;
import org.apache.dns.chain.impl.CommandBase;
+import org.apache.dns.messages.QuestionRecord;
+import org.apache.dns.messages.QuestionRecords;
+import org.apache.dns.messages.ResourceRecord;
import org.apache.dns.messages.ResponseCode;
-import org.apache.dns.records.QuestionRecord;
import org.apache.dns.store.RecordStore;
-import org.apache.dns.store.RecordStoreEntry;
import org.apache.dns.store.operations.GetRecord;
-public class GetRecordEntry extends CommandBase
+public class GetResourceRecords extends CommandBase
{
public boolean execute( Context context ) throws Exception
{
DnsContext dnsContext = (DnsContext) context;
RecordStore store = dnsContext.getStore();
- // TODO - handle more than 1 Question Record
- QuestionRecord question = dnsContext.getRequest().getQuestionRecords()[ 0 ];
+ QuestionRecords questions = dnsContext.getRequest().getQuestionRecords();
+
+ Iterator it = questions.iterator();
- dnsContext.setRecordEntry( getEntry( store, question ) );
+ while ( it.hasNext() )
+ {
+ dnsContext.addResourceRecord( getEntry( store, (QuestionRecord) it.next() ) );
+ }
return CONTINUE_CHAIN;
}
- public RecordStoreEntry getEntry( RecordStore store, QuestionRecord question ) throws Exception
+ public ResourceRecord getEntry( RecordStore store, QuestionRecord question ) throws Exception
{
- RecordStoreEntry entry = null;
+ ResourceRecord record = null;
try
{
- entry = (RecordStoreEntry) store.execute( new GetRecord( question ) );
+ record = (ResourceRecord) store.execute( new GetRecord( question ) );
}
catch ( Exception e )
{
throw new DnsException( ResponseCode.SERVER_FAILURE );
}
- if ( entry == null )
+ if ( record == null )
{
throw new DnsException( ResponseCode.NAME_ERROR );
}
- return entry;
+ return record;
}
}
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorContext.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorContext.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorContext.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorContext.java Sun Sep 18 12:47:47 2005
@@ -18,8 +18,8 @@
import org.apache.dns.chain.Context;
import org.apache.dns.chain.impl.CommandBase;
+import org.apache.dns.messages.ResourceRecords;
import org.apache.dns.store.RecordStore;
-import org.apache.dns.store.RecordStoreEntry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,16 +36,12 @@
{
DnsContext dnsContext = (DnsContext) context;
RecordStore store = dnsContext.getStore();
- RecordStoreEntry entry = dnsContext.getRecordEntry();
+ ResourceRecords records = dnsContext.getResourceRecords();
StringBuffer sb = new StringBuffer();
sb.append( "Monitoring context:" );
- sb.append( "\n\t" + "store " + store );
- sb.append( "\n\t" + "dnsClass " + entry.getDnsClass() );
- sb.append( "\n\t" + "dnsTtl " + entry.getDnsTtl() );
- sb.append( "\n\t" + "dnsZoneName " + entry.getDnsZoneName() );
- sb.append( "\n\t" + "dnsName " + entry.getDnsName() );
- sb.append( "\n\t" + "dnsIpAddress " + entry.getDnsIpAddress() );
+ sb.append( "\n\t" + "store: " + store );
+ sb.append( "\n\t" + "records: " + records );
log.debug( sb.toString() );
}
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorMessage.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorMessage.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorMessage.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorMessage.java Sun Sep 18 12:47:47 2005
@@ -20,8 +20,8 @@
import org.apache.dns.messages.DnsMessage;
import org.apache.dns.messages.MessageType;
import org.apache.dns.messages.OpCode;
+import org.apache.dns.messages.QuestionRecords;
import org.apache.dns.messages.ResponseCode;
-import org.apache.dns.records.QuestionRecord;
public abstract class MonitorMessage extends CommandBase
{
@@ -46,14 +46,9 @@
sb.append( "\n\t" + "reserved " + message.isReserved() );
sb.append( "\n\t" + "acceptNonAuthenticatedData " + message.isAcceptNonAuthenticatedData() );
- QuestionRecord[] questions = message.getQuestionRecords();
+ QuestionRecords questions = message.getQuestionRecords();
- for ( int ii = 0; ii < questions.length; ii++ )
- {
- sb.append( "\n\t" + "domain name " + questions[ ii ].getDomainName() );
- sb.append( "\n\t" + "record class " + questions[ ii ].getRecordClass() );
- sb.append( "\n\t" + "record type " + questions[ ii ].getRecordType() );
- }
+ sb.append( "\n\t" + "questions: " + questions );
return sb.toString();
}
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/DnsAttribute.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/DnsAttribute.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/DnsAttribute.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/DnsAttribute.java Sun Sep 18 12:47:47 2005
@@ -16,6 +16,12 @@
*/
package org.apache.dns.store;
+/**
+ * Constants representing the DNS attribute ids as defined by the Apache DNS schema.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class DnsAttribute
{
/**
@@ -30,14 +36,14 @@
* objectclasses for different record types
*/
+ /** the apachedns schema name for an apacheDnsAbstractRecord */
+ public static final String NAME = "apacheDnsName";
+ /** the apachedns schema type for an apacheDnsAbstractRecord */
+ public static final String TYPE = "apacheDnsType";
/** the apachedns schema class for an apacheDnsAbstractRecord */
public static final String CLASS = "apacheDnsClass";
/** the apachedns schema TTL for an apacheDnsAbstractRecord */
public static final String TTL = "apacheDnsTtl";
- /** the apachedns schema zone for an apacheDnsAbstractRecord */
- public static final String ZONE_NAME = "apacheDnsZoneName";
- /** the apachedns schema name for an apacheDnsAbstractRecord */
- public static final String NAME = "apacheDnsName";
/**
* DNS record type - Start of Authority
@@ -62,8 +68,15 @@
* Other DNS record attributes
*/
- /** the apachedns schema apacheDnsIpAddress */
- public static final String IP_ADDRESS = "apacheDnsIpAddress";
/** the apachedns schema apacheDnsDomainName */
public static final String DOMAIN_NAME = "apacheDnsDomainName";
+
+ /** the apachedns schema apacheDnsIpAddress */
+ public static final String IP_ADDRESS = "apacheDnsIpAddress";
+
+ /** the apachedns schema apacheDnsMxPreference */
+ public static final String MX_PREFERENCE = "apacheDnsMxPreference";
+
+ /** the apachedns schema apacheDnsCharacterString */
+ public static final String CHARACTER_STRING = "apacheDnsCharacterString";
}
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/JndiRecordStoreImpl.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/JndiRecordStoreImpl.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/JndiRecordStoreImpl.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/JndiRecordStoreImpl.java Sun Sep 18 12:47:47 2005
@@ -24,7 +24,7 @@
* based store.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
+ * @version $Rev$, $Date$
*/
public class JndiRecordStoreImpl implements RecordStore
{
@@ -51,25 +51,5 @@
public Object execute( ContextOperation operation ) throws Exception
{
return operation.execute( ctx, searchBase );
- }
-
- /**
- * Gets the LdapContext used to search for records in the JNDI store.
- *
- * @return the context for the search searchBase
- */
- protected LdapContext getContext()
- {
- return ctx;
- }
-
- /**
- * Gets the search base use for finding records in the the store.
- *
- * @return search base relative to the supplied context
- */
- protected Name getSearchBase()
- {
- return searchBase;
}
}
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStore.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStore.java?rev=289962&r1=289961&r2=289962&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStore.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStore.java Sun Sep 18 12:47:47 2005
@@ -16,7 +16,20 @@
*/
package org.apache.dns.store;
+/**
+ * Interface to support the command pattern with the record store.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public interface RecordStore
{
+ /**
+ * The command pattern execute method.
+ *
+ * @param operation The operation to execute
+ * @return Object The result returned by the operation
+ * @throws Exception The exception thrown by the operation
+ */
public Object execute( ContextOperation operation ) throws Exception;
}