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 // CSrvReg.java: Service Registration, Client Side. 280Sstevel@tonic-gate // Author: James Kempf 290Sstevel@tonic-gate // Created On: Tue Feb 10 12:15:43 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: 49 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 CSrvReg class models the client side SLP service registration 430Sstevel@tonic-gate * message. 440Sstevel@tonic-gate * 450Sstevel@tonic-gate * @author James Kempf 460Sstevel@tonic-gate */ 470Sstevel@tonic-gate 480Sstevel@tonic-gate class CSrvReg extends SrvLocMsgImpl { 490Sstevel@tonic-gate 500Sstevel@tonic-gate ServiceURL URL; 510Sstevel@tonic-gate 520Sstevel@tonic-gate // Construct a CSrvReg from the arguments. This is the SrvReg for 530Sstevel@tonic-gate CSrvReg(boolean fresh, Locale locale, ServiceURL urlEntry, Vector scopes, Vector attrs, Hashtable URLSignatures, Hashtable attrSignatures)540Sstevel@tonic-gate CSrvReg(boolean fresh, 550Sstevel@tonic-gate Locale locale, 560Sstevel@tonic-gate ServiceURL urlEntry, 570Sstevel@tonic-gate Vector scopes, 580Sstevel@tonic-gate Vector attrs, 590Sstevel@tonic-gate Hashtable URLSignatures, 600Sstevel@tonic-gate Hashtable attrSignatures) 610Sstevel@tonic-gate throws ServiceLocationException { 620Sstevel@tonic-gate 630Sstevel@tonic-gate this.URL = urlEntry; 640Sstevel@tonic-gate 650Sstevel@tonic-gate // We do heavy checking of attributes here so that any registrations 660Sstevel@tonic-gate // are correct. 670Sstevel@tonic-gate 680Sstevel@tonic-gate Hashtable attrHash = new Hashtable(); 690Sstevel@tonic-gate int i, n = attrs.size(); 700Sstevel@tonic-gate 710Sstevel@tonic-gate // Verify each attribute, merging duplicates in the vector 720Sstevel@tonic-gate // and throwing an error if any duplicates have mismatched types. 730Sstevel@tonic-gate 740Sstevel@tonic-gate Vector attrList = new Vector(); 750Sstevel@tonic-gate 760Sstevel@tonic-gate for (i = 0; i < n; i++) { 770Sstevel@tonic-gate Object o = attrs.elementAt(i); 780Sstevel@tonic-gate 790Sstevel@tonic-gate if (!(o instanceof ServiceLocationAttribute)) { 800Sstevel@tonic-gate throw 810Sstevel@tonic-gate new IllegalArgumentException( 820Sstevel@tonic-gate SLPConfig.getSLPConfig().formatMessage("not_an_attribute", 830Sstevel@tonic-gate new Object[0])); 840Sstevel@tonic-gate } 850Sstevel@tonic-gate 860Sstevel@tonic-gate // Make a new copy of the attribute, so we can modify it. 870Sstevel@tonic-gate 880Sstevel@tonic-gate ServiceLocationAttribute attr = (ServiceLocationAttribute)o; 890Sstevel@tonic-gate 900Sstevel@tonic-gate ServiceLocationAttribute.mergeDuplicateAttributes( 910Sstevel@tonic-gate new ServiceLocationAttribute(attr.getId(), attr.getValues()), 920Sstevel@tonic-gate attrHash, 930Sstevel@tonic-gate attrList, 940Sstevel@tonic-gate false); 950Sstevel@tonic-gate } 960Sstevel@tonic-gate 970Sstevel@tonic-gate this.initialize(fresh, 980Sstevel@tonic-gate locale, 990Sstevel@tonic-gate urlEntry, 1000Sstevel@tonic-gate scopes, 1010Sstevel@tonic-gate attrList, 1020Sstevel@tonic-gate URLSignatures, 1030Sstevel@tonic-gate attrSignatures); 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate } 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate // Initialize the object. V1 will do it differently. 1080Sstevel@tonic-gate initialize(boolean fresh, Locale locale, ServiceURL urlEntry, Vector scopes, Vector attrs, Hashtable URLSignatures, Hashtable attrSignatures)1090Sstevel@tonic-gate void initialize(boolean fresh, 1100Sstevel@tonic-gate Locale locale, 1110Sstevel@tonic-gate ServiceURL urlEntry, 1120Sstevel@tonic-gate Vector scopes, 1130Sstevel@tonic-gate Vector attrs, 1140Sstevel@tonic-gate Hashtable URLSignatures, 1150Sstevel@tonic-gate Hashtable attrSignatures) 1160Sstevel@tonic-gate throws ServiceLocationException { 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate SLPConfig config = SLPConfig.getSLPConfig(); 1190Sstevel@tonic-gate SLPHeaderV2 hdr = new SLPHeaderV2(SrvLocHeader.SrvReg, fresh, locale); 1200Sstevel@tonic-gate this.hdr = hdr; 1210Sstevel@tonic-gate hdr.scopes = (Vector)scopes.clone(); 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate ByteArrayOutputStream baos = new ByteArrayOutputStream(); 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate // Parse out the URL. Ignore overflow. 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate hdr.parseServiceURLOut(urlEntry, 1280Sstevel@tonic-gate config.getHasSecurity(), 1290Sstevel@tonic-gate URLSignatures, 1300Sstevel@tonic-gate baos, 1310Sstevel@tonic-gate false); 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate // Parse out service type. It may be different from the 1340Sstevel@tonic-gate // service URL. 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate ServiceType serviceType = urlEntry.getServiceType(); 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate hdr.putString(serviceType.toString(), baos); 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate // Escape scope strings. 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate hdr.escapeScopeStrings(scopes); 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate // Parse out the scope list. 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate hdr.parseCommaSeparatedListOut(scopes, baos); 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate // Parse out the attribute list. 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate hdr.parseAttributeVectorOut(attrs, 1510Sstevel@tonic-gate urlEntry.getLifetime(), 1520Sstevel@tonic-gate config.getHasSecurity(), 1530Sstevel@tonic-gate attrSignatures, 1540Sstevel@tonic-gate baos, 1550Sstevel@tonic-gate true); 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate hdr.payload = baos.toByteArray(); 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate } 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate } 162