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 // CSAAdvert.java: Message class for SLP CSAAdvert message 280Sstevel@tonic-gate // Author: James Kempf 290Sstevel@tonic-gate // Created On: Fri Oct 10 10:48:05 1997 300Sstevel@tonic-gate // Last Modified By: James Kempf 310Sstevel@tonic-gate // Last Modified On: Tue Oct 27 10:57:41 1998 320Sstevel@tonic-gate // Update Count: 95 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 CSAAdvert class models the SLP SAAdvert message, client side. 430Sstevel@tonic-gate * 440Sstevel@tonic-gate * @author James Kempf 450Sstevel@tonic-gate */ 460Sstevel@tonic-gate 470Sstevel@tonic-gate 480Sstevel@tonic-gate class CSAAdvert extends SrvLocMsgImpl { 490Sstevel@tonic-gate 500Sstevel@tonic-gate ServiceURL URL = null; // The DA's service URL 510Sstevel@tonic-gate Hashtable authBlock = null; // Scope auth blocks. 520Sstevel@tonic-gate Vector attrs = new Vector(); // The attributes. 530Sstevel@tonic-gate 540Sstevel@tonic-gate // Construct a CSAAdvert from the input stream. 550Sstevel@tonic-gate CSAAdvert(SLPHeaderV2 hdr, DataInputStream dis)560Sstevel@tonic-gate CSAAdvert(SLPHeaderV2 hdr, DataInputStream dis) 570Sstevel@tonic-gate throws ServiceLocationException, IOException { 580Sstevel@tonic-gate super(hdr, SrvLocHeader.SAAdvert); 590Sstevel@tonic-gate 600Sstevel@tonic-gate // Parse in SA's service URL. 610Sstevel@tonic-gate 620Sstevel@tonic-gate StringBuffer buf = new StringBuffer(); 630Sstevel@tonic-gate 640Sstevel@tonic-gate byte[] urlBytes = hdr.getString(buf, dis); 650Sstevel@tonic-gate 660Sstevel@tonic-gate try { 670Sstevel@tonic-gate 680Sstevel@tonic-gate URL = new ServiceURL(buf.toString(), ServiceURL.LIFETIME_NONE); 690Sstevel@tonic-gate 700Sstevel@tonic-gate } catch (IllegalArgumentException ex) { 710Sstevel@tonic-gate 720Sstevel@tonic-gate throw 730Sstevel@tonic-gate new ServiceLocationException( 740Sstevel@tonic-gate ServiceLocationException.PARSE_ERROR, 750Sstevel@tonic-gate "malformed_url", 760Sstevel@tonic-gate new Object[] {ex.getMessage()}); 770Sstevel@tonic-gate 780Sstevel@tonic-gate } 790Sstevel@tonic-gate 800Sstevel@tonic-gate // Validate the service URL. 810Sstevel@tonic-gate 820Sstevel@tonic-gate ServiceType serviceType = URL.getServiceType(); 830Sstevel@tonic-gate 840Sstevel@tonic-gate if (!serviceType.equals(Defaults.SA_SERVICE_TYPE)) { 850Sstevel@tonic-gate throw 860Sstevel@tonic-gate new ServiceLocationException( 870Sstevel@tonic-gate ServiceLocationException.PARSE_ERROR, 880Sstevel@tonic-gate "not_right_url", 890Sstevel@tonic-gate new Object[] {URL, "SA"}); 900Sstevel@tonic-gate 910Sstevel@tonic-gate } 920Sstevel@tonic-gate 930Sstevel@tonic-gate // Parse in the scope list. 940Sstevel@tonic-gate 950Sstevel@tonic-gate byte[] scopeBytes = hdr.getString(buf, dis); 960Sstevel@tonic-gate 970Sstevel@tonic-gate hdr.scopes = 980Sstevel@tonic-gate hdr.parseCommaSeparatedListIn(buf.toString(), true); 990Sstevel@tonic-gate 1000Sstevel@tonic-gate // Unescape scopes. 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate hdr.unescapeScopeStrings(hdr.scopes); 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate // Validate scope list. 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate DATable.validateScopes(hdr.scopes, hdr.locale); 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate // Parse in attributes. 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate byte attrBytes[] = hdr.parseAttributeVectorIn(attrs, dis, false); 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate // Construct bytes for auth. 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate Object[] message = new Object[6]; 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate // None of the strings have leading length fields, so add them here 1170Sstevel@tonic-gate ByteArrayOutputStream abaos = new ByteArrayOutputStream(); 1180Sstevel@tonic-gate hdr.putInteger(urlBytes.length, abaos); 1190Sstevel@tonic-gate message[0] = abaos.toByteArray(); 1200Sstevel@tonic-gate message[1] = urlBytes; 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate abaos = new ByteArrayOutputStream(); 1230Sstevel@tonic-gate hdr.putInteger(attrBytes.length, abaos); 1240Sstevel@tonic-gate message[2] = abaos.toByteArray(); 1250Sstevel@tonic-gate message[3] = attrBytes; 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate abaos = new ByteArrayOutputStream(); 1280Sstevel@tonic-gate hdr.putInteger(scopeBytes.length, abaos); 1290Sstevel@tonic-gate message[4] = abaos.toByteArray(); 1300Sstevel@tonic-gate message[5] = scopeBytes; 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate // Parse in an auth block if there. 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate authBlock = hdr.parseSignatureIn(message, dis); 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate // Set number of replies. 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate hdr.iNumReplies = 1; 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate } 1410Sstevel@tonic-gate } 142