ServiceLocationAttributeV1.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright (c) 1999 by Sun Microsystems, Inc.
* All rights reserved.
*
*/
// SCCS Status: %W% %G%
// ServiceLocationAttributeV1.java: SLPv1 character encoding and decoding
// Author: James Kempf
// Created On: Fri Oct 9 19:18:17 1998
// Last Modified By: James Kempf
// Last Modified On: Sat Oct 24 13:17:58 1998
// Update Count: 15
//
/**
* Handles attribute string encoding and decoding for SLPv1.
*
* @version %R%.%L% %D%
* @author James Kempf
*/
class ServiceLocationAttributeV1 extends ServiceLocationAttribute {
// Characters to escape.
final private static String ESCAPABLE_CHARS =
UNESCAPABLE_CHARS + "&#;";
/**
* Handles radix64 string encoding and decoding for SLPv1.
*
* @version %R%.%L% %D%
* @author James Kempf
*/
/**
* Translates the 6 bit value to the corresponding radix 64
* representation.
*/
int i = (int)(cin & (char)0x00FF);
char result = ' ';
if (i < 26) {
result = (char)((char)i + 'A');
} else if (i < 52) {
} else if (i < 62) {
} else if (i == 62) {
result = '+';
} else if (i == 63) {
result = '/';
}
return result;
}
/**
* Translates a radix 64 representation to the 64 bit value which
* corresponds to it.
*/
throws ServiceLocationException {
int i = (int)(cin & 0x00ff);
char c = (char) 0xffff;
if (((char)i >= 'A') && ((char)i <= 'Z')) {
c = (char)((char)i - 'A');
}
if (((char)i >= 'a') && ((char)i <= 'z')) {
c = (char)((char)i - 'a' +(char) 26);
}
if (((char)i >= '0') && ((char)i <= '9')) {
c = (char)((char)i - '0' +(char) 52);
}
if ((char)i == '+') {
c = (char)62;
}
if ((char)i == '/') {
c = (char)63;
}
if ((char)i == '=') {
c = (char)0;
}
if (c == 0xffff) {
throw
"v1_radix64_error",
new Object[] {s});
}
return c;
}
// format of the encoding is "(###:encoding)" where ### is the length
// convert a string in the encoding to the buffer format
throws ServiceLocationException {
return new Opaque(new byte[0]);
}
int oplen = 0;
int scan = 0;
break; // scan till begins
}
scan++;
}
scan++; // past the '('
break;
}
scan++;
}
oplen *= 10;
scan++;
} else {
break;
}
}
throw
"v1_radix64_error",
new Object[] {s});
}
throw
"v1_radix64_error",
new Object[] {s});
}
scan++; // past the ':'
byte b[] = new byte[oplen];
int pos = 0;
timesthrough++;
}
for (int i = 0; i < timesthrough; i++) {
// get 4 bytes to make 3 with, skipping blanks
char v[] = new char[4];
for (int x = 0; x < 4; x++) {
scan++; // eat white
}
throw
"v1_radix64_error",
new Object[] {s});
}
scan++;
}
b[pos++] =
(byte) (((0x3F & v[0]) << 2) + ((0x30 & v[1]) >> 4));
b[pos++] =
(byte) (((0x0F & v[1]) << 4) + ((0x3C & v[2]) >> 2));
} // end of conversion loop
throw
"v1_radix64_error",
new Object[] {s});
}
throw
"v1_radix64_error",
new Object[] {s});
}
return new Opaque(b);
}
// convert an Opaque to the encoding
if (b == null) {
return new String("");
}
int datalen;
if (fill == 0) {
} else {
}
int dataoffset = 0;
if (more != 0) {
more = 1;
}
int a[] = new int[4];
for (int j = 0; j < 4; j++) {
}
dataoffset += 3;
}
if (fill == 0) {
} else if (fill == 2) {
}
for (int j = 0; j < 4; j++) {
}
}
}
// Create an SLPv1 attribute from a general attribute.
}
// Create an SLPv1 attribute from the parenthesized expression, using
// charCode to decode any encodings.
boolean allowMultiValuedBooleans)
throws ServiceLocationException {
// If start and end paren, then parse out assignment.
"=",
true);
try {
// Get the tag.
id =
throw
"null_id",
}
// Gather the rest.
// Parse the comma separated list.
// Convert to objects.
for (i = 0; i < n; i++) {
// Need to determine which type to use.
// Convert Opaque to byte array.
if (o instanceof Opaque) {
}
values.setElementAt(o, i);
}
} catch (NoSuchElementException ex) {
throw
"assignment_syntax_err",
}
} else {
// Check to make sure there's no parens.
throw
"assignment_syntax_err",
}
// Unescape the keyword.
}
}
// Duplicate of the one in ServiceLocatioAttribute, except we use our
// unescapeAttributeString.
throws ServiceLocationException {
// If it can be converted into an integer, then convert it.
try {
} catch (NumberFormatException ex) {
// Wasn't an integer. Try boolean.
} else {
// Process the string to remove escapes.
// If it begins with the opaque prefix, treat it as an
// opaque. Use radix64 parser to convert.
} else {
}
}
}
return o;
}
// Externalize the attribute, using its charCode to encode any reserved
// characters.
throws ServiceLocationException {
}
Object o = e.nextElement();
s = escapeValueInternal(o, charCode);
v.addElement(s);
}
new StringBuffer("(" +
"=");
}
// Exactly like the one in ServiceLocationAttribute, but use our
// escapeAttributeString.
String s;
// Escape any characters needing it.
try {
} catch (ServiceLocationException ex) {
throw
}
// Convert to radix 64.
} else {
}
return s;
}
// Escape an attribute string with the char code.
throws ServiceLocationException {
boolean is8bit =
for (i = 0; i < n; i++) {
} else {
// Need to check ASCII and LATIN1 to make sure that
// the character is not outside their range of
// representation.
if (is8bit && (short)c > 255) {
throw
"v1_8bit_error",
}
}
}
}
// Unescape attribute string, using charCode for reserved characters.
throws ServiceLocationException {
// Process escapes.
for (i = 0; i < n; i++) {
// Check for invalids.
int idx = -1;
throw
"v1_escape_error",
}
// Check for escapes.
if (c != '&') {
} else {
// Check to be sure we've got enough characters left. We need
// at least 3.
if ((i + 1) >= n) {
throw
"v1_escape_error",
}
if (c != '#') {
throw
"v1_escape_error",
}
// Iterate through numbers, collecting.
for (i++; i < n; i++) {
break;
}
}
// If the buffer is empty, then throw exception
throw
"v1_escape_error",
}
// If the last one isn't ";", we've got a problem.
if (c != ';') {
throw
"v1_escape_error",
}
// OK, now convert to a character and add to buffer.
try {
charCode));
} catch (NumberFormatException ex) {
throw
"v1_escape_error",
}
}
}
}
}