1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * ident "%Z%%M% %I% %E% SMI" 24*7c478bd9Sstevel@tonic-gate * 25*7c478bd9Sstevel@tonic-gate * Copyright (c) 1999 by Sun Microsystems, Inc. 26*7c478bd9Sstevel@tonic-gate * All rights reserved. 27*7c478bd9Sstevel@tonic-gate * 28*7c478bd9Sstevel@tonic-gate */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate // SCCS Status: %W% %G% 31*7c478bd9Sstevel@tonic-gate // CAttrMsg.java: Message class for SLP attribute 32*7c478bd9Sstevel@tonic-gate // reply. 33*7c478bd9Sstevel@tonic-gate // Author: James Kempf Created On: Thu Oct 9 15:17:36 1997 34*7c478bd9Sstevel@tonic-gate // Last Modified By: James Kempf 35*7c478bd9Sstevel@tonic-gate // Last Modified On: Tue Oct 27 10:57:38 1998 36*7c478bd9Sstevel@tonic-gate // Update Count: 107 37*7c478bd9Sstevel@tonic-gate // 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate package com.sun.slp; 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate import java.util.*; 42*7c478bd9Sstevel@tonic-gate import java.io.*; 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate /** 46*7c478bd9Sstevel@tonic-gate * The CAttrMsg class models the SLP client side attribute message. 47*7c478bd9Sstevel@tonic-gate * 48*7c478bd9Sstevel@tonic-gate * @version %R%.%L% %D% 49*7c478bd9Sstevel@tonic-gate * @author James Kempf 50*7c478bd9Sstevel@tonic-gate */ 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate class CAttrMsg extends SrvLocMsgImpl { 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate // Vector of ServiceLocationAttribute objects 55*7c478bd9Sstevel@tonic-gate Vector attrList = new Vector(); 56*7c478bd9Sstevel@tonic-gate Hashtable attrAuthBlock = null; // auth block list for objects 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate // Only used for testing. 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate protected CAttrMsg() { } 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate // Construct a CAttrMsg from the byte input stream. 63*7c478bd9Sstevel@tonic-gate 64*7c478bd9Sstevel@tonic-gate CAttrMsg(SLPHeaderV2 hdr, DataInputStream dis) 65*7c478bd9Sstevel@tonic-gate throws ServiceLocationException, IOException { 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate super(hdr, SrvLocHeader.AttrRply); 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate // Don't parse the rest if there's an error. 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate if (hdr.errCode != ServiceLocationException.OK) { 72*7c478bd9Sstevel@tonic-gate return; 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate } 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate // Ignore if overflow. 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate if (hdr.overflow) { 79*7c478bd9Sstevel@tonic-gate return; 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate } 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate // Parse in the potentially authenticated attribute list. 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate attrAuthBlock = 86*7c478bd9Sstevel@tonic-gate hdr.parseAuthenticatedAttributeVectorIn(attrList, dis, true); 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate // Verify authentication, if necessary. 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate if (attrAuthBlock != null) { 91*7c478bd9Sstevel@tonic-gate AuthBlock.verifyAll(attrAuthBlock); 92*7c478bd9Sstevel@tonic-gate } 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate // Set the number of replies. 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate hdr.iNumReplies = attrList.size(); 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate } 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate // Construct a CAttrMsg payload from the arguments. This will be 101*7c478bd9Sstevel@tonic-gate // an AttrRqst message. 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate CAttrMsg(Locale locale, ServiceURL url, Vector scopes, Vector tags) 104*7c478bd9Sstevel@tonic-gate throws ServiceLocationException { 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate this.hdr = new SLPHeaderV2(SrvLocHeader.AttrRqst, false, locale); 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate constructPayload(url.toString(), scopes, tags); 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate } 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate // Construct a CAttrMsg payload from the arguments. This will be 113*7c478bd9Sstevel@tonic-gate // an AttrRqst message. 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate CAttrMsg(Locale locale, ServiceType type, Vector scopes, Vector tags) 116*7c478bd9Sstevel@tonic-gate throws ServiceLocationException { 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate this.hdr = new SLPHeaderV2(SrvLocHeader.AttrRqst, false, locale); 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate constructPayload(type.toString(), scopes, tags); 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate } 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate // Convert the message into bytes for the payload buffer. 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate protected void constructPayload(String typeOrURL, 127*7c478bd9Sstevel@tonic-gate Vector scopes, 128*7c478bd9Sstevel@tonic-gate Vector tags) 129*7c478bd9Sstevel@tonic-gate throws ServiceLocationException { 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate SLPHeaderV2 hdr = (SLPHeaderV2)this.hdr; 132*7c478bd9Sstevel@tonic-gate hdr.scopes = (Vector)scopes.clone(); 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate // Set up previous responders. 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate hdr.previousResponders = new Vector(); 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate ByteArrayOutputStream baos = new ByteArrayOutputStream(); 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate // Write out the service type or URL. 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate hdr.putString(typeOrURL, baos); 143*7c478bd9Sstevel@tonic-gate 144*7c478bd9Sstevel@tonic-gate // Escape scope strings for transmission. 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate hdr.escapeScopeStrings(scopes); 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate // Parse out the scopes. 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate hdr.parseCommaSeparatedListOut(scopes, baos); 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate // Escape tags going out. 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate hdr.escapeTags(tags); 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate // Parse out the tags 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate hdr.parseCommaSeparatedListOut(tags, baos); 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate // Retrieve the configured SPI, if any 161*7c478bd9Sstevel@tonic-gate String spi = ""; 162*7c478bd9Sstevel@tonic-gate if (SLPConfig.getSLPConfig().getHasSecurity()) { 163*7c478bd9Sstevel@tonic-gate LinkedList spiList = AuthBlock.getSPIList("sun.net.slp.SPIs"); 164*7c478bd9Sstevel@tonic-gate if (spiList != null && !spiList.isEmpty()) { 165*7c478bd9Sstevel@tonic-gate // There can be only one configured SPI for UAs 166*7c478bd9Sstevel@tonic-gate spi = (String) spiList.getFirst(); 167*7c478bd9Sstevel@tonic-gate } 168*7c478bd9Sstevel@tonic-gate } 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate hdr.putString(spi, baos); 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate // Set payload. 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate hdr.payload = baos.toByteArray(); 175*7c478bd9Sstevel@tonic-gate } 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate } 178