/*
* 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
*/
/*
* Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* MODULE: dat_sr_parser.c
*
* PURPOSE: static registry parser
*
* $Id: udat_sr_parser.c,v 1.1 2003/07/31 14:04:19 jlentini Exp $
*/
#include "udat_sr_parser.h"
#include "dat_sr.h"
/*
*
* Constants
*
*/
/*
*
* Enumerations
*
*/
typedef enum
{
typedef enum
{
/*
*
* Structures
*
*/
typedef struct
{
} DAT_SR_TOKEN;
typedef struct DAT_SR_STACK_NODE
{
typedef struct
{
typedef struct
{
char *id;
typedef struct
{
typedef struct
{
char *ia_name;
char *lib_path;
char *ia_params;
char *platform_params;
/*
*
* Internal Function Declarations
*
*/
static DAT_RETURN
static DAT_BOOLEAN
static char *
static DAT_RETURN
DAT_OS_FILE *file);
static DAT_RETURN
DAT_OS_FILE *file);
static DAT_RETURN
static DAT_RETURN
static DAT_RETURN
static DAT_RETURN
static DAT_RETURN
static DAT_RETURN
static DAT_RETURN
static DAT_RETURN
static DAT_RETURN
static DAT_RETURN
char *str,
static DAT_RETURN
char *str,
static DAT_RETURN
char *str,
static DAT_RETURN
char *str,
static DAT_RETURN
static DAT_RETURN
static DAT_RETURN
static DAT_RETURN
static DAT_RETURN
static void
DAT_OS_FILE *file);
/*
*
* Global Variables
*
*/
/*
*
* External Function Definitions
*
*/
/*
* Function: dat_sr_load
*/
dat_sr_load(void)
{
char *sr_path;
}
"DAT Registry: static registry file <%s> \n", sr_path);
return (DAT_INTERNAL_ERROR);
}
for (;;) {
break;
continue;
} else {
dat_os_assert(!"unable to parse static registry file");
break;
}
}
if (0 != dat_os_fclose(sr_file)) {
return (DAT_INTERNAL_ERROR);
}
return (DAT_SUCCESS);
}
/*
*
* Internal Function Definitions
*
*/
/*
* Function: dat_sr_is_valid_entry
*/
{
(entry->is_default)) {
return (DAT_TRUE);
} else {
return (DAT_FALSE);
}
}
/*
* Function: dat_sr_load_entry
*/
{
"DAT Registry: ia name %s is longer than "
"DAT_NAME_MAX_LENGTH (%i)\n",
return (DAT_INSUFFICIENT_RESOURCES);
}
"DAT Registry: loading provider for %s\n",
}
/*
* Function: dat_sr_type_to_str
*/
char *
{
return ("error: invalid token type");
}
}
/*
* Function: dat_sr_parse_eof
*/
{
return (DAT_INTERNAL_ERROR);
}
return (DAT_SUCCESS);
} else {
return (DAT_INTERNAL_ERROR);
}
}
/*
* Function: dat_sr_parse_ia_name
*/
{
"\n"
"DAT Registry: entry \n"
" ia_name %s\n"
" api_version\n"
" type 0x%X\n"
" major.minor %d.%d\n"
" is_thread_safe %d\n"
" is_default %d\n"
" lib_path %s\n"
" provider_version\n"
" id %s\n"
" major.minor %d.%d\n"
" ia_params %s\n"
"\n",
/*
* The static registry configuration file may have
* multiple entries with the same IA name. The first
* entry will be installed in the static registry
* causing subsequent attempts to register the same IA
* name to fail. Therefore the return code from
* dat_sr_load_entry() is ignored.
*/
(void) dat_sr_load_entry(&entry);
}
} else { /* resync */
/*
* The static registry format is specified in the DAT
* specification. While the registry file's contents may change
* between revisions of the specification, there is no way to
* determine the specification version to which the
* configuration file conforms. If an entry is found that does
* not match the expected format, the entry is discarded
* and the parsing of the file continues. There is no way to
* determine if the entry was an error or an entry confirming
* to an alternate version of specification.
*/
for (;;) {
break;
}
break;
} else {
(sizeof (char) *
continue;
}
}
}
/* free resources */
}
}
sizeof (char) *
}
}
return (status);
}
/*
* Function: dat_sr_parse_ia_name
*/
{
return (DAT_INTERNAL_ERROR);
}
} else {
}
if (DAT_SUCCESS != status) {
}
return (status);
}
/*
* Function: dat_sr_parse_ia_name
*/
{
return (DAT_INTERNAL_ERROR);
}
} else if (DAT_SUCCESS != dat_sr_convert_api(
} else {
}
if (DAT_SUCCESS != status) {
}
return (status);
}
/*
* Function: dat_sr_parse_thread_safety
*/
static DAT_RETURN
{
return (DAT_INTERNAL_ERROR);
}
} else if (DAT_SUCCESS != dat_sr_convert_thread_safety(
} else {
}
if (DAT_SUCCESS != status) {
}
return (status);
}
/*
* Function: dat_sr_parse_default
*/
{
return (DAT_INTERNAL_ERROR);
}
} else if (DAT_SUCCESS != dat_sr_convert_default(
} else {
}
if (DAT_SUCCESS != status) {
}
return (status);
}
/*
* Function: dat_sr_parse_lib_path
*/
{
return (DAT_INTERNAL_ERROR);
}
} else {
}
if (DAT_SUCCESS != status) {
}
return (status);
}
/*
* Function: dat_sr_parse_provider_version
*/
{
return (DAT_INTERNAL_ERROR);
}
} else if (DAT_SUCCESS != dat_sr_convert_provider_version(
} else {
}
if (DAT_SUCCESS != status) {
}
return (status);
}
/*
* Function: dat_sr_parse_ia_params
*/
{
return (DAT_INTERNAL_ERROR);
}
} else {
}
if (DAT_SUCCESS != status) {
}
return (status);
}
/*
* Function: dat_sr_parse_platform_params
*/
{
return (DAT_INTERNAL_ERROR);
}
} else {
}
if (DAT_SUCCESS != status) {
}
return (status);
}
/*
* Function: dat_sr_parse_eoe
*/
{
return (DAT_INTERNAL_ERROR);
}
} else {
}
if (DAT_SUCCESS != status) {
}
return (status);
}
/*
* Function: dat_sr_convert_api
*/
char *str,
{
int i;
int minor_i;
if ('u' == str[0]) {
} else if ('k' == str[0]) {
} else {
return (DAT_INTERNAL_ERROR);
}
if ('.' == str[i]) {
break;
return (DAT_INTERNAL_ERROR);
}
}
10);
/* move past '.' */
minor_i = ++i;
for (; '\0' != str[i]; i++) {
return (DAT_INTERNAL_ERROR);
}
}
NULL, 10);
if ('\0' != str[i]) {
return (DAT_INTERNAL_ERROR);
}
return (DAT_SUCCESS);
}
/*
* Function: dat_sr_convert_thread_safety
*/
static DAT_RETURN
char *str,
{
if (!dat_os_strncmp(str,
return (DAT_SUCCESS);
} else if (!dat_os_strncmp(str,
return (DAT_SUCCESS);
} else {
return (DAT_INTERNAL_ERROR);
}
}
/*
* Function: dat_sr_convert_default
*/
static DAT_RETURN
char *str,
{
if (!dat_os_strncmp(str,
*is_default = DAT_TRUE;
return (DAT_SUCCESS);
} else if (!dat_os_strncmp(str,
*is_default = DAT_FALSE;
return (DAT_SUCCESS);
} else {
return (DAT_INTERNAL_ERROR);
}
}
/*
* Function: dat_sr_convert_provider_version
*/
char *str,
{
int i;
int decimal_i;
for (i = 0; '\0' != str[i]; i++) {
if ('.' == str[i]) {
break;
}
}
/* if no id value was found */
if (0 == i) {
goto exit;
}
(i + 1)))) {
goto exit;
}
/* move past '.' */
decimal_i = ++i;
for (; '\0' != str[i]; i++) {
if ('.' == str[i]) {
break;
goto exit;
}
}
/* if no version value was found */
if (decimal_i == i) {
goto exit;
}
/* move past '.' */
decimal_i = ++i;
for (; '\0' != str[i]; i++) {
goto exit;
}
}
/* if no version value was found */
if (decimal_i == i) {
goto exit;
}
if ('\0' != str[i]) {
goto exit;
}
exit:
if (DAT_SUCCESS != status) {
sizeof (char) *
}
}
return (status);
}
/*
* Function: dat_sr_get_token
*/
{
if (NULL == g_token_stack) {
} else {
top = g_token_stack;
return (DAT_SUCCESS);
}
}
/*
* Function: dat_sr_put_token
*/
{
return (DAT_INSUFFICIENT_RESOURCES | DAT_RESOURCE_MEMORY);
}
g_token_stack = top;
return (DAT_SUCCESS);
}
/*
* Function: dat_sr_read_token
*/
{
/*
* The DAT standard does not specify a maximum size for quoted strings.
* Therefore the tokenizer must be able to read in a token of arbitrary
* size. Instead of allocating a fixed length buffer, the tokenizer
* first scans the input a single character at a time looking for the
* begining and end of the token. Once the these positions are found,
* the entire token is read into memory. By using this algorithm, the
* implementation does not place an arbitrary maximum on the token size.
*/
token_len = 0;
num_escape_seq = 0;
for (;;) {
int c;
/* if looking for start of the token */
if (0 == token_len) {
return (DAT_INTERNAL_ERROR);
}
}
c = dat_os_fgetc(file);
/* if looking for start of the token */
if (0 == token_len) {
if (EOF == c) {
goto success;
} else if (DAT_SR_CHAR_NEWLINE == c) {
goto success;
} else if (dat_os_isblank(c)) {
continue;
} else if (DAT_SR_CHAR_COMMENT == c) {
continue;
} else {
if (DAT_SR_CHAR_QUOTE == c) {
}
token_len++;
}
} else { /* looking for the end of the token */
if (EOF == c) {
break;
} else if (DAT_SR_CHAR_NEWLINE == c) {
/* put back the newline */
(void) dat_os_fungetc(file);
break;
} else if (!is_quoted_str && dat_os_isblank(c)) {
break;
} else {
token_len++;
if ((DAT_SR_CHAR_QUOTE == c) &&
break;
} else if ((DAT_SR_CHAR_BACKSLASH == c) &&
} else {
}
}
}
}
/* the token was a string */
return (DAT_INTERNAL_ERROR);
}
if (is_quoted_str) {
num_escape_seq)) {
return (DAT_INTERNAL_ERROR);
}
} else {
token_len)) {
return (DAT_INTERNAL_ERROR);
}
}
"\n"
"DAT Registry: token\n"
" type %s\n"
" value <%s>\n"
"\n",
return (DAT_SUCCESS);
}
/*
* Function: dat_sr_read_str
*/
{
/* +1 for null termination */
return (DAT_INSUFFICIENT_RESOURCES | DAT_RESOURCE_MEMORY);
}
return (DAT_INTERNAL_ERROR);
}
return (DAT_SUCCESS);
}
/*
* Function: dat_sr_read_quoted_str
*/
{
DAT_OS_SIZE i;
DAT_OS_SIZE j;
int c;
/* +1 for null termination */
goto exit;
}
/* throw away " */
goto exit;
}
for (i = 0, j = 0; i < str_len; i++) {
c = dat_os_fgetc(file);
if (EOF == c) {
goto exit;
} else if ((DAT_SR_CHAR_BACKSLASH == c) &&
} else {
j++;
}
}
/* throw away " */
goto exit;
}
exit:
if (DAT_SUCCESS != status) {
}
}
return (status);
}
/*
* Function: dat_sr_read_comment
*/
void
{
int c;
/* read up to an EOR or EOF to move past the comment */
do {
c = dat_os_fgetc(file);
} while ((DAT_SR_CHAR_NEWLINE != c) && (EOF != c));
/* put back the newline */
(void) dat_os_fungetc(file);
}