Daniel-Constantin Mierla

Edited by

Daniel-Constantin Mierla

Table of Contents

1. Admin Guide
1. Overview
2. Dependencies
2.1. Kamailio Modules
2.2. External Libraries or Applications
3. Functions
3.1. sj_serialize(opt, ovar)
4. Output Samples

List of Examples

1.1. sj_serialize usage
1.2. sj_serialize output

Chapter 1. Admin Guide

1. Overview

This module serializes SIP message attributes into a JSON document.

It can facilitate getting the SIP attributes in a structure inside one of the embedded interpreters (e.g., KEMI interpreters, Lua can parse JSON in an internal hash table).

2. Dependencies

2.1. Kamailio Modules

The following modules must be loaded before this module:

  • none.

2.2. External Libraries or Applications

The following libraries or applications must be installed before running Kamailio with this module loaded:

  • none

3. Functions

3.1.  sj_serialize(opt, ovar)

Do the serialization of SIP messagge attributes into a JSON document.

When there is a match, it uses the corresponding pseudo-variable name for JSON attribute (e.g., 'ru' is the R-URI attribute name).

Meaning of the parameters:

  • opt - list of optional groups of attributes to be serialized. Each group of attributes has a corresponding character. These are:

    • 0 - (zero) default attributes to be serialized. They are added even if '0' is not provided as parameter, however, because 'opt' parameter cannot be empty, '0' can be given when only default attributes are wanted.

    • B - (uppercase B) SIP message body

    • c - (lowercase c) CSeq attributes

    • t - (lowercase t) To header attributes

  • ovar - name of the output pseduo-variable

This function can be used from ANY_ROUTE.

Example 1.1. sj_serialize usage

sj_serialize("0B", "$var(json)");

4. Output Samples

The content of the output variable is a JSON. Next are some samples. Note that the content might change with future development and this example become outdated, simply print the document when you start testing your config and match the name of the attribute with the name of pseudo-variables to understand what values can be there. Unlike pseudo-variables, the $null values might converted to empty strings.

Example 1.2. sj_serialize output

# the content of $var(json) after sj_serialize("0B", "$var(json)")
#  - the content is compacted, next it has been pretty-formatted for better viewing
  "ua":"sipsak 0.9.7pre",
# the sip message sent to Kamailio:
OPTIONS sip:alice@ SIP/2.0
Via: SIP/2.0/UDP;branch=z9hG4bK.79e78613;rport;alias
From: sip:sipsak@;tag=74806173
To: sip:alice@
Call-ID: 482215126@
Contact: sip:sipsak@
Content-Length: 0
Max-Forwards: 70
User-Agent: sipsak 0.9.7pre
Accept: text/plain