1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 1999 by Sun Microsystems, Inc.
23  * All rights reserved.
24  *
25  */
26 
27 //  SLPV1SSrvDereg.java:    Message class for SLP service deregistration
28 //			    request.
29 //  Author:           James Kempf
30 //  Created On:       Thu Oct  9 15:00:38 1997
31 //  Last Modified By: James Kempf
32 //  Last Modified On: Mon Jan  4 15:26:33 1999
33 //  Update Count:     82
34 //
35 
36 package com.sun.slp;
37 
38 import java.util.*;
39 import java.io.*;
40 
41 
42 /**
43  * The SLPV1SSrvDereg class models the server side SLP service
44  * deregistration.
45  *
46  * @author James Kempf
47  */
48 
49 
50 class SLPV1SSrvDereg extends SSrvDereg {
51 
52     // Construct a SLPV1SSrvDereg from the byte input stream.
53 
SLPV1SSrvDereg(SrvLocHeader hdr, DataInputStream dis)54     SLPV1SSrvDereg(SrvLocHeader hdr, DataInputStream dis)
55 	throws ServiceLocationException, IOException {
56 
57 	super(hdr, dis);
58 
59     }
60 
61     // Initialize the object.
62 
initialize(DataInputStream dis)63     void initialize(DataInputStream dis)
64 	throws ServiceLocationException, IOException {
65 
66 	SLPHeaderV1 hdr = (SLPHeaderV1)getHeader();
67 	StringBuffer buf = new StringBuffer();
68 
69 	// Parse in the service URL.
70 
71 	URL =
72 	    hdr.parseServiceURLIn(dis,
73 				  false,
74 				ServiceLocationException.INVALID_REGISTRATION);
75 
76 	hdr.getString(buf, dis);
77 
78 	tags = hdr.parseCommaSeparatedListIn(buf.toString().trim(), true);
79 
80 	// Error if any tags are wildcarded. Only allowed for AttrRqst.
81 
82 	int i, n = tags.size();
83 
84 	for (i = 0; i < n; i++) {
85 	    String tag = (String)tags.elementAt(i);
86 
87 	    // Unescape tag.
88 
89 	    tag =
90 		ServiceLocationAttributeV1.unescapeAttributeString(tag,
91 								hdr.charCode);
92 
93 	    if (tag.startsWith("*") || tag.endsWith("*")) {
94 		throw
95 		    new ServiceLocationException(
96 				ServiceLocationException.PARSE_ERROR,
97 				"v1_dereg_wildcard",
98 				new Object[0]);
99 	    }
100 
101 	    tags.setElementAt(tag, i);
102 	}
103 
104 	// If no tags, then set the tags vector to null. This indicates
105 	//  that the service: URL needs to be deregistered.
106 
107 	if (tags.size() <= 0) {
108 	    tags = null;
109 	}
110 
111 	// We need to find all the scopes for this guy and put them into the
112 	//  scope list on the header.
113 
114 	ServiceTable table = ServiceTable.getServiceTable();
115 
116 	ServiceStore.ServiceRecord rec = table.getServiceRecord(URL,
117 								hdr.locale);
118 
119 	// If the record is there, then get the scopes.
120 
121 	if (rec != null) {
122 	    hdr.scopes = (Vector)rec.getScopes().clone();
123 
124 	} else {
125 
126 	    SLPConfig config = SLPConfig.getSLPConfig();
127 
128 	    // We simply put in the useScopes, just to make the request.
129 	    //  The request will be rejected when presented to ServiceTable.
130 
131 	    hdr.scopes = (Vector)config.getSAConfiguredScopes().clone();
132 
133 	}
134 
135 	hdr.constructDescription("SrvDereg",
136 				 "         URL=``" + URL + "''\n" +
137 				 "         tags=``" + tags + "''\n");
138 
139     }
140 
141     // Return a SrvAck.
142 
makeReply()143     SrvLocMsg makeReply() {
144 
145 	SLPHeaderV1 hdr = ((SLPHeaderV1)getHeader()).makeReplyHeader();
146 
147 	// Construct description.
148 
149 	hdr.constructDescription("SrvAck", "");
150 
151 	return hdr;
152 
153     }
154 }
155