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