xref: /onnv-gate/usr/src/lib/libslp/javalib/com/sun/slp/SLPV1SSrvReg.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 //  SLPV1SSrvReg.java:      Message class for SLP service registration request.
280Sstevel@tonic-gate //  Author:           James Kempf
290Sstevel@tonic-gate //  Created On:       Thu Oct  9 14:47:48 1997
300Sstevel@tonic-gate //  Last Modified By: James Kempf
310Sstevel@tonic-gate //  Last Modified On: Thu Mar 25 15:30:25 1999
320Sstevel@tonic-gate //  Update Count:     80
330Sstevel@tonic-gate //
340Sstevel@tonic-gate 
350Sstevel@tonic-gate package com.sun.slp;
360Sstevel@tonic-gate 
370Sstevel@tonic-gate import java.util.*;
380Sstevel@tonic-gate import java.io.*;
390Sstevel@tonic-gate 
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /**
420Sstevel@tonic-gate  * The SLPV1SSrvReg class models the server side SLPv1 service registration.
430Sstevel@tonic-gate  *
440Sstevel@tonic-gate  * @author James Kempf
450Sstevel@tonic-gate  */
460Sstevel@tonic-gate 
470Sstevel@tonic-gate class SLPV1SSrvReg extends SSrvReg {
480Sstevel@tonic-gate 
490Sstevel@tonic-gate     // For identifying scopes.
500Sstevel@tonic-gate 
510Sstevel@tonic-gate     static private final String SCOPE_ATTR_ID = "scope";
520Sstevel@tonic-gate 
530Sstevel@tonic-gate     // Construct a SLPV1SSrvReg from the input stream.
540Sstevel@tonic-gate 
SLPV1SSrvReg(SrvLocHeader hdr, DataInputStream dis)550Sstevel@tonic-gate     SLPV1SSrvReg(SrvLocHeader hdr, DataInputStream dis)
560Sstevel@tonic-gate 	throws ServiceLocationException, IOException {
570Sstevel@tonic-gate 
580Sstevel@tonic-gate 	super(hdr, dis);
590Sstevel@tonic-gate 
600Sstevel@tonic-gate     }
610Sstevel@tonic-gate 
620Sstevel@tonic-gate     // Initialzie the object from the stream.
630Sstevel@tonic-gate 
initialize(DataInputStream dis)640Sstevel@tonic-gate     void initialize(DataInputStream dis)
650Sstevel@tonic-gate 	throws ServiceLocationException, IOException {
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 	SLPHeaderV1 hdr = (SLPHeaderV1)getHeader();
680Sstevel@tonic-gate 	StringBuffer buf = new StringBuffer();
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	// Parse in the service URL
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 	Hashtable table = new Hashtable();
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 	URL =
750Sstevel@tonic-gate 	    hdr.parseServiceURLIn(dis,
760Sstevel@tonic-gate 				  true,
770Sstevel@tonic-gate 				ServiceLocationException.INVALID_REGISTRATION);
780Sstevel@tonic-gate 
790Sstevel@tonic-gate 	serviceType = URL.getServiceType().toString();
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 	// Parse in the attribute list.
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 	attrList = hdr.parseAttributeVectorIn(dis);
840Sstevel@tonic-gate 
850Sstevel@tonic-gate 	// Get the scopes. Note that if there's no scope, the request
860Sstevel@tonic-gate 	//  will automatically be rejected as SCOPE_NOT_SUPPORTED.
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	int i, n = attrList.size();
890Sstevel@tonic-gate 	Vector scopes = new Vector();
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
920Sstevel@tonic-gate 	    ServiceLocationAttribute attr =
930Sstevel@tonic-gate 		(ServiceLocationAttribute)attrList.elementAt(i);
940Sstevel@tonic-gate 	    String id = attr.getId().toLowerCase().trim();
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	    if (id.equals(SCOPE_ATTR_ID)) {
970Sstevel@tonic-gate 		Vector vals = attr.getValues();
980Sstevel@tonic-gate 		int j, m = vals.size();
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 		for (j = 0; j < m; j++) {
1010Sstevel@tonic-gate 		    Object o = vals.elementAt(j);
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 		    // Must be a string in v1!
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate 		    if (!(o instanceof String)) {
1060Sstevel@tonic-gate 			throw
1070Sstevel@tonic-gate 			    new ServiceLocationException(
1080Sstevel@tonic-gate 				ServiceLocationException.INVALID_REGISTRATION,
1090Sstevel@tonic-gate 				"v1_scope_format",
1100Sstevel@tonic-gate 				new Object[] {vals});
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 		    }
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 		    String scope = (String)o;
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate 		    hdr.validateScope(scope);
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 		    scopes.addElement(scope);
1190Sstevel@tonic-gate 		}
1200Sstevel@tonic-gate 	    }
1210Sstevel@tonic-gate 	}
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate 	// If the vector is empty, then add empty string as the scope name.
1240Sstevel@tonic-gate 	//  This will cause the service table to throw the registration
1250Sstevel@tonic-gate 	//  as scope not supported. If unscoped regs are supported, then
1260Sstevel@tonic-gate 	//  change to default scope.
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	if (scopes.size() <= 0) {
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 	    if (!SLPConfig.getSLPConfig().getAcceptSLPv1UnscopedRegs()) {
1310Sstevel@tonic-gate 		scopes.addElement("");
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	    } else {
1340Sstevel@tonic-gate 		scopes.addElement(Defaults.DEFAULT_SCOPE);
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 	    }
1370Sstevel@tonic-gate 	}
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate 	hdr.scopes = scopes;
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate 	// Check if the registration is fresh or not.
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate 	hdr.fresh = true;
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate 	// Perform lookup for existing.
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate 	ServiceStore.ServiceRecord rec =
1480Sstevel@tonic-gate 	    ServiceTable.getServiceTable().getServiceRecord(URL, hdr.locale);
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate 	if (rec != null) {
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate 	    // Check scopes.
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	    Vector recScopes = (Vector)rec.getScopes().clone();
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 	    DATable.filterScopes(recScopes, scopes, true);
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate 	    // If it is registered in the same scopes, then it is considered
1590Sstevel@tonic-gate 	    //  to be the same. Otherwise, it replaces.
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 	    if (recScopes.size() == 0) {
1620Sstevel@tonic-gate 		hdr.fresh = false;
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	    }
1650Sstevel@tonic-gate 	}
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate 	hdr.constructDescription("SrvReg",
1680Sstevel@tonic-gate 				 "       URL=``" + URL + "''\n" +
1690Sstevel@tonic-gate 				 "       attribute list=``" +
1700Sstevel@tonic-gate 				 attrList + "''\n");
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate     }
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate     // Return a SrvAck.
1750Sstevel@tonic-gate 
makeReply(boolean existing)1760Sstevel@tonic-gate     SrvLocMsg makeReply(boolean existing) {
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate 	SLPHeaderV1 hdr = ((SLPHeaderV1)getHeader()).makeReplyHeader();
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate 	hdr.fresh = existing;
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate 	// Construct description.
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate 	hdr.constructDescription("SrvAck", "");
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate 	return hdr;
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate     }
1890Sstevel@tonic-gate }
190