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 "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 秒超时}if (($rs == "200") && !has_body("application/sdp")) {# restore sdp$var(key) = $ci + "+body";cache_fetch("local", $var(key), $var(sdp));xlog("****$var(sdp)\n");$var(key) = $ci + "+length"; cache_fetch("local", $var(key), $var(length));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"); }}
}