xref: /onnv-gate/usr/src/lib/libslp/javalib/com/sun/slp/SLPV1SSrvDereg.java (revision 7298:b69e27387f74)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7298SMark.J.Nelson@Sun.COM  * Common Development and Distribution License (the "License").
6*7298SMark.J.Nelson@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
220Sstevel@tonic-gate  * Copyright (c) 1999 by Sun Microsystems, Inc.
230Sstevel@tonic-gate  * All rights reserved.
240Sstevel@tonic-gate  *
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate //  SLPV1SSrvDereg.java:    Message class for SLP service deregistration
280Sstevel@tonic-gate //			    request.
290Sstevel@tonic-gate //  Author:           James Kempf
300Sstevel@tonic-gate //  Created On:       Thu Oct  9 15:00:38 1997
310Sstevel@tonic-gate //  Last Modified By: James Kempf
320Sstevel@tonic-gate //  Last Modified On: Mon Jan  4 15:26:33 1999
330Sstevel@tonic-gate //  Update Count:     82
340Sstevel@tonic-gate //
350Sstevel@tonic-gate 
360Sstevel@tonic-gate package com.sun.slp;
370Sstevel@tonic-gate 
380Sstevel@tonic-gate import java.util.*;
390Sstevel@tonic-gate import java.io.*;
400Sstevel@tonic-gate 
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /**
430Sstevel@tonic-gate  * The SLPV1SSrvDereg class models the server side SLP service
440Sstevel@tonic-gate  * deregistration.
450Sstevel@tonic-gate  *
460Sstevel@tonic-gate  * @author James Kempf
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate 
490Sstevel@tonic-gate 
500Sstevel@tonic-gate class SLPV1SSrvDereg extends SSrvDereg {
510Sstevel@tonic-gate 
520Sstevel@tonic-gate     // Construct a SLPV1SSrvDereg from the byte input stream.
530Sstevel@tonic-gate 
SLPV1SSrvDereg(SrvLocHeader hdr, DataInputStream dis)540Sstevel@tonic-gate     SLPV1SSrvDereg(SrvLocHeader hdr, DataInputStream dis)
550Sstevel@tonic-gate 	throws ServiceLocationException, IOException {
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 	super(hdr, dis);
580Sstevel@tonic-gate 
590Sstevel@tonic-gate     }
600Sstevel@tonic-gate 
610Sstevel@tonic-gate     // Initialize the object.
620Sstevel@tonic-gate 
initialize(DataInputStream dis)630Sstevel@tonic-gate     void initialize(DataInputStream dis)
640Sstevel@tonic-gate 	throws ServiceLocationException, IOException {
650Sstevel@tonic-gate 
660Sstevel@tonic-gate 	SLPHeaderV1 hdr = (SLPHeaderV1)getHeader();
670Sstevel@tonic-gate 	StringBuffer buf = new StringBuffer();
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 	// Parse in the service URL.
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 	URL =
720Sstevel@tonic-gate 	    hdr.parseServiceURLIn(dis,
730Sstevel@tonic-gate 				  false,
740Sstevel@tonic-gate 				ServiceLocationException.INVALID_REGISTRATION);
750Sstevel@tonic-gate 
760Sstevel@tonic-gate 	hdr.getString(buf, dis);
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	tags = hdr.parseCommaSeparatedListIn(buf.toString().trim(), true);
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	// Error if any tags are wildcarded. Only allowed for AttrRqst.
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 	int i, n = tags.size();
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
850Sstevel@tonic-gate 	    String tag = (String)tags.elementAt(i);
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	    // Unescape tag.
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 	    tag =
900Sstevel@tonic-gate 		ServiceLocationAttributeV1.unescapeAttributeString(tag,
910Sstevel@tonic-gate 								hdr.charCode);
920Sstevel@tonic-gate 
930Sstevel@tonic-gate 	    if (tag.startsWith("*") || tag.endsWith("*")) {
940Sstevel@tonic-gate 		throw
950Sstevel@tonic-gate 		    new ServiceLocationException(
960Sstevel@tonic-gate 				ServiceLocationException.PARSE_ERROR,
970Sstevel@tonic-gate 				"v1_dereg_wildcard",
980Sstevel@tonic-gate 				new Object[0]);
990Sstevel@tonic-gate 	    }
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 	    tags.setElementAt(tag, i);
1020Sstevel@tonic-gate 	}
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate 	// If no tags, then set the tags vector to null. This indicates
1050Sstevel@tonic-gate 	//  that the service: URL needs to be deregistered.
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 	if (tags.size() <= 0) {
1080Sstevel@tonic-gate 	    tags = null;
1090Sstevel@tonic-gate 	}
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	// We need to find all the scopes for this guy and put them into the
1120Sstevel@tonic-gate 	//  scope list on the header.
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 	ServiceTable table = ServiceTable.getServiceTable();
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate 	ServiceStore.ServiceRecord rec = table.getServiceRecord(URL,
1170Sstevel@tonic-gate 								hdr.locale);
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate 	// If the record is there, then get the scopes.
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 	if (rec != null) {
1220Sstevel@tonic-gate 	    hdr.scopes = (Vector)rec.getScopes().clone();
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 	} else {
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 	    SLPConfig config = SLPConfig.getSLPConfig();
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	    // We simply put in the useScopes, just to make the request.
1290Sstevel@tonic-gate 	    //  The request will be rejected when presented to ServiceTable.
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 	    hdr.scopes = (Vector)config.getSAConfiguredScopes().clone();
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	}
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	hdr.constructDescription("SrvDereg",
1360Sstevel@tonic-gate 				 "         URL=``" + URL + "''\n" +
1370Sstevel@tonic-gate 				 "         tags=``" + tags + "''\n");
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate     }
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate     // Return a SrvAck.
1420Sstevel@tonic-gate 
makeReply()1430Sstevel@tonic-gate     SrvLocMsg makeReply() {
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate 	SLPHeaderV1 hdr = ((SLPHeaderV1)getHeader()).makeReplyHeader();
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate 	// Construct description.
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	hdr.constructDescription("SrvAck", "");
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 	return hdr;
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate     }
1540Sstevel@tonic-gate }
155