JSONRPC-S Module

Daniel-Constantin Mierla

Edited by

Daniel-Constantin Mierla


Table of Contents

1. Admin Guide
1. Overview
1.1. Limitations
2. Dependencies
2.1. Kamailio Modules
2.2. External Libraries or Applications
3. Parameters
3.1. pretty_format (int)
4. Functions
4.1. jsonrpc_dispatch()
4.2. jsonrpc_exec(cmd)

List of Examples

1.1. Set pretty_format parameter
1.2. jsonrpc_dispatch usage
1.3. jsonrpc_exec usage

Chapter 1. Admin Guide

1. Overview

This module provides a JSON-RPC server over HTTP implementation, tailored for the needs of Kamailio. It implements the Kamailio RPC interface over JSON-RPC.

The JSONRPC-S module uses the xHTTP module to handle HTTP requests. Read the documentation of the xHTTP module for more details.

1.1. Limitations

  • This module does not implement asynchronous RPC commands. It is unlikely that asynchronous RPC commands will be executed from an JSON-RPC over HTTP client.

  • This module does not accept parameters embedded in a structure (see the RPC documentation for more info about how parameters can be passed to RPC).

2. Dependencies

2.1. Kamailio Modules

The following modules must be loaded before this module:

  • xhttp - xHTTP.

2.2. External Libraries or Applications

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

  • None

3. Parameters

3.1. pretty_format (int)

Pretty format for JSON-RPC response document.

Default value is '0'.

Example 1.1. Set pretty_format parameter

...
modparam("jsonrpc-s", "pretty_format", 1)
...

4. Functions

4.1.  jsonrpc_dispatch()

Handle the JSONRPC request and generate a response.

Example 1.2. jsonrpc_dispatch usage

...
#!KAMAILIO

memdbg=5
memlog=5

debug=3
log_stderror=yes

fork=yes
children=2

tcp_accept_no_cl=yes

mpath="modules/"

loadmodule "sl.so"
loadmodule "pv.so"
loadmodule "xhttp.so"
loadmodule "jsonrpc-s.so"

request_route {
	send_reply("404", "not found");
	exit;
}

event_route[xhttp:request] {
    if(src_ip!=127.0.0.1) {
        xhttp_reply("403", "Forbidden", "text/html",
            "<html><body>Not allowed from $si</body></html>");
        exit;
	}
	if ($hu =~ "^/RPC") {
		jsonrpc_dispatch();
	} else {
        xhttp_reply("200", "OK", "text/html",
            "<html><body>Wrong URL $hu</body></html>");
    }
    return;
}
...

4.2.  jsonrpc_exec(cmd)

Execute a JSON-RPC command given as a parameter.

The parameter has to be a valid full JSON-RPC document. It can be a dynamic string with variables. The result of the command can be accessed via $jsonrpl(key) pseudo variables.

Example 1.3. jsonrpc_exec usage

...
jsonrpc_exec({"jsonrpc": "2.0", "method": "dispatcher.reload", "id": 1}');
...