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