xadhoom left a comment (kamailio/kamailio#4301)
In the end, since to properly un-topos it needs some step and my C knowledge is not that good, I was able to do it from the script.
For example: ``` route[MANGLE_REFER] { if (!has_totag()) return;
if (!is_method("REFER")) return;
if ($rt ne "") { $var(hdrs) = $(rt{uri.headers}); $var(hdrs) = $(var(hdrs){s.urldecode.param}); $var(uri-user) = $(rt{uri.user});
if ($(var(hdrs){param.in,Replaces,&}) == 0) { xlog("L_DBG", "Detected blind transfer to $rt skipping mangling \n"); return; }
$var(replaces) = $(var(hdrs){param.value,Replaces,&}); $var(from-tag) = $(var(replaces){param.value,from-tag}); $var(to-tag) = $(var(replaces){param.value,to-tag}); $var(call-id) = $(var(replaces){s.select,0,;});
xlog("L_DBG", "Got Refer-To: $rt \n"); xlog("L_DBG", "Got Refer-To headers $var(hdrs) \n"); xlog("L_DBG", "Got Refer-To replaces $var(replaces) \n"); xlog("L_DBG", "Got Refer-To uri user $var(uri-user) \n"); xlog("L_DBG", "Got Refer-To call-id $var(call-id) \n"); xlog("L_DBG", "Got Refer-To from tag $var(from-tag) \n"); xlog("L_DBG", "Got Refer-To to tag $var(to-tag) \n");
$var(query) = $_s(SELECT b_contact FROM topos_d WHERE a_callid = '$var(call-id)' AND a_uuid = '$var(uri-user)'); sql_xquery("conn1", "$var(query)", "topos_rset"); switch ($rc) { case 1: xlog("L_DBG", "B-Contact for refer is $xavp(topos_rset=>b_contact)\n"); break; case -1: xlog("L_ERR", "Error in topos lookup of refer target contact \n"); return; break; default: xlog("L_ERR", "Unhandled result $rc in lookup of refer target contact \n"); return; }
remove_hf("Refer-To");
$var(params) = $_s($var(call-id);to-tag=$var(to-tag);from-tag=$var(from-tag)); $var(params_enc) = $(var(params){s.urlencode.param}); $var(new_replaces) = $_s(Replaces=$var(params_enc));
xlog("L_DBG", "Replacing refer target contact with $var(new_replaces) \n");
append_hf("Refer-To: <$xavp(topos_rset=>b_contact)?$var(new_replaces)>\r\n"); } else { xlog("L_ERR", "Uh? Refer without Refer-To \n");
return; } } ```
and then (for example) in call it from the route WITHIN_DIALOG just before the loose_route relay.
This won't work if call-id is masked, but in my setup I'm not using call-id masking.