paquete genérico sip para enviar notfounds random no mapeo de extensiós
This commit is contained in:
parent
3452ce58ee
commit
b86f811bf9
16
src/main.rs
16
src/main.rs
@ -5,7 +5,7 @@
|
||||
*/
|
||||
pub mod sip;
|
||||
|
||||
use crate::sip::forbidden::*;
|
||||
use crate::sip::generic::*;
|
||||
use crate::sip::not_found::*;
|
||||
use crate::sip::options::*;
|
||||
use crate::sip::register::*;
|
||||
@ -79,7 +79,7 @@ impl Server {
|
||||
let register = Register::parse(&msg);
|
||||
|
||||
// responde aleatoriamente unauthorized (a ext. existe)
|
||||
// ou forbidden (non existe)
|
||||
// ou un notfound genérico (non existe)
|
||||
let mut num = rand::thread_rng().gen_range(0..1000);
|
||||
|
||||
//To: "6666666666"<sip:6666666666@xinu.me>
|
||||
@ -114,6 +114,7 @@ impl Server {
|
||||
server: Some("Asterisk PBX 18.9.0".to_string()),
|
||||
content_length: Some(0)
|
||||
};
|
||||
// println!("{}", std::str::from_utf8(&unauthorized.serialize()).unwrap());
|
||||
let amt = socket.send_to(&unauthorized.serialize(), &peer).await?;
|
||||
println!(
|
||||
"Unauthorized: Sent {}/{} bytes to {}",
|
||||
@ -122,8 +123,8 @@ impl Server {
|
||||
peer
|
||||
);
|
||||
} else {
|
||||
let forbidden = Forbidden {
|
||||
command: "SIP/2.0 403 Forbidden".to_string(),
|
||||
let notfound = Generic {
|
||||
command: "SIP/2.0 404 NotFound".to_string(),
|
||||
via: register.via,
|
||||
call_id: register.call_id,
|
||||
from: register.from,
|
||||
@ -132,11 +133,12 @@ impl Server {
|
||||
server: Some("Asterisk PBX 18.9.0".to_string()),
|
||||
content_length: Some(0)
|
||||
};
|
||||
let amt = socket.send_to(&forbidden.serialize(), &peer).await?;
|
||||
// println!("{}", std::str::from_utf8(¬found.serialize()).unwrap());
|
||||
let amt = socket.send_to(¬found.serialize(), &peer).await?;
|
||||
println!(
|
||||
"Forbidden: Sent {}/{} bytes to {}",
|
||||
"NotFound: Sent {}/{} bytes to {}",
|
||||
amt,
|
||||
&forbidden.serialize().len(),
|
||||
¬found.serialize().len(),
|
||||
peer
|
||||
);
|
||||
}
|
||||
|
46
src/sip/forbidden.rs
Normal file
46
src/sip/forbidden.rs
Normal file
@ -0,0 +1,46 @@
|
||||
// SIP/2.0 403 Forbidden
|
||||
// Via: SIP/2.0/UDP 127.0.1.1:5060;rport=65476;received=185.179.142.180;branch=z9hG4bK-457882779
|
||||
// Call-ID: 2112593047
|
||||
// From: "6666666667" <sip:6666666667@xinu.me>;tag=363636363636363636370133303731363137323935
|
||||
// To: "6666666667" <sip:6666666667@xinu.me>;tag=z9hG4bK-457882779
|
||||
// CSeq: 1 REGISTER
|
||||
// Server: Asterisk PBX 18.9.0
|
||||
// Content-Length: 0
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Forbidden {
|
||||
pub command: String, // SIP/2.0 403 Forbidden
|
||||
pub via: String, // SIP/2.0/UDP 127.0.1.1:5061;branch=z9hG4bK-487618168;rport
|
||||
pub call_id: Option<String>, // Call-ID: 447615548427934163033914
|
||||
pub from: String, // "sipvicious"<sip:100@1.1.1.1>;tag=37663030303030313133633401393537303038303638
|
||||
pub to: String, // "sipvicious"<sip:100@1.1.1.1>
|
||||
pub cseq: String, // 1 OPTIONS
|
||||
pub server: Option<String>, // Asterisk PBX 18.9.0
|
||||
pub content_length: Option<i32>, // 0
|
||||
}
|
||||
|
||||
impl Forbidden {
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
let mut preout = format!(
|
||||
"{}
|
||||
Via: {}
|
||||
Call-ID: {}
|
||||
From: {}
|
||||
To: {}
|
||||
CSeq: {}
|
||||
Server: {}
|
||||
Content-Length: {}",
|
||||
&self.command,
|
||||
&self.via,
|
||||
&self.call_id.as_ref().unwrap(),
|
||||
&self.from,
|
||||
&self.to,
|
||||
&self.cseq,
|
||||
&self.server.as_ref().unwrap(),
|
||||
&self.content_length.unwrap().to_string(),
|
||||
);
|
||||
preout.push_str("\n\n\n");
|
||||
// println!("{}", preout);
|
||||
preout.as_bytes().to_vec()
|
||||
}
|
||||
}
|
39
src/sip/generic.rs
Normal file
39
src/sip/generic.rs
Normal file
@ -0,0 +1,39 @@
|
||||
// Para enviar respostas xenéricas
|
||||
// un "vale para todo"
|
||||
#[derive(Debug)]
|
||||
pub struct Generic {
|
||||
pub command: String,
|
||||
pub via: String,
|
||||
pub call_id: Option<String>,
|
||||
pub from: String,
|
||||
pub to: String,
|
||||
pub cseq: String,
|
||||
pub server: Option<String>,
|
||||
pub content_length: Option<i32>,
|
||||
}
|
||||
|
||||
impl Generic {
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
let mut preout = format!(
|
||||
"{}
|
||||
Via: {}
|
||||
Call-ID: {}
|
||||
From: {}
|
||||
To: {}
|
||||
CSeq: {}
|
||||
Server: {}
|
||||
Content-Length: {}",
|
||||
&self.command,
|
||||
&self.via,
|
||||
&self.call_id.as_ref().unwrap(),
|
||||
&self.from,
|
||||
&self.to,
|
||||
&self.cseq,
|
||||
&self.server.as_ref().unwrap(),
|
||||
&self.content_length.unwrap().to_string(),
|
||||
);
|
||||
preout.push_str("\n\n\n");
|
||||
// println!("{}", preout);
|
||||
preout.as_bytes().to_vec()
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
pub mod forbidden;
|
||||
pub mod generic;
|
||||
pub mod not_found;
|
||||
pub mod options;
|
||||
pub mod register;
|
||||
|
Loading…
Reference in New Issue
Block a user