~liz/yooper

064791f233f5d3e3a7b3c7188ca9f22357dedce8 — Ellie Frost 2 years ago 550163c
Add MAN and Host fields
3 files changed, 30 insertions(+), 3 deletions(-)

M yooper/src/discovery.rs
M yooper/src/ssdp/message.rs
M yooper/src/ssdp/message/types.rs
M yooper/src/discovery.rs => yooper/src/discovery.rs +5 -2
@@ 16,7 16,8 @@ use futures::sink::SinkExt;

use crate::{
    ssdp::message::{
        Codec, Message, MSearch
        Codec, Message, MSearch,

    },
    Error,
};


@@ 67,10 68,12 @@ impl Discovery {
                max_wait: Some(secs.to_string()),
                target: "ssdp:all".into(),
                user_agent: Some(self.user_agent.clone()),
                host: format!("{}:{}", SSDP_ADDRESS, SSDP_PORT),

                tcp_port: None,
                friendly_name: Some("yooper".into()),
                uuid: Some(self.uuid.to_string()),

                ..Default::default()
            }
        );


M yooper/src/ssdp/message.rs => yooper/src/ssdp/message.rs +6 -1
@@ 4,13 4,18 @@ pub(self) mod types;
use crate::ssdp::packet::{FromHeaders, FromPacket, ToHeaders, ToPacket};
pub use codec::Codec;

#[derive(ToHeaders, FromHeaders, Debug, PartialEq)]
#[derive(ToHeaders, FromHeaders, Debug, PartialEq, Default)]
pub struct MSearch {
    /// Maximum wait time in seconds. shall be greater than or equal to 1 and should
    /// be less than 5 inclusive.
    #[header("cache-control")]
    pub max_wait: Option<String>,
    /// Field value contains Search Target.

    pub host: String,

    pub man: types::ManDiscover,

    // TODO: enum
    #[header("st")]
    pub target: String,

M yooper/src/ssdp/message/types.rs => yooper/src/ssdp/message/types.rs +19 -0
@@ 19,3 19,22 @@ impl FromStr for Ext {
        }
    }
}

#[derive(PartialEq, Debug, Default)]
pub struct ManDiscover;

impl ToString for ManDiscover{
    fn to_string(&self) -> String {
        String::from("ssdp:discover")
    }
}

impl FromStr for ManDiscover {
    type Err = Error;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "ssdp:discover" => Ok(Self {}),
            _ => Err(Error::IncorrectHeader("man")),
        }
    }
}