drachtio-srf 4.5.34 → 4.5.36

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.
@@ -245,7 +245,9 @@ function parseUri(s) {
245
245
  .map(function(s) { return s.split('='); })
246
246
  .reduce(function(params, x) { params[x[0]] = x[1] || null; return params; }, {}),
247
247
  headers: ((r[7] || '').split('&').filter((header) => header !== '').reduce((acc, header) => {
248
- const [key, value] = header.split('=');
248
+ const index = header.indexOf('=');
249
+ const key = header.slice(0, index);
250
+ const value = header.slice(index + 1);
249
251
  acc[key] = value;
250
252
  return acc;
251
253
  }, {}))
@@ -10,22 +10,19 @@ const DEFAULT_PING_INTERVAL = 15000;
10
10
  const MIN_PING_INTERVAL = 5000;
11
11
  const MAX_PING_INTERVAL = 300000;
12
12
 
13
- const containsEmoji = (str) => {
14
- const regex = /[\uD800-\uDBFF][\uDC00-\uDFFF]/;
15
- return regex.test(str);
16
- };
17
-
18
- const countSymbols = (text) => {
19
- return containsEmoji(text) ? [...text].length : text.length;
20
- };
21
13
 
22
14
  const parseMessageLengthSpecifier = (str) => {
15
+ let start = -1;
23
16
  for (let i = 0; i < 5; i++) {
17
+ if (start === -1 && (str[i] === ' ' || str[i] == '\n' || str[i] === '\r')) {
18
+ continue;
19
+ }
20
+ if (start === -1) start = i;
24
21
  const x = str[i];
25
22
  if (i > 0 && x === '#') {
26
23
  return {
27
24
  numChars: i,
28
- len: parseInt(str.slice(0, i))
25
+ len: parseInt(str.slice(start, i))
29
26
  };
30
27
  }
31
28
  if (x < '0' || x > '9') return;
@@ -33,7 +30,7 @@ const parseMessageLengthSpecifier = (str) => {
33
30
  return str[5] === '#' ?
34
31
  {
35
32
  numChars: 5,
36
- len: parseInt(str.slice(0, 5))
33
+ len: parseInt(str.slice(start, 5))
37
34
  } : undefined;
38
35
  };
39
36
 
@@ -298,7 +295,7 @@ module.exports = class WireProtocol extends Emitter {
298
295
  if (arr) {
299
296
  length = parseInt(arr[1]);
300
297
  start = arr[1].length + 1;
301
- haveMsg = countSymbols(obj.incomingMsg) >= length + start;
298
+ haveMsg = [...obj.incomingMsg].length >= length + start;
302
299
  }
303
300
  else haveMsg = false;
304
301
  } while (haveMsg);
@@ -322,7 +319,7 @@ module.exports = class WireProtocol extends Emitter {
322
319
  // check if we have a full message to process
323
320
  const {numChars, len} = parseMessageLengthSpecifier(obj.incomingMsg) || {};
324
321
  if (len) {
325
- if (countSymbols(obj.incomingMsg) >= len + numChars + 1) {
322
+ if ([...obj.incomingMsg].length >= len + numChars + 1) {
326
323
  this.processMessageBuffer(socket, obj, len, numChars + 1);
327
324
  }
328
325
  return;
@@ -332,7 +329,7 @@ module.exports = class WireProtocol extends Emitter {
332
329
  return;
333
330
  }
334
331
 
335
- const err = new Error(`invalid message from server, did not start with length specifier: ${obj.incomingMsg}`);
332
+ const err = new Error(`invalid message, missing length specifier: '${obj.incomingMsg}'`);
336
333
  if (this.isServer) {
337
334
  console.error(`invalid client message, closing socket: ${err}`);
338
335
  this.disconnect(socket);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drachtio-srf",
3
- "version": "4.5.34",
3
+ "version": "4.5.36",
4
4
  "description": "drachtio signaling resource framework",
5
5
  "main": "lib/srf.js",
6
6
  "types": "lib/@types/index.d.ts",
package/test/utils.js CHANGED
@@ -11,7 +11,7 @@ test('utils', (t) => {
11
11
  let uri = Srf.parseUri(uri1);
12
12
  t.ok(uri.params.transport === 'udp', 'exposes Srf.parseUri');
13
13
  t.ok(Srf.stringifyUri(uri) === uri1, 'exposes Srf.parseUri');
14
- const uri2 = 'sip:+12345612341t2@sip.jambonz.xyz;param1=value1?User-To-User=XX12344321&encoding=ascii';
14
+ const uri2 = 'sip:+12345612341t2@sip.jambonz.xyz;param1=value1?User-To-User=XX12344321;encoding=ascii&baba=lala';
15
15
  uri = Srf.parseUri(uri2);
16
16
  t.ok(uri.family === 'ipv4', ' Srf.parseUri can parse sip URI with param and headers');
17
17
  t.ok(uri.scheme === 'sip', ' Srf.parseUri can parse sip URI with param and headers');
@@ -20,8 +20,8 @@ test('utils', (t) => {
20
20
  t.ok(uri.host === 'sip.jambonz.xyz', ' Srf.parseUri can parse sip URI with param and headers');
21
21
  // t.ok(uri.port === undefined, ' Srf.parseUri can parse sip URI with param and headers');
22
22
  t.ok(uri.params.param1 === 'value1', ' Srf.parseUri can parse sip URI with param and headers');
23
- t.ok(uri.headers['User-To-User'] === 'XX12344321', ' Srf.parseUri can parse sip URI with param and headers');
24
- t.ok(uri.headers.encoding === 'ascii', ' Srf.parseUri can parse sip URI with param and headers');
23
+ t.ok(uri.headers['User-To-User'] === 'XX12344321;encoding=ascii', ' Srf.parseUri can parse sip URI with param and headers');
24
+ t.ok(uri.headers.baba === 'lala', ' Srf.parseUri can parse sip URI with param and headers');
25
25
  t.ok(Srf.stringifyUri(uri) === uri2, ' Srf.parseUri can parse sip URI with param and headers');
26
26
  let telUri = Srf.parseUri('<tel:+1-201-555-0123;phone-context=drachtio.org;ext=1>');
27
27
  t.ok(telUri.scheme === 'tel', 'Srf.parseUri can parse tel uri');