Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for 400 error for Reolink cameras events #128

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion onvif/src/soap/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl Client {
debug!(?auth_type, %redirections, "About to make request.");

let soap_msg =
soap::soap(message, &username_token).map_err(|e| Error::Protocol(format!("{e:?}")))?;
soap::soap(message, &username_token, &uri).map_err(|e| Error::Protocol(format!("{e:?}")))?;

let mut request = self
.client
Expand Down
8 changes: 7 additions & 1 deletion onvif/src/soap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod tests;
use auth::username_token::UsernameToken;
use schema::soap_envelope;
use xmltree::{Element, Namespace, XMLNode};
use url::Url;

const SOAP_URI: &str = "http://www.w3.org/2003/05/soap-envelope";

Expand All @@ -24,11 +25,12 @@ pub struct Response {
pub response: Option<String>,
}

pub fn soap(xml: &str, username_token: &Option<UsernameToken>) -> Result<String, Error> {
pub fn soap(xml: &str, username_token: &Option<UsernameToken>, uri: &Url) -> Result<String, Error> {
let app_data = parse(xml)?;

let mut namespaces = app_data.namespaces.clone().unwrap_or_else(Namespace::empty);
namespaces.put("s", SOAP_URI);
namespaces.put("a", "http://www.w3.org/2005/08/addressing");

let mut body = Element::new("Body");
body.prefix = Some("s".to_string());
Expand All @@ -44,6 +46,10 @@ pub fn soap(xml: &str, username_token: &Option<UsernameToken>) -> Result<String,
header
.children
.push(XMLNode::Element(parse(&username_token.to_xml())?));
let mut to_el = Element::new("To");
to_el.prefix = Some("a".to_string());
to_el.children.push(XMLNode::Text(uri.as_str().to_owned()));
header.children.push(XMLNode::Element(to_el));
envelope.children.push(XMLNode::Element(header));
}

Expand Down