cpl-c_admin.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  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>cpl-c modules implements a CPL (Call Processing Language)
  14. interpreter. Support for uploading/downloading/removing scripts via
  15. SIP REGISTER method is present.
  16. </para>
  17. </section>
  18. <section>
  19. <title>Dependencies</title>
  20. <section>
  21. <title>&kamailio; Modules</title>
  22. <para>
  23. The following modules must be loaded before this module:
  24. <itemizedlist>
  25. <listitem>
  26. <para>
  27. <emphasis>any DB module- a DB module for interfacing the DB
  28. operations (modules like mysql, postgres, dbtext, etc)
  29. </emphasis>
  30. </para>
  31. </listitem>
  32. <listitem>
  33. <para>
  34. <emphasis>TM (Transaction) module- used for proxying/forking
  35. requests
  36. </emphasis>
  37. </para>
  38. </listitem>
  39. <listitem>
  40. <para>
  41. <emphasis>SL (StateLess) module - used for sending stateless
  42. reply when responding to REGISTER request or for sending back
  43. error responses
  44. </emphasis>
  45. </para>
  46. </listitem>
  47. <listitem>
  48. <para>
  49. <emphasis>USRLOC (User Location) module - used for implementing
  50. lookup("registration") tag (adding into location set of the
  51. users' contact)
  52. </emphasis>
  53. </para>
  54. </listitem>
  55. </itemizedlist>
  56. </para>
  57. </section>
  58. <section>
  59. <title>External Libraries or Applications</title>
  60. <para>
  61. The following libraries or applications must be installed
  62. before running &kamailio; with this module loaded:
  63. <itemizedlist>
  64. <listitem>
  65. <para>
  66. <emphasis>libxml2 and libxml2-devel - on some SO, these to
  67. packages are merged into libxml2. This library contains an
  68. engine for XML parsing, DTD validation and
  69. DOM manipulation.
  70. </emphasis>
  71. </para>
  72. </listitem>
  73. </itemizedlist>
  74. </para>
  75. </section>
  76. </section>
  77. <section>
  78. <title>Parameters</title>
  79. <section>
  80. <title><varname>db_url</varname> (string)</title>
  81. <para>
  82. A SQL URL have to be given to the module for knowing where the
  83. database containing the table with CPL scripts is locates. If
  84. required a user name and password can be specified for allowing
  85. the module to connect to the database server.
  86. </para>
  87. <para>
  88. <emphasis>
  89. Default value is <quote>&defaultdb;</quote>.
  90. </emphasis>
  91. </para>
  92. <example>
  93. <title>Set <varname>db_url</varname> parameter</title>
  94. <programlisting format="linespecific">
  95. ...
  96. modparam("cpl-c","db_url","&exampledb;")
  97. ...
  98. </programlisting>
  99. </example>
  100. </section>
  101. <section>
  102. <title><varname>db_table</varname> (string)</title>
  103. <para>
  104. Indicates the name of the table that store the CPL scripts.
  105. This table must be locate into the database specified by
  106. <quote>db_url</quote> parameter. For more about the format of the CPL
  107. table please see the modules/cpl-c/init.mysql file.
  108. </para>
  109. <para>
  110. <emphasis>
  111. Default value is <quote>cpl</quote>.
  112. </emphasis>
  113. </para>
  114. <example>
  115. <title>Set <varname>db_table</varname> parameter</title>
  116. <programlisting format="linespecific">
  117. ...
  118. modparam("cpl-c","cpl_table","cpl")
  119. ...
  120. </programlisting>
  121. </example>
  122. </section>
  123. <section>
  124. <title><varname>username_column</varname> (string)</title>
  125. <para>
  126. Indicates the name of the column used for storing the username.
  127. </para>
  128. <para>
  129. <emphasis>
  130. Default value is <quote>username</quote>.
  131. </emphasis>
  132. </para>
  133. <example>
  134. <title>Set <varname>username_column</varname> parameter</title>
  135. <programlisting format="linespecific">
  136. ...
  137. modparam("cpl-c","username_column","username")
  138. ...
  139. </programlisting>
  140. </example>
  141. </section>
  142. <section>
  143. <title><varname>domain_column</varname> (string)</title>
  144. <para>
  145. Indicates the name of the column used for storing the domain.
  146. </para>
  147. <para>
  148. <emphasis>
  149. Default value is <quote>domain</quote>.
  150. </emphasis>
  151. </para>
  152. <example>
  153. <title>Set <varname>domain_column</varname> parameter</title>
  154. <programlisting format="linespecific">
  155. ...
  156. modparam("cpl-c","domain_column","domain")
  157. ...
  158. </programlisting>
  159. </example>
  160. </section>
  161. <section>
  162. <title><varname>cpl_xml_column</varname> (string)</title>
  163. <para>
  164. Indicates the name of the column used for storing the
  165. the XML version of the cpl script.
  166. </para>
  167. <para>
  168. <emphasis>
  169. Default value is <quote>cpl_xml</quote>.
  170. </emphasis>
  171. </para>
  172. <example>
  173. <title>Set <varname>cpl_xml_column</varname> parameter</title>
  174. <programlisting format="linespecific">
  175. ...
  176. modparam("cpl-c","cpl_xml_column","cpl_xml")
  177. ...
  178. </programlisting>
  179. </example>
  180. </section>
  181. <section>
  182. <title><varname>cpl_bin_column</varname> (string)</title>
  183. <para>
  184. Indicates the name of the column used for storing the
  185. the binary version of the cpl script (compiled version).
  186. </para>
  187. <para>
  188. <emphasis>
  189. Default value is <quote>cpl_bin</quote>.
  190. </emphasis>
  191. </para>
  192. <example>
  193. <title>Set <varname>cpl_bin_column</varname> parameter</title>
  194. <programlisting format="linespecific">
  195. ...
  196. modparam("cpl-c","cpl_bin_column","cpl_bin")
  197. ...
  198. </programlisting>
  199. </example>
  200. </section>
  201. <section>
  202. <title><varname>cpl_dtd_file</varname> (string)</title>
  203. <para>
  204. Points to the DTD file describing the CPL grammar. The file
  205. name may include also the path to the file. This path can be
  206. absolute or relative (be careful the path will be relative
  207. to the starting directory of &kamailio;).
  208. </para>
  209. <para>
  210. <emphasis>
  211. This parameter is MANDATORY!
  212. </emphasis>
  213. </para>
  214. <example>
  215. <title>Set <varname>cpl_dtd_file</varname> parameter</title>
  216. <programlisting format="linespecific">
  217. ...
  218. modparam("cpl-c","cpl_dtd_file","/etc/kamailio/cpl-06.dtd")
  219. ...
  220. </programlisting>
  221. </example>
  222. </section>
  223. <section>
  224. <title><varname>log_dir</varname> (string)</title>
  225. <para>
  226. Points to a directory where should be created all the log file
  227. generated by the LOG CPL node. A log file per user will be
  228. created (on demand) having the name username.log.
  229. </para>
  230. <para>
  231. <emphasis>
  232. If this parameter is absent, the logging will be disabled
  233. without generating error on execution.
  234. </emphasis>
  235. </para>
  236. <example>
  237. <title>Set <varname>log_dir</varname> parameter</title>
  238. <programlisting format="linespecific">
  239. ...
  240. modparam("cpl-c","log_dir","/var/log/kamailio/cpl")
  241. ...
  242. </programlisting>
  243. </example>
  244. </section>
  245. <section>
  246. <title><varname>proxy_recurse</varname> (int)</title>
  247. <para>
  248. Tells for how many time is allow to have recurse for PROXY CPL
  249. node If it has value 2, when doing proxy, only twice the proxy
  250. action will be re-triggered by a redirect response; the third
  251. time, the proxy execution will end by going on REDIRECTION
  252. branch. The recurse feature can be disable by setting this
  253. parameter to 0
  254. </para>
  255. <para>
  256. <emphasis>
  257. Default value of this parameter is 0.
  258. </emphasis>
  259. </para>
  260. <example>
  261. <title>Set <varname>proxy_recurse</varname> parameter</title>
  262. <programlisting format="linespecific">
  263. ...
  264. modparam("cpl-c","proxy_recurse",2)
  265. ...
  266. </programlisting>
  267. </example>
  268. </section>
  269. <section>
  270. <title><varname>proxy_route</varname> (int)</title>
  271. <para>
  272. Before doing proxy (forward), a script route can be executed.
  273. All modifications made by that route will be reflected only for
  274. the current branch.
  275. </para>
  276. <para>
  277. <emphasis>
  278. Default value of this parameter is 0 (none).
  279. </emphasis>
  280. </para>
  281. <example>
  282. <title>Set <varname>proxy_route</varname> parameter</title>
  283. <programlisting format="linespecific">
  284. ...
  285. modparam("cpl-c","proxy_route",1)
  286. ...
  287. </programlisting>
  288. </example>
  289. </section>
  290. <section>
  291. <title><varname>case_sensitive</varname> (int)</title>
  292. <para>
  293. Tells if the username matching should be perform case
  294. sensitive or not. Set it to a non zero value to force
  295. a case sensitive handling of usernames.
  296. </para>
  297. <para>
  298. <emphasis>
  299. Default value of this parameter is 0.
  300. </emphasis>
  301. </para>
  302. <example>
  303. <title>Set <varname>case_sensitive</varname> parameter</title>
  304. <programlisting format="linespecific">
  305. ...
  306. modparam("cpl-c","case_sensitive",1)
  307. ...
  308. </programlisting>
  309. </example>
  310. </section>
  311. <section>
  312. <title><varname>realm_prefix</varname> (string)</title>
  313. <para>
  314. Defines a prefix for the domain part which should be ignored
  315. in handling users and scripts.
  316. </para>
  317. <para>
  318. <emphasis>
  319. Default value of this parameter is empty string.
  320. </emphasis>
  321. </para>
  322. <example>
  323. <title>Set <varname>realm_prefix</varname> parameter</title>
  324. <programlisting format="linespecific">
  325. ...
  326. modparam("cpl-c","realm_prefix","sip.")
  327. ...
  328. </programlisting>
  329. </example>
  330. </section>
  331. <section>
  332. <title><varname>timer_avp</varname> (string)</title>
  333. <para>
  334. Full specification (ID, NAME, ALIAS) of the AVP to be used to
  335. set the value of the Final Response INVITE timeout - it's
  336. used by the TIMEOUT attribute from the PROXY tag.
  337. </para>
  338. <para>
  339. NOTE: take care and syncronize this value with the similar
  340. parameters in TM module.
  341. </para>
  342. <para>
  343. <emphasis>
  344. Default value of this parameter is NULL.
  345. </emphasis>
  346. </para>
  347. <example>
  348. <title>Set <varname>timer_avp</varname> parameter</title>
  349. <programlisting format="linespecific">
  350. ...
  351. modparam("cpl-c","timer_avp","$avp(i:14)")
  352. ...
  353. </programlisting>
  354. </example>
  355. </section>
  356. <section>
  357. <title><varname>lookup_domain</varname> (string)</title>
  358. <para>
  359. Used by lookup tag to indicate where to perform user location.
  360. Basically this is the name of the usrloc domain (table) where
  361. the user registrations are kept.
  362. </para>
  363. <para>
  364. If set to empty string, the lookup node will be disabled - no
  365. user location will be performed.
  366. </para>
  367. <para>
  368. <emphasis>
  369. Default value of this parameter is NULL.
  370. </emphasis>
  371. </para>
  372. <example>
  373. <title>Set <varname>lookup_domain</varname> parameter</title>
  374. <programlisting format="linespecific">
  375. ...
  376. modparam("cpl-c","lookup_domain","location")
  377. ...
  378. </programlisting>
  379. </example>
  380. </section>
  381. <section>
  382. <title><varname>lookup_append_branches</varname> (int)</title>
  383. <para>
  384. Tells if the lookup tag should append branches (to do parallel
  385. forking) if user_location lookup returns more than one contact.
  386. Set it to a non zero value to enable parallel forking for
  387. location lookup tag.
  388. </para>
  389. <para>
  390. <emphasis>
  391. Default value of this parameter is 0.
  392. </emphasis>
  393. </para>
  394. <example>
  395. <title>Set <varname>lookup_append_branches</varname>
  396. parameter</title>
  397. <programlisting format="linespecific">
  398. ...
  399. modparam("cpl-c","lookup_append_branches",1)
  400. ...
  401. </programlisting>
  402. </example>
  403. </section>
  404. <section>
  405. <title><varname>use_domain</varname> (integer)</title>
  406. <para>
  407. Indicates if the domain part of the URI should be used in
  408. user identification (otherwise only username part will be
  409. used).
  410. </para>
  411. <para>
  412. <emphasis>
  413. Default value is <quote>0 (disabled)</quote>.
  414. </emphasis>
  415. </para>
  416. <example>
  417. <title>Set <varname>use_domain</varname> parameter</title>
  418. <programlisting format="linespecific">
  419. ...
  420. modparam("cpl-c","use_domain",1)
  421. ...
  422. </programlisting>
  423. </example>
  424. </section>
  425. </section>
  426. <section>
  427. <title>Functions</title>
  428. <section>
  429. <title>
  430. <function moreinfo="none">cpl_run_script(type,mode, [uri])</function>
  431. </title>
  432. <para>
  433. Starts the execution of the CPL script. The user name is
  434. fetched from new_uri or requested uri or from To header -in
  435. this order- (for incoming execution) or from FROM header (for
  436. outgoing execution).
  437. Regarding the stateful/stateless message processing, the
  438. function is very flexible, being able to run in different
  439. modes (see below the"mode" parameter).
  440. Normally this function will end script execution. There is no
  441. guaranty that the CPL script interpretation ended when &kamailio;
  442. script ended also (for the same INVITE ;-)) - this can happen
  443. when the CPL script does a PROXY and the script interpretation
  444. pause after proxying and it will be resume when some reply is
  445. received (this can happen in a different process of SER).
  446. If the function returns to script, the SIP server should
  447. continue with the normal behavior as if no script existed.
  448. When some error is returned, the function itself haven't sent
  449. any SIP error reply (this can be done from script).
  450. </para>
  451. <para>Meaning of the parameters is as follows:</para>
  452. <itemizedlist>
  453. <listitem>
  454. <para><emphasis>type</emphasis> - which part of the script
  455. should be run; set it to "incoming" for having the incoming
  456. part of script executed (when an INVITE is received) or to
  457. "outgoing" for running the outgoing part of script (when a
  458. user is generating an INVITE - call).
  459. </para>
  460. </listitem>
  461. <listitem>
  462. <para><emphasis>mode</emphasis> - sets the interpreter mode as
  463. stateless/stateful behavior. The following modes are accepted:
  464. </para>
  465. <itemizedlist>
  466. <listitem>
  467. <para>
  468. <emphasis>IS_STATELESS</emphasis> - the current INVITE has
  469. no transaction created yet. All replies (redirection or
  470. deny) will be done is a stateless way. The execution will
  471. switch to stateful only when proxy is done. So, if the
  472. function returns, will be in stateless mode.
  473. </para>
  474. </listitem>
  475. <listitem>
  476. <para>
  477. <emphasis>IS_STATEFUL</emphasis> - the current INVITE has
  478. already a transaction associated. All signaling operations
  479. (replies or proxy) will be done in stateful way.So, if
  480. the function returns, will be in stateful mode.
  481. </para>
  482. </listitem>
  483. <listitem>
  484. <para>
  485. <emphasis>FORCE_STATEFUL</emphasis> - the current INVITE
  486. has no transaction created yet. All signaling operations
  487. will be done is a stateful way (on signaling, the
  488. transaction will be created from within the interpreter).
  489. So, if the function returns, will be in stateless mode.
  490. </para>
  491. </listitem>
  492. </itemizedlist>
  493. <para>
  494. <emphasis>HINT</emphasis>: is_stateful is very
  495. difficult to manage from the routing script (script processing
  496. can continue in stateful mode); is_stateless is the fastest and
  497. less resources consumer (transaction is created only if
  498. proxying is done), but there is minimal protection against
  499. retransmissions (since replies are send stateless);
  500. force_stateful is a good compromise - all signaling is done
  501. stateful (retransmission protection) and in the same time, if
  502. returning to script, it will be in stateless mode (easy to
  503. continue the routing script execution)
  504. </para>
  505. </listitem>
  506. <listitem>
  507. <para><emphasis>uri</emphasis> - optional - provide the SIP URI
  508. to be used for loading the CPL script, instead of taking it from
  509. R-URI or headers.
  510. </para>
  511. </listitem>
  512. </itemizedlist>
  513. <para>
  514. This function can be used from REQUEST_ROUTE.
  515. </para>
  516. <example>
  517. <title><function>cpl_run_script</function> usage</title>
  518. <programlisting format="linespecific">
  519. ...
  520. cpl_run_script("incoming","force_stateful");
  521. ...
  522. </programlisting>
  523. </example>
  524. </section>
  525. <section>
  526. <title>
  527. <function moreinfo="none">cpl_process_register()</function>
  528. </title>
  529. <para>
  530. This function MUST be called only for REGISTER requests. It
  531. checks if the current REGISTER request is related or not with
  532. CPL script upload/download/ remove. If it is, all the needed
  533. operation will be done. For checking if the REGISTER is CPL
  534. related, the function looks fist to "Content-Type" header. If
  535. it exists and has a the mime type set to "application/cpl+xml"
  536. means this is a CPL script upload/remove operation. The
  537. distinction between to case is made by looking at
  538. "Content-Disposition" header; id its value is
  539. "script;action=store", means it's an upload; if it's
  540. "script;action=remove", means it's a remove operation; other
  541. values are considered to be errors. If no "Content-Type"
  542. header is present, the function looks to "Accept" header and
  543. if it contains the "*" or "application/cpl-xml" the request
  544. it will be consider one for downloading CPL scripts.
  545. The functions returns to script only if the REGISTER is
  546. not related to CPL. In other case, the function will send by
  547. itself the necessary replies (stateless - using sl), including
  548. for errors.
  549. </para>
  550. <para>
  551. This function can be used from REQUEST_ROUTE.
  552. </para>
  553. <example>
  554. <title><function>cpl_process_register</function> usage</title>
  555. <programlisting format="linespecific">
  556. ...
  557. if (method=="REGISTER") {
  558. cpl_process_register();
  559. }
  560. ...
  561. </programlisting>
  562. </example>
  563. </section>
  564. <section>
  565. <title>
  566. <function moreinfo="none">cpl_process_register_norpl()
  567. </function>
  568. </title>
  569. <para>
  570. Same as <quote>cpl_process_register</quote> without
  571. internally generating the reply. All information (script) is
  572. appended to the reply but without sending it out.
  573. </para>
  574. <para>
  575. Main purpose of this function is to allow integration
  576. between CPL and UserLocation services via same REGISTER
  577. messages.
  578. </para>
  579. <para>
  580. This function can be used from REQUEST_ROUTE.
  581. </para>
  582. <example>
  583. <title><function>cpl_process_register_norpl</function> usage
  584. </title>
  585. <programlisting format="linespecific">
  586. ...
  587. if (method=="REGISTER") {
  588. cpl_process_register();
  589. # continue with usrloc part
  590. save("location");
  591. }
  592. ...
  593. </programlisting>
  594. </example>
  595. </section>
  596. </section>
  597. <section>
  598. <title>MI Commands</title>
  599. <section>
  600. <title>
  601. <function moreinfo="none">LOAD_CPL</function>
  602. </title>
  603. <para>
  604. For the given user, loads the XML cpl file, compiles it into
  605. binary format and stores both format into database.
  606. </para>
  607. <para>
  608. Name: <emphasis>LOAD_CPL</emphasis>
  609. </para>
  610. <para>Parameters:</para>
  611. <itemizedlist>
  612. <listitem><para>username : name of the user</para></listitem>
  613. <listitem><para>cpl_filename: file name </para></listitem>
  614. </itemizedlist>
  615. <para>
  616. MI FIFO Command format:
  617. </para>
  618. <programlisting format="linespecific">
  619. :LOAD_CPL:_reply_fifo_file_
  620. username
  621. cpl_filename
  622. _empty_line_
  623. </programlisting>
  624. </section>
  625. <section>
  626. <title>
  627. <function moreinfo="none">REMOVE_CPL</function>
  628. </title>
  629. <para>
  630. For the given user, removes the entire database record
  631. (XML cpl and binary cpl); user with empty cpl scripts are not
  632. accepted.
  633. </para>
  634. <para>
  635. Name: <emphasis>REMOVE_CPL</emphasis>
  636. </para>
  637. <para>Parameters:</para>
  638. <itemizedlist>
  639. <listitem><para>username : name of the user</para></listitem>
  640. </itemizedlist>
  641. <para>
  642. MI FIFO Command format:
  643. </para>
  644. <programlisting format="linespecific">
  645. :REMOVE_CPL:_reply_fifo_file_
  646. username
  647. _empty_line_
  648. </programlisting>
  649. </section>
  650. <section>
  651. <title>
  652. <function moreinfo="none">GET_CPL</function>
  653. </title>
  654. <para>
  655. For the given user, returns the CPL script in XML format.
  656. </para>
  657. <para>
  658. Name: <emphasis>GET_CPL</emphasis>
  659. </para>
  660. <para>Parameters:</para>
  661. <itemizedlist>
  662. <listitem><para>username : name of the user</para></listitem>
  663. </itemizedlist>
  664. <para>
  665. MI FIFO Command format:
  666. </para>
  667. <programlisting format="linespecific">
  668. :GET_CPL:_reply_fifo_file_
  669. username
  670. _empty_line_
  671. </programlisting>
  672. </section>
  673. </section>
  674. <section>
  675. <title>Installation and Running</title>
  676. <section>
  677. <title>Database setup</title>
  678. <para>
  679. Before running &kamailio; with cpl-c, you have to setup the database
  680. table where the module will store the CPL scripts. For that, if
  681. the table was not created by the installation script or you choose
  682. to install everything by yourself you can use the cpc-create.sql
  683. <acronym>SQL</acronym> script in the database directories in the
  684. kamailio/scripts folder as template.
  685. Database and table name can be set with module parameters so they
  686. can be changed, but the name of the columns must be as they are
  687. in the <acronym>SQL</acronym> script.
  688. You can also find the complete database documentation on the
  689. project webpage, &kamailiodbdocslink;.
  690. </para>
  691. </section>
  692. </section>
  693. </chapter>