SSrvMsg.java revision 2
3988N/A/*
3988N/A * CDDL HEADER START
3988N/A *
3988N/A * The contents of this file are subject to the terms of the
3988N/A * Common Development and Distribution License (the "License").
3988N/A * You may not use this file except in compliance with the License.
3988N/A *
3988N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3988N/A * or http://www.opensolaris.org/os/licensing.
3988N/A * See the License for the specific language governing permissions
3988N/A * and limitations under the License.
3988N/A *
3988N/A * When distributing Covered Code, include this CDDL HEADER in each
3988N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3988N/A * If applicable, add the following below this CDDL HEADER, with the
3988N/A * fields enclosed by brackets "[]" replaced with your own identifying
3988N/A * information: Portions Copyright [yyyy] [name of copyright owner]
3988N/A *
3988N/A * CDDL HEADER END
3988N/A */
3988N/A/*
3988N/A * Copyright (c) 1999 by Sun Microsystems, Inc.
3988N/A * All rights reserved.
3988N/A *
4222N/A */
3988N/A
4306N/A// SSrvMsg.java: Message class for SLP service request.
4306N/A// Author: James Kempf
3988N/A// Created On: Thu Oct 9 13:40:16 1997
3988N/A// Last Modified By: James Kempf
3988N/A// Last Modified On: Tue Oct 27 10:57:38 1998
3988N/A// Update Count: 112
3988N/A//
3988N/A
3988N/Apackage com.sun.slp;
3988N/A
3988N/Aimport java.util.*;
3988N/Aimport java.io.*;
3988N/A
3988N/A
3988N/A/**
3988N/A * The SSrvMsg class models the SLP service (request, reply) message
3988N/A * server side. Subclasses for other versions can specialize the
3988N/A * initialize() and makeReply() methods.
3988N/A *
4222N/A * @author James Kempf
3988N/A */
3988N/A
3988N/Aclass SSrvMsg extends SrvLocMsgImpl {
3988N/A
3988N/A String serviceType = ""; // service type and naming authority
3988N/A String query = ""; // the query
3988N/A String spi = "";
3988N/A
3988N/A protected SSrvMsg() {}
3988N/A
3988N/A // Construct a SSrvMsg from the byte input stream.
3988N/A
3988N/A SSrvMsg(SrvLocHeader hdr, DataInputStream dis)
3988N/A throws ServiceLocationException, IOException {
3988N/A super(hdr, SrvLocHeader.SrvReq);
3988N/A
3988N/A this.initialize(dis);
4222N/A
4802N/A }
3988N/A
3988N/A // Initialize the message from the input stream.
3988N/A
3988N/A void initialize(DataInputStream dis)
3988N/A throws ServiceLocationException, IOException {
3988N/A
3988N/A SLPServerHeaderV2 hdr = (SLPServerHeaderV2)getHeader();
3988N/A StringBuffer buf = new StringBuffer();
3988N/A
3988N/A // First get the previous responder.
3988N/A
3988N/A hdr.parsePreviousRespondersIn(dis);
3988N/A
3988N/A // Get the service type.
3988N/A
3988N/A hdr.getString(buf, dis);
3988N/A
3988N/A serviceType = buf.toString();
3988N/A
3988N/A if (serviceType.length() <= 0) {
3988N/A throw
3988N/A new ServiceLocationException(
3988N/A ServiceLocationException.PARSE_ERROR,
3988N/A "srq_stype_missing",
3988N/A new Object[0]);
3988N/A }
3988N/A
3988N/A ServiceType t = new ServiceType(serviceType);
3988N/A
4222N/A serviceType = t.toString();
4222N/A
4222N/A // Get vector of scopes.
3988N/A
3988N/A hdr.getString(buf, dis);
3988N/A
3988N/A hdr.scopes = hdr.parseCommaSeparatedListIn(buf.toString(), true);
3988N/A
3988N/A // Validate, but check for empty if solicitation for DAAdvert
3988N/A // or SAAdvert.
3988N/A
3988N/A if (hdr.scopes.size() <= 0) {
3988N/A if (!t.equals(Defaults.DA_SERVICE_TYPE) &&
3988N/A !t.equals(Defaults.SA_SERVICE_TYPE)) {
3988N/A throw
3988N/A new ServiceLocationException(
3988N/A ServiceLocationException.PARSE_ERROR,
3988N/A "no_scope_vector",
3988N/A new Object[0]);
3988N/A }
3988N/A } else {
3988N/A
3988N/A // Unescape scope strings.
3988N/A
3988N/A hdr.unescapeScopeStrings(hdr.scopes);
3988N/A
3988N/A DATable.validateScopes(hdr.scopes, hdr.locale);
3988N/A
3988N/A }
3988N/A
3988N/A // Get the query.
3988N/A
3988N/A hdr.getString(buf, dis);
3988N/A
3988N/A query = buf.toString();
3988N/A
3988N/A // Get the SPI
3988N/A
3988N/A hdr.getString(buf, dis);
3988N/A
3988N/A spi = buf.toString();
3988N/A
3988N/A hdr.constructDescription("SrvRqst",
3988N/A " service type=``" +
3988N/A serviceType + "''\n" +
3988N/A " query=``" +
3988N/A query + "''\n" +
3988N/A " spi=``" +
3988N/A spi + "''");
3988N/A }
3988N/A
3988N/A // Construct a SSrvMsg from the arguments. This will be a SrvRply
3988N/A // for transmission to the client.
3988N/A
3988N/A SrvLocMsg makeReply(Hashtable urls, Hashtable URLSignatures)
3988N/A throws ServiceLocationException {
3988N/A
3988N/A SLPServerHeaderV2 hdr =
3988N/A ((SLPServerHeaderV2)getHeader()).makeReplyHeader();
3988N/A
3988N/A hdr.iNumReplies = urls.size();
3988N/A // keep this info so SAs can drop 0 replies
3988N/A
3988N/A ByteArrayOutputStream baos = new ByteArrayOutputStream();
3988N/A
3988N/A int n = urls.size();
3988N/A
3988N/A String authDesc = "\n";
3988N/A
// Write out size.
hdr.putInt(n, baos);
Enumeration en = urls.keys();
int nurls = 0;
// Write out the members of the list, including the lifetime.
while (en.hasMoreElements()) {
ServiceURL surl = (ServiceURL)en.nextElement();
Hashtable auth = null;
if (URLSignatures != null) {
auth = (Hashtable)URLSignatures.get(surl);
AuthBlock selectedAuth =
AuthBlock.getEquivalentAuth(spi, auth);
auth = null;
if (selectedAuth != null) {
auth = new Hashtable();
auth.put(spi, selectedAuth);
}
authDesc =
authDesc + " " + surl.toString() + ": " +
(auth != null ?
selectedAuth.toString() :
"No Auth Block\n");
}
// Parse out a URL entry. Check overflow. If the packet has filled
// up, then break out of the loop.
if (hdr.parseServiceURLOut(surl,
(auth != null),
auth,
baos,
true) == false) {
// Note that we set overflow here because there are additional
// URL's, but we don't have to truncate the packet.
hdr.overflow = true;
// We need to rewrite the size to what it should be.
byte[] bytes = baos.toByteArray();
baos.reset();
SrvLocHeader.putInteger(nurls, baos);
baos.write(bytes, 2, bytes.length - 2);
break;
}
nurls++;
}
hdr.payload = baos.toByteArray();
// Construct description.
hdr.constructDescription("SrvRply",
" service URLs=``" + urls + "''\n" +
" auth block=" + authDesc + "\n");
return hdr;
}
}