dhcp_symbol.c revision 2
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <ctype.h>
#include <strings.h>
#include <limits.h>
#include <errno.h>
#include <dhcp_impl.h>
#include "dhcp_symbol.h"
/*
* The following structure and table are used to define the attributes
* of a DHCP symbol category.
*/
typedef struct dsym_cat {
char *dc_string; /* string value for the category */
int dc_minlen; /* min. chars of dc_string to match */
} dsym_cat_t;
static dsym_cat_t cats[] = {
DHCP_SITE_OPT - 1 },
};
/*
* The following structure and table are used to define the attributes
* of a DHCP symbol type.
*/
typedef struct dsym_type {
char *dt_string; /* string value for the type */
} dsym_type_t;
static dsym_type_t types[] = {
};
/*
* symbol delimiters and constants
*/
#define DSYM_CLASS_DEL " \t\n"
#define DSYM_FIELD_DEL ","
#define DSYM_VENDOR_DEL '='
#define DSYM_QUOTE '"'
/*
* dsym_trim(): trims all whitespace from either side of a string
*
* input: char **: a pointer to a string to trim of whitespace.
* output: none
*/
static void
{
/*
* Trim all whitespace from the front of the string.
*/
tmpstr++;
}
/*
* Move the str pointer to first non-whitespace char.
*/
/*
* Check case where the string is nothing but whitespace.
*/
if (*tmpstr == '\0') {
/*
* Trim all whitespace from the end of the string.
*/
tmpstr--;
}
/*
* terminate after last non-whitespace char.
*/
}
}
/*
* dsym_get_token(): strtok_r() like routine, except consecutive delimiters
* result in an empty string
*
* note: original string is modified
*
* input: char *: string in which to search for tokens
* char *: list of possible token delimiter characters
* char **: location for next call to routine
* boolean_t: should delimiters be ignored if within quoted string?
* output: char *: token, or NULL if no more tokens
*/
static char *
{
char *del;
/*
* If incoming string has no tokens return a NULL
* pointer to signify no more tokens.
*/
if (*ptr == '\0') {
return (NULL);
}
/*
* Loop until either a token has been identified or until end
* of string has been reached.
*/
/*
* If pointer currently lies within a quoted string,
* then do not check for the delimiter.
*/
if (!in_quote) {
*ptr++ = '\0';
}
}
}
/*
* If the pointer is pointing at a delimiter, then
* check to see if it points to at a quote and update
* the state appropriately.
*/
if (!found) {
}
ptr++;
}
}
return (str);
}
/*
* dsym_get_long(): given a numeric string, returns its long value
*
* input: const char *: the numeric string
* long *: the return location for the long value
* output: DSYM_SUCCESS, DSYM_VALUE_OUT_OF_RANGE or DSYM_SYNTAX_ERROR
*/
static dsym_errcode_t
{
int ret = DSYM_SUCCESS;
int i;
for (i = 0; str[i] != '\0'; i++) {
return (DSYM_SYNTAX_ERROR);
}
}
errno = 0;
if (errno != 0) {
}
return (ret);
}
/*
* dsym_free_classes(): frees the classes allocated by dsym_parse_classes()
*
* input: dhcp_classes_t *: pointer to structure containing classes to free
* output: none
*/
void
{
int i;
return;
}
}
}
/*
* dsym_parse_classes(): given a "Vendor" class string, builds and returns
* the list of vendor classes
*
* input: char *: the "Vendor" class string
* dhcp_classes_t *: pointer to the classes structure
* output: DSYM_SUCCESS, DSYM_INVALID_CAT, DSYM_EXCEEDS_MAX_CLASS_SIZE,
* DSYM_EXCEEDS_CLASS_SIZE, DSYM_SYNTAX_ERROR, or DSYM_NO_MEMORY
*/
static dsym_errcode_t
{
char *cp;
int len;
int ret = DSYM_SUCCESS;
int i;
while (*ptr != '\0') {
if (*ptr == DSYM_VENDOR_DEL) {
ptr++;
break;
}
ptr++;
}
if (*ptr == '\0') {
return (DSYM_INVALID_CAT);
}
return (DSYM_EXCEEDS_MAX_CLASS_SIZE);
}
classes_ret->dc_cnt = 0;
for (i = 0; ret == DSYM_SUCCESS; i++) {
break;
}
if (len == 0) {
continue;
} else if (len > DSYM_CLASS_SIZE) {
continue;
}
continue;
}
/* Strip off the quotes */
if (cp[0] == DSYM_QUOTE) {
cp++;
}
== NULL) {
continue;
}
classes_ret->dc_cnt++;
}
if (ret != DSYM_SUCCESS) {
}
return (ret);
}
/*
* dsym_get_cat_by_name(): given a category field, returns the pointer to its
* entry in the internal category table.
*
* input: const char *: the category name
* dsym_cat_t *: the return location for the pointer to the table entry
* boolean_t: case-sensitive name compare
* output: int: DSYM_SUCCESS or DSYM_INVALID_CAT
*/
static dsym_errcode_t
{
int ret = DSYM_SUCCESS;
int result;
int len;
int i;
for (i = 0; i < cnt; i++) {
if (cs) {
} else {
}
if (result == 0) {
break;
}
}
/*
* Special code required for the Vendor category, because we
* allow whitespace between the keyword and the delimiter.
* If there is no delimiter, then this is an illegal category.
*/
ptr++;
}
if (*ptr != DSYM_VENDOR_DEL) {
}
} else {
if (*ptr != '\0') {
}
}
} else {
}
if (ret == DSYM_SUCCESS) {
}
return (ret);
}
/*
* dsym_parse_cat(): given a category field, returns the category value
* Note: The category must be a valid dhcptab category.
*
* input: const char *: a category field
* dsym_category_t *: the return location for the category value
* output: int: DSYM_SUCCESS or DSYM_INVALID_CAT
*/
static dsym_errcode_t
{
int ret;
if (ret == DSYM_SUCCESS) {
/*
* Since this routine is meant to be used to parse dhcptab
* symbol definitions, only a subset of the DHCP categories
* are valid in this context.
*/
if (entry->dc_dhcptab) {
} else {
}
}
return (ret);
}
/*
* dsym_parse_intrange(): given a DHCP integer field, returns the value
*
* input: const char *: a DHCP code field
* int *: the return location for the value
* int: the minimum valid value
* int: the maximum valid value
* output: int: DSYM_SUCCESS, DSYM_SYNTAX_ERROR, or DSYM_VALUE_OUT_OF_RANGE
*/
static dsym_errcode_t
{
int ret;
long longval;
if (ret == DSYM_SUCCESS) {
} else {
}
}
return (ret);
}
/*
* dsym_validate_code(): given a symbol category and code, validates
* that the code is valid for the category
*
* input: dsym_category_t: the symbol category
* uint16_t: the symbol code
* output: DSYM_SUCCESS, DSYM_INVALID_CAT or DSYM_CODE_OUT_OF_RANGE
*/
static dsym_errcode_t
{
int i;
/*
* Find the category entry from the internal table.
*/
for (i = 0; i < cnt; i++) {
return (DSYM_CODE_OUT_OF_RANGE);
}
return (DSYM_SUCCESS);
}
}
return (DSYM_INVALID_CAT);
}
/*
* dsym_validate_granularity(): given a symbol type, validates
* that the granularity is valid for the type
*
* input: dsym_cdtype_t: the symbol type
* uchar_t: the symbol granularity
* output: DSYM_SUCCESS or DSYM_VALUE_OUT_OF_RANGE
*/
static dsym_errcode_t
{
/*
* We only need to check for a 0 with non-boolean types, as
* anything else is already validated by the ranges passed to
* dsym_parse_intrange() in dsym_parse_field().
*/
return (DSYM_VALUE_OUT_OF_RANGE);
}
return (DSYM_SUCCESS);
}
/*
* dsym_get_type_by_name(): given a type field, returns the pointer to its
* entry in the internal type table.
*
* input: const char *: the type name
* dsym_type_t *: the return location for the pointer to the table entry
* boolean_t: case-sensitive name compare
* output: int: DSYM_SUCCESS or DSYM_INVALID_TYPE
*/
static dsym_errcode_t
{
int result;
int i;
for (i = 0; i < cnt; i++) {
if (cs) {
} else {
}
if (result == 0) {
return (DSYM_SUCCESS);
}
}
return (DSYM_INVALID_TYPE);
}
/*
* dsym_parse_type(): given a DHCP type string, returns the type id
*
* input: char *: a DHCP type string
* dsym_cdtype_t *: the return location for the type id
* output: int: DSYM_SUCCESS or DSYM_INVALID_TYPE
*/
static dsym_errcode_t
{
int ret;
if (ret == DSYM_SUCCESS) {
/*
* Since this routine is meant to be used to parse dhcptab
* symbol definitions, only a subset of the DHCP type
* are valid in this context.
*/
if (entry->dt_dhcptab) {
} else {
}
}
return (ret);
}
/*
* dsym_free_fields(): frees an array of fields allocated by
* dsym_init_parser().
*
* input: char **: array of fields to free
* output: none
*/
void
dsym_free_fields(char **fields)
{
int i;
for (i = 0; i < DSYM_NUM_FIELDS; i++) {
}
}
}
/*
* dsym_close_parser(): free up all resources associated with the parser
*
* input: char **: the fields allocated by dsym_init_parser()
* dhcp_symbol_t *: the structure populated by dsym_init_parser()
* output: none
*/
void
{
}
/*
* dsym_init_parser(): initializes the structures used to parse a symbol
* value.
*
* input: const char *: the symbol name
* const char *: the symbol value in dhcptab format
* char ***: the return location for the symbol fields
* dhcp_symbol_t *: the structure which eventually will
* be the repository for the parsed symbol data
* output: int: DSYM_SUCCESS, DYSM_NO_MEMORY, DSYM_NULL_FIELD or
* DSYM_TOO_MANY_FIELDS
*/
{
int ret = DSYM_SUCCESS;
char *cp;
char *next;
char *field;
char **fields;
int i;
/*
* Initialize the symbol structure.
*/
sym->ds_category = 0;
}
B_FALSE);
continue;
}
continue;
}
continue;
}
}
if (ret == DSYM_SUCCESS &&
}
if (ret != DSYM_SUCCESS) {
} else {
*fields_ret = fields;
}
return (ret);
}
/*
* dsym_parse_field(): parses the specified symbol field.
*
* input: int: the field number to be parsed.
* char **: symbol fields initialized by dsym_init_parser()
* dhcp_symbol_t *: the structure which will be the repository
* for the parsed field
* output: int: DSYM_SUCCESS, DSYM_SYNTAX_ERROR, DSYM_CODE_OUT_OF_RANGE,
* DSYM_INVALID_CAT, DSYM_INVALID_TYPE, DSYM_EXCEEDS_CLASS_SIZE,
* DSYM_EXCEEDS_MAX_CLASS_SIZE, DSYM_NO_MEMORY,
* DSYM_INVALID_FIELD_NUM, DSYM_VALUE_OUT_OF_RANGE
*/
{
int ret = DSYM_SUCCESS;
int intval;
switch (field_num) {
case DSYM_CAT_FIELD:
&sym->ds_classes);
}
break;
case DSYM_CODE_FIELD:
if (ret == DSYM_SUCCESS) {
}
break;
case DSYM_TYPE_FIELD:
break;
case DSYM_GRAN_FIELD:
if (ret == DSYM_SUCCESS) {
}
break;
case DSYM_MAX_FIELD:
if (ret == DSYM_SUCCESS) {
}
break;
default:
}
return (ret);
}
/*
* dsym_parser(): parses a DHCP symbol value
*
* input: char **: symbol fields initialized by dsym_init_parser()
* dhcp_symbol_t *: the structure which will be the repository
* for the parsed field
* int *: last field processed
* boolean_t: parse all fields even though errors occur?
* output: int: DSYM_SUCCESS, DSYM_SYNTAX_ERROR, DSYM_CODE_OUT_OF_RANGE,
* DSYM_INVALID_CAT, DSYM_INVALID_TYPE, DSYM_EXCEEDS_CLASS_SIZE,
* DSYM_EXCEEDS_MAX_CLASS_SIZE, DSYM_NO_MEMORY
* DSYM_INVALID_FIELD_NUM, DSYM_VALUE_OUT_OF_RANGE
*/
{
int ret = DSYM_SUCCESS;
int tret = DSYM_SUCCESS;
int i;
*lastField = -1;
for (i = DSYM_FIRST_FIELD;
if (tret != DSYM_SUCCESS) {
if (ret == DSYM_SUCCESS) {
}
if (bestEffort) {
*lastField = i;
tret = DSYM_SUCCESS;
}
}
}
if (*lastField == -1) {
*lastField = i - 1;
}
return (ret);
}
/*
* dsym_get_cat_id(): given a category string, return the associated id.
*
* input: const char *: the category name
* dsym_category_t *: the return location for the id
* boolean_t: case-sensitive name compare
* output: int: DSYM_SUCCESS or DSYM_INVALID_CAT
*/
{
int ret;
if (ret == DSYM_SUCCESS) {
}
return (ret);
}
/*
* dsym_get_code_ranges(): given a category field, returns its valid code
* ranges.
*
* input: const char *: the category name
* ushort *: return location for the minimum code value.
* ushort *: return location for the maximum code value.
* boolean_t: case-sensitive name compare
* output: int: DSYM_SUCCESS or DSYM_INVALID_CAT
*/
{
int ret;
if (ret == DSYM_SUCCESS) {
}
return (ret);
}
/*
* dsym_get_type_id(): given a type string, return the associated type id.
*
* input: const char *: the type name
* dsym_cdtype_t *: the return location for the id
* boolean_t: case-sensitive name compare
* output: int: DSYM_SUCCESS or DSYM_INVALID_TYPE
*/
{
int ret;
if (ret == DSYM_SUCCESS) {
}
return (ret);
}