OpenSIPS3.2保存和恢复sdp

UAC                             OpenSIPS            UAS

     --->invite with sdp-->

                                                    --->invite with sdp

                                                    <---183 with sdp

     <--- 183 with sdp

                                                    <--- 200 without sdp

     <---200 without sdp

这是最近碰到的一个case,需要在路由里面做如下处理:

  • 收到183 reply的时候保存sdp
  • 收到200 reply的时候恢复sdp

主要的路由代码如下:

loadmodule "sipmsgops.so"
loadmodule "textops.so"

loadmodule "cachedb_local.so"
modparam("cachedb_local", "cachedb_url", "local://")

...

route[invite] {
    $du = "sip:192.168.1.100"; 
    t_on_branch("per_branch_ops");
    t_on_reply("handle_nat");
    t_on_failure("missed_call");
    t_relay();
    exit;
}

onreply_route[handle_nat] {
	xlog("incoming reply, status = $rs\n");
	# xlog("****$mb\n");

	if (($rs =~ "18[30]") && has_body("application/sdp")) {
	    # save sdp
    	# xlog("****$rb\n");	
		$var(key) = $ci + "body";
		cache_store("local", $var(key), $rb, 120); # 120 秒超时
		$var(key) = $ci + "length";		
		cache_store("local", $var(key), $hdr(Content-Length), 120); # 120 秒超时
	} else if (($rs == "200") && !has_body("application/sdp")) {
        # restore sdp
		$var(key) = $ci + "body";
		cache_fetch("local", $var(key), $var(sdp));
        cache_remove("local", $var(key));
		xlog("****$var(sdp)\n");
		$var(key) = $ci + "length";		
		cache_fetch("local", $var(key), $var(length));
        cache_remove("local", $var(key));
		xlog("****$var(length)\n");
        if (($var(sdp) != NULL) && ($var(length) != NULL)) {
    		insert_hf("Content-Type: application/sdp\r\n", "Call-ID");
	    	insert_hf("Content-Length: $var(length)\r\n", "Call-ID");
    		add_body_part($var(sdp), "application/sdp");		
        }
	}
}

熟悉我的人都知道,我对OpenSIPS不熟,但上面的代码准确无误,先佩服自己一分钟

你可能感兴趣的:(OpenSIPS,OpenSIPS,修复sdp)