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) 2001 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A *
2N/A */
2N/A
2N/A// SSAAdvert.java: Server Side SAAdvert Message.
2N/A// Author: James Kempf
2N/A// Created On: Tue Feb 10 15:00:39 1998
2N/A// Last Modified By: James Kempf
2N/A// Last Modified On: Tue Oct 27 10:57:38 1998
2N/A// Update Count: 60
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 SSAAdvert class models the SLP SAAdvert message.
2N/A *
2N/A * @author James Kempf
2N/A */
2N/A
2N/Aclass SSAAdvert extends SrvLocMsgImpl {
2N/A
2N/A // Construct a SAAdvert from the arguments. This is a server side
2N/A // for transmission to the client.
2N/A
2N/A SSAAdvert(int version,
2N/A short xid,
2N/A Locale locale,
2N/A ServiceURL url,
2N/A Vector scopes,
2N/A Vector attrs)
2N/A throws ServiceLocationException {
2N/A
2N/A // Construct header.
2N/A
2N/A hdr = new SLPServerHeaderV2();
2N/A
2N/A Assert.slpassert(hdr != null,
2N/A "version_number_error",
2N/A new Object[] {new Integer(version)});
2N/A
2N/A hdr.functionCode = SrvLocHeader.SAAdvert;
2N/A hdr.xid = xid;
2N/A hdr.locale = locale;
2N/A
2N/A this.initialize(url, scopes, attrs);
2N/A }
2N/A
2N/A // Initialize the message.
2N/A
2N/A void initialize(ServiceURL url, Vector scopes, Vector attrs)
2N/A throws ServiceLocationException {
2N/A
2N/A SLPServerHeaderV2 hdr = (SLPServerHeaderV2)getHeader();
2N/A
2N/A ServiceType serviceType = url.getServiceType();
2N/A
2N/A if (!serviceType.equals(Defaults.SA_SERVICE_TYPE)) {
2N/A throw
2N/A new ServiceLocationException(
2N/A ServiceLocationException.PARSE_ERROR,
2N/A "ssaadv_nonsaurl",
2N/A new Object[] {serviceType});
2N/A
2N/A }
2N/A
2N/A // Validate scope list.
2N/A
2N/A DATable.validateScopes(scopes, hdr.locale);
2N/A hdr.scopes = (Vector)scopes.clone();
2N/A
2N/A // Escape scope strings.
2N/A
2N/A hdr.escapeScopeStrings(scopes);
2N/A
2N/A // Parse out the payload.
2N/A
2N/A ByteArrayOutputStream baos = new ByteArrayOutputStream();
2N/A
2N/A String surl = url.toString();
2N/A
2N/A // Parse out the URL.
2N/A
2N/A byte[] urlBytes = hdr.putString(surl, baos);
2N/A
2N/A // Parse out the scope list. We need to save the bytes for
2N/A // the authblock.
2N/A
2N/A byte[] scopeBytes =
2N/A hdr.parseCommaSeparatedListOut(scopes, baos);
2N/A
2N/A // Parse out the attribute list.
2N/A
2N/A byte[] attrBytes = hdr.parseAttributeVectorOut(attrs,
2N/A url.getLifetime(),
2N/A false,
2N/A null,
2N/A baos,
2N/A false);
2N/A
2N/A // Parse out auth blocks, if necessary.
2N/A
2N/A Hashtable auth = null;
2N/A byte nBlocks = 0;
2N/A
2N/A if (SLPConfig.getSLPConfig().getHasSecurity()) {
2N/A Object[] message = new Object[6];
2N/A
2N/A // None of the strings have leading length fields, so add them here
2N/A ByteArrayOutputStream abaos = new ByteArrayOutputStream();
2N/A hdr.putInteger(urlBytes.length, abaos);
2N/A message[0] = abaos.toByteArray();
2N/A message[1] = urlBytes;
2N/A
2N/A abaos = new ByteArrayOutputStream();
2N/A hdr.putInteger(attrBytes.length, abaos);
2N/A message[2] = abaos.toByteArray();
2N/A message[3] = attrBytes;
2N/A
2N/A abaos = new ByteArrayOutputStream();
2N/A hdr.putInteger(scopeBytes.length, abaos);
2N/A message[4] = abaos.toByteArray();
2N/A message[5] = scopeBytes;
2N/A
2N/A auth = hdr.getCheckedAuthBlockList(message,
2N/A url.getLifetime());
2N/A nBlocks = (byte) auth.size();
2N/A
2N/A }
2N/A
2N/A // Parse out number of blocks.
2N/A
2N/A baos.write(nBlocks);
2N/A hdr.nbytes++;
2N/A
2N/A // Parse out blocks, if any.
2N/A
2N/A if (auth != null) {
2N/A AuthBlock.externalizeAll(hdr, auth, baos);
2N/A
2N/A }
2N/A
2N/A // Save bytes.
2N/A
2N/A hdr.payload = baos.toByteArray();
2N/A
2N/A // Construct description of outgoing packet for logging.
2N/A
2N/A hdr.constructDescription("SAAdvert",
2N/A " URL=``" + url + "''\n" +
2N/A " attrs=``" + attrs + "''\n" +
2N/A " auth block="+AuthBlock.desc(auth) +
2N/A "\n");
2N/A
2N/A }
2N/A}