I am trying to incorporate a cpl script for testing purposes with kamailio 3 but have been met with failure with each try.<br><div class="gmail_quote"><br>Test scenario<br><br>I have two sip phones registered to kamailio successfully (I can make phone calls between the two phones).<br>
<br>The CPL XML is as follows:<br><br><?xml version="1.0" encoding="UTF-8"?><br><cpl><br> <incoming ><br> <location clear="yes" url="<a href="mailto:sip%3A1000@192.168.254.144" target="_blank">sip:1000@192.168.254.144</a>" ><br>
<log comment="cpl-log - just location" /><br> </location><br> </incoming><br></cpl><br><br>This compiled successfully and is populating the cpl table in the openser database.<br>
<br>When I call this from kamailio.cfg I get the 483 (Too many hops) error. If someone could spot an obvious error, I would appreciate it.<br><br>The current kamailio.cfg file is as follows:<br>------------------<br><br>
debug=8<br>log_stderror=yes<br><br>memdbg=5<br>memlog=5<br><br>log_facility=LOG_LOCAL0<br>
<br>fork=yes<br>children=4<br><br>/* uncomment the next line to disable TCP (default on) */<br>disable_tcp=yes<br><br>/* uncomment the next line to disable the auto discovery of local aliases<br> based on revers DNS on IPs (default on) */<br>
auto_aliases=no<br><br>port=5060<br><br>/* uncomment and configure the following line if you want Kamailio to <br> bind on a specific interface/port/proto (default bind on all available) */<br>listen=udp:<a href="http://192.168.254.144:5060" target="_blank">192.168.254.144:5060</a><br>
<br><br>####### Custom Parameters #########<br><br># These parameters can be modified runtime via RPC interface<br># - see the documentation of 'cfg_rpc' module.<br>#<br># Format: <a href="http://group.id" target="_blank">group.id</a> = value 'desc' description<br>
# Access: $sel(<a href="http://cfg_get.group.id" target="_blank">cfg_get.group.id</a>) or @<a href="http://cfg_get.group.id" target="_blank">cfg_get.group.id</a><br>#<br><br>pstn.gw_ip = "" desc "PSTN GW Address"<br>
<br>####### Modules Section ########<br>
<br>#set module path<br>mpath="/usr/lib/kamailio/modules_k/:/usr/lib/kamailio/modules/"<br><br>/* uncomment next line for MySQL DB support */<br>loadmodule "db_mysql.so"<br>loadmodule "mi_fifo.so"<br>
loadmodule "kex.so"<br>loadmodule "tm.so"<br>loadmodule "tmx.so"<br>loadmodule "sl.so"<br>loadmodule "rr.so"<br>loadmodule "pv.so"<br>loadmodule "maxfwd.so"<br>
loadmodule "usrloc.so"<br>loadmodule "registrar.so"<br>loadmodule "textops.so"<br>loadmodule "uri_db.so"<br>loadmodule "siputils.so"<br>loadmodule "xlog.so"<br>
loadmodule "sanity.so"<br>
loadmodule "ctl.so"<br>loadmodule "mi_rpc.so"<br>loadmodule "acc.so"<br>#!ifdef WITH_AUTH<br>loadmodule "auth.so"<br>loadmodule "auth_db.so"<br>#!endif<br>/* uncomment next line for aliases support<br>
NOTE: a DB (like db_mysql) module must be also loaded */<br>#loadmodule "alias_db.so"<br>/* uncomment next line for multi-domain support<br> NOTE: a DB (like db_mysql) module must be also loaded<br> NOTE: be sure and enable multi-domain support in all used modules<br>
(see "multi-module params" section ) */<br>#loadmodule "domain.so"<br>#!ifdef WITH_PRESENCE<br>loadmodule "presence.so"<br>loadmodule "presence_xml.so"<br>#!endif<br><br>#!ifdef WITH_NAT<br>
loadmodule "nathelper.so"<br>#!endif<br># ----kh add------#<br>loadmodule "cpl-c.so"<br># ----kh end -----#<br><br># ----------------- setting module-specific parameters ---------------<br><br><br># ----- mi_fifo params -----<br>
modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")<br><br><br># ----- rr params -----<br># add value to ;lr param to cope with most of the UAs<br>modparam("rr", "enable_full_lr", 1)<br>
# do not append from tag to the RR (no need for this script)<br>modparam("rr", "append_fromtag", 0)<br><br><br># ----- rr params -----<br>modparam("registrar", "method_filtering", 1)<br>
/* uncomment the next line to disable parallel forking via location */<br># modparam("registrar", "append_branches", 0)<br>/* uncomment the next line not to allow more than 10 contacts per AOR */<br>#modparam("registrar", "max_contacts", 10)<br>
<br><br># ----- uri_db params -----<br>/* by default we disable the DB support in the module as we do not need it<br> in this configuration */<br>modparam("uri_db", "use_uri_table", 0)<br>modparam("uri_db", "db_url", "")<br>
<br><br># ----- acc params -----<br>/* what sepcial events should be accounted ? */<br>modparam("acc", "early_media", 1)<br>modparam("acc", "report_ack", 1)<br>modparam("acc", "report_cancels", 1)<br>
/* by default ww do not adjust the direct of the sequential requests.<br> if you enable this parameter, be sure the enable "append_fromtag"<br> in "rr" module */<br>modparam("acc", "detect_direction", 0)<br>
/* account triggers (flags) */<br>modparam("acc", "failed_transaction_flag", 3)<br>modparam("acc", "log_flag", 1)<br>modparam("acc", "log_missed_flag", 2)<br>modparam("acc", "log_extra", <br>
"src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")<br>/* enhanced DB accounting */<br>#!ifdef WITH_ACCDB<br>modparam("acc", "db_flag", 1)<br>modparam("acc", "db_missed_flag", 2)<br>
modparam("acc", "db_url",<br> "mysql://openser:openserrw@localhost/openser")<br>modparam("acc", "db_extra",<br> "src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")<br>
#!endif<br><br># ----- usrloc params -----<br>/* enable DB persistency for location entries */<br>#!ifdef WITH_USRLOCDB<br>modparam("usrloc", "db_mode", 2)<br>modparam("usrloc", "db_url",<br>
"mysql://openser:openserrw@localhost/openser")<br>#!endif<br><br># ----- auth_db params -----<br>/* enable the DB based authentication */<br>#!ifdef WITH_AUTH<br>modparam("auth_db", "calculate_ha1", yes)<br>
modparam("auth_db", "password_column", "password")<br>modparam("auth_db", "db_url",<br> "mysql://openser:openserrw@localhost/openser")<br>modparam("auth_db", "load_credentials", "")<br>
#!endif<br><br># ----- alias_db params -----<br>/* uncomment the following lines if you want to enable the DB based<br> aliases */<br>#modparam("alias_db", "db_url",<br># "mysql://openser:openserrw@localhost/openser")<br>
<br><br># ----- domain params -----<br>/* uncomment the following lines to enable multi-domain detection<br> support */<br>#modparam("domain", "db_url",<br># "mysql://openser:openserrw@localhost/openser")<br>
#modparam("domain", "db_mode", 1) # Use caching<br><br><br># ----- multi-module params -----<br>/* uncomment the following line if you want to enable multi-domain support<br> in the modules (dafault off) */<br>
#modparam("alias_db|auth_db|usrloc|uri_db", "use_domain", 1)<br><br><br># ----- presence params -----<br>/* enable presence server support */<br>#!ifdef WITH_PRESENCE<br>modparam("presence|presence_xml", "db_url",<br>
"mysql://openser:openserrw@localhost/openser")<br>modparam("presence_xml", "force_active", 1)<br>modparam("presence", "server_address", "sip:<a href="http://10.0.0.10:5060" target="_blank">10.0.0.10:5060</a>")<br>
#!endif<br><br># ----- nathelper -----<br>#!ifdef WITH_NAT<br>modparam("nathelper", "rtpproxy_sock", "udp:<a href="http://127.0.0.1:7722" target="_blank">127.0.0.1:7722</a>")<br>modparam("nathelper", "natping_interval", 30)<br>
modparam("nathelper", "ping_nated_only", 1)<br>modparam("nathelper", "sipping_bflag", 7)<br>modparam("nathelper", "sipping_from", "<a href="mailto:sip%3Apinger@kamailio.org" target="_blank">sip:pinger@kamailio.org</a>")<br>
modparam("registrar|nathelper", "received_avp", "$avp(i:80)")<br>modparam("usrloc", "nat_bflag", 6)<br>#!endif<br><br># ----- cpl --------<br>modparam("cpl-c","db_url","mysql://openser:openserrw@localhost/openser")<br>
modparam("cpl-c","cpl_dtd_file","/etc/kamailio/cpl-06.dtd")<br>modparam("cpl-c","log_dir","/var/log/kamailio/cpl")<br># ----- cpl --------<br><br>####### Routing Logic ########<br>
<br>route{<br><br> if (!mf_process_maxfwd_header("10")) {<br> sl_send_reply("483","Too Many Hops");<br> exit;<br> }<br><br> if(!sanity_check("1511", "7"))<br>
{<br> xlog("Malformed SIP message from $si:$sp\n");<br> exit;<br> }<br><br> # NAT detection<br> route(NAT);<br><br> if (has_totag()) {<br> # sequential request withing a dialog should<br>
# take the path determined by record-routing<br> if (loose_route()) {<br> if (is_method("BYE")) {<br> setflag(1); # do accounting ...<br> setflag(3); # ... even if the transaction fails<br>
}<br> route(RELAY);<br> } else {<br> if (is_method("SUBSCRIBE") && uri == myself) {<br> # in-dialog subscribe requests<br> route(PRESENCE);<br>
exit;<br> }<br> if ( is_method("ACK") ) {<br> if ( t_check_trans() ) {<br> # non loose-route, but stateful ACK; must be an ACK after a 487 or e.g. 404 from upstream server<br>
t_relay();<br> exit;<br> } else {<br> # ACK without matching transaction ... ignore and discard.\n");<br> exit;<br> }<br>
}<br> sl_send_reply("404","Not here");<br> }<br> exit;<br> }<br><br> #initial requests<br><br> # CANCEL processing<br> if (is_method("CANCEL"))<br>
{<br> if (t_check_trans())<br> t_relay();<br> exit;<br> }<br><br> t_check_trans();<br><br> # authentication<br> route(AUTH);<br><br> # record routing for dialog forming requests (in case they are routed)<br>
# - remove preloaded route headers<br> remove_hf("Route");<br> if (is_method("INVITE|SUBSCRIBE"))<br> record_route();<br><br> # account only INVITEs<br> if (is_method("INVITE")) {<br>
setflag(1); # do accounting<br> }<br> if (!uri==myself)<br> /* replace with following line if multi-domain support is used */<br> ##if (!is_uri_host_local())<br> {<br> append_hf("P-hint: outbound\r\n"); <br>
route(RELAY);<br> }<br><br> # requests for my domain<br><br> if( is_method("PUBLISH|SUBSCRIBE"))<br> route(PRESENCE);<br><br> if (is_method("REGISTER"))<br> {<br> if(isflagset(5))<br>
{<br> setbflag("6");<br> # uncomment next line to do SIP NAT pinging <br> ## setbflag("7");<br> }<br> if (!save("location"))<br> sl_reply_error();<br>
<br> exit;<br> }<br><br> if ($rU==$null) {<br> # request with no Username in RURI<br> sl_send_reply("484","Address Incomplete");<br> exit;<br> }<br><br> route(PSTN);<br>
<br> # apply DB based aliases (uncomment to enable)<br> ##alias_db_lookup("dbaliases");<br><br> if (!lookup("location")) {<br> switch ($rc) {<br> case -1:<br> case -3:<br>
t_newtran();<br> t_reply("404", "Not Found");<br> exit;<br> case -2:<br> sl_send_reply("405", "Method Not Allowed");<br>
exit;<br> }<br> }<br><br> # when routing via usrloc, log the missed calls also<br> setflag(2);<br> <br> route(RELAY);<br>}<br><br><br>route[RELAY] {<br>#!ifdef WITH_NAT<br> if (check_route_param("nat=yes")) {<br>
setbflag("6");<br> }<br> if (isflagset(5) || isbflagset("6")) {<br> route(RTPPROXY);<br> }<br>#!endif<br><br> /* example how to enable some additional event routes */<br> if (is_method("INVITE")) {<br>
#t_on_branch("BRANCH_ONE");<br> xlog("--kh-- before cpl call");<br> cpl_run_script("incoming", "force_stateful");<br> xlog("--kh-- after cpl call");<br>
t_on_reply("REPLY_ONE");<br> t_on_failure("FAIL_ONE");<br> }<br><br> if (!t_relay()) {<br> sl_reply_error();<br> }<br> exit;<br>}<br><br><br># Presence server route<br>
route[PRESENCE]<br>{<br>#!ifdef WITH_PRESENCE<br> if (!t_newtran())<br> {<br> sl_reply_error();<br> exit;<br> };<br><br> if(is_method("PUBLISH"))<br> {<br> handle_publish();<br>
t_release();<br> }<br> else<br> if( is_method("SUBSCRIBE"))<br> {<br> handle_subscribe();<br> t_release();<br> }<br> exit;<br>#!endif<br> <br> # if presence enabled, this part will not be executed<br>
if (is_method("PUBLISH") || $rU==$null)<br> {<br> sl_send_reply("404", "Not here");<br> exit;<br> }<br> return;<br>}<br><br># Authentication route<br>route[AUTH] {<br>
#!ifdef WITH_AUTH<br> if (is_method("REGISTER"))<br> {<br> # authenticate the REGISTER requests (uncomment to enable auth)<br> if (!www_authorize("", "subscriber"))<br> {<br>
www_challenge("", "0");<br> exit;<br> }<br><br> if ($au!=$tU)<br> {<br> sl_send_reply("403","Forbidden auth ID");<br> exit;<br>
}<br> } else {<br> # authenticate if from local subscriber (uncomment to enable auth)<br> if (from_uri==myself)<br> {<br> if (!proxy_authorize("", "subscriber")) {<br>
proxy_challenge("", "0");<br> exit;<br> }<br> if (is_method("PUBLISH"))<br> {<br> if ($au!=$tU) {<br> sl_send_reply("403","Forbidden auth ID");<br>
exit;<br> }<br> } else {<br> if ($au!=$fU) {<br> sl_send_reply("403","Forbidden auth ID");<br> exit;<br>
}<br> }<br><br> consume_credentials();<br> # caller authenticated<br> }<br> }<br>#!endif<br> return;<br>}<br><br># Caller NAT detection route<br>route[NAT]{<br>
#!ifdef WITH_NAT<br> force_rport();<br> if (nat_uac_test("19")) {<br> if (method=="REGISTER") {<br> fix_nated_register();<br> } else {<br> fix_nated_contact();<br>
}<br> setflag(5);<br> }<br>#!endif<br> return;<br>}<br><br># RTPProxy control<br>route[RTPPROXY] {<br>#!ifdef WITH_NAT<br> if (is_method("BYE")) {<br> unforce_rtp_proxy();<br> } else if (is_method("INVITE")){<br>
force_rtp_proxy();<br> }<br> if (!has_totag()) add_rr_param(";nat=yes");<br>#!endif<br> return;<br>}<br><br># PSTN GW routing<br>route[PSTN] {<br>#!ifdef WITH_PSTN<br> # check if PSTN GW IP is defined<br>
if (strempty($sel(cfg_get.pstn.gw_ip))) {<br> xlog("SCRIPT: PSTN rotuing enabled but pstn.gw_ip not defined\n");<br> return;<br> }<br><br> # route to PSTN dialed numbers starting with '+' or '00'<br>
# (international format)<br> # - update the condition to match your dialing rules for PSTN routing<br> if(!($rU=~"^(\+|00)[1-9][0-9]{3,20}$"))<br> return;<br><br> # only local users allowed to call<br>
if(from_uri!=myself) {<br> sl_send_reply("403", "Not Allowed");<br> exit;<br> }<br><br> $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip);<br><br> route(RELAY);<br>
exit;<br>#!endif<br><br> return;<br>}<br><br># Sample branch router<br>branch_route[BRANCH_ONE] {<br> xdbg("new branch at $ru\n");<br>}<br><br># Sample onreply route<br>onreply_route[REPLY_ONE] {<br> xdbg("incoming reply\n");<br>
#!ifdef WITH_NAT<br> if ((isflagset(5) || isbflagset("6")) && status=~"(183)|(2[0-9][0-9])") {<br> force_rtp_proxy();<br> }<br> if (isbflagset("6")) {<br> fix_nated_contact();<br>
}<br>#!endif<br>}<br><br># Sample failure route<br>failure_route[FAIL_ONE] {<br>#!ifdef WITH_NAT<br> if (is_method("INVITE")<br> && (isbflagset("6") || isflagset(5))) {<br> unforce_rtp_proxy();<br>
}<br>#!endif<br><br> if (t_is_canceled()) {<br> exit;<br> }<br><br><br>}<br>
<br>
</div><br><br clear="all"><br>-- <br>Karl Harris<br><br>