Option.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 1998-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/**
* Option is a simple data class which encapsulates an option record in
* the dhcptab. See dhcptab(4) for the gory details on options (aka symbols).
*
* @see DhcptabRecord
* @see Macro
*/
private byte context;
private short code;
private byte type;
private int granularity;
private int maximum;
private boolean valueClean = false;
private boolean validValue = true;
// The Option attributes that must match their native values.
// Definition for attribute limits
public static short MAX_NAME_SIZE = 128;
// Option contexts.
public static byte STANDARD = 0;
public static byte EXTEND = 1;
public static byte VENDOR = 2;
public static byte SITE = 3;
public static byte CONTEXTS = 4;
public static OptionContext [] ctxts = {
// Option types.
public static byte ASCII = 0;
public static byte OCTET = 1;
public static byte IP = 2;
public static byte NUMBER = 3;
public static byte BOOLEAN = 4;
public static byte UNUMBER8 = 5;
public static byte UNUMBER16 = 6;
public static byte UNUMBER32 = 7;
public static byte UNUMBER64 = 8;
public static byte SNUMBER8 = 9;
public static byte SNUMBER16 = 10;
public static byte SNUMBER32 = 11;
public static byte SNUMBER64 = 12;
public static byte TYPES = 13;
public static OptionType [] types = {
/*
* These need to be the same as the definitions in libdhcputil's
* parser in dhcp_symbol.c
*/
public static char DSYM_FIELD_DEL = ',';
public static char DSYM_QUOTE = '"';
// Serialization id for this class
static final long serialVersionUID = 7468266817375654444L;
/**
* Construct an empty instance. Default to Site option, IP type.
*/
public Option() {
valueClean = false;
granularity = 1;
}
/**
* Construct a fully defined instance. Used by the server to create
* Options.
* @param vendors the list of vendors (if any)
* @param code the option code
* @param type the option type code
* @param gran the option granularity
* @param max the option maximum
* @param sig the signature from the dhcptab
* @param isValid the flag indicating option definition validity
*/
valueClean = false;
}
}
/**
* Set the option name as specified.
* @param name a string representing the option name.
*/
try {
} catch (ValidationException e) {
// Can't happen.
}
}
/**
* Get the context for this option
* @return a byte for the option context (context codes are
* defined by the OptionContext objects in the ctxts array).
*/
public byte getContext() {
return context;
}
/**
* Set the context for this option (context codes are defined
* by the OptionContext objects in the ctxts array).
*/
public void setContext(byte c) {
context = c;
valueClean = false;
}
/**
* Enumerate the vendor list.
* @return an Enumeration of the vendors, which will be empty for
* non-vendor options.
*/
public Enumeration getVendors() {
}
/**
* Get the number of vendors for this option.
* @return an int count of the vendors, zero for non-vendor options.
*/
public int getVendorCount() {
}
/**
* Add a vendor to the list for this option.
* @param v the vendor name as a String.
*/
throw new ValidationException(v);
}
vendors.addElement(v);
valueClean = false;
}
/**
* Empty the vendor list.
*/
public void clearVendors() {
valueClean = false;
}
/**
* Remove a vendor from the list.
* @param index the position of the vendor to remove in the list of vendors
*/
public void removeVendorAt(int index) {
valueClean = false;
}
/**
* Get the vendor at a specified index in the vendor list.
* @param index the index of the vendor to retrieve
* @return the vendor name
*/
}
return;
}
}
}
/**
* Set the vendor name at a specified index in the list.
* @param vendor the vendor name
* @param index the position in the list to set.
*/
}
valueClean = false;
}
/**
* Get the option code.
* @return the code as a short.
*/
public short getCode() {
return code;
}
/**
* Set the option code.
* @param c the code to use
*/
public void setCode(short c) {
code = c;
valueClean = false;
}
/**
* Get the type.
* @return a byte value for the type (type codes are
* defined by the OptionTypes objects in the type array).
* OCTET
*/
public byte getType() {
return type;
}
/**
* Set the type.
* @param t the type code (type codes are defined by the
* OptionTypes objects in the type array).
* or OCTET.
*/
public void setType(byte t) {
type = t;
valueClean = false;
}
/**
* Get the granularity. See dhcptab(4) for an explanation of granularity
* interpretations.
* @return the granularity as an int
*/
public int getGranularity() {
return granularity;
}
/**
* Set the granularity. See dhcptab(4) for an explanation of granularity
* interpretations.
* @param g the granularity as an int.
*/
public void setGranularity(int g) {
granularity = g;
valueClean = false;
}
/**
* Get the maximum. See dhcptab(4) for an explanation of maximum.
* @return the maximum as an int.
*/
public int getMaximum() {
return maximum;
}
/**
* Set the maximum. See dhcptab(4) for an explanation of maximum.
* @param m the maximum as an int.
*/
public void setMaximum(int m) {
maximum = m;
valueClean = false;
}
/**
* Return validity of this option.
* @return true if the option is correctly defined, false if not
*/
public boolean isValid() {
return (validValue);
}
/**
* Get the definition as a string in the format specified by dhcptab(4)
* @return a String containing the definition
*/
/* The value string stored is not clean, regenerate */
if (!valueClean) {
StringBuffer b = new StringBuffer();
// Start with context
// Vendor context next adds the vendors, separate by blanks
boolean first = true;
if (!first) {
} else {
first = false;
}
// If vendor class contains whitespace, need to quote it
if (needQuoting) {
b.append(DSYM_QUOTE);
}
b.append(s);
if (needQuoting) {
b.append(DSYM_QUOTE);
}
}
}
b.append(DSYM_FIELD_DEL);
// Add the code
b.append(DSYM_FIELD_DEL);
// Add the type
b.append(DSYM_FIELD_DEL);
// Add the granularity
b.append(granularity);
b.append(DSYM_FIELD_DEL);
// Add the maximum
// Save it and note as such so we can avoid doing this again
try {
} catch (ValidationException e) {
// This should never happen!
}
valueClean = true;
}
return super.getValue();
}
// Make a copy of this option
o.setContext(getContext());
}
o.setGranularity(getGranularity());
o.setMaximum(getMaximum());
o.setSignature(getSignature());
return o;
}
/**
* Returns a string representation of this object.
* @return a string representation of this object.
*/
}
/**
* Returns the context definition for the specified context.
* @param code the context code.
* @return the OptionContext for the context.
*/
for (int i = 0; i < CONTEXTS; i++) {
break;
}
}
return (ctxt);
}
/**
* Returns the dhcptab string representation of the specified context.
* @param code the context code.
* @return the dhcptab string representation of the context.
*/
return ("undefined");
} else {
return (ctxt.getDhcptabString());
}
}
/**
* Returns the string representation of the specified context.
* @param code the context code.
* @return a string representation of the context.
*/
return ("undefined");
} else {
}
}
/**
* Returns the type definition for the specified type.
* @param code the type code.
* @return the OptionType for the type.
*/
for (int i = 0; i < TYPES; i++) {
break;
}
}
return (type);
}
/**
* Returns the dhcptab string representation of the specified type.
* @param code the type code.
* @return the dhcptab string representation of the type.
*/
return ("undefined"); // should never happen
} else {
return (type.getDhcptabString());
}
}
/**
* Returns the string representation of the specified type.
* @param code the type code.
* @return a string representation of the type.
*/
return ("undefined"); // should never happen
} else {
}
}
}