10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7298SMark.J.Nelson@Sun.COM * Common Development and Distribution License (the "License"). 6*7298SMark.J.Nelson@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 220Sstevel@tonic-gate * Copyright (c) 1999 by Sun Microsystems, Inc. 230Sstevel@tonic-gate * All rights reserved. 240Sstevel@tonic-gate * 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate // CAttrMsg.java: Message class for SLP attribute 280Sstevel@tonic-gate // reply. 290Sstevel@tonic-gate // Author: James Kempf Created On: Thu Oct 9 15:17:36 1997 300Sstevel@tonic-gate // Last Modified By: James Kempf 310Sstevel@tonic-gate // Last Modified On: Tue Oct 27 10:57:38 1998 320Sstevel@tonic-gate // Update Count: 107 330Sstevel@tonic-gate // 340Sstevel@tonic-gate 350Sstevel@tonic-gate package com.sun.slp; 360Sstevel@tonic-gate 370Sstevel@tonic-gate import java.util.*; 380Sstevel@tonic-gate import java.io.*; 390Sstevel@tonic-gate 400Sstevel@tonic-gate 410Sstevel@tonic-gate /** 420Sstevel@tonic-gate * The CAttrMsg class models the SLP client side attribute message. 430Sstevel@tonic-gate * 440Sstevel@tonic-gate * @author James Kempf 450Sstevel@tonic-gate */ 460Sstevel@tonic-gate 470Sstevel@tonic-gate class CAttrMsg extends SrvLocMsgImpl { 480Sstevel@tonic-gate 490Sstevel@tonic-gate // Vector of ServiceLocationAttribute objects 500Sstevel@tonic-gate Vector attrList = new Vector(); 510Sstevel@tonic-gate Hashtable attrAuthBlock = null; // auth block list for objects 520Sstevel@tonic-gate 530Sstevel@tonic-gate // Only used for testing. 540Sstevel@tonic-gate CAttrMsg()550Sstevel@tonic-gate protected CAttrMsg() { } 560Sstevel@tonic-gate 570Sstevel@tonic-gate // Construct a CAttrMsg from the byte input stream. 580Sstevel@tonic-gate CAttrMsg(SLPHeaderV2 hdr, DataInputStream dis)590Sstevel@tonic-gate CAttrMsg(SLPHeaderV2 hdr, DataInputStream dis) 600Sstevel@tonic-gate throws ServiceLocationException, IOException { 610Sstevel@tonic-gate 620Sstevel@tonic-gate super(hdr, SrvLocHeader.AttrRply); 630Sstevel@tonic-gate 640Sstevel@tonic-gate // Don't parse the rest if there's an error. 650Sstevel@tonic-gate 660Sstevel@tonic-gate if (hdr.errCode != ServiceLocationException.OK) { 670Sstevel@tonic-gate return; 680Sstevel@tonic-gate 690Sstevel@tonic-gate } 700Sstevel@tonic-gate 710Sstevel@tonic-gate // Ignore if overflow. 720Sstevel@tonic-gate 730Sstevel@tonic-gate if (hdr.overflow) { 740Sstevel@tonic-gate return; 750Sstevel@tonic-gate 760Sstevel@tonic-gate } 770Sstevel@tonic-gate 780Sstevel@tonic-gate // Parse in the potentially authenticated attribute list. 790Sstevel@tonic-gate 800Sstevel@tonic-gate attrAuthBlock = 810Sstevel@tonic-gate hdr.parseAuthenticatedAttributeVectorIn(attrList, dis, true); 820Sstevel@tonic-gate 830Sstevel@tonic-gate // Verify authentication, if necessary. 840Sstevel@tonic-gate 850Sstevel@tonic-gate if (attrAuthBlock != null) { 860Sstevel@tonic-gate AuthBlock.verifyAll(attrAuthBlock); 870Sstevel@tonic-gate } 880Sstevel@tonic-gate 890Sstevel@tonic-gate // Set the number of replies. 900Sstevel@tonic-gate 910Sstevel@tonic-gate hdr.iNumReplies = attrList.size(); 920Sstevel@tonic-gate 930Sstevel@tonic-gate } 940Sstevel@tonic-gate 950Sstevel@tonic-gate // Construct a CAttrMsg payload from the arguments. This will be 960Sstevel@tonic-gate // an AttrRqst message. 970Sstevel@tonic-gate CAttrMsg(Locale locale, ServiceURL url, Vector scopes, Vector tags)980Sstevel@tonic-gate CAttrMsg(Locale locale, ServiceURL url, Vector scopes, Vector tags) 990Sstevel@tonic-gate throws ServiceLocationException { 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate this.hdr = new SLPHeaderV2(SrvLocHeader.AttrRqst, false, locale); 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate constructPayload(url.toString(), scopes, tags); 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate } 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate // Construct a CAttrMsg payload from the arguments. This will be 1080Sstevel@tonic-gate // an AttrRqst message. 1090Sstevel@tonic-gate CAttrMsg(Locale locale, ServiceType type, Vector scopes, Vector tags)1100Sstevel@tonic-gate CAttrMsg(Locale locale, ServiceType type, Vector scopes, Vector tags) 1110Sstevel@tonic-gate throws ServiceLocationException { 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate this.hdr = new SLPHeaderV2(SrvLocHeader.AttrRqst, false, locale); 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate constructPayload(type.toString(), scopes, tags); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate } 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate // Convert the message into bytes for the payload buffer. 1200Sstevel@tonic-gate constructPayload(String typeOrURL, Vector scopes, Vector tags)1210Sstevel@tonic-gate protected void constructPayload(String typeOrURL, 1220Sstevel@tonic-gate Vector scopes, 1230Sstevel@tonic-gate Vector tags) 1240Sstevel@tonic-gate throws ServiceLocationException { 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate SLPHeaderV2 hdr = (SLPHeaderV2)this.hdr; 1270Sstevel@tonic-gate hdr.scopes = (Vector)scopes.clone(); 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate // Set up previous responders. 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate hdr.previousResponders = new Vector(); 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate ByteArrayOutputStream baos = new ByteArrayOutputStream(); 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate // Write out the service type or URL. 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate hdr.putString(typeOrURL, baos); 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate // Escape scope strings for transmission. 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate hdr.escapeScopeStrings(scopes); 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate // Parse out the scopes. 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate hdr.parseCommaSeparatedListOut(scopes, baos); 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate // Escape tags going out. 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate hdr.escapeTags(tags); 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate // Parse out the tags 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate hdr.parseCommaSeparatedListOut(tags, baos); 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate // Retrieve the configured SPI, if any 1560Sstevel@tonic-gate String spi = ""; 1570Sstevel@tonic-gate if (SLPConfig.getSLPConfig().getHasSecurity()) { 1580Sstevel@tonic-gate LinkedList spiList = AuthBlock.getSPIList("sun.net.slp.SPIs"); 1590Sstevel@tonic-gate if (spiList != null && !spiList.isEmpty()) { 1600Sstevel@tonic-gate // There can be only one configured SPI for UAs 1610Sstevel@tonic-gate spi = (String) spiList.getFirst(); 1620Sstevel@tonic-gate } 1630Sstevel@tonic-gate } 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate hdr.putString(spi, baos); 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate // Set payload. 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate hdr.payload = baos.toByteArray(); 1700Sstevel@tonic-gate } 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate } 173