2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1999 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A *
2N/A */
2N/A
2N/A// SLPV1SAttrMsg.java: SLPv1 Attribute request for server.
2N/A// Author: James Kempf
2N/A// Created On: Fri Sep 11 13:23:28 1998
2N/A// Last Modified By: James Kempf
2N/A// Last Modified On: Tue Oct 27 10:57:39 1998
2N/A// Update Count: 19
2N/A//
2N/A
2N/A
2N/A
2N/Apackage com.sun.slp;
2N/A
2N/Aimport java.util.*;
2N/Aimport java.io.*;
2N/A
2N/A
2N/A/**
2N/A * The SLPV1SAttrMsg class models the SLP server side attribute message.
2N/A *
2N/A * @author James Kempf
2N/A */
2N/A
2N/Aclass SLPV1SAttrMsg extends SAttrMsg {
2N/A
2N/A // For creating null reply.
2N/A
2N/A SLPV1SAttrMsg() {}
2N/A
2N/A // Construct a SLPV1SAttrMsg from the byte input stream. This will
2N/A
2N/A SLPV1SAttrMsg(SrvLocHeader hdr, DataInputStream dis)
2N/A throws ServiceLocationException, IOException {
2N/A
2N/A super(hdr, dis);
2N/A
2N/A }
2N/A
2N/A // Construct an empty SLPV1SSrvMsg, for monolingual off.
2N/A
2N/A static SrvLocMsg makeEmptyReply(SLPHeaderV1 hdr)
2N/A throws ServiceLocationException {
2N/A
2N/A SLPV1SAttrMsg msg = new SLPV1SAttrMsg();
2N/A msg.hdr = hdr;
2N/A
2N/A msg.makeReply(new Vector(), null);
2N/A
2N/A return msg;
2N/A
2N/A }
2N/A
2N/A void initialize(DataInputStream dis)
2N/A throws ServiceLocationException, IOException {
2N/A
2N/A SLPHeaderV1 hdr = (SLPHeaderV1)getHeader();
2N/A StringBuffer buf = new StringBuffer();
2N/A
2N/A // Parse in the previous responder's list.
2N/A
2N/A hdr.parsePreviousRespondersIn(dis);
2N/A
2N/A // Parse in the URL or service type.
2N/A
2N/A hdr.getString(buf, dis);
2N/A
2N/A String urlOrServiceType = buf.toString().trim();
2N/A
2N/A // Decide whether this is a service type or service URL
2N/A
2N/A try {
2N/A
2N/A URL = new ServiceURLV1(urlOrServiceType,
2N/A ServiceURL.LIFETIME_DEFAULT);
2N/A
2N/A serviceType = null;
2N/A
2N/A } catch (IllegalArgumentException ex) {
2N/A
2N/A // Check to make sure service type is right.
2N/A
2N/A serviceType =
2N/A hdr.checkServiceType(urlOrServiceType.toLowerCase());
2N/A
2N/A URL = null;
2N/A }
2N/A
2N/A // Parse in the scope and validate it.
2N/A
2N/A hdr.getString(buf, dis);
2N/A
2N/A String scope = buf.toString().toLowerCase().trim();
2N/A
2N/A hdr.validateScope(scope);
2N/A
2N/A // Change unscoped to default.
2N/A
2N/A if (scope.length() <= 0) {
2N/A scope = Defaults.DEFAULT_SCOPE;
2N/A
2N/A }
2N/A
2N/A hdr.scopes = new Vector();
2N/A hdr.scopes.addElement(scope);
2N/A
2N/A // Parse in the attribute tags.
2N/A
2N/A hdr.getString(buf, dis);
2N/A
2N/A tags =
2N/A hdr.parseCommaSeparatedListIn(buf.toString().trim(), true);
2N/A
2N/A // Unescape tags.
2N/A
2N/A int i, n = tags.size();
2N/A
2N/A for (i = 0; i < n; i++) {
2N/A String tag = (String)tags.elementAt(i);
2N/A
2N/A // Check for starting and ending wildcards.
2N/A
2N/A boolean wildcardStart = false;
2N/A boolean wildcardEnd = false;
2N/A
2N/A if (tag.startsWith("*")) {
2N/A wildcardStart = true;
2N/A tag = tag.substring(1, tag.length());
2N/A }
2N/A
2N/A if (tag.endsWith("*")) {
2N/A wildcardEnd = true;
2N/A tag = tag.substring(0, tag.length()-1);
2N/A }
2N/A
2N/A tag =
2N/A ServiceLocationAttributeV1.unescapeAttributeString(tag,
2N/A hdr.charCode);
2N/A
2N/A if (wildcardStart) {
2N/A tag = "*" + tag;
2N/A }
2N/A
2N/A if (wildcardEnd) {
2N/A tag = tag + "*";
2N/A }
2N/A
2N/A tags.setElementAt(tag.trim(), i);
2N/A }
2N/A
2N/A hdr.constructDescription("AttrRqst",
2N/A " " +
2N/A (URL != null ? ("URL=``" + URL):
2N/A ("service type=``" + serviceType)) +
2N/A "''\n" +
2N/A " tags=``" + tags + "''");
2N/A }
2N/A
2N/A // Construct an SAttrMsg payload for reply to client.
2N/A
2N/A SrvLocMsg makeReply(Vector attrs, Hashtable auth)
2N/A throws ServiceLocationException {
2N/A
2N/A SLPHeaderV1 hdr = ((SLPHeaderV1)getHeader()).makeReplyHeader();
2N/A
2N/A // We need to check whether this is an AttrRqst by type and
2N/A // if the type was an abstract type. If so, we simply return
2N/A // an empty reply, but we print a message to the log so the problem
2N/A // can be fixed.
2N/A
2N/A if (serviceType != null) {
2N/A ServiceType type = new ServiceType(serviceType);
2N/A ServiceStore store = ServiceTable.getServiceTable().store;
2N/A Vector types = store.findServiceTypes(type.getNamingAuthority(),
2N/A this.hdr.scopes);
2N/A
2N/A int i, n = types.size();
2N/A
2N/A for (i = 0; i < n; i++) {
2N/A String stype = (String)types.elementAt(i);
2N/A ServiceType ttype = new ServiceType(stype);
2N/A
2N/A if (ttype.isAbstractType() &&
2N/A type.equals(ttype.getAbstractTypeName())) {
2N/A
2N/A // We are out of luck!
2N/A
2N/A SLPConfig config = SLPConfig.getSLPConfig();
2N/A
2N/A config.writeLog("v1_abstract_type_conflict",
2N/A new Object[] {serviceType,
2N/A ttype});
2N/A attrs.removeAllElements();
2N/A }
2N/A }
2N/A }
2N/A
2N/A hdr.iNumReplies = attrs.size();
2N/A
2N/A ByteArrayOutputStream baos = new ByteArrayOutputStream();
2N/A
2N/A hdr.parseAttributeVectorOut(attrs, baos); // attributes
2N/A
2N/A hdr.payload = baos.toByteArray();
2N/A
2N/A hdr.constructDescription("AttrRply",
2N/A " attributes=``" + attrs + "''\n");
2N/A
2N/A return hdr;
2N/A }
2N/A}