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 // SLPV1SAttrMsg.java: SLPv1 Attribute request for server. 280Sstevel@tonic-gate // Author: James Kempf 290Sstevel@tonic-gate // Created On: Fri Sep 11 13:23:28 1998 300Sstevel@tonic-gate // Last Modified By: James Kempf 310Sstevel@tonic-gate // Last Modified On: Tue Oct 27 10:57:39 1998 320Sstevel@tonic-gate // Update Count: 19 330Sstevel@tonic-gate // 340Sstevel@tonic-gate 350Sstevel@tonic-gate 360Sstevel@tonic-gate 370Sstevel@tonic-gate package com.sun.slp; 380Sstevel@tonic-gate 390Sstevel@tonic-gate import java.util.*; 400Sstevel@tonic-gate import java.io.*; 410Sstevel@tonic-gate 420Sstevel@tonic-gate 430Sstevel@tonic-gate /** 440Sstevel@tonic-gate * The SLPV1SAttrMsg class models the SLP server side attribute message. 450Sstevel@tonic-gate * 460Sstevel@tonic-gate * @author James Kempf 470Sstevel@tonic-gate */ 480Sstevel@tonic-gate 490Sstevel@tonic-gate class SLPV1SAttrMsg extends SAttrMsg { 500Sstevel@tonic-gate 510Sstevel@tonic-gate // For creating null reply. 520Sstevel@tonic-gate SLPV1SAttrMsg()530Sstevel@tonic-gate SLPV1SAttrMsg() {} 540Sstevel@tonic-gate 550Sstevel@tonic-gate // Construct a SLPV1SAttrMsg from the byte input stream. This will 560Sstevel@tonic-gate SLPV1SAttrMsg(SrvLocHeader hdr, DataInputStream dis)570Sstevel@tonic-gate SLPV1SAttrMsg(SrvLocHeader hdr, DataInputStream dis) 580Sstevel@tonic-gate throws ServiceLocationException, IOException { 590Sstevel@tonic-gate 600Sstevel@tonic-gate super(hdr, dis); 610Sstevel@tonic-gate 620Sstevel@tonic-gate } 630Sstevel@tonic-gate 640Sstevel@tonic-gate // Construct an empty SLPV1SSrvMsg, for monolingual off. 650Sstevel@tonic-gate makeEmptyReply(SLPHeaderV1 hdr)660Sstevel@tonic-gate static SrvLocMsg makeEmptyReply(SLPHeaderV1 hdr) 670Sstevel@tonic-gate throws ServiceLocationException { 680Sstevel@tonic-gate 690Sstevel@tonic-gate SLPV1SAttrMsg msg = new SLPV1SAttrMsg(); 700Sstevel@tonic-gate msg.hdr = hdr; 710Sstevel@tonic-gate 720Sstevel@tonic-gate msg.makeReply(new Vector(), null); 730Sstevel@tonic-gate 740Sstevel@tonic-gate return msg; 750Sstevel@tonic-gate 760Sstevel@tonic-gate } 770Sstevel@tonic-gate initialize(DataInputStream dis)780Sstevel@tonic-gate void initialize(DataInputStream dis) 790Sstevel@tonic-gate throws ServiceLocationException, IOException { 800Sstevel@tonic-gate 810Sstevel@tonic-gate SLPHeaderV1 hdr = (SLPHeaderV1)getHeader(); 820Sstevel@tonic-gate StringBuffer buf = new StringBuffer(); 830Sstevel@tonic-gate 840Sstevel@tonic-gate // Parse in the previous responder's list. 850Sstevel@tonic-gate 860Sstevel@tonic-gate hdr.parsePreviousRespondersIn(dis); 870Sstevel@tonic-gate 880Sstevel@tonic-gate // Parse in the URL or service type. 890Sstevel@tonic-gate 900Sstevel@tonic-gate hdr.getString(buf, dis); 910Sstevel@tonic-gate 920Sstevel@tonic-gate String urlOrServiceType = buf.toString().trim(); 930Sstevel@tonic-gate 940Sstevel@tonic-gate // Decide whether this is a service type or service URL 950Sstevel@tonic-gate 960Sstevel@tonic-gate try { 970Sstevel@tonic-gate 980Sstevel@tonic-gate URL = new ServiceURLV1(urlOrServiceType, 990Sstevel@tonic-gate ServiceURL.LIFETIME_DEFAULT); 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate serviceType = null; 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate } catch (IllegalArgumentException ex) { 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate // Check to make sure service type is right. 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate serviceType = 1080Sstevel@tonic-gate hdr.checkServiceType(urlOrServiceType.toLowerCase()); 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate URL = null; 1110Sstevel@tonic-gate } 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate // Parse in the scope and validate it. 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate hdr.getString(buf, dis); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate String scope = buf.toString().toLowerCase().trim(); 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate hdr.validateScope(scope); 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate // Change unscoped to default. 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate if (scope.length() <= 0) { 1240Sstevel@tonic-gate scope = Defaults.DEFAULT_SCOPE; 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate } 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate hdr.scopes = new Vector(); 1290Sstevel@tonic-gate hdr.scopes.addElement(scope); 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate // Parse in the attribute tags. 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate hdr.getString(buf, dis); 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate tags = 1360Sstevel@tonic-gate hdr.parseCommaSeparatedListIn(buf.toString().trim(), true); 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate // Unescape tags. 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate int i, n = tags.size(); 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate for (i = 0; i < n; i++) { 1430Sstevel@tonic-gate String tag = (String)tags.elementAt(i); 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate // Check for starting and ending wildcards. 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate boolean wildcardStart = false; 1480Sstevel@tonic-gate boolean wildcardEnd = false; 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate if (tag.startsWith("*")) { 1510Sstevel@tonic-gate wildcardStart = true; 1520Sstevel@tonic-gate tag = tag.substring(1, tag.length()); 1530Sstevel@tonic-gate } 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate if (tag.endsWith("*")) { 1560Sstevel@tonic-gate wildcardEnd = true; 1570Sstevel@tonic-gate tag = tag.substring(0, tag.length()-1); 1580Sstevel@tonic-gate } 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate tag = 1610Sstevel@tonic-gate ServiceLocationAttributeV1.unescapeAttributeString(tag, 1620Sstevel@tonic-gate hdr.charCode); 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate if (wildcardStart) { 1650Sstevel@tonic-gate tag = "*" + tag; 1660Sstevel@tonic-gate } 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate if (wildcardEnd) { 1690Sstevel@tonic-gate tag = tag + "*"; 1700Sstevel@tonic-gate } 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate tags.setElementAt(tag.trim(), i); 1730Sstevel@tonic-gate } 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate hdr.constructDescription("AttrRqst", 1760Sstevel@tonic-gate " " + 1770Sstevel@tonic-gate (URL != null ? ("URL=``" + URL): 1780Sstevel@tonic-gate ("service type=``" + serviceType)) + 1790Sstevel@tonic-gate "''\n" + 1800Sstevel@tonic-gate " tags=``" + tags + "''"); 1810Sstevel@tonic-gate } 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate // Construct an SAttrMsg payload for reply to client. 1840Sstevel@tonic-gate makeReply(Vector attrs, Hashtable auth)1850Sstevel@tonic-gate SrvLocMsg makeReply(Vector attrs, Hashtable auth) 1860Sstevel@tonic-gate throws ServiceLocationException { 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate SLPHeaderV1 hdr = ((SLPHeaderV1)getHeader()).makeReplyHeader(); 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate // We need to check whether this is an AttrRqst by type and 1910Sstevel@tonic-gate // if the type was an abstract type. If so, we simply return 1920Sstevel@tonic-gate // an empty reply, but we print a message to the log so the problem 1930Sstevel@tonic-gate // can be fixed. 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate if (serviceType != null) { 1960Sstevel@tonic-gate ServiceType type = new ServiceType(serviceType); 1970Sstevel@tonic-gate ServiceStore store = ServiceTable.getServiceTable().store; 1980Sstevel@tonic-gate Vector types = store.findServiceTypes(type.getNamingAuthority(), 1990Sstevel@tonic-gate this.hdr.scopes); 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate int i, n = types.size(); 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate for (i = 0; i < n; i++) { 2040Sstevel@tonic-gate String stype = (String)types.elementAt(i); 2050Sstevel@tonic-gate ServiceType ttype = new ServiceType(stype); 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate if (ttype.isAbstractType() && 2080Sstevel@tonic-gate type.equals(ttype.getAbstractTypeName())) { 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate // We are out of luck! 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate SLPConfig config = SLPConfig.getSLPConfig(); 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate config.writeLog("v1_abstract_type_conflict", 2150Sstevel@tonic-gate new Object[] {serviceType, 2160Sstevel@tonic-gate ttype}); 2170Sstevel@tonic-gate attrs.removeAllElements(); 2180Sstevel@tonic-gate } 2190Sstevel@tonic-gate } 2200Sstevel@tonic-gate } 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate hdr.iNumReplies = attrs.size(); 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate ByteArrayOutputStream baos = new ByteArrayOutputStream(); 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate hdr.parseAttributeVectorOut(attrs, baos); // attributes 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate hdr.payload = baos.toByteArray(); 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate hdr.constructDescription("AttrRply", 2310Sstevel@tonic-gate " attributes=``" + attrs + "''\n"); 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate return hdr; 2340Sstevel@tonic-gate } 2350Sstevel@tonic-gate } 236