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
5*9a70fc3bSMark J. Nelson  * Common Development and Distribution License (the "License").
6*9a70fc3bSMark 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 //  SLPV1SDAAdvert.java: SLPv1 DAAdvert, server side.
287c478bd9Sstevel@tonic-gate //  Author:           James Kempf
297c478bd9Sstevel@tonic-gate //  Created On:       Thu Sep 10 11:00:26 1998
307c478bd9Sstevel@tonic-gate //  Last Modified By: James Kempf
317c478bd9Sstevel@tonic-gate //  Last Modified On: Mon Nov  2 15:55:47 1998
327c478bd9Sstevel@tonic-gate //  Update Count:     27
337c478bd9Sstevel@tonic-gate //
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate package com.sun.slp;
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate import java.util.*;
397c478bd9Sstevel@tonic-gate import java.io.*;
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /**
437c478bd9Sstevel@tonic-gate  * The SLPV1SDAAdvert class models the SLPv1 DAAdvert message.
447c478bd9Sstevel@tonic-gate  *
457c478bd9Sstevel@tonic-gate  * @author James Kempf
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate class SLPV1SDAAdvert extends SDAAdvert {
497c478bd9Sstevel@tonic-gate 
SLPV1SDAAdvert(SrvLocHeader hdr, short xid, long timestamp, ServiceURL url, Vector scopes, Vector attrs)507c478bd9Sstevel@tonic-gate     SLPV1SDAAdvert(SrvLocHeader hdr,
517c478bd9Sstevel@tonic-gate 		   short xid,
527c478bd9Sstevel@tonic-gate 		   long timestamp,
537c478bd9Sstevel@tonic-gate 		   ServiceURL url,
547c478bd9Sstevel@tonic-gate 		   Vector scopes,
557c478bd9Sstevel@tonic-gate 		   Vector attrs)
567c478bd9Sstevel@tonic-gate 	throws ServiceLocationException {
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	super(hdr, xid, timestamp, url, scopes, attrs);
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate     }
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate     // Initialize the message.
637c478bd9Sstevel@tonic-gate 
initialize(long timestamp, ServiceURL url, Vector scopes, Vector attrs)647c478bd9Sstevel@tonic-gate     void initialize(long timestamp,
657c478bd9Sstevel@tonic-gate 		    ServiceURL url,
667c478bd9Sstevel@tonic-gate 		    Vector scopes,
677c478bd9Sstevel@tonic-gate 		    Vector attrs)
687c478bd9Sstevel@tonic-gate 	throws ServiceLocationException {
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	// By using the incoming header, we are assured of
717c478bd9Sstevel@tonic-gate 	//  getting the encoding required by the client.
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	SLPHeaderV1 hdr = (SLPHeaderV1)this.hdr;
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 	int i, n = scopes.size();
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
787c478bd9Sstevel@tonic-gate 	    hdr.validateScope((String)scopes.elementAt(i));
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	}
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	// If the only scope we support is default and we are to
837c478bd9Sstevel@tonic-gate 	//  support unscoped regs, then advertise us
847c478bd9Sstevel@tonic-gate 	//  as an unscoped DA. However, if default is there with others,
857c478bd9Sstevel@tonic-gate 	//  we keep it.
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	SLPConfig config = SLPConfig.getSLPConfig();
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	if (config.getAcceptSLPv1UnscopedRegs() &&
907c478bd9Sstevel@tonic-gate 	    scopes.size() <= 1 &&
917c478bd9Sstevel@tonic-gate 	    scopes.contains(Defaults.DEFAULT_SCOPE)) {
927c478bd9Sstevel@tonic-gate 	    scopes.removeAllElements();
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	}
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	// Parse out the payload.
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 	ByteArrayOutputStream baos = new ByteArrayOutputStream();
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	// Parse out the URL.
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	hdr.parseServiceURLOut(url, false, baos);
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	// Parse out the scope list. Same in V1 and V2.
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	hdr.parseCommaSeparatedListOut(scopes, baos);
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	hdr.payload = baos.toByteArray();
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	hdr.iNumReplies = 1;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	hdr.constructDescription("DAAdvert",
1137c478bd9Sstevel@tonic-gate 				 "         URL=``" + url + "''\n" +
1147c478bd9Sstevel@tonic-gate 				 "         scopes=``" + scopes + "''\n");
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate     }
1177c478bd9Sstevel@tonic-gate }
118