/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
// SrvLocHeader.java: Abstract superclass for SLP Headers
// Author: James Kempf
// Created On: Mon Sep 14 12:47:20 1998
// Last Modified By: James Kempf
// Last Modified On: Mon Nov 23 14:32:50 1998
// Update Count: 55
//
/**
* SrvLocHeader handles different versions of the SLP header. Clients
* call the instance methods returned by newInstance(). If no version
* specific subclass exists for the version number, null is returned
* from newInstance. Parsing of the header and message bodies, and
* creation of error replies are handled by the version specific
* subclasses. We also let the SrvLocHeader serve as a SrvLocMsg object
* to handle the SrvAck, which only has an error code.
*
* @author James Kempf
*/
// Table of header classes. Keys are the version number.
// Offset to XID.
// Common constants and instance variables.
// Number of bytes in the version and function fields.
// SLP function codes. Even though SAAdvert isn't in all versions,
// we include it here.
"0",
"SrvReq",
"SrvRply",
"SrvReg",
"SrvDereg",
"SrvAck",
"AttrRqst",
"AttrRply",
"DAAdvert",
"SrvTypeRqst",
"SrvTypeRply",
"SAAdvert",
};
// Sizes of data items.
//
// Header instance variables.
//
// Unprotected for less code.
short errCode =
// Message description.
SrvLocHeader() {
}
//
// SrvLocMsg Implementation.
//
return this;
}
public short getErrorCode() {
return errCode;
}
// Return number of replies to this message.
public int getNumReplies() {
return iNumReplies;
}
//
// SrvLocHeader Interface.
//
// Register a new header class for version. Serious error, causing
// program termination, if we can't find it.
try {
} catch (ClassNotFoundException ex) {
"no_class",
}
}
// Create a version specific instance. We use a naming convention
// to identify the version specific classes used to create the
// instance.
try {
// Get header class.
return null;
}
return hdr;
new Object[] {
ex,
ex.getMessage()});
return null;
}
}
// Parse the incoming stream to obtain the header.
// Parse the incoming stream to obtain the message.
// Externalize the message.
abstract void
boolean multicast,
boolean isTCP)
throws ServiceLocationException;
// Return the appropriately versioned DAAdvert.
abstract SDAAdvert
long timestamp,
throws ServiceLocationException;
//
// Methods that some subclasses may reimplement.
//
// Parse any options.
throws ServiceLocationException,
}
// Create an error reply for this message. This reply will be appropriate
// for the server to send back to the client. Default is to do nothing,
// which is the code for the client.
return null;
}
//
// Common utilities for all versions.
//
// Set the packet length to the incoming value.
if (newLength > 0) {
}
}
// Add an Internet address to the previous responders list.
"prev_resp_reply",
new Object[0]);
}
}
// Get a unique transaction id.
synchronized static short getUniqueXID() {
if (uniqueXID == 0) {
}
uniqueXID++;
return (short)(uniqueXID & 0xFFFF);
}
// Parse 2-byte integer, bump byte count.
throws ServiceLocationException, IOException {
nbytes += SHORT_SIZE;
return ret;
}
// Parse a 2-byte integer from the input stream.
throws ServiceLocationException, IOException {
byte[] b = new byte[2];
int x = (int)((char)b[0] & 0xFF);
int y = (int)((char)b[1] & 0xFF);
int z = x << 8;
z += y;
return z;
}
// Parse 2-byte integer, bump byte count.
putInteger(z, baos);
nbytes += SHORT_SIZE;
}
// Parse a 2-byte integer to the output stream.
}
// Parse a 3-byte integer from the byte input stream.
throws ServiceLocationException, IOException {
byte[] b = new byte[3];
int w = (int)((char)b[0] & 0xFF);
int x = (int)((char)b[1] & 0xFF);
int y = (int)((char)b[2] & 0xFF);
int z = w << 16;
z += x << 8;
z += y;
nbytes += 3;
return z;
}
// Parse a 3-byte integer to the output stream.
nbytes += 3;
}
// Parse string, bump byte count. Use UTF8 encoding.
throws ServiceLocationException, IOException {
return ret;
}
// Parse a string with an initial length from the input stream.
// Convert it to the proper encoding. Return the raw bytes for
// auth block creation.
static byte[]
throws ServiceLocationException, IOException {
// Clear out buffer first.
// First get the length.
int i, n = 0;
n = getInteger(dis);
// Now get the bytes.
byte[] bytes = new byte[n];
// Convert to string and return.
return bytes;
}
// Parse out string, bump byte count. Use UTF8 encoding.
return bytes;
}
// Put a string with an initial length into the byte stream, converting
// into the proper encoding.
static byte[]
// Put out the string's length in the encoding.
// Now really write out the bytes.
return bytes;
}
// Convert a Unicode string into encoded bytes.
try {
} catch (UnsupportedEncodingException ex) {
return new byte[0]; // won't happen, hopefully...
}
}
// Convert bytes into a Unicode string.
try {
} catch (UnsupportedEncodingException ex) {
return ""; // won't happen, hopefully ...
}
}
// Parse a comma separated list of strings from the vector into the
// output stream.
protected byte[]
}
/**
* Create a comma separated list of strings out of the vector.
*
* @param v A Vector of strings.
*/
static String
// Construct in a string buffer first.
int i, n = v.size();
for (i = 0; i < n; i++) {
// Add comma for previous one if we need it.
if (i != 0) {
}
}
// Return the bytes.
}
/**
* @parameter The string has the format = STRING *("," STRING)
* @parameter A boolean indicating whether parens should be ignored or
* used for grouping.
* @return A vector (of Strings) based upon the (comma delimited) string.
*/
throws ServiceLocationException {
if (s == null)
return new Vector();
if (s.length() == 0)
return new Vector();
try {
int level = 0;
while (st.hasMoreElements()) {
// It's an open paren, so begin collecting.
// Increment the level if not ignoring parens, add to token
if (!ignoreParens) {
level++;
}
// Decrement level if not ignoring parens.
if (!ignoreParens) {
level--;
}
// Add if collecting.
if (level != 0) {
} else {
// Check for empty token.
throw
"csl_syntax_error",
new Object[] {s});
}
// If not collecting, then close off the element.
v.addElement(el);
el = "";
}
} else {
}
}
// Add last token, but check first for empty token.
throw
"csl_syntax_error",
new Object[] {s});
}
v.addElement(el);
// If we're still collecting on close, then there's a syntax error.
if (level != 0) {
throw
"csl_syntax_error",
new Object[] {s});
}
return v;
} catch (NoSuchElementException nsee) {
throw
"csl_syntax_error",
new Object[] {s});
}
}
// Allow clients to clone the header.
throws CloneNotSupportedException {
// Reinitialize some stuff. Subclasses must reimplement nbytes
// header size calculation.
// packetlength stays the same, we may be using the same transport.
return hdr;
}
// Construct a description of the header. Messages add individual
// descriptions to this.
this.msgDescription = msgDescription;
}
return functionCodeAbbr[functionCode];
} else {
}
} else {
return msgType;
}
}
}
}