1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * ident	"%Z%%M%	%I%	%E% SMI"
24*7c478bd9Sstevel@tonic-gate  *
25*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1999 by Sun Microsystems, Inc.
26*7c478bd9Sstevel@tonic-gate  * All rights reserved.
27*7c478bd9Sstevel@tonic-gate  *
28*7c478bd9Sstevel@tonic-gate  */
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate //  SCCS Status:      %W%	%G%
31*7c478bd9Sstevel@tonic-gate //  SLPV1CDAAdvert.java: SLP V1 compatible client side DAAdvert
32*7c478bd9Sstevel@tonic-gate //  Author:           James Kempf
33*7c478bd9Sstevel@tonic-gate //  Created On:       Fri Oct  9 14:20:16 1998
34*7c478bd9Sstevel@tonic-gate //  Last Modified By: James Kempf
35*7c478bd9Sstevel@tonic-gate //  Last Modified On: Mon Nov  2 15:59:49 1998
36*7c478bd9Sstevel@tonic-gate //  Update Count:     10
37*7c478bd9Sstevel@tonic-gate //
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate package com.sun.slp;
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate import java.util.*;
43*7c478bd9Sstevel@tonic-gate import java.io.*;
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate /**
47*7c478bd9Sstevel@tonic-gate  * The SLPV1CDAAdvert class models the SLP V1 DAAdvert message, client side.
48*7c478bd9Sstevel@tonic-gate  *
49*7c478bd9Sstevel@tonic-gate  * @version %R%.%L% %D%
50*7c478bd9Sstevel@tonic-gate  * @author James Kempf
51*7c478bd9Sstevel@tonic-gate  */
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate class SLPV1CDAAdvert extends CDAAdvert {
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate     boolean unsolicited = true;   // we assume unsolicited, set if solicited.
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate     // Construct a SLPV1CDAAdvert from the byte input stream.
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate     SLPV1CDAAdvert(SLPHeaderV1 hdr, DataInputStream dis)
60*7c478bd9Sstevel@tonic-gate 	throws ServiceLocationException, IOException {
61*7c478bd9Sstevel@tonic-gate 	super(hdr, dis);
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate 	// Super initializes it.
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate     }
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate     // Initialize object from input stream.
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate     protected void initialize(DataInputStream dis)
70*7c478bd9Sstevel@tonic-gate 	throws ServiceLocationException, IOException {
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	SLPHeaderV1 hdr = (SLPHeaderV1)getHeader();
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate 	// Parse in error code.
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate 	hdr.errCode = (short)hdr.getInt(dis);
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate 	// Don't parse the rest if there's an error.
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate 	if (hdr.errCode != ServiceLocationException.OK) {
81*7c478bd9Sstevel@tonic-gate 	    return;
82*7c478bd9Sstevel@tonic-gate 	}
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate 	// Parse in DA's service URL.
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 	URL =
87*7c478bd9Sstevel@tonic-gate 	    hdr.parseServiceURLIn(dis,
88*7c478bd9Sstevel@tonic-gate 				  false,
89*7c478bd9Sstevel@tonic-gate 				  ServiceLocationException.PARSE_ERROR);
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate 	// Validate the service URL.
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate 	ServiceType serviceType = URL.getServiceType();
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate 	if (!serviceType.equals(Defaults.DA_SERVICE_TYPE)) {
96*7c478bd9Sstevel@tonic-gate 	    throw
97*7c478bd9Sstevel@tonic-gate 		new ServiceLocationException(
98*7c478bd9Sstevel@tonic-gate 				ServiceLocationException.PARSE_ERROR,
99*7c478bd9Sstevel@tonic-gate 				"not_right_url",
100*7c478bd9Sstevel@tonic-gate 				new Object[] {URL, "DA"});
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	}
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	// Parse in the scope list.
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate 	StringBuffer buf = new StringBuffer();
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 	hdr.getString(buf, dis);
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	hdr.scopes = hdr.parseCommaSeparatedListIn(buf.toString(), true);
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate 	// Validate the scope list.
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 	int i, n = hdr.scopes.size();
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
117*7c478bd9Sstevel@tonic-gate 	    String scope = (String)hdr.scopes.elementAt(i);
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate 	    SLPHeaderV1.validateScope(scope);
120*7c478bd9Sstevel@tonic-gate 	    hdr.scopes.setElementAt(scope.toLowerCase().trim(), i);
121*7c478bd9Sstevel@tonic-gate 	}
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate 	// If they are unscoped and we support unscoped regs, then
124*7c478bd9Sstevel@tonic-gate 	//  change the scope name to default. We don't check whether we
125*7c478bd9Sstevel@tonic-gate 	//  support default or not. We actually don't use these at
126*7c478bd9Sstevel@tonic-gate 	//  the moment, but we still keep track of them in case we
127*7c478bd9Sstevel@tonic-gate 	//  ever do reg forwarding.
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate 	SLPConfig config = SLPConfig.getSLPConfig();
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 	if (config.getAcceptSLPv1UnscopedRegs() &&
132*7c478bd9Sstevel@tonic-gate 	    hdr.scopes.size() == 0) {
133*7c478bd9Sstevel@tonic-gate 	    hdr.scopes.addElement(Defaults.DEFAULT_SCOPE);
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 	}
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 	hdr.iNumReplies = 1;
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate     }
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate     // Can't tell if the DA is going down or not from the advert in V1,
142*7c478bd9Sstevel@tonic-gate     //  but it doesn't matter since they won't tell us anyway.
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate     boolean isGoingDown() {
145*7c478bd9Sstevel@tonic-gate 	return false;
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate     }
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate     // Return true if the advert was unsolicited.
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate     boolean isUnsolicited() {
152*7c478bd9Sstevel@tonic-gate 	return unsolicited;
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate     }
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate     // Set unSolicited flag.
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate     void setIsUnsolicited(boolean flag) {
159*7c478bd9Sstevel@tonic-gate 	unsolicited = flag;
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate     }
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate }
164