Support outbound call

This commit is contained in:
2026-03-29 02:07:39 -04:00
parent 06c8bd9919
commit 0483588af5
4 changed files with 95 additions and 33 deletions

View File

@@ -127,3 +127,32 @@ pub fn list_did() ->Result<Vec<Did>, Error> {
Ok(res)
}
pub fn from_pbx(ipaddr: &str) -> Result<bool, Error> {
use crate::schema::dids::dsl::*;
let pattern = format!("%{}%", ipaddr);
let mut conn = connect();
let count = dids
.filter(target.is_not_null().and(target.ilike(&pattern)))
.count()
.get_result::<i64>(&mut conn)?;
Ok(count > 0)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn validate_from_pbx() {
assert_eq!(Ok(true), from_pbx("172.16.0.213"));
assert_eq!(Ok(true), from_pbx("172.16.0.215"));
}
#[test]
fn validate_not_from_pbx() {
assert_eq!(Ok(false), from_pbx("192.168.1.1"));
}
}