libnxsrv and nxcore moved to VS2005 (nxcore cannot be linked because libnxsl not...
[public/netxms.git] / src / snmp / nxmibc / parser.y
CommitLineData
5039dede
AK
1%{
2/*
3 * Copyright 2001, THE AUTHOR <mibparser@cvtt.net>
4 * All rights reserved.
5 *
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/*
35 * A parser for the basic grammar to use for snmp V2c modules
36 */
37
944016d6 38#pragma warning(disable : 4065 4102)
5039dede 39
944016d6 40/*
5039dede
AK
41#ifndef __STDC__
42#define __STDC__ 1
43#endif
944016d6 44*/
5039dede
AK
45
46#define YYMALLOC malloc
47#define YYFREE free
48
944016d6
VK
49#include <nms_common.h>
50#include <nms_util.h>
5039dede
AK
51#include <string.h>
52#include <time.h>
53#include "mibparse.h"
54#include "nxmibc.h"
55#include "nxsnmp.h"
56
57#define YYINCLUDED_STDLIB_H 1
58
59#ifdef _WIN32
60#define strdup _strdup
61#define stricmp _stricmp
62#endif
63
64#ifdef YYTEXT_POINTER
65extern char *mptext;
66#else
67extern char mptext[];
68#endif
69
70#ifdef __64BIT__
71#define YYSIZE_T INT64
72#endif
73
74extern FILE *mpin, *mpout;
75extern int g_nCurrLine;
76
77static MP_MODULE *m_pModule;
78static char *m_pszCurrentFilename;
79
80int mperror(char *pszMsg);
81int mplex(void);
82
83MP_SYNTAX *create_std_syntax(int nSyntax)
84{
85 MP_SYNTAX *p;
86
87 p = CREATE(MP_SYNTAX);
88 p->nSyntax = nSyntax;
89 return p;
90}
91
92void *__zmalloc(unsigned int nSize)
93{
94 void *p;
95
96 p = malloc(nSize);
97 if (p != NULL)
98 memset(p, 0, nSize);
99 return p;
100}
101
944016d6 102static int AccessFromText(const char *pszText)
5039dede 103{
944016d6
VK
104 static const char *pText[] = { "read-only", "read-write", "write-only",
105 "not-accessible", "accessible-for-notify",
106 "read-create", NULL };
5039dede
AK
107 char szBuffer[256];
108 int i;
109
110 for(i = 0; pText[i] != NULL; i++)
111 if (strcmp(pszText, pText[i]))
112 return i + 1;
113 sprintf(szBuffer, "Invalid ACCESS value \"%s\"", pszText);
114 mperror(szBuffer);
115 return -1;
116}
117
118%}
119
120/*
121 * Union structure. A terminal or non-terminal can have
122 * one of these type values.
123 */
124
125%union
126{
127 int nInteger;
128 char *pszString;
129 MP_NUMERIC_VALUE number;
130 DynArray *pList;
131 MP_IMPORT_MODULE *pImports;
132 MP_OBJECT *pObject;
133 MP_SUBID *pSubId;
134 MP_SYNTAX *pSyntax;
135}
136
137%token ENTERPRISE_SYM
138%token TRAP_TYPE_SYM
139%token VARIABLES_SYM
140%token EXPLICIT_SYM
141%token IMPLICIT_SYM
142%token IMPLIED_SYM
143%token RIGHT_BRACE_SYM
144%token LEFT_BRACE_SYM
145%token RIGHT_BRACKET_SYM
146%token LEFT_BRACKET_SYM
147%token DEFINITIONS_SYM
148%token ASSIGNMENT_SYM
149%token BEGIN_SYM
150%token END_SYM
151%token FROM_SYM
152%token IMPORTS_SYM
153%token EXPORTS_SYM
154%token COMMA_SYM
155%token SEMI_COLON_SYM
156%token DOT_SYM
157%token DESCRIPTION_SYM
158%token ORGANIZATION_SYM
159%token CONTACT_SYM
160%token UPDATE_SYM
161%token MODULE_IDENTITY_SYM
162%token MODULE_COMPLIANCE_SYM
163%token OBJECT_IDENTIFIER_SYM
164%token OBJECT_TYPE_SYM
165%token OBJECT_GROUP_SYM
166%token OBJECT_IDENTITY_SYM
167%token OBJECTS_SYM
168%token MANDATORY_GROUPS_SYM
169%token GROUP_SYM
170%token AGENT_CAPABILITIES_SYM
171%token KEYWORD_SYM
172%token KEYWORD_VALUE_SYM
173%token KEYWORD_BIND_SYM
174%token TOKEN_SYM
175
176%token INTEGER_SYM
177%token INTEGER32_SYM
178%token UNSIGNED32_SYM
179%token GAUGE32_SYM
180%token COUNTER_SYM
181%token COUNTER32_SYM
182%token COUNTER64_SYM
183%token BITS_SYM
184%token STRING_SYM
185%token OCTET_SYM
186%token SEQUENCE_SYM
187%token OF_SYM
188%token TIMETICKS_SYM
189%token IP_ADDRESS_SYM
190%token NETWORK_ADDRESS_SYM
191%token OPAQUE_SYM
192%token REVISION_SYM
193%token TEXTUAL_CONVENTION_SYM
194
195%token ACCESS_SYM
196%token MAX_ACCESS_SYM
197%token MIN_ACCESS_SYM
198%token SYNTAX_SYM
199%token STATUS_SYM
200%token INDEX_SYM
201%token REFERENCE_SYM
202%token DEFVAL_SYM
203%token LEFT_PAREN_SYM
204%token RIGHT_PAREN_SYM
205%token NOTIFICATIONS_SYM
206%token NOTIFICATION_GROUP_SYM
207%token NOTIFICATION_TYPE_SYM
208%token SIZE_SYM
209%token BAR_SYM
210%token VARIATION_SYM
211%token WRITE_SYNTAX_SYM
212%token SUPPORTS_SYM
213%token INCLUDES_SYM
214%token CREATION_REQUIRES_SYM
215%token PRODUCT_RELEASE_SYM
216%token CHOICE_SYM
217%token UNITS_SYM
218%token AUGMENTS_SYM
219%token OBJECT_SYM
220%token TAGS_SYM
221%token AUTOMATIC_SYM
222
223%token <pszString> MACRO_SYM
224%token <pszString> MODULE_SYM
225%token <pszString> UCASEFIRST_IDENT_SYM LCASEFIRST_IDENT_SYM
226%token <pszString> BSTRING_SYM HSTRING_SYM CSTRING_SYM DISPLAY_HINT_SYM
227
228%token <number> NUMBER_SYM
229
230%type <nInteger> SnmpStatusPart SnmpAccessPart
231
232%type <pSyntax> SnmpSyntaxPart SnmpSyntax Type BuiltInType NamedType
233%type <pSyntax> TextualConventionAssignment BuiltInTypeAssignment
234
235%type <pszString> UCidentifier LCidentifier Identifier
236%type <pszString> ModuleIdentifier DefinedValue SnmpIdentityPart
237%type <pszString> Symbol CharString NumericValue
238%type <pszString> SnmpDescriptionPart
239
240%type <number> Number
241
242%type <pList> SymbolList SymbolsFromModuleList
243%type <pList> AssignedIdentifierList AssignedIdentifier ObjectIdentifierList
244%type <pImports> SymbolsFromModule
245%type <pObject> ObjectIdentifierAssignment ObjectIdentityAssignment ObjectTypeAssignment
246%type <pObject> MacroAssignment TypeOrValueAssignment ModuleIdentityAssignment
247%type <pObject> SnmpObjectGroupAssignment SnmpNotificationGroupAssignment
248%type <pObject> SnmpNotificationTypeAssignment AgentCapabilitiesAssignment
249%type <pSubId> ObjectIdentifier
250
251/*
252 * Type definitions of non-terminal symbols
253*/
254
255%start ModuleDefinition
256%%
257
258/*-----------------------------------------------------------------------*/
259/* Module def/import/export productions */
260/*-----------------------------------------------------------------------*/
261
262ModuleDefinition:
263 ModuleIdentifierAssignment AssignmentList
264 End
265;
266
267AssignmentList:
268 AssignmentList Assignment
269| Assignment
270;
271
272Assignment:
273 ObjectIdentifierAssignment
274{
275 da_add(m_pModule->pObjectList, $1);
276}
277| ObjectIdentityAssignment
278{
279 da_add(m_pModule->pObjectList, $1);
280}
281| ObjectTypeAssignment
282{
283 da_add(m_pModule->pObjectList, $1);
284}
285| MacroAssignment
286{
287 da_add(m_pModule->pObjectList, $1);
288}
289| TypeOrValueAssignment
290{
291 da_add(m_pModule->pObjectList, $1);
292}
293| SnmpNotificationTypeAssignment
294{
295 da_add(m_pModule->pObjectList, $1);
296}
297| ModuleComplianceAssignment
298| SnmpNotificationGroupAssignment
299{
300 da_add(m_pModule->pObjectList, $1);
301}
302| SnmpObjectGroupAssignment
303{
304 da_add(m_pModule->pObjectList, $1);
305}
306| SnmpKeywordAssignment
307| AgentCapabilitiesAssignment
308{
309 da_add(m_pModule->pObjectList, $1);
310}
311| ModuleIdentityAssignment
312{
313 da_add(m_pModule->pObjectList, $1);
314}
315| ImportsAssignment
316| ExportsAssignment
317;
318
319ModuleIdentifierAssignment:
320 ModuleIdentifier
321{
322 m_pModule = CREATE(MP_MODULE);
323 m_pModule->pszName = $1;
324 m_pModule->pObjectList = da_create();
325}
326;
327
328ModuleIdentifier:
329 UCidentifier DEFINITIONS_SYM ASSIGNMENT_SYM Begin
330{
331 $$ = $1;
332}
333| UCidentifier DEFINITIONS_SYM ASSIGNMENT_SYM AUTOMATIC_SYM TAGS_SYM Begin
334{
335 $$ = $1;
336}
337;
338
339ObjectIdentifierAssignment:
340 LCidentifier OBJECT_IDENTIFIER_SYM AssignedIdentifier
341{
342 $$ = CREATE(MP_OBJECT);
343 $$->iType = MIBC_OBJECT;
344 $$->pszName = $1;
345 $$->pOID = $3;
346}
347| LCidentifier AssignedIdentifier
348{
349 $$ = CREATE(MP_OBJECT);
350 $$->iType = MIBC_OBJECT;
351 $$->pszName = $1;
352 $$->pOID = $2;
353}
354;
355
356AssignedIdentifier:
357 ASSIGNMENT_SYM AssignedIdentifierList
358{
359 $$ = $2;
360}
361| ASSIGNMENT_SYM Number
362{
363 MP_SUBID *subid;
364
365 subid = CREATE(MP_SUBID);
366 subid->dwValue = $2.value.nInt32;
367 subid->pszName = NULL;
368 subid->bResolved = TRUE;
369 $$ = da_create();
370 da_add($$, subid);
371}
372;
373
374AssignedIdentifierList:
375 LEFT_BRACE_SYM ObjectIdentifierList RIGHT_BRACE_SYM
376{
377 $$ = $2;
378}
379;
380
381ObjectIdentifierList:
382 ObjectIdentifierList ObjectIdentifier
383{
384 da_add($$, $2);
385}
386| ObjectIdentifier
387{
388 $$ = da_create();
389 da_add($$, $1);
390}
391;
392
393ObjectIdentifier:
394 Number
395{
396 $$ = CREATE(MP_SUBID);
397 $$->dwValue = $1.value.nInt32;
398 $$->pszName = NULL;
399 $$->bResolved = TRUE;
400}
401| DefinedValue
402{
403 $$ = CREATE(MP_SUBID);
404 $$->dwValue = 0;
405 $$->pszName = $1;
406 $$->bResolved = FALSE;
407}
408| Identifier LEFT_PAREN_SYM Number RIGHT_PAREN_SYM
409{
410 $$ = CREATE(MP_SUBID);
411 $$->dwValue = $3.value.nInt32;
412 $$->pszName = $1;
413 $$->bResolved = TRUE;
414}
415;
416
417NumericValue:
418 Number
419{
420 $$ = NULL;
421}
422| DefinedValue
423{
424 $$ = NULL;
425}
426| Number DOT_SYM DOT_SYM Number
427{
428 $$ = NULL;
429}
430| Identifier LEFT_PAREN_SYM Number RIGHT_PAREN_SYM
431{
432 $$ = NULL;
433}
434;
435
436DefinedValue:
437 UCidentifier DOT_SYM LCidentifier
438{
439 $$ = (char *)malloc(strlen($1) + strlen($3) + 2);
440 sprintf($$, "%s.%s", $1, $3);
441 free($1);
442 free($3);
443}
444| LCidentifier
445{
446 $$ = $1;
447}
448;
449
450Number:
451 NUMBER_SYM
452{
453 $$ = $1;
454}
455;
456
457ObjectIdentityAssignment:
458 LCidentifier OBJECT_IDENTITY_SYM
459 SnmpStatusPart
460 SnmpDescriptionPart
461 SnmpReferencePart
462 AssignedIdentifier
463{
464 $$ = CREATE(MP_OBJECT);
465 $$->iType = MIBC_OBJECT;
466 $$->pszName = $1;
467 $$->iStatus = $3;
468 $$->pszDescription = $4;
469 $$->pOID = $6;
470}
471;
472
473ObjectTypeAssignment:
474 Identifier OBJECT_TYPE_SYM
475 SnmpSyntaxPart
476 SnmpUnitsPart
477 SnmpAccessPart
478 SnmpStatusPart
479 SnmpDescriptionPart
480 SnmpReferencePart
481 SnmpIndexPart
482 SnmpDefValPart
483 AssignedIdentifier
484{
485 $$ = CREATE(MP_OBJECT);
486 $$->iType = MIBC_OBJECT;
487 $$->pszName = $1;
488 $$->iSyntax = $3->nSyntax;
489 $$->pszDataType = $3->pszStr;
490 safe_free($3);
491 $$->iAccess = $5;
492 $$->iStatus = $6;
493 $$->pszDescription = $7;
494 $$->pOID = $11;
495}
496;
497
498ModuleIdentityAssignment:
499 SnmpIdentityPart
500 SnmpUpdatePart
501 SnmpOrganisationPart
502 SnmpContactInfoPart
503 SnmpDescriptionPart
504 SnmpRevisionPart
505 AssignedIdentifier
506{
507 $$ = CREATE(MP_OBJECT);
508 $$->iType = MIBC_OBJECT;
509 $$->iSyntax = MIB_TYPE_MODID;
510 $$->pszName = $1;
511 $$->pszDescription = $5;
512 $$->pOID = $7;
513}
514;
515
516ImportsAssignment:
517 IMPORTS_SYM SymbolsFromModuleList SEMI_COLON_SYM
518{
519 m_pModule->pImportList = $2;
520}
521;
522
523ExportsAssignment:
524 EXPORTS_SYM SymbolList SEMI_COLON_SYM
525;
526
527SnmpRevisionPart:
528 SnmpRevisionList
529|
530;
531
532SnmpRevisionList:
533 SnmpRevisionList SnmpRevisionObject
534| SnmpRevisionObject
535;
536
537SnmpRevisionObject:
538 REVISION_SYM CharString
539 SnmpDescriptionPart
540;
541
542SnmpIdentityPart:
543 LCidentifier MODULE_IDENTITY_SYM
544{
545 $$ = $1;
546}
547;
548
549SnmpOrganisationPart:
550 ORGANIZATION_SYM CharString
551;
552
553SnmpContactInfoPart:
554 CONTACT_SYM CharString
555;
556
557SnmpUpdatePart:
558 UPDATE_SYM CharString
559;
560
561SnmpDescriptionPart:
562 DESCRIPTION_SYM CharString
563{
564 $$ = $2;
565}
566|
567{
568 $$ = NULL;
569}
570;
571
572ValueConstraint:
573 LEFT_PAREN_SYM NumericValueConstraintList RIGHT_PAREN_SYM
574| LEFT_PAREN_SYM SIZE_SYM LEFT_PAREN_SYM NumericValueConstraintList RIGHT_PAREN_SYM RIGHT_PAREN_SYM
575| LEFT_BRACE_SYM NumericValueConstraintList RIGHT_BRACE_SYM
576;
577
578NumericValueConstraintList:
579 NumericValue BAR_SYM NumericValueConstraintList
580| NumericValue COMMA_SYM NumericValueConstraintList
581| NumericValue
582{
583}
584;
585
586SnmpKeywordAssignment:
587 SnmpKeywordName
588| SnmpKeywordName SnmpKeywordValue
589| SnmpKeywordName SnmpKeywordBinding SnmpKeywordValue
590;
591
592SnmpKeywordName:
593 KEYWORD_SYM ASSIGNMENT_SYM CharString
594;
595
596SnmpKeywordValue:
597 KEYWORD_VALUE_SYM ASSIGNMENT_SYM CharString
598;
599
600SnmpKeywordBinding:
601 KEYWORD_BIND_SYM ASSIGNMENT_SYM LEFT_BRACE_SYM SymbolList RIGHT_BRACE_SYM
602;
603
604SnmpSyntax:
605 SYNTAX_SYM Type
606{
607 $$ = $2;
608}
609;
610
611SnmpSyntaxPart:
612 SnmpSyntax
613{
614 $$ = $1;
615}
616|
617{
618 $$ = CREATE(MP_SYNTAX);
619 $$->nSyntax = MIB_TYPE_OTHER;
620}
621;
622
623SnmpUnitsPart:
624 UNITS_SYM CharString
625|
626;
627
628SnmpWriteSyntaxPart:
629 WRITE_SYNTAX_SYM Type
630|
631;
632
633SnmpCreationPart:
634 CREATION_REQUIRES_SYM SymbolList
635|
636;
637
638TypeOrValueAssignment:
639 BuiltInTypeAssignment
640{
641 $$ = CREATE(MP_OBJECT);
642 $$->iType = MIBC_TYPEDEF;
643 if ($1 != NULL)
644 {
645 $$->pszName = $1->pszStr;
646 $$->iSyntax = $1->nSyntax;
647 free($1);
648 }
649}
650| UCidentifier ASSIGNMENT_SYM TextualConventionAssignment
651{
652 $$ = CREATE(MP_OBJECT);
653 $$->iType = MIBC_TEXTUAL_CONVENTION;
654 $$->pszName = $1;
655 if ($3 != NULL)
656 {
657 $$->iSyntax = $3->nSyntax;
658 $$->pszDataType = $3->pszStr;
659 free($3);
660 }
661}
662| UCidentifier ASSIGNMENT_SYM Type
663{
664 $$ = CREATE(MP_OBJECT);
665 $$->iType = MIBC_TYPEDEF;
666 $$->pszName = $1;
667 if ($3 != NULL)
668 {
669 $$->iSyntax = $3->nSyntax;
670 $$->pszDataType = $3->pszStr;
671 free($3);
672 }
673}
674| UCidentifier ASSIGNMENT_SYM SEQUENCE_SYM SequenceAssignment
675{
676 $$ = CREATE(MP_OBJECT);
677 $$->iType = MIBC_SEQUENCE;
678 $$->pszName = $1;
679}
680| LCidentifier ASSIGNMENT_SYM SEQUENCE_SYM SequenceAssignment
681{
682 $$ = CREATE(MP_OBJECT);
683 $$->iType = MIBC_SEQUENCE;
684 $$->pszName = $1;
685}
686| UCidentifier ASSIGNMENT_SYM CHOICE_SYM SequenceAssignment
687{
688 $$ = CREATE(MP_OBJECT);
689 $$->iType = MIBC_CHOICE;
690 $$->pszName = $1;
691}
692| UCidentifier ASSIGNMENT_SYM Value
693{
694 $$ = CREATE(MP_OBJECT);
695 $$->iType = MIBC_VALUE;
696 $$->pszName = $1;
697}
698;
699
700Type:
701 BuiltInType
702{
703 $$ = $1;
704}
705| NamedType
706{
707 $$ = $1;
708}
709| BuiltInType ValueConstraint
710{
711 $$ = $1;
712}
713| NamedType ValueConstraint
714{
715 $$ = $1;
716}
717;
718
719NamedType:
720 SnmpTypeTagPart Identifier
721{
722 $$ = CREATE(MP_SYNTAX);
723 $$->nSyntax = -1;
724 $$->pszStr = $2;
725}
726;
727
728BuiltInType:
729 SnmpTypeTagPart INTEGER_SYM
730{
731 $$ = create_std_syntax(MIB_TYPE_INTEGER);
732}
733| SnmpTypeTagPart IMPLICIT_SYM INTEGER_SYM
734{
735 $$ = create_std_syntax(MIB_TYPE_INTEGER);
736}
737| SnmpTypeTagPart INTEGER32_SYM
738{
739 $$ = create_std_syntax(MIB_TYPE_INTEGER32);
740}
741| SnmpTypeTagPart UNSIGNED32_SYM
742{
743 $$ = create_std_syntax(MIB_TYPE_UNSIGNED32);
744}
745| SnmpTypeTagPart COUNTER_SYM
746{
747 $$ = create_std_syntax(MIB_TYPE_COUNTER);
748}
749| SnmpTypeTagPart COUNTER32_SYM
750{
751 $$ = create_std_syntax(MIB_TYPE_COUNTER32);
752}
753| SnmpTypeTagPart COUNTER64_SYM
754{
755 $$ = create_std_syntax(MIB_TYPE_COUNTER64);
756}
757| SnmpTypeTagPart GAUGE32_SYM
758{
759 $$ = create_std_syntax(MIB_TYPE_GAUGE32);
760}
761| SnmpTypeTagPart TIMETICKS_SYM
762{
763 $$ = create_std_syntax(MIB_TYPE_TIMETICKS);
764}
765| SEQUENCE_SYM OF_SYM NamedType
766{
767 $$ = create_std_syntax(MIB_TYPE_SEQUENCE);
768}
769| SnmpTypeTagPart OBJECT_IDENTIFIER_SYM
770{
771 $$ = create_std_syntax(MIB_TYPE_OBJID);
772}
773| SnmpTypeTagPart OctetStringType
774{
775 $$ = create_std_syntax(MIB_TYPE_OCTETSTR);
776}
777;
778
779BuiltInTypeAssignment:
780 IP_ADDRESS_SYM ASSIGNMENT_SYM Type
781{
782 $$ = create_std_syntax(MIB_TYPE_IPADDR);
783 $$->pszStr = strdup("IpAddress");
784}
785| OPAQUE_SYM ASSIGNMENT_SYM Type
786{
787 $$ = create_std_syntax(MIB_TYPE_OPAQUE);
788 $$->pszStr = strdup("Opaque");
789}
790| INTEGER32_SYM ASSIGNMENT_SYM Type
791{
792 $$ = create_std_syntax(MIB_TYPE_INTEGER32);
793 $$->pszStr = strdup("Integer32");
794}
795| UNSIGNED32_SYM ASSIGNMENT_SYM Type
796{
797 $$ = create_std_syntax(MIB_TYPE_UNSIGNED32);
798 $$->pszStr = strdup("Unsigned32");
799}
800| TIMETICKS_SYM ASSIGNMENT_SYM Type
801{
802 $$ = create_std_syntax(MIB_TYPE_TIMETICKS);
803 $$->pszStr = strdup("TimeTicks");
804}
805| COUNTER_SYM ASSIGNMENT_SYM Type
806{
807 $$ = create_std_syntax(MIB_TYPE_COUNTER);
808 $$->pszStr = strdup("Counter");
809}
810| COUNTER32_SYM ASSIGNMENT_SYM Type
811{
812 $$ = create_std_syntax(MIB_TYPE_COUNTER32);
813 $$->pszStr = strdup("Counter32");
814}
815| COUNTER64_SYM ASSIGNMENT_SYM Type
816{
817 $$ = create_std_syntax(MIB_TYPE_COUNTER64);
818 $$->pszStr = strdup("Counter64");
819}
820| GAUGE32_SYM ASSIGNMENT_SYM Type
821{
822 $$ = create_std_syntax(MIB_TYPE_GAUGE32);
823 $$->pszStr = strdup("Gauge32");
824}
825;
826
827MacroAssignment:
828 MACRO_SYM ASSIGNMENT_SYM Begin TokenList End
829{
830 $$ = CREATE(MP_OBJECT);
831 $$->iType = MIBC_MACRO;
832 $$->pszName = $1;
833}
834;
835
836TokenList:
837 TokenList TokenObject
838| TokenObject
839;
840
841TokenObject:
842 TOKEN_SYM
843;
844
845TextualConventionAssignment:
846 TEXTUAL_CONVENTION_SYM
847 SnmpDisplayHintPart
848 SnmpStatusPart
849 SnmpDescriptionPart
850 SnmpReferencePart
851 SnmpSyntaxPart
852{
853 $$ = $6;
854}
855;
856
857SnmpNotificationTypeAssignment:
858 LCidentifier NOTIFICATION_TYPE_SYM
859 SnmpObjectsPart
860 SnmpStatusPart
861 SnmpDescriptionPart
862 SnmpReferencePart
863 AssignedIdentifier
864{
865 $$ = CREATE(MP_OBJECT);
866 $$->iType = MIBC_OBJECT;
867 $$->pszName = $1;
868 $$->iSyntax = MIB_TYPE_NOTIFTYPE;
869 $$->iStatus = $4;
870 $$->pszDescription = $5;
871 $$->pOID = $7;
872}
873| LCidentifier TRAP_TYPE_SYM
874 ENTERPRISE_SYM LCidentifier
875 SnmpTrapVariablePart
876 SnmpDescriptionPart
877 SnmpReferencePart
878 AssignedIdentifier
879{
880 MP_SUBID *pSubId;
881
882 $$ = CREATE(MP_OBJECT);
883 $$->iType = MIBC_OBJECT;
884 $$->pszName = $1;
885 $$->iSyntax = MIB_TYPE_TRAPTYPE;
886 $$->pszDescription = $6;
887
888 pSubId = CREATE(MP_SUBID);
889 pSubId->pszName = $4;
890 $$->pOID = da_create();
891 da_add($$->pOID, pSubId);
892
893 pSubId = CREATE(MP_SUBID);
894 pSubId->pszName = (char *)malloc(strlen($4) + 3);
895 sprintf(pSubId->pszName, "%s#0", $4);
896 pSubId->bResolved = TRUE;
897 da_add($$->pOID, pSubId);
898
899 da_join($$->pOID, $8);
900 da_destroy($8);
901}
902;
903
904SnmpTrapVariablePart:
905 SnmpTrapVariableList
906|
907;
908
909SnmpTrapVariableList:
910 VARIABLES_SYM LEFT_BRACE_SYM SymbolList RIGHT_BRACE_SYM
911;
912
913SnmpMandatoryGroupPart:
914 SnmpMandatoryGroupList
915|
916;
917
918SnmpMandatoryGroupList:
919 SnmpMandatoryGroupList SnmpMandatoryGroup
920| SnmpMandatoryGroup
921;
922
923SnmpMandatoryGroup:
924 MANDATORY_GROUPS_SYM LEFT_BRACE_SYM SymbolList RIGHT_BRACE_SYM
925;
926
927SnmpCompliancePart:
928 SnmpComplianceList
929|
930;
931
932SnmpComplianceList:
933 SnmpComplianceList SnmpComplianceObject
934| SnmpComplianceObject
935;
936
937SnmpComplianceObject:
938 OBJECT_SYM LCidentifier
939 SnmpSyntaxPart
940 SnmpWriteSyntaxPart
941 SnmpAccessPart
942 SnmpDescriptionPart
943| GROUP_SYM LCidentifier SnmpDescriptionPart
944;
945
946SnmpObjectsPart:
947 OBJECTS_SYM LEFT_BRACE_SYM SymbolList RIGHT_BRACE_SYM
948| NOTIFICATIONS_SYM LEFT_BRACE_SYM SymbolList RIGHT_BRACE_SYM
949|
950;
951
952SnmpObjectGroupAssignment:
953 LCidentifier OBJECT_GROUP_SYM
954 SnmpObjectsPart
955 SnmpStatusPart
956 SnmpDescriptionPart
957 AssignedIdentifier
958{
959 $$ = CREATE(MP_OBJECT);
960 $$->iType = MIBC_OBJECT;
961 $$->pszName = $1;
962 $$->iStatus = $4;
963 $$->iSyntax = MIB_TYPE_OBJGROUP;
964 $$->pszDescription = $5;
965 $$->pOID = $6;
966}
967;
968
969SnmpNotificationGroupAssignment:
970 LCidentifier NOTIFICATION_GROUP_SYM
971 SnmpObjectsPart
972 SnmpStatusPart
973 SnmpDescriptionPart
974 AssignedIdentifier
975{
976 $$ = CREATE(MP_OBJECT);
977 $$->iType = MIBC_OBJECT;
978 $$->pszName = $1;
979 $$->iStatus = $4;
980 $$->pszDescription = $5;
981 $$->pOID = $6;
982}
983;
984
985ModuleComplianceAssignment:
986 LCidentifier MODULE_COMPLIANCE_SYM
987 SnmpStatusPart
988 SnmpDescriptionPart
989 SnmpReferencePart
990 SnmpModuleComplianceList
991 AssignedIdentifier
992{
993 free($1);
994 safe_free($4);
995}
996;
997
998SnmpModuleComplianceList:
999 SnmpModuleComplianceList SnmpModuleComplianceObject
1000| SnmpModuleComplianceObject
1001;
1002
1003SnmpModuleComplianceObject:
1004 MODULE_SYM
1005 SnmpMandatoryGroupPart
1006 SnmpCompliancePart
1007{
1008 free($1);
1009}
1010;
1011
1012SnmpVariationsListPart:
1013 SnmpVariationsList
1014|
1015;
1016
1017SnmpVariationsList:
1018 SnmpVariationsList SnmpVariationPart
1019| SnmpVariationPart
1020;
1021
1022SnmpVariationPart:
1023 VARIATION_SYM LCidentifier
1024 SnmpSyntaxPart
1025 SnmpWriteSyntaxPart
1026 SnmpAccessPart
1027 SnmpCreationPart
1028 SnmpDefValPart
1029;
1030
1031ModuleCapabilitiesList:
1032 ModuleCapabilitiesList ModuleCapabilitiesAssignment
1033| ModuleCapabilitiesAssignment
1034;
1035
1036ModuleCapabilitiesAssignment:
1037 ModuleIdentifier INCLUDES_SYM SymbolList SnmpVariationsListPart
1038{
1039 safe_free($1);
1040}
1041;
1042
1043AgentCapabilitiesAssignment:
1044 LCidentifier AGENT_CAPABILITIES_SYM
1045 PRODUCT_RELEASE_SYM CharString
1046 SnmpStatusPart
1047 SnmpDescriptionPart
1048 ModuleCapabilitiesList
1049 AssignedIdentifier
1050{
1051 $$ = CREATE(MP_OBJECT);
1052 $$->iType = MIBC_OBJECT;
1053 $$->pszName = $1;
1054 $$->iStatus = $5;
1055 $$->iSyntax = MIB_TYPE_AGENTCAP;
1056 $$->pszDescription = $6;
1057 $$->pOID = $8;
1058}
1059;
1060
1061SnmpAccessPart:
1062 ACCESS_SYM LCidentifier
1063{
1064 $$ = AccessFromText($2);
1065}
1066| MAX_ACCESS_SYM LCidentifier
1067{
1068 $$ = AccessFromText($2);
1069}
1070| MIN_ACCESS_SYM LCidentifier
1071{
1072 $$ = AccessFromText($2);
1073}
1074|
1075{
1076 $$ = 0;
1077}
1078;
1079
1080SnmpStatusPart:
1081 STATUS_SYM LCidentifier
1082{
1083 static char *pStatusText[] = { "mandatory", "optional", "obsolete",
1084 "deprecated", "current", NULL };
1085 int i;
1086
1087 for(i = 0; pStatusText[i] != NULL; i++)
1088 if (!stricmp(pStatusText[i], $2))
1089 {
1090 $$ = i + 1;
1091 break;
1092 }
1093 if (pStatusText[i] == NULL)
1094 {
1095 char szBuffer[256];
1096
1097 sprintf(szBuffer, "Invalid STATUS value \"%s\"", $2);
1098 mperror(szBuffer);
1099 }
1100}
1101;
1102
1103SnmpReferencePart:
1104 REFERENCE_SYM CharString
1105|
1106;
1107
1108SnmpDisplayHintPart:
1109 DISPLAY_HINT_SYM CharString
1110{
1111 safe_free($2);
1112}
1113|
1114;
1115
1116SnmpIndexPart:
1117 INDEX_SYM LEFT_BRACE_SYM SymbolList RIGHT_BRACE_SYM
1118| AUGMENTS_SYM LEFT_BRACE_SYM DefinedValue RIGHT_BRACE_SYM
1119|
1120;
1121
1122SnmpDefValPart:
1123 DEFVAL_SYM LEFT_BRACE_SYM BinaryString RIGHT_BRACE_SYM
1124| DEFVAL_SYM LEFT_BRACE_SYM HexString RIGHT_BRACE_SYM
1125| DEFVAL_SYM LEFT_BRACE_SYM CharString RIGHT_BRACE_SYM
1126| DEFVAL_SYM LEFT_BRACE_SYM DefValList RIGHT_BRACE_SYM
1127| DEFVAL_SYM AssignedIdentifierList
1128|
1129;
1130
1131DefValList:
1132 DefValListElement COMMA_SYM DefValList
1133| DefValListElement
1134;
1135
1136DefValListElement:
1137 LEFT_BRACE_SYM SymbolList RIGHT_BRACE_SYM
1138| LEFT_BRACE_SYM RIGHT_BRACE_SYM
1139;
1140
1141BinaryString:
1142 BSTRING_SYM
1143{
1144 safe_free($1);
1145}
1146;
1147
1148HexString:
1149 HSTRING_SYM
1150{
1151 safe_free($1);
1152}
1153;
1154
1155CharString:
1156 CSTRING_SYM
1157{
1158 $$ = $1;
1159}
1160;
1161
1162SymbolsFromModuleList:
1163 SymbolsFromModuleList SymbolsFromModule
1164{
1165 da_add($$, $2);
1166}
1167| SymbolsFromModule
1168{
1169 $$ = da_create();
1170 da_add($$, $1);
1171}
1172;
1173
1174SymbolsFromModule:
1175 SymbolList FROM_SYM UCidentifier
1176{
1177 $$ = CREATE(MP_IMPORT_MODULE);
1178 $$->pszName = $3;
1179 $$->pSymbols = $1;
1180}
1181;
1182
1183SymbolList:
1184 SymbolList COMMA_SYM Symbol
1185{
1186 da_add($$, $3);
1187}
1188| Symbol
1189{
1190 $$ = da_create();
1191 da_add($$, $1);
1192}
1193;
1194
1195Symbol:
1196 UCidentifier
1197{
1198 $$ = $1;
1199}
1200| LCidentifier
1201{
1202 $$ = $1;
1203}
1204| IMPLIED_SYM LCidentifier
1205{
1206 $$ = $2;
1207}
1208;
1209
1210SequenceItem:
1211 Identifier Type
1212{
1213 safe_free($1);
1214 if ($2 != NULL)
1215 {
1216 safe_free($2->pszStr);
1217 free($2);
1218 }
1219}
1220;
1221
1222SequenceList:
1223 SequenceItem
1224| SequenceList COMMA_SYM SequenceItem
1225;
1226
1227SequenceAssignment:
1228 LEFT_BRACE_SYM SequenceList RIGHT_BRACE_SYM
1229;
1230
1231SnmpTypeTagPart:
1232 SnmpTypeTagList
1233|
1234;
1235
1236SnmpTypeTagList:
1237 SnmpTypeTagList SnmpTypeTagItem
1238| SnmpTypeTagItem
1239;
1240
1241SnmpTypeTagItem:
1242 LEFT_BRACKET_SYM UCidentifier Number RIGHT_BRACKET_SYM
1243;
1244
1245OctetStringType:
1246 OCTET_SYM STRING_SYM
1247| EXPLICIT_SYM OCTET_SYM STRING_SYM
1248| IMPLICIT_SYM OCTET_SYM STRING_SYM
1249| IP_ADDRESS_SYM
1250| NETWORK_ADDRESS_SYM
1251| OPAQUE_SYM
1252| BITS_SYM
1253;
1254
1255Value:
1256 Number
1257{
1258}
1259| HexString
1260| BinaryString
1261| CharString
1262{
1263 safe_free($1);
1264}
1265;
1266
1267Identifier:
1268 UCidentifier
1269{
1270 $$ = $1;
1271}
1272| LCidentifier
1273{
1274 $$ = $1;
1275}
1276;
1277
1278UCidentifier:
1279 UCASEFIRST_IDENT_SYM
1280{
1281 $$ = $1;
1282}
1283;
1284
1285LCidentifier:
1286 LCASEFIRST_IDENT_SYM
1287{
1288 $$ = $1;
1289}
1290;
1291
1292End:
1293 END_SYM
1294;
1295
1296Begin:
1297 BEGIN_SYM
1298;
1299
1300%%
1301
1302MP_MODULE *ParseMIB(char *pszFilename)
1303{
1304 m_pModule = NULL;
1305 mpin = fopen(pszFilename, "r");
1306 if(mpin != NULL)
1307 {
1308 m_pszCurrentFilename = pszFilename;
1309 g_nCurrLine = 1;
1310 InitStateStack();
1311 /*mpdebug=1;*/
1312 mpparse();
1313 fclose(mpin);
1314 }
1315 else
1316 {
1317 Error(ERR_CANNOT_OPEN_FILE, pszFilename, strerror(errno));
1318 return NULL;
1319 }
1320 return m_pModule;
1321}
1322
944016d6 1323extern "C" int mpwrap()
5039dede
AK
1324{
1325 return 1;
1326}
1327
1328int mperror(char *pszMsg)
1329{
1330 Error(ERR_PARSER_ERROR, m_pszCurrentFilename, pszMsg, g_nCurrLine);
1331 return 0;
1332}