From 0960a768e6dd212a24122fabc380856471ac9c19 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Thu, 29 Aug 2024 12:23:18 +0100 Subject: [PATCH] Implement stubs for actual connection manager methods --- Makefile | 2 +- .../control/get_current_connection_ids.xml | 10 ++++++++ .../control/get_current_connection_info.xml | 16 +++++++++++++ .../templates/connection_manager/scpd.xml | 8 +++---- .../src/services/connection_manager.rs | 23 +++++++++++++++---- crates/upnp-serve/src/subscriptions.rs | 15 +++++++++++- 6 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 crates/upnp-serve/src/resources/templates/connection_manager/control/get_current_connection_ids.xml create mode 100644 crates/upnp-serve/src/resources/templates/connection_manager/control/get_current_connection_info.xml diff --git a/Makefile b/Makefile index 9277346..79501fb 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ webui-dev: webui-deps export RQBIT_UPNP_SERVER_ENABLE ?= true export RQBIT_UPNP_SERVER_FRIENDLY_NAME ?= rqbit-dev export RQBIT_HTTP_API_LISTEN_ADDR ?= 0.0.0.0:3030 -CARGO_RUN_FLAGS ?= "" +CARGO_RUN_FLAGS ?= RQBIT_OUTPUT_FOLDER ?= /tmp/scratch RQBIT_POSTGRES_CONNECTION_STRING ?= postgres:///rqbit diff --git a/crates/upnp-serve/src/resources/templates/connection_manager/control/get_current_connection_ids.xml b/crates/upnp-serve/src/resources/templates/connection_manager/control/get_current_connection_ids.xml new file mode 100644 index 0000000..799061f --- /dev/null +++ b/crates/upnp-serve/src/resources/templates/connection_manager/control/get_current_connection_ids.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/crates/upnp-serve/src/resources/templates/connection_manager/control/get_current_connection_info.xml b/crates/upnp-serve/src/resources/templates/connection_manager/control/get_current_connection_info.xml new file mode 100644 index 0000000..95feadb --- /dev/null +++ b/crates/upnp-serve/src/resources/templates/connection_manager/control/get_current_connection_info.xml @@ -0,0 +1,16 @@ + + + + + 0 + 0 + http-get:*:*:DLNA.ORG_OP=01 + + -1 + Output + OK + + + diff --git a/crates/upnp-serve/src/resources/templates/connection_manager/scpd.xml b/crates/upnp-serve/src/resources/templates/connection_manager/scpd.xml index 5304264..9e4cf95 100644 --- a/crates/upnp-serve/src/resources/templates/connection_manager/scpd.xml +++ b/crates/upnp-serve/src/resources/templates/connection_manager/scpd.xml @@ -20,7 +20,7 @@ - + + GetCurrentConnectionIDs diff --git a/crates/upnp-serve/src/services/connection_manager.rs b/crates/upnp-serve/src/services/connection_manager.rs index 469d2d0..4422156 100644 --- a/crates/upnp-serve/src/services/connection_manager.rs +++ b/crates/upnp-serve/src/services/connection_manager.rs @@ -38,7 +38,7 @@ pub(crate) async fn http_handler( } }; - let not_implemented = StatusCode::NOT_IMPLEMENTED.into_response(); + let not_implemented = || StatusCode::NOT_IMPLEMENTED.into_response(); match action.as_ref() { SOAP_ACTION_GET_PROTOCOL_INFO => ( @@ -46,10 +46,23 @@ pub(crate) async fn http_handler( include_str!("../resources/templates/connection_manager/control/get_protocol_info.xml"), ) .into_response(), - SOAP_ACTION_CONNECTION_COMPLETE => not_implemented, - SOAP_ACTION_GET_CURRENT_CONNECTION_INFO => not_implemented, - SOAP_ACTION_GET_CURRENT_CONNECTION_IDS => not_implemented, - SOAP_ACTION_PREPARE_FOR_CONNECTION => not_implemented, + + SOAP_ACTION_GET_CURRENT_CONNECTION_INFO => ( + [(CONTENT_TYPE, CONTENT_TYPE_XML_UTF8)], + include_str!( + "../resources/templates/connection_manager/control/get_current_connection_info.xml" + ), + ) + .into_response(), + SOAP_ACTION_GET_CURRENT_CONNECTION_IDS => ( + [(CONTENT_TYPE, CONTENT_TYPE_XML_UTF8)], + include_str!( + "../resources/templates/connection_manager/control/get_current_connection_ids.xml" + ), + ) + .into_response(), + SOAP_ACTION_PREPARE_FOR_CONNECTION => not_implemented(), + SOAP_ACTION_CONNECTION_COMPLETE => not_implemented(), _ => StatusCode::BAD_REQUEST.into_response(), } } diff --git a/crates/upnp-serve/src/subscriptions.rs b/crates/upnp-serve/src/subscriptions.rs index 16aac67..f3fdd80 100644 --- a/crates/upnp-serve/src/subscriptions.rs +++ b/crates/upnp-serve/src/subscriptions.rs @@ -82,6 +82,19 @@ pub enum SubscribeRequest { }, } +impl core::fmt::Display for SubscribeRequest { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + SubscribeRequest::Create { callback, timeout } => { + write!(f, "create;callback={callback};timeout={timeout:?}") + } + SubscribeRequest::Renew { sid, timeout } => { + write!(f, "renew;sid={sid};timeout={timeout:?}") + } + } + } +} + impl SubscribeRequest { fn timeout(&self) -> Duration { match self { @@ -159,7 +172,7 @@ pub(crate) fn subscription_into_response( request: &SubscribeRequest, result: anyhow::Result, ) -> axum::response::Response { - trace!(?request, ?result, "subscription request->response"); + trace!(%request, ?result, "request->response"); let result = match result { Ok(r) => r,