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 // SunServerDATable.java: Server DA Table for Sun's client/SA server SLP. 280Sstevel@tonic-gate // Author: James Kempf 290Sstevel@tonic-gate // Created On: Wed May 20 09:58:46 1998 300Sstevel@tonic-gate // Last Modified By: James Kempf 310Sstevel@tonic-gate // Last Modified On: Mon Mar 8 14:30:29 1999 320Sstevel@tonic-gate // Update Count: 79 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.net.*; 390Sstevel@tonic-gate import java.io.*; 400Sstevel@tonic-gate 410Sstevel@tonic-gate /** 420Sstevel@tonic-gate * SunServerDATable is a subclass class that provides the 430Sstevel@tonic-gate * implementation for DA storage on Solaris. As described in 440Sstevel@tonic-gate * the header for SunDATable, DA information is stored in the server's 450Sstevel@tonic-gate * SA table as the service type "directory-agent.sun" with a 460Sstevel@tonic-gate * attribute, scopes. The attribute contains a list of scopes supported 470Sstevel@tonic-gate * by the DA. The service: URL of the registration contains the 480Sstevel@tonic-gate * DA address as the host, followed by the list of scopes as an attribute 490Sstevel@tonic-gate * in the URL part. An example is: 500Sstevel@tonic-gate * 510Sstevel@tonic-gate * service:directory-agent.sun:// 199.200.200.5/scopes=eng, corp, freeb 520Sstevel@tonic-gate * 530Sstevel@tonic-gate * The scopes of the registration are the scopes provided as the Sun-specific 540Sstevel@tonic-gate * system property "sun.net.slp.SAOnlyScopes". By convention, this is 550Sstevel@tonic-gate * initialized to be the local machine name, but it may also include other 560Sstevel@tonic-gate * names. 570Sstevel@tonic-gate * 580Sstevel@tonic-gate * @author James Kempf 590Sstevel@tonic-gate */ 600Sstevel@tonic-gate 610Sstevel@tonic-gate class SunServerDATable extends ServerDATable { 620Sstevel@tonic-gate 630Sstevel@tonic-gate // DA boot timestamp. 640Sstevel@tonic-gate 650Sstevel@tonic-gate static final private String TIMESTAMP_ID = 660Sstevel@tonic-gate "424242SUN-TABLE-TIMESTAMP424242"; 670Sstevel@tonic-gate 680Sstevel@tonic-gate // Address. Makes deletion easier. 690Sstevel@tonic-gate 700Sstevel@tonic-gate static final private String ADDRESS_ID = "424242SUN-TABLE-ADDRESS424242"; 710Sstevel@tonic-gate 720Sstevel@tonic-gate private ServiceTable serviceTable = null; // SA table for regs. 730Sstevel@tonic-gate private Vector saOnlyScopes = null; // Scopes for SA only. 740Sstevel@tonic-gate SunServerDATable()750Sstevel@tonic-gate SunServerDATable() { 760Sstevel@tonic-gate 770Sstevel@tonic-gate // Get the service table. 780Sstevel@tonic-gate 790Sstevel@tonic-gate try { 800Sstevel@tonic-gate 810Sstevel@tonic-gate serviceTable = ServiceTable.getServiceTable(); 820Sstevel@tonic-gate 830Sstevel@tonic-gate } catch (ServiceLocationException ex) { 840Sstevel@tonic-gate 850Sstevel@tonic-gate } 860Sstevel@tonic-gate 870Sstevel@tonic-gate // Get the vector of SA scopes. 880Sstevel@tonic-gate 890Sstevel@tonic-gate saOnlyScopes = conf.getSAOnlyScopes(); 900Sstevel@tonic-gate 910Sstevel@tonic-gate Assert.slpassert(saOnlyScopes.size() > 0, 920Sstevel@tonic-gate "no_sa_scopes", 930Sstevel@tonic-gate new Object[0]); 940Sstevel@tonic-gate 950Sstevel@tonic-gate } 960Sstevel@tonic-gate 970Sstevel@tonic-gate /** 980Sstevel@tonic-gate * Record a new DA in the service table. 990Sstevel@tonic-gate * 1000Sstevel@tonic-gate * @param URL The DAAdvert URL. 1010Sstevel@tonic-gate * @param scopes The scopes. 1020Sstevel@tonic-gate * @param version DA version number. 1030Sstevel@tonic-gate * @param spis SPIs this DA can support 1040Sstevel@tonic-gate * @return The boot timestamp in the previous registration. Used 1050Sstevel@tonic-gate * to determine if registration is necessary. If an error occurs, 1060Sstevel@tonic-gate * the returned value is negative. If the DA is new, the return 1070Sstevel@tonic-gate * value is the maximum long value. This will cause all 1080Sstevel@tonic-gate * registrations to be forwarded, because it is larger than any 1090Sstevel@tonic-gate * current time. 1100Sstevel@tonic-gate */ 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate public synchronized long recordNewDA(ServiceURL url, Vector scopes, long timestamp, int version, Vector attrs, String spis)1130Sstevel@tonic-gate recordNewDA(ServiceURL url, 1140Sstevel@tonic-gate Vector scopes, 1150Sstevel@tonic-gate long timestamp, 1160Sstevel@tonic-gate int version, 1170Sstevel@tonic-gate Vector attrs, 1180Sstevel@tonic-gate String spis) { 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate String addr = url.getHost(); 1210Sstevel@tonic-gate long formerTimestamp = -1L; 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate // We record all DAs regardless of whether we support them or not, 1240Sstevel@tonic-gate // because a UA client may be using the user selectable scoping 1250Sstevel@tonic-gate // model and therefore may want to see them. 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate Vector v = (Vector)scopes.clone(); 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate // Add the Sun attributes. 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate ServiceLocationAttribute attr = 1320Sstevel@tonic-gate new ServiceLocationAttribute(SunDATable.SCOPES_ID, scopes); 1330Sstevel@tonic-gate attrs.addElement(attr); 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate Vector vals = new Vector(); 1360Sstevel@tonic-gate vals.addElement(Long.toString(timestamp)); 1370Sstevel@tonic-gate attr = 1380Sstevel@tonic-gate new ServiceLocationAttribute(SunServerDATable.TIMESTAMP_ID, vals); 1390Sstevel@tonic-gate attrs.addElement(attr); 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate vals = new Vector(); 1420Sstevel@tonic-gate vals.addElement(new Integer(version)); 1430Sstevel@tonic-gate attr = new ServiceLocationAttribute(SunDATable.VERSION_ID, vals); 1440Sstevel@tonic-gate attrs.addElement(attr); 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate vals = new Vector(); 1470Sstevel@tonic-gate vals.addElement(url.getHost()); 1480Sstevel@tonic-gate attr = new ServiceLocationAttribute(SunServerDATable.ADDRESS_ID, vals); 1490Sstevel@tonic-gate attrs.addElement(attr); 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate // Form the URL for the DA. 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate ServiceURL adURL = formServiceTableDAURL(url, attrs); 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate // Reach *around* the service table for registration, because 1560Sstevel@tonic-gate // we don't need a message. The service table abstraction 1570Sstevel@tonic-gate // is basically for decoding message objects, and we already 1580Sstevel@tonic-gate // have things in the internal form needed by the service store. 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate ServiceStore store = serviceTable.store; 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate try { 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate // First, get the boot time stamp if there. 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate Vector tags = new Vector(); 1670Sstevel@tonic-gate tags.addElement(SunServerDATable.TIMESTAMP_ID); 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate Hashtable attrRec = 1700Sstevel@tonic-gate store.findAttributes(adURL, 1710Sstevel@tonic-gate saOnlyScopes, 1720Sstevel@tonic-gate tags, 1730Sstevel@tonic-gate Defaults.locale); 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate Vector formerAttrs = 1760Sstevel@tonic-gate (Vector)attrRec.get(ServiceStore.FA_ATTRIBUTES); 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate // If there, then get the old timestamp. 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate if (formerAttrs != null && !(formerAttrs.size() <= 0)) { 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate // Get the timestamp into a long. 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate attr = (ServiceLocationAttribute)formerAttrs.elementAt(0); 1850Sstevel@tonic-gate vals = attr.getValues(); 1860Sstevel@tonic-gate String stamp = (String)vals.elementAt(0); 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate try { 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate formerTimestamp = Long.parseLong(stamp.trim()); 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate } catch (NumberFormatException ex) { 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate Assert.slpassert(false, 1950Sstevel@tonic-gate "ssdat_number_format", 1960Sstevel@tonic-gate new Object[0]); 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate } 1990Sstevel@tonic-gate } 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate // Now register the URL. 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate store.register(adURL, 2040Sstevel@tonic-gate attrs, 2050Sstevel@tonic-gate saOnlyScopes, 2060Sstevel@tonic-gate Defaults.locale, 2070Sstevel@tonic-gate null, 2080Sstevel@tonic-gate null); 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate // Keep track of this DAs supported SPIs 2110Sstevel@tonic-gate LinkedList spiList = 2120Sstevel@tonic-gate AuthBlock.commaSeparatedListToLinkedList(spis); 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate // convert addr to an InetAddress for hashing 2150Sstevel@tonic-gate InetAddress inetAddr = null; 2160Sstevel@tonic-gate try { 2170Sstevel@tonic-gate inetAddr = InetAddress.getByName(addr); 2180Sstevel@tonic-gate } catch (UnknownHostException e) {} 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate // If we didn't get the InetAddress, this DA will never be used 2210Sstevel@tonic-gate // anyway 2220Sstevel@tonic-gate if (addr != null) { 2230Sstevel@tonic-gate daSPIsHash.put(inetAddr, spiList); 2240Sstevel@tonic-gate } 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate } catch (ServiceLocationException ex) { 2270Sstevel@tonic-gate conf.writeLog("ssdat_register_error", 2280Sstevel@tonic-gate new Object[] { 2290Sstevel@tonic-gate ex.getMessage(), 2300Sstevel@tonic-gate adURL, 2310Sstevel@tonic-gate saOnlyScopes}); 2320Sstevel@tonic-gate } 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate return formerTimestamp; 2350Sstevel@tonic-gate } 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate /** 2380Sstevel@tonic-gate * Remove a DA. The Sun-specific convention is used to deregister 2390Sstevel@tonic-gate * the URL. 2400Sstevel@tonic-gate * 2410Sstevel@tonic-gate * @param address The host address of the DA, from its service URL. 2420Sstevel@tonic-gate * @param scopes The scopes. 2430Sstevel@tonic-gate * @return True if removed, false if not. 2440Sstevel@tonic-gate */ 2450Sstevel@tonic-gate removeDA(InetAddress address, Vector scopes)2460Sstevel@tonic-gate public synchronized boolean removeDA(InetAddress address, Vector scopes) { 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate // Find URLs corresponding to this address. 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate String query = "(" + ADDRESS_ID + "=" + address.getHostAddress() + ")"; 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate // Reach *around* the service table for dregistration, because 2530Sstevel@tonic-gate // we don't need a message. The service table abstraction 2540Sstevel@tonic-gate // is basically for decoding message objects, and we already 2550Sstevel@tonic-gate // have things in the internal form needed by the service store. 2560Sstevel@tonic-gate 2570Sstevel@tonic-gate ServiceStore store = serviceTable.store; 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate try { 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate Hashtable das = returnMatchingDAs(query); 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate Enumeration daURLs = das.keys(); 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate while (daURLs.hasMoreElements()) { 2660Sstevel@tonic-gate ServiceURL adURL = (ServiceURL)daURLs.nextElement(); 2670Sstevel@tonic-gate store.deregister(adURL, saOnlyScopes, null); 2680Sstevel@tonic-gate 2690Sstevel@tonic-gate } 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate } catch (ServiceLocationException ex) { 2720Sstevel@tonic-gate conf.writeLog("ssdat_deregister_error", 2730Sstevel@tonic-gate new Object[] { 2740Sstevel@tonic-gate ex.getMessage(), 2750Sstevel@tonic-gate address, 2760Sstevel@tonic-gate saOnlyScopes}); 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate return false; 2790Sstevel@tonic-gate } 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate return true; 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate } 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate /** 2860Sstevel@tonic-gate * Return a hashtable in ServiceTable.findServices() format (e.g. 2870Sstevel@tonic-gate * URL's as keys, scopes as values) for DAs matching the query. 2880Sstevel@tonic-gate * 2890Sstevel@tonic-gate * @param query Query for DA attributes. 2900Sstevel@tonic-gate */ 2910Sstevel@tonic-gate returnMatchingDAs(String query)2920Sstevel@tonic-gate public synchronized Hashtable returnMatchingDAs(String query) 2930Sstevel@tonic-gate throws ServiceLocationException { 2940Sstevel@tonic-gate ServiceStore store = ServiceTable.getServiceTable().store; 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate // Get DA records matching the query. 2970Sstevel@tonic-gate 2980Sstevel@tonic-gate Vector saOnlyScopes = conf.getSAOnlyScopes(); 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate Hashtable returns = 3010Sstevel@tonic-gate store.findServices(Defaults.SUN_DA_SERVICE_TYPE.toString(), 3020Sstevel@tonic-gate saOnlyScopes, 3030Sstevel@tonic-gate query, 3040Sstevel@tonic-gate Defaults.locale); 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate // Return the hashtable of services v.s. scopes. 3070Sstevel@tonic-gate 3080Sstevel@tonic-gate return (Hashtable)returns.get(ServiceStore.FS_SERVICES); 3090Sstevel@tonic-gate } 3100Sstevel@tonic-gate 3110Sstevel@tonic-gate /** 3120Sstevel@tonic-gate * Return a hashtable of DA equivalence classes and multicast 3130Sstevel@tonic-gate * scopes. Multicast scopes are stored in the special hashtable 3140Sstevel@tonic-gate * key MULTICAST_KEY. Unicast DA equivalence classes are stored 3150Sstevel@tonic-gate * under the key UNICAST_KEY. This implementation goes directly 3160Sstevel@tonic-gate * to the service table in the SA server for the DA addresses. 3170Sstevel@tonic-gate * 3180Sstevel@tonic-gate * @param scopes Scope list for DAs needed. 3190Sstevel@tonic-gate * @return Hashtable with DA addresses as keys and scopes to contact 3200Sstevel@tonic-gate * them with as values. Any scopes not associated with a 3210Sstevel@tonic-gate * DA come back stored under the key MULTICAST_KEY. 3220Sstevel@tonic-gate * Unicast DA equivalence classes are stored 3230Sstevel@tonic-gate * under the key UNICAST_KEY. 3240Sstevel@tonic-gate */ 3250Sstevel@tonic-gate findDAScopes(Vector scopes)3260Sstevel@tonic-gate public synchronized Hashtable findDAScopes(Vector scopes) 3270Sstevel@tonic-gate throws ServiceLocationException { 3280Sstevel@tonic-gate 3290Sstevel@tonic-gate // Formulate a query for the DAs. 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate int i, n = scopes.size(); 3320Sstevel@tonic-gate StringBuffer buf = new StringBuffer(); 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate for (i = 0; i < n; i++) { 3350Sstevel@tonic-gate buf.append("("); 3360Sstevel@tonic-gate buf.append(SunDATable.SCOPES_ID); 3370Sstevel@tonic-gate buf.append("="); 3380Sstevel@tonic-gate buf.append((String)scopes.elementAt(i)); 3390Sstevel@tonic-gate buf.append(")"); 3400Sstevel@tonic-gate } 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate // Add logical disjunction if more than one element. 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate if (i > 1) { 3450Sstevel@tonic-gate buf.insert(0, "(|"); 3460Sstevel@tonic-gate buf.append(")"); 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate } 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate // Add version number. 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate if (i > 0) { 3530Sstevel@tonic-gate buf.insert(0, "(&"); 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate } 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate buf.append("("); 3580Sstevel@tonic-gate buf.append(SunDATable.VERSION_ID); 3590Sstevel@tonic-gate buf.append("="); 3600Sstevel@tonic-gate buf.append((new Integer(Defaults.version)).toString()); 3610Sstevel@tonic-gate buf.append(")"); 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate // Add closing paren if there were any scopes. 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate if (i > 0) { 3660Sstevel@tonic-gate buf.append(")"); 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate } 3690Sstevel@tonic-gate 3700Sstevel@tonic-gate ServiceStore store = serviceTable.store; 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate Hashtable returns = 3730Sstevel@tonic-gate store.findServices(Defaults.SUN_DA_SERVICE_TYPE.toString(), 3740Sstevel@tonic-gate saOnlyScopes, 3750Sstevel@tonic-gate buf.toString(), 3760Sstevel@tonic-gate Defaults.locale); 3770Sstevel@tonic-gate 3780Sstevel@tonic-gate Hashtable retRec = (Hashtable)returns.get(ServiceStore.FS_SERVICES); 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate // Convert to a vector. Keys are the service: URLs. 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate Enumeration en = retRec.keys(); 3830Sstevel@tonic-gate Vector ret = new Vector(); 3840Sstevel@tonic-gate Vector multiScopes = (Vector)scopes.clone(); 3850Sstevel@tonic-gate Vector attrTags = new Vector(); 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate attrTags.addElement(SunDATable.SCOPES_ID); 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate while (en.hasMoreElements()) { 3900Sstevel@tonic-gate ServiceURL url = (ServiceURL)en.nextElement(); 3910Sstevel@tonic-gate Vector urlScopes = (Vector)retRec.get(url); 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate // Get the scope attributes for this URL. 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate Hashtable attrRec = 3960Sstevel@tonic-gate store.findAttributes(url, 3970Sstevel@tonic-gate urlScopes, 3980Sstevel@tonic-gate attrTags, 3990Sstevel@tonic-gate Defaults.locale); 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate Vector retAttrs = (Vector)attrRec.get(ServiceStore.FA_ATTRIBUTES); 4020Sstevel@tonic-gate String host = url.getHost(); 4030Sstevel@tonic-gate Vector retScopes = null; 4040Sstevel@tonic-gate n = retAttrs.size(); 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate for (i = 0; i < n; i++) { 4070Sstevel@tonic-gate ServiceLocationAttribute attr = 4080Sstevel@tonic-gate (ServiceLocationAttribute)retAttrs.elementAt(i); 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate // Distinguish based on type. We assume the attributes are 4110Sstevel@tonic-gate // prescreened when the URL was formed to make sure they're OK 4120Sstevel@tonic-gate 4130Sstevel@tonic-gate String id = attr.getId(); 4140Sstevel@tonic-gate Vector vals = attr.getValues(); 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate if (id.equals(SunDATable.SCOPES_ID)) { 4170Sstevel@tonic-gate retScopes = vals; 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate } 4200Sstevel@tonic-gate } 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate // Add to equivalence class. 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate DATable.addToEquivClass(host, retScopes, ret); 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate // Filter scopes for any that might be multicast. 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate DATable.filterScopes(multiScopes, retScopes, false); 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate } 4310Sstevel@tonic-gate 4320Sstevel@tonic-gate // Format the return. 4330Sstevel@tonic-gate 4340Sstevel@tonic-gate retRec.clear(); 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate if (multiScopes.size() > 0) { 4370Sstevel@tonic-gate retRec.put(DATable.MULTICAST_KEY, multiScopes); 4380Sstevel@tonic-gate 4390Sstevel@tonic-gate } 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate if (ret.size() > 0) { 4420Sstevel@tonic-gate retRec.put(DATable.UNICAST_KEY, ret); 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate } 4450Sstevel@tonic-gate 4460Sstevel@tonic-gate return retRec; 4470Sstevel@tonic-gate } 4480Sstevel@tonic-gate 4490Sstevel@tonic-gate // Form a URL for the service table, from the DA URL and attributes. 4500Sstevel@tonic-gate // Attributes and scope have been prechecked for correctness. 4510Sstevel@tonic-gate formServiceTableDAURL(ServiceURL url, Vector attrs)4520Sstevel@tonic-gate private ServiceURL formServiceTableDAURL(ServiceURL url, Vector attrs) { 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate // Form up the URL part. 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate StringBuffer buf = new StringBuffer(); 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate int i, n = attrs.size(); 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate for (i = 0; i < n; i++) { 4610Sstevel@tonic-gate ServiceLocationAttribute attr = 4620Sstevel@tonic-gate (ServiceLocationAttribute)attrs.elementAt(i); 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate // If this is a URL attribute, then externalize and 4650Sstevel@tonic-gate // put into URL. 4660Sstevel@tonic-gate 4670Sstevel@tonic-gate String id = attr.getId(); 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate if (id.equals(SunDATable.SCOPES_ID)) { 4700Sstevel@tonic-gate String rep = ""; 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate try { 4730Sstevel@tonic-gate rep = attr.externalize(); 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate } catch (ServiceLocationException ex) { 4760Sstevel@tonic-gate conf.writeLog("ssdat_inter_attr_err", 4770Sstevel@tonic-gate new Object[] {attr, ex.getMessage()}); 4780Sstevel@tonic-gate continue; 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate } 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate // Add semi if something already there. 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate if (buf.length() > 0) { 4850Sstevel@tonic-gate buf.append(";"); 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate } 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate // Remove parens before inserting. 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate buf.append(rep.substring(1, rep.length()-1)); 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate } 4940Sstevel@tonic-gate } 4950Sstevel@tonic-gate 4960Sstevel@tonic-gate // Create the URL. 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate ServiceURL daURL = 4990Sstevel@tonic-gate new ServiceURL(Defaults.SUN_DA_SERVICE_TYPE+ 5000Sstevel@tonic-gate "://"+ 5010Sstevel@tonic-gate url.getHost()+ 5020Sstevel@tonic-gate "/"+ 5030Sstevel@tonic-gate buf.toString(), 5040Sstevel@tonic-gate url.getLifetime()); 5050Sstevel@tonic-gate return daURL; 5060Sstevel@tonic-gate 5070Sstevel@tonic-gate } 5080Sstevel@tonic-gate } 509