drachtio-srf 4.5.13 → 4.5.16

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.
@@ -536,7 +536,7 @@ class DrachtioAgent extends Emitter {
536
536
  debugSocket(`_initServer: removed socket: ${sockPort(socket)}, count now: ${this.mapServer.size}`);
537
537
  }
538
538
 
539
- _onMsg(socket, msg) {
539
+ _onMsg(socket, msg, {length, start, fullMsg}) {
540
540
  const obj = this.mapServer.get(socket) ;
541
541
  const pos = msg.indexOf(CR) ;
542
542
  const leader = -1 === pos ? msg : msg.slice(0, pos) ;
@@ -751,6 +751,8 @@ class DrachtioAgent extends Emitter {
751
751
  break ;
752
752
 
753
753
  default:
754
+ console.log(`invalid or garbage message: '${msg}'`) ;
755
+ console.log(`buffer start ${start}, length ${length}: '${fullMsg}'`);
754
756
  throw new Error('unexpected message with type: ' + token[1]) ;
755
757
  }
756
758
  }
@@ -86,7 +86,12 @@ class SipMessage {
86
86
 
87
87
  getParsedHeader(hdr) {
88
88
  const name = parser.getHeaderName(hdr) ;
89
- const v = this.headers[name] ;
89
+ const v = this.headers[name];
90
+
91
+ if (!v) {
92
+ throw new Error('header not available');
93
+ }
94
+
90
95
  const fn = parser.getParser(hdr.toLowerCase()) ;
91
96
  return fn({s:v, i:0}) ;
92
97
  }
package/lib/srf.js CHANGED
@@ -821,7 +821,7 @@ class Srf extends Emitter {
821
821
  if (!(opts.headers.to || opts.headers.To) && !opts.calledNumber) { opts.calledNumber = req.calledNumber; }
822
822
 
823
823
  opts.localSdp = opts.localSdpB && typeof opts.localSdpB !== 'function' ? opts.localSdpB : req.body ;
824
- const is3pcc = !opts.localSdp;
824
+ const is3pcc = !opts.localSdp || opts.noAck;
825
825
  if (is3pcc) opts.noAck = true;
826
826
 
827
827
  let remoteSdpB, translatedRemoteSdpB ;
@@ -267,7 +267,7 @@ module.exports = class WireProtocol extends Emitter {
267
267
 
268
268
  do {
269
269
  const msg = [...obj.incomingMsg].slice(start, start + length).join('');
270
- this.emit('msg', socket, msg);
270
+ this.emit('msg', socket, msg, {length, start, fullMsg: obj.incomingMsg});
271
271
  obj.incomingMsg = [...obj.incomingMsg].slice(start + length).join('');
272
272
 
273
273
  // check for another message
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drachtio-srf",
3
- "version": "4.5.13",
3
+ "version": "4.5.16",
4
4
  "description": "drachtio signaling resource framework",
5
5
  "main": "lib/srf.js",
6
6
  "scripts": {
@@ -40,6 +40,10 @@ describe('Parser', function () {
40
40
  msg.set('From', '<sip:daveh@localhost>;tag=1234');
41
41
  msg.get('from').should.eql('<sip:daveh@localhost>;tag=1234');
42
42
  });
43
+ it('should not parse a header when not available', function () {
44
+ var msg = new SipMessage();
45
+ should.throws(msg.getParsedHeader.bind(msg, 'contact'));
46
+ });
43
47
  it('should parse multiple headers into an array', function () {
44
48
  var msg = new SipMessage(examples('invite'));
45
49
  var via = msg.getParsedHeader('via');
@@ -146,5 +150,11 @@ describe('Parser', function () {
146
150
  msg.get('From').should.eql('"Dave" <sip:daveh@localhost>;tag=1234');
147
151
  msg.callingName.should.eql('Dave');
148
152
  });
153
+ it('should parse calling name', function () {
154
+ var msg = new SipMessage();
155
+ msg.set('From', '"Dave" <sip:daveh@localhost>;tag=1234');
156
+ msg.get('From').should.eql('"Dave" <sip:daveh@localhost>;tag=1234');
157
+ msg.callingName.should.eql('Dave');
158
+ });
149
159
  });
150
160