home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume30 / mibcc / part01 < prev    next >
Encoding:
Text File  |  1992-06-20  |  58.6 KB  |  2,037 lines

  1. Newsgroups: comp.sources.misc
  2. From: wegrzyn@nic.cerf.net (Chuck Wegrzyn)
  3. Subject:  v30i074:  mibcc - SNMP MIB Compiler, Part01/02
  4. Message-ID: <csm-v30i074=mibcc.124851@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 2b4a834a99d1f6f7285419a11dc44d3c
  6. Date: Sat, 20 Jun 1992 17:49:07 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: wegrzyn@nic.cerf.net (Chuck Wegrzyn)
  10. Posting-number: Volume 30, Issue 74
  11. Archive-name: mibcc/part01
  12. Environment: UNIX
  13.  
  14. Here is my MIB compiler; I place it in the public domain.
  15. Please check the README file for information about making
  16. it, running it and a little on the "insides."
  17.  
  18. Please don't put any copyright notices -- or copyleft notices
  19. on it. I did not place any restrictions on it, and I would
  20. not like to see any placed on it. Please honor my wishes.
  21.  
  22. Thanks, and have fun
  23. Chuck Wegrzyn
  24. ------------------------------ CUT HERE --------------------------
  25. #! /bin/sh
  26. # This is a shell archive.  Remove anything before this line, then feed it
  27. # into a shell via "sh file" or similar.  To overwrite existing files,
  28. # type "sh file -c".
  29. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  30. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  31. # Contents:  README AssignOBJECT.c AssignTRAP.c AssignTYPE.h main.c
  32. #   yacc.y
  33. # Wrapped by kent@sparky on Sat Jun 20 12:45:44 1992
  34. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  35. echo If this archive is complete, you will see the following message:
  36. echo '          "shar: End of archive 1 (of 2)."'
  37. if test -f 'README' -a "${1}" != "-c" ; then 
  38.   echo shar: Will not clobber existing file \"'README'\"
  39. else
  40.   echo shar: Extracting \"'README'\" \(4208 characters\)
  41.   sed "s/^X//" >'README' <<'END_OF_FILE'
  42. XIntroduction
  43. X------------
  44. X
  45. XThis is a MIB compiler that will read and parse MIBs according to
  46. XRFC-1212, Definition of a Concise MIB. It will also handle trap
  47. Xdefinitions if they are included (see RFC-1213 for the trap stuff).
  48. X
  49. XI release the code with no warranty and copyright -- I place it in
  50. Xthe public domain. Please honor my intentions by not placing a
  51. Xrestrictive copyright on it -- specifically the GNU copyleft statement
  52. Xor any others.
  53. X
  54. XLike all software, it probably has bugs in it. I have tried my best
  55. Xto find them and fix them. This software is a small part of the 
  56. XMotorola Codex SNMP Mgr. software which I wrote, and has been
  57. Xoperational for the last year and one-half. The compiler has been
  58. Xused on just about every MIB placed on venera.isi.edu, and appears
  59. Xto work. But, that said I am sure that there are bugs in there
  60. Xsomewhere. If you do find a problem or bug, please send me mail
  61. Xat
  62. X
  63. X        wegrzyn@cerf.net
  64. X
  65. Xand I will try my best to fix the problem. If you make any changes
  66. XI would appreciate receiving any changes. I will integrate them into
  67. Xthe system and re-issue the software. Of course, you can make any 
  68. Xchanges you wish and post them as well.
  69. X
  70. XBuilding the system
  71. X-------------------
  72. XFor some information about building the software. There is a MAKE
  73. Xfile called Makefile, that can be used to build the system. If you
  74. Xexamine Makefile you will find that CFLAGS has two possible formats:
  75. Xone for stdarg.h and the other for using varargs.h ... pick which
  76. Xever is appropriate. The software has been tested on a number of
  77. X5.4 systems and works. It has also been ported to HP/UX and works.
  78. X
  79. XAfter the program is built, you can call it MIBcompiler or MIBcheck.
  80. XIf the name MIBcheck is used, it will do a syntax/semantic check of
  81. Xthe MIB put will not ever call any database routines. If it is called
  82. XMIBcompiler, it will do the syntax/semantic check and possibly call
  83. Xthe database routines. A Mib is defined to have an extension of .my, 
  84. Xbut can really be anything.
  85. X
  86. X
  87. X
  88. XSome Internal stuff
  89. X-------------------
  90. X
  91. XThere are a number of statements allowed in a MIB. I will discuss each
  92. Xbriefly and tell you how each statement is processed.
  93. X
  94. XThere is an OID definition, that looks something like:
  95. X
  96. X               cisco  OBJECT IDENTIFIER ::= { enterprises 9 }
  97. X
  98. XThis statement is processed by a routine called ProcessOID() in the
  99. Xfile AssignOID.c. 
  100. X
  101. XAnother file is a TYPE definition, which looks something like:
  102. X
  103. X               LIfEntry ::=
  104. X                   SEQUENCE {
  105. X                       locIfLastIn
  106. X                           INTEGER,
  107. X                       locIfDelay
  108. X                           INTEGER,
  109. X                       locIfOutputQueueDrops
  110. X                           INTEGER
  111. X                   }
  112. X
  113. XThis statement, after parsing, is processed by routine ProcessType()
  114. Xin file AssignTYPE.c
  115. X
  116. XThe actual object definition, of which
  117. X
  118. X          ifEntry OBJECT-TYPE
  119. X              SYNTAX  IfEntry
  120. X              ACCESS  not-accessible
  121. X              STATUS  mandatory
  122. X              DESCRIPTION
  123. X                      "An interface entry containing objects at the
  124. X                      subnetwork layer and below for a particular
  125. X                      interface."
  126. X              INDEX   { ifIndex }
  127. X              ::= { ifTable 1 }
  128. X
  129. Xis an example, is processed by routine ProcessObject() in file AssignOBJECT.c.
  130. X
  131. XFinally, trap statements are processed by routine ProcessTrap() in file
  132. XAssignTRAP.c. An example of a trap statement is
  133. X
  134. X    coldStart TRAP-TYPE
  135. X        ENTERPRISE {snmp}
  136. X        DESCRIPTION "Cold start of the machine"
  137. X        ::= {1}
  138. X
  139. X
  140. XThe overall flow is that the system will run in up to two passes: all
  141. XOIDs and symbols that can be resolved in the first pass are processed 
  142. Xin the first pass. Anything that requires two passes is processed in
  143. Xthe second pass. Basically, if you define something before it is used,
  144. Xthe "thing" that uses it will be processed in the first pass. Something
  145. Xthat is used before it is defined, will be processed in the second
  146. Xpass.
  147. X
  148. XIn processing OIDs and TYPE statements, a linked list is kept and passed
  149. Xto the various routines.
  150. X
  151. X
  152. XOne last note -- I have tried to comment the code with meaningful
  153. Xinformation. I hope that I have succeeded....
  154. X
  155. XSincerely, Chuck Wegrzyn
  156. X
  157. X
  158. X
  159. X
  160. END_OF_FILE
  161.   if test 4208 -ne `wc -c <'README'`; then
  162.     echo shar: \"'README'\" unpacked with wrong size!
  163.   fi
  164.   # end of 'README'
  165. fi
  166. if test -f 'AssignOBJECT.c' -a "${1}" != "-c" ; then 
  167.   echo shar: Will not clobber existing file \"'AssignOBJECT.c'\"
  168. else
  169.   echo shar: Extracting \"'AssignOBJECT.c'\" \(17859 characters\)
  170.   sed "s/^X//" >'AssignOBJECT.c' <<'END_OF_FILE'
  171. X#include <stdio.h>
  172. X#include <stdlib.h>
  173. X#include <string.h>
  174. X
  175. X#include "oid.h"
  176. X
  177. X#include "MibCompiler.h"
  178. X#include "AssignOID.h"
  179. X#include "AssignOBJECT.h"
  180. X#include "symbol.h"
  181. X
  182. X
  183. Xextern int debug,bResolveOIDsNeeded,yyErrorCnt,nCheckOnly;
  184. Xextern int errno;
  185. X
  186. X
  187. XQUEUEOBJ *HeadObj = {0},*TailObj = {0};
  188. X
  189. X
  190. X/*
  191. X * SaveOID
  192. X *
  193. X * Save the compiled OID somewhere...You might want to write things
  194. X * out to a database, etc....
  195. X *
  196. X */
  197. Xint SaveOID(OIDINFO *pOID)
  198. X {
  199. X    int nRc = 0;
  200. X    /*
  201. X     * Return the outcome.
  202. X     */
  203. X    return(nRc);
  204. X }
  205. X
  206. X
  207. Xstatic void RegisterAs(char *pName,char *pOID,int type)
  208. X {
  209. X    SYMBOL *pSym;
  210. X    /*
  211. X     * Allocate space for the symbol.
  212. X     */
  213. X    pSym = (SYMBOL *) malloc(sizeof(SYMBOL));
  214. X    if( pSym )
  215. X             {
  216. X                /*
  217. X                 * Fill it in.
  218. X                 */
  219. X                pSym->DefinedLineNo = 0;
  220. X                pSym->SymbolName = pName;
  221. X                if( pOID ) pSym->SymbolValue = (LIST *) strdup(pOID);
  222. X                     else  pSym->SymbolValue = 0;
  223. X
  224. X                /*
  225. X                 * Add it to the symbol table.
  226. X                 */
  227. X                AddToSymbolTable(pSym,type);
  228. X             }
  229. X        else {
  230. X                /*
  231. X                 * Out of memory!
  232. X                 */
  233. X                RestoreErrorMsg("Out of memory\n");
  234. X             }
  235. X }
  236. X
  237. X
  238. Xstatic int IsArray(char *pName)
  239. X {
  240. X    SYMBOL *pSym;
  241. X    /*
  242. X     * See if we know about the symbol already.
  243. X     */
  244. X    for( pSym = 0; pSym = GetNextSymbol(pSym,ARRAYTABLE); )
  245. X        {
  246. X            if( strcmp(pName,pSym->SymbolName) == 0 ) return(1);
  247. X        }
  248. X    return(0);
  249. X }
  250. X
  251. X
  252. Xstatic char *CheckForColumnEntry(char *pOID)
  253. X {
  254. X    SYMBOL *pSym;
  255. X    int n;
  256. X    /*
  257. X     * See if we have this OID as a subset of any array.
  258. X     */
  259. X    for( pSym = 0; pSym = GetNextSymbol(pSym,ROWTABLE); )
  260. X        {
  261. X            if( strstr(pOID,(char *)pSym->SymbolValue) ) return(pSym->SymbolName);
  262. X        }
  263. X    return((char *)0);
  264. X }
  265. X
  266. X
  267. Xstatic OIDTYPE ProcessType(char *pName,TYPE **pT,int nLineNo)
  268. X {
  269. X    TYPE *pNewType;
  270. X    SYMBOL *pSym;
  271. X    OIDTYPE oidtype,BasicType(char *,TYPE **,int);
  272. X    /*
  273. X     * Look up the type in the symbol table -- it must be present.
  274. X     */
  275. X    pSym = FindSymbol((*pT)->Data.TypeName,NEWTYPES);
  276. X    if( pSym )
  277. X             {
  278. X                /*
  279. X                 * We have something, so resolve it into something we can
  280. X                 * use.
  281. X                 */
  282. X                pNewType = (TYPE * )pSym->SymbolValue;
  283. X                oidtype = BasicType(pSym->SymbolName,&pNewType,pSym->DefinedLineNo);
  284. X                if( oidtype != NOTYPE ) *pT = pNewType;
  285. X             }
  286. X        else {
  287. X                /*
  288. X                 * Not present, so kick it out with an error...
  289. X                 */
  290. X                oidtype = NOTYPE;
  291. X                RestoreErrorMsg("Line %d : Illegal SYNTAX type of \"%s\" in OBJECT-TYPE \"%s\"\n",nLineNo,(*pT)->Data.TypeName,pName);
  292. X                yyErrorCnt++;
  293. X             }
  294. X
  295. X    /*
  296. X     * Return the outcome...
  297. X     */
  298. X    return(oidtype);
  299. X }
  300. X
  301. X
  302. Xstatic OIDTYPE BasicType(char *pName,TYPE **pT,int nLineNo)
  303. X {
  304. X    OIDTYPE type;
  305. X    /*
  306. X     * Do normal checking of type...
  307. X     */
  308. X    switch((*pT)->Type)
  309. X        {
  310. X            case NULLTYPE:
  311. X                    type = NULLOBJ;
  312. X                    break;
  313. X            case TICKTYPE:
  314. X                    type = TIMETICKS;
  315. X                    break;
  316. X            case COUNTERTYPE:
  317. X                    type = COUNTER;
  318. X                    break;
  319. X            case GAUGETYPE:
  320. X                    type = GAUGE;
  321. X                    break;
  322. X            case INTEGERTYPE:
  323. X            case RANGEINTEGER:
  324. X            case ENUMINTEGER:
  325. X                    type = INTEGER;
  326. X                    break;
  327. X            case OBJIDTYPE:
  328. X                    type = OBJECTID;
  329. X                    break;
  330. X            case IPADDRTYPE:
  331. X                    type = IPADDR;
  332. X                    break;
  333. X            case NETWORKTYPE:
  334. X                    type = NETADDR;
  335. X                    break;
  336. X            case OCTETTYPE:
  337. X                    type = OCTETSTRING;
  338. X                    break;
  339. X            case STRINGTYPE:
  340. X                    type = DISPLAYSTRING;
  341. X                    break;
  342. X            case SEQOFTYPE:
  343. X            case ITEMTYPE:
  344. X            case SEQTYPE:
  345. X                    type = NOTYPE;
  346. X                    RestoreErrorMsg("Line %d : Illegal SYNTAX type in OBJECT-TYPE \"%s\"\n",nLineNo,pName);
  347. X                    yyErrorCnt++;
  348. X                    break;
  349. X            case TYPENAME:
  350. X                    /*
  351. X                     * We need to resolve this type, to the true thing behind
  352. X                     * it. Only if we can't resolve things any further do we
  353. X                     * actually display an error.
  354. X                     */
  355. X                    type = ProcessType(pName,pT,nLineNo);
  356. X                    break;
  357. X        }
  358. X    return(type);
  359. X }
  360. X
  361. X
  362. Xstatic void FillInDetails(OIDINFO *pOI,TYPE *pT)
  363. X {
  364. X    LIST *pL;
  365. X    int i;
  366. X    /*
  367. X     * Set the default conditions... no specific sub information!
  368. X     */
  369. X    pOI->OIDsubtype = NOSUBTYPE;
  370. X
  371. X    /*
  372. X     * Fill in the other details.
  373. X     */
  374. X    switch(pT->Type)
  375. X        {
  376. X            case RANGEINTEGER:
  377. X            case OCTETTYPE:
  378. X            case STRINGTYPE:
  379. X                    /*
  380. X                     * These types can have ranges associated with them. 
  381. X                     * See if the MIB defined them.
  382. X                     */
  383. X                    if( pT->Data.Range.Lower || pT->Data.Range.Upper )
  384. X                        {
  385. X                            /*
  386. X                             * We need to store a range in the array.
  387. X                             */
  388. X                            i = pOI->NoElems;
  389. X                            pOI->OIDsubtype = RANGESET;
  390. X                            pOI->extra[i].Pair.Lower = pT->Data.Range.Lower;
  391. X                            pOI->extra[i].Pair.Upper = pT->Data.Range.Upper;
  392. X                            pOI->NoElems = i+1;
  393. X                        }
  394. X                    break;
  395. X            case ENUMINTEGER:
  396. X                    /*
  397. X                     * This one has a lot of data!
  398. X                     */
  399. X                    i = pOI->NoElems;
  400. X                    for( pL = pT->Data.EnumList; pL; pL = (LIST *)pL->Next,i++ )
  401. X                        {
  402. X                            /*
  403. X                             * Store the entry in the 'extra' array.
  404. X                             */
  405. X                            pOI->extra[i].EnumData.EnumName = pL->Name;
  406. X                            pOI->extra[i].EnumData.EnumValue = pL->Number;
  407. X                        }
  408. X                    pOI->NoElems = i;
  409. X                    pOI->OIDsubtype = ENUMSET;
  410. X                    break;
  411. X        }
  412. X }
  413. X
  414. X
  415. Xstatic void FillInArrayDetails(OIDINFO *pOI,LIST *pIndex)
  416. X {
  417. X    int i;
  418. X    /*
  419. X     * This one has a lot of data!
  420. X     */
  421. X    for( i = pOI->NoElems ; pIndex; pIndex = (LIST *)pIndex->Next,i++ )
  422. X        {
  423. X            /*
  424. X             * Store the entry in the 'extra' array.
  425. X             */
  426. X            pOI->extra[i].IndexName = pIndex->Name;
  427. X        }
  428. X    pOI->NoElems = i;
  429. X    pOI->OIDsubtype = ENUMSET;
  430. X }
  431. X
  432. X
  433. X/*
  434. X * Process the object. We take all the input, process it and place it
  435. X * in a data structure called OIDINFO.
  436. X */
  437. Xstatic void SaveObject(char *pName,TYPE *pSyntax,int Access,int Status,
  438. X                         char *pDesc,char *pRef,LIST *pIndex,LIST *pDefault,
  439. X                                                        LIST *pOID,int nLineNo)
  440. X {
  441. X    OIDINFO oid;
  442. X    char *pRowName;
  443. X    /*
  444. X     * Do the simple cleanup to initialize the oid structure.
  445. X     */
  446. X    memset((char *)&oid,0,sizeof(oid));
  447. X
  448. X    /*
  449. X     * Make sure that the access and status are okay.
  450. X     */
  451. X    if( (Access == (int)UNKNOWN) || (Status == (int)UNKNOWN) )
  452. X        {
  453. X            RestoreErrorMsg("Line : %d Illegal ACCESS or STATUS in definition \"%s\"\n",nLineNo,pName);
  454. X            yyErrorCnt++;
  455. X            return;
  456. X        }
  457. X    /*
  458. X     * Convert the OID to a string for later reference.
  459. X     */
  460. X    oid.OIDoid = OIDListToString(pOID);
  461. X
  462. X    /*
  463. X     * Assign the easy things...
  464. X     */
  465. X    oid.OIDname = pName;
  466. X    oid.OIDaccess = (OIDACCESS) Access;
  467. X    oid.OIDstatus = (OIDSTATUS) Status;
  468. X    oid.OIDcomments.Comments = pDesc;
  469. X
  470. X    /*
  471. X     * See if this is the "base" of a SEQUENCE OF syntax. If so, then
  472. X     * this is an array. We should also have a INDEX list as well. If
  473. X     * not, complain.
  474. X     */
  475. X    if( pSyntax->Type == SEQOFTYPE )
  476. X            {
  477. X                /*
  478. X                 * Register this object id as a array for later reference.
  479. X                 * Remember that the thing on the end of the SEQUENCE OF is
  480. X                 * an ID!
  481. X                 */
  482. X                RegisterAs(((TYPE *)(pSyntax->Data.TypeList))->Data.TypeName,oid.OIDoid,ARRAYTABLE);
  483. X
  484. X                /*
  485. X                 * Assign this as the ARRAYTYPE - it is the base of the array.
  486. X                 */
  487. X                oid.OIDflag = ARRAYTYPE;
  488. X                oid.OIDtype = NOTYPE;
  489. X                oid.OIDsubtype = NOSUBTYPE;
  490. X
  491. X                /*
  492. X                 * Make sure we don't have an INDEX statement.
  493. X                 */
  494. X                if( pIndex )
  495. X                    {
  496. X                        RestoreErrorMsg("Line %d : \"%s\" is an OBJECT-TYPE with an INDEX clause; it is probably misplaced\n",nLineNo,pName);
  497. X                        yyErrorCnt++;
  498. X                    }
  499. X            }
  500. X       else {
  501. X                /*
  502. X                 * We have something that isn't an array definition. So
  503. X                 * see if it is part of a column, a slice or a leaf.
  504. X                 */
  505. X                if( (pSyntax->Type == TYPENAME) &&
  506. X                            IsArray(pSyntax->Data.TypeName) )
  507. X                         {
  508. X                            /*
  509. X                             * This is the "slice" of the array; it has no
  510. X                             * real type - it is an aggregate for all purposes.
  511. X                             */
  512. X                            oid.OIDflag = ROWTYPE;
  513. X                            oid.OIDtype = AGGREGATE;
  514. X                            oid.OIDsubtype = NOSUBTYPE;
  515. X
  516. X                            /*
  517. X                             * We need to have an INDEX clause for this definition.
  518. X                             * Complain if we don't.
  519. X                             */
  520. X                            if( pIndex == (LIST *)0 )
  521. X                                {
  522. X                                    ErrorMsg("Line %d : \"%s\" is an OBJECT-TYPE without an INDEX clause; it should have one\n",nLineNo,pName);
  523. X                                    yyErrorCnt++;
  524. X                                }
  525. X
  526. X                            /*
  527. X                             * Fill in the details we need.
  528. X                             */
  529. X                            FillInArrayDetails(&oid,pIndex);
  530. X
  531. X                            /*
  532. X                             * Register this thing for later access.
  533. X                            */
  534. X                           RegisterAs(pName,oid.OIDoid,ROWTABLE);
  535. X                         }
  536. X                    else {
  537. X                            /*
  538. X                             * For these types, we shouldn't have an INDEX
  539. X                             * field. If so it is probably a misplacement.
  540. X                             */
  541. X                            if( pIndex )
  542. X                                {
  543. X                                    RestoreErrorMsg("Line %d : \"%s\" is an OBJECT-TYPE with an INDEX clause; it is probably misplaced\n",nLineNo,pName);
  544. X                                    yyErrorCnt++;
  545. X                                }
  546. X
  547. X                            /*
  548. X                             * Assign the type necessary.
  549. X                             */
  550. X                            oid.OIDtype = BasicType(pName,&pSyntax,nLineNo);
  551. X                            if( oid.OIDtype == NOTYPE ) return;
  552. X
  553. X                            /*
  554. X                             * We might have a column entry or leaf. Figure
  555. X                             * out which by looking at the OID numbers.
  556. X                             */
  557. X                            if( pRowName = CheckForColumnEntry(oid.OIDoid) )
  558. X                                     {
  559. X                                        /*
  560. X                                         * For a column type, we store the
  561. X                                         * name of the row in the first
  562. X                                         * entry in the extra[] array.
  563. X                                         */
  564. X                                        oid.extra[0].IndexName = pRowName;
  565. X                                        oid.NoElems = 1;
  566. X                                        oid.OIDflag = COLTYPE;
  567. X                                     }
  568. X                                else {
  569. X                                        oid.OIDflag = LEAFTYPE;
  570. X
  571. X                                        /*
  572. X                                         * A leaf always has a 0 at the end
  573. X                                         * of the OID.
  574. X                                         */
  575. X                                        strcat(oid.OIDoid,".0");
  576. X                                     }
  577. X
  578. X                            /*
  579. X                             * This is the hard part... fill in the
  580. X                             * oid.NoElems value and the array extra!
  581. X                             */
  582. X                            FillInDetails(&oid,pSyntax);
  583. X
  584. X                         }
  585. X            }
  586. X
  587. X    /*
  588. X     * We now have assembled everything, and it has now to be written to
  589. X     * the database!
  590. X     */
  591. X    if( (nCheckOnly == 0) && SaveOID(&oid) )
  592. X         {
  593. X             RestoreErrorMsg("Problem with database : couldn't write record for OBJECT-TYPE \"%s\" (errno = %d uerr_cod = %d)\n",pName,errno);
  594. X         }
  595. X }
  596. X
  597. X
  598. Xstatic void QueueObject(char *pName,TYPE *pSyntax,int Access,int Status,
  599. X                          char *pDesc,char *pRef,LIST *pIndex,LIST *pDefault,
  600. X                                                        LIST *pOID,int nLineNo)
  601. X{ 
  602. X    QUEUEOBJ *pQ;
  603. X    /*
  604. X     * Allocate a queue structure to store everything...
  605. X     */
  606. X    pQ = (QUEUEOBJ *) malloc(sizeof(QUEUEOBJ));
  607. X    if( pQ )
  608. X             {
  609. X                /*
  610. X                 * Okay, fill in the details.
  611. X                 */
  612. X                pQ->Name = pName;
  613. X                pQ->Syntax = pSyntax;
  614. X                pQ->Access = Access;
  615. X                pQ->Status = Status;
  616. X                pQ->Description = pDesc;
  617. X                pQ->Reference = pRef;
  618. X                pQ->Index = pIndex;
  619. X                pQ->Default = pDefault;
  620. X                pQ->OID = pOID;
  621. X                pQ->LineNo = nLineNo;
  622. X
  623. X                /*
  624. X                 * Queue up the thing for later processing. Note that they
  625. X                 * must be queued in the order they are seen!
  626. X                 */
  627. X                if( HeadObj )
  628. X                         {
  629. X                            TailObj->Next = (struct qobject *) pQ;
  630. X                         }
  631. X                    else {
  632. X                            HeadObj = pQ;
  633. X                         }
  634. X                TailObj = pQ;
  635. X                pQ->Next = 0;
  636. X             }
  637. X        else {
  638. X                /*
  639. X                 * Too bad, we couldn't fit everything.
  640. X                 */
  641. X                RestoreErrorMsg("Out of memory\n");
  642. X             }
  643. X}
  644. X
  645. X
  646. X/*
  647. X * pName        name of the object being defined.
  648. X * pSyntax        what type of data is involved.
  649. X * Access        what type of access is allowed.
  650. X * Status        what is the status of the object.
  651. X * pDesc        pointer to description of the object.
  652. X * pRef            pointer to reference list.
  653. X * pIndex        pointer to table index list.
  654. X * pDefault        default value.
  655. X * pOID            OID of this object.
  656. X * nLineNo        where, in the MIB file it is defined.
  657. X * bSaveOID        whether or not the OID and name is to be added
  658. X *                to the symbol table.
  659. X */
  660. Xvoid ProcessObject(char *pName,TYPE *pSyntax,int Access,int Status,
  661. X                         char *pDesc,char *pRef,LIST *pIndex,LIST *pDefault,
  662. X                                            LIST *pOID,int nLineNo,int bSaveOID)
  663. X {
  664. X    LIST *pNew;
  665. X    /*
  666. X     * See if the OID supplied can be converted to only numbers, such as
  667. X     * 1.3.6
  668. X     */
  669. X    *pNew = ResolveSpecificOID(pOID,pName,0);
  670. X
  671. X    /*
  672. X     * We add the passed in OID to the symbol table list. We will use
  673. X     * the resolved OID if it is available. Otherwise we use the original!
  674. X     */
  675. X    if( pNew )
  676. X          pOID = pNew;
  677. X     else bResolveOIDsNeeded++;
  678. X    if( bSaveOID ) AddOIDSymbol(pName,pOID,nLineNo);
  679. X
  680. X    /*
  681. X     * Determine what to do... If we were able to resolve the OID at this 
  682. X     * time we will add the entry to the database. Otherwise, we create
  683. X     * a "in-memory" copy and link them altogether for later access.
  684. X     */
  685. X    if( pNew == pOID )
  686. X             {
  687. X                /*
  688. X                 * Save it now.
  689. X                 */
  690. X                SaveObject(pName,pSyntax,Access,Status,pDesc,pRef,pIndex,
  691. X                                            pDefault,pOID,nLineNo);
  692. X             }
  693. X        else {
  694. X                /*
  695. X                 * Save it for later use -- FinishObjectProcessing
  696. X                 * will deal with it.
  697. X                 */
  698. X                QueueObject(pName,pSyntax,Access,Status,pDesc,pRef,pIndex,
  699. X                                            pDefault,pOID,nLineNo);
  700. X             }
  701. X }
  702. X
  703. X
  704. X/*
  705. X * Do the second pass of the object definitions, just in case there
  706. X * are some that need to be processed.
  707. X */
  708. Xvoid FinishObjectProcessing()
  709. X {
  710. X    QUEUEOBJ *pQ;
  711. X    /*
  712. X     * See if there is any deferred processing to do...
  713. X     */
  714. X    for( pQ = HeadObj; pQ; pQ = (QUEUEOBJ *)pQ->Next )
  715. X        {
  716. X            /*
  717. X             * Process this object definition.
  718. X             */
  719. X            ProcessObject(pQ->Name,pQ->Syntax,pQ->Access,pQ->Status,
  720. X                                pQ->Description,pQ->Reference,pQ->Index,
  721. X                                           pQ->Default,pQ->OID,pQ->LineNo,0);
  722. X        }
  723. X }
  724. END_OF_FILE
  725.   if test 17859 -ne `wc -c <'AssignOBJECT.c'`; then
  726.     echo shar: \"'AssignOBJECT.c'\" unpacked with wrong size!
  727.   fi
  728.   # end of 'AssignOBJECT.c'
  729. fi
  730. if test -f 'AssignTRAP.c' -a "${1}" != "-c" ; then 
  731.   echo shar: Will not clobber existing file \"'AssignTRAP.c'\"
  732. else
  733.   echo shar: Extracting \"'AssignTRAP.c'\" \(1044 characters\)
  734.   sed "s/^X//" >'AssignTRAP.c' <<'END_OF_FILE'
  735. X#include <stdio.h>
  736. X
  737. X#include "MibCompiler.h"
  738. X#include "AssignTRAP.h"
  739. X
  740. X
  741. Xextern int debug,nCheckOnly;
  742. X
  743. X
  744. X/*
  745. X * pName    name of the trap
  746. X * pOID        pointer to linked list that is the enterprise OID
  747. X * pVar        pointer to linked list of variables that are part
  748. X *            of the trap message
  749. X * pDescr    pointer to character string that is a description of
  750. X *            the trap
  751. X * pRef        pointer to character string that is the reference of
  752. X *            the trap
  753. X * TrapNo    trap number
  754. X * nLineNo    start of definition of trap in .my file.
  755. X *
  756. X */
  757. Xvoid ProcessTrap(char *pName,LIST *pOID,LIST *pVar,
  758. X                        char *pDescr,char *pRef,int TrapNo,int nLineNo)
  759. X {
  760. X    /*
  761. X     * First, see if we are going to display the trap info.
  762. X     */
  763. X    if( debug )
  764. X        {
  765. X            printf("Trap name %s (number %d)\n",pName,TrapNo);
  766. X            printf("\tEnterprise ");PrintList(pOID,0);printf("\n");
  767. X            printf("\tReference %s\n",pRef);
  768. X            printf("\tDescription %s\n",pDescr);
  769. X            printf("\tVariables ");PrintList(pVar,0);printf("\n\n");
  770. X        }
  771. X }
  772. X
  773. END_OF_FILE
  774.   if test 1044 -ne `wc -c <'AssignTRAP.c'`; then
  775.     echo shar: \"'AssignTRAP.c'\" unpacked with wrong size!
  776.   fi
  777.   # end of 'AssignTRAP.c'
  778. fi
  779. if test -f 'AssignTYPE.h' -a "${1}" != "-c" ; then 
  780.   echo shar: Will not clobber existing file \"'AssignTYPE.h'\"
  781. else
  782.   echo shar: Extracting \"'AssignTYPE.h'\" \(147 characters\)
  783.   sed "s/^X//" >'AssignTYPE.h' <<'END_OF_FILE'
  784. X#if defined(__STDC__)
  785. Xvoid ProcessType(char *,TYPE *,int);
  786. Xvoid AddStandardTypes(void);
  787. X#else
  788. Xvoid ProcessType();
  789. Xvoid AddStandardTypes();
  790. X#endif
  791. X
  792. END_OF_FILE
  793.   if test 147 -ne `wc -c <'AssignTYPE.h'`; then
  794.     echo shar: \"'AssignTYPE.h'\" unpacked with wrong size!
  795.   fi
  796.   # end of 'AssignTYPE.h'
  797. fi
  798. if test -f 'main.c' -a "${1}" != "-c" ; then 
  799.   echo shar: Will not clobber existing file \"'main.c'\"
  800. else
  801.   echo shar: Extracting \"'main.c'\" \(6219 characters\)
  802.   sed "s/^X//" >'main.c' <<'END_OF_FILE'
  803. X#include <stdio.h>
  804. X#include <limits.h>
  805. X#include <string.h>
  806. X
  807. Xextern char getopt(),*optarg,*getenv(),*Version;
  808. Xextern int debug,optind,bNoStandardOIDs,bDoingTraps;
  809. Xextern int nCheckOnly,nErrorCount;
  810. X
  811. X
  812. X/*
  813. X * InitDB
  814. X *
  815. X * Do any necessary database initialization.
  816. X */
  817. Xvoid InitDB(void)
  818. X {
  819. X }
  820. X
  821. X
  822. X/*
  823. X * SaveMainOIDFiles 
  824. X *
  825. X * Save the main database files just in case we need to restore
  826. X * them later. This happens when the MIB has an error in it, and
  827. X * the underlying database system isn't capable of dealing with
  828. X * multiple definitions.
  829. X */
  830. Xstatic int SaveMainOIDFiles()
  831. X {
  832. X    int nRc = 0;
  833. X    /*
  834. X     * Return the results.
  835. X     */
  836. X    return(nRc);
  837. X }
  838. X
  839. X
  840. X/*
  841. X * RecoverMainOIDFiles
  842. X *
  843. X * Restore the main database files. This routine is called whenever one
  844. X * or more "fatal" errors are uncovered in the MIB.
  845. X */
  846. Xstatic void RecoverMainOIDFiles()
  847. X {
  848. X }
  849. X
  850. X
  851. X/*
  852. X * CreateOIDFiles
  853. X *
  854. X * Create any necessary database files needed to hold the compiled MIB.
  855. X */
  856. Xstatic int CreateOIDFiles(char *pName)
  857. X {
  858. X    int nRc = 0;
  859. X    /*
  860. X     * Return the results.
  861. X     */
  862. X    return(nRc);
  863. X }
  864. X
  865. X
  866. X/*
  867. X * CloseOIDFiles 
  868. X *
  869. X * Close any necessary database files.
  870. X */
  871. Xstatic void CloseOIDFiles(void)
  872. X {
  873. X }
  874. X
  875. X
  876. X/*
  877. X * ProcessRequest
  878. X *
  879. X * Compile a MIB definition.
  880. X */
  881. Xstatic void ProcessRequest(char *pName)
  882. X {
  883. X    int nRc = 0;
  884. X    static char filename[PATH_MAX];
  885. X    char *pStr;
  886. X    /*
  887. X     * Reset the error count for this mib. This error count is the fatal
  888. X     * error count; if it is non-zero it will force a call to restore
  889. X     * the database files.
  890. X     */
  891. X    nErrorCount = 0;
  892. X
  893. X    /*
  894. X     * Create a filename for the database. Here we strip off the extension
  895. X     * and provide a suffix O. For example, a mib called mib2.my, would
  896. X     * have a database file name of Omib2. We also handle the path
  897. X     * name part, as well.
  898. X     */
  899. X    pStr = strrchr(pName,'/');
  900. X    if( pStr )
  901. X             {
  902. X                /*
  903. X                 * It has a path part...
  904. X                 */
  905. X                strncpy(filename,pName,(pStr - pName + 1));
  906. X                strcat(filename,"O");
  907. X                strcat(filename,pStr+1);
  908. X                pStr = strchr(filename,'.');
  909. X                if( pStr ) *pStr = '\0';
  910. X             }
  911. X        else {
  912. X                /*
  913. X                 * It has no path!
  914. X                 */
  915. X                strcpy(filename,"O");
  916. X                strcat(filename,pName);
  917. X                pStr = strchr(filename,'.');
  918. X                if( pStr ) *pStr = '\0';
  919. X             }
  920. X    pName = filename;
  921. X    
  922. X    /*
  923. X     * Create an appropriate private MIB database file, but only if this
  924. X     * isn't a check.
  925. X     */
  926. X    if( nCheckOnly == 0 )
  927. X        nRc = CreateOIDFiles(pName);
  928. X    if( nRc )
  929. X            {
  930. X                ErrorMsg("Couldn't create MIB db file %s\n",pName);
  931. X            }
  932. X       else {
  933. X                /*
  934. X                 * Save the main OID files, just in case.
  935. X                 */
  936. X                if( !nCheckOnly && SaveMainOIDFiles() )
  937. X                    {
  938. X                        ErrorMsg("Couldn't save main database files\n");
  939. X                    }
  940. X
  941. X                /*
  942. X                 * Process the input file. If it failed, delete the private
  943. X                 * MIB file.
  944. X                 */
  945. X                if( yyparse() || nErrorCount )
  946. X                         {
  947. X                            /*
  948. X                             * It failed. So close the file out and delete it.
  949. X                             */
  950. X                            if( !nCheckOnly )
  951. X                                {
  952. X                                    CloseOIDFiles();
  953. X                                    unlink(pName);
  954. X
  955. X                                    /*
  956. X                                     * We should also recover the main
  957. X                                     * oid files as well.
  958. X                                     */
  959. X                                    RecoverMainOIDFiles();
  960. X                                    printf("Database recovered.\n");
  961. X                                }
  962. X                         }
  963. X                    else {
  964. X                            /*
  965. X                             * It worked!
  966. X                             */
  967. X                            if( !nCheckOnly ) CloseOIDFiles();
  968. X                         }
  969. X            }
  970. X }
  971. X
  972. X
  973. Xmain(argc,argv)
  974. X int argc;
  975. X char *argv[];
  976. X {
  977. X    char c,*pStr;
  978. X    int nRc;
  979. X    /*
  980. X     * If the name of this is MIBcheck, we will only check the mib.
  981. X     */
  982. X    pStr = strrchr(argv[0],'/');
  983. X    if( pStr ) pStr++;
  984. X          else pStr = argv[0];
  985. X    if( strcmp(pStr,"MIBcheck") == 0 )
  986. X        {
  987. X            nCheckOnly = 1;
  988. X        }
  989. X
  990. X    /*
  991. X     * Collect any run time flags...
  992. X     */
  993. X    while( (c = getopt(argc,argv,"cd:lv")) != -1 )
  994. X        switch(c)
  995. X         {
  996. X            case 'c' :
  997. X                    /*
  998. X                     * Check only.
  999. X                     */
  1000. X                    nCheckOnly = 1;
  1001. X                    break;
  1002. X
  1003. X            case 'd' :
  1004. X                    /*
  1005. X                     * Set debug flag.
  1006. X                     */
  1007. X                    debug = atoi(optarg);
  1008. X                    break;
  1009. X
  1010. X            case 'v' :
  1011. X                    /*
  1012. X                     * Display the current version number.
  1013. X                     */
  1014. X                    printf(Version,pStr);
  1015. X                    break;
  1016. X
  1017. X            default  :
  1018. X                    ErrorMsg("Unknown option -- %c\n",c);
  1019. X            exit(1);
  1020. X        }
  1021. X
  1022. X    /*
  1023. X     * Do any onetime initialization necessary.
  1024. X     */
  1025. X    if( nCheckOnly ==0 )
  1026. X      {
  1027. X        /*
  1028. X         * Init the database system, as needed.
  1029. X         */
  1030. X        InitDB();
  1031. X      }
  1032. X
  1033. X    /*
  1034. X     * Process all the file names that follow.
  1035. X     */
  1036. X    for( ; optind < argc; optind++ )
  1037. X    {
  1038. X            /*
  1039. X             * This is easy - we take the file name, and open it as
  1040. X             * standard input.
  1041. X             */
  1042. X            if( freopen(argv[optind],"r",stdin) )
  1043. X                     {
  1044. X                        /*
  1045. X                         * Okay. Process the request.
  1046. X                         */
  1047. X                        ProcessRequest(argv[optind]);
  1048. X                     }
  1049. X                else {
  1050. X                        ErrorMsg("Couldn't open file %s\n",argv[optind]);
  1051. X                     }
  1052. X    }
  1053. X
  1054. X    /*
  1055. X     * And exit.
  1056. X     */
  1057. X    exit(0);
  1058. X }
  1059. X
  1060. END_OF_FILE
  1061.   if test 6219 -ne `wc -c <'main.c'`; then
  1062.     echo shar: \"'main.c'\" unpacked with wrong size!
  1063.   fi
  1064.   # end of 'main.c'
  1065. fi
  1066. if test -f 'yacc.y' -a "${1}" != "-c" ; then 
  1067.   echo shar: Will not clobber existing file \"'yacc.y'\"
  1068. else
  1069.   echo shar: Extracting \"'yacc.y'\" \(24493 characters\)
  1070.   sed "s/^X//" >'yacc.y' <<'END_OF_FILE'
  1071. X%{
  1072. X/*
  1073. X *    Copyright 1992  C. Wegrzyn
  1074. X *
  1075. X */
  1076. X#include <stdio.h>
  1077. X
  1078. X#include "oid.h"
  1079. X
  1080. X#include "MibCompiler.h"
  1081. X#include "AssignOID.h"
  1082. X#include "AssignTRAP.h"
  1083. X#include "AssignOBJECT.h"
  1084. X#include "AssignTYPE.h"
  1085. X
  1086. X
  1087. Xextern char *ShouldBeKeyword(char *);
  1088. X
  1089. Xextern KEYTYPES eNoKeyWords;
  1090. Xextern char yytext[];
  1091. Xextern int yylineno,yyErrorCnt;
  1092. X
  1093. Xint bNoStandardOIDs = {0},bDoingTraps = {0};
  1094. Xint bResolveOIDsNeeded = {0},nLineNoOfDef;
  1095. Xint debug = {0},nCheckOnly = {0};
  1096. X%}
  1097. X
  1098. X%token      ACCESS BGIN COUNTER DEFINITIONS DEFVAL DEPRECATEDOBJECT
  1099. X            DESCRIPTION DOTDOT END ENTERPRISE EXPORTS FROM GAUGE ID 
  1100. X            IDENTIFIER IMPORTS INDEX INTEGER IPADDRESS MANDATORYOBJECT
  1101. X            NETWORKADDRESS NOTACCESSIBLEOBJECT NULLID OCTET OCTSTR OBJECT 
  1102. X            OBJECTTYPE OBSOLETEOBJECT OF OPAQUE OPTIONALOBJECT
  1103. X            READONLYOBJECT READWRITEOBJECT REFERENCE SEQUENCE SIZE
  1104. X            STATUS STRING SYNTAX TIMETICKS TRAPTYPE VARIABLES
  1105. X            WRITEONLYOBJECT NAME CCE SEMICOLON COMMA LITSTRING LBRACE
  1106. X            RBRACE LITNUMBER LPAREN RPAREN ERROR
  1107. X
  1108. X%union 
  1109. X    {
  1110. X        PAIR  yy_pair;
  1111. X        LIST *yy_list;
  1112. X        char *yy_string;
  1113. X        long  yy_number;
  1114. X        TYPE *yy_type;
  1115. X     int  yy_int;
  1116. X    }
  1117. X
  1118. X%type   <yy_pair>       RangeOfValues OctetSize
  1119. X%type   <yy_list>       OIDSubId OIDList ObjectId OptObjectId Data Default
  1120. X                        IndexList Index IndexElement VarList Variables
  1121. X                        NamedNumber NamedNumberList ModuleName
  1122. X%type   <yy_string>     ReferenceLine DescriptionLine LITSTRING NAME ID
  1123. X%type   <yy_number>     Access AccessLine Status StatusLine LITNUMBER 
  1124. X%type   <yy_type>       NullType TimeTickType CounterType ObjectIdType
  1125. X                        OptionalType GaugeType IpAddressType BuiltInType
  1126. X                        NetworkAddressType IntegerType OctetType
  1127. X                        OptionalTypeList SeqList SequenceType SequenceOfType
  1128. X            Type DefinedType SyntaxLine SyntaxType
  1129. X%type    <yy_int>    TrapType TypeDefinition ObjectIdAssignment ObjectType
  1130. X            $MARK ImportItem
  1131. X
  1132. X%%
  1133. X
  1134. XModuleDefinition
  1135. X        :   
  1136. X                {
  1137. X                    /*
  1138. X                     * Add in the standard stuff from the SMI RFC; we won't
  1139. X                     * do it if told not to.
  1140. X                     */
  1141. X                    if( bNoStandardOIDs == 0 )
  1142. X                        {
  1143. X                            AddStandardOIDS();
  1144. X                            AddStandardTypes();
  1145. X                        }
  1146. X                }
  1147. X                ModuleName DEFINITIONS CCE
  1148. X                BGIN
  1149. X                    Exports
  1150. X                    Imports
  1151. X                    Statements
  1152. X                END
  1153. X                {   
  1154. X                    /*
  1155. X                     * See if we have any syntax errors. If so, we abort
  1156. X                     * the operation to update the database files. Other-
  1157. X                     * wise we continue on.
  1158. X                     */
  1159. X                    if( 0 == yyErrorCnt )
  1160. X                        {
  1161. X                            /*
  1162. X                             * Resolve the OID numbers; any unresolved OID
  1163. X                             * assignments will abort the operation. We do
  1164. X                             * this only if we have found unresolved refs
  1165. X                             * in the course of the operation.
  1166. X                             */
  1167. X                            if( debug ) DumpAllOIDs();
  1168. X                            if( bResolveOIDsNeeded && !AllOIDsResolved() )
  1169. X                                {
  1170. X                                    /*
  1171. X                                     * Too bad, we have things that couldn't
  1172. X                                     * be resolved. So exit now.
  1173. X                                     */
  1174. X                                    exit(1);
  1175. X                                }
  1176. X
  1177. X                            /*
  1178. X                             * Do any final object type output.
  1179. X                             */
  1180. X                            FinishObjectProcessing();
  1181. X                        }
  1182. X                }
  1183. X        ;
  1184. XModuleName
  1185. X        :   ID OptObjectId
  1186. X                {
  1187. X                    $$ = newListElement(NAMEANDOID,$1,0);
  1188. X                    $$->OID = (struct list *)$2;
  1189. X                }
  1190. X        ;
  1191. X
  1192. XImports
  1193. X        :   IMPORTS ImportFromModuleList SEMICOLON
  1194. X        |   IMPORTS SEMICOLON
  1195. X        |   empty
  1196. X        ;
  1197. XImportFromModuleList
  1198. X        :   ImportFromModuleList ImportFromModule
  1199. X        |   ImportFromModule
  1200. X        ;
  1201. XImportFromModule
  1202. X        :   ImportList FROM ID
  1203. X        ;
  1204. XImportList
  1205. X        :   ImportItem
  1206. X        |   ImportList COMMA ImportItem
  1207. X                {
  1208. X                    yyerrok;
  1209. X                }
  1210. X        |   error
  1211. X        |   ImportList error
  1212. X        |   ImportList error ImportItem
  1213. X                {
  1214. X                    yyerrok;
  1215. X                }
  1216. X        |   ImportList COMMA error
  1217. X        ;
  1218. XImportItem
  1219. X        :   NAME
  1220. X            {
  1221. X            }
  1222. X        |   ID
  1223. X            {
  1224. X            }
  1225. X        |   COUNTER
  1226. X            {
  1227. X            }
  1228. X        |   GAUGE
  1229. X            {
  1230. X            }
  1231. X        |   IPADDRESS
  1232. X            {
  1233. X            }
  1234. X        |   NETWORKADDRESS
  1235. X            {
  1236. X            }
  1237. X        |   OBJECTTYPE
  1238. X            {
  1239. X            }
  1240. X        |   TIMETICKS
  1241. X            {
  1242. X            }
  1243. X        |   TRAPTYPE
  1244. X            {
  1245. X            }
  1246. X        |   ERROR
  1247. X                {
  1248. X                    fprintf(stderr,"Line %d : Invalid TYPE \"%s\" -- should be \"%s\"\n",yylineno,yytext,ShouldBeKeyword(yytext));
  1249. X                }
  1250. X        ;
  1251. X
  1252. XExports
  1253. X        :   EXPORTS
  1254. X                {
  1255. X                    /*
  1256. X                     * Indicate we don't want keywords at this point.
  1257. X                     */
  1258. X                    eNoKeyWords = NOKEYWORDS;
  1259. X                }
  1260. X                ExportList
  1261. X                {
  1262. X                    /*
  1263. X                     * At this point turn keyword searching on again.
  1264. X                     */
  1265. X                    eNoKeyWords = ALLKEYWORDS;
  1266. X                }
  1267. X             SEMICOLON
  1268. X        |   EXPORTS SEMICOLON
  1269. X        |   empty
  1270. X        ;
  1271. XExportList
  1272. X        :   ExportItem
  1273. X        |   ExportList COMMA ExportItem
  1274. X                {
  1275. X                    yyerrok;
  1276. X                }
  1277. X        |   error
  1278. X        |   ExportList error
  1279. X        |   ExportList error ExportItem
  1280. X                {
  1281. X                    yyerrok;
  1282. X                }
  1283. X        |   ExportList COMMA error
  1284. X        ;
  1285. XExportItem
  1286. X        :   ID
  1287. X        |   NAME
  1288. X        ;
  1289. X
  1290. XStatements
  1291. X        :   
  1292. X        |   Statements Statement
  1293. X                {
  1294. X                    yyerrok;
  1295. X                }
  1296. X        |   Statements error
  1297. X        ;
  1298. XStatement
  1299. X        :   ObjectIdAssignment
  1300. X        |   ObjectType
  1301. X        |   TrapType
  1302. X        |   TypeDefinition
  1303. X        ;
  1304. X
  1305. X$MARK    :
  1306. X        {
  1307. X                    /*
  1308. X                     * This is performed only to get save the correct
  1309. X                     * line number for an ASN.1 definition.
  1310. X                     */
  1311. X                    nLineNoOfDef = yylineno;
  1312. X        }
  1313. X    ;
  1314. X
  1315. XObjectIdAssignment
  1316. X        :   NAME OBJECT $MARK IDENTIFIER CCE ObjectId
  1317. X                {
  1318. X                    /*
  1319. X                     * This assigns a name to an object id; we store it
  1320. X                     * in our database.
  1321. X                     */
  1322. X                    ProcessOID($1,$6,nLineNoOfDef);
  1323. X                }
  1324. X        ;
  1325. X
  1326. XObjectType
  1327. X        :   NAME OBJECTTYPE $MARK
  1328. X                SyntaxLine
  1329. X                AccessLine
  1330. X                StatusLine
  1331. X                DescriptionLine
  1332. X                ReferenceLine
  1333. X                Index
  1334. X                Default
  1335. X                CCE ObjectId
  1336. X                {
  1337. X                    /*
  1338. X                     * Process the object definition.
  1339. X                     */
  1340. X                    ProcessObject($1,$4,$5,$6,$7,$8,$9,$10,$12,nLineNoOfDef,1);
  1341. X
  1342. X                }
  1343. X    ;
  1344. X
  1345. XTrapType
  1346. X        :   NAME TRAPTYPE $MARK
  1347. X                ENTERPRISE ObjectId
  1348. X                Variables
  1349. X                DescriptionLine
  1350. X                ReferenceLine
  1351. X                CCE LITNUMBER
  1352. X                    {
  1353. X                        /*
  1354. X                         * If we are doing stuff with traps, emit all the
  1355. X                         * things necessary now.
  1356. X                         */
  1357. X                        ProcessTrap($1,$5,$6,$7,$8,$10,nLineNoOfDef);
  1358. X                    }
  1359. X        ;
  1360. X
  1361. XTypeDefinition
  1362. X        :   ID CCE $MARK Type
  1363. X                {
  1364. X                    /*
  1365. X                     * Process any type definition stuff.
  1366. X                     */
  1367. X                    ProcessType($1,$4,nLineNoOfDef);
  1368. X                }
  1369. X        ;
  1370. X
  1371. XType
  1372. X        :   BuiltInType
  1373. X                {
  1374. X                    $$ = $1;
  1375. X                }
  1376. X        |   DefinedType
  1377. X                {
  1378. X                    $$ = $1;
  1379. X                }
  1380. X        ;
  1381. X
  1382. XDefinedType
  1383. X        :   ID
  1384. X                {
  1385. X                    /*
  1386. X                     * Notice that we don't worry about checking to see if
  1387. X                     * 'ID' is really defined now. We will check it out
  1388. X                     * later on. This will allow a type to be used before
  1389. X                     * it is defined; it means a little more work later on.
  1390. X                     */
  1391. X                    $$ = newTypeElement(TYPENAME,$1);
  1392. X                }
  1393. X        |   ERROR
  1394. X                {
  1395. X                    fprintf(stderr,"Line %d : Invalid TYPE \"%s\" -- should be \"%s\"\n",yylineno,yytext,ShouldBeKeyword(yytext));
  1396. X                    $$ = (TYPE *)0;
  1397. X                }
  1398. X        ;
  1399. X
  1400. XBuiltInType
  1401. X        :   IntegerType
  1402. X                {
  1403. X                    $$ = $1;
  1404. X                }    
  1405. X        |   OctetType
  1406. X                {
  1407. X                    $$ = $1;
  1408. X                }    
  1409. X        |   NullType
  1410. X                {
  1411. X                    $$ = $1;
  1412. X                }    
  1413. X        |   SequenceType
  1414. X                {
  1415. X                    $$ = $1;
  1416. X                }    
  1417. X        |   SequenceOfType
  1418. X                {
  1419. X                    $$ = $1;
  1420. X                }
  1421. X        |   ObjectIdType
  1422. X                {
  1423. X                    $$ = $1;
  1424. X                }    
  1425. X        |   CounterType
  1426. X                {
  1427. X                    $$ = $1;
  1428. X                }    
  1429. X        |   TimeTickType
  1430. X                {
  1431. X                    $$ = $1;
  1432. X                }    
  1433. X        |   GaugeType
  1434. X                {
  1435. X                    $$ = $1;
  1436. X                }    
  1437. X        |   IpAddressType
  1438. X                {
  1439. X                    $$ = $1;
  1440. X                }    
  1441. X        |   NetworkAddressType
  1442. X                {
  1443. X                    $$ = $1;
  1444. X                }
  1445. X        ;
  1446. X
  1447. XNetworkAddressType
  1448. X        :   NETWORKADDRESS
  1449. X                {
  1450. X                    $$ = newTypeElement(NETWORKTYPE,(char *)0);
  1451. X                }
  1452. X        ;
  1453. X
  1454. XIpAddressType
  1455. X        :   IPADDRESS
  1456. X                {
  1457. X                    $$ = newTypeElement(IPADDRTYPE,(char *)0);
  1458. X                }
  1459. X        ;
  1460. X
  1461. XGaugeType
  1462. X        :   GAUGE
  1463. X                {
  1464. X                    $$ = newTypeElement(GAUGETYPE,(char *)0);
  1465. X                }
  1466. X        ;
  1467. X
  1468. XTimeTickType
  1469. X        :   TIMETICKS
  1470. X                {
  1471. X                    $$ = newTypeElement(TICKTYPE,(char *)0);
  1472. X                }
  1473. X        ;
  1474. X
  1475. XCounterType
  1476. X        :   COUNTER
  1477. X                {
  1478. X                    $$ = newTypeElement(COUNTERTYPE,(char *)0);
  1479. X                }
  1480. X        ;
  1481. X
  1482. XOctetType
  1483. X        :   OCTET STRING OctetSize
  1484. X                {
  1485. X                    $$ = newTypeElement(OCTETTYPE,(char *)&($3));
  1486. X                }
  1487. X        |   OCTSTR OctetSize
  1488. X                {
  1489. X                    $$ = newTypeElement(OCTETTYPE,(char *)&($2));
  1490. X                }
  1491. X        ;
  1492. X
  1493. XIntegerType
  1494. X        :   INTEGER
  1495. X                {
  1496. X                    $$ = newTypeElement(INTEGERTYPE,(char *)0);
  1497. X                }
  1498. X        |   INTEGER LBRACE NamedNumberList RBRACE
  1499. X                {
  1500. X                    $$ = newTypeElement(ENUMINTEGER,(char *)$3);
  1501. X                }
  1502. X        |   INTEGER LPAREN RangeOfValues RPAREN
  1503. X                {
  1504. X                    $$ = newTypeElement(RANGEINTEGER,(char *)&($3));
  1505. X                }
  1506. X        ;
  1507. X
  1508. XObjectIdType
  1509. X        :   OBJECT IDENTIFIER
  1510. X                {
  1511. X                    $$ = newTypeElement(OBJIDTYPE,(char *)0);
  1512. X                }
  1513. X        ;
  1514. X
  1515. XNullType
  1516. X        :   NULLID
  1517. X                {
  1518. X                    $$ = newTypeElement(NULLTYPE,(char *)0);
  1519. X                }
  1520. X        ;
  1521. X
  1522. XSequenceOfType
  1523. X        :   SEQUENCE OF Type
  1524. X                {
  1525. X                    $$ = newTypeElement(SEQOFTYPE,(char *)$3);
  1526. X                }
  1527. X        ;
  1528. X
  1529. XSequenceType
  1530. X        :   SEQUENCE LBRACE SeqList RBRACE
  1531. X                {
  1532. X                    $$ = newTypeElement(SEQTYPE,(char *)$3);
  1533. X                }
  1534. X        ;
  1535. XSeqList
  1536. X        :   OptionalTypeList
  1537. X                {
  1538. X                    $$ = $1;
  1539. X                }
  1540. X        |   empty
  1541. X                {
  1542. X                    $$ = 0;
  1543. X                }
  1544. X        ;
  1545. XOptionalTypeList
  1546. X        :   OptionalType
  1547. X                {
  1548. X                    $$ = $1;
  1549. X                }
  1550. X        |   OptionalTypeList COMMA OptionalType
  1551. X                {
  1552. X                    yyerrok;
  1553. X                    $$ = LinkToType($1,$3);
  1554. X                }
  1555. X        |   error
  1556. X                {
  1557. X                    $$ = 0;
  1558. X                }
  1559. X        |   OptionalTypeList error
  1560. X                {
  1561. X                    $$ = $1;
  1562. X                }
  1563. X        |   OptionalTypeList error OptionalType
  1564. X                {
  1565. X                    yyerrok;
  1566. X                    $$ = LinkToType($1,$3);
  1567. X                }
  1568. X        |   OptionalTypeList COMMA error
  1569. X                {
  1570. X                    $$ = $1;
  1571. X                }
  1572. X        ;
  1573. XOptionalType
  1574. X        :   NAME Type
  1575. X                {
  1576. X                    $$ = newTypeElement(ITEMTYPE,(char *)0);
  1577. X                    $$->Data.Names.ItemName = $1;
  1578. X                    $$->Data.Names.ItemType = $2;
  1579. X                }
  1580. X        ;
  1581. X
  1582. XOctetSize
  1583. X        :   LPAREN SIZE LPAREN RangeOfValues RPAREN RPAREN
  1584. X                {
  1585. X                    $$ = $4;
  1586. X                }
  1587. X        |   empty
  1588. X                {
  1589. X                    memset(&($$),0,sizeof(PAIR));
  1590. X                }
  1591. X        ;
  1592. XRangeOfValues
  1593. X        :   LITNUMBER DOTDOT LITNUMBER
  1594. X                {
  1595. X                    /*
  1596. X                     * Make sure that the first integer is less than the
  1597. X                     * second.
  1598. X                     */
  1599. X                    if( $1 > $3 )
  1600. X                             {
  1601. X                                fprintf(stderr,"Line %d : Range of %d..%d is incorrect\n",yylineno,$1,$3);
  1602. X                                $$.Lower = $3;
  1603. X                                $$.Upper = $1;
  1604. X                             }
  1605. X                        else {
  1606. X                                $$.Lower = $1;
  1607. X                                $$.Upper = $3;
  1608. X                             }
  1609. X                }
  1610. X        |   LITNUMBER
  1611. X                {
  1612. X                    $$.Lower = $$.Upper = $1;
  1613. X                }
  1614. X        ;
  1615. X
  1616. XNamedNumberList
  1617. X        :   NamedNumber
  1618. X                {
  1619. X                    $$ = $1;
  1620. X                }
  1621. X        |   NamedNumberList COMMA NamedNumber
  1622. X                {
  1623. X                    $$ = LinkToList($1,$3);
  1624. X                    yyerrok;
  1625. X                }
  1626. X        |   error
  1627. X                {
  1628. X                    $$ = 0;
  1629. X                }
  1630. X        |   NamedNumberList error
  1631. X                {
  1632. X                    $$ = $1;
  1633. X                }
  1634. X        |   NamedNumberList error NamedNumber
  1635. X                {
  1636. X                    $$ = LinkToList($1,$3);
  1637. X                    yyerrok;
  1638. X                }
  1639. X        |   NamedNumberList COMMA error
  1640. X                {
  1641. X                    $$ = $1;
  1642. X                }
  1643. X        ;
  1644. XNamedNumber
  1645. X        :   NAME LPAREN LITNUMBER RPAREN
  1646. X                {
  1647. X                    /*
  1648. X                     * Allocate a new element for the list.
  1649. X                     */
  1650. X                    $$ = newListElement(NAMEANDNUMBER,$1,$3);
  1651. X                }
  1652. X        |   NAME LPAREN error RPAREN
  1653. X                {
  1654. X                    /*
  1655. X                     * Invalid thing in the middle.
  1656. X                     */
  1657. X            fprintf(stderr,"Line %d : Incorrect NAME - NUMBER pair for name \"%s\"\n",yylineno,$1);
  1658. X                    $$ = newListElement(NAMEANDNUMBER,(char *)0,0);
  1659. X                    yyerrok;
  1660. X                }
  1661. X        ;
  1662. X
  1663. X
  1664. X
  1665. XVariables
  1666. X        :   VARIABLES LBRACE VarList RBRACE
  1667. X                {
  1668. X                    $$ = $3;
  1669. X                }
  1670. X        |   empty
  1671. X                {
  1672. X                    $$ = 0;
  1673. X                }
  1674. X        ;
  1675. XVarList
  1676. X        :   NAME
  1677. X                {
  1678. X                    $$ = newListElement(NAMEONLY,$1,0);
  1679. X                }
  1680. X        |   VarList COMMA NAME
  1681. X                {
  1682. X                    $$ = LinkToList($1,newListElement(NAMEONLY,$3,0));
  1683. X                    yyerrok;
  1684. X                }
  1685. X        |   error
  1686. X                {
  1687. X                    $$ = 0;
  1688. X                }
  1689. X        |   VarList error
  1690. X                {
  1691. X                    $$ = $1;
  1692. X                }
  1693. X        |   VarList error NAME
  1694. X                {
  1695. X                    $$ = LinkToList($1,newListElement(NAMEONLY,$3,0));
  1696. X                    yyerrok;
  1697. X                }
  1698. X        |   VarList COMMA error
  1699. X                {
  1700. X                    $$ = $1;
  1701. X                }
  1702. X        ;
  1703. X
  1704. XStatusLine
  1705. X        :   STATUS Status
  1706. X                {
  1707. X                    $$ = $2;
  1708. X                    yyerrok;
  1709. X                }
  1710. X        |   STATUS error
  1711. X                {
  1712. X                    $$ = UNKNOWN;
  1713. X                }
  1714. X        |   error
  1715. X                {
  1716. X                    $$ = UNKNOWN;
  1717. X                }
  1718. X        ;
  1719. X
  1720. XStatus
  1721. X        :   MANDATORYOBJECT
  1722. X                {
  1723. X                    $$ = (int) MANDATORY;
  1724. X                }
  1725. X        |   OPTIONALOBJECT
  1726. X                {
  1727. X                    $$ = (int) OPTIONAL;
  1728. X                }
  1729. X        |   OBSOLETEOBJECT
  1730. X                {
  1731. X                    $$ = (int) OBSOLETE;
  1732. X                }
  1733. X        |   DEPRECATEDOBJECT
  1734. X                {
  1735. X                    $$ = (int) DEPRECATED;
  1736. X                }
  1737. X        |   error
  1738. X                {
  1739. X                    $$ = (int) UNKNOWN;
  1740. X                }
  1741. X        ;
  1742. X
  1743. XAccessLine
  1744. X        :   ACCESS Access
  1745. X                {
  1746. X                    $$ = $2;
  1747. X                    yyerrok;
  1748. X                }
  1749. X        |   ACCESS error
  1750. X                {
  1751. X                    $$ = (int) UNKNOWN;
  1752. X                }
  1753. X        |   error
  1754. X                {
  1755. X                    $$ = (int) UNKNOWN;
  1756. X                }
  1757. X        ;
  1758. XAccess
  1759. X        :   READONLYOBJECT
  1760. X                {
  1761. X                    $$ = (int) RONLY;
  1762. X                }
  1763. X        |   READWRITEOBJECT
  1764. X                {
  1765. X                    $$ = (int) RWRITE;
  1766. X                }
  1767. X        |   WRITEONLYOBJECT
  1768. X                {
  1769. X                    $$ = (int) WRITEONLY;
  1770. X                }
  1771. X        |   NOTACCESSIBLEOBJECT
  1772. X                {
  1773. X                    $$ = (int) NOACCESS;
  1774. X                }
  1775. X        ;
  1776. X
  1777. XSyntaxLine
  1778. X        :   SYNTAX SyntaxType
  1779. X                {
  1780. X                    yyerrok;
  1781. X                    $$ = $2;
  1782. X                }
  1783. X        |   SYNTAX error
  1784. X                {
  1785. X                    $$ = 0;
  1786. X                }
  1787. X        ;
  1788. XSyntaxType
  1789. X        :   IntegerType
  1790. X        |   OctetType
  1791. X        |   NullType
  1792. X        |   ObjectIdType
  1793. X        |   CounterType
  1794. X        |   TimeTickType
  1795. X        |   GaugeType
  1796. X        |   IpAddressType
  1797. X        |   NetworkAddressType
  1798. X        |   SEQUENCE OF ID
  1799. X                {
  1800. X                    $$ = newTypeElement(SEQOFTYPE,
  1801. X                                    (char *)newTypeElement(TYPENAME,$3));
  1802. X                }
  1803. X    |   ID
  1804. X                {
  1805. X                    $$ = newTypeElement(TYPENAME,$1);
  1806. X                }
  1807. X        |   ERROR
  1808. X                {
  1809. X                    fprintf(stderr,"Line %d : Invalid TYPE \"%s\" -- should be \"%s\"\n",yylineno,yytext,ShouldBeKeyword(yytext));
  1810. X                    $$ = (TYPE *)0;
  1811. X                }
  1812. X        ;
  1813. X
  1814. XDescriptionLine
  1815. X        :   DESCRIPTION LITSTRING
  1816. X                {
  1817. X                    $$ = $2;
  1818. X                }
  1819. X        |   DESCRIPTION error
  1820. X                {
  1821. X                    fprintf(stderr,"Line %d : Invalid DESCRIPTION statement\n",yylineno);
  1822. X                    yyclearin;
  1823. X                    yyerrok;
  1824. X                    $$ = 0;
  1825. X                }
  1826. X        |   empty
  1827. X                {
  1828. X                    $$ = 0;
  1829. X                }
  1830. X        ;
  1831. X
  1832. XReferenceLine
  1833. X        :   REFERENCE LITSTRING
  1834. X                {
  1835. X                    $$ = $2;
  1836. X                }
  1837. X        |   REFERENCE error
  1838. X                {
  1839. X                    fprintf(stderr,"Line %d : Invalid REFERENCE statement\n",yylineno);
  1840. X                    yyclearin;
  1841. X                    yyerrok;
  1842. X                    $$ = 0;
  1843. X                }
  1844. X        |   empty
  1845. X                {
  1846. X                    $$ = 0;
  1847. X                }
  1848. X        ;
  1849. X
  1850. XIndex
  1851. X        :   INDEX LBRACE IndexList RBRACE
  1852. X                {
  1853. X                    $$ = $3;
  1854. X                }
  1855. X        |   empty
  1856. X                {
  1857. X                    $$ = 0;
  1858. X                }
  1859. X        ;
  1860. XIndexList
  1861. X        :   IndexElement
  1862. X                {
  1863. X                    $$ = $1;   
  1864. X                }
  1865. X        |   IndexList COMMA IndexElement
  1866. X                {
  1867. X                    $$ = LinkToList($1,$3);
  1868. X                    yyerrok;
  1869. X                }
  1870. X        |   error
  1871. X                {
  1872. X                    $$ = 0;
  1873. X                }
  1874. X        |   IndexList error
  1875. X                {
  1876. X                    $$ = $1;
  1877. X                }
  1878. X        |   IndexList error IndexElement
  1879. X                {
  1880. X                    $$ = LinkToList($1,$3);
  1881. X                    yyerrok;
  1882. X                }
  1883. X        |   IndexList COMMA error
  1884. X                {
  1885. X                    $$ = $1;
  1886. X                }    
  1887. X        ;
  1888. XIndexElement
  1889. X    :   NAME
  1890. X                {
  1891. X                    $$ = newListElement(NAMEONLY,$1,0);
  1892. X                }
  1893. X        |   INTEGER
  1894. X                {
  1895. X                    $$ = newListElement(NAMEONLY,"INTEGER",0);
  1896. X                }
  1897. X        |   GAUGE
  1898. X                {
  1899. X                    $$ = newListElement(NAMEONLY,"GAUGE",0);
  1900. X                }
  1901. X        |   COUNTER
  1902. X                {
  1903. X                    $$ = newListElement(NAMEONLY,"COUNTER",0);
  1904. X                }
  1905. X        |   TIMETICKS
  1906. X                {
  1907. X                    $$ = newListElement(NAMEONLY,"TIMETICKS",0);
  1908. X                }
  1909. X        |   NETWORKADDRESS
  1910. X                {
  1911. X                    $$ = newListElement(NAMEONLY,"NETWORKADDRESS",0);
  1912. X                }
  1913. X        |   IPADDRESS
  1914. X                {
  1915. X                    $$ = newListElement(NAMEONLY,"IPADDRESS",0);
  1916. X                }
  1917. X        |   OBJECT IDENTIFIER
  1918. X                {
  1919. X                    $$ = newListElement(NAMEONLY,"OID",0);
  1920. X                }
  1921. X        |   OCTET STRING
  1922. X                {
  1923. X                    $$ = newListElement(NAMEONLY,"STRING",0);
  1924. X                }
  1925. X    ;
  1926. X
  1927. XDefault
  1928. X        :   DEFVAL LBRACE Data RBRACE
  1929. X                {
  1930. X                    $$ = $3;
  1931. X                }
  1932. X        |   DEFVAL  error RBRACE
  1933. X                {
  1934. X                    fprintf(stderr,"Line %d : Invalid DEFVAL statement; expected an integer or string type\n",yylineno);
  1935. X                    yyclearin;
  1936. X                    yyerrok;
  1937. X                    $$ = 0;
  1938. X                }
  1939. X        |   empty
  1940. X                {
  1941. X                    $$ = 0;
  1942. X                }
  1943. X        ;
  1944. XData
  1945. X        :   LITNUMBER
  1946. X                {
  1947. X                    $$ = newListElement(NUMBERONLY,(char *)0,$1);
  1948. X                }
  1949. X        |   LITSTRING
  1950. X                {
  1951. X                    $$ = newListElement(STRINGONLY,$1,0);
  1952. X                }
  1953. X        |   NAME
  1954. X                {
  1955. X                    $$ = newListElement(NAMEONLY,$1,0);
  1956. X                }
  1957. X        ;
  1958. X
  1959. XOptObjectId
  1960. X        :   ObjectId
  1961. X                {
  1962. X                    $$ = $1;
  1963. X                }
  1964. X        |   empty
  1965. X                {
  1966. X                    $$ = 0;
  1967. X                }
  1968. X        ;
  1969. XObjectId
  1970. X        :   NAME
  1971. X                {
  1972. X                    $$ = newListElement(NAMEONLY,$1,0);
  1973. X                }
  1974. X        |   LBRACE  OIDList RBRACE
  1975. X                {
  1976. X                    $$ = $2;
  1977. X                }
  1978. X        ;
  1979. XOIDList
  1980. X        :   OIDSubId
  1981. X                {
  1982. X                    $$ = $1;
  1983. X                }
  1984. X        |   OIDList OIDSubId
  1985. X                {
  1986. X                    $$ = LinkToList($1,$2);
  1987. X                    yyerrok;
  1988. X                }
  1989. X        |   OIDList error
  1990. X                {
  1991. X                    $$ = $1;
  1992. X                }
  1993. X        ;
  1994. XOIDSubId
  1995. X        :   LITNUMBER
  1996. X                {
  1997. X                    $$ = newListElement(NUMBERONLY,(char *)0,$1);
  1998. X                }
  1999. X        |   NAME
  2000. X                {
  2001. X                    $$ = newListElement(NAMEONLY,$1,0);
  2002. X                }
  2003. X        |   NAME LPAREN LITNUMBER RPAREN
  2004. X                {
  2005. X                    $$ = newListElement(NAMEANDNUMBER,$1,$3);
  2006. X                }
  2007. X        ;
  2008. X
  2009. Xempty
  2010. X    :
  2011. X    ;        
  2012. X%%
  2013. X
  2014. END_OF_FILE
  2015.   if test 24493 -ne `wc -c <'yacc.y'`; then
  2016.     echo shar: \"'yacc.y'\" unpacked with wrong size!
  2017.   fi
  2018.   # end of 'yacc.y'
  2019. fi
  2020. echo shar: End of archive 1 \(of 2\).
  2021. cp /dev/null ark1isdone
  2022. MISSING=""
  2023. for I in 1 2 ; do
  2024.     if test ! -f ark${I}isdone ; then
  2025.     MISSING="${MISSING} ${I}"
  2026.     fi
  2027. done
  2028. if test "${MISSING}" = "" ; then
  2029.     echo You have unpacked both archives.
  2030.     rm -f ark[1-9]isdone
  2031. else
  2032.     echo You still must unpack the following archives:
  2033.     echo "        " ${MISSING}
  2034. fi
  2035. exit 0
  2036. exit 0 # Just in case...
  2037.