directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r125015 - incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol
Date Thu, 13 Jan 2005 01:48:06 GMT
Author: erodriguez
Date: Wed Jan 12 17:48:04 2005
New Revision: 125015

URL: http://svn.apache.org/viewcvs?view=rev&rev=125015
Log:
MINA frontend for DNS.  Tested with dig on FC2.
Added:
   incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsDecoder.java
   incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsEncoder.java
   incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsProtocolHandler.java
   incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsProtocolProvider.java

Added: incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsDecoder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsDecoder.java?view=auto&rev=125015
==============================================================================
--- (empty file)
+++ incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsDecoder.java
Wed Jan 12 17:48:04 2005
@@ -0,0 +1,37 @@
+/*
+ *   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.protocol;
+
+import org.apache.dns.io.DnsMessageDecoder;
+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;
+
+
+public class DnsDecoder implements ProtocolDecoder
+{
+    public void decode( ProtocolSession session, ByteBuffer in, ProtocolDecoderOutput out
)
+            throws ProtocolViolationException
+    {
+    	 DnsMessageDecoder decoder = new DnsMessageDecoder();
+    	 out.write( decoder.decode( in.buf() ) );
+    }
+}
+

Added: incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsEncoder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsEncoder.java?view=auto&rev=125015
==============================================================================
--- (empty file)
+++ incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsEncoder.java
Wed Jan 12 17:48:04 2005
@@ -0,0 +1,44 @@
+/*
+ *   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.protocol;
+
+import org.apache.dns.io.DnsMessageEncoder;
+import org.apache.dns.messages.DnsMessage;
+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;
+
+
+public class DnsEncoder implements ProtocolEncoder
+{
+    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 );
+        
+        buf.flip();
+        
+        out.write( buf );
+    }
+}
+

Added: incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsProtocolHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsProtocolHandler.java?view=auto&rev=125015
==============================================================================
--- (empty file)
+++ incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsProtocolHandler.java
Wed Jan 12 17:48:04 2005
@@ -0,0 +1,63 @@
+/*
+ *   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.protocol;
+
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.protocol.ProtocolHandler;
+import org.apache.mina.protocol.ProtocolSession;
+
+
+public class DnsProtocolHandler implements ProtocolHandler
+{
+
+    public void sessionOpened( ProtocolSession session )
+    {
+        System.out.println( session.getRemoteAddress() + " OPENED" );
+    }
+
+    public void sessionClosed( ProtocolSession session )
+    {
+        System.out.println( session.getRemoteAddress() + " CLOSED" );
+    }
+
+    public void sessionIdle( ProtocolSession session, IdleStatus status )
+    {
+        System.out.println( session.getRemoteAddress() + " IDLE(" + status + ")" );
+    }
+
+    public void exceptionCaught( ProtocolSession session, Throwable cause )
+    {
+        System.out.println( session.getRemoteAddress() + " EXCEPTION" );
+        cause.printStackTrace( System.out );
+
+        session.close();
+    }
+
+    public void messageReceived( ProtocolSession session, Object message )
+    {
+        System.out.println( session.getRemoteAddress() + " RCVD: " + message );
+        
+        session.write( message );
+    }
+
+    public void messageSent( ProtocolSession session, Object message )
+    {
+        System.out.println( session.getRemoteAddress() + " SENT: " + message );
+    }
+}
+

Added: incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsProtocolProvider.java
Url: http://svn.apache.org/viewcvs/incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsProtocolProvider.java?view=auto&rev=125015
==============================================================================
--- (empty file)
+++ incubator/directory/dns/trunk/protocol/src/java/org/apache/dns/protocol/DnsProtocolProvider.java
Wed Jan 12 17:48:04 2005
@@ -0,0 +1,58 @@
+/*
+ *   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.protocol;
+
+import org.apache.mina.protocol.ProtocolCodecFactory;
+import org.apache.mina.protocol.ProtocolDecoder;
+import org.apache.mina.protocol.ProtocolEncoder;
+import org.apache.mina.protocol.ProtocolHandler;
+import org.apache.mina.protocol.ProtocolProvider;
+
+
+public class DnsProtocolProvider implements ProtocolProvider
+{
+    // Protocol handler is usually a singleton.
+    private static ProtocolHandler HANDLER = new DnsProtocolHandler();
+
+    // Codec factory is also usually a singleton.
+    private static ProtocolCodecFactory CODEC_FACTORY = new ProtocolCodecFactory()
+    {
+        public ProtocolEncoder newEncoder()
+        {
+            // Create a new encoder.
+            return new DnsEncoder();
+        }
+
+        public ProtocolDecoder newDecoder()
+        {
+            // Create a new decoder.
+            return new DnsDecoder();
+        }
+    };
+
+    public ProtocolCodecFactory getCodecFactory()
+    {
+        return CODEC_FACTORY;
+    }
+
+    public ProtocolHandler getHandler()
+    {
+        return HANDLER;
+    }
+}
+

Mime
View raw message