modiface.xml 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  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_interface" 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. <abstract>
  13. <para>
  14. SER features modular architecture which allows us to split SER's
  15. functionality across several modules. This approach gives us
  16. greater flexibility, only required set of functions can be loaded
  17. upon startup which minimizes the server's memory footprint. Modules
  18. can be also provided by 3rd party developers and distributed
  19. separately from the main server. Most of the functionality that SER
  20. provides is available through modules, the core itself contains
  21. only minimum set of functions that is essential for proper server's
  22. behavior or that is needed by all modules.
  23. </para>
  24. <para>
  25. This chapter provides detailed information on module interface of
  26. SER, which is used to pass information on available functions and
  27. parameters from the modules to the core.
  28. </para>
  29. </abstract>
  30. </sectioninfo>
  31. <title>Module Interface</title>
  32. <section id="shared_objects">
  33. <title>Shared Objects</title>
  34. <abstract>
  35. <para>
  36. First it would be good to know how SER loads and uses modules
  37. before we describe the module interface in detail. This section
  38. gives a brief overview of SER's module subsystem.
  39. </para>
  40. </abstract>
  41. <para>
  42. SER modules are compiled as "shared objects". A file containing a
  43. shared object has usually .so suffix. All modules (shared objects)
  44. will be stored in one directory after installation. For example tm
  45. module, which contains code essential for stateful processing, will
  46. be stored in file named <filename>tm.so</filename>. By default
  47. these files are stored in
  48. <filename>/usr/local/lib/ser/modules</filename> directory.
  49. </para>
  50. <para>
  51. You can later load the modules using <command>loadmodule</command>
  52. command in your configuration file. If you want to load previously
  53. mentioned <filename>tm.so</filename> module, you can do it using
  54. <command>loadmodule "/usr/local/lib/ser/modules/tm.so"</command> in
  55. your configuration file. This command invokes dynamic linker
  56. provided by the operating system which opens
  57. <filename>tm.so</filename> file, loads it into memory and resolves
  58. all symbol dependencies (a module might require symbols from the
  59. core, for example functions and variables).
  60. </para>
  61. <para>
  62. As the last step of the module loading the core tries to find
  63. variable named <varname>exports</varname>, which describes all
  64. functions and parameters provided by the module. These functions
  65. and parameters are later available to the server and can be used
  66. either in the configuration file or by other modules.
  67. </para>
  68. </section>
  69. <section id="exporting_functions">
  70. <title>Exporting Functions</title>
  71. <abstract>
  72. <para>
  73. Each module can provide zero or more functions, which can be
  74. used in the configuration file or by other modules
  75. internally. This section gives a detailed description of
  76. structure describing exported functions and passing this
  77. information to the core through the module interface.
  78. </para>
  79. </abstract>
  80. <para>
  81. Each function exported by a module must be described by
  82. <structname>cmd_export_t</structname> structure. Structures
  83. describing all exported functions are arranged into an array and
  84. pointer to the array is then passed to the core. The last element
  85. of the array must contain 0 in all it's fields, this element serves
  86. as the mark telling the core that this is the very last element and
  87. it must stop scanning the array.
  88. </para>
  89. <para>
  90. Each exported function is described by the following structure:
  91. </para>
  92. <programlisting>
  93. struct cmd_export_ {
  94. char* name; /* null terminated command name */
  95. cmd_function function; /* pointer to the corresponding function */
  96. int param_no; /* number of parameters used by the function */
  97. fixup_function fixup; /* pointer to the function called to "fix" the parameters */
  98. int flags; /* Function flags */
  99. };
  100. typedef struct cmd_export_ cmd_export_t;
  101. </programlisting>
  102. <itemizedlist>
  103. <title>Meaning of the fileds:</title>
  104. <listitem>
  105. <simpara><varname>char* name</varname></simpara>
  106. <simpara>
  107. This is the name under which the function will be visible
  108. to the core. Usually it is the same as the name of the
  109. corresponding function.
  110. </simpara>
  111. </listitem>
  112. <listitem>
  113. <simpara><varname>cmd_function function</varname></simpara>
  114. <para>cmd_function type is defined as follows: </para>
  115. <programlisting>
  116. typedef int (*cmd_function)(struct sip_msg*, char*, char*);
  117. </programlisting>
  118. <simpara>
  119. The first parameter is a SIP message
  120. being processed, the other 2 parameters are given from the
  121. configuration file.
  122. </simpara>
  123. <note>
  124. <simpara>
  125. From time to time you might need to export a function
  126. that has different synopsis. This can happen if you
  127. export functions that are supposed to be called by
  128. other modules only and must not be called from the
  129. configuration script. In this case you will have to do
  130. type-casting otherwise the compiler will complain and
  131. will not compile your module.
  132. </simpara>
  133. <simpara>
  134. Simply put (cmd_function) just before the function
  135. name, for example
  136. <function>(cmd_function)my_function</function>. Don't
  137. use this unless you know what are you doing ! The
  138. server might crash if you pass wrong parameters to the
  139. function later !
  140. </simpara>
  141. </note>
  142. </listitem>
  143. <listitem>
  144. <simpara><varname>int param_no</varname></simpara>
  145. <simpara>
  146. Number of parameters of the function. It can be 0, 1 or
  147. 2. The function will be not visible from the configuration
  148. script if you use another value.
  149. </simpara>
  150. </listitem>
  151. <listitem>
  152. <simpara><varname>fixup_function fixup</varname></simpara>
  153. <simpara>
  154. This is the function that will be used to "fixup" function
  155. parameters. Set this field to 0 if you don't need this.
  156. </simpara>
  157. <simpara>
  158. If you provide pointer to a fixup function in this field,
  159. the fixup function will be called for each occurrence of
  160. the exported function in the configuration script.
  161. </simpara>
  162. <simpara>
  163. The fixup function can be used to perform some operation on
  164. the function parameters. For example, if one of the
  165. parameters is a regular expression, you can use the fixup
  166. to compile the regular expression. The fixup functions are
  167. called only once - upon the server startup and so the
  168. regular expression will be compiled before the server
  169. starts processing messages. When the server calls the
  170. exported function to process a SIP message, the function
  171. will be given the already compiled regular expression and
  172. doesn't have to compile it again. This is a significant
  173. performance improvement.
  174. </simpara>
  175. <simpara>
  176. Fixup functions can also be used to convert string to
  177. integer. As you have might noticed, the exported functions
  178. accept up to 2 parameters of type char*. Because of that it
  179. is not possible to pass integer parameters from the script
  180. files directly. If you want to pass an integer as a
  181. parameter, you must pass it as string (i.e. enclosed in
  182. quotes).
  183. </simpara>
  184. <simpara>
  185. Fixup function can be used to convert the string back to
  186. integer. Such a conversion should happened only once because
  187. the string parameter doesn't change when the server is
  188. running. Fixup is therefore ideal place for the conversion,
  189. it will be converted upon the server startup before the
  190. server starts processing SIP messages. After the conversion
  191. the function will get directly the converted value. See
  192. existing modules for example of such a fixup function.
  193. </simpara>
  194. </listitem>
  195. <listitem>
  196. <simpara><varname>int flags</varname></simpara>
  197. <simpara>
  198. Usage of each function can be restricted. You may want to
  199. write a function that can be used by other modules but
  200. cannot be called from the script. If you write a function
  201. that is supposed to process SIP requests only, you may want
  202. to restrict it so it will be never called for SIP replies
  203. and vice versa. That's what is flags field for.
  204. </simpara>
  205. <simpara>
  206. This field is OR value of different flags. Currently only
  207. REQUEST_ROUTE and REPLY_ROUTE flags are defined and used by
  208. the core. If you use REQUEST_ROUTE flag, then the function
  209. can be called from the main route block. If you use
  210. REPLY_ROUTE flag, then the function can be called from
  211. reply route blocks (More on this in the SER User's
  212. Guide). If this field is set to 0, then the function can be
  213. called internally (i.e. from other modules) only. If you
  214. want to make your function callable anywhere in the script,
  215. you can use REQUEST_ROUTE | REPLY_ROUTE.
  216. </simpara>
  217. </listitem>
  218. </itemizedlist>
  219. </section>
  220. <section id="exporting_parameters">
  221. <title>Exporting Parameters</title>
  222. <abstract>
  223. <simpara>
  224. Each module can provide zero or more parameters, which can
  225. affect the module's behavior. This section gives a detailed
  226. description of structures describing exported parameters and
  227. passing this information to the core through the module
  228. interface.
  229. </simpara>
  230. </abstract>
  231. <simpara>
  232. Each parameter exported by a module must be described by
  233. <structname>param_export_t</structname> structure. Structures
  234. describing all exported parameters are arranged into an array and
  235. pointer to the array is then passed to the core. The last element
  236. of the array must contain 0 in all it's fields, this element serves
  237. as the mark telling the core that this is the very last element and
  238. it must stop scanning the array (This is same as in array of
  239. exported functions).
  240. </simpara>
  241. <simpara>
  242. Each exported parameter is described by the following structure:
  243. </simpara>
  244. <programlisting>
  245. struct param_export_ {
  246. char* name; /* null terminated param. name */
  247. modparam_t type; /* param. type */
  248. void* param_pointer; /* pointer to the param. memory location */
  249. };
  250. typedef struct param_export_ param_export_t;
  251. </programlisting>
  252. <itemizedlist>
  253. <title>Meaning of the fields:</title>
  254. <listitem>
  255. <simpara><varname>char* name</varname></simpara>
  256. <simpara>
  257. This is null-terminated name of the parameters as it will
  258. be used in the scripts. Usually this is the same as the
  259. name of the variable holding the value.
  260. </simpara>
  261. </listitem>
  262. <listitem>
  263. <simpara><varname>modparam_t type</varname></simpara>
  264. <simpara>
  265. Type of the parameter. Currently only two types are
  266. defined. PARAM_INT for integer parameters (corresponding
  267. variable must be of type int), PARAM_STR for str parameters
  268. (corresponding variable must be of type char*) and PARAM_STRING
  269. for string parameters (corresponding variable must be of type char*).
  270. </simpara>
  271. </listitem>
  272. <listitem>
  273. <simpara><varname>void* param_pointer</varname></simpara>
  274. <simpara>
  275. Pointer to the corresponding variable (stored as void*
  276. pointer, make sure that the variable has appropriate type
  277. depending on the type of the parameter !).
  278. </simpara>
  279. </listitem>
  280. </itemizedlist>
  281. </section>
  282. <section id="module_initialization">
  283. <title>Module Initialization</title>
  284. <simpara>
  285. If you need to initialize your module before the server starts
  286. processing SIP messages, you should provide
  287. initialization function. Each module can provide two initialization
  288. functions, main initialization function and child-specific
  289. initialization function. Fields holding pointers to both
  290. initialization functions are in main export structure (will be
  291. described later). Simply pass 0 instead of function pointer if you
  292. don't need one or both initialization functions.
  293. </simpara>
  294. <simpara>
  295. The main initialization function will be called before any other
  296. function exported by the module. The function will be called only
  297. once, before the main process forks. This function is good for
  298. initialization that is common for all the children (processes). The
  299. function should return 0 if everything went OK and a negative error
  300. code otherwise. Server will abort if the function returns a
  301. negative value.
  302. </simpara>
  303. <simpara>
  304. Per-child initialization function will be called
  305. <emphasis>after</emphasis> the main process forks. The function
  306. will be called for each child separately. The function should
  307. perform initialization that is specific for each child. For example
  308. each child process might open it's own database connection to avoid
  309. locking of a single connection shared by many processes. Such
  310. connections can be opened in the per-child initialization
  311. function. The function accepts one parameter which is rank
  312. (integer) of child for which the function is being executed. This
  313. allows developers to distinguish different children and perform
  314. different initialization for each child. The meaning of return
  315. value is same as in the main initialization function.
  316. </simpara>
  317. </section>
  318. <section id="module_cleanup">
  319. <title>Module Clean-up</title>
  320. <simpara>
  321. A module can also export a clean-up function that will be called by
  322. the main process when the server shuts down. The function accepts
  323. no parameters and return no value.
  324. </simpara>
  325. </section>
  326. <section id="module_callbacks">
  327. <title>Module Callbacks</title>
  328. <para>
  329. TBD.
  330. </para>
  331. </section>
  332. <section id="exports_structure">
  333. <title><structname>exports</structname> Structure - Assembling the Pieces Together</title>
  334. <simpara>
  335. We have already described how a module can export functions and
  336. parameters, but we haven't yet described how to pass this
  337. information to the core. Each module must have variable named
  338. <varname>exports</varname> which is structure module_exports. The
  339. variable will be looked up by the core immediately after it loads
  340. the module. The structure contains pointers to both arrays
  341. (functions, parameters), pointers to both initialization functions,
  342. destroy function and the callbacks. So the structure contains
  343. everything the core will need.
  344. </simpara>
  345. <simpara>The structure looks like the follows:</simpara>
  346. <programlisting>
  347. struct module_exports{
  348. char* name; /* null terminated module name */
  349. cmd_export_t* cmds; /* null terminated array of the exported commands */
  350. param_export_t* params; /* null terminated array of the exported module parameters */
  351. init_function init_f; /* Initialization function */
  352. response_function response_f; /* function used for responses, returns yes or no; can be null */
  353. destroy_function destroy_f; /* function called when the module should be "destroyed", e.g: on ser exit; can be null */
  354. onbreak_function onbreak_f;
  355. child_init_function init_child_f; /* function called by all processes after the fork */
  356. };
  357. </programlisting>
  358. <itemizedlist>
  359. <title>Field description:</title>
  360. <listitem>
  361. <simpara><varname>char* name</varname></simpara>
  362. <simpara>Null terminated name of the module</simpara>
  363. </listitem>
  364. <listitem>
  365. <simpara><varname>cmd_exports* cmds</varname></simpara>
  366. <simpara>
  367. Pointer to the array of exported functions
  368. </simpara>
  369. </listitem>
  370. <listitem>
  371. <simpara><varname>param_export_t* params</varname></simpara>
  372. <simpara>
  373. Pointer to the array of exported parameters
  374. </simpara>
  375. </listitem>
  376. <listitem>
  377. <simpara><varname>init_function init_f</varname></simpara>
  378. <simpara>Pointer to the module initialization function</simpara>
  379. </listitem>
  380. <listitem>
  381. <simpara><varname>response_function response_f</varname></simpara>
  382. <simpara>Pointer to function processing responses</simpara>
  383. </listitem>
  384. <listitem>
  385. <simpara><varname>destroy_function destroy_f</varname></simpara>
  386. <simpara>Pointer to the module clean-up function</simpara>
  387. </listitem>
  388. <listitem>
  389. <simpara><varname>onbreak_function onbreak_f</varname></simpara>
  390. <simpara>TBD</simpara>
  391. </listitem>
  392. <listitem>
  393. <simpara><varname>child_init_function init_child_f</varname></simpara>
  394. <simpara>Pointer to the per-child initialization function</simpara>
  395. </listitem>
  396. </itemizedlist>
  397. </section>
  398. <section id="simple_interface">
  399. <title>Example - Simple Module Interface</title>
  400. <para>
  401. Let's suppose that we are going to write a simple module. The
  402. module will export two functions - <function>foo_req</function>
  403. which will be processing <acronym>SIP</acronym> requests and
  404. <function>foo_int</function> which is an internal function that can
  405. be called by other modules only. Both functions will take 2
  406. parameters.
  407. </para>
  408. <programlisting>
  409. /* Prototypes */
  410. int foo_req(struct sip_msg* msg, char* param1, char* param2);
  411. int foo_res(struct sip_msg* msg, char* param1, char* param2);
  412. static cmd_export cmds[] = {
  413. {"foo_req", foo_req, 2, 0, ROUTE_REQUEST},
  414. {"foo_int", foo_int, 2, 0, 0 },
  415. {0, 0, 0, 0}
  416. };
  417. </programlisting>
  418. <para>
  419. The module will also have two parameters, foo_bar of type integer
  420. and bar_foo of type string.
  421. </para>
  422. <programlisting>
  423. int foo_bar = 0;
  424. char* bar_foo = "default value";
  425. str bar_bar = STR_STATIC_INIT("default");
  426. static param_export params[] = {
  427. {"foo_bar", PARAM_INT, &amp;foo_bar},
  428. {"bar_foo", PARAM_STRING, &amp;bar_foo},
  429. {"bar_bar", PARAM_STR, &amp;ar_bar.s},
  430. {0, 0, 0}
  431. };
  432. </programlisting>
  433. <para>
  434. We will also create both initialization functions and a clean-up function:
  435. </para>
  436. <programlisting>
  437. static int mod_init(void)
  438. {
  439. printf("foo module initializing\n");
  440. }
  441. static int child_init(int rank)
  442. {
  443. printf("child nr. %d initializing\n", rank);
  444. return 0;
  445. }
  446. static void destroy(void)
  447. {
  448. printf("foo module cleaning up\n");
  449. }
  450. </programlisting>
  451. <para>
  452. And finally we put everything into the exports structure:
  453. </para>
  454. <programlisting>
  455. struct module_exports exports = {
  456. "foobar", /* Module name */
  457. cmds, /* Exported functions */
  458. params, /* Exported parameters */
  459. mod_init, /* Module initialization function */
  460. 0, /* Response function */
  461. destroy, /* Clean-up function */
  462. 0, /* On Cancel function */
  463. child_init /* Per-child init function */
  464. };
  465. </programlisting>
  466. <simpara>And that's it.</simpara>
  467. </section>
  468. <section id="module_interface_internals">
  469. <title>Module Interface Internals</title>
  470. <para>
  471. All the data structures and functions mentioned in this section can
  472. be found in files <filename>sr_module.h</filename> and
  473. <function>sr_module.c</function>.
  474. </para>
  475. <xi:include href="sr_module.xml"/>
  476. <xi:include href="module_exports.xml"/>
  477. <section id="module-loading">
  478. <title>Module Loading</title>
  479. <para>
  480. Modules are compiled and stored as shared objects. Shared
  481. objects have usually appendix ".so". Shared objects can be
  482. loaded at runtime.
  483. </para>
  484. <para>
  485. When you instruct the server to load a module using
  486. <function>loadmodule</function> command in the config file, it
  487. will call function <function>load_module</function>. The
  488. function will do the following:
  489. <itemizedlist>
  490. <listitem>
  491. <para>
  492. It will try to open specified file using
  493. <function>dlopen</function>. For example if you
  494. write loadmodule "/usr/lib/ser/modules/auth.so" in
  495. the config file, the server will try to open file
  496. "/usr/lib/ser/modules/auth.so" using
  497. <function>dlopen</function> function.
  498. </para>
  499. <para>
  500. If <function>dlopen</function> failed, the server
  501. will issue an error and abort.
  502. </para>
  503. </listitem>
  504. <listitem>
  505. <para>
  506. As the next step, list of all previously loaded
  507. modules will be searched for the same module. If
  508. such module is found, it means, that user is trying
  509. to load the same module twice. In such case an
  510. warning will be issued and server will abort.
  511. </para>
  512. </listitem>
  513. <listitem>
  514. <para>
  515. The server will try to find pointer to "exports"
  516. symbol using <function>dlsym</function> in the
  517. module. If that fails, server will issue an error
  518. and abort.
  519. </para>
  520. </listitem>
  521. <listitem>
  522. <para>
  523. And as the last step, function
  524. <function>register_module</function> will register
  525. the module with the server core and loading of the
  526. module is complete.
  527. </para>
  528. </listitem>
  529. </itemizedlist>
  530. </para>
  531. <para>
  532. Function <function>register_module</function> registers a
  533. module with the server core. By registration we mean the
  534. following set of steps (see function
  535. <function>register_module</function> in file
  536. <filename>sr_module.c</filename> for more details):
  537. <itemizedlist>
  538. <listitem>
  539. <para>
  540. The function creates and initializes new instance
  541. of <structname>sr_module</structname> structure.
  542. </para>
  543. </listitem>
  544. <listitem>
  545. <para>
  546. <structfield>path</structfield> field will be set
  547. to path of the module.
  548. </para>
  549. </listitem>
  550. <listitem>
  551. <para>
  552. <structfield>handle</structfield> field will be set
  553. to handle previously returned by
  554. <function>dlopen</function>.
  555. </para>
  556. </listitem>
  557. <listitem>
  558. <para>
  559. <structfield>exports</structfield> field will be
  560. set to pointer to module's
  561. <varname>exports</varname> structure previously
  562. obtained through <function>dlsym</function> in
  563. <function>load_module</function> function.
  564. </para>
  565. </listitem>
  566. <listitem>
  567. <para>
  568. As the last step, the newly created structure will
  569. be inserted into linked list of all loaded modules
  570. and registration is complete.
  571. </para>
  572. </listitem>
  573. </itemizedlist>
  574. </para>
  575. </section> <!-- module-loading -->
  576. <section id="module_configuration">
  577. <title>Module Configuration</title>
  578. <para>
  579. In addition to set of functions each module can export set of
  580. configuration variables. Value of a module's configuration
  581. variable can be changed in the config file using <function
  582. moreinfo="none">modparam</function> function. Module
  583. configuration will be described in this section.
  584. </para>
  585. <section id="modparam">
  586. <title>Function <function>modparam</function></title>
  587. <para>
  588. <function>modparam</function> function accepts three
  589. parameters:
  590. <itemizedlist>
  591. <listitem>
  592. <para>
  593. <emphasis>module name</emphasis> - Name of
  594. module as exported in
  595. <structfield>name</structfield> field of
  596. <varname>exports</varname> global variable.
  597. </para>
  598. </listitem>
  599. <listitem>
  600. <para>
  601. <emphasis>variable name</emphasis> - Name of
  602. variable to be set - it must be one of names
  603. specified in
  604. <structfield>param_names</structfield> field of
  605. <varname>exports</varname> variable of the
  606. module.
  607. </para>
  608. </listitem>
  609. <listitem>
  610. <para>
  611. <emphasis>value</emphasis> - New value of the
  612. variable. There are two types of variables:
  613. string and integer. If the last parameter
  614. (value) of <function>modparam</function>
  615. function is enclosed in quotes, it is string
  616. parameter and server will try to find the
  617. corresponding variable among string parameters
  618. only.
  619. </para>
  620. <para>
  621. Otherwise it is integer parameter and server
  622. will try to find corresponding variable among
  623. integer parameters only.
  624. </para>
  625. </listitem>
  626. </itemizedlist>
  627. </para>
  628. </section> <!-- modparam -->
  629. <section id="set_mod_param">
  630. <title>Function <function>set_mod_param</function></title>
  631. <para>
  632. When the server finds <function>modparam</function>
  633. function in the config file, it will call
  634. <function>set_mod_param</function> function. The function
  635. can be found in <filename>modparam.c</filename> file. The
  636. function will do the following:
  637. </para>
  638. <itemizedlist>
  639. <listitem>
  640. <para>
  641. It tries to find corresponding variable using
  642. <function>find_param_export</function> function.
  643. </para>
  644. </listitem>
  645. <listitem>
  646. <para>
  647. If it is string parameter, a new copy of the string
  648. will be obtained using <function>strdup</function>
  649. function and pointer to the copy will be stored in
  650. the variable.
  651. </para>
  652. <para>
  653. If it is integer parameter, its value will be
  654. simply copied in the variable.
  655. </para>
  656. </listitem>
  657. </itemizedlist>
  658. </section> <!-- set_mod_param -->
  659. <section id="find_param_export">
  660. <title>Function <function>find_param_export</function></title>
  661. <para>
  662. This function accepts 3 parameters:
  663. <itemizedlist>
  664. <listitem>
  665. <para>
  666. <emphasis>module</emphasis> - Name of module.
  667. </para>
  668. </listitem>
  669. <listitem>
  670. <para>
  671. <emphasis>parameter</emphasis> - Name of parameter to be found.
  672. </para>
  673. </listitem>
  674. <listitem>
  675. <para>
  676. <emphasis>type</emphasis> - Type of the parameter.
  677. </para>
  678. </listitem>
  679. </itemizedlist>
  680. </para>
  681. <para>
  682. The function will search list of all modules until it finds
  683. module with given name. Then it will search through all
  684. module's exported parameters until it finds parameter with
  685. corresponding name and type. If such parameter was found,
  686. pointer to variable holding the parameter's value will be
  687. returned. If the function failed to find either module or
  688. parameter with given name and type then zero will be
  689. returned.
  690. </para>
  691. </section> <!-- find_param_export -->
  692. </section> <!-- module_config -->
  693. <section id="lookingup_exported_function">
  694. <title>Looking Up an Exported Function</title>
  695. <para>
  696. If you need to find exported function with given name and
  697. number of parameters, <function>find_export</function> function
  698. is what you need. The function is defined in
  699. <filename>sr_module.c</filename> file. The function accepts
  700. two parameters:
  701. <itemizedlist>
  702. <listitem>
  703. <para>
  704. <emphasis>name</emphasis> - Name of function to be
  705. found.
  706. </para>
  707. </listitem>
  708. <listitem>
  709. <para>
  710. <emphasis>param_no</emphasis> - Number of
  711. parameters of the function.
  712. </para>
  713. </listitem>
  714. </itemizedlist>
  715. </para>
  716. <para>
  717. The function will search through list of all loaded modules and
  718. in each module through array of all exported functions until it
  719. finds function with given name and number of parameters. If
  720. such exported function was found,
  721. <function>find_exported</function> will return pointer to the
  722. function, otherwise zero will be returned.
  723. </para>
  724. </section> <!-- lookingup_exported_function -->
  725. <section id="additional_functions">
  726. <title>Additional Functions</title>
  727. <para>
  728. There are several additional functions defined in file
  729. <filename>sr_module.c</filename>. There functions are mostly
  730. internal and shouldn't be used directly by user. We will
  731. shortly describe them here.
  732. </para>
  733. <itemizedlist>
  734. <listitem>
  735. <para>
  736. <function>register_builtin_modules</function> - Some
  737. modules might be linked statically with main
  738. executable, this is handy for debugging. This function
  739. will register all such modules upon server startup.
  740. </para>
  741. </listitem>
  742. <listitem>
  743. <para>
  744. <function>init_child</function> - This function will
  745. call child-initialization function of all loaded
  746. modules. The function will be called by the server core
  747. immediately after the fork.
  748. </para>
  749. </listitem>
  750. <listitem>
  751. <para>
  752. <function>find_module</function> - The function accepts
  753. pointer to an exported function and number of
  754. parameters as parameters and returns pointer to
  755. corresponding module that exported the function.
  756. </para>
  757. </listitem>
  758. <listitem>
  759. <para>
  760. <function>destroy_modules</function> - The function
  761. will call destroy function of all loaded modules. This
  762. function will be called by the server core upon shut
  763. down.
  764. </para>
  765. </listitem>
  766. <listitem>
  767. <para>
  768. <function>init_modules</function> - The function will
  769. call initialization function of all loaded modules. The
  770. function will be called by the server before the fork.
  771. </para>
  772. </listitem>
  773. </itemizedlist>
  774. </section>
  775. </section>
  776. </section>