Debian Codegraph @

src/modules/app_ruby/README

raw
1 app_ruby Module
2
3 Daniel-Constantin Mierla
4
5 asipto.com
6
7 Edited by
8
9 Daniel-Constantin Mierla
10
11 <[email protected]>
12
13 Copyright © 2018 Daniel-Constantin Mierla (asipto.com)
14 __________________________________________________________________
15
16 Table of Contents
17
18 1. Admin Guide
19
20 1. Overview
21 2. Dependencies
22
23 2.1. Kamailio Modules
24 2.2. External Libraries or Applications
25
26 3. Parameters
27
28 3.1. load (str)
29 3.2. xval_mode (int)
30 3.3. modproc (str)
31
32 4. Functions
33
34 4.1. ruby_run(function, params)
35
36 5. RPC Commands
37
38 5.1. app_ruby.reload
39 5.2. app_ruby.api_list
40
41 6. Example of usage
42
43 List of Examples
44
45 1.1. Set load parameter
46 1.2. Set xval_mode parameter
47 1.3. Set modproc parameter
48 1.4. jsdt_run usage
49
50 Chapter 1. Admin Guide
51
52 Table of Contents
53
54 1. Overview
55 2. Dependencies
56
57 2.1. Kamailio Modules
58 2.2. External Libraries or Applications
59
60 3. Parameters
61
62 3.1. load (str)
63 3.2. xval_mode (int)
64 3.3. modproc (str)
65
66 4. Functions
67
68 4.1. ruby_run(function, params)
69
70 5. RPC Commands
71
72 5.1. app_ruby.reload
73 5.2. app_ruby.api_list
74
75 6. Example of usage
76
77 1. Overview
78
79 This module allows executing Ruby scripts from the Kamailio
80 configuration file. It exports all KEMI functions to Ruby in order to
81 access the currently processed SIP message. These functions are
82 available within the Ruby module 'KSR'.
83
84 IMPORTANT: because of Ruby language policy (which require that a public
85 submodule name has to start with an uppercase letter), the KSR
86 submodule names are with all letters uppercase. For example, what is
87 documented as KSR.sl in KEMI docs, must be used as KSR::SL in Ruby
88 scripts.
89
90 2. Dependencies
91
92 2.1. Kamailio Modules
93 2.2. External Libraries or Applications
94
95 2.1. Kamailio Modules
96
97 The following modules must be installed (but not loaded) before this
98 module:
99 * app_ruby_proc.
100
101 2.2. External Libraries or Applications
102
103 The following libraries or applications must be installed before
104 running Kamailio with this module loaded:
105 * libruby - the ruby library (for compilation on Debian, ruby-dev
106 package is needed.
107
108 3. Parameters
109
110 3.1. load (str)
111 3.2. xval_mode (int)
112 3.3. modproc (str)
113
114 3.1. load (str)
115
116 Set the path to the Ruby file to be loaded at startup. Then you can use
117 Ruby_run(function, params) to execute a function from the script at
118 runtime. If you use it for KEMI configuration, then it has to include
119 the required functions.
120
121 Default value is “null”.
122
123 Example 1.1. Set load parameter
124 ...
125 modparam("app_ruby", "load", "/usr/local/etc/kamailio/ruby/myscript.rb")
126 ...
127
128 3.2. xval_mode (int)
129
130 Control if the external sub-module functions returning extended-values
131 should propagate their string return value (when set to 0) or be
132 replaced by NULL/nil (when set to 1).
133
134 When set to 0, the KSR::PV Ruby submodule is implemented with the
135 internal functions from the app_ruby module, otherwise the ones from
136 core are used.
137
138 Note: upt to version 5.7, when set to 1, there were crashing reports
139 that are under investigation, this option being provided as
140 intermediary solution to preserve the behaviour from older versions.
141
142 Default value is “1”.
143
144 Example 1.2. Set xval_mode parameter
145 ...
146 modparam("app_ruby", "xval_mode", 0)
147 ...
148
149 3.3. modproc (str)
150
151 The name of or the path to the required per-process API module.
152
153 Default value is "app_ruby_proc.so".
154
155 Example 1.3. Set modproc parameter
156 ...
157 modparam("app_ruby", "modproc", "app_ruby_proc2.so")
158 ...
159
160 4. Functions
161
162 4.1. ruby_run(function, params)
163
164 4.1. ruby_run(function, params)
165
166 Execute the Ruby function 'func' giving params as parameters. There can
167 be up to 3 string parameters. The function must exist in the script
168 loaded at startup via parameter 'load'. Parameters can be strings with
169 pseudo-variables that are evaluated at runtime.
170
171 Example 1.4. jsdt_run usage
172 ...
173 if(!ruby_run("rb_append_fu_to_reply"))
174 {
175 xdbg("SCRIPT: failed to execute ruby function!\n");
176 }
177 ...
178 ruby_run("rb_funcx", "$rU", "2");
179 ...
180
181 5. RPC Commands
182
183 5.1. app_ruby.reload
184 5.2. app_ruby.api_list
185
186 5.1. app_ruby.reload
187
188 Marks the need to reload the js script. The actual reload is done by
189 every working process when the next call to ruby_run() function or KEMI
190 config is executed.
191
192 Name: app_ruby.reload
193
194 Parameters: none
195
196 Example:
197 ...
198 kamctl rpc app_ruby.reload
199 ...
200
201 5.2. app_ruby.api_list
202
203 List the functions available via Kemi framework.
204
205 Name: app_ruby.api_list
206
207 Parameters: none
208
209 Example:
210 ...
211 kamctl rpc app_ruby.api_list
212 ...
213
214 6. Example of usage
215
216 Create your Ruby script and store it on the file system, say:
217 '/usr/local/etc/kamailio/ruby/myscript.rb'.
218 ...
219 def ksr_sl_reply()
220 KSR.dbg("==== from ruby - src ip: " + KSR::PV.get("$si") + "\n")
221 KSR::SL.sl_send_reply(200, "OK-Ruby")
222 end
223 ...
224
225 Load the script via parameter 'load' and execute function via
226 ruby_run(...).
227 ...
228 modparam("app_ruby", "load", "/usr/local/etc/kamailio/ruby/myscript.rb")
229 ...
230 request_route {
231 ...
232 if(!ruby_run("ksr_sl_reply")) {
233 xdbg("SCRIPT: failed to execute ruby function!\n");
234 }
235 ...
236 }
237 ...