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// SAttrMsg.java: Message class for SLP attribute request.
2N/A// Author: James Kempf
2N/A// Created On: Thu Oct 9 14:24:55 1997
2N/A// Last Modified By: James Kempf
2N/A// Last Modified On: Tue Oct 27 10:57:41 1998
2N/A// Update Count: 131
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 SAttrMsg class models the SLP server side attribute message.
2N/A * 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 SAttrMsg extends SrvLocMsgImpl {
2N/A
2N/A ServiceURL URL = null; // nonNull if a URL query.
2N/A String serviceType = null; // nonNull if a service type query.
2N/A Vector tags = new Vector(); // Vector of String tags.
2N/A String spi = ""; // requested SPI
2N/A
2N/A protected SAttrMsg() {}
2N/A
2N/A // Construct a SAttrMsg from the input stream. This will
2N/A // be an SLP attribute request.
2N/A
2N/A SAttrMsg(SrvLocHeader hdr, DataInputStream dis)
2N/A throws ServiceLocationException, IOException {
2N/A
2N/A super(hdr, SrvLocHeader.AttrRqst);
2N/A
2N/A this.initialize(dis);
2N/A
2N/A }
2N/A
2N/A // Initialize the message object.
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 // Parse in the previous responder's list.
2N/A
2N/A hdr.parsePreviousRespondersIn(dis);
2N/A
2N/A // Parse in the URL or service type.
2N/A
2N/A hdr.getString(buf, dis);
2N/A
2N/A String urlOrServiceType = buf.toString();
2N/A
2N/A // Decide whether this is a service type or service URL
2N/A
2N/A try {
2N/A URL = new ServiceURL(urlOrServiceType, ServiceURL.LIFETIME_NONE);
2N/A
2N/A serviceType = null;
2N/A
2N/A } catch (IllegalArgumentException ex) {
2N/A
2N/A // Validate and remove IANA.
2N/A
2N/A ServiceType t = new ServiceType(urlOrServiceType);
2N/A
2N/A serviceType = t.toString();
2N/A
2N/A URL = null;
2N/A }
2N/A
2N/A // Parse in the scopes.
2N/A
2N/A hdr.parseScopesIn(dis);
2N/A
2N/A // Parse in the attribute tags.
2N/A
2N/A hdr.getString(buf, dis);
2N/A
2N/A tags = hdr.parseCommaSeparatedListIn(buf.toString(), true);
2N/A
2N/A // Unescape tags.
2N/A
2N/A hdr.unescapeTags(tags);
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 // Construct the description.
2N/A
2N/A hdr.constructDescription("AttrRqst",
2N/A " " +
2N/A (URL != null ?
2N/A ("URL=``" + URL):
2N/A ("service type=``" + serviceType)) +
2N/A "''\n" +
2N/A " tags=``" + tags + "''\n" +
2N/A " spi=``" + spi + "''\n");
2N/A }
2N/A
2N/A // Construct an SAttrMsg payload for reply to client. This will
2N/A // be an AttrRply message.
2N/A
2N/A SrvLocMsg makeReply(Vector attrs, Hashtable auth)
2N/A throws ServiceLocationException {
2N/A
2N/A SLPServerHeaderV2 hdr =
2N/A ((SLPServerHeaderV2)getHeader()).makeReplyHeader();
2N/A
2N/A hdr.iNumReplies = attrs.size();
2N/A
2N/A // Select AuthBlock with requested SPI
2N/A if (auth != null) {
2N/A AuthBlock selectedAuth = 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 }
2N/A
2N/A ByteArrayOutputStream baos = new ByteArrayOutputStream();
2N/A
2N/A hdr.parseAttributeVectorOut(attrs, 0, (auth != null),
2N/A auth, baos, true);
2N/A
2N/A hdr.payload = baos.toByteArray();
2N/A
2N/A // Construct description.
2N/A
2N/A hdr.constructDescription("AttrRply",
2N/A " attributes=``" +
2N/A attrs +
2N/A "''\n" +
2N/A " auth block=" +
2N/A AuthBlock.desc(auth) +
2N/A "\n");
2N/A
2N/A return hdr;
2N/A
2N/A }
2N/A
2N/A}