evapi_admin.xml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?xml version="1.0" encoding='ISO-8859-1'?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  4. <!-- Include general documentation entities -->
  5. <!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
  6. %docentities;
  7. ]>
  8. <!-- Module User's Guide -->
  9. <chapter>
  10. <title>&adminguide;</title>
  11. <section>
  12. <title>Overview</title>
  13. <para>
  14. The EVAPI module can be used to create an event message flow
  15. from Kamailio to any application that can connect to a TCP
  16. socket. The remote application can also issue messages received
  17. by Kamailio.
  18. </para>
  19. <para>
  20. There is no protocol definition, it is all up to the author of
  21. the routing script. Events can be generated for any event in
  22. Kamailio. For 3rd party transaction control, a transaction can
  23. be automatically suspended when sending the event, to be resumed
  24. at a later point, maybe triggered by an incoming message on the event socket.
  25. </para>
  26. </section>
  27. <section>
  28. <title>Dependencies</title>
  29. <section>
  30. <title>&kamailio; Modules</title>
  31. <para>
  32. The following modules must be loaded before this module:
  33. <itemizedlist>
  34. <listitem>
  35. <para>
  36. <emphasis>tm</emphasis> - (optional) needed only by
  37. evapi_async_relay()
  38. </para>
  39. </listitem>
  40. </itemizedlist>
  41. </para>
  42. </section>
  43. <section>
  44. <title>External Libraries or Applications</title>
  45. <para>
  46. The following libraries or applications must be installed before running
  47. &kamailio; with this module loaded:
  48. <itemizedlist>
  49. <listitem>
  50. <para>
  51. <emphasis>libev</emphasis>
  52. </para>
  53. </listitem>
  54. </itemizedlist>
  55. </para>
  56. </section>
  57. </section>
  58. <section>
  59. <title>Parameters</title>
  60. <section id="evapi.p.workers">
  61. <title><varname>workers</varname> (int)</title>
  62. <para>
  63. Number of worker processes to be started to handle incoming messages
  64. from remote applications.
  65. </para>
  66. <para>
  67. <emphasis>
  68. Default value is 1.
  69. </emphasis>
  70. </para>
  71. <example>
  72. <title>Set <varname>workers</varname> parameter</title>
  73. <programlisting format="linespecific">
  74. ...
  75. modparam("evapi", "workers", 2)
  76. ...
  77. </programlisting>
  78. </example>
  79. </section>
  80. <section id="evapi.p.bind_addr">
  81. <title><varname>bind_addr</varname> (str)</title>
  82. <para>
  83. Local IP and port to listen on for incoming TCP connections.
  84. </para>
  85. <para>
  86. <emphasis>
  87. Default value is "127.0.0.1:8448".
  88. </emphasis>
  89. </para>
  90. <example>
  91. <title>Set <varname>bind_addr</varname> parameter</title>
  92. <programlisting format="linespecific">
  93. ...
  94. modparam("evapi", "bind_addr", "1.2.3.4:8228")
  95. ...
  96. </programlisting>
  97. </example>
  98. </section>
  99. <section id="evapi.p.netstring_format">
  100. <title><varname>netstring_format</varname> (int)</title>
  101. <para>
  102. Control if messages on the socket (to and from clients)
  103. are encapsulated in netstring format.
  104. </para>
  105. <para>
  106. <emphasis>
  107. Default value is 1 (netstring format).
  108. </emphasis>
  109. </para>
  110. <example>
  111. <title>Set <varname>netstring_format</varname> parameter</title>
  112. <programlisting format="linespecific">
  113. ...
  114. modparam("evapi", "netstring_format", 0)
  115. ...
  116. </programlisting>
  117. </example>
  118. </section>
  119. </section>
  120. <section>
  121. <title>Functions</title>
  122. <section id="evapi.f.evapi_relay">
  123. <title>
  124. <function moreinfo="none">evapi_relay(evdata)</function>
  125. </title>
  126. <para>
  127. Relay the event data give as parameter to connected applications.
  128. The format on the network is netstring with evdata payload.
  129. </para>
  130. <para>
  131. This function can be used from ANY_ROUTE.
  132. </para>
  133. <example>
  134. <title><function>evapi_relay</function> usage</title>
  135. <programlisting format="linespecific">
  136. ...
  137. evapi_relay("{ \"event\": \"test\",\n \"data\": { \"fU\": \"$fU\" }\n}");
  138. ...
  139. </programlisting>
  140. </example>
  141. <para>
  142. The above exaple will send the following message over tcp:
  143. </para>
  144. <example>
  145. <title>TCP message</title>
  146. <programlisting format="linespecific">
  147. ...
  148. 47:{
  149. "event": "test",
  150. "data": { "fU": "test" }
  151. },
  152. ...
  153. </programlisting>
  154. </example>
  155. </section>
  156. <section id="evapi.f.evapi_async_relay">
  157. <title>
  158. <function moreinfo="none">evapi_async_relay(evdata)</function>
  159. </title>
  160. <para>
  161. Relay the event data give as parameter to connected applications.
  162. The format on the network is netstring with evdata payload. Before
  163. evaluating the parameter, the request processing is suspended using
  164. tm module.
  165. </para>
  166. <para>
  167. This function can be used from REQUEST_ROUTE.
  168. </para>
  169. <example>
  170. <title><function>evapi_async_relay</function> usage</title>
  171. <programlisting format="linespecific">
  172. ...
  173. evapi_async_relay("{ \"event\": \"suspend\",\n \"data\":"
  174. " { \"index\": \"$T(id_index)\", \"label\": \"$T(id_label)\" }\n}");
  175. ...
  176. </programlisting>
  177. </example>
  178. </section>
  179. <section id="evapi.f.evapi_close">
  180. <title>
  181. <function moreinfo="none">evapi_close()</function>
  182. </title>
  183. <para>
  184. Close evapi current client connection.
  185. </para>
  186. <para>
  187. This function can be used from ANY_ROUTE.
  188. </para>
  189. <example>
  190. <title><function>evapi_evapi</function> usage</title>
  191. <programlisting format="linespecific">
  192. ...
  193. event_route[evapi:connection-new] {
  194. if($evapi(srcaddr)!="127.0.0.1") {
  195. evapi_close();
  196. exit;
  197. }
  198. }
  199. ...
  200. </programlisting>
  201. </example>
  202. </section>
  203. </section>
  204. <section>
  205. <title>Event routes</title>
  206. <section>
  207. <title>
  208. <function moreinfo="none">evapi:connection-new</function>
  209. </title>
  210. <para>
  211. If defined, the module calls event_route[evapi:connection-new]
  212. when a new client is connected.
  213. </para>
  214. <programlisting format="linespecific">
  215. ...
  216. event_route[evapi:connection-new] {
  217. xlog("new connection from $evapi(srcaddr):$evapi(srcport)\n");
  218. }
  219. ...
  220. </programlisting>
  221. </section>
  222. <section>
  223. <title>
  224. <function moreinfo="none">evapi:connection-closed</function>
  225. </title>
  226. <para>
  227. If defined, the module calls event_route[evapi:connection-closed]
  228. when a client connection is closed.
  229. </para>
  230. <programlisting format="linespecific">
  231. ...
  232. event_route[evapi:connection-closed] {
  233. xlog("connection closed by $evapi(srcaddr):$evapi(srcport)\n");
  234. }
  235. ...
  236. </programlisting>
  237. </section>
  238. <section>
  239. <title>
  240. <function moreinfo="none">evapi:message-received</function>
  241. </title>
  242. <para>
  243. If defined, the module calls event_route[evapi:message-received]
  244. when a message is received from a client.
  245. </para>
  246. <programlisting format="linespecific">
  247. ...
  248. event_route[evapi:message-received] {
  249. xlog("received [$evapi(msg)] from $evapi(srcaddr):$evapi(srcport)\n");
  250. }
  251. ...
  252. </programlisting>
  253. </section>
  254. </section>
  255. <section>
  256. <title>Exported pseudo-variables</title>
  257. <itemizedlist>
  258. <listitem><para>
  259. <emphasis>$evapi(srcaddr)</emphasis> - source ip
  260. </para></listitem>
  261. <listitem><para>
  262. <emphasis>$evapi(srcport)</emphasis> - source port
  263. </para></listitem>
  264. <listitem><para>
  265. <emphasis>$evapi(msg)</emphasis> - received event message
  266. </para></listitem>
  267. <listitem><para>
  268. <emphasis>$evapi(conidx)</emphasis> - internal connection index
  269. </para></listitem>
  270. </itemizedlist>
  271. <para>
  272. Exported pseudo-variables are documented at &kamwikilink;.
  273. </para>
  274. </section>
  275. </chapter>