net-snmp 3.9.1 → 3.9.3

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.
package/README.md CHANGED
@@ -655,7 +655,7 @@ for v1 and v2c.
655
655
 
656
656
  ## session.on ("close", callback)
657
657
 
658
- The `close` event is emitted by the session when the sessions underlying UDP
658
+ The `close` event is emitted by the session when the session's underlying UDP
659
659
  socket is closed.
660
660
 
661
661
  No arguments are passed to the callback.
@@ -665,7 +665,7 @@ in the failure of each outstanding request. The error passed back through to
665
665
  each request will be an instance of the `Error` class with the errors
666
666
  `message` attribute set to `Socket forcibly closed`.
667
667
 
668
- The following example prints a message to the console when a sessions
668
+ The following example prints a message to the console when a session's
669
669
  underlying UDP socket is closed:
670
670
 
671
671
  ```js
@@ -676,7 +676,7 @@ session.on ("close", function () {
676
676
 
677
677
  ## session.on ("error", callback)
678
678
 
679
- The `error` event is emitted by the session when the sessions underlying UDP
679
+ The `error` event is emitted by the session when the session's underlying UDP
680
680
  socket emits an error.
681
681
 
682
682
  The following arguments will be passed to the `callback` function:
@@ -685,7 +685,7 @@ The following arguments will be passed to the `callback` function:
685
685
  will contain a detailed error message.
686
686
 
687
687
  The following example prints a message to the console when an error occurs
688
- with a sessions underlying UDP socket, the session is then closed:
688
+ with a session's underlying UDP socket, the session is then closed:
689
689
 
690
690
  ```js
691
691
  session.on ("error", function (error) {
@@ -2704,6 +2704,40 @@ Sends a "ping" to the master agent using a `Ping` PDU, to confirm that the maste
2704
2704
  responsive. The supplied `callback` is called on reception of the subsequent
2705
2705
  `Response` PDU from the master to the `Ping` PDU.
2706
2706
 
2707
+ ## subagent.on ("close", callback)
2708
+
2709
+ The `close` event is emitted by the subagent when its underlying TCP socket is closed.
2710
+
2711
+ No arguments are passed to the callback.
2712
+
2713
+ The following example prints a message to the console when a subagent's
2714
+ underlying TCP socket is closed:
2715
+
2716
+ ```js
2717
+ subagent.on ("close", function () {
2718
+ console.log ("Subagent socket closed");
2719
+ });
2720
+ ```
2721
+
2722
+ ## subagent.on ("error", callback)
2723
+
2724
+ The `error` event is emitted by the subagent when its underlying TCP socket emits an error.
2725
+
2726
+ The following argument will be passed to the `callback` function:
2727
+
2728
+ * `error` - An instance of the `Error` class, the exposed `message` attribute
2729
+ will contain a detailed error message.
2730
+
2731
+ The following example prints a message to the console when an error occurs
2732
+ with a subagent's underlying TCP socket, and the subagent is then closed:
2733
+
2734
+ ```js
2735
+ subagent.on ("error", function (error) {
2736
+ console.log (error.toString ());
2737
+ subagent.close ();
2738
+ });
2739
+ ```
2740
+
2707
2741
 
2708
2742
  # Example Programs
2709
2743
 
@@ -3247,6 +3281,14 @@ Example programs are included under the module's `example` directory.
3247
3281
 
3248
3282
  * Fix MIB parsing of unclosed brackets in comments
3249
3283
 
3284
+ ## Version 3.9.2 - 26/04/2023
3285
+
3286
+ * Fix MIB parsing of non-comments in descriptions and unmatched quotations
3287
+
3288
+ ## Version 3.9.3 - 28/04/2023
3289
+
3290
+ * Add AgentX subagent "error" and "close" events
3291
+
3250
3292
  # License
3251
3293
 
3252
3294
  Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
@@ -66,6 +66,9 @@ agent.open(function (error, data) {
66
66
  agent.registerProvider (tableProvider, null);
67
67
  agent.getMib ().addTableRow ("smallIfTable", [1, "lo", 24]);
68
68
  agent.getMib ().addTableRow ("smallIfTable", [2, "eth0", 6]);
69
+ agent.on("close", function() {
70
+ console.log ("Subagent socket closed");
71
+ });
69
72
  }
70
73
  });
71
74
 
package/index.js CHANGED
@@ -5708,6 +5708,16 @@ var Subagent = function (options) {
5708
5708
  this.setTransactions = {};
5709
5709
  };
5710
5710
 
5711
+ util.inherits (Subagent, events.EventEmitter);
5712
+
5713
+ Subagent.prototype.onClose = function () {
5714
+ this.emit ("close");
5715
+ };
5716
+
5717
+ Subagent.prototype.onError = function (error) {
5718
+ this.emit ("error", error);
5719
+ };
5720
+
5711
5721
  Subagent.prototype.getMib = function () {
5712
5722
  return this.mib;
5713
5723
  };
@@ -5720,9 +5730,8 @@ Subagent.prototype.connectSocket = function () {
5720
5730
  });
5721
5731
 
5722
5732
  this.socket.on ("data", me.onMsg.bind (me));
5723
- this.socket.on ("error", function (error) {
5724
- console.error (error);
5725
- });
5733
+ this.socket.on ("error", me.onError.bind (me));
5734
+ this.socket.on ("close", me.onClose.bind (me));
5726
5735
  };
5727
5736
 
5728
5737
  Subagent.prototype.open = function (callback) {
package/lib/mib.js CHANGED
@@ -1,18 +1,9 @@
1
1
  var fs = require('fs');
2
2
 
3
3
  var MIB = function (dir) {
4
- return ({
5
- directory: dir ? dir : '',
6
- SymbolBuffer: {},
7
- StringBuffer: '',
8
- Modules: {},
9
- Objects: {},
10
- MACROS: [],
11
- CurrentObject: null,
12
- TempObject: {},
13
- CurrentClause: '',
14
- WaitFor: '',
15
- CharBuffer: {
4
+
5
+ var initializeBuffer = function (buffer) {
6
+ return Object.assign(buffer, {
16
7
  logit: false,
17
8
  lastChar: '',
18
9
  state: '',
@@ -27,11 +18,26 @@ var MIB = function (dir) {
27
18
  inComment: false,
28
19
  inGroup: 0,
29
20
  builder: '',
30
- Table: {},
31
21
  ColumnIndex: 0,
32
22
  RowIndex: 0,
23
+ PreviousRow: 0
24
+ });
25
+ };
26
+
27
+ var newMIB = ({
28
+ directory: dir ? dir : '',
29
+ SymbolBuffer: {},
30
+ StringBuffer: '',
31
+ Modules: {},
32
+ Objects: {},
33
+ MACROS: [],
34
+ CurrentObject: null,
35
+ TempObject: {},
36
+ CurrentClause: '',
37
+ WaitFor: '',
38
+ CharBuffer: {
39
+ Table: {},
33
40
  ModuleName: {},
34
- PreviousRow: 0,
35
41
  Append: function (char) {
36
42
  this.builder += char;
37
43
  },
@@ -45,12 +51,7 @@ var MIB = function (dir) {
45
51
  this.builder.length = 0;
46
52
  if (!this.Table[FileName]) {
47
53
  this.Table[FileName] = [];
48
- }
49
- if (row == 0) {
50
- this.RowIndex = 0;
51
- this.PreviousRow = 0;
52
- }
53
- if (this.PreviousRow < row) {
54
+ } else if (this.PreviousRow < row) {
54
55
  this.RowIndex++;
55
56
  this.ColumnIndex = 0;
56
57
  this.PreviousRow = row;
@@ -60,7 +61,10 @@ var MIB = function (dir) {
60
61
  var C = this.ColumnIndex;
61
62
 
62
63
  if (!this.Table[FileName][R]) {
63
- this.Table[FileName][R] = [];
64
+ this.Table[FileName][R] = Object.defineProperty([], "line", {
65
+ enumerable: false,
66
+ value: row + 1
67
+ });
64
68
  }
65
69
  this.isEqual = false;
66
70
  switch (symbol) {
@@ -128,8 +132,7 @@ var MIB = function (dir) {
128
132
  this.ParseModule(FileName.split('/')[FileName.split('/').length - 1].split('.')[0], fs.readFileSync(FileName).toString());
129
133
  },
130
134
  ParseModule: function (FileName, Contents) {
131
- this.CharBuffer.RowIndex = 0;
132
- this.CharBuffer.ColumnIndex = 0;
135
+ initializeBuffer(this.CharBuffer);
133
136
 
134
137
  var lines = Contents.split('\n');
135
138
  var line = '';
@@ -234,7 +237,7 @@ var MIB = function (dir) {
234
237
  break;
235
238
  case "-":
236
239
  this.CharBuffer.Append(char);
237
- if (this.CharBuffer.lastChar == '-') {
240
+ if (!this.CharBuffer.isString && this.CharBuffer.lastChar == '-') {
238
241
  this.CharBuffer.isComment = true;
239
242
  this.CharBuffer.builder = this.CharBuffer.builder.split('--')[0];
240
243
  this.CharBuffer.Fill(FileName, row, column);
@@ -244,7 +247,7 @@ var MIB = function (dir) {
244
247
  break;
245
248
  case '"':
246
249
  if (this.CharBuffer.isComment && !this.CharBuffer.isString && !this.CharBuffer.inComment) {
247
- //011 = COMMENT
250
+ //011 = COMMENT
248
251
  //IF 011 SET 101
249
252
  this.CharBuffer.isComment = true;
250
253
  this.CharBuffer.isString = false;
@@ -289,18 +292,42 @@ var MIB = function (dir) {
289
292
  for (var FileName in Table) {
290
293
  ModuleName = this.CharBuffer.ModuleName[FileName];
291
294
  this.SymbolBuffer[ModuleName] = [];
292
- for (var r = 0; r < Table[FileName].length; r++) {
293
- for (var c = 0; c < Table[FileName][r].length; c++) {
294
- var symbol = Table[FileName][r][c];
295
+ var foundTheEnd = false;
296
+ var lastGoodDeclaration = [ 'none' ];
297
+ var file = Table[FileName];
298
+ for (var r = 0; r < file.length; r++) {
299
+ var row = file[r];
300
+ for (var c = 0; c < row.length; c++) {
301
+ var symbol = row[c];
302
+ var addSymbol = true;
295
303
  switch (symbol) {
304
+ case 'END':
305
+ foundTheEnd = true;
306
+ break;
307
+ case '::=':
308
+ foundTheEnd = false;
309
+ lastGoodDeclaration = row;
310
+ break;
296
311
  default:
297
- if (symbol.indexOf('--') != 0) {//REMOVE COMMENTS
312
+ if (symbol.indexOf('--') == 0) {//REMOVE COMMENTS
298
313
  //console.log(ModuleName, symbol);
299
- this.SymbolBuffer[ModuleName].push(symbol);
314
+ addSymbol = false;
315
+ } else {
316
+ foundTheEnd = false;
300
317
  }
301
318
  }
319
+ if (addSymbol) {
320
+ this.SymbolBuffer[ModuleName].push(symbol);
321
+ }
302
322
  }
303
323
  }
324
+ if (!foundTheEnd) {
325
+ // Warn that the contents are malformed
326
+ console.warn(
327
+ '[%s]: Incorrect formatting: no END statement found - last good declaration "%s" (line %s)',
328
+ ModuleName, lastGoodDeclaration.join(' '), lastGoodDeclaration.line
329
+ );
330
+ }
304
331
 
305
332
  }
306
333
  this.Compile();
@@ -359,7 +386,7 @@ var MIB = function (dir) {
359
386
  //BUILD OBJECT FROM MACRO TYPE NOTATION
360
387
  var MARCO = this[Symbols[r]];
361
388
  if (!MARCO) {
362
- //HACK IF MARCO IS NOT FOUND
389
+ //HACK IF MARCO IS NOT FOUND
363
390
  //MARCO = {};
364
391
  //return;
365
392
  }
@@ -401,7 +428,7 @@ var MIB = function (dir) {
401
428
  val = val.replace("{", "").replace("}", "").split(",");
402
429
  }
403
430
  }
404
-
431
+
405
432
  switch (key) {
406
433
  case 'SYNTAX':
407
434
  switch (val) {
@@ -727,6 +754,11 @@ var MIB = function (dir) {
727
754
  }
728
755
  }
729
756
  });
757
+
758
+ // Complete buffer setup before returning to caller.
759
+ initializeBuffer(newMIB.CharBuffer);
760
+
761
+ return newMIB;
730
762
  };
731
763
 
732
764
  module.exports = exports = MIB;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "net-snmp",
3
- "version": "3.9.1",
3
+ "version": "3.9.3",
4
4
  "description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
5
5
  "main": "index.js",
6
6
  "directories": {