module_exports.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
  4. <section id="module_exports" xmlns:xi="http://www.w3.org/2001/XInclude">
  5. <sectioninfo>
  6. <revhistory>
  7. <revision>
  8. <revnumber>$Revision$</revnumber>
  9. <date>$Date$</date>
  10. </revision>
  11. </revhistory>
  12. </sectioninfo>
  13. <title>Structure <structname>module_exports</structname></title>
  14. <para>
  15. This structure describes interface that must be exported by each
  16. module. Every module must have a global variable named
  17. <varname>exports</varname> which is of type <structname>struct
  18. module_exports</structname>.
  19. </para>
  20. <para>
  21. Immediately after <function>dlopen</function> the server will try to
  22. find symbol named <varname>exports</varname> in the module to be
  23. loaded. This symbol is a structure describing interface of the
  24. module. Pointer to the symbol will be then put in
  25. <structfield>exports</structfield> field of
  26. <structname>sr_module</structname> structure representing the module in
  27. the server.
  28. </para>
  29. <para>
  30. Detailed description of the structure follows:
  31. </para>
  32. <programlisting>
  33. struct module_exports{
  34. char* name; /* null terminated module name */
  35. char** cmd_names; /* cmd names registered
  36. * by this modules */
  37. cmd_function* cmd_pointers; /* pointers to the
  38. * corresponding functions */
  39. int* param_no; /* number of parameters used by
  40. * the function */
  41. fixup_function* fixup_pointers; /* pointers to functions
  42. * called to "fix"
  43. * the params, e.g: precompile
  44. * a re */
  45. int cmd_no; /* number of registered commands
  46. * (size of cmd_{names,pointers}
  47. */
  48. char** param_names; /* parameter names registered
  49. * by this modules */
  50. modparam_t* param_types; /* Type of parameters */
  51. void** param_pointers; /* Pointers to the corresponding
  52. * memory locations */
  53. int par_no; /* number of registered parameters */
  54. init_function init_f; /* Initialization function */
  55. response_function response_f; /* function used for responses,
  56. * returns yes or no; can be null
  57. */
  58. destroy_function destroy_f; /* function called when the module
  59. * should be "destroyed", e.g: on
  60. * ser exit;
  61. * can be null */
  62. onbreak_function onbreak_f;
  63. child_init_function init_child_f; /* function called by all
  64. * processes after the fork */
  65. };
  66. </programlisting>
  67. <para>
  68. <emphasis>Fields and their description</emphasis>:
  69. </para>
  70. <itemizedlist>
  71. <listitem>
  72. <para>
  73. <structfield>name</structfield> - Name of the module.
  74. </para>
  75. </listitem>
  76. <listitem>
  77. <para>
  78. <structfield>cmd_names</structfield> - Array of names of
  79. exported commands.
  80. </para>
  81. </listitem>
  82. <listitem>
  83. <para>
  84. <structfield>cmd_pointers</structfield> - Array of pointers to
  85. functions implementing commands specified in
  86. <structfield>cmd_names</structfield> array.
  87. </para>
  88. <para>
  89. <emphasis>Function Prototype</emphasis>:
  90. </para>
  91. <funcsynopsis>
  92. <funcprototype>
  93. <funcdef>int <function>cmd_function</function></funcdef>
  94. <paramdef>struct sip_msg* <parameter>msg</parameter></paramdef>
  95. <paramdef>char* <parameter>param1</parameter></paramdef>
  96. <paramdef>char* <parameter>param2</parameter></paramdef>
  97. </funcprototype>
  98. </funcsynopsis>
  99. <para>
  100. The first parameter is <structname>sip_msg</structname>
  101. currently being processed. Remaining parameters are parameters
  102. from the config file. If the function accepts only one
  103. parameter, <parameter>param2</parameter> will be set to zero,
  104. if the function accepts no parameters,
  105. <parameter>param1</parameter> and <parameter
  106. moreinfo="none">param2</parameter> will be set to zero.
  107. </para>
  108. <para>
  109. The function should return number &gt; 0 if everything went OK
  110. and processing of the message should continue. The function
  111. should return 0 if processing of the message should be stopped.
  112. The function should return number &lt; 0 on an error.
  113. </para>
  114. </listitem>
  115. <listitem>
  116. <para>
  117. <structfield>param_no</structfield> - Array of number of
  118. parameters of exported commands.
  119. </para>
  120. </listitem>
  121. <listitem>
  122. <para>
  123. <structfield>fixup_pointer</structfield> - Array of pointers to
  124. fixup functions, each fixup function for one exported
  125. command. If there is no fixup function for a particular
  126. exported function, corresponding field in the array will
  127. contain zero.
  128. </para>
  129. <para>
  130. <emphasis>Function Prototype</emphasis>:
  131. </para>
  132. <funcsynopsis>
  133. <funcprototype>
  134. <funcdef>int <function>fixup_function</function></funcdef>
  135. <paramdef>void** <parameter>param</parameter></paramdef>
  136. <paramdef>int <parameter>param_no</parameter></paramdef>
  137. </funcprototype>
  138. </funcsynopsis>
  139. <para>
  140. The first parameter is pointing to variable to be fixed. The
  141. second parameter is order of the variable.
  142. </para>
  143. <para>
  144. The function should return 0 if everything went OK and number
  145. &lt; 0 on an error.
  146. </para>
  147. </listitem>
  148. <listitem>
  149. <para>
  150. <structfield>cmd_no</structfield> - Number of exported commands.
  151. </para>
  152. <important>
  153. <para>
  154. <structfield>cmd_names</structfield>,
  155. <structfield>cmd_pointers</structfield>,
  156. <structfield>param_no</structfield> and
  157. <structfield>fixup_pointer</structfield> arrays must have
  158. at least <structfield>cmd_no</structfield> elements ! (It
  159. might even kill your cat if you fail to fulfill this
  160. condition).
  161. </para>
  162. </important>
  163. </listitem>
  164. <listitem>
  165. <para>
  166. <structfield>param_names</structfield> - Array of names of
  167. exported parameters.
  168. </para>
  169. </listitem>
  170. <listitem>
  171. <para>
  172. <structfield>param_types</structfield> - Array of types of
  173. parameters, each field of the array can be either PARAM_STR/PARAM_STRING or
  174. PARAM_INT (currently only three parameter types are defined).
  175. </para>
  176. </listitem>
  177. <listitem>
  178. <para>
  179. <structfield>param_pointers</structfield> - Array of pointers
  180. to variables, that hold values of the parameters.
  181. </para>
  182. </listitem>
  183. <listitem>
  184. <para>
  185. <structfield>param_no</structfield> - Number of exported
  186. parameters.
  187. </para>
  188. <important>
  189. <para>
  190. <structfield>param_names</structfield>,
  191. <structfield>param_types</structfield> and
  192. <structfield>param_pointers</structfield> arrays must have
  193. at least <structfield>param_no</structfield> elements !
  194. (Remember the previous note about your cat ? The same might
  195. happen to your dog if you fail to fulfill the condition
  196. second time !).
  197. </para>
  198. </important>
  199. </listitem>
  200. <listitem>
  201. <para>
  202. <structfield>init_f</structfield> - Pointer to module's
  203. initialization function, 0 if the module doesn't need
  204. initialization function.
  205. </para>
  206. <para>
  207. <emphasis>Function Prototype</emphasis>:
  208. </para>
  209. <funcsynopsis>
  210. <funcprototype>
  211. <funcdef>int <function>init_function</function></funcdef>
  212. <void/>
  213. </funcprototype>
  214. </funcsynopsis>
  215. <para>
  216. The function should return 0 if everything went OK and number
  217. &lt; 0 on an error;
  218. </para>
  219. </listitem>
  220. <listitem>
  221. <para>
  222. <structfield>response_f</structfield> - If a module is
  223. interested in seeing responses, it will provide pointer to a
  224. function here. The function will be called when a response
  225. comes. The field will contain 0 if the module doesn't want to
  226. see responses.
  227. </para>
  228. <para>
  229. <emphasis>Function Prototype</emphasis>:
  230. </para>
  231. <funcsynopsis>
  232. <funcprototype>
  233. <funcdef>int <function>response_function</function></funcdef>
  234. <paramdef>struct sip_msg* <parameter>msg</parameter></paramdef>
  235. </funcprototype>
  236. </funcsynopsis>
  237. <para>
  238. The function accepts one parameter which is structure
  239. representing the response currently being processed.
  240. </para>
  241. <para>
  242. The function should return 0 if the response should be dropped.
  243. </para>
  244. </listitem>
  245. <listitem>
  246. <para>
  247. <structfield>destroy_f</structfield> - Destroy function. The
  248. function will be called when the server is shutting down. Can
  249. be 0 if the module doesn't need destroy function.
  250. </para>
  251. <para>
  252. <emphasis>Function Prototype</emphasis>:
  253. </para>
  254. <funcsynopsis>
  255. <funcprototype>
  256. <funcdef>void <function>destroy_function</function></funcdef>
  257. <void/>
  258. </funcprototype>
  259. </funcsynopsis>
  260. </listitem>
  261. <listitem>
  262. <para>
  263. <structfield>onbreak_f</structfield> - On break function. The
  264. function will be called when processing of a route statement
  265. was aborted. Can be 0 if module doesn't need this function.
  266. </para>
  267. <para>
  268. <emphasis>Function Prototype</emphasis>:
  269. </para>
  270. <funcsynopsis>
  271. <funcprototype>
  272. <funcdef>void <function>onbreak_function</function></funcdef>
  273. <paramdef>struct sip_msg* <parameter>msg</parameter></paramdef>
  274. </funcprototype>
  275. </funcsynopsis>
  276. <para>
  277. The function accepts one parameter which is message currently
  278. being processed.
  279. </para>
  280. </listitem>
  281. <listitem>
  282. <para>
  283. <structfield>init_child_f</structfield> - Child initialization
  284. function. This is an additional initialization
  285. function. <structfield>init_f</structfield> will be called from
  286. the main process <emphasis>BEFORE</emphasis> the main process
  287. forks children. <structfield>init_child_f</structfield> will be
  288. called from all children <emphasis>AFTER</emphasis> the fork.
  289. </para>
  290. <para>
  291. Per-child specific initialization can be done here. For
  292. example, each child can open its own database connection in the
  293. function, and so on.
  294. </para>
  295. <para>
  296. <emphasis>Function Prototype</emphasis>:
  297. </para>
  298. <funcsynopsis>
  299. <funcprototype>
  300. <funcdef>int <function>child_init_function</function></funcdef>
  301. <paramdef>int <parameter>rank</parameter></paramdef>
  302. </funcprototype>
  303. </funcsynopsis>
  304. <para>
  305. The function accepts one parameter, which is rank (starting
  306. from 0) of child executing the function.
  307. </para>
  308. <para>
  309. The function should return 0 if everything went OK and number
  310. &lt; 0 on an error.
  311. </para>
  312. </listitem>
  313. </itemizedlist>
  314. </section>