sip-matching
v1.5.2
Published
Permits to match and collect data from SIP messages using opensips/kamailio/openser pseudo-variables syntax.
Downloads
20
Maintainers
Readme
sip-matching
Permits to match and collect data from SIP messages using opensips/kamailio/openser pseudo-variables syntax.
Example:
const sip_matching = require('sip-matching')
const dm = require('data-matching')
const assert = require('assert')
var msg = `INVITE sip:[email protected] SIP/2.0
Via: SIP/2.0/UDP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c2312983.1
Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8;received=192.0.2.1
Max-Forwards: 70
To: Bob <sip:[email protected]>
From: Alice <sip:[email protected]>;tag=1928301774
Call-ID: a84b4c76e66710
CSeq: 314159 INVITE
USER-AGENT: SomeUA
Contact: <sip:[email protected]>
Content-Type: application/sdp
cONTENT-lENGTH: 142
v=0
o=root 123 456 IN IP4 1.2.3.4
a=rtpmap:0 pcmu/8000
a=sendrecv`
msg = msg.replace(/\n/g, "\r\n")
var matcher = sip_matching({
$fU: 'alice',
$ua: 'SomeUA',
'$hdr(Accept)': dm.absent,
'$hdr(max-forwards)': '70',
'$(hdrcnt(v))': 2,
$fu: 'sip:!{user1}@!{domain1}',
$tu: 'sip:!{user2}@!{domain2}',
'$hdr(call-id)': dm.collect('call_id'),
})
var store = {}
assert(matcher(msg, store, false, '') == true)
assert(store.user1 == 'alice')
assert(store.domain1 == 'atlanta.com')
assert(store.user2 == 'bob')
assert(store.domain2 == 'biloxi.com')
assert(store.call_id == 'a84b4c76e66710')
console.log("success")