You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by rj...@apache.org on 2009/06/09 14:00:32 UTC
svn commit: r782968 [7/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...
Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AbstractSLPRequestMessage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AbstractSLPRequestMessage.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AbstractSLPRequestMessage.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AbstractSLPRequestMessage.java Tue Jun 9 12:00:29 2009
@@ -0,0 +1,88 @@
+/*
+ * 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.messages;
+
+import java.util.Arrays;
+
+import org.apache.directory.slp.impl.SLPCore;
+import org.apache.directory.slp.impl.SLPUtils;
+
+
+/**
+ * Abstract base class for all request messages.
+ *
+ * @author Jan S. Rellermeyer
+ */
+public abstract class AbstractSLPRequestMessage extends AbstractSLPMessage {
+
+ /**
+ * the list of previous responders. If a peer receives a request message and
+ * is already in the previous responder list, it will silently drop the
+ * message.
+ */
+ protected String[] prevResponders = EMPTY;
+
+ /**
+ * a list of scopes that will be included.
+ */
+ protected String[] scopes = new String[] { "default" };
+
+ AbstractSLPRequestMessage(byte funcID) {
+ super(funcID);
+ scopes = SLPUtils.stringToStringArray(SLPCore.CONFIG.getScopes(),",");
+ }
+
+ public final void setPrevResponders(final String[] responders) {
+ this.prevResponders = responders;
+ }
+
+ public final String[] getPrevResponders() {
+ return prevResponders;
+ }
+
+ public final void setScopes(final String[] scopes) {
+ if (scopes != null) {
+ this.scopes = scopes;
+ }
+ }
+
+ public final String[] getScopes() {
+ return scopes;
+ }
+
+ public final String getHeaderString() {
+ final StringBuffer buffer = new StringBuffer();
+ buffer.append(super.getHeaderString());
+ buffer.append(", prevResponders=");
+ buffer.append(Arrays.asList(prevResponders));
+ buffer.append(", scopes=");
+ buffer.append(Arrays.asList(scopes));
+ return buffer.toString();
+ }
+
+ public final boolean knowsResponder(String url) {
+ for (int i = 0;i<prevResponders.length;i++){
+ if (prevResponders[i].equals(url)){
+ return true;
+ }
+ }
+ return false;
+ }
+}
Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AbstractSLPRequestMessage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AttributeReplyMessage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AttributeReplyMessage.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AttributeReplyMessage.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AttributeReplyMessage.java Tue Jun 9 12:00:29 2009
@@ -0,0 +1,245 @@
+/*
+ * 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.messages;
+
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.slp.*;
+import org.apache.directory.slp.impl.AuthenticationBlock;
+import org.apache.directory.slp.impl.SLPUtils;
+
+
+/**
+ * abstract base class for all reply messages.
+ *
+ * @author Jan S. Rellermeyer
+ */
+public final class AttributeReplyMessage extends AbstractSLPReplyMessage {
+
+ /**
+ * the message funcID values according to RFC 2608, Attribute Reply = 7.
+ */
+ public static final byte FUNC_ID = 7;
+
+ public static final String TYPE = "ATTRRPLY";
+
+ private String[] attributes = new String[]{};
+
+ private AuthenticationBlock[] authBlocks = new AuthenticationBlock[]{};
+
+ public AttributeReplyMessage() {
+ super(FUNC_ID);
+ }
+
+ public void setAttributes(final String[] attributes) {
+ this.attributes = fixAttributeArray(attributes);
+ }
+
+ public String[] getAttributes() {
+ return attributes;
+ }
+
+ public void setAuthBlocks(final AuthenticationBlock[] authBlocks) {
+ this.authBlocks = authBlocks;
+ }
+
+ public AuthenticationBlock[] getAuthBlocks() {
+ return authBlocks;
+ }
+
+ /**
+ * verify this AttributeReply.
+ *
+ * @return true if verification suceeds.
+ * @throws ServiceLocationException
+ * in case of IO errors.
+ */
+ public boolean verify() throws ServiceLocationException {
+ for (int i = 0; i < authBlocks.length; i++) {
+ if (authBlocks[i].verify(getAuthData(authBlocks[i].getSpi(),
+ authBlocks[i].getTimestamp()))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(TYPE);
+ buffer.append(" [");
+ buffer.append(getHeaderString());
+ buffer.append(", attrCount=" + attributes.length);
+ buffer.append(", attributes=" + Arrays.asList(attributes));
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+ /**
+ * get the length of the message.
+ *
+ * @return the length of the message.
+ * @see org.apache.directory.server.slp.messages.AbstractSLPMessage#getSize()
+ */
+ public int getSize() {
+ int len = getHeaderSize() + 4 + arrayToString(attributes, ",").length() + 1;
+ for (int i=0; i<authBlocks.length; i++) {
+ len += authBlocks[i].getLength();
+ }
+ return len;
+ }
+
+ /**
+ * get the bytes of the message body in the following RFC 2608 compliant
+ * format:
+ * <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 = AttrRply = 7) |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Error Code | length of <attr-list> |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | <attr-list> \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |# of AttrAuths | Attribute Authentication Block (if present) \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * </p>
+ *
+ * @return array of bytes.
+ * @throws ServiceLocationException
+ * if an IO Exception occurs.
+ * @throws IOException
+ */
+ public void writeTo(final DataOutputStream out, final int mtu) throws IOException {
+ super.writeHeader(out, getSize(),mtu);
+ out.writeShort(getErrorCode());
+ out.writeUTF(arrayToString(attributes, ","));
+ out.write(authBlocks.length);
+ for (int i = 0; i < authBlocks.length; i++) {
+ authBlocks[i].write(out);
+ }
+ }
+
+ /**
+ * get the result.
+ *
+ * @see ch.ethz.iks.slp.impl.ReplyMessage#getResult()
+ * @return the <code>List</code> of results.
+ */
+ public String[] getResult() {
+ return attributes;
+ }
+
+ public List<String> getResultAsList(){
+ return AbstractSLPMessage.arrayToList(attributes);
+ }
+
+ /**
+ * sign this AttributeReply.
+ *
+ * @param spiStr
+ * a String of SPIs.
+ * @throws ServiceLocationException
+ * in case of IO errors.
+ */
+ public void sign(final String spiStr) throws ServiceLocationException {
+ List spiList = stringToList(spiStr, ",");
+ authBlocks = new AuthenticationBlock[spiList.size()];
+ for (int k = 0; k < spiList.size(); k++) {
+ int timestamp = SLPUtils.getTimestamp();
+
+ String spi = (String) spiList.get(k);
+ byte[] data = getAuthData(spi, timestamp);
+ byte[] sig;
+ try {
+ sig = AuthenticationBlock.sign(spi,data);
+ } catch (Exception e) {
+ //SLPCore.platform.logError(e.getMessage(), e.fillInStackTrace());
+ throw new ServiceLocationException(
+ ServiceLocationException.AUTHENTICATION_FAILED,
+ "Could not sign data");
+ }
+
+
+ authBlocks[k] = new AuthenticationBlock(timestamp,spi,sig);
+ }
+ }
+
+ /**
+ * get the authentication data.
+ *
+ * @param spiStr
+ * the SPI.
+ * @param timestamp
+ * the timestamp.
+ * @return the auth data.
+ * @throws ServiceLocationException
+ * in case of IO errors.
+ */
+ private byte[] getAuthData(final String spiStr, final int timestamp)
+ throws ServiceLocationException {
+ try {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream(bos);
+ dos.writeUTF(spiStr);
+ dos.writeUTF(arrayToString(attributes, ","));
+ dos.writeInt(timestamp);
+ return bos.toByteArray();
+ } catch (IOException ioe) {
+ throw new ServiceLocationException(
+ ServiceLocationException.INTERNAL_SYSTEM_ERROR, ioe
+ .getMessage());
+ }
+ }
+
+
+ private String[] fixAttributeArray(String[] attr){
+ List<String> fixedAttrs = new ArrayList<String>();
+ String combined = "";
+ for (String s: attr){
+ if (s.toLowerCase().trim().startsWith("(")){
+ if (s.trim().endsWith(")")){
+ fixedAttrs.add(s);
+ continue;
+ }
+ combined = s;
+ } else {
+ if (s.trim().endsWith(")")){
+ fixedAttrs.add(combined+", "+s.trim());
+ continue;
+ }
+ combined = combined+","+s.trim();
+ }
+ }
+ return fixedAttrs.toArray(new String[]{});
+ }
+
+
+}
Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AttributeReplyMessage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AttributeRequestMessage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AttributeRequestMessage.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AttributeRequestMessage.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AttributeRequestMessage.java Tue Jun 9 12:00:29 2009
@@ -0,0 +1,143 @@
+/*
+ * 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.messages;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.directory.slp.ServiceLocationException;
+import org.apache.directory.slp.ServiceURL;
+
+
+
+/**
+ * Attribute request message (ATTRRQST).
+ *
+ * @author Jan S. Rellermeyer
+ */
+public final class AttributeRequestMessage extends AbstractSLPRequestMessage {
+
+ /**
+ * the message funcID values according to RFC 2608, Attribute Request = 6.
+ */
+ public static final byte FUNC_ID = 6;
+
+ public static final String TYPE = "ATTRRQST";
+
+ private ServiceURL url;
+
+ private String[] tags = EMPTY;
+
+ private String[] spis = EMPTY;
+
+
+ public AttributeRequestMessage() {
+ super(FUNC_ID);
+ }
+
+ public void setServiceURL(final ServiceURL url) {
+ this.url = url;
+ }
+
+ public ServiceURL getServiceUrl() {
+ return url;
+ }
+
+ public void setTags(final String[] tags) {
+ this.tags = tags;
+ }
+
+ public String[] getTags() {
+ return tags;
+ }
+
+ public void setSPIs(final String[] spis) {
+ this.spis = spis;
+ }
+
+ public String[] getSPIs() {
+ return spis;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(TYPE);
+ buffer.append(" [");
+ buffer.append(getHeaderString());
+ buffer.append(", url=" + url);
+ buffer.append(", tags=" + Arrays.asList(tags));
+ buffer.append(", spis=" + Arrays.asList(spis));
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+ /**
+ * get the length of the message.
+ *
+ * @return the length of the message.
+ * @see org.apache.directory.server.slp.messages.AbstractSLPMessage#getSize()
+ */
+ public int getSize() {
+ return getHeaderSize() + 2 + arrayToString(prevResponders, ",").length()
+ + 2 + url.getURL().length() + 2 + arrayToString(scopes, ",").length()
+ + 2 + arrayToString(tags, ",").length() + 2 + arrayToString(spis,",").length();
+ }
+
+ /**
+ * get the bytes of the message body in the following RFC 2608 compliant
+ * format:
+ * <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 = AttrRqst = 6) |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of PRList | <PRList> String \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of URL | URL \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of <scope-list> | <scope-list> string \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of <tag-list> string | <tag-list> string \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of <SLP SPI> string | <SLP SPI> string \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * </p>
+ *
+ * @return array of bytes.
+ * @throws ServiceLocationException
+ * @throws ServiceLocationException
+ * if an IO Exception occurs.
+ */
+ public void writeTo(final DataOutputStream out, final int mtu) throws IOException {
+ super.writeHeader(out, getSize(),mtu);
+ out.writeUTF(arrayToString(prevResponders, ","));
+ out.writeUTF(url.toString());
+ out.writeUTF(arrayToString(scopes, ","));
+ out.writeUTF(arrayToString(tags, ","));
+ out.writeUTF(arrayToString(spis,","));
+ }
+
+
+}
Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/AttributeRequestMessage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/DAAdvertisementMessage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/DAAdvertisementMessage.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/DAAdvertisementMessage.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/DAAdvertisementMessage.java Tue Jun 9 12:00:29 2009
@@ -0,0 +1,300 @@
+/*
+ * 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.messages;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.slp.ServiceLocationException;
+import org.apache.directory.slp.ServiceURL;
+import org.apache.directory.slp.impl.AuthenticationBlock;
+import org.apache.directory.slp.impl.SLPUtils;
+
+
+
+/**
+ * Directory Agent Advertisement Message (DAADVERT).
+ *
+ * @author Jan S. Rellermeyer
+ */
+public class DAAdvertisementMessage extends AbstractSLPReplyMessage {
+
+ /**
+ * the message funcID values according to RFC 2608, DA Advertisement = 8.
+ */
+ public static final byte FUNC_ID = 8;
+
+ public static final String TYPE = "DAADVERT";
+
+ private int bootTimestamp;
+
+ private ServiceURL serviceURL;
+
+ // For verification
+ private String origURL;
+
+ private String[] scopes = EMPTY;
+
+ private String[] attributes = EMPTY;
+
+ private String[] spis = EMPTY;
+
+ private AuthenticationBlock[] authBlocks = new AuthenticationBlock[0];
+
+ public DAAdvertisementMessage() {
+ super(FUNC_ID);
+ scopes=new String[]{"default"};
+ }
+
+ public void setStatelessBootTimestamp(int bootTimestamp) {
+ this.bootTimestamp = bootTimestamp;
+ }
+
+ public int getStatelessBootTimestamp() {
+ return bootTimestamp;
+ }
+
+ public void setOrigURL(String s){
+ origURL=s;
+ }
+
+ public void setServiceURL(ServiceURL serviceURL) {
+ this.serviceURL = serviceURL;
+ }
+
+ public ServiceURL getServiceURL() {
+ return serviceURL;
+ }
+
+ public void setScopes(String[] scopes) {
+ this.scopes = scopes;
+ }
+
+ public String[] getScopes() {
+ return scopes;
+ }
+
+ public void setAttributes(String[] attributes) {
+ this.attributes = attributes;
+ }
+
+ public String[] getAttributes() {
+ return attributes;
+ }
+
+ public void setSPIs(String[] spis) {
+ this.spis = spis;
+ }
+
+ public String[] getSPIs() {
+ return spis;
+ }
+
+ public void setAuthBlocks(AuthenticationBlock[] authBlocks) {
+ this.authBlocks = authBlocks;
+ }
+
+ public AuthenticationBlock[] getAuthBlocks() {
+ return authBlocks;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(TYPE);
+ buffer.append(" [");
+ buffer.append(getHeaderString());
+ buffer.append(", url=" + serviceURL);
+ buffer.append(", scopes=");
+ buffer.append(Arrays.asList(scopes));
+ buffer.append(", attributes=");
+ buffer.append(Arrays.asList(attributes));
+ buffer.append(", spis=");
+ buffer.append(Arrays.asList(spis));
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+
+ /**
+ * get the length of the message.
+ *
+ * @return the length of the message.
+ * @see org.apache.directory.server.slp.messages.AbstractSLPMessage#getSize()
+ */
+ public int getSize() {
+ int len = getHeaderSize() + 8 + serviceURL.getURL().length() + 2
+ + arrayToString(scopes,",").length() + 2 + arrayToString(attributes,",").length() + 2
+ + arrayToString(spis,",").length() + 1;
+ for (int i = 0; i < authBlocks.length; i++) {
+ len += authBlocks[i].getLength();
+ }
+ return len;
+ }
+
+ /**
+ * get the bytes of the message body in the following RFC 2608 compliant
+ * format:
+ * <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 = DAAdvert = 8) |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Error Code | DA Stateless Boot Timestamp |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |DA Stateless Boot Time,, contd.| Length of URL |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * \ URL \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Length of <scope-list> | <scope-list> \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Length of <attr-list> | <attr-list> \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Length of <SLP SPI List> | <SLP SPI List> String \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | # Auth Blocks | Authentication block (if any) \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * </p>
+ *
+ * @return array of bytes.
+ * @throws ServiceLocationException
+ * if an IO Exception occurs.
+ */
+ public void writeTo(final DataOutputStream out, final int mtu) throws IOException {
+ // this is never sent, since we are not a DA...
+ }
+
+
+ public String[] getResult() {
+ if (origURL.equals("") || origURL==null){
+ return new String[]{serviceURL.toString()};
+ }
+ return new String[]{origURL};
+ }
+
+ public List<String> getResultAsList(){
+ if (origURL.equals("") || origURL==null){
+ return AbstractSLPMessage.arrayToList(new String[]{serviceURL.toString()});
+ }
+
+ return AbstractSLPMessage.arrayToList(new String[]{origURL});
+ }
+
+
+ /**
+ * verify the DAAdvertisement.
+ *
+ * @return true if verification succeeded.
+ * @throws ServiceLocationException
+ * in case of IO errors.
+ */
+ public boolean verify() throws ServiceLocationException {
+ for (int i = 0; i < authBlocks.length; i++) {
+ if (authBlocks[i].verify(getAuthData(authBlocks[i].getSpi(),
+ authBlocks[i].getTimestamp()))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+
+ /**
+ * get the authentication data.
+ *
+ * @param spiStr
+ * the SPI
+ * @param timestamp
+ * the timestamp
+ * @return the authentication data.
+ * @throws ServiceLocationException
+ * in case of IO errors.
+ */
+ private byte[] getAuthData(final String spiStr, final int timestamp)
+ throws ServiceLocationException {
+ try {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream(bos);
+
+ dos.writeUTF(spiStr);
+ dos.writeInt(bootTimestamp);
+ dos.writeUTF(origURL);
+ /*
+ * THIS IS WRONG: RFC 2608 wants the attrs first, followed by the
+ * scopes but OpenSLP makes it the other way around !!!
+ *
+ * see bug #1346056
+ */
+ dos.writeUTF(arrayToString(scopes, ","));
+ dos.writeUTF(arrayToString(attributes,","));
+ dos.writeUTF(arrayToString(spis, ","));
+ dos.writeInt(timestamp);
+
+ return bos.toByteArray();
+ } catch (IOException ioe) {
+ throw new ServiceLocationException(
+ ServiceLocationException.INTERNAL_SYSTEM_ERROR, ioe
+ .getMessage());
+ }
+ }
+
+ /**
+ * sign this DAAdvert.
+ *
+ * @param spiStr
+ * a String of SPIs.
+ * @throws ServiceLocationException
+ * in case of IO errors.
+ */
+ public void sign(final String spiStr) throws ServiceLocationException {
+ List spiList = stringToList(spiStr, ",");
+ authBlocks = new AuthenticationBlock[spiList.size()];
+ for (int k = 0; k < spiList.size(); k++) {
+ int timestamp = SLPUtils.getTimestamp();
+
+ String spi = (String) spiList.get(k);
+ byte[] data = getAuthData(spi, timestamp);
+ byte[] sig;
+ try {
+ sig = AuthenticationBlock.sign(spi,data);
+ } catch (Exception e) {
+ //SLPCore.platform.logError(e.getMessage(), e.fillInStackTrace());
+ throw new ServiceLocationException(
+ ServiceLocationException.AUTHENTICATION_FAILED,
+ "Could not sign data");
+ }
+
+
+ authBlocks[k] = new AuthenticationBlock(timestamp,spi,sig);
+ }
+ }
+
+
+
+
+
+}
Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/DAAdvertisementMessage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceAcknowledgementMessage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceAcknowledgementMessage.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceAcknowledgementMessage.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceAcknowledgementMessage.java Tue Jun 9 12:00:29 2009
@@ -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.slp.messages;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.directory.slp.ServiceLocationException;
+
+
+/**
+ * Service Acknowledgement Message (SRVACK).
+ *
+ * @author Jan S. Rellermeyer
+ */
+public class ServiceAcknowledgementMessage extends AbstractSLPReplyMessage {
+
+ /**
+ * the message funcID values according to RFC 2608, Service Acknowledgement =
+ * 5.
+ */
+ public static final byte FUNC_ID = 5;
+
+ public static final String TYPE = "SRVACK";
+
+ public ServiceAcknowledgementMessage() {
+ super(FUNC_ID);
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(TYPE);
+ buffer.append(" [");
+ buffer.append(getHeaderString());
+ buffer.append(", errorCode=" + getErrorCode());
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+ /**
+ * get the length of the message.
+ *
+ * @return the length of the message.
+ * @see org.apache.directory.server.slp.messages.AbstractSLPMessage#getSize()
+ */
+ public int getSize() {
+ return getHeaderSize() + 2;
+ }
+
+ /**
+ * get the bytes of the message body in the following RFC 2608 compliant
+ * format:
+ * <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 = SrvAck = 5) |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Error Code |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * </p>
+ *
+ * @return array of bytes.
+ * @throws ServiceLocationException
+ * if an IO Exception occurs.
+ */
+ public void writeTo(final DataOutputStream out, final int mtu) throws IOException {
+ super.writeHeader(out, getSize(),mtu);
+ out.writeShort(getErrorCode());
+ }
+
+ public String[] getResult() {
+ return null;
+ }
+
+ public List<String> getResultAsList(){
+
+ return null;
+ }
+
+}
Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceAcknowledgementMessage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceDeregistrationMessage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceDeregistrationMessage.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceDeregistrationMessage.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceDeregistrationMessage.java Tue Jun 9 12:00:29 2009
@@ -0,0 +1,169 @@
+/*
+ * 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.messages;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.slp.ServiceLocationException;
+import org.apache.directory.slp.ServiceURL;
+import org.apache.directory.slp.impl.SLPCore;
+import org.apache.directory.slp.impl.SLPUtils;
+
+
+/**
+ * Service Derigistration Message (SRVDEREG).
+ *
+ * @author Jan S. Rellermeyer
+ */
+public final class ServiceDeregistrationMessage extends AbstractSLPMessage {
+
+ /**
+ * the message funcID values according to RFC 2608, Service Deregistration =
+ * 4.
+ */
+ public static final byte FUNC_ID = 4;
+
+ public static final String TYPE = "SRVDEREG";
+
+ private String[] scopes = EMPTY;
+
+ private ServiceURL url;
+
+ private String[] tags = EMPTY;
+
+ public ServiceDeregistrationMessage() {
+ super(FUNC_ID);
+ scopes = SLPUtils.stringToStringArray(SLPCore.CONFIG.getScopes(), ",");
+ }
+
+ public void setScopes(final String[] scopes) {
+ if (scopes!=null){
+ this.scopes = scopes;
+ }
+
+ }
+
+ public String[] getScopes() {
+ return scopes;
+ }
+
+ public void setServiceURL(ServiceURL url) {
+ this.url = url;
+ }
+
+ public ServiceURL getServiceURL() {
+ return url;
+ }
+
+ public void setTags(String[] tags) {
+ this.tags = tags;
+ }
+
+ public String[] getTags() {
+ return tags;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(TYPE);
+ buffer.append(" [");
+ buffer.append(getHeaderString());
+ buffer.append(", scopes=" + Arrays.asList(scopes));
+ buffer.append(", url=" + url.toString());
+ buffer.append(", tags=" + Arrays.asList(tags));
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+ /**
+ * get the length of the message.
+ *
+ * @return the length of the message.
+ * @see org.apache.directory.server.slp.messages.AbstractSLPMessage#getSize()
+ */
+ public int getSize() {
+ return getHeaderSize() + 2 + arrayToString(scopes, ",").length()
+ + url.getLength() + 2
+ + arrayToString(tags, ",").length();
+ }
+
+ /**
+ * get the bytes from a ServiceDeregistration:
+ * <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 = SrvDeReg = 4) |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Length of <scope-list> | <scope-list> \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | URL Entry \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Length of <tag-list> | <tag-list> \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * </p>
+ *
+ * @return the bytes.
+ * @throws ServiceLocationException
+ * in case of IO errors.
+ */
+ public void writeTo(final DataOutputStream out, final int mtu) throws IOException {
+ super.writeHeader(out, getSize(),mtu);
+ out.writeUTF(arrayToString(scopes, ","));
+ url.writeTo(out);
+ out.writeUTF(arrayToString(tags, ","));
+ }
+
+ /**
+ * sign this ServiceDeregistration.
+ *
+ * @param spiList
+ * a List of SPIs.
+ * @throws ServiceLocationException
+ * in case of IO errors.
+ */
+ public void sign(final List spiList) throws ServiceLocationException {
+ url.sign(spiList);
+ }
+
+ /**
+ * verify the ServiceDeregistration.
+ *
+ * @return true if it could be verified.
+ * @throws ServiceLocationException
+ * in case of IO errors.
+ */
+ boolean verify() throws ServiceLocationException {
+ try {
+ url.verify();
+ return true;
+ } catch (Exception e){
+ throw new ServiceLocationException(ServiceLocationException.AUTHENTICATION_FAILED,e.getMessage());
+ }
+
+ }
+
+}
Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceDeregistrationMessage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceRegistrationMessage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceRegistrationMessage.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceRegistrationMessage.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceRegistrationMessage.java Tue Jun 9 12:00:29 2009
@@ -0,0 +1,358 @@
+/*
+ * 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.messages;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.directory.slp.ServiceLocationException;
+import org.apache.directory.slp.ServiceType;
+import org.apache.directory.slp.ServiceURL;
+import org.apache.directory.slp.impl.AuthenticationBlock;
+import org.apache.directory.slp.impl.SLPCore;
+import org.apache.directory.slp.impl.SLPUtils;
+
+
+
+
+/**
+ * Service Registration Message (SRVREG)
+ *
+ * @author Jan S. Rellermeyer
+ */
+public class ServiceRegistrationMessage extends AbstractSLPMessage {
+
+ /**
+ * the message funcID values according to RFC 2608, Service Registration =
+ * 3.
+ */
+ public static final byte FUNC_ID = 3;
+
+ public static final String TYPE = "SRVREG";
+
+ private ServiceURL serviceURL;
+
+ private ServiceType serviceType;
+
+ private String[] scopes = EMPTY;
+
+ private String[] attrList = EMPTY;
+
+ private String verbatimAttrList = "";
+
+ private AuthenticationBlock[] authBlocks;
+
+ public ServiceRegistrationMessage() {
+ super(FUNC_ID);
+ scopes = SLPUtils.stringToStringArray(SLPCore.CONFIG.getScopes(), ",");
+ }
+
+ public ServiceURL getServiceURL() {
+ return serviceURL;
+ }
+
+ public void setServiceURL(final ServiceURL serviceURL) {
+ this.serviceURL = serviceURL;
+ }
+
+ public ServiceType getServiceType() {
+ return serviceType;
+ }
+
+ public void setServiceType(final ServiceType serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ public String[] getScopes() {
+ return scopes;
+ }
+
+ public void setScopes(final String[] scopes) {
+ if (scopes!=null){
+ this.scopes = scopes;
+ }
+
+ }
+
+ public String[] getAttrList() {
+ return attrList;
+ }
+
+ public void setAttrList(final String[] attrList) {
+ this.attrList = attrList;
+ }
+
+ public void setAttributes(final String verbatim){
+ verbatimAttrList = verbatim;
+ attrList = makeAttributeArray(verbatim);
+
+ }
+
+ public String getVerbatimAttributeList(){
+ return verbatimAttrList;
+ }
+
+ public void setAuthBlocks(final AuthenticationBlock[] authBlocks) {
+ this.authBlocks = authBlocks;
+ }
+
+ public AuthenticationBlock[] getAuthBlocks() {
+ return authBlocks;
+ }
+
+
+
+
+ /**
+ * sign this ServiceRegistration.
+ *
+ * @param spiList
+ * the List of SPIs.
+ * @throws ServiceLocationException
+ * in case of IO errors.
+ */
+ public void sign(final String[] spis) throws ServiceLocationException {
+ serviceURL.sign(spis);
+
+ authBlocks = new AuthenticationBlock[spis.length];
+ for (int k = 0; k < spis.length; k++) {
+ int timestamp = SLPUtils.getTimestamp();
+
+ String spi = (String) spis[k];
+
+ byte[] data = getAuthData(spi, timestamp);
+ byte[] sig;
+ try {
+ sig = AuthenticationBlock.sign(spi,data);
+ } catch (Exception e) {
+ //SLPCore.platform.logError(e.getMessage(), e.fillInStackTrace());
+ throw new ServiceLocationException(
+ ServiceLocationException.AUTHENTICATION_FAILED,
+ "Could not sign data");
+ }
+ authBlocks[k] = new AuthenticationBlock(timestamp,spi,sig);
+
+
+
+ }
+ }
+
+ /**
+ * verify this ServiceRegistration.
+ *
+ * @return true if verification suceeds.
+ * @throws ServiceLocationException
+ * in case of IO errors.
+ */
+ public boolean verify() throws ServiceLocationException {
+ serviceURL.verify();
+ for (int i = 0; i < authBlocks.length; i++) {
+ if (authBlocks[i].verify(getAuthData(authBlocks[i].getSpi(),
+ authBlocks[i].getTimestamp()))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+
+
+ public String toString() {
+ final StringBuffer buffer = new StringBuffer();
+ buffer.append(TYPE);
+ buffer.append(" [");
+ buffer.append("xid=" + xid);
+ buffer.append(", locale=" + locale);
+ buffer.append(", url: " + serviceURL);
+ buffer.append(", serviceType: " + serviceType);
+ buffer.append(", scopeList: " + Arrays.asList(scopes));
+ buffer.append(", attList: " + Arrays.asList(attrList));
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+ /**
+ * get the length of the message.
+ *
+ * @return the length of the message.
+ * @see org.apache.directory.server.slp.messages.AbstractSLPMessage#getSize()
+ */
+ public int getSize() {
+ int len = getHeaderSize() + serviceURL.getLength() + 2
+ + serviceType.toString().length() + 2
+ + arrayToString(scopes, ",").length() + 2
+ + arrayToString(attrList, ",").length() + 1;
+ if (authBlocks!=null){
+ for (int i = 0; i < authBlocks.length; i++) {
+ len += authBlocks[i].getLength();
+ }
+ }
+ return len;
+ }
+
+ /**
+ * get the bytes of the message body in the following RFC 2608 compliant
+ * format:
+ * <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) |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | <URL-Entry> \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of service type string | <service-type> \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of <scope-list> | <scope-list> \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of attr-list string | <attr-list> \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |# of AttrAuths |(if present) Attribute Authentication Blocks...\
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * </p>
+ *
+ * @return array of bytes.
+ * @throws ServiceLocationException
+ * if an IO Exception occurs.
+ */
+ public void writeTo(final DataOutputStream out, final int mtu) throws IOException {
+ super.writeHeader(out, getSize(),mtu);
+ serviceURL.writeTo(out);
+ out.writeUTF(serviceType.toString());
+ out.writeUTF(arrayToString(scopes, ","));
+ out.writeUTF(arrayToString(attrList, ","));
+ out.write(authBlocks.length);
+ for (int i = 0; i < authBlocks.length; i++) {
+ authBlocks[i].write(out);
+ }
+
+
+ }
+
+ /**
+ * get the authentication data.
+ *
+ * @param spi
+ * the SPI.
+ * @param timestamp
+ * the timestamp.
+ * @return the auth data.
+ * @throws ServiceLocationException
+ * in case of IO errors.
+ */
+ private byte[] getAuthData(final String spi, final int timestamp)
+ throws ServiceLocationException {
+ try {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream(bos);
+
+ dos.writeUTF(spi);
+ dos.writeUTF(arrayToString(attrList, ","));
+ dos.writeInt(timestamp);
+ return bos.toByteArray();
+ } catch (IOException ioe) {
+ throw new ServiceLocationException(
+ ServiceLocationException.INTERNAL_SYSTEM_ERROR, ioe
+ .getMessage());
+ }
+ }
+
+
+
+
+ public boolean checkAttributeListValidity(){
+ boolean valid = true;
+ int pos = 0;
+ String initialType;
+ String type;
+ for (String s : attrList){
+ pos = s.indexOf("=");
+ if (pos<0){
+ // it's just a keyword
+ continue;
+ }
+ String value = s.substring(pos+1,s.length()-1);
+ StringTokenizer tokenizer = new StringTokenizer(value,",");
+ if (tokenizer.countTokens()==1){
+ //single-valued, no worries
+ continue;
+ }
+ initialType = "";
+ while (tokenizer.hasMoreTokens()){
+ type="";
+ String token = tokenizer.nextToken().trim();
+ if (token.startsWith("\\FF")){
+ type = "opaque";
+ } else if (token.toLowerCase().trim().equals("true") || token.toLowerCase().trim().equals("false") ){
+ type="boolean";
+ } else {
+ try {
+ Integer.parseInt(token.trim());
+ type = "integer";
+ } catch (NumberFormatException e){
+ type= "string";
+ }
+ }
+ if (initialType.equals("")){
+ //first round
+ initialType = type;
+ continue;
+ }
+ if (!type.equals(initialType)){
+ valid = false;
+ }
+ }
+ }
+ return valid;
+ }
+
+
+ private String[] makeAttributeArray(String attrString){
+ List<String> fixedAttrs = new ArrayList<String>();
+ String combined = "";
+ for (String s: SLPUtils.stringToStringArray(attrString, ",")){
+ if (s.toLowerCase().trim().startsWith("(")){
+ if (s.trim().endsWith(")")){
+ fixedAttrs.add(s);
+ continue;
+ }
+ combined = s;
+ } else {
+ if (s.trim().endsWith(")")){
+ fixedAttrs.add(combined+", "+s.trim());
+ continue;
+ }
+ combined = combined+","+s.trim();
+ }
+ }
+ return fixedAttrs.toArray(new String[]{});
+ }
+
+
+}
Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceRegistrationMessage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceReplyMessage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceReplyMessage.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceReplyMessage.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceReplyMessage.java Tue Jun 9 12:00:29 2009
@@ -0,0 +1,171 @@
+/*
+ * 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.messages;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.slp.ServiceLocationException;
+import org.apache.directory.slp.ServiceURL;
+
+
+
+/**
+ * Service Reply Message (SRVRPLY).
+ *
+ * @author Jan S. Rellermeyer
+ */
+public class ServiceReplyMessage extends AbstractSLPReplyMessage {
+
+ /**
+ * the message funcID values according to RFC 2608, Service Reply = 2.
+ */
+ public static final byte FUNC_ID = 2;
+
+ public static final String TYPE = "SRVRPLY";
+
+ private ServiceURL[] serviceURLs;
+
+ public ServiceReplyMessage() {
+ super(FUNC_ID);
+ }
+
+ public void setServiceURLs(ServiceURL[] serviceURLs) {
+ this.serviceURLs = serviceURLs;
+ }
+
+ public ServiceURL[] getServiceURLs() {
+ return serviceURLs;
+ }
+
+ public String toString() {
+ final StringBuffer buffer = new StringBuffer();
+ buffer.append(TYPE);
+ buffer.append(" - ");
+ buffer.append(getHeaderString());
+ buffer.append(", serviceURLs=");
+ buffer.append(Arrays.asList(serviceURLs));
+ return buffer.toString();
+ }
+
+ /**
+ * get the length of the message.
+ *
+ * @return the length of the message.
+ * @see org.apache.directory.server.slp.messages.AbstractSLPMessage#getSize()
+ */
+ public int getSize() {
+ int len = getHeaderSize() + 2 + 2;
+ for (int i = 0; i < serviceURLs.length; i++) {
+ len += serviceURLs[i].getLength();
+ }
+ return len;
+ }
+
+ /**
+ * get the bytes of the message body in the following RFC 2608 compliant
+ * format:
+ * <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 = SrvRply = 2) |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Error Code | URL Entry count |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | <URL Entry 1> ... <URL Entry N> \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ * </pre>
+ *
+ * </p>
+ *
+ * @return array of bytes.
+ * @throws ServiceLocationException
+ * if an IO Exception occurs.
+ */
+ public void writeTo(final DataOutputStream out, final int mtu) throws IOException {
+ super.writeHeader(out, getSize(),mtu);
+ out.writeShort(getErrorCode());
+ out.writeShort(serviceURLs.length);
+ for (int i = 0; i < serviceURLs.length; i++) {
+ ((ServiceURL) serviceURLs[i]).writeTo(out);
+ }
+ }
+
+ public String[] getResult() {
+ String[] res = new String[serviceURLs.length];
+ for (int i=0;i<serviceURLs.length;i++){
+ res[i]=serviceURLs[i].getURL();
+ }
+ return res;
+ }
+
+
+ public List<String> getResultAsList(){
+ List<String> result = new ArrayList<String>();
+ for (int i=0;i<serviceURLs.length;i++){
+ result.add(serviceURLs[i].toString());
+ }
+ return result;
+ }
+
+
+
+
+ /**
+ * sign the ServiceReply.
+ *
+ * @param spiStr
+ * the SPI String.
+ * @throws ServiceLocationException
+ * in case of IO errors.
+ */
+ public void sign(final String spiStr) throws ServiceLocationException {
+ List spiList = stringToList(spiStr, ",");
+ for (int i=0;i<serviceURLs.length;i++) {
+ ServiceURL url = serviceURLs[i];
+ url.sign(spiList);
+ }
+ for (int i=0;i<extensions.length;i++){
+ extensions[i].sign(spiStr);
+ }
+ }
+
+ /**
+ * verify the ServiceReply.
+ *
+ * @return true if it could be verified.
+ * @throws ServiceLocationException
+ * in case of IO errors.
+ */
+ public boolean verify() throws ServiceLocationException {
+ for (int i = 0; i<serviceURLs.length;i++) {
+ ServiceURL url = serviceURLs[i];
+ url.verify();
+ }
+ return true;
+ }
+}
Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceReplyMessage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceRequestMessage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceRequestMessage.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceRequestMessage.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceRequestMessage.java Tue Jun 9 12:00:29 2009
@@ -0,0 +1,144 @@
+/*
+ * 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.messages;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.directory.slp.ServiceLocationException;
+import org.apache.directory.slp.ServiceType;
+
+
+/**
+ * Service Request Message (SRVRQST).
+ *
+ * @author Jan S. Rellermeyer
+ */
+public class ServiceRequestMessage extends AbstractSLPRequestMessage {
+
+ /**
+ * the message funcID values according to RFC 2608, Service Request = 1.
+ */
+ public static final byte FUNC_ID = 1;
+
+ public static final String TYPE = "SRVRQST";
+
+ private ServiceType serviceType;
+
+ private String predicate = "";
+
+ private String[] spis = EMPTY;
+
+ public ServiceRequestMessage() {
+ super(FUNC_ID);
+ }
+
+ public void setServiceType(final ServiceType serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ public ServiceType getServiceType() {
+ return serviceType;
+ }
+
+ public void setPredicate(final String predicate) {
+ if (predicate != null) {
+ this.predicate = predicate;
+ }
+ }
+
+ public String getPredicate() {
+ return predicate;
+ }
+
+ public void setSPIs(String[] spis) {
+ this.spis = spis;
+ }
+
+ public String[] getSPIs() {
+ return spis;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(TYPE);
+ buffer.append(" [");
+ buffer.append(getHeaderString());
+ buffer.append(", serviceType=" + serviceType);
+ buffer.append(", predicate=" + predicate);
+ buffer.append(", spis=" + Arrays.asList(spis));
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+ /**
+ * get the length of the message.
+ *
+ * @return the length of the message.
+ * @see org.apache.directory.server.slp.messages.AbstractSLPMessage#getSize()
+ */
+ public int getSize() {
+ return getHeaderSize() + 2 + arrayToString(prevResponders, ",").length()
+ + 2 + serviceType.toString().length() + 2
+ + arrayToString(scopes, ",").length() + 2
+ + (predicate == null ? 0 : predicate.toString().length()) + 2
+ + arrayToString(spis, ",").length();
+ }
+
+ /**
+ * get the bytes of the message body in the following RFC 2608 compliant
+ * format:
+ * <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 = SrvRqst = 1) |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of <PRList> | <PRList> String \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of <service-type> | <service-type> String \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of <scope-list> | <scope-list> String \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of predicate string | Service Request <predicate> \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of <SLP SPI> string | <SLP SPI> String \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * </p>
+ *
+ * @return array of bytes.
+ * @throws ServiceLocationException
+ * @throws ServiceLocationException
+ * if an IO Exception occurs.
+ */
+ public void writeTo(final DataOutputStream out, final int mtu) throws IOException {
+ super.writeHeader(out, getSize(),mtu);
+ out.writeUTF(arrayToString(prevResponders, ","));
+ out.writeUTF(serviceType.toString());
+ out.writeUTF(arrayToString(scopes, ","));
+ out.writeUTF(predicate == null ? "" : predicate.toString());
+ out.writeUTF(arrayToString(spis,","));
+ }
+
+}
Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceRequestMessage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceTypeReplyMessage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceTypeReplyMessage.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceTypeReplyMessage.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceTypeReplyMessage.java Tue Jun 9 12:00:29 2009
@@ -0,0 +1,156 @@
+/*
+ * 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.messages;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.slp.ServiceLocationException;
+import org.apache.directory.slp.ServiceType;
+
+
+/**
+ * Service Type Reply Message (SRVTYPEREPLY)
+ *
+ * @author Jan S. Rellermeyer
+ */
+public class ServiceTypeReplyMessage extends AbstractSLPReplyMessage {
+
+ /**
+ * the message funcID values according to RFC 2608, Service Type Reply = 10.
+ */
+ public static final byte FUNC_ID = 10;
+
+ public static final String TYPE = "SRVTYPERPLY";
+
+ private ServiceType[] serviceTypes;
+
+ public ServiceTypeReplyMessage() {
+ super(FUNC_ID);
+ }
+
+ public void setServiceTypes(ServiceType[] serviceTypes) {
+ this.serviceTypes = serviceTypes;
+ }
+
+ public ServiceType[] getServiceTypes() {
+ return serviceTypes;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(TYPE);
+ buffer.append(" [");
+ buffer.append(getHeaderString());
+ buffer.append(", serviceTypes=");
+ buffer.append(Arrays.asList(serviceTypes));
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+ /**
+ * get the length of the message.
+ *
+ * @return the length of the message.
+ * @see org.apache.directory.server.slp.messages.AbstractSLPMessage#getSize()
+ */
+ public int getSize() {
+ int len = 0;
+ for (int i=0;i<serviceTypes.length;i++){
+ len+=serviceTypes[i].toString().length();
+ }
+ return getHeaderSize() + 2 + 2
+ + len;
+ }
+
+ /**
+ * get the bytes of the message body in the following RFC 2608 compliant
+ * format:
+ * <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 <srvType-list> |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | <srvtype--list> \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * </p>
+ *
+ * @return array of bytes.
+ * @throws ServiceLocationException
+ * if an IO Exception occurs.
+ */
+ public void writeTo(final DataOutputStream out, final int mtu) throws IOException {
+ super.writeHeader(out, getSize(),mtu);
+ out.writeShort(getErrorCode());
+ for (int i=0;i<serviceTypes.length-1;i++){
+ out.writeUTF(serviceTypes[i].toString()+",");
+ }
+ out.writeUTF(serviceTypes[serviceTypes.length].toString());
+ }
+
+ /**
+ * get the result of the reply message.
+ *
+ * @return the <code>List</code> of results.
+ * @see ch.ethz.iks.slp.impl.ReplyMessage#getResult()
+ */
+ public String[] getResult() {
+ String[] res = new String[serviceTypes.length];
+ for (int i=0;i<serviceTypes.length;i++){
+ res[i]=serviceTypes[i].toString();
+ }
+ return res;
+ }
+
+ public List<String> getResultAsList(){
+ List<String> result = new ArrayList<String>();
+ for (int i=0;i<serviceTypes.length;i++){
+ result.add(serviceTypes[i].toString());
+ }
+ return result;
+ }
+
+ /**
+ *
+ * Converts a <code>List</code> of <code>ServiceType</code> objects to an array of such.
+ *
+ * @param list The <code>List</code> of <code>ServiceType</code>
+ *
+ * @return array of <code>ServiceType</code>.
+ *
+ */
+ public static ServiceType[] listToServiceTypeArray(final List list){
+ ServiceType[] result = new ServiceType[list.size()];
+ for (int i=0;i<result.length;i++){
+ result[i]=(ServiceType) list.get(i);
+ }
+ return result;
+ }
+
+}
Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceTypeReplyMessage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceTypeRequestMessage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceTypeRequestMessage.java?rev=782968&view=auto
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceTypeRequestMessage.java (added)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceTypeRequestMessage.java Tue Jun 9 12:00:29 2009
@@ -0,0 +1,129 @@
+/*
+ * 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.messages;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.directory.slp.ServiceLocationException;
+
+
+/**
+ * Service Type Request Message (SRVTYPERQST)
+ *
+ * @author Jan S. Rellermeyer
+ */
+public class ServiceTypeRequestMessage extends AbstractSLPRequestMessage {
+
+ /**
+ * the message funcID values according to RFC 2608, Service Type Request =
+ * 9.
+ */
+ public static final byte FUNC_ID = 9;
+
+ public static final String TYPE = "SRVTYPERQST";
+
+ private String namingAuthority;
+
+
+ private static final String NA_ALL = "*";
+ private static final String NA_DEFAULT = "";
+
+ public ServiceTypeRequestMessage() {
+ super(FUNC_ID);
+ scopes=new String[]{"default"};
+ }
+
+ public void setNamingAuthority(String namingAuthority) {
+ this.namingAuthority = namingAuthority;
+ }
+
+ public String getNamingAuthority() {
+ return namingAuthority;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(TYPE);
+ buffer.append(" [");
+ buffer.append(getHeaderString());
+ buffer.append(", namingAuthority=" + namingAuthority);
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+ /**
+ * get the length of the message.
+ *
+ * @return the length of the message.
+ * @see org.apache.directory.server.slp.messages.AbstractSLPMessage#getSize()
+ */
+ public int getSize() {
+ int len = getHeaderSize() + 2
+ + arrayToString(prevResponders, ",").length();
+ if(namingAuthority.equals(NA_DEFAULT) || namingAuthority.equals(NA_ALL)) {
+ len += 2;
+ } else {
+ len += 2 + namingAuthority.length();
+ }
+ len += 2 + arrayToString(scopes, ",").length();
+ return len;
+ }
+
+ /**
+ * get the bytes of the message body in the following RFC 2608 compliant
+ * format:
+ * <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 = SrvTypeRqst = 9) |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of PRList | <PRList> String \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of Naming Authority | <Naming Authority String> \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | length of <scope-list> | <scope-list> String \
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * </pre>.
+ * </p>
+ *
+ * @return array of bytes.
+ * @throws IOException
+ * @throws ServiceLocationException
+ * @throws ServiceLocationException
+ * if an IO Exception occurs.
+ */
+ public void writeTo(final DataOutputStream out, final int mtu) throws IOException {
+ super.writeHeader(out, getSize(),mtu);
+ out.writeUTF(arrayToString(prevResponders, ","));
+ if (namingAuthority.equals(NA_ALL)) {
+ out.writeShort(0xFFFF);
+ } else if (namingAuthority.equals(NA_DEFAULT)) {
+ out.writeUTF("");
+ } else {
+ out.writeUTF(namingAuthority);
+ }
+ out.writeUTF(arrayToString(scopes, ","));
+ }
+
+}
Propchange: directory/sandbox/slp/src/main/java/org/apache/directory/slp/messages/ServiceTypeRequestMessage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: directory/sandbox/slp/src/test/java/org/apache/directory/slp/messages/MessageTest.java.disabled (from r782966, directory/sandbox/slp/src/test/java/org/apache/directory/server/slp/messages/MessageTest.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/test/java/org/apache/directory/slp/messages/MessageTest.java.disabled?p2=directory/sandbox/slp/src/test/java/org/apache/directory/slp/messages/MessageTest.java.disabled&p1=directory/sandbox/slp/src/test/java/org/apache/directory/server/slp/messages/MessageTest.java&r1=782966&r2=782968&rev=782968&view=diff
==============================================================================
--- directory/sandbox/slp/src/test/java/org/apache/directory/server/slp/messages/MessageTest.java (original)
+++ directory/sandbox/slp/src/test/java/org/apache/directory/slp/messages/MessageTest.java.disabled Tue Jun 9 12:00:29 2009
@@ -1,14 +1,14 @@
-package org.apache.directory.server.slp.messages;
+package org.apache.directory.slp.messages;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
-import org.apache.directory.server.slp.ServiceLocationException;
-import org.apache.directory.server.slp.ServiceType;
-import org.apache.directory.server.slp.ServiceURL;
-import org.apache.directory.server.slp.codec.SLPProtocolCodecFactory;
+import org.apache.directory.slp.ServiceLocationException;
+import org.apache.directory.slp.ServiceType;
+import org.apache.directory.slp.ServiceURL;
+import org.apache.directory.slp.codec.SLPProtocolCodecFactory;
import org.apache.mina.common.ConnectFuture;
import org.apache.mina.common.IdleStatus;
import org.apache.mina.common.IoHandler;