backend.c 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
*/
/*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/** HISTORY
* 5-15-96 Jerry Yeung replace the Integer to Integer*
* 5-20-96 Jerry Yeung add default_sec_config_file
* 8-23-96 Jerry Yeung change the default path
* 8-27-96 Jerry Yeung change oid_string
* 9-06-96 Jiten Gaitonde change cmd line usage
* 10-21-96 Jerry Yeung fix template-code
*/
#include <stdio.h>
#include <ctype.h>
#include "impl.h"
#include "error.h"
#include "asn1.h"
#include "parse.h"
#define OBJECT 1
#define COLUMN 2
#define NODE 3
#define TABLE 4
#define ENTRY 5
#define SET_PRINT_ENTRY_BLOCK \
#define PRINT_GET_STRING_DUMBY_BLOCK \
#define PRINT_GET_OID_DUMBY_BLOCK \
#define PRINT_SET_CASE_BLOCK \
#define PRINT_GET_CASE_BLOCK \
/* trap support snmp oid */
extern int trace_level;
/*************************************************************************/
static void application_end();
static void init_tree_first_pass(struct tree *current, int *index, int *object_index, int *column_index, int *entry_index);
static void output_object_table(FILE *fp, struct tree *current, int *subid_index, int *enum_index, int *size);
static void output_column_table(FILE *fp, struct tree *current, int *subid_index, int *enum_index, int *size);
/*************************************************************************/
static void application_end()
{
}
/*************************************************************************/
static void print_usage()
{
exit(1);
#if 0
error_exit("Usage: mibcodegen -b SubagentName -f mib_1.txt [mib2.txt....] [-h]");
#endif
}
/*
* get the reverse-subid list from the given tree node
* len stores the number of subids
*/
{
*len=0 ;
parent = t;
while(parent){
}
}
/*************************************************************************/
int argc;
char *argv[];
{
int i;
int node_index;
int object_index;
int column_index;
int entry_index;
char *filep[50];
extern char * optarg;
extern int optind;
doit = 0;
mibcoreflag=0;
filep[0] = "/var/snmp/mib/mib_core.txt";
switch(opt) {
case 'b':
break;
case 'f':
mibcoreflag=1;
else
doit=1;
optind++) {
mibcoreflag=1;
else
doit = 1;
}
break;
case 'h':
default:
print_usage();
}
} /*end of while*/
print_usage();
/******
if(argc < 3)
{
print_usage();
}
base_name = (char *) malloc(strlen(argv[1]) + 1);
strcpy(base_name, argv[1]);
*******/
parse_init();
for(i = mibcoreflag; i < filecount; i++)
{
{
print_usage();
}
if(n == NULL)
{
}
else
{
{
nodes = n;
}
else
{
{
}
}
}
}
node_index = 0;
object_index = 0;
column_index = 0;
entry_index = 0;
exit(0);
}
/*************************************************************************/
/* Possible returned values: */
/* NODE, TABLE, ENTRY, OBJECT, COLUMN */
{
{
{
{
return COLUMN;
}
else
{
error_exit("get_node_type(): Inconsistent table definition: %s->%s->%s", tp->label, tp->parent->label, tp->parent->parent->label);
}
}
else
{
return OBJECT;
}
}
else
{
{
case TYPE_TABLE:
return TABLE;
case TYPE_ENTRY:
return ENTRY;
default:
return NODE;
}
}
return NODE; /*lint*/
}
/*************************************************************************/
/* we suppose that the tree is ordered according to the value of subid */
static void init_tree_first_pass(struct tree *current, int *node_index, int *object_index, int *column_index, int *entry_index)
{
int node_type;
/* node_index */
(*node_index)++;
/* node_type, object_index, column_index */
switch(node_type)
{
case OBJECT:
(*object_index)++;
break;
case COLUMN:
(*column_index)++;
break;
case NODE:
case TABLE:
break;
case ENTRY:
(*entry_index)++;
break;
default:
error_exit("init_tree_first_pass(): Unknown node type (%d) for node %s",
}
/* next FIRST PASS */
if(next)
{
/* current is not a leaf of the tree */
while(next->child_list)
{
}
}
else
{
/* current is a leaf of the tree */
while(parent)
{
/* the goal of this loop is to find an ancestor */
/* of current for which the subtree that contains */
/* current is not the last subtree */
/* is parent the last child? */
{
/* parent is the last child in the child*/
/* list of its parent, so go one step up*/
}
else
{
/* parent is not the last child in the */
/* child list of its parent */
break;
}
}
{
/* we found the last node of the MIB */
}
else
{
while(next->child_list)
{
}
}
}
{
}
}
/*************************************************************************/
{
int node_type;
struct index_list *indexs;
/* next SECOND PASS */
while(next)
{
{
{
break;
}
}
}
/* consistency of node_type COLUMN, ENTRY, TABLE */
{
case COLUMN:
{
error_exit("The node type (%d) of %s is not ENTRY although the node type of %s is COLUMN",
}
{
error_exit("The node type (%d) of %s is not TABLE although the node type of %s is COLUMN",
}
{
error_exit("The node %s of type COLUMN has some INDEXs!",
}
break;
case ENTRY:
{
error_exit("The node type (%d) of %s is not TABLE although the node type of %s is ENTRY",
}
/* n_indexs, indexs */
{
error_exit("The node %s of type ENTRY has no INDEX",
}
while(indexs)
{
{
error("WARNING: Can't match the INDEX %s of the entry %s",
}
else
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
case TYPE_OCTETSTR:
break;
default:
error("WARNING: The agent will not support the INDEX %s whose type %d for the entry %s",
}
}
}
break;
default:
/* n_indexs, indexs */
{
error_exit("The node %s of type %d has some INDEXs!",
}
break;
}
{
}
}
/*************************************************************************/
{
}
}
{
struct index_list *variables;
int index;
error_exit("output_trap_structure(): \
"\t\tSSASetVarIndx(\"%s\",%d);\n",
}
}
}
{
struct index_list *indexs;
{
case OBJECT:
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_extern_function(): Unknown type (%d) for %s",
}
}
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS: /*(5-15-95)*/
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_extern_function(): Unknown type (%d) for %s",
}
}
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS: /*(5-15-95)*/
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_extern_function(): Unknown type (%d) for %s",
}
}
break;
case COLUMN:
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS: /*(5-15-96)*/
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_extern_function(): Unknown type (%d) for %s",
}
/* not more ind. index */
if(indexs)
{
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
"index");
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
"index");
break;
case TYPE_OBJID:
"index");
break;
default:
error_exit("output_extern_function(): Unknown type (%d) for %s",
}
}
else
{
error("WARNING: By default, the type of INDEX %s set to INTEGER",
"index");
}
}
}
{
/* not more ind. index */
if(indexs)
{
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
"index");
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
"index");
break;
case TYPE_OBJID:
"index");
break;
default:
error_exit("output_extern_function(): Unknown type (%d) for %s",
}
}
else
{
error("WARNING: By default, the type of INDEX %s set to INTEGER",
"index");
}
}
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS: /*(5-15-96)*/
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_extern_function(): Unknown type (%d) for %s",
}
}
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS: /*(5-15-95)*/
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_extern_function(): Unknown type (%d) for %s",
}
}
break;
case ENTRY:
/* no more ind. index */
if(indexs)
{
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
"index");
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
"index");
break;
case TYPE_OBJID:
"index");
default:
error_exit("output_extern_function(): Unknown type (%d) for %s",
}
}
else
{
error("WARNING: By default, the type of INDEX %s set to INTEGER",
"index");
}
}
break;
}
{
}
}
/*************************************************************************/
{
{
{
"NULL",
}
else
{
(*enum_index) + 1,
}
(*enum_index)++;
}
{
}
}
/*************************************************************************/
{
int len = 0;
int i;
{
*subid_index);
while(parent)
{
}
(*subid_index)++;
for(i = len - 2; i >= 0; i--)
{
(*subid_index)++;
}
}
{
}
}
/*************************************************************************/
static void output_object_table(FILE *fp, struct tree *current, int *subid_index, int *enum_index, int *size)
{
int len;
{
/* name */
len = 0;
while(parent)
{
len++;
}
/* asn1_type */
{
case TYPE_INTEGER:
break;
case TYPE_COUNTER:
break;
case TYPE_GAUGE:
break;
case TYPE_TIMETICKS:
break;
case TYPE_OCTETSTR:
break;
case TYPE_IPADDR:
break;
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("Unknown ASN.1 type (%d) for object %s",
}
/* first_enum */
{
}
else
{
}
/* access */
{
}
else
{
}
else
{
}
else
{
}
/* type for trap fix */
/* get() */
{
}
else
{
}
/* set() */
{
}
else
{
}
/* dealloc() */
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
break;
default:
}
}
else
{
}
(*size)++;
}
{
while(parent)
{
(*subid_index)++;
}
}
{
(*enum_index)++;
}
{
}
}
/*************************************************************************/
{
struct index_list *indexs;
{
{
{
"NULL",
}
else
{
(*index_index) + 1,
}
}
else
{
error("WARNING: node pointer for INDEX %s is NULL",
{
"NULL",
}
else
{
(*index_index) + 1,
}
}
(*index_index)++;
}
{
}
}
/*************************************************************************/
{
{
struct index_list *indexs;
/* first_index, n_indexs */
{
(*index_index)++;
}
/* get() */
/* dealloc() */
(*size)++;
}
{
}
}
/*************************************************************************/
static void output_column_table(FILE *fp, struct tree *current, int *subid_index, int *enum_index, int *size)
{
{
int offset;
int len;
/* name */
len = 0;
while(parent)
{
len++;
}
/* asn1_type */
{
case TYPE_INTEGER:
break;
case TYPE_COUNTER:
break;
case TYPE_GAUGE:
break;
case TYPE_TIMETICKS:
break;
case TYPE_OCTETSTR:
break;
case TYPE_IPADDR:
break;
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("Unknown ASN.1 type (%d) for object %s",
}
/* first_enum */
{
}
else
{
}
/* access */
{
}
else
{
}
else
{
}
else
{
}
/* type for trap fix */
/* get() */
{
}
else
{
}
/* set() */
{
}
else
{
}
/* table */
/* offset */
offset = 0;
{
{
continue;
}
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_column_table(): Unknown type (%d) for %s",
}
}
(*size)++;
}
{
while(parent)
{
(*subid_index)++;
}
}
{
(*enum_index)++;
}
{
}
}
/*************************************************************************/
{
/* parent */
{
}
else
{
}
/* first_child */
{
}
else
{
}
/* next_peer */
{
}
else
{
}
/* next */
{
}
else
{
}
/* label, subid */
/* type, data */
{
case OBJECT:
break;
case COLUMN:
break;
case NODE:
case TABLE:
case ENTRY:
break;
default:
error_exit("Unknown node type (%d) for %s",
}
(*size)++;
{
}
}
/*************************************************************************/
{
char pathname[MAXPATHLEN];
char backup_pathname[MAXPATHLEN];
int subid_index;
int enum_index;
int index_index;
int size;
{
}
}
{
}
subid_index = 0;
enum_index = 0;
subid_index = 0;
enum_index = 0;
size = 0;
index_index = 0;
size = 0;
index_index = 0;
subid_index = 0;
enum_index = 0;
size = 0;
size = 0;
}
/*************************************************************************/
{
struct tree *t;
{
return current;
}
{
if(t != NULL)
{
return t;
}
}
return NULL;
}
/*************************************************************************/
{
{
{
{
continue;
}
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_structure(): Unknown type (%d) for %s",
}
}
}
{
}
}
/*************************************************************************/
{
char pathname[MAXPATHLEN];
char backup_pathname[MAXPATHLEN];
int i;
{
}
}
{
}
for(i = 0; base_name[i] != '\0'; i++)
{
}
for(i = 0; base_name[i] != '\0'; i++)
{
}
}
/*************************************************************************/
{
int i,j,len;
/* find the enterprise_subids */
for(j=0,i=len-1;i>=0;i--,j++)
}
{
int i, enterprise_trap;
struct index_list *var;
int numCallItem = 0;
int numTrapElem = 0;
int *trapTableMap = NULL;
int variableExist, columnExist = 0;
numTrapElem++;
numCallItem++;
}
if (numTrapElem > 0) {
if (!trapTableMap)
error_exit("malloc failed");
}
if (numCallItem > 0)
numCallItem+10);
else
numCallItem+10);
numCallItem = 0;
numTrapElem = 0;
variableExist = 0;
variableExist = 1;
error_exit("output_trap_structure():Unknown \
tp->object_index);
else
columnExist = 1;
"\t{(Object *)&column_table[%d],",
tp->column_index);
} else
error_exit("variable: %s is not\
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("unknown object type of \
}
numCallItem++;
else
}
if (variableExist == 0)
numTrapElem++;
}
/* dumby the map */
if (numTrapElem > 0)
else
}
if (numTrapElem > 0)
numTrapElem + 10);
else
numTrapElem+10);
else
for (i = 0; i < 8; i++) {
}
} else {
}
for (i = 0; i < 7; i++) {
break;
}
}
if (enterprise_trap) {
} else {
}
}
/* For arbitrary length enterprise OID in traps - bug 4133978 */
/* Initializing new trap enterprise info which handles arbitrary subids */
if (numTrapElem > 0)
"struct TrapAnyEnterpriseInfo genTrapAnyEnterpriseInfo[%d] = {\n",
numTrapElem + 10);
else
}
}
if (numTrapElem == 0)
return;
if (columnExist != 0) {
index = 0;
index++;
}
}
}
}
}
}
}
index = 0;
"\t{1,1,&Indx[%d].index},\n", index++);
} else
error_exit("variable: %s is not \
}
}
trapTableMap[idx]);
}
if (numTrapElem > 0) {
"\ttrapAnyEnterpriseInfo = genTrapAnyEnterpriseInfo;\n");
/* SSASendTrap4 handles tabular column elements - 4519879 */
(_SSASendTrap4(name, CallTrapIndx[i].pindex_obj)); \n");
}
}
{
struct index_list *indexs;
{
case COLUMN:
{
break;
}
break;
case ENTRY:
/* open a new file */
break;
}
{
case COLUMN:
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS: /*(5-15-96)*/
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_extern_function(): Unknown type (%d) for %s",
}
/* not more ind. index */
if(indexs)
{
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
"index");
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
"index");
break;
case TYPE_OBJID:
"index");
break;
default:
error_exit("output_extern_function(): Unknown type (%d) for %s",
}
}
else
{
error("WARNING: By default, the type of INDEX %s set to INTEGER",
"index");
}
}
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_TIMETICKS:
case TYPE_GAUGE:
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_extern_function(): Unknown type (%d) for %s",
}
}
{
/* no more ind. index */
if(indexs)
{
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
case TYPE_OBJID:
"index");
break;
default:
error_exit("output_function(): Unknown type (%d) for %s",
}
}
else
{
error("WARNING: By default, the type of INDEX %s set to INTEGER",
}
}
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS: /*(5-15-96)*/
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_function(): Unknown type (%d) for %s",
}
}
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS: /*(5-15-95)*/
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_extern_function(): Unknown type (%d) for %s",
}
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_function(): Unknown type (%d) for %s",
}
}
break;
case ENTRY:
/* no more ind. index */
if(indexs)
{
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
case TYPE_OBJID:
"index");
break;
default:
error_exit("output_function(): Unknown type (%d) for %s",
}
}
else
{
error("WARNING: By default, the type of INDEX %s set to INTEGER",
}
}
{
continue;
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
case TYPE_OBJID:
if(first_time_entry_print==1){
}else{
}
if(first_time_entry_print==1)
else
break;
default:
error_exit("output_function(): Unknown type (%d) for %s",
}
}
{
continue;
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
case TYPE_OBJID:
break;
default:
error_exit("output_function(): Unknown type (%d) for %s",
}
}
break;
}
{
}
}
{
{
case OBJECT:
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
}
}
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS: /*(5-15-96)*/
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
}
}
{
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_function(): Unknown type (%d) for %s",
}
{
case TYPE_INTEGER:
case TYPE_COUNTER:
case TYPE_GAUGE:
case TYPE_TIMETICKS:
break;
case TYPE_OCTETSTR:
case TYPE_IPADDR:
case TYPE_OPAQUE:
break;
case TYPE_OBJID:
break;
default:
error_exit("output_function(): Unknown type (%d) for %s",
}
}
break;
}
{
}
}
/*************************************************************************/
{
char pathname[MAXPATHLEN];
char backup_pathname[MAXPATHLEN];
{
}
}
{
}
return(fp);
}
{
}
{
}
{
}