net-snmp 3.9.5 → 3.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +4 -0
  2. package/index.js +11 -22
  3. package/lib/mib.js +31 -29
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -3297,6 +3297,10 @@ Example programs are included under the module's `example` directory.
3297
3297
 
3298
3298
  * Normalize whitespace parsing for OBJECT IDENTIFIER value
3299
3299
 
3300
+ ## Version 3.9.6 - 30/05/2023
3301
+
3302
+ * Add type constraint support for textual conventions
3303
+
3300
3304
  # License
3301
3305
 
3302
3306
  Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
package/index.js CHANGED
@@ -88,22 +88,6 @@ ObjectType.Integer32 = ObjectType.Integer;
88
88
  ObjectType.Counter32 = ObjectType.Counter;
89
89
  ObjectType.Gauge32 = ObjectType.Gauge;
90
90
  ObjectType.Unsigned32 = ObjectType.Gauge32;
91
- // SNMPv2-TC
92
- ObjectType.AutonomousType = ObjectType["OBJECT IDENTIFIER"];
93
- ObjectType.DateAndTime = ObjectType["OCTET STRING"];
94
- ObjectType.DisplayString = ObjectType["OCTET STRING"];
95
- ObjectType.InstancePointer = ObjectType["OBJECT IDENTIFIER"];
96
- ObjectType.MacAddress = ObjectType["OCTET STRING"];
97
- ObjectType.PhysAddress = ObjectType["OCTET STRING"];
98
- ObjectType.RowPointer = ObjectType["OBJECT IDENTIFIER"];
99
- ObjectType.RowStatus = ObjectType.INTEGER;
100
- ObjectType.StorageType = ObjectType.INTEGER;
101
- ObjectType.TestAndIncr = ObjectType.INTEGER;
102
- ObjectType.TimeStamp = ObjectType.TimeTicks;
103
- ObjectType.TruthValue = ObjectType.INTEGER;
104
- ObjectType.TAddress = ObjectType["OCTET STRING"];
105
- ObjectType.TDomain = ObjectType["OBJECT IDENTIFIER"];
106
- ObjectType.VariablePointer = ObjectType["OBJECT IDENTIFIER"];
107
91
 
108
92
  var PduType = {
109
93
  160: "GetRequest",
@@ -3174,7 +3158,7 @@ ModuleStore.prototype.getSyntaxTypes = function () {
3174
3158
  if ( mibEntry.MACRO == "TEXTUAL-CONVENTION" ) {
3175
3159
  if ( mibEntry.SYNTAX && ! syntaxTypes[mibEntry.ObjectName] ) {
3176
3160
  if ( typeof mibEntry.SYNTAX == "object" ) {
3177
- syntaxTypes[mibEntry.ObjectName] = syntaxTypes.Integer;
3161
+ syntaxTypes[mibEntry.ObjectName] = mibEntry.SYNTAX;
3178
3162
  } else {
3179
3163
  syntaxTypes[mibEntry.ObjectName] = syntaxTypes[mibEntry.SYNTAX];
3180
3164
  }
@@ -3239,7 +3223,7 @@ ModuleStore.prototype.getProvidersForModule = function (moduleName) {
3239
3223
  var defVal = mibEntry["DEFVAL"];
3240
3224
 
3241
3225
  if ( syntax ) {
3242
- constraintsResults = ModuleStore.getConstraintsFromSyntax (syntax);
3226
+ constraintsResults = ModuleStore.getConstraintsFromSyntax (syntax, syntaxTypes);
3243
3227
  syntax = constraintsResults.syntax;
3244
3228
  constraints = constraintsResults.constraints;
3245
3229
 
@@ -3269,7 +3253,7 @@ ModuleStore.prototype.getProvidersForModule = function (moduleName) {
3269
3253
  maxAccess = (typeof mibEntry["MAX-ACCESS"] != "undefined" ? mibEntry["MAX-ACCESS"] : (access ? AccessToMaxAccess[access] : "not-accessible"));
3270
3254
  defVal = mibEntry["DEFVAL"];
3271
3255
 
3272
- constraintsResults = ModuleStore.getConstraintsFromSyntax (syntax);
3256
+ constraintsResults = ModuleStore.getConstraintsFromSyntax (syntax, syntaxTypes);
3273
3257
  syntax = constraintsResults.syntax;
3274
3258
  constraints = constraintsResults.constraints;
3275
3259
 
@@ -3349,11 +3333,14 @@ ModuleStore.prototype.getProvidersForModule = function (moduleName) {
3349
3333
  }
3350
3334
  } else if ( mibEntry.MACRO == "OBJECT-TYPE" ) {
3351
3335
  // OBJECT-TYPE entries not in a table are scalars
3336
+ let scalarType = syntaxTypes[syntax];
3337
+ if (typeof scalarType === 'object')
3338
+ scalarType = syntaxTypes[Object.keys(scalarType)[0]];
3352
3339
  var scalarDefinition = {
3353
3340
  name: mibEntry.ObjectName,
3354
3341
  type: MibProviderType.Scalar,
3355
3342
  oid: mibEntry.OID,
3356
- scalarType: syntaxTypes[syntax],
3343
+ scalarType: scalarType,
3357
3344
  maxAccess: MaxAccess[maxAccess]
3358
3345
  };
3359
3346
 
@@ -3379,9 +3366,11 @@ ModuleStore.prototype.loadBaseModules = function () {
3379
3366
  this.parser.Serialize ();
3380
3367
  };
3381
3368
 
3382
- ModuleStore.getConstraintsFromSyntax = function (syntax) {
3369
+ ModuleStore.getConstraintsFromSyntax = function (syntax, syntaxTypes) {
3383
3370
  let constraints;
3384
-
3371
+ if ( typeof syntaxTypes[syntax] === 'object' ) {
3372
+ syntax = syntaxTypes[syntax];
3373
+ }
3385
3374
  // detect INTEGER ranges, OCTET STRING sizes, and INTEGER enumerations
3386
3375
  if ( typeof syntax == "object" ) {
3387
3376
  let firstSyntaxKey = syntax[Object.keys(syntax)[0]];
package/lib/mib.js CHANGED
@@ -60,7 +60,7 @@ var MIB = function (dir) {
60
60
  var R = this.RowIndex;
61
61
  var C = this.ColumnIndex;
62
62
 
63
- if (!this.Table[FileName][R]) {
63
+ if (!this.Table[FileName][R] || C === 0) {
64
64
  this.Table[FileName][R] = Object.defineProperty([], "line", {
65
65
  enumerable: false,
66
66
  value: row + 1
@@ -143,11 +143,14 @@ var MIB = function (dir) {
143
143
  }
144
144
  },
145
145
  ParseLine: function (FileName, line, row) {
146
- line = line + "\n";
147
- for (var i = 0; i < line.length; i++) {
146
+ let len = line.length;
147
+ if (line[len - 1] === '\r')
148
+ --len;
149
+ for (var i = 0; i < len; i++) {
148
150
  var char = line.charAt(i);
149
151
  this.ParseChar(FileName, char, row, i);
150
152
  }
153
+ this.ParseChar(FileName, '\n', row, len);
151
154
  },
152
155
  ParseChar: function (FileName, char, row, column) {
153
156
  switch (char) {
@@ -310,7 +313,7 @@ var MIB = function (dir) {
310
313
  lastGoodDeclaration = row;
311
314
  break;
312
315
  default:
313
- if (symbol.indexOf('--') == 0) {//REMOVE COMMENTS
316
+ if (symbol.startsWith('--')) {//REMOVE COMMENTS
314
317
  //console.log(ModuleName, symbol);
315
318
  addSymbol = false;
316
319
  } else {
@@ -670,35 +673,34 @@ var MIB = function (dir) {
670
673
  },
671
674
  BuildObject: function (Object, ObjectName, macro, i, Symbols) {
672
675
 
673
- var r = i;
674
- var m = Symbols.indexOf('SYNTAX', r) - r;
675
- var SYNTAX = Symbols[Symbols.indexOf('SYNTAX', r) + 1];
676
- var val = Symbols[Symbols.indexOf('SYNTAX', r) + 2];
677
- var c1 = Symbols.indexOf('SYNTAX', r) + 1;
676
+ var syntaxKeyword = Symbols.indexOf('SYNTAX', i);
677
+ var m = syntaxKeyword - i;
678
+ var c1 = syntaxKeyword + 1;
679
+ var SYNTAX = Symbols[c1];
680
+ var val = Symbols[c1 + 1];
678
681
 
679
682
  if (this.MACROS.indexOf(macro) > -1 && m < 10) {
680
- switch (SYNTAX) {
681
- case "INTEGER":
682
- if (val.indexOf("{") == 0) {
683
- c1++;
684
- while (Symbols[c1].indexOf("}") == -1) {
685
- c1++;
686
- val += Symbols[c1].trim();
687
- }
688
- val = val.replace("{", "").replace("}", "").split(",");
689
-
690
- Object[ObjectName]['SYNTAX'] = {};
691
- Object[ObjectName]['SYNTAX'][SYNTAX] = {};
683
+ if (val[0] === "{") {
684
+ c1++;
685
+ while (Symbols[c1].indexOf("}") == -1) {
686
+ c1++;
687
+ val += Symbols[c1].trim();
688
+ }
689
+ val = val.replace("{", "").replace("}", "").split(",");
692
690
 
693
- for (var TC = 0; TC < val.length; TC++) {
694
- Object[ObjectName]['SYNTAX'][SYNTAX][val[TC].split("(")[1].replace(")", "")] = val[TC].split("(")[0];
695
- }
696
- }
697
- break;
698
- default:
699
- Object[ObjectName]['SYNTAX'] = SYNTAX;
700
- break;
691
+ Object[ObjectName]['SYNTAX'] = {};
692
+ Object[ObjectName]['SYNTAX'][SYNTAX] = {};
701
693
 
694
+ for (var TC = 0; TC < val.length; TC++) {
695
+ let openParenSplit = val[TC].split(/\s*\(\s*/);
696
+ Object[ObjectName]['SYNTAX'][SYNTAX][openParenSplit[1].replace(/\s*\)\s*$/, '')] = openParenSplit[0].trimStart();
697
+ }
698
+ } else if (val[0] === '(') {
699
+ const key = val.startsWith('(SIZE')? 'sizes' : 'ranges';
700
+ Object[ObjectName]['SYNTAX'] = {};
701
+ Object[ObjectName]['SYNTAX'][SYNTAX] = { [key]: this.GetRanges(val) };
702
+ } else {
703
+ Object[ObjectName]['SYNTAX'] = SYNTAX;
702
704
  }
703
705
  }
704
706
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "net-snmp",
3
- "version": "3.9.5",
3
+ "version": "3.9.6",
4
4
  "description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
5
5
  "main": "index.js",
6
6
  "directories": {