fix(proxy-engine): improve inbound SIP routing diagnostics and enrich leg media state reporting

This commit is contained in:
2026-04-14 20:19:34 +00:00
parent 0d82a626b5
commit 88768f0586
46 changed files with 555689 additions and 107 deletions
+46
View File
@@ -273,6 +273,38 @@ pub fn normalize_routing_identity(value: &str) -> String {
digits
}
fn looks_like_phone_identity(value: &str) -> bool {
let digits = value.chars().filter(|c| c.is_ascii_digit()).count();
digits >= 6 && value.chars().all(|c| c.is_ascii_digit() || c == '+')
}
/// Pick the best inbound called-number identity from common SIP headers.
///
/// Some providers deliver the DID in `To` / `P-Called-Party-ID` while the
/// request URI contains an account username. Prefer a phone-like identity when
/// present; otherwise fall back to the request URI user part.
pub fn extract_inbound_called_number(msg: &SipMessage) -> String {
let request_uri = normalize_routing_identity(msg.request_uri().unwrap_or(""));
if looks_like_phone_identity(&request_uri) {
return request_uri;
}
for header_name in [
"P-Called-Party-ID",
"X-Called-Party-ID",
"Diversion",
"History-Info",
"To",
] {
let candidate = normalize_routing_identity(msg.get_header(header_name).unwrap_or(""));
if looks_like_phone_identity(&candidate) {
return candidate;
}
}
request_uri
}
fn parse_numeric_range_value(value: &str) -> Option<(bool, &str)> {
let trimmed = value.trim();
if trimmed.is_empty() {
@@ -636,6 +668,20 @@ mod tests {
assert!(!support.ring_browsers);
}
#[test]
fn extract_inbound_called_number_prefers_did_headers_over_username_ruri() {
let raw = b"INVITE sip:2830573e1@proxy.example SIP/2.0\r\nTo: <sip:+4942116767548@proxy.example>\r\nFrom: <sip:+491701234567@provider.example>;tag=abc\r\nCall-ID: test-1\r\nCSeq: 1 INVITE\r\nContent-Length: 0\r\n\r\n";
let msg = SipMessage::parse(raw).expect("invite should parse");
assert_eq!(extract_inbound_called_number(&msg), "+4942116767548");
}
#[test]
fn extract_inbound_called_number_keeps_phone_ruri_when_already_present() {
let raw = b"INVITE sip:042116767548@proxy.example SIP/2.0\r\nTo: <sip:2830573e1@proxy.example>\r\nFrom: <sip:+491701234567@provider.example>;tag=abc\r\nCall-ID: test-2\r\nCSeq: 1 INVITE\r\nContent-Length: 0\r\n\r\n";
let msg = SipMessage::parse(raw).expect("invite should parse");
assert_eq!(extract_inbound_called_number(&msg), "042116767548");
}
#[test]
fn matches_pattern_supports_numeric_ranges() {
assert!(matches_pattern(