xref: /illumos-gate/usr/src/lib/libslp/javalib/com/sun/slp/CSAAdvert.java (revision e7cbe64f7a72dae5cb44f100db60ca88f3313c65)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * ident	"%Z%%M%	%I%	%E% SMI"
24  *
25  * Copyright (c) 1999 by Sun Microsystems, Inc.
26  * All rights reserved.
27  *
28  */
29 
30 //  SCCS Status:      %W%	%G%
31 //  CSAAdvert.java:    Message class for SLP CSAAdvert message
32 //  Author:           James Kempf
33 //  Created On:       Fri Oct 10 10:48:05 1997
34 //  Last Modified By: James Kempf
35 //  Last Modified On: Tue Oct 27 10:57:41 1998
36 //  Update Count:     95
37 //
38 
39 package com.sun.slp;
40 
41 import java.util.*;
42 import java.io.*;
43 
44 
45 /**
46  * The CSAAdvert class models the SLP SAAdvert message, client side.
47  *
48  * @version %R%.%L% %D%
49  * @author James Kempf
50  */
51 
52 
53 class CSAAdvert extends SrvLocMsgImpl {
54 
55     ServiceURL URL = null;	// The DA's service URL
56     Hashtable authBlock = null;	// Scope auth blocks.
57     Vector attrs = new Vector(); // The attributes.
58 
59     // Construct a CSAAdvert from the input stream.
60 
61     CSAAdvert(SLPHeaderV2 hdr, DataInputStream dis)
62 	throws ServiceLocationException, IOException {
63 	super(hdr, SrvLocHeader.SAAdvert);
64 
65 	// Parse in SA's service URL.
66 
67 	StringBuffer buf = new StringBuffer();
68 
69 	byte[] urlBytes = hdr.getString(buf, dis);
70 
71 	try {
72 
73 	    URL = new ServiceURL(buf.toString(), ServiceURL.LIFETIME_NONE);
74 
75 	} catch (IllegalArgumentException ex) {
76 
77 	    throw
78 		new ServiceLocationException(
79 				ServiceLocationException.PARSE_ERROR,
80 				"malformed_url",
81 				new Object[] {ex.getMessage()});
82 
83 	}
84 
85 	// Validate the service URL.
86 
87 	ServiceType serviceType = URL.getServiceType();
88 
89 	if (!serviceType.equals(Defaults.SA_SERVICE_TYPE)) {
90 	    throw
91 		new ServiceLocationException(
92 				ServiceLocationException.PARSE_ERROR,
93 				"not_right_url",
94 				new Object[] {URL, "SA"});
95 
96 	}
97 
98 	// Parse in the scope list.
99 
100 	byte[] scopeBytes = hdr.getString(buf, dis);
101 
102 	hdr.scopes =
103 	    hdr.parseCommaSeparatedListIn(buf.toString(), true);
104 
105 	// Unescape scopes.
106 
107 	hdr.unescapeScopeStrings(hdr.scopes);
108 
109 	// Validate scope list.
110 
111 	DATable.validateScopes(hdr.scopes, hdr.locale);
112 
113 	// Parse in attributes.
114 
115 	byte attrBytes[] = hdr.parseAttributeVectorIn(attrs, dis, false);
116 
117 	// Construct bytes for auth.
118 
119 	Object[] message = new Object[6];
120 
121 	// None of the strings have leading length fields, so add them here
122 	ByteArrayOutputStream abaos = new ByteArrayOutputStream();
123 	hdr.putInteger(urlBytes.length, abaos);
124 	message[0] = abaos.toByteArray();
125 	message[1] = urlBytes;
126 
127 	abaos = new ByteArrayOutputStream();
128 	hdr.putInteger(attrBytes.length, abaos);
129 	message[2] = abaos.toByteArray();
130 	message[3] = attrBytes;
131 
132 	abaos = new ByteArrayOutputStream();
133 	hdr.putInteger(scopeBytes.length, abaos);
134 	message[4] = abaos.toByteArray();
135 	message[5] = scopeBytes;
136 
137 	// Parse in an auth block if there.
138 
139 	authBlock = hdr.parseSignatureIn(message, dis);
140 
141 	// Set number of replies.
142 
143 	hdr.iNumReplies = 1;
144 
145     }
146 }
147