/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* After having been declared, events, FMRIs and authorities must be defined
* (instantiated) before they can be used as the subjects of commands.
*/
#include <sys/sysmacros.h>
#include <libnvpair.h>
#include <string.h>
#include <assert.h>
#include <inj_event.h>
#include <inj_err.h>
#include <inj_lex.h>
#include <inj_string.h>
#include <inj.h>
static int inj_defns_initialized;
/* Intrinsics (signed and unsigned integer integer constants) */
typedef struct intr {
} intr_t;
static inj_hash_t *
{
int i;
if (!inj_defns_initialized) {
for (i = 0; i < sizeof (inj_defns) / sizeof (inj_hash_t); i++)
inj_strhash_create(&inj_defns[i]);
}
}
{
inj_var_t *v;
return (NULL);
return (inj_hash_get_cookie(v));
}
static void
{
inj_defnmem_t *n;
for (/* */; m != NULL; m = n) {
n = inj_list_next(m);
switch (m->dfm_type) {
case DEFNMEM_ARRAY:
case DEFNMEM_LIST:
break;
default:
inj_strfree(m->dfm_str);
}
}
}
void
{
}
static inj_defnmem_t *
{
return (dfm);
}
{
return (dfm);
}
{
return (dfm);
}
{
return (defn);
}
void
{
}
/*
* Validate the dimensions of an array. If the declared array size was zero,
* accept (and return) whatever the definition used. If fewer cells were
* defined than were declared, return the declared size - the calling code will
* fill the remaining cells with zeros. The definition of more than the
* declared number of cells triggers an error. We print and error message in
* this case and return the declared number. This will allow processing to
* continue. The act of emitting the error will guarantee that we never
* pass from parsing to program execution.
*/
static size_t
{
inj_list_t *l;
l = inj_list_next(l), dfnelems++);
yyerror(" %d: defined array has %d elements, expected %d\n",
}
}
/*
* The inj_defn_memcmp_* routines serve two purposes. First, they compare a
* given defined member with the corresponding declared member, signalling an
* error if the two are incompatible.
*
* Assuming that validation succeeds, an entry is added to the passed nvlist
* for the defined member.
*/
/* Used to ease signed and unsigned integer validation */
{ 0, 0 }, /* MEMTYPE_UNKNOWN */
{ 1, 8 }, { 1, 16 }, { 1, 32 }, { 1, 64 },
{ 0, 8 }, { 0, 16 }, { 0, 32 }, { 0, 64 }
};
static int
{
return (inj_set_errno(EINVAL));
return (-1); /* errno is set for us */
case MEMTYPE_INT8:
break;
case MEMTYPE_INT16:
break;
case MEMTYPE_INT32:
break;
case MEMTYPE_INT64:
}
if (errno != 0)
return (0);
}
static int
{
return (inj_set_errno(EINVAL));
return (-1); /* errno is set for us */
case MEMTYPE_UINT8:
break;
case MEMTYPE_UINT16:
break;
case MEMTYPE_UINT32:
break;
case MEMTYPE_UINT64:
}
if (errno != 0)
return (0);
}
/* Validate an array of (un)signed integers. */
static int
{
typedef int (*adder_t)();
};
NULL,
};
union {
char *a;
} a;
int err = 0;
int i;
return (inj_set_errno(EINVAL));
/*
* Each nvlist array adder wants an array of its own type as input,
* which is reasonable, but it complicates our general implementation.
* We fight back with casting magic.
*/
yyerror(" %d: array cell %d is invalid\n",
dfm->dfm_lineno, i);
err++;
continue;
}
&val) < 0) {
yyerror(" %d: array cell %d %s\n",
"out of range for type" : "invalid"));
err++;
continue;
}
case 8:
break;
case 16:
break;
case 32:
break;
default:
}
} else {
&val) < 0) {
yyerror(" %d: array cell %d %s\n",
"out of range for type" : "invalid"));
err++;
continue;
}
case 8:
break;
case 16:
break;
case 32:
break;
default:
}
}
}
if (err != 0)
return (inj_set_errno(EINVAL));
return (0);
}
static int
{
*valp = 1;
*valp = 0;
else
return (-1);
return (0);
}
static int
{
return (inj_set_errno(EINVAL));
return (inj_set_errno(EINVAL));
val)) != 0)
return (0);
}
static int
{
int err = 0;
int i;
return (inj_set_errno(EINVAL));
yyerror(" %d: array cell %d is invalid\n",
err++;
continue;
}
return (inj_set_errno(EINVAL));
}
return (0);
}
/* Used for both strings and enums */
static int
{
"string");
return (inj_set_errno(EINVAL));
return (0);
}
static int
{
"string");
const char **arr;
int err = 0;
int i;
return (inj_set_errno(EINVAL));
yyerror(" %d: array cell %d is invalid\n",
err++;
continue;
}
NULL) {
yyerror(" %d: invalid enum value %s\n",
err++;
continue;
}
}
return (0);
}
/*
* Validator for embedded lists (events, fmris, authorities, lists, etc.).
* There are two cases to deal with here. The user could either have provided
* the name of a previously-defined list, in which case we just make a copy of
* said list for insertion into ours. Alternatively, the user could simply
* define a new list here. In that case, we recursively invoke the member
* comparator, but against the list type for the member being defined.
*/
/* Embedded definition */
static nvlist_t *
{
}
/* Reference to previously-defined thing */
static nvlist_t *
{
(void) inj_set_errno(EINVAL);
return (NULL);
}
(void) inj_set_errno(EINVAL);
return (NULL);
}
die("failed to duplicate %s list %s",
}
return (new);
}
static nvlist_t *
{
if (dftype == DEFNMEM_LIST)
else
(void) inj_set_errno(EINVAL);
return (new);
}
/* A single sub-list */
static int
{
return (-1); /* errno is set for us */
new)) != 0)
return (0);
}
/* An array of sub-lists (for example, an array of events of a given type) */
static int
{
int err = 0;
int i;
return (inj_set_errno(EINVAL));
yyerror(" %d: array cell %d is invalid\n",
err++;
continue;
}
}
return (0);
}
/*
* The declaration-definition member comparator. Designed to recursive
* invocation to allow for the validation of embedded/referenced lists.
*/
nvlist_t *
{
int err = 0;
die("failed to allocate nvl for event");
case MEMTYPE_INT8:
case MEMTYPE_INT16:
case MEMTYPE_INT32:
case MEMTYPE_INT64:
nvl);
} else {
nvl);
}
break;
case MEMTYPE_UINT8:
case MEMTYPE_UINT16:
case MEMTYPE_UINT32:
case MEMTYPE_UINT64:
nvl);
} else {
nvl);
}
break;
case MEMTYPE_BOOL:
else
break;
case MEMTYPE_STRING:
nvl);
} else
break;
case MEMTYPE_ENUM:
nvl);
} else
break;
case MEMTYPE_EVENT:
case MEMTYPE_FMRI:
case MEMTYPE_AUTH:
case MEMTYPE_LIST:
else
break;
default:
die("unknown decl member type %d on member %s\n",
}
if (rc < 0) {
err++;
}
}
dlnmem++;
}
dfnmem++;
}
err++;
}
if (err > 0) {
return (NULL);
}
return (nvl);
}
/*
* The members have all been defined. Validate the members against the
* declaration, and add it to the appropriate "defined" list.
*/
void
{
inj_var_t *v;
return;
}
return;
}
if (type == ITEMTYPE_EVENT) {
}
yyerror("duplicate %s name %s (other on line %d)\n",
return;
}
}