📄 parse.c
字号:
//==========================================================================
//
// ./lib/current/src/parse.c
//
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//####UCDSNMPCOPYRIGHTBEGIN####
//
// -------------------------------------------
//
// Portions of this software may have been derived from the UCD-SNMP
// project, <http://ucd-snmp.ucdavis.edu/> from the University of
// California at Davis, which was originally based on the Carnegie Mellon
// University SNMP implementation. Portions of this software are therefore
// covered by the appropriate copyright disclaimers included herein.
//
// The release used was version 4.1.2 of May 2000. "ucd-snmp-4.1.2"
// -------------------------------------------
//
//####UCDSNMPCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): hmt
// Contributors: hmt
// Date: 2000-05-30
// Purpose: Port of UCD-SNMP distribution to eCos.
// Description:
//
//
//####DESCRIPTIONEND####
//
//==========================================================================
/********************************************************************
Copyright 1989, 1991, 1992 by Carnegie Mellon University
Derivative Work -
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
All Rights Reserved
Permission to use, copy, modify and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appears in all copies and
that both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU and The Regents of
the University of California not be used in advertising or publicity
pertaining to distribution of the software without specific written
permission.
CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL CMU OR
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*********************************************************************/
/*
* parse.c
*
* Update: 1998-09-22 <mslifcak@iss.net>
* Clear nbuckets in init_node_hash.
* New method xcalloc returns zeroed data structures.
* New method alloc_node encapsulates common node creation.
* New method to configure terminate comment at end of line.
* New method to configure accept underscore in labels.
*
* Update: 1998-10-10 <daves@csc.liv.ac.uk>
* fully qualified OID parsing patch
*
* Update: 1998-10-20 <daves@csc.liv.ac.uk>
* merge_anon_children patch
*
* Update: 1998-10-21 <mslifcak@iss.net>
* Merge_parse_objectid associates information with last node in chain.
*/
/******************************************************************
Copyright 1989, 1991, 1992 by Carnegie Mellon University
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#include <config.h>
#include <snmp_logging.h>
#include <stdio.h>
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#include <ctype.h>
#include <sys/types.h>
#ifndef __ECOS
#include <sys/stat.h>
#endif
/* Wow. This is ugly. -- Wes */
#if HAVE_DIRENT_H
# include <dirent.h>
# define NAMLEN(dirent) strlen((dirent)->d_name)
#else
# define dirent direct
# define NAMLEN(dirent) (dirent)->d_namlen
# if HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
# if HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
# if HAVE_NDIR_H
# include <ndir.h>
# endif
#endif
#if HAVE_WINSOCK_H
#include <winsock.h>
#endif
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#if defined(HAVE_REGEX_H) && defined(HAVE_REGCOMP)
#include <regex.h>
#endif
#if HAVE_DMALLOC_H
#include <dmalloc.h>
#endif
#include "system.h"
#include "parse.h"
#include "asn1.h"
#include "mib.h"
#include "snmp_api.h"
#include "snmp_debug.h"
#include "snmp_logging.h"
#include "default_store.h"
#include "tools.h"
/*
* This is one element of an object identifier with either an integer
* subidentifier, or a textual string label, or both.
* The subid is -1 if not present, and label is NULL if not present.
*/
struct subid_s {
int subid;
int modid;
char *label;
};
#define MAXTC 1024
struct tc { /* textual conventions */
int type;
int modid;
char *descriptor;
char *hint;
struct enum_list *enums;
struct range_list *ranges;
} tclist[MAXTC];
int Line = 0;
const char *File = "(none)";
static int anonymous = 0;
#define SYNTAX_MASK 0x80
/* types of tokens
Tokens wiht the SYNTAX_MASK bit set are syntax tokens */
#define CONTINUE -1
#define ENDOFFILE 0
#define LABEL 1
#define SUBTREE 2
#define SYNTAX 3
#define OBJID (4 | SYNTAX_MASK)
#define OCTETSTR (5 | SYNTAX_MASK)
#define INTEGER (6 | SYNTAX_MASK)
#define INTEGER32 INTEGER
#define NETADDR (7 | SYNTAX_MASK)
#define IPADDR (8 | SYNTAX_MASK)
#define COUNTER (9 | SYNTAX_MASK)
#define GAUGE (10 | SYNTAX_MASK)
#define TIMETICKS (11 | SYNTAX_MASK)
#define KW_OPAQUE (12 | SYNTAX_MASK)
#define NUL (13 | SYNTAX_MASK)
#define SEQUENCE 14
#define OF 15 /* SEQUENCE OF */
#define OBJTYPE 16
#define ACCESS 17
#define READONLY 18
#define READWRITE 19
#define WRITEONLY 20
#define NOACCESS 21
#define STATUS 22
#define MANDATORY 23
#define KW_OPTIONAL 24
#define OBSOLETE 25
/* #define RECOMMENDED 26 */
#define PUNCT 27
#define EQUALS 28
#define NUMBER 29
#define LEFTBRACKET 30
#define RIGHTBRACKET 31
#define LEFTPAREN 32
#define RIGHTPAREN 33
#define COMMA 34
#define DESCRIPTION 35
#define QUOTESTRING 36
#define INDEX 37
#define DEFVAL 38
#define DEPRECATED 39
#define SIZE 40
#define BITSTRING (41 | SYNTAX_MASK)
#define NSAPADDRESS (42 | SYNTAX_MASK)
#define COUNTER64 (43 | SYNTAX_MASK)
#define OBJGROUP 44
#define NOTIFTYPE 45
#define AUGMENTS 46
#define COMPLIANCE 47
#define READCREATE 48
#define UNITS 49
#define REFERENCE 50
#define NUM_ENTRIES 51
#define MODULEIDENTITY 52
#define LASTUPDATED 53
#define ORGANIZATION 54
#define CONTACTINFO 55
#define UINTEGER32 (56 | SYNTAX_MASK)
#define CURRENT 57
#define DEFINITIONS 58
#define END 59
#define SEMI 60
#define TRAPTYPE 61
#define ENTERPRISE 62
/* #define DISPLAYSTR (63 | SYNTAX_MASK) */
#define BEGIN 64
#define IMPORTS 65
#define EXPORTS 66
#define ACCNOTIFY 67
#define BAR 68
#define RANGE 69
#define CONVENTION 70
#define DISPLAYHINT 71
#define FROM 72
#define CAPABILITIES 73
#define MACRO 74
#define IMPLIED 75
struct tok {
const char *name; /* token name */
int len; /* length not counting nul */
int token; /* value */
int hash; /* hash of name */
struct tok *next; /* pointer to next in hash table */
};
static struct tok tokens[] = {
{ "obsolete", sizeof ("obsolete")-1, OBSOLETE },
{ "Opaque", sizeof ("Opaque")-1, KW_OPAQUE },
{ "optional", sizeof ("optional")-1, KW_OPTIONAL },
{ "LAST-UPDATED", sizeof ("LAST-UPDATED")-1, LASTUPDATED },
{ "ORGANIZATION", sizeof ("ORGANIZATION")-1, ORGANIZATION },
{ "CONTACT-INFO", sizeof ("CONTACT-INFO")-1, CONTACTINFO },
{ "MODULE-IDENTITY", sizeof ("MODULE-IDENTITY")-1, MODULEIDENTITY },
{ "MODULE-COMPLIANCE", sizeof ("MODULE-COMPLIANCE")-1, COMPLIANCE },
{ "DEFINITIONS", sizeof("DEFINITIONS")-1, DEFINITIONS},
{ "END", sizeof("END")-1, END},
{ "AUGMENTS", sizeof ("AUGMENTS")-1, AUGMENTS },
{ "not-accessible", sizeof ("not-accessible")-1, NOACCESS },
{ "write-only", sizeof ("write-only")-1, WRITEONLY },
{ "NsapAddress", sizeof("NsapAddress")-1, NSAPADDRESS},
{ "UNITS", sizeof("Units")-1, UNITS},
{ "REFERENCE", sizeof("REFERENCE")-1, REFERENCE},
{ "NUM-ENTRIES", sizeof("NUM-ENTRIES")-1, NUM_ENTRIES},
{ "BITSTRING", sizeof("BITSTRING")-1, BITSTRING},
{ "BIT", sizeof("BIT")-1, CONTINUE},
{ "BITS", sizeof("BITS")-1, BITSTRING},
{ "Counter64", sizeof("Counter64")-1, COUNTER64},
{ "TimeTicks", sizeof ("TimeTicks")-1, TIMETICKS },
{ "NOTIFICATION-TYPE", sizeof ("NOTIFICATION-TYPE")-1, NOTIFTYPE },
{ "OBJECT-GROUP", sizeof ("OBJECT-GROUP")-1, OBJGROUP },
{ "OBJECT-IDENTITY", sizeof ("OBJECT-IDENTITY")-1, OBJGROUP },
{ "OBJECTIDENTIFIER", sizeof ("OBJECTIDENTIFIER")-1, OBJID },
{ "OBJECT", sizeof ("OBJECT")-1, CONTINUE },
{ "NetworkAddress", sizeof ("NetworkAddress")-1, NETADDR },
{ "Gauge", sizeof ("Gauge")-1, GAUGE },
{ "Gauge32", sizeof ("Gauge32")-1, GAUGE },
{ "Unsigned32", sizeof ("Unsigned32")-1, GAUGE },
{ "read-write", sizeof ("read-write")-1, READWRITE },
{ "read-create", sizeof ("read-create")-1, READCREATE },
{ "OCTETSTRING", sizeof ("OCTETSTRING")-1, OCTETSTR },
{ "OCTET", sizeof ("OCTET")-1, CONTINUE },
{ "OF", sizeof ("OF")-1, OF },
{ "SEQUENCE", sizeof ("SEQUENCE")-1, SEQUENCE },
{ "NULL", sizeof ("NULL")-1, NUL },
{ "IpAddress", sizeof ("IpAddress")-1, IPADDR },
{ "UInteger32", sizeof ("UInteger32")-1, UINTEGER32 },
{ "INTEGER", sizeof ("INTEGER")-1, INTEGER },
{ "Integer32", sizeof ("Integer32")-1, INTEGER32 },
{ "Counter", sizeof ("Counter")-1, COUNTER },
{ "Counter32", sizeof ("Counter32")-1, COUNTER },
{ "read-only", sizeof ("read-only")-1, READONLY },
{ "DESCRIPTION", sizeof ("DESCRIPTION")-1, DESCRIPTION },
{ "INDEX", sizeof ("INDEX")-1, INDEX },
{ "DEFVAL", sizeof ("DEFVAL")-1, DEFVAL },
{ "deprecated", sizeof ("deprecated")-1, DEPRECATED },
{ "SIZE", sizeof ("SIZE")-1, SIZE },
{ "MAX-ACCESS", sizeof ("MAX-ACCESS")-1, ACCESS },
{ "ACCESS", sizeof ("ACCESS")-1, ACCESS },
{ "mandatory", sizeof ("mandatory")-1, MANDATORY },
{ "current", sizeof ("current")-1, CURRENT },
{ "STATUS", sizeof ("STATUS")-1, STATUS },
{ "SYNTAX", sizeof ("SYNTAX")-1, SYNTAX },
{ "OBJECT-TYPE", sizeof ("OBJECT-TYPE")-1, OBJTYPE },
{ "TRAP-TYPE", sizeof ("TRAP-TYPE")-1, TRAPTYPE },
{ "ENTERPRISE", sizeof ("ENTERPRISE")-1, ENTERPRISE },
{ "BEGIN", sizeof ("BEGIN")-1, BEGIN },
{ "IMPORTS", sizeof ("IMPORTS")-1, IMPORTS },
{ "EXPORTS", sizeof ("EXPORTS")-1, EXPORTS },
{ "accessible-for-notify", sizeof ("accessible-for-notify")-1, ACCNOTIFY },
{ "TEXTUAL-CONVENTION", sizeof ("TEXTUAL-CONVENTION")-1, CONVENTION },
{ "NOTIFICATION-GROUP", sizeof ("NOTIFICATION-GROUP")-1, NOTIFTYPE },
{ "DISPLAY-HINT", sizeof ("DISPLAY-HINT")-1, DISPLAYHINT },
{ "FROM", sizeof ("FROM")-1, FROM },
{ "AGENT-CAPABILITIES", sizeof ("AGENT-CAPABILITIES")-1, CAPABILITIES },
{ "MACRO", sizeof ("MACRO")-1, MACRO },
{ "IMPLIED", sizeof ("IMPLIED")-1, IMPLIED },
{ NULL }
};
static struct module_compatability *module_map_head;
static struct module_compatability module_map[] = {
{ "RFC1065-SMI", "RFC1155-SMI", NULL, 0},
{ "RFC1066-MIB", "RFC1156-MIB", NULL, 0},
/* 'mib' -> 'mib-2' */
{ "RFC1156-MIB", "RFC1158-MIB", NULL, 0},
/* 'snmpEnableAuthTraps' -> 'snmpEnableAuthenTraps' */
{ "RFC1158-MIB", "RFC1213-MIB", NULL, 0},
/* 'nullOID' -> 'zeroDotZero' */
{ "RFC1155-SMI", "SNMPv2-SMI", NULL, 0},
{ "RFC1213-MIB", "SNMPv2-SMI", "mib-2", 0},
{ "RFC1213-MIB", "SNMPv2-MIB", "sys", 3},
{ "RFC1213-MIB", "IF-MIB", "if", 2},
{ "RFC1213-MIB", "IP-MIB", "ip", 2},
{ "RFC1213-MIB", "IP-MIB", "icmp", 4},
{ "RFC1213-MIB", "TCP-MIB", "tcp", 3},
{ "RFC1213-MIB", "UDP-MIB", "udp", 3},
{ "RFC1213-MIB", "SNMPv2-SMI", "transmission", 0},
{ "RFC1213-MIB", "SNMPv2-MIB", "snmp", 4},
{ "RFC1271-MIB", "RMON-MIB", NULL, 0},
{ "RFC1286-MIB", "SOURCE-ROUTING-MIB", "dot1dSr", 7},
{ "RFC1286-MIB", "BRIDGE-MIB", NULL, 0},
{ "RFC1315-MIB", "FRAME-RELAY-DTE-MIB", NULL, 0},
{ "RFC1316-MIB", "CHARACTER-MIB", NULL, 0},
};
#define MODULE_NOT_FOUND 0
#define MODULE_LOADED_OK 1
#define MODULE_ALREADY_LOADED 2
/* #define MODULE_LOAD_FAILED 3 */
#define MODULE_LOAD_FAILED MODULE_NOT_FOUND
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -