xref: /illumos-gate/usr/src/lib/libslp/javalib/com/sun/slp/CSAAdvert.java (revision e4d060fb4c00d44cd578713eb9a921f594b733b8)
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 //  CSAAdvert.java:    Message class for SLP CSAAdvert message
28 //  Author:           James Kempf
29 //  Created On:       Fri Oct 10 10:48:05 1997
30 //  Last Modified By: James Kempf
31 //  Last Modified On: Tue Oct 27 10:57:41 1998
32 //  Update Count:     95
33 //
34 
35 package com.sun.slp;
36 
37 import java.util.*;
38 import java.io.*;
39 
40 
41 /**
42  * The CSAAdvert class models the SLP SAAdvert message, client side.
43  *
44  * @author James Kempf
45  */
46 
47 
48 class CSAAdvert extends SrvLocMsgImpl {
49 
50     ServiceURL URL = null;	// The DA's service URL
51     Hashtable authBlock = null;	// Scope auth blocks.
52     Vector attrs = new Vector(); // The attributes.
53 
54     // Construct a CSAAdvert from the input stream.
55 
56     CSAAdvert(SLPHeaderV2 hdr, DataInputStream dis)
57 	throws ServiceLocationException, IOException {
58 	super(hdr, SrvLocHeader.SAAdvert);
59 
60 	// Parse in SA's service URL.
61 
62 	StringBuffer buf = new StringBuffer();
63 
64 	byte[] urlBytes = hdr.getString(buf, dis);
65 
66 	try {
67 
68 	    URL = new ServiceURL(buf.toString(), ServiceURL.LIFETIME_NONE);
69 
70 	} catch (IllegalArgumentException ex) {
71 
72 	    throw
73 		new ServiceLocationException(
74 				ServiceLocationException.PARSE_ERROR,
75 				"malformed_url",
76 				new Object[] {ex.getMessage()});
77 
78 	}
79 
80 	// Validate the service URL.
81 
82 	ServiceType serviceType = URL.getServiceType();
83 
84 	if (!serviceType.equals(Defaults.SA_SERVICE_TYPE)) {
85 	    throw
86 		new ServiceLocationException(
87 				ServiceLocationException.PARSE_ERROR,
88 				"not_right_url",
89 				new Object[] {URL, "SA"});
90 
91 	}
92 
93 	// Parse in the scope list.
94 
95 	byte[] scopeBytes = hdr.getString(buf, dis);
96 
97 	hdr.scopes =
98 	    hdr.parseCommaSeparatedListIn(buf.toString(), true);
99 
100 	// Unescape scopes.
101 
102 	hdr.unescapeScopeStrings(hdr.scopes);
103 
104 	// Validate scope list.
105 
106 	DATable.validateScopes(hdr.scopes, hdr.locale);
107 
108 	// Parse in attributes.
109 
110 	byte attrBytes[] = hdr.parseAttributeVectorIn(attrs, dis, false);
111 
112 	// Construct bytes for auth.
113 
114 	Object[] message = new Object[6];
115 
116 	// None of the strings have leading length fields, so add them here
117 	ByteArrayOutputStream abaos = new ByteArrayOutputStream();
118 	hdr.putInteger(urlBytes.length, abaos);
119 	message[0] = abaos.toByteArray();
120 	message[1] = urlBytes;
121 
122 	abaos = new ByteArrayOutputStream();
123 	hdr.putInteger(attrBytes.length, abaos);
124 	message[2] = abaos.toByteArray();
125 	message[3] = attrBytes;
126 
127 	abaos = new ByteArrayOutputStream();
128 	hdr.putInteger(scopeBytes.length, abaos);
129 	message[4] = abaos.toByteArray();
130 	message[5] = scopeBytes;
131 
132 	// Parse in an auth block if there.
133 
134 	authBlock = hdr.parseSignatureIn(message, dis);
135 
136 	// Set number of replies.
137 
138 	hdr.iNumReplies = 1;
139 
140     }
141 }
142