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