xref: /illumos-gate/usr/src/lib/libslp/javalib/com/sun/slp/CAttrMsg.java (revision 55fea89dcaa64928bed4327112404dcb3e07b79f)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 1999 by Sun Microsystems, Inc.
23  * All rights reserved.
24  *
25  */
26 
27 //  CAttrMsg.java: Message class for SLP attribute
28 //                 reply.
29 //  Author: James Kempf Created On: Thu Oct 9 15:17:36 1997
30 //  Last Modified By: James Kempf
31 //  Last Modified On: Tue Oct 27 10:57:38 1998
32 //  Update Count: 107
33 //
34 
35 package com.sun.slp;
36 
37 import java.util.*;
38 import java.io.*;
39 
40 
41 /**
42  * The CAttrMsg class models the SLP client side attribute message.
43  *
44  * @author James Kempf
45  */
46 
47 class CAttrMsg extends SrvLocMsgImpl {
48 
49     // Vector of ServiceLocationAttribute objects
50     Vector attrList = new Vector();
51     Hashtable attrAuthBlock = null;  // auth block list for objects
52 
53     // Only used for testing.
54 
CAttrMsg()55     protected CAttrMsg() { }
56 
57     // Construct a CAttrMsg from the byte input stream.
58 
CAttrMsg(SLPHeaderV2 hdr, DataInputStream dis)59     CAttrMsg(SLPHeaderV2 hdr, DataInputStream dis)
60 	throws ServiceLocationException, IOException {
61 
62 	super(hdr, SrvLocHeader.AttrRply);
63 
64 	// Don't parse the rest if there's an error.
65 
66 	if (hdr.errCode != ServiceLocationException.OK) {
67 	    return;
68 
69 	}
70 
71 	// Ignore if overflow.
72 
73 	if (hdr.overflow) {
74 	    return;
75 
76 	}
77 
78 	// Parse in the potentially authenticated attribute list.
79 
80 	attrAuthBlock =
81 	    hdr.parseAuthenticatedAttributeVectorIn(attrList, dis, true);
82 
83 	// Verify authentication, if necessary.
84 
85 	if (attrAuthBlock != null) {
86 	    AuthBlock.verifyAll(attrAuthBlock);
87 	}
88 
89 	// Set the number of replies.
90 
91 	hdr.iNumReplies = attrList.size();
92 
93     }
94 
95     // Construct a CAttrMsg payload from the arguments. This will be
96     //   an AttrRqst message.
97 
CAttrMsg(Locale locale, ServiceURL url, Vector scopes, Vector tags)98     CAttrMsg(Locale locale, ServiceURL url, Vector scopes, Vector tags)
99 	throws ServiceLocationException {
100 
101 	this.hdr = new SLPHeaderV2(SrvLocHeader.AttrRqst, false, locale);
102 
103 	constructPayload(url.toString(), scopes, tags);
104 
105     }
106 
107     // Construct a CAttrMsg payload from the arguments. This will be
108     //   an AttrRqst message.
109 
CAttrMsg(Locale locale, ServiceType type, Vector scopes, Vector tags)110     CAttrMsg(Locale locale, ServiceType type, Vector scopes, Vector tags)
111 	throws ServiceLocationException {
112 
113 	this.hdr = new SLPHeaderV2(SrvLocHeader.AttrRqst, false, locale);
114 
115 	constructPayload(type.toString(), scopes, tags);
116 
117     }
118 
119     // Convert the message into bytes for the payload buffer.
120 
constructPayload(String typeOrURL, Vector scopes, Vector tags)121     protected void constructPayload(String typeOrURL,
122 				    Vector scopes,
123 				    Vector tags)
124 	throws ServiceLocationException {
125 
126 	SLPHeaderV2 hdr = (SLPHeaderV2)this.hdr;
127 	hdr.scopes = (Vector)scopes.clone();
128 
129 	// Set up previous responders.
130 
131 	hdr.previousResponders = new Vector();
132 
133 	ByteArrayOutputStream baos = new ByteArrayOutputStream();
134 
135 	// Write out the service type or URL.
136 
137 	hdr.putString(typeOrURL, baos);
138 
139 	// Escape scope strings for transmission.
140 
141 	hdr.escapeScopeStrings(scopes);
142 
143 	// Parse out the scopes.
144 
145 	hdr.parseCommaSeparatedListOut(scopes, baos);
146 
147 	// Escape tags going out.
148 
149 	hdr.escapeTags(tags);
150 
151 	// Parse out the tags
152 
153 	hdr.parseCommaSeparatedListOut(tags, baos);
154 
155 	// Retrieve the configured SPI, if any
156 	String spi = "";
157 	if (SLPConfig.getSLPConfig().getHasSecurity()) {
158 	    LinkedList spiList = AuthBlock.getSPIList("sun.net.slp.SPIs");
159 	    if (spiList != null && !spiList.isEmpty()) {
160 		// There can be only one configured SPI for UAs
161 		spi = (String) spiList.getFirst();
162 	    }
163 	}
164 
165 	hdr.putString(spi, baos);
166 
167 	// Set payload.
168 
169 	hdr.payload = baos.toByteArray();
170     }
171 
172 }
173