/*
* 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.
*
*/
// SLPHeaderV1.java: SLPv1 Header.
// Author: James Kempf
// Created On: Thu Sep 10 15:12:14 1998
// Last Modified By: James Kempf
// Last Modified On: Wed Jan 20 15:38:07 1999
// Update Count: 59
//
/**
* The SLPHeaderV1 class models the SLPv1 server side header.
*
* @author James Kempf
*/
// Version number.
// Function code for message reply.
// Various header flags.
protected static int HEADER_BYTES =
// Characters to escape.
UNESCAPABLE_CHARS + "&#;";
// Used to construct a header in SrvLocHeader.newInstance().
SLPHeaderV1() {
super();
}
// Assign reply code based on function code type, then use superclass
// method to parse header.
throws ServiceLocationException, IOException {
this.functionCode = functionCode;
// We ignore the error case here.
switch (functionCode) {
case SrvLocHeader.SrvReq:
break;
case SrvLocHeader.AttrRqst:
break;
case SrvLocHeader.SrvTypeRqst:
break;
}
nbytes++;
fresh = false; // fresh gets set on output in SLPv1
// Security not handled for SLPv1.
throw
"v1_no_security",
new Object[0]);
}
nbytes++;
// Dialect must be zero.
if (dialect != 0) {
throw
"v1_nonzero_dialect",
new Object[0]);
}
byte a_bTemp[] = new byte[LANG_CODE_BYTES];
nbytes += 2;
try {
} catch (UnsupportedEncodingException ex) {
}
}
// Parse an incoming V1 message and return the SrvLocMsg object.
throws ServiceLocationException,
// If this is a *multicast* request, we reject it except for DAAdvert.
// Multicast requests are only taken by SA servers.
return null;
}
// Switch and convert according to function code.
switch (functionCode) {
case SrvLocHeader.SrvReq:
break;
case SrvLocHeader.SrvReg:
break;
case SrvLocHeader.SrvDereg:
break;
case SrvLocHeader.AttrRqst:
break;
case SrvLocHeader.SrvTypeRqst:
break;
case SrvLocHeader.DAAdvert:
break;
default:
throw
"function_code_error",
new Object[] {
new Integer(functionCode)});
}
// Check for size overflow.
throw
"length_overflow",
new Object[] {
}
return msg;
}
// Externalize the message by converting it to bytes and writing
// it to the output stream.
public void
throws ServiceLocationException {
// Need to put in the error code or previous responders.
} else {
// Parse out previous responders. Note there will only be some
// if the error code is not put out.
if (previousResponders != null) {
}
}
// Parse payload out if error code is OK and payload is nonnull.
}
// Don't touch payload here, somebody may put in a previousResponder
// and resend the message.
// Set overflow flag if buffer is too large and this isn't going out
// via TCP.
!isTCP) {
overflow = true;
}
nbytes++;
nbytes++;
byte flags = 0X00;
if (overflow) {
} else {
}
if (monolingual) {
} else {
}
if (fresh) {
} else {
}
nbytes++;
nbytes++;
nbytes += 2;
int intCharCode = 0;
try {
} catch (ServiceLocationException ex) {
"v1_unsupported_encoding",
}
// Write the body.
}
// Create an error reply using the reply code. Calculate the
// error code using the exception.
// If this is a DAAdvert, then no error reply is returned
// because V1 doesn't support unicast SrvRqst for DAAdvert.
return null;
}
// Clone the header to make sure that everything else is the same.
// We don't want to use the same header because it may be tested
// elsewhere.
try {
} catch (CloneNotSupportedException exx) {
// We know we support it.
}
// We should *not* be getting a null exception down this path!
"null_parameter",
if (ex instanceof ServiceLocationException) {
// Handle monolingual bit here. If the exception is
// LANGUAGE_NOT_SUPPORTED and the message type is
// either SrvRqst or AttrRqst, then we simply return an
// empty message unless the monolingual flag is on.
try {
if (!hdr.monolingual) {
}
}
} catch (ServiceLocationException exx) {
hdr.monolingual = true;
}
// Otherwise, we just ignore it.
}
// Anything over AUTHENTICATION_FAILED is an internal error in V1.
}
} else if (ex instanceof IllegalArgumentException ||
ex instanceof IOException) {
} else {
}
// Construct header description.
return hdr;
}
// Return a reply header with flags properly set.
try {
} catch (CloneNotSupportedException ex) {
// We know that we support it.
}
return hdr;
}
// Return display string.
return
}
//
// Validation Utilities.
//
/**
* Validate the scope name to be sure it doesn't contain forbidden
* chars and isn't one of the reserved scope names.
*/
throws ServiceLocationException
{
throw new ServiceLocationException(
"v1_scope_char_res",
}
// Check against reserved scope names.
throw new ServiceLocationException(
"v1_scope_name_res",
}
}
/**
* Remove IANA from the service type name.
*
* @param serviceType The service type and naming authority.
* @return The service type name with IANA removed.
*/
// Substitute null string for IANA.
int idx = 0;
}
return serviceType;
}
// Check whether this is a vaild SLPv1 service type. Also remove
// IANA.
throws ServiceLocationException {
// Check for trailing colon and remove it.
throw
"v1_service_type_format",
}
// Remove IANA.
// Check syntax.
// Reject if abstract type. SLPv1 doesn't handle
// abstract types.
if (st.isAbstractType()) {
throw
"v1_abstract_type",
new Object[0]);
}
// Reject if not a service: type. SLPv1 doesn't handle
// nonservice: types.
if (!st.isServiceURL()) {
throw
"v1_not_surl",
new Object[0]);
}
return type;
}
//
// Parsing Utilities.
//
// Parse string, bump byte count.
throws ServiceLocationException, IOException {
int i, n = 0;
// Get length.
n = getInteger(dis);
byte[] bytes = new byte[n];
// Read bytes.
// If the encoding type is Unicode, then figure out first
// whether it's big or little endian from byte header. Future
// calls won't have to go through this grief unless the byte header
// is missing.
}
// If we are still just Unicode by this point, then we need to
// add the big endian bytes to the beginning of the array.
// Otherwise, Java won't parse it. Note that we don't change
// the flag in the header, since we will need to convert the
// next time around as well.
}
// Convert the bytes into a string.
return bytes;
}
// Parse out string, bump byte count. Use header encoding.
// If the charCode is UNICODE, arbirtarily change to big or little,
// while Java will parse.
}
return bytes;
}
// Parse in a service URL including lifetime if necessary.
protected ServiceURL
boolean lifeTimeToo,
short errCode)
throws ServiceLocationException, IOException {
int lifetime = 0;
if (lifeTimeToo) {
}
try {
} catch (IllegalArgumentException ex) {
throw
"malformed_url",
}
return url;
}
// Parse out a service URL including lifetime if required.
void
boolean lifetimeToo,
throws ServiceLocationException {
if (lifetimeToo) {
}
}
// Parse in a list of attributes, returing a vector of
// ServiceLocationAttribute objects.
throws ServiceLocationException, IOException {
// Parse the list into ServiceLocationAttribute objects.
for (i = 0; i < n; i++) {
false),
i);
}
return attrForms;
}
// Parse out a V1 attribute vector.
void
throws ServiceLocationException {
// Convert the attributes to strings, escaping characters to
// escape.
while (en.hasMoreElements()) {
// Make an SLPv1 attribute out of it, so we can
// externalize it with the v1 encoding scheme.
}
// Parse it out.
}
// Parse in previous responders.
throws ServiceLocationException, IOException {
}
// Put out a vector of strings.
int i, n = v.size();
// Put out the total number of strings.
// Put out the strings.
for (i = 0; i < n; i++) {
}
}
// Return an SLPv1 DAAdvert.
long timestamp,
throws ServiceLocationException {
// If scopes vector is null, then return all scopes for this
// DA.
}
}
// Reimplement clone() to get the header size right.
throws CloneNotSupportedException {
return hdr;
}
}