diff --git a/protocol/rtmp/CHANGELOG.md b/protocol/rtmp/CHANGELOG.md index 8ed9e3a3..1cdc571f 100644 --- a/protocol/rtmp/CHANGELOG.md +++ b/protocol/rtmp/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate +- Fix: RTMP Auth failing due to empty string query string in packet + ## [0.6.3] - 2021-03-15 - Upgrade failure library. - Support querying more detailed statistic data. diff --git a/protocol/rtmp/src/session/server_session.rs b/protocol/rtmp/src/session/server_session.rs index 521ac232..6bbf8ce8 100644 --- a/protocol/rtmp/src/session/server_session.rs +++ b/protocol/rtmp/src/session/server_session.rs @@ -438,7 +438,11 @@ impl ServerSession { let app_name = command_obj.get("app"); self.app_name = match app_name { - Some(Amf0ValueType::UTF8String(app)) => app.clone(), + Some(Amf0ValueType::UTF8String(app)) => { + // the value can weirdly have the query params, lets just remove it + // example: live/stream?token=123 + app.split(&['?', '/']).next().unwrap_or(app).to_string() + } _ => { return Err(SessionError { value: SessionErrorValue::NoAppName, @@ -672,9 +676,28 @@ impl ServerSession { } }; - (self.stream_name, self.query) = - RtmpUrlParser::parse_stream_name_with_query(&stream_name_with_query); - + if !stream_name_with_query.is_empty() { + (self.stream_name, self.query) = + RtmpUrlParser::parse_stream_name_with_query(&stream_name_with_query); + } else { + log::warn!("stream_name_with_query is empty, extracing info from swf_url instead..."); + let mut url = RtmpUrlParser::new( + self.connect_properties + .swf_url + .clone() + .unwrap_or("".to_string()), + ); + + match url.parse_url() { + Ok(_) => { + self.stream_name = url.stream_name; + self.query = url.query; + } + Err(e) => { + log::warn!("Failed to parse swf_url: {e}"); + } + } + } if let Some(auth) = &self.auth { auth.authenticate(&self.stream_name, &self.query, false)? }