npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sip-parsing

v1.5.9

Published

Parses SIP messages and allows access using using opensips/kamailio/openser pseudo-variables syntax.

Downloads

105

Readme

sip-parsing

Parses SIP messages and allows access using using opensips/kamailio/openser pseudo-variables syntax.

Sample usage:

const sip_parsing = require('sip-parsing')
const assert = require('assert')

var s = `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`

s = s.replace(/\n/g, "\r\n")

var msg = sip_parsing.parse(s)

assert(msg.$rU == "bob")
assert(msg.$ru == "sip:[email protected]")
assert(msg['$hdr(From)'] == 'Alice <sip:[email protected]>;tag=1928301774')
assert(msg['$(hdrcnt(Via))'] == 2)
assert(msg['$hdr(v)'] == 'SIP/2.0/UDP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c2312983.1')
assert(msg['$(hdr(v)[0])'] == 'SIP/2.0/UDP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c2312983.1')
assert(msg['$(hdr(v)[1])'] == 'SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8;received=192.0.2.1')
assert(msg.$ua == 'SomeUA')
assert(msg.$ci == 'a84b4c76e66710')
assert(msg.$cT == 'application/sdp')
assert(msg.$cl == '142')
assert(msg.$rb == 'v=0\r\no=root 123 456 IN IP4 1.2.3.4\r\na=rtpmap:0 pcmu/8000\r\na=sendrecv')

Here is the full list of supported pseudo-variables:

    $rm : request method ('INVITE', 'ACK', 'BYE' etc)

    $fn  : header From DisplayName
    $fu  : header From URI
    $fU  : header From UserName
    $fd  : header From Domain
    $ft: : header From parameter tag
    $fUl : header From UserName length

    $tn : header To DisplayName
    $tu : header To URI
    $tU : header To UserName
    $td : header To Domain
    $tt : headet To parameter tag

    $pn : header P-Preferred-Identity DisplayName
    $pu : header P-Preferred-Identity URI
    $pU : header P-Preferred-Identity UserName
    $pd : header P-Preferred-Identity Domain

    $adu: header Authorization or Proxy-Authorization uri
    $aa : header Authorization or Proxy-Authorization algorithm
    $ar : header Authorization or Proxy-Authorization realm
    $au : header Authorization or Proxy-Authorization user part of username
    $ad : header Authorization or Proxy-Authorization domain part of username
    $aU : header Authorization or Proxy-Authorization username
    $an : header Authorization or Proxy-Authorization nonce

    $ai : header P-Asserted-Identity URI

    $di  : header Diversion URI
    $dip : header Diversion parameter privacy
    $dir : header Diversion parametter reason

    $re : header Remote-Party-ID URI

    $rt : header Refer-To URI

    $cs : header CSeq seq
    
    $rb : msg body
    $ua : header User-Agent

    $ci : header Call-ID

    $cl : header Content-Length

    $cT : header Content-Type

    $ml : msg length

    $mt : msg type 1 (request) or 2 (reply)

    $route_uri: first Route header URI

    '$msg.is_request' : 1 (true) or 0 (false)
    '$msg.type' : 'request' or 'reply'

    '$auth.nonce'  : header Authorization or Proxy-Authorization nonce
    '$auth.resp'   : header Authorization or Proxy-Authorization response
    '$auth.opaque' : header Authorization or Proxy-Authorization opaque
    '$auth.alg'    : header Authorization or Proxy-Authorization algorithm
    '$auth.qop'    : header Authorization or Proxy-Authorization qop

Obs: some pseudo-variables are redundant but this is because we combined the pseudo-variables provided by openser/opensips/kamailio.

Also we support these special pseudo-variables defined by kamailio/opensips:

  '$(hdrcnt(HEADER_NAME))' : number of header with that name in the msg
  '$hdr(HEADER_NAME)' : gets the first header with HEADER_NAME in the msg
  '$(hdr(HEADER_NAME)[n])' : gets the nth header with name HEADER_NAME in the msg 

The case (upper/lower) of header names are irrelevant and you can specify them by their compact format

As an altenative to simplify specifying headers you can use:

  hdr_HEADER_NAME
or
  hdr_COMPACTNAME

Ex:

  assert(msg.hdr_max_forwards == '70')
  assert(msg.hdr_c == 'application/sdp')

Obs: you must replace dashes in the header names with underscores.

A few pseudo-variables are currently not supported (as I need more details to implement them):

$(rb[*]) - same as $rb

$(rb[n]) - the n-th body belonging to a multi-part body from the beginning of message, starting with index 0

$(rb[-n]) - the n-th body belonging to a multi-part body from the end of the message, starting with index -1 (the last contact instance)

$rb(application/sdp) - get the first SDP body part

$(rb(application/isup)[-1]) - get the last ISUP body part

$ru_q - reference to q value of the R-URI

Ref:

https://www.kamailio.org/wiki/cookbooks/5.4.x/pseudovariables

https://www.opensips.org/Documentation/Script-CoreVar-3-4