17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
59a70fc3bSMark J. Nelson  * Common Development and Distribution License (the "License").
69a70fc3bSMark J. Nelson  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
227c478bd9Sstevel@tonic-gate  * Copyright (c) 1999 by Sun Microsystems, Inc.
237c478bd9Sstevel@tonic-gate  * All rights reserved.
247c478bd9Sstevel@tonic-gate  *
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate //  CSrvReg.java:    Service Registration, Client Side.
287c478bd9Sstevel@tonic-gate //  Author:           James Kempf
297c478bd9Sstevel@tonic-gate //  Created On:       Tue Feb 10 12:15:43 1998
307c478bd9Sstevel@tonic-gate //  Last Modified By: James Kempf
317c478bd9Sstevel@tonic-gate //  Last Modified On: Tue Oct 27 10:57:38 1998
327c478bd9Sstevel@tonic-gate //  Update Count:     49
337c478bd9Sstevel@tonic-gate //
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate package com.sun.slp;
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate import java.util.*;
387c478bd9Sstevel@tonic-gate import java.io.*;
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /**
42*55fea89dSDan Cross  * The CSrvReg class models the client side SLP service registration
43*55fea89dSDan Cross  * message.
447c478bd9Sstevel@tonic-gate  *
457c478bd9Sstevel@tonic-gate  * @author James Kempf
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate class CSrvReg extends SrvLocMsgImpl {
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate     ServiceURL URL;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate     // Construct a CSrvReg from the arguments. This is the SrvReg for
537c478bd9Sstevel@tonic-gate 
CSrvReg(boolean fresh, Locale locale, ServiceURL urlEntry, Vector scopes, Vector attrs, Hashtable URLSignatures, Hashtable attrSignatures)547c478bd9Sstevel@tonic-gate     CSrvReg(boolean fresh,
557c478bd9Sstevel@tonic-gate 	    Locale locale,
567c478bd9Sstevel@tonic-gate 	    ServiceURL urlEntry,
577c478bd9Sstevel@tonic-gate 	    Vector scopes,
587c478bd9Sstevel@tonic-gate 	    Vector attrs,
597c478bd9Sstevel@tonic-gate 	    Hashtable URLSignatures,
60*55fea89dSDan Cross 	    Hashtable attrSignatures)
617c478bd9Sstevel@tonic-gate 	throws ServiceLocationException {
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 	this.URL = urlEntry;
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate 	// We do heavy checking of attributes here so that any registrations
667c478bd9Sstevel@tonic-gate 	//  are correct.
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 	Hashtable attrHash = new Hashtable();
697c478bd9Sstevel@tonic-gate 	int i, n = attrs.size();
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 	// Verify each attribute, merging duplicates in the vector
727c478bd9Sstevel@tonic-gate 	//  and throwing an error if any duplicates have mismatched types.
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 	Vector attrList = new Vector();
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
777c478bd9Sstevel@tonic-gate 	    Object o = attrs.elementAt(i);
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	    if (!(o instanceof ServiceLocationAttribute)) {
807c478bd9Sstevel@tonic-gate 		throw
817c478bd9Sstevel@tonic-gate 		    new IllegalArgumentException(
827c478bd9Sstevel@tonic-gate 		SLPConfig.getSLPConfig().formatMessage("not_an_attribute",
837c478bd9Sstevel@tonic-gate 						       new Object[0]));
847c478bd9Sstevel@tonic-gate 	    }
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 	    // Make a new copy of the attribute, so we can modify it.
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	    ServiceLocationAttribute attr = (ServiceLocationAttribute)o;
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate 	    ServiceLocationAttribute.mergeDuplicateAttributes(
917c478bd9Sstevel@tonic-gate 		new ServiceLocationAttribute(attr.getId(), attr.getValues()),
927c478bd9Sstevel@tonic-gate 		attrHash,
937c478bd9Sstevel@tonic-gate 		attrList,
947c478bd9Sstevel@tonic-gate 		false);
957c478bd9Sstevel@tonic-gate 	}
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	this.initialize(fresh,
987c478bd9Sstevel@tonic-gate 			locale,
997c478bd9Sstevel@tonic-gate 			urlEntry,
1007c478bd9Sstevel@tonic-gate 			scopes,
1017c478bd9Sstevel@tonic-gate 			attrList,
1027c478bd9Sstevel@tonic-gate 			URLSignatures,
1037c478bd9Sstevel@tonic-gate 			attrSignatures);
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate     }
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate     // Initialize the object. V1 will do it differently.
1087c478bd9Sstevel@tonic-gate 
initialize(boolean fresh, Locale locale, ServiceURL urlEntry, Vector scopes, Vector attrs, Hashtable URLSignatures, Hashtable attrSignatures)1097c478bd9Sstevel@tonic-gate     void initialize(boolean fresh,
1107c478bd9Sstevel@tonic-gate 		    Locale locale,
1117c478bd9Sstevel@tonic-gate 		    ServiceURL urlEntry,
1127c478bd9Sstevel@tonic-gate 		    Vector scopes,
1137c478bd9Sstevel@tonic-gate 		    Vector attrs,
1147c478bd9Sstevel@tonic-gate 		    Hashtable URLSignatures,
115*55fea89dSDan Cross 		    Hashtable attrSignatures)
1167c478bd9Sstevel@tonic-gate 	throws ServiceLocationException {
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	SLPConfig config = SLPConfig.getSLPConfig();
1197c478bd9Sstevel@tonic-gate 	SLPHeaderV2 hdr = new SLPHeaderV2(SrvLocHeader.SrvReg, fresh, locale);
1207c478bd9Sstevel@tonic-gate 	this.hdr = hdr;
1217c478bd9Sstevel@tonic-gate 	hdr.scopes = (Vector)scopes.clone();
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	ByteArrayOutputStream baos = new ByteArrayOutputStream();
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	// Parse out the URL. Ignore overflow.
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	hdr.parseServiceURLOut(urlEntry,
1287c478bd9Sstevel@tonic-gate 			       config.getHasSecurity(),
1297c478bd9Sstevel@tonic-gate 			       URLSignatures,
1307c478bd9Sstevel@tonic-gate 			       baos,
1317c478bd9Sstevel@tonic-gate 			       false);
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	// Parse out service type. It may be different from the
1347c478bd9Sstevel@tonic-gate 	//  service URL.
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 	ServiceType serviceType = urlEntry.getServiceType();
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	hdr.putString(serviceType.toString(), baos);
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	// Escape scope strings.
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	hdr.escapeScopeStrings(scopes);
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	// Parse out the scope list.
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	hdr.parseCommaSeparatedListOut(scopes, baos);
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	// Parse out the attribute list.
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	hdr.parseAttributeVectorOut(attrs,
1517c478bd9Sstevel@tonic-gate 				    urlEntry.getLifetime(),
1527c478bd9Sstevel@tonic-gate 				    config.getHasSecurity(),
1537c478bd9Sstevel@tonic-gate 				    attrSignatures,
1547c478bd9Sstevel@tonic-gate 				    baos,
1557c478bd9Sstevel@tonic-gate 				    true);
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	hdr.payload = baos.toByteArray();
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate     }
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate }
162