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