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