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 //  SLPV1CDAAdvert.java: SLP V1 compatible client side DAAdvert
287c478bd9Sstevel@tonic-gate //  Author:           James Kempf
297c478bd9Sstevel@tonic-gate //  Created On:       Fri Oct  9 14:20:16 1998
307c478bd9Sstevel@tonic-gate //  Last Modified By: James Kempf
317c478bd9Sstevel@tonic-gate //  Last Modified On: Mon Nov  2 15:59:49 1998
327c478bd9Sstevel@tonic-gate //  Update Count:     10
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 SLPV1CDAAdvert class models the SLP V1 DAAdvert message, client side.
447c478bd9Sstevel@tonic-gate  *
457c478bd9Sstevel@tonic-gate  * @author James Kempf
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate class SLPV1CDAAdvert extends CDAAdvert {
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate     boolean unsolicited = true;   // we assume unsolicited, set if solicited.
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate     // Construct a SLPV1CDAAdvert from the byte input stream.
537c478bd9Sstevel@tonic-gate 
SLPV1CDAAdvert(SLPHeaderV1 hdr, DataInputStream dis)547c478bd9Sstevel@tonic-gate     SLPV1CDAAdvert(SLPHeaderV1 hdr, DataInputStream dis)
557c478bd9Sstevel@tonic-gate 	throws ServiceLocationException, IOException {
567c478bd9Sstevel@tonic-gate 	super(hdr, dis);
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	// Super initializes it.
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate     }
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate     // Initialize object from input stream.
637c478bd9Sstevel@tonic-gate 
initialize(DataInputStream dis)647c478bd9Sstevel@tonic-gate     protected void initialize(DataInputStream dis)
657c478bd9Sstevel@tonic-gate 	throws ServiceLocationException, IOException {
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 	SLPHeaderV1 hdr = (SLPHeaderV1)getHeader();
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 	// Parse in error code.
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 	hdr.errCode = (short)hdr.getInt(dis);
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	// Don't parse the rest if there's an error.
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 	if (hdr.errCode != ServiceLocationException.OK) {
767c478bd9Sstevel@tonic-gate 	    return;
777c478bd9Sstevel@tonic-gate 	}
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	// Parse in DA's service URL.
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	URL =
827c478bd9Sstevel@tonic-gate 	    hdr.parseServiceURLIn(dis,
837c478bd9Sstevel@tonic-gate 				  false,
847c478bd9Sstevel@tonic-gate 				  ServiceLocationException.PARSE_ERROR);
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 	// Validate the service URL.
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	ServiceType serviceType = URL.getServiceType();
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate 	if (!serviceType.equals(Defaults.DA_SERVICE_TYPE)) {
917c478bd9Sstevel@tonic-gate 	    throw
927c478bd9Sstevel@tonic-gate 		new ServiceLocationException(
937c478bd9Sstevel@tonic-gate 				ServiceLocationException.PARSE_ERROR,
947c478bd9Sstevel@tonic-gate 				"not_right_url",
957c478bd9Sstevel@tonic-gate 				new Object[] {URL, "DA"});
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	}
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	// Parse in the scope list.
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	StringBuffer buf = new StringBuffer();
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	hdr.getString(buf, dis);
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 	hdr.scopes = hdr.parseCommaSeparatedListIn(buf.toString(), true);
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	// Validate the scope list.
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	int i, n = hdr.scopes.size();
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
1127c478bd9Sstevel@tonic-gate 	    String scope = (String)hdr.scopes.elementAt(i);
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	    SLPHeaderV1.validateScope(scope);
1157c478bd9Sstevel@tonic-gate 	    hdr.scopes.setElementAt(scope.toLowerCase().trim(), i);
1167c478bd9Sstevel@tonic-gate 	}
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	// If they are unscoped and we support unscoped regs, then
1197c478bd9Sstevel@tonic-gate 	//  change the scope name to default. We don't check whether we
1207c478bd9Sstevel@tonic-gate 	//  support default or not. We actually don't use these at
1217c478bd9Sstevel@tonic-gate 	//  the moment, but we still keep track of them in case we
1227c478bd9Sstevel@tonic-gate 	//  ever do reg forwarding.
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	SLPConfig config = SLPConfig.getSLPConfig();
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 	if (config.getAcceptSLPv1UnscopedRegs() &&
1277c478bd9Sstevel@tonic-gate 	    hdr.scopes.size() == 0) {
1287c478bd9Sstevel@tonic-gate 	    hdr.scopes.addElement(Defaults.DEFAULT_SCOPE);
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	}
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	hdr.iNumReplies = 1;
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate     }
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate     // Can't tell if the DA is going down or not from the advert in V1,
1377c478bd9Sstevel@tonic-gate     //  but it doesn't matter since they won't tell us anyway.
1387c478bd9Sstevel@tonic-gate 
isGoingDown()1397c478bd9Sstevel@tonic-gate     boolean isGoingDown() {
1407c478bd9Sstevel@tonic-gate 	return false;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate     }
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate     // Return true if the advert was unsolicited.
1457c478bd9Sstevel@tonic-gate 
isUnsolicited()1467c478bd9Sstevel@tonic-gate     boolean isUnsolicited() {
1477c478bd9Sstevel@tonic-gate 	return unsolicited;
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate     }
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate     // Set unSolicited flag.
1527c478bd9Sstevel@tonic-gate 
setIsUnsolicited(boolean flag)1537c478bd9Sstevel@tonic-gate     void setIsUnsolicited(boolean flag) {
1547c478bd9Sstevel@tonic-gate 	unsolicited = flag;
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate     }
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate }
159