app_python_admin.xml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. This module allows executing Python scripts from config file,
  15. exporting functions to access the SIP message from Python.
  16. </para>
  17. <para>
  18. For some basic examples of Python scripts that can be used with
  19. this module, look at the files inside source tree located at
  20. 'modules/app_python/python_examples/'.
  21. </para>
  22. </section>
  23. <section>
  24. <title>Dependencies</title>
  25. <section>
  26. <title>&kamailio; Modules</title>
  27. <para>
  28. The following modules must be loaded before this module:
  29. <itemizedlist>
  30. <listitem>
  31. <para>
  32. <emphasis>none</emphasis>.
  33. </para>
  34. </listitem>
  35. </itemizedlist>
  36. </para>
  37. </section>
  38. <section>
  39. <title>External Libraries or Applications</title>
  40. <para>
  41. The following libraries or applications must be installed before running
  42. &kamailio; with this module loaded:
  43. <itemizedlist>
  44. <listitem>
  45. <para>
  46. <emphasis>python-dev</emphasis> - Python devel library.
  47. </para>
  48. </listitem>
  49. </itemizedlist>
  50. </para>
  51. </section>
  52. </section>
  53. <section>
  54. <title>Parameters</title>
  55. <section>
  56. <title><varname>script_name</varname> (string)</title>
  57. <para>
  58. The path to the fiel with Python code to be executed
  59. from configuration file.
  60. </para>
  61. <para>
  62. <emphasis>
  63. Default value is <quote>/usr/local/etc/kamailio/handler.py</quote>.
  64. </emphasis>
  65. </para>
  66. <example>
  67. <title>Set <varname>script_name</varname> parameter</title>
  68. <programlisting format="linespecific">
  69. ...
  70. modparam("app_python", "script_name", "/usr/local/etc/kamailio/myscript.py")
  71. ...
  72. </programlisting>
  73. </example>
  74. </section>
  75. <section>
  76. <title><varname>mod_init_function</varname> (string)</title>
  77. <para>
  78. The Python function to be executed by this module when
  79. it is initialied by &kamailio;.
  80. </para>
  81. <para>
  82. <emphasis>
  83. Default value is <quote>mod_init</quote>.
  84. </emphasis>
  85. </para>
  86. <example>
  87. <title>Set <varname>mod_init_function</varname> parameter</title>
  88. <programlisting format="linespecific">
  89. ...
  90. modparam("app_python", "mod_init_function", "my_mod_init")
  91. ...
  92. </programlisting>
  93. </example>
  94. </section>
  95. <section>
  96. <title><varname>child_init_method</varname> (string)</title>
  97. <para>
  98. The Python function to be executed by this module when
  99. a new worker process (child) is initialied by &kamailio;.
  100. </para>
  101. <para>
  102. <emphasis>
  103. Default value is <quote>child_init</quote>.
  104. </emphasis>
  105. </para>
  106. <example>
  107. <title>Set <varname>child_init_method</varname> parameter</title>
  108. <programlisting format="linespecific">
  109. ...
  110. modparam("app_python", "child_init_method", "my_child_init")
  111. ...
  112. </programlisting>
  113. </example>
  114. </section>
  115. </section>
  116. <section>
  117. <title>Functions</title>
  118. <section>
  119. <title>
  120. <function moreinfo="none">python_exec(method [, args])</function>
  121. </title>
  122. <para>
  123. Execute the Python function with the name given by the parameter 'method'.
  124. Optionally can be provided a second string with parameters to be passed
  125. to the Python function.
  126. </para>
  127. <example>
  128. <title><function>python_exec</function> usage</title>
  129. <programlisting format="linespecific">
  130. ...
  131. python_exec("my_python_function");
  132. python_exec("my_python_function", "my_params");
  133. ...
  134. </programlisting>
  135. </example>
  136. </section>
  137. </section>
  138. </chapter>