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 // SSrvMsg.java: Message class for SLP service request. 280Sstevel@tonic-gate // Author: James Kempf 290Sstevel@tonic-gate // Created On: Thu Oct 9 13:40:16 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: 112 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 SSrvMsg class models the SLP service (request, reply) message 430Sstevel@tonic-gate * server side. Subclasses for other versions can specialize the 440Sstevel@tonic-gate * initialize() and makeReply() methods. 450Sstevel@tonic-gate * 460Sstevel@tonic-gate * @author James Kempf 470Sstevel@tonic-gate */ 480Sstevel@tonic-gate 490Sstevel@tonic-gate class SSrvMsg extends SrvLocMsgImpl { 500Sstevel@tonic-gate 510Sstevel@tonic-gate String serviceType = ""; // service type and naming authority 520Sstevel@tonic-gate String query = ""; // the query 530Sstevel@tonic-gate String spi = ""; 540Sstevel@tonic-gate SSrvMsg()550Sstevel@tonic-gate protected SSrvMsg() {} 560Sstevel@tonic-gate 570Sstevel@tonic-gate // Construct a SSrvMsg from the byte input stream. 580Sstevel@tonic-gate SSrvMsg(SrvLocHeader hdr, DataInputStream dis)590Sstevel@tonic-gate SSrvMsg(SrvLocHeader hdr, DataInputStream dis) 600Sstevel@tonic-gate throws ServiceLocationException, IOException { 610Sstevel@tonic-gate super(hdr, SrvLocHeader.SrvReq); 620Sstevel@tonic-gate 630Sstevel@tonic-gate this.initialize(dis); 640Sstevel@tonic-gate 650Sstevel@tonic-gate } 660Sstevel@tonic-gate 670Sstevel@tonic-gate // Initialize the message from the input stream. 680Sstevel@tonic-gate initialize(DataInputStream dis)690Sstevel@tonic-gate void initialize(DataInputStream dis) 700Sstevel@tonic-gate throws ServiceLocationException, IOException { 710Sstevel@tonic-gate 720Sstevel@tonic-gate SLPServerHeaderV2 hdr = (SLPServerHeaderV2)getHeader(); 730Sstevel@tonic-gate StringBuffer buf = new StringBuffer(); 740Sstevel@tonic-gate 750Sstevel@tonic-gate // First get the previous responder. 760Sstevel@tonic-gate 770Sstevel@tonic-gate hdr.parsePreviousRespondersIn(dis); 780Sstevel@tonic-gate 790Sstevel@tonic-gate // Get the service type. 800Sstevel@tonic-gate 810Sstevel@tonic-gate hdr.getString(buf, dis); 820Sstevel@tonic-gate 830Sstevel@tonic-gate serviceType = buf.toString(); 840Sstevel@tonic-gate 850Sstevel@tonic-gate if (serviceType.length() <= 0) { 860Sstevel@tonic-gate throw 870Sstevel@tonic-gate new ServiceLocationException( 880Sstevel@tonic-gate ServiceLocationException.PARSE_ERROR, 890Sstevel@tonic-gate "srq_stype_missing", 900Sstevel@tonic-gate new Object[0]); 910Sstevel@tonic-gate } 920Sstevel@tonic-gate 930Sstevel@tonic-gate ServiceType t = new ServiceType(serviceType); 940Sstevel@tonic-gate 950Sstevel@tonic-gate serviceType = t.toString(); 960Sstevel@tonic-gate 970Sstevel@tonic-gate // Get vector of scopes. 980Sstevel@tonic-gate 990Sstevel@tonic-gate hdr.getString(buf, dis); 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate hdr.scopes = hdr.parseCommaSeparatedListIn(buf.toString(), true); 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate // Validate, but check for empty if solicitation for DAAdvert 1040Sstevel@tonic-gate // or SAAdvert. 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate if (hdr.scopes.size() <= 0) { 1070Sstevel@tonic-gate if (!t.equals(Defaults.DA_SERVICE_TYPE) && 1080Sstevel@tonic-gate !t.equals(Defaults.SA_SERVICE_TYPE)) { 1090Sstevel@tonic-gate throw 1100Sstevel@tonic-gate new ServiceLocationException( 1110Sstevel@tonic-gate ServiceLocationException.PARSE_ERROR, 1120Sstevel@tonic-gate "no_scope_vector", 1130Sstevel@tonic-gate new Object[0]); 1140Sstevel@tonic-gate } 1150Sstevel@tonic-gate } else { 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate // Unescape scope strings. 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate hdr.unescapeScopeStrings(hdr.scopes); 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate DATable.validateScopes(hdr.scopes, hdr.locale); 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate } 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate // Get the query. 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate hdr.getString(buf, dis); 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate query = buf.toString(); 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate // Get the SPI 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate hdr.getString(buf, dis); 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate spi = buf.toString(); 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate hdr.constructDescription("SrvRqst", 1380Sstevel@tonic-gate " service type=``" + 1390Sstevel@tonic-gate serviceType + "''\n" + 1400Sstevel@tonic-gate " query=``" + 1410Sstevel@tonic-gate query + "''\n" + 1420Sstevel@tonic-gate " spi=``" + 1430Sstevel@tonic-gate spi + "''"); 1440Sstevel@tonic-gate } 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate // Construct a SSrvMsg from the arguments. This will be a SrvRply 1470Sstevel@tonic-gate // for transmission to the client. 1480Sstevel@tonic-gate makeReply(Hashtable urls, Hashtable URLSignatures)1490Sstevel@tonic-gate SrvLocMsg makeReply(Hashtable urls, Hashtable URLSignatures) 1500Sstevel@tonic-gate throws ServiceLocationException { 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate SLPServerHeaderV2 hdr = 1530Sstevel@tonic-gate ((SLPServerHeaderV2)getHeader()).makeReplyHeader(); 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate hdr.iNumReplies = urls.size(); 1560Sstevel@tonic-gate // keep this info so SAs can drop 0 replies 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate ByteArrayOutputStream baos = new ByteArrayOutputStream(); 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate int n = urls.size(); 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate String authDesc = "\n"; 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate // Write out size. 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate hdr.putInt(n, baos); 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate Enumeration en = urls.keys(); 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate int nurls = 0; 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate // Write out the members of the list, including the lifetime. 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate while (en.hasMoreElements()) { 1750Sstevel@tonic-gate ServiceURL surl = (ServiceURL)en.nextElement(); 1760Sstevel@tonic-gate Hashtable auth = null; 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate if (URLSignatures != null) { 1790Sstevel@tonic-gate auth = (Hashtable)URLSignatures.get(surl); 1800Sstevel@tonic-gate AuthBlock selectedAuth = 1810Sstevel@tonic-gate AuthBlock.getEquivalentAuth(spi, auth); 1820Sstevel@tonic-gate auth = null; 1830Sstevel@tonic-gate if (selectedAuth != null) { 1840Sstevel@tonic-gate auth = new Hashtable(); 1850Sstevel@tonic-gate auth.put(spi, selectedAuth); 1860Sstevel@tonic-gate } 1870Sstevel@tonic-gate authDesc = 1880Sstevel@tonic-gate authDesc + " " + surl.toString() + ": " + 1890Sstevel@tonic-gate (auth != null ? 1900Sstevel@tonic-gate selectedAuth.toString() : 1910Sstevel@tonic-gate "No Auth Block\n"); 1920Sstevel@tonic-gate } 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate // Parse out a URL entry. Check overflow. If the packet has filled 1950Sstevel@tonic-gate // up, then break out of the loop. 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate if (hdr.parseServiceURLOut(surl, 1980Sstevel@tonic-gate (auth != null), 1990Sstevel@tonic-gate auth, 2000Sstevel@tonic-gate baos, 2010Sstevel@tonic-gate true) == false) { 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate // Note that we set overflow here because there are additional 2040Sstevel@tonic-gate // URL's, but we don't have to truncate the packet. 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate hdr.overflow = true; 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate // We need to rewrite the size to what it should be. 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate byte[] bytes = baos.toByteArray(); 2110Sstevel@tonic-gate baos.reset(); 2120Sstevel@tonic-gate SrvLocHeader.putInteger(nurls, baos); 2130Sstevel@tonic-gate baos.write(bytes, 2, bytes.length - 2); 2140Sstevel@tonic-gate break; 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate } 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate nurls++; 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate } 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate hdr.payload = baos.toByteArray(); 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate // Construct description. 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate hdr.constructDescription("SrvRply", 2270Sstevel@tonic-gate " service URLs=``" + urls + "''\n" + 2280Sstevel@tonic-gate " auth block=" + authDesc + "\n"); 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate return hdr; 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate } 2330Sstevel@tonic-gate } 234