directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r620585 - /directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/
Date Mon, 11 Feb 2008 19:24:21 GMT
Author: akarasulu
Date: Mon Feb 11 11:24:19 2008
New Revision: 620585

URL: http://svn.apache.org/viewvc?rev=620585&view=rev
Log:
DIRSERVER-1128: SLP codec patch from Jan S. Rellermeyer

Added:
    directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/
    directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AbstractSLPMessageCodec.java
    directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AttributeReplyMessageCodec.java
    directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AttributeRequestMessageCodec.java
    directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/DAAdvertisementMessageCodec.java
    directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/SLPProtocolCodecFactory.java
    directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceAcknowledgementMessageCodec.java
    directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceDeregistrationMessageCodec.java
    directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceRegistrationMessageCodec.java
    directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceReplyMessageCodec.java
    directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceRequestMessageCodec.java
    directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceTypeReplyMessageCodec.java
    directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceTypeRequestMessageCodec.java

Added: directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AbstractSLPMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AbstractSLPMessageCodec.java?rev=620585&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AbstractSLPMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AbstractSLPMessageCodec.java Mon Feb 11 11:24:19 2008
@@ -0,0 +1,330 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  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. 
+ *  
+ */
+package org.apache.directory.server.slp.codec;
+
+import java.io.IOException;
+import java.net.ProtocolException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.TransportType;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.apache.mina.filter.codec.demux.MessageDecoder;
+import org.apache.mina.filter.codec.demux.MessageDecoderResult;
+import org.apache.mina.filter.codec.demux.MessageEncoder;
+
+import org.apache.directory.server.slp.ServiceLocationException;
+import org.apache.directory.server.slp.ServiceURL;
+import org.apache.directory.server.slp.impl.AuthenticationBlock;
+import org.apache.directory.server.slp.messages.AbstractSLPMessage;
+
+/**
+ * <pre>
+ *                   0                   1                   2                   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
+ *                  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *                  |    Version    |  Function-ID  |            Length             |
+ *                  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *                  | Length, contd.|O|F|R|       reserved          |Next Ext Offset|
+ *                  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *                  |  Next Extension Offset, contd.|              XID              |
+ *                  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *                  |      Language Tag Length      |         Language Tag          \
+ *                  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>
+ * 
+ * @author Jan S. Rellermeyer, ETH Zurich
+ * 
+ */
+public abstract class AbstractSLPMessageCodec implements MessageDecoder,
+		MessageEncoder {
+
+	private static Charset CHARSET = Charset.forName("UTF-8");
+
+	protected static CharsetDecoder DECODER = CHARSET.newDecoder();
+
+	protected static CharsetEncoder ENCODER = CHARSET.newEncoder();
+
+	private final byte type;
+
+	public AbstractSLPMessageCodec(final byte type) {
+		this.type = type;
+	}
+
+	public MessageDecoderResult decodable(IoSession session, ByteBuffer in) {
+		if (in.remaining() < 2) {
+			return MessageDecoderResult.NEED_DATA;
+		}
+		final int version = in.get(); // version
+		if (version == 1) {
+			return MessageDecoderResult.NOT_OK;
+		}
+		final byte funcID = in.get(); // funcID
+		final int len = (in.get() & 0xff) << 16 + (in.get() & 0xff) << 8 + (in
+				.get() & 0xff);
+		if (in.remaining() < len - 5) {
+			return MessageDecoderResult.NEED_DATA;
+		}
+		return funcID == type ? MessageDecoderResult.OK
+				: MessageDecoderResult.NOT_OK;
+	}
+
+	public MessageDecoderResult decode(IoSession session, ByteBuffer in,
+			ProtocolDecoderOutput out) throws Exception {
+		try {
+			in.skip(5); // version and funcID are already parsed
+
+			byte flags = (byte) (in.getShort() >> 8);
+			if (session.getTransportType().equals(TransportType.DATAGRAM)
+					&& (flags & 0x80) != 0) {
+				throw new ProtocolException(
+						"Multicast message does not have the correct flag set.");
+			}
+
+			// we don't process extensions, we simply ignore them
+			// TODO: clean extensions from the pipe
+			in.skip(3); // extOffset
+
+			final short xid = in.getShort(); // XID
+
+			final Locale locale = new Locale(decodeString(in), "");
+
+			final AbstractSLPMessage msg = decodeBody(session, in, out);
+			msg.setXid(xid);
+			msg.setLocale(locale);
+			msg.setTcp(true);
+			msg.setMulticast(((flags & 0x2000) >> 13) == 1 ? true : false);
+
+			out.write(msg);
+
+			return MessageDecoderResult.OK;
+		} catch (Exception t) {
+			t.printStackTrace();
+			throw t;
+		}
+	}
+
+	protected final void encodeString(final ByteBuffer out, final String s)
+			throws IOException {
+		out.putShort((short) s.length());
+		out.putString(s, ENCODER);
+	}
+
+	protected final String decodeString(final ByteBuffer in) throws IOException {
+		final short len = in.getShort();
+		return in.getString(len, DECODER);
+	}
+
+	protected abstract AbstractSLPMessage decodeBody(final IoSession session,
+			final ByteBuffer in, final ProtocolDecoderOutput out)
+			throws Exception;
+
+	public void finishDecode(IoSession session, ProtocolDecoderOutput out)
+			throws Exception {
+		// TODO Auto-generated method stub
+
+	}
+
+	/**
+	 * Reads a byte stream from a DataInput and constructs a ServiceURL from it,
+	 * following the RFC 2608 schema:
+	 * <p>
+	 * 
+	 * <pre>
+	 *    0                   1                   2                   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
+	 *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+	 *   |   Reserved    |          Lifetime             |   URL Length  |
+	 *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+	 *   |URL len, contd.|            URL (variable length)              \
+	 *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+	 *   |# of URL auths |            Auth. blocks (if any)              \
+	 *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+	 * </pre>.
+	 * </p>
+	 * 
+	 * @param input
+	 *            the DataInput streaming the ServiceURL bytes.
+	 * @return a ServiceURL instance.
+	 * @throws ServiceLocationException
+	 *             in case of IO exceptions.
+	 * @throws IOException
+	 */
+	protected final ServiceURL decodeServiceURL(final IoSession session,
+			final ByteBuffer in) throws Exception {
+		in.skip(1); // reserved
+		final short lifetime = in.getShort(); // Lifetime
+		final ServiceURL result = new ServiceURL(decodeString(in), lifetime);
+		result.setAuthBlocks(decodeAuthBlocks(session, in));
+		result.verify();
+		return result;
+	}
+
+	protected final void encodeServiceURL(final ServiceURL url,
+			final IoSession session, final ByteBuffer out) throws Exception {
+		out.skip(1);
+		out.putShort((short) url.getLifetime());
+		encodeString(out, url.toString());
+		encodeAuthBlocks(url.getAuthBlocks(), session, out);
+	}
+
+	/**
+	 * 0 1 2 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
+	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Block
+	 * Structure Descriptor | Authentication Block Length |
+	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
+	 * Timestamp |
+	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | SLP
+	 * SPI String Length | SLP SPI String \
+	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
+	 * Structured Authentication Block ... \
+	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+	 * 
+	 * @param session
+	 * @param in
+	 * @return
+	 */
+	protected final AuthenticationBlock[] decodeAuthBlocks(
+			final IoSession session, final ByteBuffer in) throws Exception {
+		final short blocks = (short) in.get();
+		final AuthenticationBlock[] result = new AuthenticationBlock[blocks];
+		for (int i = 0; i < blocks; i++) {
+			final short bsd = (short) in.getShort();
+			if (bsd != AuthenticationBlock.BSD_DSA) {
+				throw new ServiceLocationException(
+						ServiceLocationException.AUTHENTICATION_FAILED, "BSD "
+								+ bsd + " is not supported.");
+			}
+			final int size = in.getShort();
+			final int timestamp = in.getInt();
+			final String spi = decodeString(in);
+			final byte[] sig = new byte[size - 2 - 2 - 4 - 2
+					- spi.getBytes().length];
+			in.get(sig);
+			result[i] = new AuthenticationBlock(timestamp, spi, sig);
+		}
+
+		// return SLPCore.CONFIG.getSecurityEnabled() ? result
+		// : new AuthenticationBlock[0];
+		return result;
+	}
+
+	protected final void encodeAuthBlocks(
+			final AuthenticationBlock[] authBlocks, final IoSession session,
+			final ByteBuffer out) throws Exception {
+		// FIXME: hack
+		if (authBlocks == null) {
+			out.put((byte) 0);
+			return;
+		}
+		out.put((byte) authBlocks.length);
+		for (int i = 0; i < authBlocks.length; i++) {
+			final int pos = out.position();
+			out.putShort(AuthenticationBlock.BSD_DSA); // BSD
+			out.skip(2); // skip the length field
+			out.putInt(authBlocks[i].getTimestamp());
+			encodeString(out, authBlocks[i].getSpi());
+			out.put(authBlocks[i].getSig());
+			// fill in the length
+			out.putShort(pos + 2, (short) (out.position() - pos));
+		}
+	}
+
+	public final static String[] stringToArray(final String str) {
+		final StringTokenizer tokenizer = new StringTokenizer(str, ",");
+		final String[] result = new String[tokenizer.countTokens()];
+		for (int i = 0; i < result.length; i++) {
+			result[i] = tokenizer.nextToken();
+		}
+		return result;
+	}
+
+	public final static String arrayToString(final String[] strs) {
+		if (strs.length == 0) {
+			return "";
+		}
+		final StringBuffer buffer = new StringBuffer();
+		for (int i = 0; i < strs.length - 1; i++) {
+			buffer.append(strs[i]);
+			buffer.append(',');
+		}
+		buffer.append(strs[strs.length - 1]);
+		return buffer.toString();
+	}
+
+	// Encoder part
+
+	/**
+	 * Encodes higher-level message objects into binary or protocol-specific
+	 * data. MINA invokes
+	 * {@link #encode(IoSession, Object, ProtocolEncoderOutput)} method with
+	 * message which is popped from the session write queue, and then the
+	 * encoder implementation puts encoded {@link ByteBuffer}s into
+	 * {@link ProtocolEncoderOutput}.
+	 * 
+	 * @throws Exception
+	 *             if the message violated protocol specification
+	 */
+	public void encode(IoSession session, Object message,
+			ProtocolEncoderOutput out) throws Exception {
+		AbstractSLPMessage msg = (AbstractSLPMessage) message;
+		final ByteBuffer buf = ByteBuffer.allocate(128);
+		buf.setAutoExpand(true); // Enable auto-expand for easier encoding
+
+		buf.put((byte) 2); // version
+		buf.put(type); // funcID
+		buf.skip(3); // size will be filled in later
+		// TODO: fix the flags
+		/*
+		 * if (msg .funcID == SRVREG) { flags |= 0x40; }
+		 */
+		byte flags = 0;
+		if (msg.isMulticast()) {
+			flags |= 0x20;
+		}
+		/*
+		 * if (!msg.isTcp() && msg.getSize() > SLPCore.CONFIG.getMTU()) { flags |=
+		 * 0x80; }
+		 */
+		buf.put(flags);
+		buf.skip(1); // reserved
+		buf.skip(3); // extensions // TODO: process the extensions
+		buf.putShort(msg.getXid()); // XID
+		encodeString(buf, msg.getLocale().getLanguage()); // language tag
+		encodeBody(session, msg, buf);
+		// fill in the message length
+		final int len = buf.position();
+		buf.put(2, (byte) (len >> 16));
+		buf.put(3, (byte) ((len >> 8) & 0xFF));
+		buf.put(4, (byte) ((len) & 0xFF));
+		buf.flip();
+		out.write(buf);
+	}
+
+	protected abstract void encodeBody(final IoSession session,
+			final AbstractSLPMessage msg, final ByteBuffer buf)
+			throws Exception;
+}

Added: directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AttributeReplyMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AttributeReplyMessageCodec.java?rev=620585&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AttributeReplyMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AttributeReplyMessageCodec.java Mon Feb 11 11:24:19 2008
@@ -0,0 +1,87 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  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. 
+ *  
+ */
+package org.apache.directory.server.slp.codec;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.directory.server.slp.messages.AttributeReplyMessage;
+import org.apache.directory.server.slp.messages.AbstractSLPMessage;
+
+/**
+ * 
+ * <pre>
+ *    0                   1                   2                   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
+ *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *   |       Service Location header (function = AttrRply = 7)       |
+ *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *   |         Error Code            |      length of &lt;attr-list&gt;    |
+ *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *   |                         &lt;attr-list&gt;                           \
+ *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *   |# of AttrAuths |  Attribute Authentication Block (if present)  \
+ *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * 
+ * @author Jan S. Rellermeyer, ETH Zurich
+ * 
+ */
+public class AttributeReplyMessageCodec extends AbstractSLPMessageCodec {
+
+	private static final Set MESSAGE_TYPE;
+
+	static {
+		MESSAGE_TYPE = Collections.unmodifiableSet(new HashSet(Arrays
+				.asList(new Class[] { AttributeReplyMessage.class })));
+	}
+
+	public AttributeReplyMessageCodec() {
+		super(AttributeReplyMessage.FUNC_ID);
+	}
+
+	protected AbstractSLPMessage decodeBody(IoSession session, ByteBuffer in,
+			ProtocolDecoderOutput out) throws Exception {
+		final AttributeReplyMessage msg = new AttributeReplyMessage();
+		msg.setErrorCode(in.getShort());
+		msg.setAttributes(stringToArray(decodeString(in)));
+		msg.setAuthBlocks(decodeAuthBlocks(session, in));
+		msg.verify();
+		return msg;
+	}
+
+	protected void encodeBody(IoSession session, AbstractSLPMessage msg,
+			ByteBuffer out) throws Exception {
+		final AttributeReplyMessage message = (AttributeReplyMessage) msg;
+		out.putShort(message.getErrorCode());
+		encodeString(out, arrayToString(message.getAttributes()));
+		encodeAuthBlocks(message.getAuthBlocks(), session, out);
+	}
+
+	public Set getMessageTypes() {
+		return MESSAGE_TYPE;
+	}
+
+}

Added: directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AttributeRequestMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AttributeRequestMessageCodec.java?rev=620585&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AttributeRequestMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/AttributeRequestMessageCodec.java Mon Feb 11 11:24:19 2008
@@ -0,0 +1,92 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  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. 
+ *  
+ */
+package org.apache.directory.server.slp.codec;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.directory.server.slp.messages.AttributeRequestMessage;
+import org.apache.directory.server.slp.messages.AbstractSLPMessage;
+
+/**
+ * <pre>
+ *   0                   1                   2                   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
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |       Service Location header (function = AttrRqst = 6)       |
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |       length of PRList        |        &lt;PRList&gt; String        \
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |         length of URL         |              URL              \
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |    length of &lt;scope-list&gt;     |      &lt;scope-list&gt; string      \
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |  length of &lt;tag-list&gt; string  |       &lt;tag-list&gt; string       \
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |   length of &lt;SLP SPI&gt; string  |        &lt;SLP SPI&gt; string       \
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * 
+ * @author Jan S. Rellermeyer, ETH Zurich
+ * 
+ */
+public class AttributeRequestMessageCodec extends AbstractSLPMessageCodec {
+
+	public AttributeRequestMessageCodec() {
+		super(AttributeRequestMessage.FUNC_ID);
+	}
+
+	private static final Set MESSAGE_TYPE;
+
+	static {
+		MESSAGE_TYPE = Collections.unmodifiableSet(new HashSet(Arrays
+				.asList(new Class[] { AttributeRequestMessage.class })));
+	}
+
+	protected AbstractSLPMessage decodeBody(IoSession session, ByteBuffer in,
+			ProtocolDecoderOutput out) throws Exception {
+		final AttributeRequestMessage msg = new AttributeRequestMessage();
+		msg.setPrevResponders(stringToArray(decodeString(in)));
+		msg.setServiceURL(decodeServiceURL(session, in));
+		msg.setScopes(stringToArray(decodeString(in)));
+		msg.setTags(stringToArray(decodeString(in)));
+		msg.setSpis(stringToArray(decodeString(in)));
+		return msg;
+	}
+
+	protected void encodeBody(IoSession session, AbstractSLPMessage msg,
+			ByteBuffer buf) throws Exception {
+		final AttributeRequestMessage req = (AttributeRequestMessage) msg;
+		encodeString(buf, arrayToString(req.getPrevResponders()));
+		encodeServiceURL(req.getServiceUrl(), session, buf);
+		encodeString(buf, arrayToString(req.getScopes()));
+		encodeString(buf, arrayToString(req.getTags()));
+		encodeString(buf, arrayToString(req.getSpis()));
+	}
+
+	public Set getMessageTypes() {
+		return MESSAGE_TYPE;
+	}
+
+}

Added: directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/DAAdvertisementMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/DAAdvertisementMessageCodec.java?rev=620585&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/DAAdvertisementMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/DAAdvertisementMessageCodec.java Mon Feb 11 11:24:19 2008
@@ -0,0 +1,102 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  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. 
+ *  
+ */
+package org.apache.directory.server.slp.codec;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+import org.apache.directory.server.slp.messages.DAAdvertisementMessage;
+import org.apache.directory.server.slp.messages.AbstractSLPMessage;
+
+/**
+ * <pre>
+ *  0                   1                   2                   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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |        Service Location header (function = DAAdvert = 8)      |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |          Error Code           |  DA Stateless Boot Timestamp  |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |DA Stateless Boot Time,, contd.|         Length of URL         |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * \                              URL                              \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |     Length of &lt;scope-list&gt;    |         &lt;scope-list&gt;          \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |     Length of &lt;attr-list&gt;     |          &lt;attr-list&gt;          \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |    Length of &lt;SLP SPI List&gt;   |     &lt;SLP SPI List&gt; String     \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | # Auth Blocks |         Authentication block (if any)         \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * 
+ * @author Jan S. Rellermeyer, ETH Zurich
+ *
+ */
+public class DAAdvertisementMessageCodec extends AbstractSLPMessageCodec {
+
+    private static final Set MESSAGE_TYPE;
+
+    static {
+        MESSAGE_TYPE = Collections.unmodifiableSet(new HashSet(Arrays
+                .asList(new Class[] { DAAdvertisementMessage.class })));
+    }
+
+    public DAAdvertisementMessageCodec() {
+        super(DAAdvertisementMessage.FUNC_ID);
+    }
+
+    protected AbstractSLPMessage decodeBody(IoSession session, ByteBuffer in,
+            ProtocolDecoderOutput out) throws Exception {
+        final DAAdvertisementMessage msg = new DAAdvertisementMessage();
+        msg.setErrorCode(in.getShort());
+        msg.setStatelessBootTimestamp(in.getInt());
+        msg.setServiceURL(decodeServiceURL(session, in));
+        msg.setScopes(stringToArray(decodeString(in)));
+        msg.setAttributes(stringToArray(decodeString(in)));
+        msg.setSPIs(stringToArray(decodeString(in)));
+        msg.setAuthBlocks(decodeAuthBlocks(session, in));
+        return msg;
+    }
+
+    protected void encodeBody(IoSession session, AbstractSLPMessage message,
+            ByteBuffer buf) throws Exception {
+        final DAAdvertisementMessage msg = (DAAdvertisementMessage) message;
+        buf.putShort(msg.getErrorCode());
+        buf.putInt(msg.getStatelessBootTimestamp());
+        encodeServiceURL(msg.getServiceURL(), session, buf);
+        encodeString(buf, arrayToString(msg.getScopes()));
+        encodeString(buf, arrayToString(msg.getAttributes()));
+        encodeString(buf, arrayToString(msg.getSPIs()));
+        encodeAuthBlocks(msg.getAuthBlocks(), session, buf);
+    }
+
+    public Set getMessageTypes() {
+        return MESSAGE_TYPE;
+    }
+
+}

Added: directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/SLPProtocolCodecFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/SLPProtocolCodecFactory.java?rev=620585&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/SLPProtocolCodecFactory.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/SLPProtocolCodecFactory.java Mon Feb 11 11:24:19 2008
@@ -0,0 +1,45 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  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. 
+ *  
+ */
+package org.apache.directory.server.slp.codec;
+
+import org.apache.mina.filter.codec.demux.DemuxingProtocolCodecFactory;
+
+/**
+ * Protocol codec factory for the SLP protocol.
+ * 
+ * @author Jan S. Rellermeyer, ETH Zurich
+ * 
+ */
+public class SLPProtocolCodecFactory extends DemuxingProtocolCodecFactory {
+
+	public SLPProtocolCodecFactory() {
+		register(AttributeReplyMessageCodec.class);
+		register(AttributeRequestMessageCodec.class);
+		register(DAAdvertisementMessageCodec.class);
+		register(ServiceAcknowledgementMessageCodec.class);
+		register(ServiceDeregistrationMessageCodec.class);
+		register(ServiceRegistrationMessageCodec.class);
+		register(ServiceReplyMessageCodec.class);
+		register(ServiceRequestMessageCodec.class);
+		register(ServiceTypeReplyMessageCodec.class);
+		register(ServiceTypeRequestMessageCodec.class);
+	}
+
+}

Added: directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceAcknowledgementMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceAcknowledgementMessageCodec.java?rev=620585&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceAcknowledgementMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceAcknowledgementMessageCodec.java Mon Feb 11 11:24:19 2008
@@ -0,0 +1,78 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  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. 
+ *  
+ */
+package org.apache.directory.server.slp.codec;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+import org.apache.directory.server.slp.messages.AbstractSLPMessage;
+import org.apache.directory.server.slp.messages.ServiceAcknowledgementMessage;
+
+/**
+ * <pre>
+ *       0                   1                   2                   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
+ *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *      |          Service Location header (function = SrvAck = 5)      |
+ *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *      |          Error Code           |
+ *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * 
+ * @author Jan S. Rellermeyer, ETH Zurich
+ *
+ */
+public class ServiceAcknowledgementMessageCodec extends AbstractSLPMessageCodec {
+
+    private static final Set MESSAGE_TYPE;
+
+    static {
+        MESSAGE_TYPE = Collections.unmodifiableSet(new HashSet(Arrays
+                .asList(new Class[] { ServiceAcknowledgementMessage.class })));
+    }
+
+    public ServiceAcknowledgementMessageCodec() {
+        super(ServiceAcknowledgementMessage.FUNC_ID);
+    }
+
+    protected AbstractSLPMessage decodeBody(IoSession session, ByteBuffer in,
+            ProtocolDecoderOutput out) throws Exception {
+        final ServiceAcknowledgementMessage msg = new ServiceAcknowledgementMessage();
+        msg.setErrorCode(in.getShort());
+        return msg;
+    }
+
+    protected void encodeBody(IoSession session, AbstractSLPMessage msg, ByteBuffer buf)
+            throws Exception {
+        final ServiceAcknowledgementMessage ack = (ServiceAcknowledgementMessage) msg;
+        buf.putShort(ack.getErrorCode());
+    }
+
+    public Set getMessageTypes() {
+        return MESSAGE_TYPE;
+    }
+
+}

Added: directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceDeregistrationMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceDeregistrationMessageCodec.java?rev=620585&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceDeregistrationMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceDeregistrationMessageCodec.java Mon Feb 11 11:24:19 2008
@@ -0,0 +1,84 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  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. 
+ *  
+ */
+package org.apache.directory.server.slp.codec;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.directory.server.slp.messages.AbstractSLPMessage;
+import org.apache.directory.server.slp.messages.ServiceDeregistrationMessage;
+
+/**
+ * <pre>
+ *  0                   1                   2                   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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |         Service Location header (function = SrvDeReg = 4)     |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |    Length of &lt;scope-list&gt;     |         &lt;scope-list&gt;          \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |                           URL Entry                           \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |      Length of &lt;tag-list&gt;     |            &lt;tag-list&gt;         \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>. 
+ * 
+ * @author Jan S. Rellermeyer, ETH Zurich
+ *
+ */
+public class ServiceDeregistrationMessageCodec extends AbstractSLPMessageCodec {
+
+    private static final Set MESSAGE_TYPE;
+
+    static {
+        MESSAGE_TYPE = Collections.unmodifiableSet(new HashSet(Arrays
+                .asList(new Class[] { ServiceDeregistrationMessage.class })));
+    }
+
+    public ServiceDeregistrationMessageCodec() {
+        super(ServiceDeregistrationMessage.FUNC_ID);
+    }
+
+    protected AbstractSLPMessage decodeBody(IoSession session, ByteBuffer in,
+            ProtocolDecoderOutput out) throws Exception {
+        final ServiceDeregistrationMessage msg = new ServiceDeregistrationMessage();
+        msg.setScopes(stringToArray(decodeString(in)));
+        msg.setServiceURL(decodeServiceURL(session, in));
+        msg.setTags(stringToArray(decodeString(in)));
+        return msg;
+    }
+
+    protected void encodeBody(IoSession session, AbstractSLPMessage msg, ByteBuffer buf)
+            throws Exception {
+        final ServiceDeregistrationMessage sdreg = (ServiceDeregistrationMessage) msg;
+        encodeString(buf, arrayToString(sdreg.getScopes()));
+        encodeServiceURL(sdreg.getServiceURL(), session, buf);
+        encodeString(buf, arrayToString(sdreg.getTags()));
+    }
+
+    public Set getMessageTypes() {
+        return MESSAGE_TYPE;
+    }
+
+}

Added: directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceRegistrationMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceRegistrationMessageCodec.java?rev=620585&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceRegistrationMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceRegistrationMessageCodec.java Mon Feb 11 11:24:19 2008
@@ -0,0 +1,99 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  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. 
+ *  
+ */
+package org.apache.directory.server.slp.codec;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.directory.server.slp.ServiceType;
+import org.apache.directory.server.slp.messages.AbstractSLPMessage;
+import org.apache.directory.server.slp.messages.ServiceRegistrationMessage;
+
+/**
+ * Encodes and decodes a service registration message with the following body:
+ * <p>
+ * 
+ * <pre>
+ *         0                   1                   2                   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
+ *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *        |         Service Location header (function = SrvReg = 3)       |
+ *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *        |                          &lt;URL-Entry&gt;                          \
+ *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *        | length of service type string |        &lt;service-type&gt;         \
+ *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *        |     length of &lt;scope-list&gt;    |         &lt;scope-list&gt;          \
+ *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *        |  length of attr-list string   |          &lt;attr-list&gt;          \
+ *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *        |# of AttrAuths |(if present) Attribute Authentication Blocks...\
+ *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * </p>
+ * 
+ * @author Jan S. Rellermeyer, ETH Zurich
+ * 
+ */
+public class ServiceRegistrationMessageCodec extends AbstractSLPMessageCodec {
+
+    private static final Set MESSAGE_TYPE;
+
+    static {
+        MESSAGE_TYPE = Collections.unmodifiableSet(new HashSet(Arrays
+                .asList(new Class[] { ServiceRegistrationMessage.class })));
+    }
+
+    public ServiceRegistrationMessageCodec() {
+        super(ServiceRegistrationMessage.FUNC_ID);
+    }
+
+    protected AbstractSLPMessage decodeBody(IoSession session, ByteBuffer in,
+            ProtocolDecoderOutput out) throws Exception {
+        final ServiceRegistrationMessage msg = new ServiceRegistrationMessage();
+        msg.setServiceURL(decodeServiceURL(session, in));
+        msg.setServiceType(new ServiceType(decodeString(in)));
+        msg.setScopes(stringToArray(decodeString(in)));
+        msg.setAttrList(stringToArray(decodeString(in)));
+        msg.setAuthBlocks(decodeAuthBlocks(session, in));
+        msg.verify();
+        return msg;
+    }
+
+    protected void encodeBody(IoSession session, AbstractSLPMessage msg, ByteBuffer buf)
+            throws Exception {
+        final ServiceRegistrationMessage sreg = (ServiceRegistrationMessage) msg;
+        encodeServiceURL(sreg.getServiceURL(), session, buf);
+        encodeString(buf, sreg.getServiceType().toString());
+        encodeString(buf, arrayToString(sreg.getScopes()));
+        encodeString(buf, arrayToString(sreg.getAttrList()));
+        encodeAuthBlocks(sreg.getAuthBlocks(), session, buf);
+    }
+
+    public Set getMessageTypes() {
+        return MESSAGE_TYPE;
+    }
+
+}

Added: directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceReplyMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceReplyMessageCodec.java?rev=620585&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceReplyMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceReplyMessageCodec.java Mon Feb 11 11:24:19 2008
@@ -0,0 +1,93 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  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. 
+ *  
+ */
+package org.apache.directory.server.slp.codec;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+import org.apache.directory.server.slp.ServiceURL;
+import org.apache.directory.server.slp.messages.AbstractSLPMessage;
+import org.apache.directory.server.slp.messages.ServiceReplyMessage;
+
+/**
+ * <pre>
+ *  0                   1                   2                   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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |        Service Location header (function = SrvRply = 2)       |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |        Error Code             |        URL Entry count        |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |       &lt;URL Entry 1&gt;          ...       &lt;URL Entry N&gt;          \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * 
+ * </pre>
+ * 
+ * @author Jan S. Rellermeyer, ETH Zurich
+ * 
+ */
+public class ServiceReplyMessageCodec extends AbstractSLPMessageCodec {
+
+    private static final Set MESSAGE_TYPE;
+
+    static {
+        MESSAGE_TYPE = Collections.unmodifiableSet(new HashSet(Arrays
+                .asList(new Class[] { ServiceReplyMessage.class })));
+    }
+
+    public ServiceReplyMessageCodec() {
+        super(ServiceReplyMessage.FUNC_ID);
+    }
+
+    protected AbstractSLPMessage decodeBody(IoSession session, ByteBuffer in,
+            ProtocolDecoderOutput out) throws Exception {
+        final ServiceReplyMessage msg = new ServiceReplyMessage();
+        msg.setErrorCode(in.getShort());
+        final short count = in.getShort();
+        final ServiceURL[] serviceURLs = new ServiceURL[count];
+        for (int i = 0; i < count; i++) {
+            serviceURLs[i] = decodeServiceURL(session, in);
+        }
+        msg.setServiceURLs(serviceURLs);
+        return msg;
+    }
+
+    protected void encodeBody(IoSession session, AbstractSLPMessage msg, ByteBuffer buf)
+            throws Exception {
+        final ServiceReplyMessage repl = (ServiceReplyMessage) msg;
+        buf.putShort(repl.getErrorCode());
+        final int count = repl.getServiceURLs().length;
+        buf.putShort((short) count);
+        for (int i = 0; i < count; i++) {
+            encodeServiceURL(repl.getServiceURLs()[i], session, buf);
+        }
+    }
+
+    public Set getMessageTypes() {
+        return MESSAGE_TYPE;
+    }
+
+}

Added: directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceRequestMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceRequestMessageCodec.java?rev=620585&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceRequestMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceRequestMessageCodec.java Mon Feb 11 11:24:19 2008
@@ -0,0 +1,95 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  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. 
+ *  
+ */
+package org.apache.directory.server.slp.codec;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+import org.apache.directory.server.slp.ServiceType;
+import org.apache.directory.server.slp.messages.AbstractSLPMessage;
+import org.apache.directory.server.slp.messages.ServiceRequestMessage;
+
+/**
+ * <pre>
+ *  0                   1                   2                   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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |       Service Location header (function = SrvRqst = 1)        |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |      length of &lt;PRList&gt;       |        &lt;PRList&gt; String        \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |   length of &lt;service-type&gt;    |    &lt;service-type&gt; String      \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |    length of &lt;scope-list&gt;     |     &lt;scope-list&gt; String       \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |  length of predicate string   |  Service Request &lt;predicate&gt;  \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |  length of &lt;SLP SPI&gt; string   |       &lt;SLP SPI&gt; String        \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>. 
+ * 
+ * @author Jan S. Rellermeyer, ETH Zurich
+ *
+ */
+public class ServiceRequestMessageCodec extends AbstractSLPMessageCodec {
+
+    private static final Set MESSAGE_TYPE;
+
+    static {
+        MESSAGE_TYPE = Collections.unmodifiableSet(new HashSet(Arrays
+                .asList(new Class[] { ServiceRequestMessage.class })));
+    }
+
+    public ServiceRequestMessageCodec() {
+        super(ServiceRequestMessage.FUNC_ID);
+    }
+
+    protected AbstractSLPMessage decodeBody(IoSession session, ByteBuffer in,
+            ProtocolDecoderOutput out) throws Exception {
+        final ServiceRequestMessage msg = new ServiceRequestMessage();
+        msg.setPrevResponders(stringToArray(decodeString(in)));
+        msg.setServiceType(new ServiceType(decodeString(in)));
+        msg.setScopes(stringToArray(decodeString(in)));
+        msg.setPredicate(decodeString(in));
+        msg.setSPIs(stringToArray(decodeString(in)));
+        return msg;
+    }
+
+    protected void encodeBody(IoSession session, AbstractSLPMessage msg, ByteBuffer buf)
+            throws Exception {
+        final ServiceRequestMessage sreq = (ServiceRequestMessage) msg;
+        encodeString(buf, arrayToString(sreq.getPrevResponders()));
+        encodeString(buf, sreq.getServiceType().toString());
+        encodeString(buf, arrayToString(sreq.getScopes()));
+        encodeString(buf, sreq.getPredicate());
+        encodeString(buf, arrayToString(sreq.getSPIs()));
+    }
+
+    public Set getMessageTypes() {
+        return MESSAGE_TYPE;
+    }
+
+}

Added: directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceTypeReplyMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceTypeReplyMessageCodec.java?rev=620585&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceTypeReplyMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceTypeReplyMessageCodec.java Mon Feb 11 11:24:19 2008
@@ -0,0 +1,95 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  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. 
+ *  
+ */
+package org.apache.directory.server.slp.codec;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+import org.apache.directory.server.slp.ServiceType;
+import org.apache.directory.server.slp.messages.AbstractSLPMessage;
+import org.apache.directory.server.slp.messages.ServiceTypeReplyMessage;
+
+/**
+ * <p>
+ * <pre>
+ *    0                   1                   2                   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
+ *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *   |      Service Location header (function = SrvTypeRply = 10)    |
+ *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *   |           Error Code          |    length of &lt;srvType-list&gt;   |
+ *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *   |                       &lt;srvtype--list&gt;                         \
+ *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * </p>
+ * 
+ * @author Jan S. Rellermeyer, ETH Zurich
+ *
+ */
+public class ServiceTypeReplyMessageCodec extends AbstractSLPMessageCodec {
+
+    private static final Set MESSAGE_TYPE;
+
+    static {
+        MESSAGE_TYPE = Collections.unmodifiableSet(new HashSet(Arrays
+                .asList(new Class[] { ServiceTypeReplyMessage.class })));
+    }
+
+    public ServiceTypeReplyMessageCodec() {
+        super(ServiceTypeReplyMessage.FUNC_ID);
+    }
+
+    protected AbstractSLPMessage decodeBody(IoSession session, ByteBuffer in,
+            ProtocolDecoderOutput out) throws Exception {
+        final ServiceTypeReplyMessage msg = new ServiceTypeReplyMessage();
+        msg.setErrorCode(in.getShort());
+        final String[] res = stringToArray(decodeString(in));
+        final ServiceType[] result = new ServiceType[res.length];
+        for (int i = 0; i < result.length; i++) {
+            result[i] = new ServiceType(res[i]);
+        }
+        msg.setServiceTypes(result);
+        return msg;
+    }
+
+    protected void encodeBody(IoSession session, AbstractSLPMessage msg, ByteBuffer buf)
+            throws Exception {
+        final ServiceTypeReplyMessage repl = (ServiceTypeReplyMessage) msg;
+        buf.putShort(repl.getErrorCode());
+        final ServiceType[] res = repl.getServiceTypes();
+        final String[] result = new String[res.length];
+        for (int i = 0; i < result.length; i++) {
+            result[i] = res[i].toString();
+        }
+        encodeString(buf, arrayToString(result));
+    }
+
+    public Set getMessageTypes() {
+        return MESSAGE_TYPE;
+    }
+
+}

Added: directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceTypeRequestMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceTypeRequestMessageCodec.java?rev=620585&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceTypeRequestMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/server/slp/codec/ServiceTypeRequestMessageCodec.java Mon Feb 11 11:24:19 2008
@@ -0,0 +1,86 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  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. 
+ *  
+ */
+package org.apache.directory.server.slp.codec;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+import org.apache.directory.server.slp.messages.AbstractSLPMessage;
+import org.apache.directory.server.slp.messages.ServiceTypeRequestMessage;
+
+/**
+ * <pre>
+ *   0                   1                   2                   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
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |      Service Location header (function = SrvTypeRqst = 9)     |
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |        length of PRList       |        &lt;PRList&gt; String        \
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |   length of Naming Authority  |   &lt;Naming Authority String&gt;   \
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |     length of &lt;scope-list&gt;    |      &lt;scope-list&gt; String      \
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+
+ * @author Jan S. Rellermeyer, ETH Zurich
+ *
+ */
+public class ServiceTypeRequestMessageCodec extends AbstractSLPMessageCodec {
+
+    private static final Set MESSAGE_TYPE;
+
+    static {
+        MESSAGE_TYPE = Collections.unmodifiableSet(new HashSet(Arrays
+                .asList(new Class[] { ServiceTypeRequestMessage.class })));
+    }
+
+    public ServiceTypeRequestMessageCodec() {
+        super(ServiceTypeRequestMessage.FUNC_ID);
+    }
+
+    protected AbstractSLPMessage decodeBody(IoSession session, ByteBuffer in,
+            ProtocolDecoderOutput out) throws Exception {
+        final ServiceTypeRequestMessage msg = new ServiceTypeRequestMessage();
+        msg.setPrevResponders(stringToArray(decodeString(in)));
+        msg.setNamingAuthority(decodeString(in));
+        msg.setScopes(stringToArray(decodeString(in)));
+        return msg;
+    }
+
+    protected void encodeBody(IoSession session, AbstractSLPMessage message,
+            ByteBuffer buf) throws Exception {
+        final ServiceTypeRequestMessage msg = (ServiceTypeRequestMessage) message;
+        encodeString(buf, arrayToString(msg.getPrevResponders()));
+        encodeString(buf, msg.getNamingAuthority());
+        encodeString(buf, arrayToString(msg.getScopes()));
+    }
+
+    public Set getMessageTypes() {
+        return MESSAGE_TYPE;
+    }
+
+}



Mime
View raw message