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// SSrvTypeMsg.java: Message class for SLP service type request
2N/A// Author: James Kempf
2N/A// Created On: Thu Oct 9 14:29:22 1997
2N/A// Last Modified By: James Kempf
2N/A// Last Modified On: Tue Oct 27 10:57:38 1998
2N/A// Update Count: 101
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 SSrvTypeMsg class models the SLP service type request message.
2N/A *
2N/A * @author James Kempf
2N/A */
2N/A
2N/Aclass SSrvTypeMsg extends SrvLocMsgImpl {
2N/A
2N/A String namingAuthority = ""; // empty string is IANA
2N/A
2N/A // Construct a SSrvTypeMsg from the byte input stream. This will be
2N/A // a SrvTypeRqst.
2N/A
2N/A SSrvTypeMsg(SrvLocHeader hdr, DataInputStream dis)
2N/A throws ServiceLocationException, IOException {
2N/A
2N/A super(hdr, SrvLocHeader.SrvTypeRqst);
2N/A
2N/A this.initialize(dis);
2N/A
2N/A }
2N/A
2N/A // Initialize the message.
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 // Now get naming authority.
2N/A
2N/A namingAuthority = parseNamingAuthorityIn(hdr, dis, Defaults.UTF8);
2N/A
2N/A // Error if equals IANA.
2N/A
2N/A if (namingAuthority.equalsIgnoreCase(ServiceType.IANA)) {
2N/A throw
2N/A new ServiceLocationException(
2N/A ServiceLocationException.PARSE_ERROR,
2N/A "sstm_iana",
2N/A new Object[0]);
2N/A
2N/A }
2N/A
2N/A // Finally get scopes.
2N/A
2N/A hdr.parseScopesIn(dis);
2N/A
2N/A // Construct description.
2N/A
2N/A hdr.constructDescription("SrvTypeRqst",
2N/A " naming authority=``" +
2N/A namingAuthority + "''\n");
2N/A }
2N/A
2N/A // Parse a naming authority name and verify.
2N/A
2N/A protected String
2N/A parseNamingAuthorityIn(SrvLocHeader hdr,
2N/A DataInputStream dis,
2N/A String charCode)
2N/A throws ServiceLocationException, IOException {
2N/A
2N/A int len = 0;
2N/A
2N/A len = hdr.getInt(dis);
2N/A
2N/A // Handle the special cases of no naming authority or
2N/A // all authorities.
2N/A
2N/A if (len == 0) {
2N/A return "";
2N/A
2N/A } else if (len == 0xFFFF) {
2N/A return Defaults.ALL_AUTHORITIES;
2N/A
2N/A }
2N/A
2N/A byte bStr[] = new byte[len];
2N/A
2N/A dis.readFully(bStr, 0, len);
2N/A hdr.nbytes += len;
2N/A
2N/A // Convert to string.
2N/A
2N/A String name = hdr.getBytesString(bStr, charCode).toLowerCase();
2N/A
2N/A // Validate.
2N/A
2N/A ServiceType.validateTypeComponent(name);
2N/A
2N/A return name;
2N/A }
2N/A
2N/A // Construct a SSrvTypeMsg from the arguments. This will be a
2N/A // SrvTypeRply for transmission to client.
2N/A
2N/A SrvLocMsg makeReply(Vector typeNames)
2N/A throws ServiceLocationException {
2N/A
2N/A SLPServerHeaderV2 hdr =
2N/A ((SLPServerHeaderV2)getHeader()).makeReplyHeader();
2N/A
2N/A hdr.iNumReplies = typeNames.size();
2N/A
2N/A // Construct payload.
2N/A
2N/A ByteArrayOutputStream baos = new ByteArrayOutputStream();
2N/A
2N/A hdr.parseCommaSeparatedListOut(typeNames, baos);
2N/A
2N/A hdr.payload = baos.toByteArray();
2N/A
2N/A // Construct description.
2N/A
2N/A hdr.constructDescription("SrvTypeRply",
2N/A " types=``" + typeNames + "''\n");
2N/A
2N/A return hdr;
2N/A }
2N/A}