diff --git a/onvif/Cargo.toml b/onvif/Cargo.toml index 3fc16f7..a0cf18b 100644 --- a/onvif/Cargo.toml +++ b/onvif/Cargo.toml @@ -36,7 +36,6 @@ xsd-macro-utils = { git = "https://github.com/lumeohq/xsd-parser-rs", rev = "7f3 xsd-types = { git = "https://github.com/lumeohq/xsd-parser-rs", rev = "7f3d433" } yaserde = "0.7.1" yaserde_derive = "0.7.1" -b_2 = {path = "../wsdl_rs/b_2"} [dev-dependencies] dotenv = "0.15.0" @@ -44,3 +43,4 @@ futures-util = "0.3.8" structopt = "0.3.21" tokio = { version = "1.0.1", features = ["full"] } tracing-subscriber = "0.2.20" +b_2 = {path = "../wsdl_rs/b_2"} diff --git a/onvif/examples/event.rs b/onvif/examples/event.rs index 04ba78a..2c4bd2d 100644 --- a/onvif/examples/event.rs +++ b/onvif/examples/event.rs @@ -52,10 +52,10 @@ async fn main() { let create_pull_sub_request = CreatePullPointSubscription { initial_termination_time: None, filter: Some(b_2::FilterType { - topic_expression: b_2::TopicExpressionType { + topic_expression: Some(b_2::TopicExpressionType { dialect: "http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet".to_string(), inner_text: "tns1:RuleEngine//.".to_string(), - }, + }), }), subscription_policy: None, }; diff --git a/schema/src/tests.rs b/schema/src/tests.rs index 40da2da..b155a30 100644 --- a/schema/src/tests.rs +++ b/schema/src/tests.rs @@ -620,3 +620,88 @@ fn extension_inside_extension() { let _ = yaserde::de::from_str::(ser).unwrap(); } + +#[tokio::test] +async fn operation_pull_messages() { + let req: event::PullMessages = Default::default(); + + let transport = FakeTransport { + response: r#" + + + + + + + + + + + + + "# + .into(), + }; + + let resp = event::pull_messages(&transport, &req).await.unwrap(); + + assert_eq!( + resp.notification_message[0].message.msg.source.simple_item[0].name, + "VideoSourceConfigurationToken" + ); + assert_eq!( + resp.notification_message[0].message.msg.source.simple_item[0].value, + "00000" + ); + assert_eq!( + resp.notification_message[0].message.msg.data.simple_item[0].name, + "IsMotion" + ); + assert_eq!( + resp.notification_message[0].message.msg.data.simple_item[0].value, + "true" + ); +} + +#[tokio::test] +async fn operation_create_pullpoint_subscription() { + let req: event::CreatePullPointSubscription = Default::default(); + + let transport = FakeTransport { + response: r#" + + + + http://192.168.88.108/onvif/Subscription?Idx=162 + + + + 2023-09-26T07:55:05Z + + + 2023-09-26T07:56:05Z + + + "# + .into(), + }; + + let resp = event::create_pull_point_subscription(&transport, &req) + .await + .unwrap(); + + assert_eq!( + resp.subscription_reference.address, + "http://192.168.88.108/onvif/Subscription?Idx=162" + ); +} diff --git a/wsdl_rs/b_2/src/lib.rs b/wsdl_rs/b_2/src/lib.rs index 7edef0d..ba72cd8 100644 --- a/wsdl_rs/b_2/src/lib.rs +++ b/wsdl_rs/b_2/src/lib.rs @@ -41,7 +41,7 @@ impl Validate for TopicExpressionType {} )] pub struct FilterType { #[yaserde(prefix = "wsnt", rename = "TopicExpression")] - pub topic_expression: TopicExpressionType, + pub topic_expression: Option, } impl Validate for FilterType {} @@ -139,7 +139,6 @@ impl Validate for NotificationMessageHolderType {} #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] #[yaserde(prefix = "tt", namespace = "tt: http://www.onvif.org/ver10/schema")] - pub struct SimpleItemType { // Item name. #[yaserde(attribute, rename = "Name")] @@ -157,12 +156,22 @@ pub mod notification_message_holder_type { #[yaserde(prefix = "tt", namespace = "tt: http://www.onvif.org/ver10/schema")] pub struct DataType { #[yaserde(prefix = "tt", rename = "SimpleItem")] - pub simple_item: SimpleItemType, + pub simple_item: Vec, + } + + #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] + #[yaserde(prefix = "tt", namespace = "tt: http://www.onvif.org/ver10/schema")] + pub struct SourceType { + #[yaserde(prefix = "tt", rename = "SimpleItem")] + pub simple_item: Vec, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] #[yaserde(prefix = "tt", namespace = "tt: http://www.onvif.org/ver10/schema")] pub struct MessageTypeInner { + #[yaserde(prefix = "tt", rename = "Source")] + pub source: SourceType, + #[yaserde(prefix = "tt", rename = "Data")] pub data: DataType, }