1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
JSONRPC-S Module
Daniel-Constantin Mierla
<miconda@gmail.com>
Edited by
Daniel-Constantin Mierla
<miconda@gmail.com>
Copyright 2014 asipto.com
__________________________________________________________________
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
Table of Contents
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)
1. Overview
1.1. Limitations
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
2.2. External Libraries or Applications
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)
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()
4.2. jsonrpc_exec(cmd)
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}');
...
|