[Serusers] help cpl-c. forwarding just do as redirect!

jacky jacklyman at sohu.com
Fri Dec 3 06:08:01 CET 2004


I have two CPL scripts, redirect work fine, but forwarding work as redirect! 
My ser from CVS. ua is SJphone-252.

this is redirect.xml for sip:100004 at 192.168.2.77, when i invited 100004, redirect to 100003
------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE cpl PUBLIC '-//IETF//DTD RFCxxxx CPL 1.0//EN' 'cpl.dtd'>

 <cpl>
   <incoming>
     <location url="sip:100004 at 192.168.2.77">
       <redirect/>
     </location>
   </incoming>
 </cpl>
---------------------------------------------------

this is forwarding.xml for sip:100002 at 192.168.2.77. I have use tcpdump on sip proxy, not find invite request send to 100002. as redirect, sip proxy after receive invite request, as soon as send to 100003.

-------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE cpl PUBLIC '-//IETF//DTD RFCxxxx CPL 1.0//EN' 'cpl.dtd'>

<cpl>
   <subaction id="voicemail">
       <location url="sip:100003 at 192.168.2.77">
          <proxy/>
       </location>
   </subaction>
   <incoming>
      <location url="sip:100003 at 192.168.2.77">
         <proxy timeout="8">
             <busy>
                <sub ref="voicemail"/>
             </busy>
             <noanswer>
                <sub ref="voicemail"/>
             </noanswer>
         </proxy>
      </location>
   </incoming>
</cpl>
-------------------------------------------------


this is my ser.cfg,  in ser log. not find serror.

-------------------------------------------------
#
# $Id: ser.cfg,v 1.21 2003/06/04 13:47:36 jiri Exp $
#
# simple quick-start config script
#

# ----------- global configuration parameters ------------------------

debug=8  # debug level 3 (cmd line: -dddddddddd)
fork=yes
log_stderror=no # (cmd line: -E)


# Uncomment these lines to enter debugging mode 
/*
debug=8
fork=no
log_stderror=yes
*/

check_via=no # (cmd. line: -v)
dns=no           # (cmd. line: -r)
rev_dns=no      # (cmd. line: -R)
port=16800
children=4
fifo="/tmp/ser_fifo"
disable_core_dump=1
alias=192.168.2.77

# ------------------ module loading ----------------------------------

# Uncomment this if you want to use SQL database
loadmodule "/usr/local/lib/ser/modules/mysql.so"
loadmodule "/usr/local/lib/ser/modules/sl.so"
loadmodule "/usr/local/lib/ser/modules/tm.so"
loadmodule "/usr/local/lib/ser/modules/rr.so"
loadmodule "/usr/local/lib/ser/modules/maxfwd.so"
loadmodule "/usr/local/lib/ser/modules/usrloc.so"
loadmodule "/usr/local/lib/ser/modules/registrar.so"
loadmodule "/usr/local/lib/ser/modules/textops.so"
loadmodule "/usr/local/lib/ser/modules/auth.so"
loadmodule "/usr/local/lib/ser/modules/auth_db.so"
loadmodule "/usr/local/lib/ser/modules/auth_radius.so"
loadmodule "/usr/local/lib/ser/modules/enum.so"
loadmodule "/usr/local/lib/ser/modules/nathelper.so"
loadmodule "/usr/local/lib/ser/modules/acc.so"
loadmodule "/usr/local/lib/ser/modules/cpl-c.so"

modparam("registrar", "nat_flag", 6)
modparam("registrar", "max_expires", 1200)
modparam("registrar", "min_expires", 300)
modparam("registrar", "default_expires", 1200)
modparam("usrloc", "db_mode",   0)
modparam("usrloc", "db_mode", 2)
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
modparam("rr", "enable_full_lr", 1)
modparam("nathelper", "natping_interval", 10)
modparam("nathelper", "ping_nated_only", 1)
modparam("tm", "fr_timer", 60 )
modparam("tm", "fr_inv_timer", 120 )
modparam("acc", "log_level", 1)
modparam("acc", "radius_flag", 1)

modparam("cpl-c","cpl_db","mysql://ser:heslo@localhost/ser")
modparam("cpl-c","cpl_table","cpl")
modparam("cpl-c","cpl_dtd_file","/usr/local/etc/ser/cpl-06.dtd")
modparam("cpl-c","log_dir","/var/log/")
modparam("cpl-c","proxy_recurse",0)
##modparam("cpl-c","proxy_route",1)
modparam("cpl-c","nat_flag",6)

# -------------------------  request routing logic -------------------

# main routing logic

route{
 log(1, "-------------------------------------------\n");
 log(1, "entering main loop\n");

 # initial sanity checks -- messages with
 # max_forwards==0, or excessively long requests
 if (!mf_process_maxfwd_header("10")) {
  sl_send_reply("483","Too Many Hops");
  break;
 };

 if (msg:len > max_len) {
 #if (len_gt( max_len )) {
  sl_send_reply("513", "Message too big");
  break;
 };
 
 if (nat_uac_test("2")) {
  log(1, "src address different than via header->NAT detected\n");
  log(1, "force_rport and fix_nated_contact and setflag(5)\n");
  #try NAT traversal, works only if the client is symmetrical
  force_rport();
  fix_nated_contact();
  append_hf("P-hint: fixed NAT contact for request\r\n");
  # flag 5 indicates that incoming request is from NATed client
  setflag(5);
 };

 setflag(1);
 setflag(2);

 

# create transaction state; abort if error occured
# if ( !t_newtran()) {
#  sl_reply_error();
#  break;
# };
 if (!method=="REGISTER") {
  record_route();
 };

# if the request is for other domain use UsrLoc
# (in case, it does not work, use the following command
# with proper names and addresses in it)

 if (uri==myself) {

    if (method=="REGISTER") {
       log(1, "analyzing REGISTER request\n");
       log(1, "About to register cpl script\n");
       if(!cpl_process_register()) {
           log(1, "Error: fail cpl registering\n");
           break;
       }
       # Uncomment this if you want to use digest authentication
       if (!radius_www_authorize("192.168.2.77")) {
          log(1,"radius_www_authorize fail\n");
          www_challenge("192.168.2.77", "0");
          break;
       };

       if (isflagset(5)) {
          #register from nated client, save nat_flag=6
                 #in location table
          setflag(6);
       };

       if (!save("location")) {
          log(1, "save location error\n");
          sl_send_reply("404", "Not Find User");
          break;
       };
       break;
    };

    lookup("aliases");

    if (method=="INVITE") {

          if(!cpl_run_script("incoming","force_stateful"))
          {
                log(1,"cpl_run_script fail\n"); 
                break;
          };
 
    };
    # native SIP destinations are handled using our USRLOC DB
    if (!lookup("location")) {
       # handle user which was not found
       log(1, "requested user not found\n");
       route(4);
       break;
    };
 };

 #add failure route which should be performed if response code >=300
 if  (method=="INVITE" && isflagset(4)) {
    log(1, "invite for voicemail user->initiate failureroute[1]\nn");
    t_on_failure("1");
 };

 # forward to current uri now; use stateful forwarding; that
 # works reliably even if we forward from TCP to UDP

 route(1);
}

route[1]{
 log(1, "-------------------------------------------\n");
 log(1, "entering route[1] - relaying SIP message\n");
 if ((isflagset(5)) || (isflagset(6))) {
    log(1, "at least one of the participants is NATed->record_route\n");
    record_route();
    log(1, "     -->setting up reply processing ->onreply_route[1]");
    t_on_reply("1");
    if (method=="INVITE") {
       log(1, "     INVITE request-->force_rtp_proxy, set NATED-INVITE flag(7)");
       force_rtp_proxy();
       append_hf("P-hint: request forced to rtp proxy\r\n");
       setflag(7);
    };
 };

 log(1, "relaying message ...\n");
 if (!t_relay()) {
    log(1, "t_relay error occured\n");
    sl_reply_error();
 };

}

# all incoming replies for t_onrepli-ed transactions enter here
onreply_route[1] {
 log(1, "-------------------------------------------\n");
 log(1, "onreply_route[1] entered\n");

 if (isflagset(6)) {
    log(1, "transaction was sent to a NATED client -> fix nated contact\n");
    fix_nated_contact();
    append_hf("P-hint: fixed NAT contact for response\r\n");
 }

 if ( (status=~"100") ) {
    log(1, "status 100 received\n");
 };

 if ( (status=~"180") ) {
    log(1, "status 180 received\n");
 };

 if ( (status=~"202") ) {
    log(1, "status 202 received\n");
 };

 if ( (status=~"200" || status=~"183") ) {
    log(1, "status 2xx or 183");
    if ( isflagset(7) ) {
       log(1, "marked(7) as NATED-INVITE -> force_rtp_proxy \n");
       force_rtp_proxy();
       append_hf("P-hint: response forced to rtp proxy\r\n");
    };
 };
}

route[4]{
 log(1, "-------------------------------------------\n");
 log(1, "entering route[4] = requested user not online\n");
 # non-Voip -- just send "off-line"
 if (!(method == "INVITE" || method == "ACK" || method == "CANCEL" || method == "REFER" || method == "BYE")) {
   log(1, "no invite,ack,cancel,refer->return 404\n");
   sl_send_reply("404", "Not Found");
   break;
 };

 # not voicemail subscriber and no echo/conference call
 if ( isflagset(4)) {
    log(1, "flag(4) active\n");
 };
 if (uri =~ "conference") {
    log(1, "conference call\n");
 };
 if (uri =~ "echo") {
    log(1, "echo call\n");
 };
 if ( !( isflagset(4) || (uri =~ "conference") || (uri =~ "echo") ) ) {
    log(1, "no voicemail subscriber->return 404");
    sl_send_reply("404", "Not Found and no voicemail turned on");
    break;
 };

 if ( isflagset(5) ) {
    log(1, "caller is NATed->record_route\n");
    record_route();
    log(1, "     -->setting up reply processing ->onreply_route[1]\n");
    t_on_reply("1");
    if (method=="INVITE") {
       log(1, "     INVITE request-->force_rtp_proxy\n");
       force_rtp_proxy();
    };
 };
}



failure_route[1] {
 /* XX: note: unsafe if preloaded routes without username used */
 log(1, "-------------------------------------------\n");
 log(1, "failureroute[1] entered");
 revert_uri();
 #rewritehostport("machtnix.ict.tuwien.ac.at:5060");
 # append_branch();
 ##t_relay_to_udp("192.168.2.77", "5060");
 ##sl_send_reply("404", "Not Found");
 break;
}


-------------------------------------------------



More information about the sr-users mailing list