Debian Codegraph @

src/modules/evapi/README

raw
1 EVAPI Module
2
3 Daniel-Constantin Mierla
4
5 <[email protected]>
6
7 Edited by
8
9 Daniel-Constantin Mierla
10
11 <[email protected]>
12
13 Copyright © 2014 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. workers (int)
29 3.2. bind_addr (str)
30 3.3. netstring_format (int)
31 3.4. event_callback (str)
32 3.5. max_clients (int)
33 3.6. wait_idle (int)
34 3.7. wait_increase (int)
35
36 4. Functions
37
38 4.1. evapi_relay(evdata)
39 4.2. evapi_async_relay(evdata)
40 4.3. evapi_multicast(evdata, etag)
41 4.4. evapi_async_multicast(evdata, etag)
42 4.5. evapi_unicast(evdata, etag)
43 4.6. evapi_async_unicast(evdata, etag)
44 4.7. evapi_close()
45 4.8. evapi_set_tag(tname)
46
47 5. Event routes
48
49 5.1. evapi:connection-new
50 5.2. evapi:connection-closed
51 5.3. evapi:message-received
52
53 6. Exported pseudo-variables
54
55 List of Examples
56
57 1.1. Set workers parameter
58 1.2. Set bind_addr parameter
59 1.3. Set netstring_format parameter
60 1.4. Set event_callback parameter
61 1.5. Set max_clients parameter
62 1.6. Set wait_idle parameter
63 1.7. Set wait_increase parameter
64 1.8. evapi_relay usage
65 1.9. TCP message
66 1.10. evapi_async_relay usage
67 1.11. evapi_multicast usage
68 1.12. evapi_async_multicast usage
69 1.13. evapi_unicast usage
70 1.14. evapi_async_unicast usage
71 1.15. evapi_close usage
72 1.16. evapi_set_tag usage
73
74 Chapter 1. Admin Guide
75
76 Table of Contents
77
78 1. Overview
79 2. Dependencies
80
81 2.1. Kamailio Modules
82 2.2. External Libraries or Applications
83
84 3. Parameters
85
86 3.1. workers (int)
87 3.2. bind_addr (str)
88 3.3. netstring_format (int)
89 3.4. event_callback (str)
90 3.5. max_clients (int)
91 3.6. wait_idle (int)
92 3.7. wait_increase (int)
93
94 4. Functions
95
96 4.1. evapi_relay(evdata)
97 4.2. evapi_async_relay(evdata)
98 4.3. evapi_multicast(evdata, etag)
99 4.4. evapi_async_multicast(evdata, etag)
100 4.5. evapi_unicast(evdata, etag)
101 4.6. evapi_async_unicast(evdata, etag)
102 4.7. evapi_close()
103 4.8. evapi_set_tag(tname)
104
105 5. Event routes
106
107 5.1. evapi:connection-new
108 5.2. evapi:connection-closed
109 5.3. evapi:message-received
110
111 6. Exported pseudo-variables
112
113 1. Overview
114
115 The EVAPI module can be used to create an event message flow from
116 Kamailio to any application that can connect to a TCP socket. The
117 remote application can also issue messages received by Kamailio.
118
119 There is no protocol definition, it is all up to the author of the
120 routing script. Events can be generated for any event in Kamailio. For
121 3rd party transaction control, a transaction can be automatically
122 suspended when sending the event, to be resumed at a later point, maybe
123 triggered by an incoming message on the event socket.
124
125 2. Dependencies
126
127 2.1. Kamailio Modules
128 2.2. External Libraries or Applications
129
130 2.1. Kamailio Modules
131
132 The following modules must be loaded before this module:
133 * tm - (optional) needed only by evapi_async_relay()
134
135 2.2. External Libraries or Applications
136
137 The following libraries or applications must be installed before
138 running Kamailio with this module loaded:
139 * libev - http://software.schmorp.de/pkg/libev
140
141 3. Parameters
142
143 3.1. workers (int)
144 3.2. bind_addr (str)
145 3.3. netstring_format (int)
146 3.4. event_callback (str)
147 3.5. max_clients (int)
148 3.6. wait_idle (int)
149 3.7. wait_increase (int)
150
151 3.1. workers (int)
152
153 Number of worker processes to be started to handle incoming messages
154 from remote applications. If the value is 0, the handling of the
155 incoming message is done by the evapi dispatcher process.
156
157 Default value is 1.
158
159 Example 1.1. Set workers parameter
160 ...
161 modparam("evapi", "workers", 2)
162 ...
163
164 3.2. bind_addr (str)
165
166 Local IP and port to listen on for incoming TCP connections.
167
168 Default value is "127.0.0.1:8448".
169
170 Example 1.2. Set bind_addr parameter
171 ...
172 modparam("evapi", "bind_addr", "1.2.3.4:8228")
173 ...
174
175 3.3. netstring_format (int)
176
177 Control if messages on the socket (to and from clients) are
178 encapsulated in netstring format.
179
180 Default value is 1 (netstring format).
181
182 Example 1.3. Set netstring_format parameter
183 ...
184 modparam("evapi", "netstring_format", 0)
185 ...
186
187 3.4. event_callback (str)
188
189 The name of the function in the kemi configuration file (embedded
190 scripting language such as Lua, Python, ...) to be executed instead of
191 event_route[...] blocks.
192
193 The function receives a string parameter with the name of the event,
194 the values are: 'evapi:connection-new', 'evapi:connection-closed',
195 'evapi:message-received'.
196
197 Default value is 'empty' (no function is executed for events).
198
199 Example 1.4. Set event_callback parameter
200 ...
201 modparam("evapi", "event_callback", "ksr_evapi_event")
202 ...
203 -- event callback function implemented in Lua
204 function ksr_evapi_event(evname)
205 KSR.info("===== evapi module triggered event: " .. evname .. "\n");
206 return 1;
207 end
208 ...
209
210 3.5. max_clients (int)
211
212 Maximum number of clients that can connect to evapi socket.
213
214 Default value is 8.
215
216 Example 1.5. Set max_clients parameter
217 ...
218 modparam("evapi", "max_clients", 4)
219 ...
220
221 3.6. wait_idle (int)
222
223 How many micro-seconds to wait on idle, when no evapi messages are in
224 the processing queue.
225
226 Default value is 500 000 (0.5 seconds).
227
228 Example 1.6. Set wait_idle parameter
229 ...
230 modparam("evapi", "wait_idle", 100000)
231 ...
232
233 3.7. wait_increase (int)
234
235 Increase wait_idle by itself till its value becomes initial value
236 multiplied with wait_increase. The increase is done only consecutive
237 cycles without any evapi message. When a new evapi message is received,
238 wait_idle is reset to initial value. If wait_increase is set to 1, then
239 wait_idle is used with its initial value always.
240
241 Default value is 3.
242
243 Example 1.7. Set wait_increase parameter
244 ...
245 modparam("evapi", "wait_increase", 1)
246 ...
247
248 4. Functions
249
250 4.1. evapi_relay(evdata)
251 4.2. evapi_async_relay(evdata)
252 4.3. evapi_multicast(evdata, etag)
253 4.4. evapi_async_multicast(evdata, etag)
254 4.5. evapi_unicast(evdata, etag)
255 4.6. evapi_async_unicast(evdata, etag)
256 4.7. evapi_close()
257 4.8. evapi_set_tag(tname)
258
259 4.1. evapi_relay(evdata)
260
261 Relay the event data given as parameter to connected applications.
262
263 The format on the network is netstring with evdata payload if
264 netstring_format parameter is set to 1 or bare evdata if
265 netstring_format parameter is set to 0.
266
267 The function is passing the task to evapi dispatcher process, therefore
268 the SIP worker process is not blocked. Also, it doesn't wait for any
269 response, therefore the processing of the configuration continues very
270 fast when executing evapi_relay().
271
272 This function can be used from ANY_ROUTE.
273
274 Example 1.8. evapi_relay usage
275 ...
276 evapi_relay("{ \"event\": \"test\",\n \"data\": { \"fU\": \"$fU\" }\n}");
277 ...
278
279 The above example will send the following message over tcp:
280
281 Example 1.9. TCP message
282 ...
283 47:{
284 "event": "test",
285 "data": { "fU": "test" }
286 },
287 ...
288
289 4.2. evapi_async_relay(evdata)
290
291 Relay the event data given as parameter to connected applications.
292 Before evaluating the parameter, the request processing is suspended
293 using tm module (using the t_suspend()/t_continue() framework). The
294 routing of the SIP request can be continued once
295 event_route[evapi:message-received] is triggered. After
296 evapi_async_relay() returns true, no relaying should happen in
297 request_route(), it should be followed by exit;.
298
299 The format on the network is netstring with evdata payload if
300 netstring_format parameter is set to 1 or bare evdata if
301 netstring_format parameter is set to 0.
302
303 This function can be used from REQUEST_ROUTE.
304
305 Example 1.10. evapi_async_relay usage
306 ...
307 evapi_async_relay("{ \"event\": \"suspend\",\n \"data\":"
308 " { \"index\": \"$T(id_index)\", \"label\": \"$T(id_label)\" }\n}");
309 ...
310
311 4.3. evapi_multicast(evdata, etag)
312
313 Relay the event data given as parameter to connections that match the
314 tag provided by etag value. The etag can be a variable. For more see
315 evapi_relay() and evapi_set_tag().
316
317 Example 1.11. evapi_multicast usage
318 ...
319 evapi_multicast("{ \"event\": \"test\",\n \"data\": { \"fU\": \"$fU\" }\n}", "ta
320 gx");
321 ...
322
323 4.4. evapi_async_multicast(evdata, etag)
324
325 Async relay the event data given as parameter to connections that match
326 the tag provided by etag value. The etag can be a variable. For more
327 see evapi_async_relay() and evapi_set_tag().
328
329 Example 1.12. evapi_async_multicast usage
330 ...
331 evapi_async_multicast("{ \"event\": \"suspend\",\n \"data\":"
332 " { \"index\": \"$T(id_index)\", \"label\": \"$T(id_label)\" }\n}", "tagx");
333 ...
334
335 4.5. evapi_unicast(evdata, etag)
336
337 Relay the event data given as parameter to the first connection that
338 match the tag provided by etag value. The etag can be a variable. For
339 more see evapi_relay() and evapi_set_tag().
340
341 Example 1.13. evapi_unicast usage
342 ...
343 evapi_unicast("{ \"event\": \"test\",\n \"data\": { \"fU\": \"$fU\" }\n}", "tagx
344 ");
345 ...
346
347 4.6. evapi_async_unicast(evdata, etag)
348
349 Async relay the event data given as parameter to the first connection
350 that match the tag provided by etag value. The etag can be a variable.
351 For more see evapi_async_relay() and evapi_set_tag().
352
353 Example 1.14. evapi_async_unicast usage
354 ...
355 evapi_async_unicast("{ \"event\": \"suspend\",\n \"data\":"
356 " { \"index\": \"$T(id_index)\", \"label\": \"$T(id_label)\" }\n}", "tagx");
357 ...
358
359 4.7. evapi_close()
360
361 Close evapi current client connection.
362
363 This function can be used from ANY_ROUTE.
364
365 Example 1.15. evapi_close usage
366 ...
367 event_route[evapi:connection-new] {
368 if($evapi(srcaddr)!="127.0.0.1") {
369 evapi_close();
370 exit;
371 }
372 }
373 ...
374
375 4.8. evapi_set_tag(tname)
376
377 Set tag name for current client connection. The parameters has to be a
378 string up to 64 characters. It can also be a variable holding such
379 string.
380
381 This function can be used from ANY_ROUTE.
382
383 Example 1.16. evapi_set_tag usage
384 ...
385 event_route[evapi:connection-new] {
386 if($evapi(srcaddr)=="127.0.0.1") {
387 evapi_set_tag("local");
388 exit;
389 }
390 }
391 ...
392
393 5. Event routes
394
395 5.1. evapi:connection-new
396 5.2. evapi:connection-closed
397 5.3. evapi:message-received
398
399 5.1. evapi:connection-new
400
401 If defined, the module calls event_route[evapi:connection-new] when a
402 new client is connected.
403 ...
404 event_route[evapi:connection-new] {
405 xlog("new connection from $evapi(srcaddr):$evapi(srcport)\n");
406 }
407 ...
408
409 5.2. evapi:connection-closed
410
411 If defined, the module calls event_route[evapi:connection-closed] when
412 a client connection is closed.
413 ...
414 event_route[evapi:connection-closed] {
415 xlog("connection closed by $evapi(srcaddr):$evapi(srcport)\n");
416 }
417 ...
418
419 5.3. evapi:message-received
420
421 If defined, the module calls event_route[evapi:message-received] when a
422 message is received from a client.
423 ...
424 event_route[evapi:message-received] {
425 xlog("received [$evapi(msg)] from $evapi(srcaddr):$evapi(srcport)\n");
426 }
427 ...
428
429 6. Exported pseudo-variables
430
431 * $evapi(srcaddr) - source ip
432 * $evapi(srcport) - source port
433 * $evapi(msg) - received event message
434 * $evapi(conidx) - internal connection index
435
436 Exported pseudo-variables are documented at
437 https://www.kamailio.org/wikidocs/.