1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
// SLPServerHeaderV2.java: SLPv2 Header Class for Server Side
// Author: James Kempf
// Created On: Wed Sep 16 08:44:31 1998
// Last Modified By: James Kempf
// Last Modified On: Mon Jan 4 15:26:33 1999
// Update Count: 30
//
package com.sun.slp;
import java.util.*;
import java.net.*;
import java.io.*;
import java.security.*;
/**
* The SLPServerHeaderV2 class serves as the header class for all server side
* SLPv2 messages.
*
* @author James Kempf
*/
class SLPServerHeaderV2 extends SLPHeaderV2 implements Cloneable {
// Function code for message reply.
int replyFunctionCode = SrvLocHeader.SrvAck;
// For SrvLocHeader.newInstance().
SLPServerHeaderV2() {
super();
}
// Construct a header for output. Used by the client side code to
// construct an initial request and the server side code to construct
// a reply.
SLPServerHeaderV2(int functionCode, boolean fresh, Locale locale)
throws ServiceLocationException {
super(functionCode, fresh, locale);
}
// Assign reply code based on function code type, then use superclass
// method to parse header.
void parseHeader(int functionCode, DataInputStream dis)
throws ServiceLocationException, IOException {
// We ignore the error case here.
switch (functionCode) {
case SrvLocHeader.SrvReq:
replyFunctionCode = SrvLocHeader.SrvRply;
break;
case SrvLocHeader.AttrRqst:
replyFunctionCode = SrvLocHeader.AttrRply;
break;
case SrvLocHeader.SrvTypeRqst:
replyFunctionCode = SrvLocHeader.SrvTypeRply;
break;
case SrvLocHeader.SrvReg: case SrvLocHeader.SrvDereg:
replyFunctionCode = SrvLocHeader.SrvAck;
break;
// If we get an error during creating of the DAAdvert to
// reply, we need to continue and reply with DAAdvert.
// This is only true for a unicast DAAdvert, though.
case SrvLocHeader.DAAdvert:
replyFunctionCode = SrvLocHeader.DAAdvert;
break;
// We ignore the header error code for SAAdvert because
// it is always multicast.
}
// We are now set up to handle any errors that may come flying out
// of here.
super.parseHeader(functionCode, dis);
}
// Replace the superclass method with a method that parses the server
// side.
SrvLocMsg parseMsg(DataInputStream dis)
throws ServiceLocationException,
IOException,
IllegalArgumentException {
SrvLocMsg msg = null;
// DAAdvert needs to get it's error code parsed here because
// error codes are always handled in parseMsg() and it is
// the only server side message that has one.
if (functionCode == SrvLocHeader.DAAdvert) {
errCode = (short)getInt(dis);
}
// Switch and convert according to function code.
switch (functionCode) {
case SrvLocHeader.SrvReg:
msg = new SSrvReg(this, dis);
break;
case SrvLocHeader.SrvDereg:
msg = new SSrvDereg(this, dis);
break;
case SrvLocHeader.SrvReq:
msg = new SSrvMsg(this, dis);
break;
case SrvLocHeader.AttrRqst:
msg = new SAttrMsg(this, dis);
break;
case SrvLocHeader.SrvAck:
// We function as our own message.
msg = this;
iNumReplies = 1;
break;
case SrvLocHeader.SrvTypeRqst:
msg = new SSrvTypeMsg(this, dis);
break;
case SrvLocHeader.DAAdvert:
msg = new CDAAdvert(this, dis);
break;
case SrvLocHeader.SAAdvert:
msg = new CSAAdvert(this, dis);
break;
default:
throw
new ServiceLocationException(
ServiceLocationException.PARSE_ERROR,
"function_code_error",
new Object[] {
new Integer(functionCode)});
}
// Check for size overflow.
if (nbytes > length) {
throw
new ServiceLocationException(
ServiceLocationException.PARSE_ERROR,
"length_overflow",
new Object[] {
new Integer(nbytes), new Integer(length)});
}
return msg;
}
// Create an error reply using the reply code. Calculate the
// error code using the exception.
SrvLocMsg makeErrorReply(Exception ex) {
SrvLocHeader hdr = null;
// Clone the header to make sure that everything else is the same.
// We don't want to use the same header because it may be tested
// elsewhere.
try {
hdr = (SrvLocHeader)this.clone();
} catch (CloneNotSupportedException exx) {
// We support it, so no-op.
}
// Re-initialize flags but not multicast, since we need to filter on it
hdr.fresh = false;
hdr.overflow = false;
hdr.functionCode = replyFunctionCode;
// We should *not* be getting a null exception down this path!
Assert.slpassert(ex != null,
"null_parameter",
new Object[] {ex});
if (ex instanceof ServiceLocationException) {
hdr.errCode = ((ServiceLocationException)ex).getErrorCode();
if (!ServiceLocationException.validWireErrorCode(hdr.errCode)) {
hdr.errCode = ServiceLocationException.INTERNAL_ERROR;
}
} else if (ex instanceof IllegalArgumentException ||
ex instanceof IOException) {
hdr.errCode = ServiceLocationException.PARSE_ERROR;
} else {
hdr.errCode = ServiceLocationException.INTERNAL_ERROR;
}
// Construct header description.
constructDescription("SrvLocMsg", "");
return hdr;
}
// Return a reply header with flags properly set.
SLPServerHeaderV2 makeReplyHeader() {
SLPServerHeaderV2 hdr = null;
try {
hdr = (SLPServerHeaderV2)this.clone();
} catch (CloneNotSupportedException ex) {
// No-op, since we support it.
}
hdr.functionCode = replyFunctionCode;
hdr.length = 0;
hdr.previousResponders = null;
hdr.scopes = null;
hdr.overflow = false;
hdr.fresh = false;
hdr.mcast = false;
hdr.nbytes = 0;
return hdr;
}
// Return display string.
public String toString() {
return
getMsgType() + ":version=``" + version + "''\n" +
" functionCode=``" + functionCode + "''\n" +
" length=``" + length + "''" + "''\n" +
" overflow=``" + overflow + "''\n" +
" mcast = ``" + mcast + "''\n" +
" fresh=``" + fresh + "''\n" +
" locale = ``" + locale + "''\n" +
" xid=``0x" + Integer.toHexString(xid) + "''\n" +
" errCode=``" + errCode + "''\n" +
" previousResponders=``" + previousResponders + "''\n" +
" scopes=``" + scopes + "''\n" +
getMsgDescription();
}
//
// Parsing Utilities.
//
// Parse in the scope list.
void parseScopesIn(DataInputStream dis)
throws ServiceLocationException, IOException {
StringBuffer buf = new StringBuffer();
getString(buf, dis);
scopes = parseCommaSeparatedListIn(buf.toString(), true);
// Unescape scope strings.
unescapeScopeStrings(scopes);
// Validate.
DATable.validateScopes(scopes, locale);
}
void parsePreviousRespondersIn(DataInputStream dis)
throws ServiceLocationException, IOException {
StringBuffer buf = new StringBuffer();
getString(buf, dis);
previousResponders =
parseCommaSeparatedListIn(buf.toString(), true);
}
// Return an SLPv2 DAAdvert.
SDAAdvert
getDAAdvert(short xid,
long timestamp,
ServiceURL url,
Vector scopes,
Vector attrs)
throws ServiceLocationException {
// If scopes vector is null, then return all scopes for this
// DA.
if (scopes.size() <= 0) {
scopes = SLPConfig.getSLPConfig().getSAConfiguredScopes();
}
return new SDAAdvert(this, xid, timestamp, url, scopes, attrs);
}
}
|