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 * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 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 * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A// Author: James Kempf 2N/A// Created On: Mon Sep 14 12:47:20 1998 2N/A// Last Modified By: James Kempf 2N/A// Last Modified On: Mon Nov 23 14:32:50 1998 2N/A * SrvLocHeader handles different versions of the SLP header. Clients 2N/A * call the instance methods returned by newInstance(). If no version 2N/A * specific subclass exists for the version number, null is returned 2N/A * from newInstance. Parsing of the header and message bodies, and 2N/A * creation of error replies are handled by the version specific 2N/A * subclasses. We also let the SrvLocHeader serve as a SrvLocMsg object 2N/A * to handle the SrvAck, which only has an error code. 2N/A * @author James Kempf 2N/A // Table of header classes. Keys are the version number. 2N/A // Common constants and instance variables. 2N/A // Number of bytes in the version and function fields. 2N/A // SLP function codes. Even though SAAdvert isn't in all versions, 2N/A // we include it here. 2N/A // Sizes of data items. 2N/A // Header instance variables. 2N/A // Unprotected for less code. 2N/A short xid =
0;
// transaction id 2N/A boolean mcast =
false;
// Mulitcast flag. 2N/A byte[]
payload =
new byte[
0];
// bytes of outgoing payload, 2N/A protected static short uniqueXID =
0;
// outgoing transaction id. 2N/A // Message description. 2N/A // SrvLocMsg Implementation. 2N/A // Return number of replies to this message. 2N/A // SrvLocHeader Interface. 2N/A // Register a new header class for version. Serious error, causing 2N/A // program termination, if we can't find it. 2N/A // Create a version specific instance. We use a naming convention 2N/A // to identify the version specific classes used to create the 2N/A // Get header class. 2N/A // Parse the incoming stream to obtain the header. 2N/A // Parse the incoming stream to obtain the message. 2N/A // Externalize the message. 2N/A // Return the appropriately versioned DAAdvert. 2N/A // Methods that some subclasses may reimplement. 2N/A // Parse any options. 2N/A // Create an error reply for this message. This reply will be appropriate 2N/A // for the server to send back to the client. Default is to do nothing, 2N/A // which is the code for the client. 2N/A // Common utilities for all versions. 2N/A // Set the packet length to the incoming value. 2N/A // Add an Internet address to the previous responders list. 2N/A // Get a unique transaction id. 2N/A // Parse 2-byte integer, bump byte count. 2N/A // Parse a 2-byte integer from the input stream. 2N/A byte[] b =
new byte[
2];
2N/A int x = (
int)((
char)b[
0] &
0xFF);
2N/A int y = (
int)((
char)b[
1] &
0xFF);
2N/A // Parse 2-byte integer, bump byte count. 2N/A // Parse a 2-byte integer to the output stream. 2N/A // Parse a 3-byte integer from the byte input stream. 2N/A byte[] b =
new byte[
3];
2N/A int w = (
int)((
char)b[
0] &
0xFF);
2N/A int x = (
int)((
char)b[
1] &
0xFF);
2N/A int y = (
int)((
char)b[
2] &
0xFF);
2N/A // Parse a 3-byte integer to the output stream. 2N/A // Parse string, bump byte count. Use UTF8 encoding. 2N/A // Parse a string with an initial length from the input stream. 2N/A // Convert it to the proper encoding. Return the raw bytes for 2N/A // auth block creation. 2N/A // Clear out buffer first. 2N/A // First get the length. 2N/A // Now get the bytes. 2N/A // Convert to string and return. 2N/A // Parse out string, bump byte count. Use UTF8 encoding. 2N/A // Put a string with an initial length into the byte stream, converting 2N/A // into the proper encoding. 2N/A // Put out the string's length in the encoding. 2N/A // Now really write out the bytes. 2N/A // Convert a Unicode string into encoded bytes. 2N/A return new byte[
0];
// won't happen, hopefully... 2N/A // Convert bytes into a Unicode string. 2N/A return "";
// won't happen, hopefully ... 2N/A // Parse a comma separated list of strings from the vector into the 2N/A * Create a comma separated list of strings out of the vector. 2N/A * @param v A Vector of strings. 2N/A // Construct in a string buffer first. 2N/A for (i =
0; i < n; i++) {
2N/A // Add comma for previous one if we need it. 2N/A // Return the bytes. 2N/A * @parameter The string has the format = STRING *("," STRING) 2N/A * @parameter A boolean indicating whether parens should be ignored or 2N/A * used for grouping. 2N/A * @return A vector (of Strings) based upon the (comma delimited) string. 2N/A // It's an open paren, so begin collecting. 2N/A // Increment the level if not ignoring parens, add to token 2N/A // Decrement level if not ignoring parens. 2N/A // Add if collecting. 2N/A // Check for empty token. 2N/A // If not collecting, then close off the element. 2N/A // Add last token, but check first for empty token. 2N/A // If we're still collecting on close, then there's a syntax error. 2N/A // Allow clients to clone the header. 2N/A // Reinitialize some stuff. Subclasses must reimplement nbytes 2N/A // header size calculation. 2N/A // packetlength stays the same, we may be using the same transport. 2N/A // Construct a description of the header. Messages add individual 2N/A // descriptions to this.