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) 2001 by Sun Microsystems, Inc. 230Sstevel@tonic-gate * All rights reserved. 240Sstevel@tonic-gate * 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate // SSAAdvert.java: Server Side SAAdvert Message. 280Sstevel@tonic-gate // Author: James Kempf 290Sstevel@tonic-gate // Created On: Tue Feb 10 15:00:39 1998 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: 60 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 SSAAdvert class models the SLP SAAdvert message. 430Sstevel@tonic-gate * 440Sstevel@tonic-gate * @author James Kempf 450Sstevel@tonic-gate */ 460Sstevel@tonic-gate 470Sstevel@tonic-gate class SSAAdvert extends SrvLocMsgImpl { 480Sstevel@tonic-gate 490Sstevel@tonic-gate // Construct a SAAdvert from the arguments. This is a server side 500Sstevel@tonic-gate // for transmission to the client. 510Sstevel@tonic-gate SSAAdvert(int version, short xid, Locale locale, ServiceURL url, Vector scopes, Vector attrs)520Sstevel@tonic-gate SSAAdvert(int version, 530Sstevel@tonic-gate short xid, 540Sstevel@tonic-gate Locale locale, 550Sstevel@tonic-gate ServiceURL url, 560Sstevel@tonic-gate Vector scopes, 570Sstevel@tonic-gate Vector attrs) 580Sstevel@tonic-gate throws ServiceLocationException { 590Sstevel@tonic-gate 600Sstevel@tonic-gate // Construct header. 610Sstevel@tonic-gate 620Sstevel@tonic-gate hdr = new SLPServerHeaderV2(); 630Sstevel@tonic-gate 640Sstevel@tonic-gate Assert.slpassert(hdr != null, 650Sstevel@tonic-gate "version_number_error", 660Sstevel@tonic-gate new Object[] {new Integer(version)}); 670Sstevel@tonic-gate 680Sstevel@tonic-gate hdr.functionCode = SrvLocHeader.SAAdvert; 690Sstevel@tonic-gate hdr.xid = xid; 700Sstevel@tonic-gate hdr.locale = locale; 710Sstevel@tonic-gate 720Sstevel@tonic-gate this.initialize(url, scopes, attrs); 730Sstevel@tonic-gate } 740Sstevel@tonic-gate 750Sstevel@tonic-gate // Initialize the message. 760Sstevel@tonic-gate initialize(ServiceURL url, Vector scopes, Vector attrs)770Sstevel@tonic-gate void initialize(ServiceURL url, Vector scopes, Vector attrs) 780Sstevel@tonic-gate throws ServiceLocationException { 790Sstevel@tonic-gate 800Sstevel@tonic-gate SLPServerHeaderV2 hdr = (SLPServerHeaderV2)getHeader(); 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 "ssaadv_nonsaurl", 890Sstevel@tonic-gate new Object[] {serviceType}); 900Sstevel@tonic-gate 910Sstevel@tonic-gate } 920Sstevel@tonic-gate 930Sstevel@tonic-gate // Validate scope list. 940Sstevel@tonic-gate 950Sstevel@tonic-gate DATable.validateScopes(scopes, hdr.locale); 960Sstevel@tonic-gate hdr.scopes = (Vector)scopes.clone(); 970Sstevel@tonic-gate 980Sstevel@tonic-gate // Escape scope strings. 990Sstevel@tonic-gate 1000Sstevel@tonic-gate hdr.escapeScopeStrings(scopes); 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate // Parse out the payload. 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate ByteArrayOutputStream baos = new ByteArrayOutputStream(); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate String surl = url.toString(); 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate // Parse out the URL. 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate byte[] urlBytes = hdr.putString(surl, baos); 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate // Parse out the scope list. We need to save the bytes for 1130Sstevel@tonic-gate // the authblock. 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate byte[] scopeBytes = 1160Sstevel@tonic-gate hdr.parseCommaSeparatedListOut(scopes, baos); 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate // Parse out the attribute list. 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate byte[] attrBytes = hdr.parseAttributeVectorOut(attrs, 1210Sstevel@tonic-gate url.getLifetime(), 1220Sstevel@tonic-gate false, 1230Sstevel@tonic-gate null, 1240Sstevel@tonic-gate baos, 1250Sstevel@tonic-gate false); 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate // Parse out auth blocks, if necessary. 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate Hashtable auth = null; 1300Sstevel@tonic-gate byte nBlocks = 0; 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate if (SLPConfig.getSLPConfig().getHasSecurity()) { 1330Sstevel@tonic-gate Object[] message = new Object[6]; 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate // None of the strings have leading length fields, so add them here 1360Sstevel@tonic-gate ByteArrayOutputStream abaos = new ByteArrayOutputStream(); 1370Sstevel@tonic-gate hdr.putInteger(urlBytes.length, abaos); 1380Sstevel@tonic-gate message[0] = abaos.toByteArray(); 1390Sstevel@tonic-gate message[1] = urlBytes; 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate abaos = new ByteArrayOutputStream(); 1420Sstevel@tonic-gate hdr.putInteger(attrBytes.length, abaos); 1430Sstevel@tonic-gate message[2] = abaos.toByteArray(); 1440Sstevel@tonic-gate message[3] = attrBytes; 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate abaos = new ByteArrayOutputStream(); 1470Sstevel@tonic-gate hdr.putInteger(scopeBytes.length, abaos); 1480Sstevel@tonic-gate message[4] = abaos.toByteArray(); 1490Sstevel@tonic-gate message[5] = scopeBytes; 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate auth = hdr.getCheckedAuthBlockList(message, 1520Sstevel@tonic-gate url.getLifetime()); 1530Sstevel@tonic-gate nBlocks = (byte) auth.size(); 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate } 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate // Parse out number of blocks. 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate baos.write(nBlocks); 1600Sstevel@tonic-gate hdr.nbytes++; 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate // Parse out blocks, if any. 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate if (auth != null) { 1650Sstevel@tonic-gate AuthBlock.externalizeAll(hdr, auth, baos); 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate } 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate // Save bytes. 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate hdr.payload = baos.toByteArray(); 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate // Construct description of outgoing packet for logging. 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate hdr.constructDescription("SAAdvert", 1760Sstevel@tonic-gate " URL=``" + url + "''\n" + 1770Sstevel@tonic-gate " attrs=``" + attrs + "''\n" + 1780Sstevel@tonic-gate " auth block="+AuthBlock.desc(auth) + 1790Sstevel@tonic-gate "\n"); 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate } 1820Sstevel@tonic-gate } 183