directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r782968 [2/7] - in /directory/sandbox/slp: ./ src/main/java/org/apache/directory/slp/ src/main/java/org/apache/directory/slp/codec/ src/main/java/org/apache/directory/slp/extensions/ src/main/java/org/apache/directory/slp/impl/ src/main/jav...
Date Tue, 09 Jun 2009 12:00:32 GMT
Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/ServiceURL.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/ServiceURL.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/ServiceURL.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/ServiceURL.java Tue Jun  9 12:00:29 2009
@@ -0,0 +1,396 @@
+/* 
+ *   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.slp;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+/**
+ * Implementation of the SLP ServiceURL class defined in RFC 2614.
+ * 
+ * @author Jan S. Rellermeyer
+ */
+public final class ServiceURL extends AuthenticatedServiceURL {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 9181946114021582389L;
+
+	/**
+	 * 
+	 */
+	public static final int NO_PORT = 0;
+
+	/**
+	 * 
+	 */
+	public static final int LIFETIME_NONE = 0;
+
+	/**
+	 * 
+	 */
+	public static final int LIFETIME_DEFAULT = 10800;
+
+	/**
+	 * 
+	 */
+	public static final int LIFETIME_MAXIMUM = 65535;
+
+	/**
+	 * 
+	 */
+	public static final int LIFETIME_PERMANENT = -1;
+
+	/**
+	 * 
+	 */
+	private String url = "";
+
+	/**
+	 * 
+	 */
+	private int lifetime = 0;
+
+	/**
+	 * 
+	 */
+	private ServiceType type = null;
+
+	/**
+	 * 
+	 */
+	private String host = "";
+
+	/**
+	 * 
+	 */
+	private String protocol = "";
+
+	/**
+	 * 
+	 */
+	private int port = 0;
+
+	/**
+	 * 
+	 */
+	private String path = "";
+
+	/**
+	 * 
+	 * 
+	 */
+	private ServiceURL() {
+	}
+
+	/**
+	 * create a new ServiceURL instance from a String.
+	 * 
+	 * @param serviceURL
+	 *            the string representation of a ServiceURL like
+	 * 
+	 * <pre>
+	 *                 service::&quot;serviceType&quot;://&quot;addrspec&quot;
+	 * </pre>
+	 * 
+	 * where servicetype should be of the form abstractType:concreteType and
+	 * addrspec is the hostname or dotted decimal notation of the host's address
+	 * followed by an optional :portNumber. Example:
+	 * 
+	 * <pre>
+	 *                     service:osgi:remote://my.host.ch:9200
+	 * </pre>
+	 * 
+	 * @param lifeTime
+	 *            the lifetime of the ServiceURL in seconds.
+	 * @throws ServiceLocationException
+	 *             if the String is not parsable.
+	 */
+	public ServiceURL(final String serviceURL, final int lifeTime)
+			throws ServiceLocationException {
+		url = serviceURL;
+		lifetime = lifeTime;
+
+		try {
+			parse();
+		} catch (Exception ex) {
+			throw new ServiceLocationException(
+					ServiceLocationException.PARSE_ERROR,
+					"service url is malformed: [" + url + "]. ");
+		}
+	}
+	
+	
+	/**
+	 * create a new ServiceURL instance from a <code>ServiceType</code>.
+	 * 
+	 * @param serviceType
+	 *            the ServiceType
+	 * 
+	 * 
+	 * This constructor was added by Lorenz Breu during the initial porting of jSLP
+	 * to the Apache Mina framework due to type incompatibilities between the original
+	 * jSLP implementation and the Codecs for Mina designed by Jan Rellermeyer. 
+	 * 
+	 * @param lifeTime
+	 *            the lifetime of the ServiceURL in seconds.
+	 */
+	public ServiceURL(final ServiceType serviceType, final int lifeTime){
+		type=serviceType;
+		url=serviceType.toString();
+		lifetime=lifeTime;
+	}
+	
+
+	/**
+	 * parse the url string.
+	 * 
+	 */
+	private void parse() {
+		int pos1 = url.indexOf("://");
+		type = new ServiceType(url.substring(0, pos1++));
+
+		int pos2 = url.indexOf("://", pos1 + 1);
+		if (pos2 > -1) {
+			protocol = url.substring(pos1 + 2, pos2);
+			pos1 = pos2 + 1;
+		}
+
+		int hostEnd = url.indexOf(":", pos1 + 2);
+
+		int pathStart;
+		if (hostEnd == -1) {
+			port = NO_PORT;
+			pathStart = hostEnd = url.indexOf("/", pos1 + 2);
+		} else {
+			pathStart = url.indexOf("/", hostEnd + 1);
+			if (pathStart == -1) {
+				port = Integer.parseInt(url.substring(hostEnd + 1));
+			} else {
+				port = Integer.parseInt(url.substring(hostEnd + 1, pathStart));
+			}
+		}
+
+		if (hostEnd == -1) {
+			host = url.substring(pos1 + 2);
+		} else {
+			host = url.substring(pos1 + 2, hostEnd);
+		}
+
+		if (pathStart == -1) {
+			path = "";
+		} else {
+			path = url.substring(pathStart);
+		}
+		
+		
+	}
+
+	/**
+	 * Check if two instances are equal.
+	 * 
+	 * @inheritDoc java.lang.Object.equals(Object)
+	 * @param obj
+	 *            the object to compare to.
+	 * @return true if the instances are equal.
+	 */
+	public boolean equals(final Object obj) {
+		if (obj instanceof ServiceURL) {
+			final ServiceURL u = (ServiceURL) obj;
+			return (type.equals(u.type)
+					&& host.equals(u.host)
+					&& port == u.port
+					&& ((protocol == null && u.protocol == null) || protocol
+							.equals(u.protocol)) && path.equals(u.path));
+		}
+		return false;
+	}
+
+	/**
+	 * Check if a ServiceURL matches another ServiceURL or a ServiceType. In the
+	 * first case, the method performs an equality check with equals(Object
+	 * obj), for ServiceTypes, the ServiceType part of the ServiceURL is checked
+	 * against the given ServiceType.
+	 * 
+	 * @param obj
+	 *            a ServiceURL or ServiceType. All other objects will return
+	 *            false.
+	 * @return true if the match succeeds.
+	 */
+	public boolean matches(final Object obj) {
+		if (obj instanceof ServiceURL) {
+			return equals(obj);
+		} else if (obj instanceof ServiceType) {
+			return type.matches(obj);
+		}
+		return false;
+	}
+
+	/**
+	 * get a String representation of the ServiceURL.
+	 * 
+	 * @return the String representation.
+	 */
+	public String toString() {
+		String res = type.toString() + "://"
+				+ (protocol != "" ? protocol + "://" : "") + host
+				+ (port != NO_PORT ? (":" + port) : "") + path;
+		if (res.lastIndexOf("://")==res.length()-3){
+			return res.substring(0,res.length()-3);
+		}
+		return res.replace("://://", "://");
+	}
+
+	/**
+	 * get the hashCode of the ServiceURL instance.
+	 * 
+	 * @return the hashCode.
+	 */
+	public int hashCode() {
+		return url.hashCode();
+	}
+
+	/**
+	 * get the service type.
+	 * 
+	 * @return the service type.
+	 */
+	public ServiceType getServiceType() {
+		return type;
+	}
+
+	/**
+	 * get the transport method.
+	 * 
+	 * @return the transport method. IP returns empty string.
+	 * @deprecated
+	 */
+	public String getTransport() {
+		return "";
+	}
+
+	/**
+	 * get the protocol.
+	 * 
+	 * @return the protocol, if specified. Otherwise, returns null.
+	 */
+	public String getProtocol() {
+		if (protocol.equals("")){
+			return null;
+		}
+		return protocol;
+	}
+
+	/**
+	 * get the host.
+	 * 
+	 * @return the host.
+	 */
+	public String getHost() {
+		return host;
+	}
+	
+	/**
+	 * set the host
+	 * 
+	 * @param s
+	 * 		the host part of this service url
+	 */
+	public void setHost(String s){
+		host=s;
+	}
+
+	/**
+	 * get the port.
+	 * 
+	 * @return the port.
+	 */
+	public int getPort() {
+		return port;
+	}
+
+	/**
+	 * get the URL path.
+	 * 
+	 * @return the URL path.
+	 */
+	public String getURLPath() {
+		return path;
+	}
+
+	/**
+	 * get the lifetime.
+	 * 
+	 * @return the lifetime.
+	 */
+	public int getLifetime() {
+		return lifetime;
+	}
+
+	/**
+	 * get the byte representation of the ServiceURL instance.
+	 * 
+	 * @throws IOException
+	 * @throws IOException
+	 *             if an internal processing error occurs.
+	 */
+	public void writeTo(DataOutputStream out) throws IOException {
+		out.write(0);
+		out.writeShort((short) lifetime);
+		out.writeUTF(toString());
+		// writeAuthBlock(out);
+	}
+
+	/**
+	 * Get the length of the Strig representation of this URL for encoding into a SLP message
+	 * 
+	 * @return
+	 * 		the length
+	 */
+	public int getLength() {
+		return 1 + 2 + 2 + toString().length(); // + getAuthBlockLength();
+	}
+	
+	
+	/**
+	 * Get the URL
+	 * 
+	 * @return
+	 * 		The URL
+	 */
+	public String getURL(){
+		// somewhere along the way of porting jSLP to MINA and moving to java5 the trio Service, ServiceURL and ServiceType and their conversion back and forth caused some mix-ups...
+		if (url.lastIndexOf("://")==url.length()-3){
+			return url.substring(0,url.length()-3);
+		}
+		return url;
+	}
+	
+	/**
+	 * Set the URL
+	 * 
+	 * @param u
+	 * 		The URL
+	 */
+	public void setURL(String u){
+		url=u;
+	}
+}

Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/ServiceURL.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AbstractSLPMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AbstractSLPMessageCodec.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AbstractSLPMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AbstractSLPMessageCodec.java Tue Jun  9 12:00:29 2009
@@ -0,0 +1,449 @@
+/* 
+ *   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.slp.codec;
+
+import java.io.IOException;
+import java.net.ProtocolException;
+import java.nio.ByteBuffer;
+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.directory.slp.ServiceLocationException;
+import org.apache.directory.slp.ServiceURL;
+import org.apache.directory.slp.extensions.AbstractExtension;
+import org.apache.directory.slp.impl.AuthenticationBlock;
+import org.apache.directory.slp.messages.AbstractSLPMessage;
+import org.apache.directory.slp.messages.ServiceRegistrationMessage;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.core.session.IoSessionConfig;
+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.mina.transport.socket.DatagramSessionConfig;
+
+/**
+ * <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
+ * 
+ */
+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;
+	
+	private boolean hasExtensions = false;
+
+	public AbstractSLPMessageCodec(final byte type) {
+		this.type = type;
+	}
+
+	public MessageDecoderResult decodable(IoSession session, IoBuffer 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
+		int a = in.get()<<16;
+		int b = in.get()<<8;
+		int c = in.get();
+		final int len = a + b + c;
+		if (in.remaining() < len - 5) {
+			return MessageDecoderResult.NEED_DATA;
+		}
+		return funcID == type ? MessageDecoderResult.OK
+				: MessageDecoderResult.NOT_OK;
+	}
+
+	public MessageDecoderResult decode(IoSession session, IoBuffer in,
+			ProtocolDecoderOutput out) throws Exception {
+		try {
+			
+			in.skip(5); // version and funcID are already parsed
+
+			byte flags = (byte) (in.getShort() >> 8);
+			IoSessionConfig cfg = session.getConfig();
+			if ((cfg instanceof DatagramSessionConfig) && (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
+			
+			int a = in.get()<<16;
+			int b = in.get()<<8;
+			int c = in.get();
+			final int nextOffset = a + b + c;
+			if (nextOffset>0){
+				hasExtensions = true;
+			}
+			
+			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);
+			if (cfg instanceof DatagramSessionConfig){
+				msg.setTcp(false);
+			} else {
+				msg.setTcp(true);
+			}
+			//msg.setMulticast(((flags & 0x2000) >> 13) == 1 ? true : false);
+			msg.setMulticast(((flags & 0x20) >> 5) == 1 ? true : false);
+			msg.setFresh(((flags & 0x40) >> 6) == 1 ? true : false);
+			
+			if (hasExtensions){
+				decodeExtensions(session, in, out, msg);
+			}
+			
+			out.write(msg);
+
+			return MessageDecoderResult.OK;
+		} catch (Exception t) {
+			t.printStackTrace();
+			throw t;
+		}
+	}
+
+	protected final void encodeString(final IoBuffer out, final String s)
+			throws IOException {
+		out.putShort((short) s.length());
+		out.putString(s, ENCODER);
+	}
+
+	protected final String decodeString(final IoBuffer in) throws IOException {
+		final short len = in.getShort();
+		return in.getString(len, DECODER);
+	}
+
+	protected abstract AbstractSLPMessage decodeBody(final IoSession session,
+			final IoBuffer in, final ProtocolDecoderOutput out)
+			throws Exception;
+	
+/*	 9.1. Service Location Protocol Extensions
+
+	   The format of a Service Location Extension is:
+
+	      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
+	     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+	     |         Extension ID          |       Next Extension Offset   |
+	     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+	     | Offset, contd.|                Extension Data                 \
+	     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+	   Extension IDs are assigned in the following way:
+
+	   0x0000-0x3FFF Standardized.  Optional to implement.  Ignore if
+	         unrecognized.
+	   0x4000-0x7FFF Standardized.  Mandatory to implement.  A UA or SA
+	         which receives this option in a reply and does not understand
+	         it MUST silently discard the reply.  A DA or SA which receives
+	         this option in a request and does not understand it MUST return
+	         an OPTION_NOT_UNDERSTOOD error.
+	   0x8000-0x8FFF For private use (not standardized).  Optional to
+	         implement.  Ignore if unrecognized.
+	   0x9000-0xFFFF Reserved.
+
+	   The three byte offset to next extension indicates the position of the
+	   next extension as offset from the beginning of the SLP message.
+
+	   The offset value is 0 if there are no extensions following the
+	   current extension.
+
+	   If the offset is 0, the length of the current Extension Data is
+	   determined by subtracting total length of the SLP message as given in
+	   the SLP message header minus the offset of the current extension.*/
+	
+	protected static void decodeExtensions(IoSession session, IoBuffer in,
+			ProtocolDecoderOutput out, AbstractSLPMessage msg) {
+		boolean hasMoreExtensions = true;
+		while (hasMoreExtensions){
+			short id = in.getShort();
+			int a = (0x00FF0000 & (in.get()<<16));
+			int b = (0x0000FF00 & (in.get()<<8));
+			int c = (0x000000FF & (in.get())); 
+			int nextOffset = a+b+c;
+			msg.addExtension(AbstractExtension.decode(in, id, nextOffset));
+			if (nextOffset==0){
+				hasMoreExtensions = false;
+			}
+		}
+	}
+	
+
+	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 IoBuffer 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 IoBuffer 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 IoBuffer 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 IoBuffer 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 String strFixed = str.replace("\\,", "SLP_ESCAPED_COMMA");
+		final StringTokenizer tokenizer = new StringTokenizer(strFixed, ",");
+		final String[] result = new String[tokenizer.countTokens()];
+		for (int i = 0; i < result.length; i++) {
+			result[i] = tokenizer.nextToken().replace("SLP_ESCAPED_COMMA", "\\,");
+		}
+		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 IoBuffer buf = IoBuffer.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 instanceof ServiceRegistrationMessage && msg.isFresh()) { flags |= 0x40; }
+		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
+		
+		if (msg.hasExtensions()){
+			final int offset = buf.position();
+			buf.put(7, (byte) (offset >> 16));
+			buf.put(8, (byte) ((offset >> 8) & 0xFF));
+			buf.put(9, (byte) ((offset) & 0xFF));
+			encodeExtensions(session, msg, buf);
+		} else {
+			buf.put(7, (byte) (0));
+			buf.put(8, (byte) (0));
+			buf.put(9, (byte) (0));
+		}
+		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 IoBuffer buf)
+			throws Exception;
+	
+	
+	protected void encodeExtensions(final IoSession session, final AbstractSLPMessage msg, final IoBuffer buf) throws Exception{
+		int i = 0;
+		AbstractExtension ae;
+		for (i = 0; i < msg.getExtensions().length-1; i++){
+			ae = msg.getExtensions()[i];
+			buf.putShort(ae.getId());
+			int nextOffset = buf.position() + ae.getLength() - 2; //have already added a short
+			byte b =(byte) ((nextOffset>>16) & 0x000000FF);
+			buf.put(b);
+			b =(byte) ((nextOffset>>8) & 0x000000FF);
+			buf.put(b);
+			b =(byte) (nextOffset & 0x000000FF);
+			buf.put(b);
+			ae.encodeBody(buf);
+		}
+		ae = msg.getExtensions()[i];
+		buf.putShort(ae.getId());
+		buf.put((byte)0);
+		buf.put((byte)0);
+		buf.put((byte)0);
+		ae.encodeBody(buf);
+	}
+	
+}
+
+

Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AbstractSLPMessageCodec.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AttributeReplyMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AttributeReplyMessageCodec.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AttributeReplyMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AttributeReplyMessageCodec.java Tue Jun  9 12:00:29 2009
@@ -0,0 +1,100 @@
+/* 
+ *   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.slp.codec;
+
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+
+import org.apache.directory.slp.messages.AbstractSLPMessage;
+import org.apache.directory.slp.messages.AttributeReplyMessage;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+
+/**
+ * 
+ * <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
+ * 
+ */
+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, IoBuffer 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();
+		//Set the source address from session info
+		msg.setSource(((InetSocketAddress) session.getRemoteAddress()).getAddress().getHostAddress());
+		//Weird behaviour in Debian and co. binds the local hostname to 
+		//127.0.1.1 in the hosts file...Replace all such occurences with 
+		//127.0.0.1
+		if (msg.getSource()=="127.0.1.1"){
+			msg.setSource("127.0.0.1");
+		}
+		// Set the source port of the message
+		msg.setPort(((InetSocketAddress) session.getRemoteAddress()).getPort());
+		return msg;
+	}
+
+	protected void encodeBody(IoSession session, AbstractSLPMessage msg,
+			IoBuffer 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;
+	}
+
+}

Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AttributeReplyMessageCodec.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AttributeRequestMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AttributeRequestMessageCodec.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AttributeRequestMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AttributeRequestMessageCodec.java Tue Jun  9 12:00:29 2009
@@ -0,0 +1,109 @@
+/* 
+ *   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.slp.codec;
+
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.slp.ServiceLocationException;
+import org.apache.directory.slp.ServiceType;
+import org.apache.directory.slp.ServiceURL;
+import org.apache.directory.slp.messages.AbstractSLPMessage;
+import org.apache.directory.slp.messages.AttributeRequestMessage;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+
+/**
+ * <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
+ * 
+ */
+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, IoBuffer in,
+			ProtocolDecoderOutput out) throws Exception {
+		final AttributeRequestMessage msg = new AttributeRequestMessage();
+		msg.setPrevResponders(stringToArray(decodeString(in)));
+		String srv = decodeString(in);
+		try {
+			msg.setServiceURL(new ServiceURL(srv, 0));
+		} catch (ServiceLocationException sle) {
+			msg.setServiceURL(new ServiceURL(new ServiceType(srv), 0));
+		}
+
+		msg.setScopes(stringToArray(decodeString(in)));
+		msg.setTags(stringToArray(decodeString(in)));
+		msg.setSPIs(stringToArray(decodeString(in)));
+		msg.setSource(((InetSocketAddress) session.getRemoteAddress())
+				.getAddress().getHostAddress());
+		msg.setPort(((InetSocketAddress) session.getRemoteAddress()).getPort());
+		return msg;
+	}
+
+	protected void encodeBody(IoSession session, AbstractSLPMessage msg,
+			IoBuffer buf) throws Exception {
+		final AttributeRequestMessage req = (AttributeRequestMessage) msg;
+		encodeString(buf, arrayToString(req.getPrevResponders()));
+		encodeString(buf, req.getServiceUrl().getURL());
+		encodeString(buf, arrayToString(req.getScopes()));
+		encodeString(buf, arrayToString(req.getTags()));
+		encodeString(buf, arrayToString(req.getSPIs()));
+	}
+
+	public Set getMessageTypes() {
+		return MESSAGE_TYPE;
+	}
+
+}

Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/AttributeRequestMessageCodec.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/DAAdvertisementMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/DAAdvertisementMessageCodec.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/DAAdvertisementMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/DAAdvertisementMessageCodec.java Tue Jun  9 12:00:29 2009
@@ -0,0 +1,109 @@
+/* 
+ *   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.slp.codec;
+
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.slp.ServiceURL;
+import org.apache.directory.slp.messages.AbstractSLPMessage;
+import org.apache.directory.slp.messages.DAAdvertisementMessage;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+
+/**
+ * <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
+ */
+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, IoBuffer in,
+			ProtocolDecoderOutput out) throws Exception {
+		final DAAdvertisementMessage msg = new DAAdvertisementMessage();
+		msg.setErrorCode(in.getShort());
+		msg.setStatelessBootTimestamp(in.getInt());
+		msg.setServiceURL(new ServiceURL(decodeString(in), 0));
+		msg.setOrigURL(msg.getServiceURL().toString());
+		msg.setScopes(stringToArray(decodeString(in)));
+		msg.setAttributes(stringToArray(decodeString(in)));
+		msg.setSPIs(stringToArray(decodeString(in)));
+		msg.setAuthBlocks(decodeAuthBlocks(session, in));
+		msg.setSource(((InetSocketAddress) session.getRemoteAddress())
+				.getAddress().getHostAddress());
+		msg.setPort(((InetSocketAddress) session.getRemoteAddress()).getPort());
+		return msg;
+	}
+
+	protected void encodeBody(IoSession session, AbstractSLPMessage message,
+			IoBuffer buf) throws Exception {
+		final DAAdvertisementMessage msg = (DAAdvertisementMessage) message;
+		buf.putShort(msg.getErrorCode());
+		buf.putInt(msg.getStatelessBootTimestamp());
+		encodeString(buf, msg.getServiceURL().getURL());
+		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;
+	}
+
+}

Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/DAAdvertisementMessageCodec.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/SLPProtocolCodecFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/SLPProtocolCodecFactory.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/SLPProtocolCodecFactory.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/SLPProtocolCodecFactory.java Tue Jun  9 12:00:29 2009
@@ -0,0 +1,67 @@
+/* 
+ *   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.slp.codec;
+
+
+import org.apache.directory.slp.messages.AttributeReplyMessage;
+import org.apache.directory.slp.messages.AttributeRequestMessage;
+import org.apache.directory.slp.messages.DAAdvertisementMessage;
+import org.apache.directory.slp.messages.ServiceAcknowledgementMessage;
+import org.apache.directory.slp.messages.ServiceDeregistrationMessage;
+import org.apache.directory.slp.messages.ServiceRegistrationMessage;
+import org.apache.directory.slp.messages.ServiceReplyMessage;
+import org.apache.directory.slp.messages.ServiceRequestMessage;
+import org.apache.directory.slp.messages.ServiceTypeReplyMessage;
+import org.apache.directory.slp.messages.ServiceTypeRequestMessage;
+import org.apache.mina.filter.codec.demux.DemuxingProtocolCodecFactory;
+
+
+/**
+ * Protocol codec factory for the SLP protocol.
+ * 
+ * @author Jan S. Rellermeyer
+ */
+public class SLPProtocolCodecFactory extends DemuxingProtocolCodecFactory {
+
+	public SLPProtocolCodecFactory() {
+		addMessageDecoder(AttributeReplyMessageCodec.class);
+		addMessageEncoder(AttributeReplyMessage.class,AttributeReplyMessageCodec.class);
+		addMessageDecoder(AttributeRequestMessageCodec.class);
+		addMessageEncoder(AttributeRequestMessage.class,AttributeRequestMessageCodec.class);
+		addMessageDecoder(DAAdvertisementMessageCodec.class);
+		addMessageEncoder(DAAdvertisementMessage.class,DAAdvertisementMessageCodec.class);
+		addMessageDecoder(ServiceAcknowledgementMessageCodec.class);
+		addMessageEncoder(ServiceAcknowledgementMessage.class,ServiceAcknowledgementMessageCodec.class);
+		addMessageDecoder(ServiceDeregistrationMessageCodec.class);
+		addMessageEncoder(ServiceDeregistrationMessage.class,ServiceDeregistrationMessageCodec.class);
+		addMessageDecoder(ServiceRegistrationMessageCodec.class);
+		addMessageEncoder(ServiceRegistrationMessage.class,ServiceRegistrationMessageCodec.class);
+		addMessageDecoder(ServiceReplyMessageCodec.class);
+		addMessageEncoder(ServiceReplyMessage.class,ServiceReplyMessageCodec.class);
+		addMessageDecoder(ServiceRequestMessageCodec.class);
+		addMessageEncoder(ServiceRequestMessage.class,ServiceRequestMessageCodec.class);
+		addMessageDecoder(ServiceTypeReplyMessageCodec.class);
+		addMessageEncoder(ServiceTypeReplyMessage.class,ServiceTypeReplyMessageCodec.class);
+		addMessageDecoder(ServiceTypeRequestMessageCodec.class);
+		addMessageEncoder(ServiceTypeRequestMessage.class,ServiceTypeRequestMessageCodec.class);
+		
+	}
+
+}

Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/SLPProtocolCodecFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceAcknowledgementMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceAcknowledgementMessageCodec.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceAcknowledgementMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceAcknowledgementMessageCodec.java Tue Jun  9 12:00:29 2009
@@ -0,0 +1,81 @@
+/* 
+ *   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.slp.codec;
+
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.slp.messages.AbstractSLPMessage;
+import org.apache.directory.slp.messages.ServiceAcknowledgementMessage;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+
+/**
+ * <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
+ */
+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, IoBuffer in,
+			ProtocolDecoderOutput out) throws Exception {
+		final ServiceAcknowledgementMessage msg = new ServiceAcknowledgementMessage();
+		msg.setErrorCode(in.getShort());
+		msg.setSource(((InetSocketAddress) session.getRemoteAddress())
+				.getAddress().getHostAddress());
+		msg.setPort(((InetSocketAddress) session.getRemoteAddress()).getPort());
+		return msg;
+	}
+
+	protected void encodeBody(IoSession session, AbstractSLPMessage msg,
+			IoBuffer buf) throws Exception {
+		final ServiceAcknowledgementMessage ack = (ServiceAcknowledgementMessage) msg;
+		buf.putShort(ack.getErrorCode());
+	}
+
+	public Set getMessageTypes() {
+		return MESSAGE_TYPE;
+	}
+
+}

Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceAcknowledgementMessageCodec.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceDeregistrationMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceDeregistrationMessageCodec.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceDeregistrationMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceDeregistrationMessageCodec.java Tue Jun  9 12:00:29 2009
@@ -0,0 +1,89 @@
+/* 
+ *   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.slp.codec;
+
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.slp.messages.AbstractSLPMessage;
+import org.apache.directory.slp.messages.ServiceDeregistrationMessage;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+
+
+/**
+ * <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
+ */
+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, IoBuffer 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)));
+        msg.setSource(((InetSocketAddress) session.getRemoteAddress()).getAddress().getHostAddress());
+		msg.setPort(((InetSocketAddress) session.getRemoteAddress()).getPort());
+        return msg;
+    }
+
+    protected void encodeBody(IoSession session, AbstractSLPMessage msg, IoBuffer 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;
+    }
+
+}

Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceDeregistrationMessageCodec.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceRegistrationMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceRegistrationMessageCodec.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceRegistrationMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceRegistrationMessageCodec.java Tue Jun  9 12:00:29 2009
@@ -0,0 +1,106 @@
+/* 
+ *   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.slp.codec;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.directory.slp.ServiceType;
+import org.apache.directory.slp.messages.AbstractSLPMessage;
+import org.apache.directory.slp.messages.ServiceRegistrationMessage;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+
+/**
+ * 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
+ */
+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, IoBuffer 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.setAttributes(decodeString(in));
+        msg.setAuthBlocks(decodeAuthBlocks(session, in));
+        msg.setSource(((InetSocketAddress) session.getRemoteAddress()).getAddress().getHostAddress());
+		msg.setPort(((InetSocketAddress) session.getRemoteAddress()).getPort());
+        msg.verify();
+        return msg;
+    }
+
+    protected void encodeBody(IoSession session, AbstractSLPMessage msg, IoBuffer 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;
+    }
+
+    
+    
+}

Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceRegistrationMessageCodec.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceReplyMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceReplyMessageCodec.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceReplyMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceReplyMessageCodec.java Tue Jun  9 12:00:29 2009
@@ -0,0 +1,96 @@
+/* 
+ *   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.slp.codec;
+
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.slp.ServiceURL;
+import org.apache.directory.slp.messages.AbstractSLPMessage;
+import org.apache.directory.slp.messages.ServiceReplyMessage;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+
+
+/**
+ * <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
+ */
+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, IoBuffer 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);
+        msg.setSource(((InetSocketAddress) session.getRemoteAddress()).getAddress().getHostAddress());
+		msg.setPort(((InetSocketAddress) session.getRemoteAddress()).getPort());
+        return msg;
+    }
+
+    protected void encodeBody(IoSession session, AbstractSLPMessage msg, IoBuffer 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;
+    }
+
+}

Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceReplyMessageCodec.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceRequestMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceRequestMessageCodec.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceRequestMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceRequestMessageCodec.java Tue Jun  9 12:00:29 2009
@@ -0,0 +1,97 @@
+/* 
+ *   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.slp.codec;
+
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.slp.ServiceType;
+import org.apache.directory.slp.messages.AbstractSLPMessage;
+import org.apache.directory.slp.messages.ServiceRequestMessage;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+/**
+ * <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
+ */
+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, IoBuffer 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)));
+		msg.setSource(((InetSocketAddress) session.getRemoteAddress())
+				.getAddress().getHostAddress());
+		msg.setPort(((InetSocketAddress) session.getRemoteAddress()).getPort());
+		return msg;
+	}
+
+	protected void encodeBody(IoSession session, AbstractSLPMessage msg,
+			IoBuffer 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;
+	}
+
+}

Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceRequestMessageCodec.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceTypeReplyMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceTypeReplyMessageCodec.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceTypeReplyMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceTypeReplyMessageCodec.java Tue Jun  9 12:00:29 2009
@@ -0,0 +1,97 @@
+/* 
+ *   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.slp.codec;
+
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.slp.ServiceType;
+import org.apache.directory.slp.messages.AbstractSLPMessage;
+import org.apache.directory.slp.messages.ServiceTypeReplyMessage;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+
+/**
+ * <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
+ */
+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, IoBuffer 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);
+        msg.setSource(((InetSocketAddress) session.getRemoteAddress()).getAddress().getHostAddress());
+		msg.setPort(((InetSocketAddress) session.getRemoteAddress()).getPort());
+        return msg;
+    }
+
+    protected void encodeBody(IoSession session, AbstractSLPMessage msg, IoBuffer 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;
+    }
+
+}

Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceTypeReplyMessageCodec.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceTypeRequestMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceTypeRequestMessageCodec.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceTypeRequestMessageCodec.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceTypeRequestMessageCodec.java Tue Jun  9 12:00:29 2009
@@ -0,0 +1,89 @@
+/* 
+ *   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.slp.codec;
+
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+
+import org.apache.directory.slp.messages.AbstractSLPMessage;
+import org.apache.directory.slp.messages.ServiceTypeRequestMessage;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+
+/**
+ * <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
+ */
+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, IoBuffer in,
+            ProtocolDecoderOutput out) throws Exception {
+        final ServiceTypeRequestMessage msg = new ServiceTypeRequestMessage();
+        msg.setPrevResponders(stringToArray(decodeString(in)));
+        msg.setNamingAuthority(decodeString(in));
+        msg.setScopes(stringToArray(decodeString(in)));
+        msg.setSource(((InetSocketAddress) session.getRemoteAddress()).getAddress().getHostAddress());
+		msg.setPort(((InetSocketAddress) session.getRemoteAddress()).getPort());
+        return msg;
+    }
+
+    protected void encodeBody(IoSession session, AbstractSLPMessage message,
+            IoBuffer 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;
+    }
+
+}

Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/codec/ServiceTypeRequestMessageCodec.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/extensions/AbstractExtension.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/extensions/AbstractExtension.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/extensions/AbstractExtension.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/extensions/AbstractExtension.java Tue Jun  9 12:00:29 2009
@@ -0,0 +1,244 @@
+/* 
+ *   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.slp.extensions;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+
+import org.apache.directory.slp.ServiceLocationException;
+import org.apache.directory.slp.impl.SLPCore;
+import org.apache.mina.core.buffer.IoBuffer;
+
+
+/**
+ * The base abstract class representing SLP extensions
+ * 
+ * @author Lorenz Breu
+ */
+public abstract class AbstractExtension {
+
+	// The character set to use
+	private static Charset CHARSET = Charset.forName("UTF-8");
+	protected static CharsetDecoder DECODER = CHARSET.newDecoder();
+	protected static CharsetEncoder ENCODER = CHARSET.newEncoder();
+	
+	public static final short ATTRIBUTE_LIST_EXTENSION = 2; 
+	public static final short SORT_EXTENSION = 0x4003; // decoder implemented, processing not
+	public static final short SELECT_EXTENSION = 0x4002; // decoder implemented, processing not
+
+	private short id;
+
+	private int length;
+	
+	
+	/*
+	0x0000-0x3FFF Standardized.  Optional to implement.  Ignore if
+     		unrecognized.
+	0x4000-0x7FFF Standardized.  Mandatory to implement.  A UA or SA
+     		which receives this option in a reply and does not understand
+     		it MUST silently discard the reply.  A DA or SA which receives
+     		this option in a request and does not understand it MUST return
+     		an OPTION_NOT_UNDERSTOOD error.
+	0x8000-0x8FFF For private use (not standardized).  Optional to
+     		implement.  Ignore if unrecognized.
+	0x9000-0xFFFF Reserved.
+	
+	*/
+	
+	public boolean isOptional(){
+		return (id<=0x3FFF || isPrivate());
+	}
+	
+	public boolean isMandatory(){
+		return ((id>=0x4000) && (id<=0x7FFF));
+	}
+	
+	public boolean isPrivate(){
+		return ((id>=0x8000) && (id<=0x8FFF));
+	}
+	
+	public boolean isReserved(){
+		return ((id>=0x9000) && (id<=0xFFFF));
+	}
+	
+
+	
+	
+	
+	
+	/**
+	 * Create a new SLP extension of the given id
+	 * 
+	 * @param id
+	 * 		the id
+	 */
+	public AbstractExtension(short id){
+		this.id = id;
+	}
+
+	/**
+	 * Sets the ID
+	 * 
+	 * @param id
+	 * 		the slp extension ID
+	 */
+	public void setId(short id){
+		this.id=id;
+	}
+
+	
+	/**
+	 * Gets the ID
+	 * 
+	 * @return
+	 * 		the slp extension ID
+	 */
+	public short getId(){
+		return id;
+	}
+
+	/**
+	 * Sets the length in bytes
+	 * 
+	 * @param l
+	 * 		The length in bytes
+	 */
+	public void setLength(int l){
+		length=l;
+	}
+
+	/**
+	 * Returns the length of the extension in bytes for encoding
+	 * 
+	 * @return
+	 * 		the length in bytes
+	 */
+	public int getLength(){
+		return length;
+	}
+
+
+	/**
+	 * Encodes the extension body to the given buffer
+	 * 
+	 * @param buf
+	 * 			an IoBuffer used by MINA to build messages
+	 */
+	public abstract void encodeBody(final IoBuffer buf);
+	
+	
+	/**
+	 * Decodes the extension body from the given buffer to an SLP extension ibject of the given type with the given offset to the next extension
+	 * 
+	 * @param buf
+	 * 			The buffer containing the data to be decoded
+	 * @param id
+	 * 			The SLP extension ID (decoded from header)
+	 * @param nextOffset
+	 * 			The offset to the next extension (decoded from header)
+	 * @throws Exception
+	 */
+	protected abstract void decodeBody(final IoBuffer buf, final short id, final int nextOffset) throws Exception;
+
+	
+	/**
+	 * Decodes the data in the given buffer to an SLP extension object
+	 * 
+	 *@param buf
+	 * 			The buffer containing the data to be decoded
+	 * @param id
+	 * 			The SLP extension ID (decoded from header)
+	 * @param nextOffset
+	 * 			The offset to the next extension (decoded from header)
+	 * @return
+	 */
+	public static AbstractExtension decode(final IoBuffer buf, final short id, final int nextOffset){
+		AbstractExtension ext;
+		switch(id){
+		case ATTRIBUTE_LIST_EXTENSION:
+			try{
+				ext = new AttributeListExtension();
+				ext = (AttributeListExtension) ext;
+				ext.decodeBody(buf, id, nextOffset);
+				break;
+			} catch (Exception e){
+				SLPCore.getPlatform().logDebug("[Extensions]: Error decoding Attribute List Extension: "+e.getMessage());
+				ext = new UnsupportedExtension(id);
+			}
+		default:
+			ext = new UnsupportedExtension(id);
+		if (nextOffset>0){
+			buf.skip(nextOffset-buf.position());
+		} else {
+			buf.position(buf.limit());
+		}
+		}
+		return ext;
+	}
+
+	/**
+	 * encodes a string to a buffer 
+	 * 
+	 * @param out
+	 * 		The buffer into which the encoded string is to be written
+	 * @param s
+	 * 		The string to encode
+	 * @throws IOException
+	 */
+	protected static final void encodeString(final IoBuffer out, final String s)
+	throws IOException {
+		out.putShort((short) s.length());
+		out.putString(s, ENCODER);
+	}
+
+	/**
+	 * decodes a string from a buffer
+	 * 
+	 * @param in
+	 * 		The buffer containing the data
+	 * @return
+	 * 		The decoded string
+	 * @throws IOException
+	 */
+	protected static final String decodeString(final IoBuffer in) throws IOException {
+		final short len = in.getShort();
+		return in.getString(len, DECODER);
+	}
+	
+	/**
+	 * verifies the extension if security is enabled
+	 * 
+	 * @return
+	 * 		True if verification passes, else false
+	 */
+	public abstract boolean verify();
+	
+	/**
+	 * Signs an extension using the specified SPI	
+	 * 
+	 * @param spi
+	 * 		The string representation of the SLP SPI to be ised for signing
+	 * @throws ServiceLocationException
+	 */
+	public abstract void sign(String spi) throws ServiceLocationException;
+
+}

Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/extensions/AbstractExtension.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message