rust/sip: parse and log sdp

If SDP payload is found within a SIP message, it will be parsed and then
logged.

Ticket #6627
pull/10952/head
Giuseppe Longo 12 months ago committed by Victor Julien
parent bff790b6ac
commit 868493529b

@ -18,6 +18,7 @@
// written by Giuseppe Longo <giuseppe@glongo.it>
use crate::jsonbuilder::{JsonBuilder, JsonError};
use crate::sdp::logger::sdp_log;
use crate::sip::sip::SIPTransaction;
fn log(tx: &SIPTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
@ -27,6 +28,10 @@ fn log(tx: &SIPTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.set_string("method", &req.method)?
.set_string("uri", &req.path)?
.set_string("version", &req.version)?;
if let Some(sdp_body) = &req.body {
let _ = sdp_log(sdp_body, js);
}
}
if let Some(req_line) = &tx.request_line {
@ -37,6 +42,9 @@ fn log(tx: &SIPTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.set_string("version", &resp.version)?
.set_string("code", &resp.code)?
.set_string("reason", &resp.reason)?;
if let Some(sdp_body) = &resp.body {
let _ = sdp_log(sdp_body, js);
}
}
if let Some(resp_line) = &tx.response_line {

@ -17,10 +17,11 @@
// written by Giuseppe Longo <giuseppe@glongo.it>
use crate::sdp::parser::{sdp_parse_message, SdpMessage};
use nom7::bytes::streaming::{tag, take, take_while, take_while1};
use nom7::character::streaming::{char, crlf};
use nom7::character::{is_alphabetic, is_alphanumeric, is_digit, is_space};
use nom7::combinator::map_res;
use nom7::combinator::{map_res, opt};
use nom7::sequence::delimited;
use nom7::{Err, IResult, Needed};
use std;
@ -43,6 +44,7 @@ pub struct Request {
pub headers_len: u16,
pub body_offset: u16,
pub body_len: u16,
pub body: Option<SdpMessage>,
}
#[derive(Debug)]
@ -55,6 +57,7 @@ pub struct Response {
pub headers_len: u16,
pub body_offset: u16,
pub body_len: u16,
pub body: Option<SdpMessage>,
}
/**
@ -106,8 +109,9 @@ pub fn sip_parse_request(oi: &[u8]) -> IResult<&[u8], Request> {
let headers_len = hi.len() - phi.len();
let (bi, _) = crlf(phi)?;
let body_offset = oi.len() - bi.len();
let (i, body) = opt(sdp_parse_message)(bi)?;
Ok((
bi,
i,
Request {
method: method.into(),
path: path.into(),
@ -118,6 +122,7 @@ pub fn sip_parse_request(oi: &[u8]) -> IResult<&[u8], Request> {
headers_len: headers_len as u16,
body_offset: body_offset as u16,
body_len: bi.len() as u16,
body,
},
))
}
@ -134,8 +139,9 @@ pub fn sip_parse_response(oi: &[u8]) -> IResult<&[u8], Response> {
let headers_len = hi.len() - phi.len();
let (bi, _) = crlf(phi)?;
let body_offset = oi.len() - bi.len();
let (i, body) = opt(sdp_parse_message)(bi)?;
Ok((
bi,
i,
Response {
version,
code: code.into(),
@ -145,6 +151,7 @@ pub fn sip_parse_response(oi: &[u8]) -> IResult<&[u8], Response> {
headers_len: headers_len as u16,
body_offset: body_offset as u16,
body_len: bi.len() as u16,
body,
},
))
}

Loading…
Cancel
Save