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) 2001 by Sun Microsystems, Inc. 26 * All rights reserved. 27 * 28 */ 29 30 // SCCS Status: %W% %G% 31 // SSAAdvert.java: Server Side SAAdvert Message. 32 // Author: James Kempf 33 // Created On: Tue Feb 10 15:00:39 1998 34 // Last Modified By: James Kempf 35 // Last Modified On: Tue Oct 27 10:57:38 1998 36 // Update Count: 60 37 // 38 39 package com.sun.slp; 40 41 import java.util.*; 42 import java.io.*; 43 44 45 /** 46 * The SSAAdvert class models the SLP SAAdvert message. 47 * 48 * @version 1.4 97/11/20 49 * @author James Kempf 50 */ 51 52 class SSAAdvert extends SrvLocMsgImpl { 53 54 // Construct a SAAdvert from the arguments. This is a server side 55 // for transmission to the client. 56 57 SSAAdvert(int version, 58 short xid, 59 Locale locale, 60 ServiceURL url, 61 Vector scopes, 62 Vector attrs) 63 throws ServiceLocationException { 64 65 // Construct header. 66 67 hdr = new SLPServerHeaderV2(); 68 69 Assert.slpassert(hdr != null, 70 "version_number_error", 71 new Object[] {new Integer(version)}); 72 73 hdr.functionCode = SrvLocHeader.SAAdvert; 74 hdr.xid = xid; 75 hdr.locale = locale; 76 77 this.initialize(url, scopes, attrs); 78 } 79 80 // Initialize the message. 81 82 void initialize(ServiceURL url, Vector scopes, Vector attrs) 83 throws ServiceLocationException { 84 85 SLPServerHeaderV2 hdr = (SLPServerHeaderV2)getHeader(); 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 "ssaadv_nonsaurl", 94 new Object[] {serviceType}); 95 96 } 97 98 // Validate scope list. 99 100 DATable.validateScopes(scopes, hdr.locale); 101 hdr.scopes = (Vector)scopes.clone(); 102 103 // Escape scope strings. 104 105 hdr.escapeScopeStrings(scopes); 106 107 // Parse out the payload. 108 109 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 110 111 String surl = url.toString(); 112 113 // Parse out the URL. 114 115 byte[] urlBytes = hdr.putString(surl, baos); 116 117 // Parse out the scope list. We need to save the bytes for 118 // the authblock. 119 120 byte[] scopeBytes = 121 hdr.parseCommaSeparatedListOut(scopes, baos); 122 123 // Parse out the attribute list. 124 125 byte[] attrBytes = hdr.parseAttributeVectorOut(attrs, 126 url.getLifetime(), 127 false, 128 null, 129 baos, 130 false); 131 132 // Parse out auth blocks, if necessary. 133 134 Hashtable auth = null; 135 byte nBlocks = 0; 136 137 if (SLPConfig.getSLPConfig().getHasSecurity()) { 138 Object[] message = new Object[6]; 139 140 // None of the strings have leading length fields, so add them here 141 ByteArrayOutputStream abaos = new ByteArrayOutputStream(); 142 hdr.putInteger(urlBytes.length, abaos); 143 message[0] = abaos.toByteArray(); 144 message[1] = urlBytes; 145 146 abaos = new ByteArrayOutputStream(); 147 hdr.putInteger(attrBytes.length, abaos); 148 message[2] = abaos.toByteArray(); 149 message[3] = attrBytes; 150 151 abaos = new ByteArrayOutputStream(); 152 hdr.putInteger(scopeBytes.length, abaos); 153 message[4] = abaos.toByteArray(); 154 message[5] = scopeBytes; 155 156 auth = hdr.getCheckedAuthBlockList(message, 157 url.getLifetime()); 158 nBlocks = (byte) auth.size(); 159 160 } 161 162 // Parse out number of blocks. 163 164 baos.write(nBlocks); 165 hdr.nbytes++; 166 167 // Parse out blocks, if any. 168 169 if (auth != null) { 170 AuthBlock.externalizeAll(hdr, auth, baos); 171 172 } 173 174 // Save bytes. 175 176 hdr.payload = baos.toByteArray(); 177 178 // Construct description of outgoing packet for logging. 179 180 hdr.constructDescription("SAAdvert", 181 " URL=``" + url + "''\n" + 182 " attrs=``" + attrs + "''\n" + 183 " auth block="+AuthBlock.desc(auth) + 184 "\n"); 185 186 } 187 } 188