2
0

README 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697
  1. perl Module
  2. Bastian Friedrich
  3. Collax GmbH
  4. Edited by
  5. Bastian Friedrich
  6. Copyright © 2007 Collax GmbH
  7. __________________________________________________________________
  8. Table of Contents
  9. 1. Admin Guide
  10. 1. Overview
  11. 2. Installing the module
  12. 3. Using the module
  13. 4. Dependencies
  14. 4.1. Kamailio Modules
  15. 4.2. External Libraries or Applications
  16. 5. Parameters
  17. 5.1. filename (string)
  18. 5.2. modpath (string)
  19. 5.3. reset_cycles (int)
  20. 5.4. perl_destroy_func (string)
  21. 6. Functions
  22. 6.1. perl_exec_simple(func, [param])
  23. 6.2. perl_exec(func, [param])
  24. 7. RPC Commands
  25. 7.1. app_perl.set_reset_cycles
  26. 7.2. app_perl.get_reset_cycles
  27. 2. Kamailio Perl API
  28. 1. Kamailio
  29. 1.1. log(level,message)
  30. 2. Kamailio::Message
  31. 2.1. getType()
  32. 2.2. getStatus()
  33. 2.3. getReason()
  34. 2.4. getVersion()
  35. 2.5. getRURI()
  36. 2.6. getMethod()
  37. 2.7. getFullHeader()
  38. 2.8. getBody()
  39. 2.9. getMessage()
  40. 2.10. getHeader(name)
  41. 2.11. getHeaderNames()
  42. 2.12. moduleFunction(func,string1,string2)
  43. 2.13. log(level,message) (deprecated type)
  44. 2.14. rewrite_ruri(newruri)
  45. 2.15. setFlag(flag)
  46. 2.16. resetFlag(flag)
  47. 2.17. isFlagSet(flag)
  48. 2.18. pseudoVar(string)
  49. 2.19. append_branch(branch,qval)
  50. 2.20. getParsedRURI()
  51. 3. Kamailio::URI
  52. 3.1. user()
  53. 3.2. host()
  54. 3.3. passwd()
  55. 3.4. port()
  56. 3.5. params()
  57. 3.6. headers()
  58. 3.7. transport()
  59. 3.8. ttl()
  60. 3.9. user_param()
  61. 3.10. maddr()
  62. 3.11. method()
  63. 3.12. lr()
  64. 3.13. r2()
  65. 3.14. transport_val()
  66. 3.15. ttl_val()
  67. 3.16. user_param_val()
  68. 3.17. maddr_val()
  69. 3.18. method_val()
  70. 3.19. lr_val()
  71. 3.20. r2_val()
  72. 4. Kamailio::AVP
  73. 4.1. add(name,val)
  74. 4.2. get(name)
  75. 4.3. destroy(name)
  76. 5. Kamailio::Utils::PhoneNumbers
  77. 5.1.
  78. new(publicAccessPrefix,internationalPrefix,longDistanceP
  79. refix,countryCode,areaCode,pbxCode)
  80. 5.2. canonicalForm( number [, context] )
  81. 5.3. dialNumber( number [, context] )
  82. 6. Kamailio::LDAPUtils::LDAPConf
  83. 6.1. Constructor new()
  84. 6.2. Method base()
  85. 6.3. Method host()
  86. 6.4. Method port()
  87. 6.5. Method uri()
  88. 6.6. Method rootbindpw()
  89. 6.7. Method rootbinddn()
  90. 6.8. Method binddn()
  91. 6.9. Method bindpw()
  92. 7. Kamailio::LDAPUtils::LDAPConnection
  93. 7.1. Constructor new( [config, [authenticated]] )
  94. 7.2. Function/Method search( conf, filter, base,
  95. [requested_attributes ...])
  96. 7.2.1. Arguments:
  97. 7.2.2. Result:
  98. 8. Kamailio::VDB
  99. 9. Kamailio::Constants
  100. 10. Kamailio::VDB::Adapter::Speeddial
  101. 11. Kamailio::VDB::Adapter::Alias
  102. 11.1. query(conds,retkeys,order)
  103. 12. Kamailio::VDB::Adapter::AccountingSIPtrace
  104. 13. Kamailio::VDB::Adapter::Describe
  105. 14. Kamailio::VDB::Adapter::Auth
  106. 15. Kamailio::VDB::ReqCond
  107. 15.1. new(key,op,type,name)
  108. 15.2. op()
  109. 16. Kamailio::VDB::Pair
  110. 16.1. new(key,type,name)
  111. 16.2. key()
  112. 17. Kamailio::VDB::VTab
  113. 17.1. new()
  114. 17.2. call(op,[args])
  115. 18. Kamailio::VDB::Value
  116. 18.1. stringification
  117. 18.2. new(type,data)
  118. 18.3. type()
  119. 18.4. data()
  120. 19. Kamailio::VDB::Column
  121. 19.1. Stringification
  122. 19.2. new(type,name)
  123. 19.3. type( )
  124. 19.4. name()
  125. 19.5. Kamailio::VDB::Result
  126. 19.6. new(coldefs,[row, row, ...])
  127. 19.7. coldefs()
  128. 19.8. rows()
  129. 3. Perl samples
  130. 1. Sample directory
  131. 1.1. Script descriptions
  132. 1.1.1. branches.pl
  133. 1.1.2. firstline.pl
  134. 1.1.3. flags.pl
  135. 1.1.4. functions.pl
  136. 1.1.5. headers.pl
  137. 1.1.6. logging.pl
  138. 1.1.7. messagedump.pl
  139. 1.1.8. persistence.pl
  140. 1.1.9. phonenumbers.pl
  141. 1.1.10. pseudovars.pl
  142. 4. Frequently Asked Questions
  143. List of Examples
  144. 1.1. Set filename parameter
  145. 1.2. Set modpath parameter
  146. 1.3. Set reset_cycles parameter
  147. 1.4. Set perl_destroy_func parameter
  148. 1.5. perl_exec_simple() usage
  149. 1.6. perl_exec() usage
  150. 1.7. app_perl.set_reset_cycles usage
  151. 1.8. app_perl.get_reset_cycles usage
  152. Chapter 1. Admin Guide
  153. Table of Contents
  154. 1. Overview
  155. 2. Installing the module
  156. 3. Using the module
  157. 4. Dependencies
  158. 4.1. Kamailio Modules
  159. 4.2. External Libraries or Applications
  160. 5. Parameters
  161. 5.1. filename (string)
  162. 5.2. modpath (string)
  163. 5.3. reset_cycles (int)
  164. 5.4. perl_destroy_func (string)
  165. 6. Functions
  166. 6.1. perl_exec_simple(func, [param])
  167. 6.2. perl_exec(func, [param])
  168. 7. RPC Commands
  169. 7.1. app_perl.set_reset_cycles
  170. 7.2. app_perl.get_reset_cycles
  171. 1. Overview
  172. The time needed when writing a new Kamailio module unfortunately is
  173. quite high, while the options provided by the configuration file are
  174. limited to the features implemented in the modules.
  175. With this Perl module, you can easily implement your own Kamailio
  176. extensions in Perl. This allows for simple access to the full world of
  177. CPAN modules. SIP URI rewriting could be implemented based on regular
  178. expressions; accessing arbitrary data backends, e.g. LDAP or Berkeley
  179. DB files, is now extremely simple.
  180. 2. Installing the module
  181. This Perl module is loaded in kamailio.cfg (just like all the other
  182. modules) with loadmodule("/path/to/perl.so");.
  183. For the Perl module to compile, you need a reasonably recent version of
  184. perl (tested with 5.8.8) linked dynamically. It is strongly advised to
  185. use a threaded version. The default binary packages from your favorite
  186. Linux distribution should work fine.
  187. Cross compilation is supported by the Makefile. You need to set the
  188. environment variables PERLLDOPTS, PERLCCOPTS and TYPEMAP to values
  189. similar to the output of
  190. PERLLDOPTS: perl -MExtUtils::Embed -e ldopts
  191. PERLCCOPTS: perl -MExtUtils::Embed -e ccopts
  192. TYPEMAP: echo "`perl -MConfig -e 'print $Config{installprivlib}'`/ExtUtils/ty
  193. pemap"
  194. The exact position of your (precompiled!) perl libraries depends on the
  195. setup of your environment.
  196. 3. Using the module
  197. The Perl module has two interfaces: The perl side, and the Kamailio
  198. side. Once a Perl function is defined and loaded via the module
  199. parameters (see below), it may be called in Kamailio's configuration at
  200. an arbitary point. E.g., you could write a function "ldap_alias" in
  201. Perl, and then execute
  202. ...
  203. if (perl_exec("ldap_alias")) {
  204. ...
  205. }
  206. ...
  207. just as you would have done with the current alias_db module.
  208. The functions you can use are listed in the "Exported Functions"
  209. section below.
  210. On the Perl side, there are a number of functions that let you read and
  211. modify the current SIP message, such as the RURI or the message flags.
  212. An introduction to the Perl interface and the full reference
  213. documentation can be found below.
  214. 4. Dependencies
  215. 4.1. Kamailio Modules
  216. 4.2. External Libraries or Applications
  217. 4.1. Kamailio Modules
  218. The following modules must be loaded before this module:
  219. * The "sl" module is needed for sending replies uppon fatal errors.
  220. All other modules can be accessed from the Perl module, though.
  221. 4.2. External Libraries or Applications
  222. The following libraries or applications must be installed before
  223. running Kamailio with this module loaded:
  224. * Perl 5.8.x or later
  225. Additionally, a number of perl modules should be installed. The
  226. Kamailio::LDAPUtils package relies on Net::LDAP to be installed. One of
  227. the sample scripts needs IPC::Shareable
  228. This module has been developed and tested with Perl 5.8.8, but should
  229. work with any 5.8.x release. Compilation is possible with 5.6.x, but
  230. its behavior is unsupported. Earlier versions do not work.
  231. On current Debian systems, at least the following packages should be
  232. installed:
  233. * perl
  234. * perl-base
  235. * perl-modules
  236. * libperl5.8
  237. * libperl-dev
  238. * libnet-ldap-perl
  239. * libipc-shareable-perl
  240. It was reported that other Debian-style distributions (such as Ubuntu)
  241. need the same packages.
  242. On SuSE systems, at least the following packages should be installed:
  243. * perl
  244. * perl-ldap
  245. * IPC::Shareable perl module from CPAN
  246. Although SuSE delivers a lot of perl modules, others may have to be
  247. fetched from CPAN. Consider using the program "cpan2rpm" - which, in
  248. turn, is available on CPAN. It creates RPM files from CPAN.
  249. 5. Parameters
  250. 5.1. filename (string)
  251. 5.2. modpath (string)
  252. 5.3. reset_cycles (int)
  253. 5.4. perl_destroy_func (string)
  254. 5.1. filename (string)
  255. This is the file name of your script. This may be set once only, but it
  256. may include an arbitary number of functions and "use" as many Perl
  257. module as necessary.
  258. Must not be empty!
  259. Example 1.1. Set filename parameter
  260. ...
  261. modparam("app_perl", "filename", "/home/test/kamailio/myperl.pl")
  262. ...
  263. 5.2. modpath (string)
  264. The path to the Perl modules included (Kamailio.pm et.al). It is not
  265. absolutely crucial to set this path, as you may install the Modules in
  266. Perl's standard path, or update the "%INC" variable from within your
  267. script. Using this module parameter is the standard behavior, though.
  268. Multiple paths may be specified by separating them with a ":"
  269. character. The maximum is 10 paths.
  270. Example 1.2. Set modpath parameter
  271. ...
  272. modparam("app_perl", "modpath", "/usr/local/lib/kamailio/perl/")
  273. ...
  274. 5.3. reset_cycles (int)
  275. The number of execution cycles after which the embedded perl
  276. interpreter is reset. Sometimes is hard to track the scope of variables
  277. in all used perl modules and that can result in leaks of system memory.
  278. Resetting the interpreter cleans the memory space.
  279. When the interpreter is reset, the perl script is loaded again. Note
  280. that not all Kamailio processes will reset the interpreter at the same
  281. time. Each will do it when it has executed the script for the number of
  282. reset_cycles. Also, be aware that the reset of the interpreter is
  283. taking a bit of time (in the order of tens of mili-seconds).
  284. Default value is 0 - never reset the interpreter.
  285. Example 1.3. Set reset_cycles parameter
  286. ...
  287. modparam("app_perl", "reset_cycles", 100000)
  288. ...
  289. 5.4. perl_destroy_func (string)
  290. The name of Perl function to be executed before the interpreter is
  291. re-initialized (reset -- see reset_cycles parameter) at runtime. This
  292. could be useful to clean global variables or file descriptors from the
  293. Perl script.
  294. Example 1.4. Set perl_destroy_func parameter
  295. ...
  296. modparam("app_perl", "perl_destroy_func", "my_perl_destroy")
  297. ...
  298. 6. Functions
  299. 6.1. perl_exec_simple(func, [param])
  300. 6.2. perl_exec(func, [param])
  301. 6.1. perl_exec_simple(func, [param])
  302. Calls a perl function without passing it the current SIP message. May
  303. be used for very simple simple requests that do not have to fiddle with
  304. the message themselves, but rather return information values about the
  305. environment.
  306. The first parameter is the function to be called. An arbitrary string
  307. may optionally be passed as a parameter.
  308. This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
  309. ONREPLY_ROUTE and BRANCH_ROUTE.
  310. Example 1.5. perl_exec_simple() usage
  311. ...
  312. if (method=="INVITE") {
  313. perl_exec_simple("dosomething", "on invite messages");
  314. };
  315. ...
  316. 6.2. perl_exec(func, [param])
  317. Calls a perl function with passing it the current SIP message. The SIP
  318. message is reflected by a Perl module that gives you access to the
  319. information in the current SIP message (Kamailio::Message).
  320. The first parameter is the function to be called. An arbitrary string
  321. may be passed as a parameter.
  322. This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
  323. ONREPLY_ROUTE and BRANCH_ROUTE.
  324. Example 1.6. perl_exec() usage
  325. ...
  326. if (perl_exec("ldapalias")) {
  327. ...
  328. };
  329. ...
  330. 7. RPC Commands
  331. 7.1. app_perl.set_reset_cycles
  332. 7.2. app_perl.get_reset_cycles
  333. 7.1. app_perl.set_reset_cycles
  334. Set the value of the reset_cycle. The command has one integer
  335. parameter.
  336. Example 1.7. app_perl.set_reset_cycles usage
  337. ...
  338. kamcmd app_perl.set_reset_cycles 20000
  339. ...
  340. 7.2. app_perl.get_reset_cycles
  341. Return the value of the reset_cycle.
  342. Example 1.8. app_perl.get_reset_cycles usage
  343. ...
  344. kamcmd app_perl.get_reset_cycles
  345. ...
  346. Chapter 2. Kamailio Perl API
  347. Table of Contents
  348. 1. Kamailio
  349. 1.1. log(level,message)
  350. 2. Kamailio::Message
  351. 2.1. getType()
  352. 2.2. getStatus()
  353. 2.3. getReason()
  354. 2.4. getVersion()
  355. 2.5. getRURI()
  356. 2.6. getMethod()
  357. 2.7. getFullHeader()
  358. 2.8. getBody()
  359. 2.9. getMessage()
  360. 2.10. getHeader(name)
  361. 2.11. getHeaderNames()
  362. 2.12. moduleFunction(func,string1,string2)
  363. 2.13. log(level,message) (deprecated type)
  364. 2.14. rewrite_ruri(newruri)
  365. 2.15. setFlag(flag)
  366. 2.16. resetFlag(flag)
  367. 2.17. isFlagSet(flag)
  368. 2.18. pseudoVar(string)
  369. 2.19. append_branch(branch,qval)
  370. 2.20. getParsedRURI()
  371. 3. Kamailio::URI
  372. 3.1. user()
  373. 3.2. host()
  374. 3.3. passwd()
  375. 3.4. port()
  376. 3.5. params()
  377. 3.6. headers()
  378. 3.7. transport()
  379. 3.8. ttl()
  380. 3.9. user_param()
  381. 3.10. maddr()
  382. 3.11. method()
  383. 3.12. lr()
  384. 3.13. r2()
  385. 3.14. transport_val()
  386. 3.15. ttl_val()
  387. 3.16. user_param_val()
  388. 3.17. maddr_val()
  389. 3.18. method_val()
  390. 3.19. lr_val()
  391. 3.20. r2_val()
  392. 4. Kamailio::AVP
  393. 4.1. add(name,val)
  394. 4.2. get(name)
  395. 4.3. destroy(name)
  396. 5. Kamailio::Utils::PhoneNumbers
  397. 5.1.
  398. new(publicAccessPrefix,internationalPrefix,longDistancePrefix,
  399. countryCode,areaCode,pbxCode)
  400. 5.2. canonicalForm( number [, context] )
  401. 5.3. dialNumber( number [, context] )
  402. 6. Kamailio::LDAPUtils::LDAPConf
  403. 6.1. Constructor new()
  404. 6.2. Method base()
  405. 6.3. Method host()
  406. 6.4. Method port()
  407. 6.5. Method uri()
  408. 6.6. Method rootbindpw()
  409. 6.7. Method rootbinddn()
  410. 6.8. Method binddn()
  411. 6.9. Method bindpw()
  412. 7. Kamailio::LDAPUtils::LDAPConnection
  413. 7.1. Constructor new( [config, [authenticated]] )
  414. 7.2. Function/Method search( conf, filter, base,
  415. [requested_attributes ...])
  416. 7.2.1. Arguments:
  417. 7.2.2. Result:
  418. 8. Kamailio::VDB
  419. 9. Kamailio::Constants
  420. 10. Kamailio::VDB::Adapter::Speeddial
  421. 11. Kamailio::VDB::Adapter::Alias
  422. 11.1. query(conds,retkeys,order)
  423. 12. Kamailio::VDB::Adapter::AccountingSIPtrace
  424. 13. Kamailio::VDB::Adapter::Describe
  425. 14. Kamailio::VDB::Adapter::Auth
  426. 15. Kamailio::VDB::ReqCond
  427. 15.1. new(key,op,type,name)
  428. 15.2. op()
  429. 16. Kamailio::VDB::Pair
  430. 16.1. new(key,type,name)
  431. 16.2. key()
  432. 17. Kamailio::VDB::VTab
  433. 17.1. new()
  434. 17.2. call(op,[args])
  435. 18. Kamailio::VDB::Value
  436. 18.1. stringification
  437. 18.2. new(type,data)
  438. 18.3. type()
  439. 18.4. data()
  440. 19. Kamailio::VDB::Column
  441. 19.1. Stringification
  442. 19.2. new(type,name)
  443. 19.3. type( )
  444. 19.4. name()
  445. 19.5. Kamailio::VDB::Result
  446. 19.6. new(coldefs,[row, row, ...])
  447. 19.7. coldefs()
  448. 19.8. rows()
  449. 1. Kamailio
  450. 1.1. log(level,message)
  451. This module provides access to a limited number of Kamailio core
  452. functions. As the most interesting functions deal with SIP messages,
  453. they are located in the Kamailio::Message class below.
  454. 1.1. log(level,message)
  455. Logs the message with Kamailio's logging facility. The logging level is
  456. one of the following:
  457. * L_ALERT
  458. * L_CRIT
  459. * L_ERR
  460. * L_WARN
  461. * L_NOTICE
  462. * L_INFO
  463. * L_DBG
  464. Please note that this method is NOT automatically exported, as it
  465. collides with the perl function log (which calculates the logarithm).
  466. Either explicitly import the function (via use Kamailio qw ( log );),
  467. or call it with its full name:
  468. Kamailio::log(L_INFO, "foobar");
  469. 2. Kamailio::Message
  470. 2.1. getType()
  471. 2.2. getStatus()
  472. 2.3. getReason()
  473. 2.4. getVersion()
  474. 2.5. getRURI()
  475. 2.6. getMethod()
  476. 2.7. getFullHeader()
  477. 2.8. getBody()
  478. 2.9. getMessage()
  479. 2.10. getHeader(name)
  480. 2.11. getHeaderNames()
  481. 2.12. moduleFunction(func,string1,string2)
  482. 2.13. log(level,message) (deprecated type)
  483. 2.14. rewrite_ruri(newruri)
  484. 2.15. setFlag(flag)
  485. 2.16. resetFlag(flag)
  486. 2.17. isFlagSet(flag)
  487. 2.18. pseudoVar(string)
  488. 2.19. append_branch(branch,qval)
  489. 2.20. getParsedRURI()
  490. This package provides access functions for an Kamailio sip_msg
  491. structure and its sub-components. Through its means it is possible to
  492. fully configure alternative routing decisions.
  493. 2.1. getType()
  494. Returns one of the constants SIP_REQUEST, SIP_REPLY, SIP_INVALID
  495. stating the type of the current message.
  496. 2.2. getStatus()
  497. Returns the status code of the current Reply message. This function is
  498. invalid in Request context!
  499. 2.3. getReason()
  500. Returns the reason of the current Reply message. This function is
  501. invalid in Request context!
  502. 2.4. getVersion()
  503. Returns the version string of the current SIP message.
  504. 2.5. getRURI()
  505. This function returns the recipient URI of the present SIP message:
  506. my $ruri = $m->getRURI();
  507. getRURI returns a string. See "getParsedRURI()" below how to receive a
  508. parsed structure.
  509. This function is valid in request messages only.
  510. 2.6. getMethod()
  511. Returns the current method, such as INVITE, REGISTER, ACK and so on.
  512. my $method = $m->getMethod();
  513. This function is valid in request messages only.
  514. 2.7. getFullHeader()
  515. Returns the full message header as present in the current message. You
  516. might use this header to further work with it with your favorite MIME
  517. package.
  518. my $hdr = $m->getFullHeader();
  519. 2.8. getBody()
  520. Returns the message body.
  521. 2.9. getMessage()
  522. Returns the whole message including headers and body.
  523. 2.10. getHeader(name)
  524. Returns the body of the first message header with this name.
  525. print $m->getHeader("To");
  526. "John" <sip:[email protected]>
  527. 2.11. getHeaderNames()
  528. Returns an array of all header names. Duplicates possible!
  529. 2.12. moduleFunction(func,string1,string2)
  530. Search for an arbitrary function in module exports and call it with the
  531. parameters self, string1, string2.
  532. string1 and/or string2 may be omitted.
  533. As this function provides access to the functions that are exported to
  534. the Kamailio configuration file, it is autoloaded for unknown
  535. functions. Instead of writing
  536. $m->moduleFunction("sl_send_reply", "500", "Internal Error");
  537. $m->moduleFunction("xlog", "L_INFO", "foo");
  538. you may as well write
  539. $m->sl_send_reply("500", "Internal Error");
  540. $m->xlog("L_INFO", "foo");
  541. WARNING
  542. In Kamailio 1.2, only a limited subset of module functions is
  543. available. This restriction will be removed in a later version.
  544. Here is a list of functions that are expected to be working (not
  545. claiming completeness):
  546. * alias_db_lookup
  547. * consume_credentials
  548. * is_rpid_user_e164
  549. * append_rpid_hf
  550. * bind_auth
  551. * avp_print
  552. * cpl_process_register
  553. * cpl_process_register_norpl
  554. * load_dlg
  555. * ds_next_dst
  556. * ds_next_domain
  557. * ds_mark_dst
  558. * ds_mark_dst
  559. * is_from_local
  560. * is_uri_host_local
  561. * dp_can_connect
  562. * dp_apply_policy
  563. * enum_query (without parameters)
  564. * enum_fquery (without parameters)
  565. * is_from_user_enum (without parameters)
  566. * i_enum_query (without parameters)
  567. * imc_manager
  568. * jab_* (all functions from the jabber module)
  569. * load_gws (without parameters)
  570. * next_gw
  571. * from_gw (without parameters)
  572. * to_gw (without parameters)
  573. * load_contacts
  574. * next_contacts
  575. * sdp_mangle_ip
  576. * sdp_mangle_port
  577. * encode_contact
  578. * decode_contact
  579. * decode_contact_header
  580. * fix_contact
  581. * use_media_proxy
  582. * end_media_session
  583. * m_store
  584. * m_dump
  585. * fix_nated_contact
  586. * unforce_rtp_proxy
  587. * force_rtp_proxy
  588. * fix_nated_register
  589. * add_rcv_param
  590. * options_reply
  591. * checkospheader
  592. * validateospheader
  593. * requestosprouting
  594. * checkosproute
  595. * prepareosproute
  596. * prepareallosproutes
  597. * checkcallingtranslation
  598. * reportospusage
  599. * mangle_pidf
  600. * mangle_message_cpim
  601. * add_path (without parameters)
  602. * add_path_received (without parameters)
  603. * prefix2domain
  604. * allow_routing (without parameters)
  605. * allow_trusted
  606. * pike_check_req
  607. * handle_publish
  608. * handle_subscribe
  609. * stored_pres_info
  610. * bind_pua
  611. * send_publish
  612. * send_subscribe
  613. * pua_set_publish
  614. * loose_route
  615. * record_route
  616. * load_rr
  617. * sip_trace
  618. * sl_reply_error
  619. * sms_send_msg
  620. * sd_lookup
  621. * sstCheckMin
  622. * append_time
  623. * has_body (without parameters)
  624. * is_peer_verified
  625. * t_newtran
  626. * t_release
  627. * t_relay (without parameters)
  628. * t_flush_flags
  629. * t_check_trans
  630. * t_was_cancelled
  631. * t_load_contacts
  632. * t_next_contacts
  633. * uac_restore_from
  634. * uac_auth
  635. * has_totag
  636. * tel2sip
  637. * check_to
  638. * check_from
  639. * radius_does_uri_exist
  640. * ul_* (All functions exported by the usrloc module for user access)
  641. * xmpp_send_message
  642. 2.13. log(level,message) (deprecated type)
  643. Logs the message with Kamailio's logging facility. The logging level is
  644. one of the following:
  645. * L_ALERT
  646. * L_CRIT
  647. * L_ERR
  648. * L_WARN
  649. * L_NOTICE
  650. * L_INFO
  651. * L_DBG
  652. The logging function should be accessed via the Kamailio module
  653. variant. This one, located in Kamailio::Message, is deprecated.
  654. 2.14. rewrite_ruri(newruri)
  655. Sets a new destination (recipient) URI. Useful for rerouting the
  656. current message/call.
  657. if ($m->getRURI() =~ m/\@somedomain.net/) {
  658. $m->rewrite_ruri("sip:dispatcher\@organization.net");
  659. }
  660. 2.15. setFlag(flag)
  661. Sets a message flag. The constants as known from the C API may be used,
  662. when Constants.pm is included.
  663. 2.16. resetFlag(flag)
  664. Resets a message flag.
  665. 2.17. isFlagSet(flag)
  666. Returns whether a message flag is set or not.
  667. 2.18. pseudoVar(string)
  668. Returns a new string where all pseudo variables are substituted by
  669. their values. Can be used to receive the values of single variables,
  670. too.
  671. Please remember that you need to escape the '$' sign in perl strings!
  672. 2.19. append_branch(branch,qval)
  673. Append a branch to current message.
  674. 2.20. getParsedRURI()
  675. Returns the current destination URI as an Kamailio::URI object.
  676. 3. Kamailio::URI
  677. 3.1. user()
  678. 3.2. host()
  679. 3.3. passwd()
  680. 3.4. port()
  681. 3.5. params()
  682. 3.6. headers()
  683. 3.7. transport()
  684. 3.8. ttl()
  685. 3.9. user_param()
  686. 3.10. maddr()
  687. 3.11. method()
  688. 3.12. lr()
  689. 3.13. r2()
  690. 3.14. transport_val()
  691. 3.15. ttl_val()
  692. 3.16. user_param_val()
  693. 3.17. maddr_val()
  694. 3.18. method_val()
  695. 3.19. lr_val()
  696. 3.20. r2_val()
  697. This package provides functions for access to sip_uri structures.
  698. 3.1. user()
  699. Returns the user part of this URI.
  700. 3.2. host()
  701. Returns the host part of this URI.
  702. 3.3. passwd()
  703. Returns the passwd part of this URI.
  704. 3.4. port()
  705. Returns the port part of this URI.
  706. 3.5. params()
  707. Returns the params part of this URI.
  708. 3.6. headers()
  709. Returns the headers part of this URI.
  710. 3.7. transport()
  711. Returns the transport part of this URI.
  712. 3.8. ttl()
  713. Returns the ttl part of this URI.
  714. 3.9. user_param()
  715. Returns the user_param part of this URI.
  716. 3.10. maddr()
  717. Returns the maddr part of this URI.
  718. 3.11. method()
  719. Returns the method part of this URI.
  720. 3.12. lr()
  721. Returns the lr part of this URI.
  722. 3.13. r2()
  723. Returns the r2 part of this URI.
  724. 3.14. transport_val()
  725. Returns the transport_val part of this URI.
  726. 3.15. ttl_val()
  727. Returns the ttl_val part of this URI.
  728. 3.16. user_param_val()
  729. Returns the user_param_val part of this URI.
  730. 3.17. maddr_val()
  731. Returns the maddr_val part of this URI.
  732. 3.18. method_val()
  733. Returns the method_val part of this URI.
  734. 3.19. lr_val()
  735. Returns the lr_val part of this URI.
  736. 3.20. r2_val()
  737. Returns the r2_val part of this URI.
  738. 4. Kamailio::AVP
  739. 4.1. add(name,val)
  740. 4.2. get(name)
  741. 4.3. destroy(name)
  742. This package provides access functions for Kamailio's AVPs. These
  743. variables can be created, evaluated, modified and removed through this
  744. package.
  745. Please note that these functions do NOT support the notation used in
  746. the configuration file, but directly work on strings or numbers. See
  747. documentation of add method below.
  748. 4.1. add(name,val)
  749. Add an AVP.
  750. Add an Kamailio AVP to its environment. name and val may both be
  751. integers or strings; this function will try to guess what is correct.
  752. Please note that
  753. Kamailio::AVP::add("10", "10")
  754. is something different than
  755. Kamailio::AVP::add(10, 10)
  756. due to this evaluation: The first will create _string_ AVPs with the
  757. name 10, while the latter will create a numerical AVP.
  758. You can modify/overwrite AVPs with this function.
  759. 4.2. get(name)
  760. get an Kamailio AVP:
  761. my $numavp = Kamailio::AVP::get(5);
  762. my $stravp = Kamailio::AVP::get("foo");
  763. 4.3. destroy(name)
  764. Destroy an AVP.
  765. Kamailio::AVP::destroy(5);
  766. Kamailio::AVP::destroy("foo");
  767. 5. Kamailio::Utils::PhoneNumbers
  768. 5.1.
  769. new(publicAccessPrefix,internationalPrefix,longDistancePrefix,count
  770. ryCode,areaCode,pbxCode)
  771. 5.2. canonicalForm( number [, context] )
  772. 5.3. dialNumber( number [, context] )
  773. Kamailio::Utils::PhoneNumbers - Functions for canonical forms of phone
  774. numbers.
  775. use Kamailio::Utils::PhoneNumbers;
  776. my $phonenumbers = new Kamailio::Utils::PhoneNumbers(
  777. publicAccessPrefix => "0",
  778. internationalPrefix => "+",
  779. longDistancePrefix => "0",
  780. areaCode => "761",
  781. pbxCode => "456842",
  782. countryCode => "49"
  783. );
  784. $canonical = $phonenumbers->canonicalForm("07612034567");
  785. $number = $phonenumbers->dialNumber("+497612034567");
  786. A telphone number starting with a plus sign and containing all dial
  787. prefixes is in canonical form. This is usally not the number to dial at
  788. any location, so the dialing number depends on the context of the
  789. user/system.
  790. The idea to canonicalize numbers were taken from hylafax.
  791. Example: +497614514829 is the canonical form of my phone number, 829 is
  792. the number to dial at Pyramid, 4514829 is the dialing number from
  793. Freiburg are and so on.
  794. To canonicalize any number, we strip off any dial prefix we find and
  795. then add the prefixes for the location. So, when the user enters the
  796. number 04514829 in context pyramid, we remove the publicAccessPrefix
  797. (at Pyramid this is 0) and the pbxPrefix (4514 here). The result is
  798. 829. Then we add all the general dial prefixes - 49 (country) 761
  799. (area) 4514 (pbx) and 829, the number itself => +497614514829
  800. To get the dialing number from a canonical phone number, we substract
  801. all general prefixes until we have something
  802. As said before, the interpretation of a phone number depends on the
  803. context of the location. For the functions in this package, the context
  804. is created through the new operator.
  805. The following fields should be set:
  806. 'longDistancePrefix'
  807. 'areaCode'
  808. 'pbxCode'
  809. 'internationalPrefix'
  810. 'publicAccessPrefix'
  811. 'countryCode'
  812. This module exports the following functions when useed:
  813. 5.1. new(publicAccessPrefix,internationalPrefix,longDistancePrefix,countryCod
  814. e,areaCode,pbxCode)
  815. The new operator returns an object of this type and sets its locational
  816. context according to the passed parameters. See
  817. Kamailio::Utils::PhoneNumbers above.
  818. 5.2. canonicalForm( number [, context] )
  819. Convert a phone number (given as first argument) into its canonical
  820. form. When no context is passed in as the second argument, the default
  821. context from the systems configuration file is used.
  822. 5.3. dialNumber( number [, context] )
  823. Convert a canonical phone number (given in the first argument) into a
  824. number to to dial. WHen no context is given in the second argument, a
  825. default context from the systems configuration is used.
  826. 6. Kamailio::LDAPUtils::LDAPConf
  827. 6.1. Constructor new()
  828. 6.2. Method base()
  829. 6.3. Method host()
  830. 6.4. Method port()
  831. 6.5. Method uri()
  832. 6.6. Method rootbindpw()
  833. 6.7. Method rootbinddn()
  834. 6.8. Method binddn()
  835. 6.9. Method bindpw()
  836. Kamailio::LDAPUtils::LDAPConf - Read openldap config from standard
  837. config files.
  838. use Kamailio::LDAPUtils::LDAPConf;
  839. my $conf = new Kamailio::LDAPUtils::LDAPConf();
  840. This module may be used to retrieve the global LDAP configuration as
  841. used by other LDAP software, such as nsswitch.ldap and pam-ldap. The
  842. configuration is usualy stored in /etc/openldap/ldap.conf
  843. When used from an account with sufficient privilegs (e.g. root), the
  844. ldap manager passwort is also retrieved.
  845. 6.1. Constructor new()
  846. Returns a new, initialized Kamailio::LDAPUtils::LDAPConf object.
  847. 6.2. Method base()
  848. Returns the servers base-dn to use when doing queries.
  849. 6.3. Method host()
  850. Returns the ldap host to contact.
  851. 6.4. Method port()
  852. Returns the ldap servers port.
  853. 6.5. Method uri()
  854. Returns an uri to contact the ldap server. When there is no ldap_uri in
  855. the configuration file, an ldap: uri is constucted from host and port.
  856. 6.6. Method rootbindpw()
  857. Returns the ldap "root" password.
  858. Note that the rootbindpw is only available when the current account has
  859. sufficient privilegs to access /etc/openldap/ldap.secret.
  860. 6.7. Method rootbinddn()
  861. Returns the DN to use for "root"-access to the ldap server.
  862. 6.8. Method binddn()
  863. Returns the DN to use for authentication to the ldap server. When no
  864. bind dn has been specified in the configuration file, returns the
  865. rootbinddn.
  866. 6.9. Method bindpw()
  867. Returns the password to use for authentication to the ldap server. When
  868. no bind password has been specified, returns the rootbindpw if any.
  869. 7. Kamailio::LDAPUtils::LDAPConnection
  870. 7.1. Constructor new( [config, [authenticated]] )
  871. 7.2. Function/Method search( conf, filter, base, [requested_attributes
  872. ...])
  873. 7.2.1. Arguments:
  874. 7.2.2. Result:
  875. Kamailio::LDAPUtils::LDAPConnection - Perl module to perform simple
  876. LDAP queries.
  877. OO-Style interface:
  878. use Kamailio::LDAPUtils::LDAPConnection;
  879. my $ldap = new Kamailio::LDAPUtils::LDAPConnection;
  880. my @rows = $ldap-search("uid=andi","ou=people,ou=coreworks,ou=de");
  881. Procedural interface:
  882. use Kamailio::LDAPUtils::LDAPConnection;
  883. my @rows = $ldap->search(
  884. new Kamailio::LDAPUtils::LDAPConfig(), "uid=andi","ou=people,ou=coreworks,
  885. ou=de");
  886. This perl module offers a somewhat simplified interface to the
  887. Net::LDAP functionality. It is intended for cases where just a few
  888. attributes should be retrieved without the overhead of the full
  889. featured Net::LDAP.
  890. 7.1. Constructor new( [config, [authenticated]] )
  891. Set up a new LDAP connection.
  892. The first argument, when given, should be a hash reference pointing to
  893. to the connection parameters, possibly an
  894. Kamailio::LDAPUtils::LDAPConfig object. This argument may be undef in
  895. which case a new (default) Kamailio::LDAPUtils::LDAPConfig object is
  896. used.
  897. When the optional second argument is a true value, the connection will
  898. be authenticated. Otherwise an anonymous bind is done.
  899. On success, a new LDAPConnection object is returned, otherwise the
  900. result is undef.
  901. 7.2. Function/Method search( conf, filter, base, [requested_attributes ...])
  902. perform an ldap search, return the dn of the first matching directory
  903. entry, unless a specific attribute has been requested, in wich case the
  904. values(s) fot this attribute are returned.
  905. When the first argument (conf) is a
  906. Kamailio::LDAPUtils::LDAPConnection, it will be used to perform the
  907. queries. You can pass the first argument implicitly by using the
  908. "method" syntax.
  909. Otherwise the conf argument should be a reference to a hash containing
  910. the connection setup parameters as contained in a
  911. Kamailio::LDAPUtils::LDAPConf object. In this mode, the
  912. Kamailio::LDAPUtils::LDAPConnection from previous queries will be
  913. reused.
  914. 7.2.1. Arguments:
  915. conf
  916. configuration object, used to find host,port,suffix and
  917. use_ldap_checks
  918. filter
  919. ldap search filter, eg '(mail=some@domain)'
  920. base
  921. search base for this query. If undef use default suffix, concat
  922. base with default suffix if the last char is a ','
  923. requested_attributes
  924. retrieve the given attributes instead of the dn from the ldap
  925. directory.
  926. 7.2.2. Result:
  927. Without any specific requested_attributes, return the dn of all
  928. matching entries in the LDAP directory.
  929. When some requested_attributes are given, return an array with those
  930. attibutes. When multiple entries match the query, the attribute lists
  931. are concatenated.
  932. 8. Kamailio::VDB
  933. This package is an (abstract) base class for all virtual databases.
  934. Derived packages can be configured to be used by Kamailio as a
  935. database.
  936. The base class itself should NOT be used in this context, as it does
  937. not provide any functionality.
  938. 9. Kamailio::Constants
  939. This package provides a number of constants taken from enums and
  940. defines of Kamailio header files. Unfortunately, there is no mechanism
  941. for updating the constants automatically, so check the values if you
  942. are in doubt.
  943. 10. Kamailio::VDB::Adapter::Speeddial
  944. This adapter can be used with the speeddial module.
  945. 11. Kamailio::VDB::Adapter::Alias
  946. 11.1. query(conds,retkeys,order)
  947. This package is intended for usage with the alias_db module. The query
  948. VTab has to take two arguments and return an array of two arguments
  949. (user name/domain).
  950. 11.1. query(conds,retkeys,order)
  951. Queries the vtab with the given arguments for request conditions, keys
  952. to return and sort order column name.
  953. 12. Kamailio::VDB::Adapter::AccountingSIPtrace
  954. This package is an Adapter for the acc and siptrace modules, featuring
  955. only an insert operation.
  956. 13. Kamailio::VDB::Adapter::Describe
  957. This package is intended for debug usage. It will print information
  958. about requested functions and operations of a client module.
  959. Use this module to request schema information when creating new
  960. adapters.
  961. 14. Kamailio::VDB::Adapter::Auth
  962. This adapter is intended for usage with the auth_db module. The VTab
  963. should take a username as an argument and return a (plain text!)
  964. password.
  965. 15. Kamailio::VDB::ReqCond
  966. 15.1. new(key,op,type,name)
  967. 15.2. op()
  968. This package represents a request condition for database access,
  969. consisting of a column name, an operator (=, <, >, ...), a data type
  970. and a value.
  971. This package inherits from Kamailio::VDB::Pair and thus includes its
  972. methods.
  973. 15.1. new(key,op,type,name)
  974. Constructs a new Column object.
  975. 15.2. op()
  976. Returns or sets the current operator.
  977. 16. Kamailio::VDB::Pair
  978. 16.1. new(key,type,name)
  979. 16.2. key()
  980. This package represents database key/value pairs, consisting of a key,
  981. a value type, and the value.
  982. This package inherits from Kamailio::VDB::Value and thus has the same
  983. methods.
  984. 16.1. new(key,type,name)
  985. Constructs a new Column object.
  986. 16.2. key()
  987. Returns or sets the current key.
  988. 17. Kamailio::VDB::VTab
  989. 17.1. new()
  990. 17.2. call(op,[args])
  991. This package handles virtual tables and is used by the Kamailio::VDB
  992. class to store information about valid tables. The package is not
  993. inteded for end user access.
  994. 17.1. new()
  995. Constructs a new VTab object
  996. 17.2. call(op,[args])
  997. Invokes an operation on the table (insert, update, ...) with the given
  998. arguments.
  999. 18. Kamailio::VDB::Value
  1000. 18.1. stringification
  1001. 18.2. new(type,data)
  1002. 18.3. type()
  1003. 18.4. data()
  1004. This package represents a database value. Additional to the data
  1005. itself, information about its type is stored.
  1006. 18.1. stringification
  1007. When accessing a Kamailio::VDB::Value object as a string, it simply
  1008. returns its data regardless of its type. =cut
  1009. use strict;
  1010. package Kamailio::VDB::Value;
  1011. use overload '""' => \&stringify;
  1012. sub stringify { shift->{data} }
  1013. use Kamailio; use Kamailio::Constants;
  1014. our @ISA = qw ( Kamailio::Utils::Debug );
  1015. 18.2. new(type,data)
  1016. Constructs a new Value object. Its data type and the data are passed as
  1017. parameters.
  1018. 18.3. type()
  1019. Returns or sets the current data type. Please consider using the
  1020. constants from Kamailio::Constants
  1021. 18.4. data()
  1022. Returns or sets the current data.
  1023. 19. Kamailio::VDB::Column
  1024. 19.1. Stringification
  1025. 19.2. new(type,name)
  1026. 19.3. type( )
  1027. 19.4. name()
  1028. 19.5. Kamailio::VDB::Result
  1029. 19.6. new(coldefs,[row, row, ...])
  1030. 19.7. coldefs()
  1031. 19.8. rows()
  1032. This package represents database column definition, consisting of a
  1033. column name and its data type.
  1034. 19.1. Stringification
  1035. When accessing a Kamailio::VDB::Column object as a string, it simply
  1036. returns its column name regardless of its type. =cut
  1037. package Kamailio::VDB::Column;
  1038. use overload '""' => \&stringify;
  1039. sub stringify { shift->{name} }
  1040. use Kamailio; use Kamailio::Constants;
  1041. our @ISA = qw ( Kamailio::Utils::Debug );
  1042. 19.2. new(type,name)
  1043. Constructs a new Column object. Its type and the name are passed as
  1044. parameters.
  1045. 19.3. type( )
  1046. Returns or sets the current type. Please consider using the constants
  1047. from Kamailio::Constants
  1048. 19.4. name()
  1049. Returns or sets the current column name.
  1050. 19.5. Kamailio::VDB::Result
  1051. This class represents a VDB result set. It contains a column
  1052. definition, plus an array of rows. Rows themselves are simply
  1053. references to arrays of scalars.
  1054. 19.6. new(coldefs,[row, row, ...])
  1055. The constructor creates a new Result object. Its first parameter is a
  1056. reference to an array of Kamailio::VDB::Column objects. Additional
  1057. parameters may be passed to provide initial rows, which are references
  1058. to arrays of scalars.
  1059. 19.7. coldefs()
  1060. Returns or sets the column definition of the object.
  1061. 19.8. rows()
  1062. Returns or sets the rows of the object.
  1063. Chapter 3. Perl samples
  1064. Table of Contents
  1065. 1. Sample directory
  1066. 1.1. Script descriptions
  1067. 1.1.1. branches.pl
  1068. 1.1.2. firstline.pl
  1069. 1.1.3. flags.pl
  1070. 1.1.4. functions.pl
  1071. 1.1.5. headers.pl
  1072. 1.1.6. logging.pl
  1073. 1.1.7. messagedump.pl
  1074. 1.1.8. persistence.pl
  1075. 1.1.9. phonenumbers.pl
  1076. 1.1.10. pseudovars.pl
  1077. 1. Sample directory
  1078. 1.1. Script descriptions
  1079. 1.1.1. branches.pl
  1080. 1.1.2. firstline.pl
  1081. 1.1.3. flags.pl
  1082. 1.1.4. functions.pl
  1083. 1.1.5. headers.pl
  1084. 1.1.6. logging.pl
  1085. 1.1.7. messagedump.pl
  1086. 1.1.8. persistence.pl
  1087. 1.1.9. phonenumbers.pl
  1088. 1.1.10. pseudovars.pl
  1089. There are a number of example scripts in the "samples/". They are
  1090. documented well. Read them, it will explain a lot to you :)
  1091. If you want to use any of these scripts directly in your
  1092. implementation, you can use Perl's "require" mechanism to import them
  1093. (just remember that you need to use quotes when require'ing .pl files).
  1094. 1.1. Script descriptions
  1095. The included sample scripts are described below:
  1096. 1.1.1. branches.pl
  1097. The minimal function in branches.pl demonstrates that you can access
  1098. the "append_branch" function from within perl, just as you would have
  1099. done from your normal configuration file. You'll find documentation on
  1100. the concepts of branching in the Kamailio documentation.
  1101. 1.1.2. firstline.pl
  1102. Message's first_line structure may be evaluated. Message can be either
  1103. of SIP_REQUEST or SIP_REPLY. Depending on that, different information
  1104. can be received. This script demonstrates these functions.
  1105. 1.1.3. flags.pl
  1106. The perl module provides access to Kamailio's flagging mechanism. The
  1107. flag names available for Kamailio modules are made available through
  1108. the Kamailio::Constants package, so you can flag messages as "green",
  1109. "magenta" etc.
  1110. The first function, setflag, demonstrates how the "green" flag is set.
  1111. In the second function, readflag, the "green" and "magenta" flags are
  1112. evaluated.
  1113. 1.1.4. functions.pl
  1114. This sample script demonstrates different things related to calling
  1115. functions from within perl, and the different types of functions you
  1116. can offer for Kamailio access.
  1117. "exportedfuncs" simply demonstrates that you can use the moduleFunction
  1118. method to call functions offered by other modules. The results are
  1119. equivalent to calling these functions from your config file. In the
  1120. demonstrated case, telephone calls with a destination number beginning
  1121. with 555... are rejected with an internal server error. Other
  1122. destination addresses are passed to the alias_db module.
  1123. Please note that the moduleFunction method is not fully available in
  1124. Kamailio 1.2. See the method's documentation for details.
  1125. "paramfunc" shows that you can pass arbitrary strings to perl
  1126. functions. Do with them whatever you want :)
  1127. "autotest" demonstrates that unknown functions in Kamailio::Message
  1128. objects are automatically transformed into calls to module functions.
  1129. The "diefunc"s show that dying perl scripts - by "manual" dying, or
  1130. because of script errors - are handled by the Kamailio package. The
  1131. error message is logged through Kamailio's logging mechanism. Please
  1132. note that this only works correctly if you do NOT overwrite the default
  1133. die handler. Oh, yes, that works for warnings, too.
  1134. 1.1.5. headers.pl
  1135. Header extraction is among the most crucial functionalities while
  1136. processing SIP messages. This sample script demonstrates access to
  1137. header names and values within two sample functions.
  1138. "headernames" extracts all header names and logs their names.
  1139. "someheaders" logs the contents of the two headers, "To" and
  1140. "WWW-Contact". As you can see, headers that occur more than once are
  1141. retrieved as an array, which may be accessed by Perl's array accessing
  1142. methods.
  1143. 1.1.6. logging.pl
  1144. For debugging purposes, you probably want to write messages to the
  1145. syslog. The "logdemo" shows three ways to access the Kamailio log
  1146. function: it is available through the Kamailio class as well as through
  1147. the Kamailio::Message class.
  1148. Remember that you can use exported functions from other modules. You
  1149. may thus as well use the "xlog" module and it's xlog function.
  1150. The L_INFO, L_DBG, L_ERR, L_CRIT... constants are available through the
  1151. Kamailio::Constants package.
  1152. 1.1.7. messagedump.pl
  1153. This script demonstrates how to access the whole message header of the
  1154. current message. Please note that modifications on the message made by
  1155. earlier function calls in your configuration script may NOT be
  1156. reflected in this dump.
  1157. 1.1.8. persistence.pl
  1158. When processing SIP messages, you may want to use persistent data
  1159. across multiple calls to your Perl functions. Your first option is to
  1160. use global variables in your script. Unfortunately, these globals are
  1161. not visible from the mulitple instances of Kamailio. You may want to
  1162. use a mechanism such as the IPC::Shareable shared memory access package
  1163. to correct this.
  1164. 1.1.9. phonenumbers.pl
  1165. The Kamailio::Utils::PhoneNumbers package provides two methods for the
  1166. transformation of local to canonical telephone numbers, and vice versa.
  1167. This script demonstrates it's use.
  1168. 1.1.10. pseudovars.pl
  1169. This script demonstrates the Perl module's "pseudoVar" method. It may
  1170. be used to retrieve the values of current pseudo variables.
  1171. You might notice that there is no particular function for setting
  1172. pseudo variables; you may use the exported functions from the avpops
  1173. module, though.
  1174. Chapter 4. Frequently Asked Questions
  1175. 4.1. Are there known bugs in the Perl module?
  1176. 4.2. Where can I find more about Kamailio?
  1177. 4.3. Where can I post a question about this module?
  1178. 4.4. How can I report a bug?
  1179. 4.1.
  1180. Are there known bugs in the Perl module?
  1181. The Perl module does have a few shortcomings that may be regarded as
  1182. bugs.
  1183. * Missing module functions. Not all functions of other modules are
  1184. available for Perl access. The reason for this is a design property
  1185. of Kamailio. Making available more functions is work in progress.
  1186. * Perl and threads. Perl itself is, when compiled with the correct
  1187. parameters, thread safe; unfortunately, not all Perl modules are.
  1188. The DBI modules, especially (but not restricted to) DBI::ODBC are
  1189. known NOT to be thread safe.
  1190. Using DBI::ODBC -- and possibly other non-thread-safe Perl
  1191. extensions -- may result in erroneous behavior of Kamailio,
  1192. including (but not restricted to) server crashes and wrong routing.
  1193. 4.2.
  1194. Where can I find more about Kamailio?
  1195. Take a look at http://www.kamailio.org/.
  1196. 4.3.
  1197. Where can I post a question about this module?
  1198. First at all check if your question was already answered on one of our
  1199. mailing lists:
  1200. * User Mailing List -
  1201. http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
  1202. * Developer Mailing List -
  1203. http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
  1204. E-mails regarding any stable Kamailio release should be sent to
  1205. <[email protected]> and e-mails regarding development
  1206. versions should be sent to <[email protected]>.
  1207. If you want to keep the mail private, send it to
  1208. <[email protected]>.
  1209. 4.4.
  1210. How can I report a bug?
  1211. Please follow the guidelines provided at:
  1212. http://sip-router.org/tracker.