xref: /onnv-gate/usr/src/lib/libslp/javalib/com/sun/slp/SSrvReg.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, 2001 by Sun Microsystems, Inc.
230Sstevel@tonic-gate  * All rights reserved.
240Sstevel@tonic-gate  *
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate //  SSrvReg.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: Jason Goldschmidt
310Sstevel@tonic-gate //  Last Modified On: Thu Apr  5 14:46:29 2001
320Sstevel@tonic-gate //  Update Count:     107
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 SSrvReg class models the server side SLP service registration. The
430Sstevel@tonic-gate  * default class does SLPv2 regs, but subclasses can do other versions
440Sstevel@tonic-gate  * by redefining the initialize() and makeReply() messages.
450Sstevel@tonic-gate  *
460Sstevel@tonic-gate  * @author James Kempf
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate 
490Sstevel@tonic-gate class SSrvReg extends SrvLocMsgImpl {
500Sstevel@tonic-gate 
510Sstevel@tonic-gate     ServiceURL URL = null;	         // the service URL.
520Sstevel@tonic-gate     String serviceType = "";	         // service type.
530Sstevel@tonic-gate     Vector attrList = new Vector();        // ServiceLocationAttribute objects.
540Sstevel@tonic-gate     Hashtable URLSignature = null;  // signature for URL.
550Sstevel@tonic-gate     Hashtable attrSignature = null; // the signatures for the attributes.
560Sstevel@tonic-gate 
570Sstevel@tonic-gate     // Construct a SSrvReg from the input stream.
580Sstevel@tonic-gate 
SSrvReg(SrvLocHeader hdr, DataInputStream dis)590Sstevel@tonic-gate     SSrvReg(SrvLocHeader hdr, DataInputStream dis)
600Sstevel@tonic-gate 	throws ServiceLocationException, IOException {
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 	super(hdr, SrvLocHeader.SrvReg);
630Sstevel@tonic-gate 
640Sstevel@tonic-gate 	this.initialize(dis);
650Sstevel@tonic-gate 
660Sstevel@tonic-gate     }
670Sstevel@tonic-gate 
680Sstevel@tonic-gate     // Initialize the object from the input stream.
690Sstevel@tonic-gate 
initialize(DataInputStream dis)700Sstevel@tonic-gate     void initialize(DataInputStream dis)
710Sstevel@tonic-gate 	throws ServiceLocationException, IOException {
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 	SLPServerHeaderV2 hdr = (SLPServerHeaderV2)getHeader();
740Sstevel@tonic-gate 	StringBuffer buf = new StringBuffer();
750Sstevel@tonic-gate 
760Sstevel@tonic-gate 	// Parse in the service URL
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	Hashtable table = new Hashtable();
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	URL =
810Sstevel@tonic-gate 	    hdr.parseServiceURLIn(dis,
820Sstevel@tonic-gate 				  table,
830Sstevel@tonic-gate 				ServiceLocationException.INVALID_REGISTRATION);
840Sstevel@tonic-gate 
850Sstevel@tonic-gate 	URLSignature = (Hashtable)table.get(URL);
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	// Parse in service type name.
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 	hdr.getString(buf, dis);
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 	// Validate and set URL type.
920Sstevel@tonic-gate 
930Sstevel@tonic-gate 	ServiceType t = new ServiceType(buf.toString());
940Sstevel@tonic-gate 
950Sstevel@tonic-gate 	if (!(URL.getServiceType()).isServiceURL() &&
960Sstevel@tonic-gate 	    !t.equals(URL.getServiceType())) {
970Sstevel@tonic-gate 	    URL.setServiceType(t);
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	}
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 	// Parse in the scope list.
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	hdr.parseScopesIn(dis);
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate 	// Parse in the attribute list.
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 	attrSignature =
1080Sstevel@tonic-gate 	    hdr.parseAuthenticatedAttributeVectorIn(attrList, dis, false);
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 	hdr.constructDescription("SrvReg",
1110Sstevel@tonic-gate 				 "       URL=``" +
1120Sstevel@tonic-gate 				 URL + "''\n" +
1130Sstevel@tonic-gate 				 "       service type=``" +
1140Sstevel@tonic-gate 				 serviceType + "''\n" +
1150Sstevel@tonic-gate 				 "       attribute list=``" +
1160Sstevel@tonic-gate 				 attrList + "''\n" +
1170Sstevel@tonic-gate 				 "       URL signature=" +
1180Sstevel@tonic-gate 				 AuthBlock.desc(URLSignature) + "\n" +
1190Sstevel@tonic-gate 				 "       attribute signature=" +
1200Sstevel@tonic-gate 				 AuthBlock.desc(attrSignature) + "\n");
1210Sstevel@tonic-gate     }
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate     // Return a SrvAck. We ignore the existing flag, since in V2, fresh comes
1240Sstevel@tonic-gate     //  in. In this case, all we need to do is clone the header.
1250Sstevel@tonic-gate 
makeReply(boolean existing)1260Sstevel@tonic-gate     SrvLocMsg makeReply(boolean existing) {
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	SLPServerHeaderV2 hdr =
1290Sstevel@tonic-gate 	    ((SLPServerHeaderV2)getHeader()).makeReplyHeader();
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 	// Construct description.
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	hdr.constructDescription("SrvAck", "");
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	return hdr;
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate     }
1380Sstevel@tonic-gate }
139