You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2012/02/28 03:18:05 UTC

svn commit: r1294444 - in /directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/io/encoder: QuestionRecordEncoder.java ResourceRecordEncoder.java

Author: elecharny
Date: Tue Feb 28 02:18:04 2012
New Revision: 1294444

URL: http://svn.apache.org/viewvc?rev=1294444&view=rev
Log:
Fix for DIRSERVER-1093

Modified:
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/io/encoder/QuestionRecordEncoder.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/io/encoder/ResourceRecordEncoder.java

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/io/encoder/QuestionRecordEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/io/encoder/QuestionRecordEncoder.java?rev=1294444&r1=1294443&r2=1294444&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/io/encoder/QuestionRecordEncoder.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/io/encoder/QuestionRecordEncoder.java Tue Feb 28 02:18:04 2012
@@ -6,16 +6,16 @@
  *  to you 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. 
- *  
+ *  under the License.
+ * 
  */
 
 package org.apache.directory.server.dns.io.encoder;
@@ -24,6 +24,7 @@ package org.apache.directory.server.dns.
 import org.apache.directory.server.dns.messages.QuestionRecord;
 import org.apache.directory.server.dns.messages.RecordClass;
 import org.apache.directory.server.dns.messages.RecordType;
+import org.apache.directory.shared.util.Strings;
 import org.apache.mina.core.buffer.IoBuffer;
 
 
@@ -48,16 +49,21 @@ public class QuestionRecordEncoder
 
     private void encodeDomainName( IoBuffer byteBuffer, String domainName )
     {
-        String[] labels = domainName.split( "\\." );
-
-        for ( int ii = 0; ii < labels.length; ii++ )
+        if ( ! Strings.isEmpty( domainName ) )
         {
-            byteBuffer.put( ( byte ) labels[ii].length() );
+            String[] labels = domainName.split( "\\." );
+        
 
-            char[] characters = labels[ii].toCharArray();
-            for ( int jj = 0; jj < characters.length; jj++ )
+            for ( String label : labels )
             {
-                byteBuffer.put( ( byte ) characters[jj] );
+                byteBuffer.put( ( byte ) label.length() );
+    
+                char[] characters = label.toCharArray();
+                
+                for ( char c : characters )
+                {
+                    byteBuffer.put( ( byte ) c );
+                }
             }
         }
 

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/io/encoder/ResourceRecordEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/io/encoder/ResourceRecordEncoder.java?rev=1294444&r1=1294443&r2=1294444&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/io/encoder/ResourceRecordEncoder.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/io/encoder/ResourceRecordEncoder.java Tue Feb 28 02:18:04 2012
@@ -6,16 +6,16 @@
  *  to you 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. 
- *  
+ *  under the License.
+ * 
  */
 
 package org.apache.directory.server.dns.io.encoder;
@@ -26,6 +26,7 @@ import java.io.IOException;
 import org.apache.directory.server.dns.messages.RecordClass;
 import org.apache.directory.server.dns.messages.RecordType;
 import org.apache.directory.server.dns.messages.ResourceRecord;
+import org.apache.directory.shared.util.Strings;
 import org.apache.mina.core.buffer.IoBuffer;
 
 
@@ -80,16 +81,21 @@ public abstract class ResourceRecordEnco
      */
     protected void putDomainName( IoBuffer byteBuffer, String domainName )
     {
-        String[] labels = domainName.split( "\\." );
-
-        for ( int ii = 0; ii < labels.length; ii++ )
+        if ( ! Strings.isEmpty( domainName ) )
         {
-            byteBuffer.put( ( byte ) labels[ii].length() );
+            String[] labels = domainName.split( "\\." );
+        
 
-            char[] characters = labels[ii].toCharArray();
-            for ( int jj = 0; jj < characters.length; jj++ )
+            for ( String label : labels )
             {
-                byteBuffer.put( ( byte ) characters[jj] );
+                byteBuffer.put( ( byte ) label.length() );
+    
+                char[] characters = label.toCharArray();
+                
+                for ( char c : characters )
+                {
+                    byteBuffer.put( ( byte ) c );
+                }
             }
         }