xref: /onnv-gate/usr/src/lib/libslp/javalib/com/sun/slp/SAttrMsg.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 //  SAttrMsg.java:    Message class for SLP attribute request.
280Sstevel@tonic-gate //  Author:           James Kempf
290Sstevel@tonic-gate //  Created On:       Thu Oct  9 14:24:55 1997
300Sstevel@tonic-gate //  Last Modified By: James Kempf
310Sstevel@tonic-gate //  Last Modified On: Tue Oct 27 10:57:41 1998
320Sstevel@tonic-gate //  Update Count:     131
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 SAttrMsg class models the SLP server side attribute message.
430Sstevel@tonic-gate  * Subclasses for other versions can specialize the
440Sstevel@tonic-gate  * initialize() and makeReply() methods.
450Sstevel@tonic-gate  *
460Sstevel@tonic-gate  * @author James Kempf
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate 
490Sstevel@tonic-gate class SAttrMsg extends SrvLocMsgImpl {
500Sstevel@tonic-gate 
510Sstevel@tonic-gate     ServiceURL URL = null;      // nonNull if a URL query.
520Sstevel@tonic-gate     String serviceType = null;  // nonNull if a service type query.
530Sstevel@tonic-gate     Vector tags = new Vector(); // Vector of String tags.
540Sstevel@tonic-gate     String spi = "";	      // requested SPI
550Sstevel@tonic-gate 
SAttrMsg()560Sstevel@tonic-gate     protected SAttrMsg() {}
570Sstevel@tonic-gate 
580Sstevel@tonic-gate     // Construct a SAttrMsg from the input stream. This will
590Sstevel@tonic-gate     //  be an SLP attribute request.
600Sstevel@tonic-gate 
SAttrMsg(SrvLocHeader hdr, DataInputStream dis)610Sstevel@tonic-gate     SAttrMsg(SrvLocHeader hdr, DataInputStream dis)
620Sstevel@tonic-gate 	throws ServiceLocationException, IOException {
630Sstevel@tonic-gate 
640Sstevel@tonic-gate 	super(hdr, SrvLocHeader.AttrRqst);
650Sstevel@tonic-gate 
660Sstevel@tonic-gate 	this.initialize(dis);
670Sstevel@tonic-gate 
680Sstevel@tonic-gate     }
690Sstevel@tonic-gate 
700Sstevel@tonic-gate     // Initialize the message object.
710Sstevel@tonic-gate 
initialize(DataInputStream dis)720Sstevel@tonic-gate     void initialize(DataInputStream dis)
730Sstevel@tonic-gate 	throws ServiceLocationException, IOException {
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 	SLPServerHeaderV2 hdr = (SLPServerHeaderV2)getHeader();
760Sstevel@tonic-gate 	StringBuffer buf = new StringBuffer();
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	// Parse in the previous responder's list.
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	hdr.parsePreviousRespondersIn(dis);
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 	// Parse in the URL or service type.
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	hdr.getString(buf, dis);
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 	String urlOrServiceType = buf.toString();
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	// Decide whether this is a service type or service URL
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	try {
910Sstevel@tonic-gate 	    URL = new ServiceURL(urlOrServiceType, ServiceURL.LIFETIME_NONE);
920Sstevel@tonic-gate 
930Sstevel@tonic-gate 	    serviceType = null;
940Sstevel@tonic-gate 
950Sstevel@tonic-gate 	} catch (IllegalArgumentException ex) {
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	    // Validate and remove IANA.
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	    ServiceType t = new ServiceType(urlOrServiceType);
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 	    serviceType = t.toString();
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	    URL = null;
1040Sstevel@tonic-gate 	}
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	// Parse in the scopes.
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 	hdr.parseScopesIn(dis);
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 	// Parse in the attribute tags.
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 	hdr.getString(buf, dis);
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 	tags = hdr.parseCommaSeparatedListIn(buf.toString(), true);
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate 	// Unescape tags.
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 	hdr.unescapeTags(tags);
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	// Get the SPI
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate 	hdr.getString(buf, dis);
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 	spi = buf.toString();
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 	// Construct the description.
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	hdr.constructDescription("AttrRqst",
1290Sstevel@tonic-gate 				 "         " +
1300Sstevel@tonic-gate 				 (URL != null ?
1310Sstevel@tonic-gate 					("URL=``" + URL):
1320Sstevel@tonic-gate 					("service type=``" + serviceType)) +
1330Sstevel@tonic-gate 				 "''\n" +
1340Sstevel@tonic-gate 				 "         tags=``" + tags + "''\n" +
1350Sstevel@tonic-gate 				 "         spi=``" + spi + "''\n");
1360Sstevel@tonic-gate     }
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate     // Construct an SAttrMsg payload for reply to client. This will
1390Sstevel@tonic-gate     //  be an AttrRply message.
1400Sstevel@tonic-gate 
makeReply(Vector attrs, Hashtable auth)1410Sstevel@tonic-gate     SrvLocMsg makeReply(Vector attrs, Hashtable auth)
1420Sstevel@tonic-gate 	throws ServiceLocationException {
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 	SLPServerHeaderV2 hdr =
1450Sstevel@tonic-gate 	    ((SLPServerHeaderV2)getHeader()).makeReplyHeader();
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate 	hdr.iNumReplies = attrs.size();
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	// Select AuthBlock with requested SPI
1500Sstevel@tonic-gate 	if (auth != null) {
1510Sstevel@tonic-gate 	    AuthBlock selectedAuth = AuthBlock.getEquivalentAuth(spi, auth);
1520Sstevel@tonic-gate 	    auth = null;
1530Sstevel@tonic-gate 	    if (selectedAuth != null) {
1540Sstevel@tonic-gate 		auth = new Hashtable();
1550Sstevel@tonic-gate 		auth.put(spi, selectedAuth);
1560Sstevel@tonic-gate 	    }
1570Sstevel@tonic-gate 	}
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 	ByteArrayOutputStream baos = new ByteArrayOutputStream();
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 	hdr.parseAttributeVectorOut(attrs, 0, (auth != null),
1620Sstevel@tonic-gate 				    auth, baos, true);
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	hdr.payload = baos.toByteArray();
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	// Construct description.
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate 	hdr.constructDescription("AttrRply",
1690Sstevel@tonic-gate 				 "        attributes=``" +
1700Sstevel@tonic-gate 				 attrs +
1710Sstevel@tonic-gate 				 "''\n" +
1720Sstevel@tonic-gate 				 "        auth block=" +
1730Sstevel@tonic-gate 				 AuthBlock.desc(auth) +
1740Sstevel@tonic-gate 				 "\n");
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate 	return hdr;
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate     }
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate }
181