README 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. 1. CPL Module
  2. Bogdan-Andrei Iancu
  3. FhG FOKUS
  4. Copyright © 2003 FhG FOKUS
  5. __________________________________________________________________
  6. 1.1. Overview
  7. 1.2. Dependencies
  8. 1.2.1. SER Modules
  9. 1.2.2. External Libraries or Applications
  10. 1.3. Parameters
  11. 1.3.1. cpl_db (string)
  12. 1.3.2. cpl_table (string)
  13. 1.3.3. cpl_dtd_file (string)
  14. 1.3.4. log_dir (string)
  15. 1.3.5. proxy_recurse (int)
  16. 1.3.6. proxy_route (int)
  17. 1.3.7. nat_flag (int)
  18. 1.3.8. lookup_domain (int)
  19. 1.4. Functions
  20. 1.4.1. cpl_run_script(type,mode)
  21. 1.4.2. cpl_process_register()
  22. 1.1. Overview
  23. cpl-c modules implements a CPL (Call Processing Language) interpreter.
  24. Support for uploading/downloading/removing scripts via SIP REGISTER
  25. method is implemented.
  26. 1.2. Dependencies
  27. 1.2.1. SER Modules
  28. The following modules must be loaded before this module:
  29. * tm. Transaction Manager, used for proxying/forking requests.
  30. * sl. StateLess module - used for sending stateless reply when
  31. responding to REGISTER request or for sending back error responses.
  32. * usrloc. User location module - used for implementing
  33. lookup("registration") (adding into location set of the users'
  34. contact)
  35. 1.2.2. External Libraries or Applications
  36. The following libraries or applications must be installed before
  37. running SER with this module loaded:
  38. * libxml2. This library contains an engine for XML parsing, DTD
  39. validation and DOM manipulation.
  40. 1.3. Parameters
  41. 1.3.1. cpl_db (string)
  42. A SQL URL have to be given to the module for knowing where the database
  43. containing the table with CPL scripts is locates. If required a user
  44. name and password can be specified for allowing the module to connect
  45. to the database server.
  46. Warning
  47. This parameter is mandatory.
  48. Example 1. Set cpl_db parameter
  49. ...
  50. modparam("cpl_c","cpl_db","mysql://user:passwd@host/database")
  51. ...
  52. 1.3.2. cpl_table (string)
  53. Indicates the name of the table that store the CPL scripts. This table
  54. must be locate into the database specified by "cpl_db" parameter. For
  55. more about the format of the CPL table please see
  56. modules/cpl-c/init.mysql.
  57. Warning
  58. This parameter is mandatory.
  59. Example 2. Set cpl_table parameter
  60. ...
  61. modparam("cpl_c","cpl_table","cpltable")
  62. ...
  63. 1.3.3. cpl_dtd_file (string)
  64. Points to the DTD file describing the CPL grammar. The file name may
  65. include also the path to the file. This path can be absolute or
  66. relative (be careful the path will be relative to the starting
  67. directory of SER).
  68. Warning
  69. This parameter is mandatory.
  70. Example 3. Set cpl_dtd_file parameter
  71. ...
  72. modparam("cpl_c","cpl_dtd_file","/etc/ser/cpl-06.dtd")
  73. ...
  74. 1.3.4. log_dir (string)
  75. Points to a directory where should be created all the log file
  76. generated by the LOG CPL node. A log file per user will be created (on
  77. demand) having the name username.log.
  78. Note
  79. If this parameter is absent, the logging will be disabled without
  80. generating error on execution.
  81. Example 4. Set log_dir parameter
  82. ...
  83. modparam("cpl_c","log_dir","/var/log/ser/cpl")
  84. ...
  85. 1.3.5. proxy_recurse (int)
  86. Tells for how many time is allow to have recurse for PROXY CPL node If
  87. it has value 2, when doing proxy, only twice the proxy action will be
  88. re-triggered by a redirect response; the third time, the proxy
  89. execution will end by going on REDIRECTION branch. The recurse feature
  90. can be disable by setting this parameter to 0
  91. Default value of this parameter is 0.
  92. Example 5. Set proxy_recurse parameter
  93. ...
  94. modparam("cpl_c","proxy_recurse",2)
  95. ...
  96. 1.3.6. proxy_route (int)
  97. Before doing proxy (forward), a script route can be executed. All
  98. modifications made by that route will be reflected only for the current
  99. branch.
  100. Default value of this parameter is 0 (none).
  101. Example 6. Set proxy_route parameter
  102. ...
  103. modparam("cpl_c","proxy_route",1)
  104. ...
  105. 1.3.7. nat_flag (int)
  106. Sets the flag used for marking calls via NAT. Used by lookup tag when
  107. retrieving a contact behind a NAT (this flag will be set).
  108. Default value of this parameter is 6.
  109. Example 7. Set nat_flag parameter
  110. ...
  111. modparam("cpl_c","nat_flag",4)
  112. ...
  113. 1.3.8. lookup_domain (int)
  114. Tells if the lookup tag should use or not the domain part when doing
  115. user location search. Set it to a non zero value to force also domain
  116. matching.
  117. Default value of this parameter is 0.
  118. Example 8. Set lookup_domain parameter
  119. ...
  120. modparam("cpl_c","lookup_domain",1)
  121. ...
  122. 1.4. Functions
  123. 1.4.1. cpl_run_script(type,mode)
  124. Starts the execution of the CPL script. The user name is fetched from
  125. new_uri or requested uri or from To header -in this order- (for
  126. incoming execution) or from FROM header (for outgoing execution).
  127. Regarding the stateful/stateless message processing, the function is
  128. very flexible, being able to run in different modes (see below
  129. the"mode" parameter). Normally this function will end script execution.
  130. There is no guaranty that the CPL script interpretation ended when ser
  131. script ended also (for the same INVITE ;-)) - this can happen when the
  132. CPL script does a PROXY and the script interpretation pause after
  133. proxying and it will be resume when some reply is received (this can
  134. happen in a different process of SER). If the function returns to
  135. script, the SIP server should continue with the normal behavior as if
  136. no script existed. When some error is returned, the function itself
  137. haven't sent any SIP error reply (this can be done from script).
  138. Meaning of the parameters is as follows:
  139. * type - which part of the script should be run; set it to "incoming"
  140. for having the incoming part of script executed (when an INVITE is
  141. received) or to "outgoing" for running the outgoing part of script
  142. (when a user is generating an INVITE - call).
  143. * mode - sets the interpreter mode as stateless/stateful behavior.
  144. The following modes are accepted:
  145. + IS_STATELESS - the current INVITE has no transaction created
  146. yet. All replies (redirection or deny) will be done is a
  147. stateless way. The execution will switch to stateful only when
  148. proxy is done. So, if the function returns, will be in
  149. stateless mode.
  150. + IS_STATEFUL - the current INVITE has already a transaction
  151. associated. All signaling operations (replies or proxy) will
  152. be done in stateful way.So, if the function returns, will be
  153. in stateful mode.
  154. + FORCE_STATEFUL - the current INVITE has no transaction created
  155. yet. All signaling operations will be done is a stateful way
  156. (on signaling, the transaction will be created from within the
  157. interpreter). So, if the function returns, will be in
  158. stateless mode.
  159. Note
  160. is_stateful is very difficult to manage from the routing script
  161. (script processing can continue in stateful mode); is_stateless is
  162. the fastest and consumes less resources (transaction is created
  163. only if proxying is done), but there is only a minimal protection
  164. against retransmissions (since replies are send statelessly);
  165. force_stateful is a good compromise - all signaling is done
  166. stateful (retransmission protection) and in the same time, if
  167. returning to script, it will be in stateless mode (easy to continue
  168. the routing script execution)
  169. Example 9. cpl_run_script usage
  170. ...
  171. cpl_run_script("incoming","force_stateful");
  172. ...
  173. 1.4.2. cpl_process_register()
  174. This function MUST be called only for REGISTER requests. It checks if
  175. the current REGISTER request is related or not with CPL script
  176. upload/download/ remove. If it is, all the needed operation will be
  177. done. For checking if the REGISTER is CPL related, the function looks
  178. fist to "Content-Type" header. If it exists and has a the mime type set
  179. to "application/cpl+xml" means this is a CPL script upload/remove
  180. operation. The distinction between to case is made by looking at
  181. "Content-Disposition" header; id its value is "script;action=store",
  182. means it's an upload; if it's "script;action=remove", means it's a
  183. remove operation; other values are considered to be errors. If no
  184. "Content-Type" header is present, the function looks to "Accept" header
  185. and if it contains the "*" or "application/cpl-xml" the request it will
  186. be consider one for downloading CPL scripts. The functions returns to
  187. script only if the REGISTER is not related to CPL. In other case, the
  188. function will send by itself the necessary replies (stateless - using
  189. sl), including for errors.