README 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. EVAPI Module
  2. Daniel-Constantin Mierla
  3. <[email protected]>
  4. Edited by
  5. Daniel-Constantin Mierla
  6. <[email protected]>
  7. Copyright © 2014 asipto.com
  8. __________________________________________________________________
  9. Table of Contents
  10. 1. Admin Guide
  11. 1. Overview
  12. 2. Dependencies
  13. 2.1. Kamailio Modules
  14. 2.2. External Libraries or Applications
  15. 3. Parameters
  16. 3.1. workers (int)
  17. 3.2. bind_addr (str)
  18. 3.3. netstring_format (int)
  19. 4. Functions
  20. 4.1. evapi_relay(evdata)
  21. 4.2. evapi_async_relay(evdata)
  22. 4.3. evapi_close()
  23. 5. Event routes
  24. 5.1. evapi:connection-new
  25. 5.2. evapi:connection-closed
  26. 5.3. evapi:message-received
  27. 6. Exported pseudo-variables
  28. List of Examples
  29. 1.1. Set workers parameter
  30. 1.2. Set bind_addr parameter
  31. 1.3. Set netstring_format parameter
  32. 1.4. evapi_relay usage
  33. 1.5. TCP message
  34. 1.6. evapi_async_relay usage
  35. 1.7. evapi_evapi usage
  36. Chapter 1. Admin Guide
  37. Table of Contents
  38. 1. Overview
  39. 2. Dependencies
  40. 2.1. Kamailio Modules
  41. 2.2. External Libraries or Applications
  42. 3. Parameters
  43. 3.1. workers (int)
  44. 3.2. bind_addr (str)
  45. 3.3. netstring_format (int)
  46. 4. Functions
  47. 4.1. evapi_relay(evdata)
  48. 4.2. evapi_async_relay(evdata)
  49. 4.3. evapi_close()
  50. 5. Event routes
  51. 5.1. evapi:connection-new
  52. 5.2. evapi:connection-closed
  53. 5.3. evapi:message-received
  54. 6. Exported pseudo-variables
  55. 1. Overview
  56. The EVAPI module can be used to create an event message flow from
  57. Kamailio to any application that can connect to a TCP socket. The
  58. remote application can also issue messages received by Kamailio.
  59. There is no protocol definition, it is all up to the author of the
  60. routing script. Events can be generated for any event in Kamailio. For
  61. 3rd party transaction control, a transaction can be automatically
  62. suspended when sending the event, to be resumed at a later point, maybe
  63. triggered by an incoming message on the event socket.
  64. 2. Dependencies
  65. 2.1. Kamailio Modules
  66. 2.2. External Libraries or Applications
  67. 2.1. Kamailio Modules
  68. The following modules must be loaded before this module:
  69. * tm - (optional) needed only by evapi_async_relay()
  70. 2.2. External Libraries or Applications
  71. The following libraries or applications must be installed before
  72. running Kamailio with this module loaded:
  73. * libev
  74. 3. Parameters
  75. 3.1. workers (int)
  76. 3.2. bind_addr (str)
  77. 3.3. netstring_format (int)
  78. 3.1. workers (int)
  79. Number of worker processes to be started to handle incoming messages
  80. from remote applications.
  81. Default value is 1.
  82. Example 1.1. Set workers parameter
  83. ...
  84. modparam("evapi", "workers", 2)
  85. ...
  86. 3.2. bind_addr (str)
  87. Local IP and port to listen on for incoming TCP connections.
  88. Default value is "127.0.0.1:8448".
  89. Example 1.2. Set bind_addr parameter
  90. ...
  91. modparam("evapi", "bind_addr", "1.2.3.4:8228")
  92. ...
  93. 3.3. netstring_format (int)
  94. Control if messages on the socket (to and from clients) are
  95. encapsulated in netstring format.
  96. Default value is 1 (netstring format).
  97. Example 1.3. Set netstring_format parameter
  98. ...
  99. modparam("evapi", "netstring_format", 0)
  100. ...
  101. 4. Functions
  102. 4.1. evapi_relay(evdata)
  103. 4.2. evapi_async_relay(evdata)
  104. 4.3. evapi_close()
  105. 4.1. evapi_relay(evdata)
  106. Relay the event data give as parameter to connected applications. The
  107. format on the network is netstring with evdata payload.
  108. This function can be used from ANY_ROUTE.
  109. Example 1.4. evapi_relay usage
  110. ...
  111. evapi_relay("{ \"event\": \"test\",\n \"data\": { \"fU\": \"$fU\" }\n}");
  112. ...
  113. The above exaple will send the following message over tcp:
  114. Example 1.5. TCP message
  115. ...
  116. 47:{
  117. "event": "test",
  118. "data": { "fU": "test" }
  119. },
  120. ...
  121. 4.2. evapi_async_relay(evdata)
  122. Relay the event data give as parameter to connected applications. The
  123. format on the network is netstring with evdata payload. Before
  124. evaluating the parameter, the request processing is suspended using tm
  125. module.
  126. This function can be used from REQUEST_ROUTE.
  127. Example 1.6. evapi_async_relay usage
  128. ...
  129. evapi_async_relay("{ \"event\": \"suspend\",\n \"data\":"
  130. " { \"index\": \"$T(id_index)\", \"label\": \"$T(id_label)\" }\n}");
  131. ...
  132. 4.3. evapi_close()
  133. Close evapi current client connection.
  134. This function can be used from ANY_ROUTE.
  135. Example 1.7. evapi_evapi usage
  136. ...
  137. event_route[evapi:connection-new] {
  138. if($evapi(srcaddr)!="127.0.0.1") {
  139. evapi_close();
  140. exit;
  141. }
  142. }
  143. ...
  144. 5. Event routes
  145. 5.1. evapi:connection-new
  146. 5.2. evapi:connection-closed
  147. 5.3. evapi:message-received
  148. 5.1. evapi:connection-new
  149. If defined, the module calls event_route[evapi:connection-new] when a
  150. new client is connected.
  151. ...
  152. event_route[evapi:connection-new] {
  153. xlog("new connection from $evapi(srcaddr):$evapi(srcport)\n");
  154. }
  155. ...
  156. 5.2. evapi:connection-closed
  157. If defined, the module calls event_route[evapi:connection-closed] when
  158. a client connection is closed.
  159. ...
  160. event_route[evapi:connection-closed] {
  161. xlog("connection closed by $evapi(srcaddr):$evapi(srcport)\n");
  162. }
  163. ...
  164. 5.3. evapi:message-received
  165. If defined, the module calls event_route[evapi:message-received] when a
  166. message is received from a client.
  167. ...
  168. event_route[evapi:message-received] {
  169. xlog("received [$evapi(msg)] from $evapi(srcaddr):$evapi(srcport)\n");
  170. }
  171. ...
  172. 6. Exported pseudo-variables
  173. * $evapi(srcaddr) - source ip
  174. * $evapi(srcport) - source port
  175. * $evapi(msg) - received event message
  176. * $evapi(conidx) - internal connection index
  177. Exported pseudo-variables are documented at
  178. http://www.kamailio.org/wiki/.