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 // SLPV1SAttrMsg.java: SLPv1 Attribute request for server. 32 // Author: James Kempf 33 // Created On: Fri Sep 11 13:23:28 1998 34 // Last Modified By: James Kempf 35 // Last Modified On: Tue Oct 27 10:57:39 1998 36 // Update Count: 19 37 // 38 39 40 41 package com.sun.slp; 42 43 import java.util.*; 44 import java.io.*; 45 46 47 /** 48 * The SLPV1SAttrMsg class models the SLP server side attribute message. 49 * 50 * @version %R%.%L% %D% 51 * @author James Kempf 52 */ 53 54 class SLPV1SAttrMsg extends SAttrMsg { 55 56 // For creating null reply. 57 58 SLPV1SAttrMsg() {} 59 60 // Construct a SLPV1SAttrMsg from the byte input stream. This will 61 62 SLPV1SAttrMsg(SrvLocHeader hdr, DataInputStream dis) 63 throws ServiceLocationException, IOException { 64 65 super(hdr, dis); 66 67 } 68 69 // Construct an empty SLPV1SSrvMsg, for monolingual off. 70 71 static SrvLocMsg makeEmptyReply(SLPHeaderV1 hdr) 72 throws ServiceLocationException { 73 74 SLPV1SAttrMsg msg = new SLPV1SAttrMsg(); 75 msg.hdr = hdr; 76 77 msg.makeReply(new Vector(), null); 78 79 return msg; 80 81 } 82 83 void initialize(DataInputStream dis) 84 throws ServiceLocationException, IOException { 85 86 SLPHeaderV1 hdr = (SLPHeaderV1)getHeader(); 87 StringBuffer buf = new StringBuffer(); 88 89 // Parse in the previous responder's list. 90 91 hdr.parsePreviousRespondersIn(dis); 92 93 // Parse in the URL or service type. 94 95 hdr.getString(buf, dis); 96 97 String urlOrServiceType = buf.toString().trim(); 98 99 // Decide whether this is a service type or service URL 100 101 try { 102 103 URL = new ServiceURLV1(urlOrServiceType, 104 ServiceURL.LIFETIME_DEFAULT); 105 106 serviceType = null; 107 108 } catch (IllegalArgumentException ex) { 109 110 // Check to make sure service type is right. 111 112 serviceType = 113 hdr.checkServiceType(urlOrServiceType.toLowerCase()); 114 115 URL = null; 116 } 117 118 // Parse in the scope and validate it. 119 120 hdr.getString(buf, dis); 121 122 String scope = buf.toString().toLowerCase().trim(); 123 124 hdr.validateScope(scope); 125 126 // Change unscoped to default. 127 128 if (scope.length() <= 0) { 129 scope = Defaults.DEFAULT_SCOPE; 130 131 } 132 133 hdr.scopes = new Vector(); 134 hdr.scopes.addElement(scope); 135 136 // Parse in the attribute tags. 137 138 hdr.getString(buf, dis); 139 140 tags = 141 hdr.parseCommaSeparatedListIn(buf.toString().trim(), true); 142 143 // Unescape tags. 144 145 int i, n = tags.size(); 146 147 for (i = 0; i < n; i++) { 148 String tag = (String)tags.elementAt(i); 149 150 // Check for starting and ending wildcards. 151 152 boolean wildcardStart = false; 153 boolean wildcardEnd = false; 154 155 if (tag.startsWith("*")) { 156 wildcardStart = true; 157 tag = tag.substring(1, tag.length()); 158 } 159 160 if (tag.endsWith("*")) { 161 wildcardEnd = true; 162 tag = tag.substring(0, tag.length()-1); 163 } 164 165 tag = 166 ServiceLocationAttributeV1.unescapeAttributeString(tag, 167 hdr.charCode); 168 169 if (wildcardStart) { 170 tag = "*" + tag; 171 } 172 173 if (wildcardEnd) { 174 tag = tag + "*"; 175 } 176 177 tags.setElementAt(tag.trim(), i); 178 } 179 180 hdr.constructDescription("AttrRqst", 181 " " + 182 (URL != null ? ("URL=``" + URL): 183 ("service type=``" + serviceType)) + 184 "''\n" + 185 " tags=``" + tags + "''"); 186 } 187 188 // Construct an SAttrMsg payload for reply to client. 189 190 SrvLocMsg makeReply(Vector attrs, Hashtable auth) 191 throws ServiceLocationException { 192 193 SLPHeaderV1 hdr = ((SLPHeaderV1)getHeader()).makeReplyHeader(); 194 195 // We need to check whether this is an AttrRqst by type and 196 // if the type was an abstract type. If so, we simply return 197 // an empty reply, but we print a message to the log so the problem 198 // can be fixed. 199 200 if (serviceType != null) { 201 ServiceType type = new ServiceType(serviceType); 202 ServiceStore store = ServiceTable.getServiceTable().store; 203 Vector types = store.findServiceTypes(type.getNamingAuthority(), 204 this.hdr.scopes); 205 206 int i, n = types.size(); 207 208 for (i = 0; i < n; i++) { 209 String stype = (String)types.elementAt(i); 210 ServiceType ttype = new ServiceType(stype); 211 212 if (ttype.isAbstractType() && 213 type.equals(ttype.getAbstractTypeName())) { 214 215 // We are out of luck! 216 217 SLPConfig config = SLPConfig.getSLPConfig(); 218 219 config.writeLog("v1_abstract_type_conflict", 220 new Object[] {serviceType, 221 ttype}); 222 attrs.removeAllElements(); 223 } 224 } 225 } 226 227 hdr.iNumReplies = attrs.size(); 228 229 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 230 231 hdr.parseAttributeVectorOut(attrs, baos); // attributes 232 233 hdr.payload = baos.toByteArray(); 234 235 hdr.constructDescription("AttrRply", 236 " attributes=``" + attrs + "''\n"); 237 238 return hdr; 239 } 240 } 241