Skip to content

Commit

Permalink
sip-ua: Allow handling of 423 errors when registering
Browse files Browse the repository at this point in the history
  • Loading branch information
kbalt committed Sep 13, 2023
1 parent c7ffa78 commit f7e9ae6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
27 changes: 27 additions & 0 deletions crates/sip-types/src/header/typed/expires.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ from_str_header! {
u32
}

from_str_header! {
/// `Min-Expires` header
MinExpires,
Name::MIN_EXPIRES,
u32
}

#[cfg(test)]
mod test {
use super::*;
Expand All @@ -36,4 +43,24 @@ mod test {
let expires: Expires = headers.get_named().unwrap();
assert_eq!(expires, EXPIRES);
}

const MIN_EXPIRES: MinExpires = MinExpires(300);

#[test]
fn print_min_expires() {
let mut headers = Headers::new();
headers.insert_named(&MIN_EXPIRES);
let headers = headers.to_string();

assert_eq!(headers, "Min-Expires: 300\r\n");
}

#[test]
fn parse_min_expires() {
let mut headers = Headers::new();
headers.insert(Name::MIN_EXPIRES, "300");

let min_expires: MinExpires = headers.get_named().unwrap();
assert_eq!(min_expires, MIN_EXPIRES);
}
}
2 changes: 1 addition & 1 deletion crates/sip-types/src/header/typed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub use call_id::CallID;
pub use contact::Contact;
pub use content::{ContentLength, ContentType};
pub use cseq::CSeq;
pub use expires::Expires;
pub use expires::{Expires, MinExpires};
pub use extensions::{Require, Supported};
pub use from_to::FromTo;
pub use max_fwd::MaxForwards;
Expand Down
17 changes: 16 additions & 1 deletion crates/sip-ua/src/register/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::util::{random_sequence_number, random_string};
use sip_core::transaction::TsxResponse;
use sip_core::Request;
use sip_types::header::typed::{CSeq, CallID, Contact, Expires, FromTo};
use sip_types::header::typed::{CSeq, CallID, Contact, Expires, FromTo, MinExpires};
use sip_types::uri::{NameAddr, Uri};
use sip_types::{CodeKind, Method, Name};
use std::time::Duration;
Expand Down Expand Up @@ -80,6 +80,21 @@ impl Registration {
}
}

pub fn receive_error_response(&mut self, response: TsxResponse) -> bool {
if !matches!(response.line.code.kind(), CodeKind::RequestFailure) {
return false;
}

let Ok(expires) = response.headers.get_named::<MinExpires>() else {
return false;
};

self.expires = expires.0;
self.register_interval = create_reg_interval(self.expires);

true
}

pub async fn wait_for_expiry(&mut self) {
self.register_interval.tick().await;
}
Expand Down

0 comments on commit f7e9ae6

Please sign in to comment.