2023-10-20 04:51:56 +01:00
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
|
|
use crate::JID;
|
|
|
|
|
|
|
|
|
|
pub static XMLNS: &str = "http://etherx.jabber.org/streams";
|
|
|
|
|
pub static XMLNS_CLIENT: &str = "jabber:client";
|
|
|
|
|
|
|
|
|
|
// MUST be qualified by stream namespace
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
|
pub struct Stream<'s> {
|
|
|
|
|
#[serde(rename = "@from")]
|
|
|
|
|
from: Option<&'s JID>,
|
|
|
|
|
#[serde(rename = "@to")]
|
|
|
|
|
to: Option<&'s JID>,
|
|
|
|
|
#[serde(rename = "@id")]
|
|
|
|
|
id: Option<&'s str>,
|
|
|
|
|
#[serde(rename = "@version")]
|
|
|
|
|
version: Option<&'s str>,
|
|
|
|
|
// TODO: lang enum
|
|
|
|
|
#[serde(rename = "@lang")]
|
|
|
|
|
lang: Option<&'s str>,
|
|
|
|
|
#[serde(rename = "@xmlns")]
|
|
|
|
|
xmlns: &'s str,
|
|
|
|
|
#[serde(rename = "@xmlns:stream")]
|
|
|
|
|
xmlns_stream: &'s str,
|
2023-06-19 19:23:54 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-11 21:28:42 +01:00
|
|
|
impl Stream {
|
2023-10-20 04:51:56 +01:00
|
|
|
pub fn new(
|
|
|
|
|
from: Option<&JID>,
|
|
|
|
|
to: Option<&JID>,
|
|
|
|
|
id: Option<&str>,
|
|
|
|
|
version: Option<&str>,
|
|
|
|
|
lang: Option<&str>,
|
|
|
|
|
) -> Self {
|
2023-07-11 21:28:42 +01:00
|
|
|
Self {
|
2023-10-20 04:51:56 +01:00
|
|
|
from,
|
|
|
|
|
to,
|
2023-07-11 21:28:42 +01:00
|
|
|
id,
|
2023-10-20 04:51:56 +01:00
|
|
|
version,
|
2023-07-11 21:28:42 +01:00
|
|
|
lang,
|
2023-10-20 04:51:56 +01:00
|
|
|
xmlns: XMLNS_CLIENT,
|
|
|
|
|
xmlns_stream: XMLNS,
|
2023-07-11 21:28:42 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-20 04:51:56 +01:00
|
|
|
/// For initial stream headers, the initiating entity SHOULD include the 'xml:lang' attribute.
|
|
|
|
|
/// For privacy, it is better to not set `from` when sending a client stanza over an unencrypted connection.
|
|
|
|
|
pub fn new_client(from: Option<&JID>, to: &JID, id: Option<&str>, lang: &str) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
from,
|
|
|
|
|
to: Some(to),
|
|
|
|
|
id,
|
|
|
|
|
version: Some("1.0"),
|
|
|
|
|
lang: Some(lang),
|
|
|
|
|
xmlns: XMLNS_CLIENT,
|
|
|
|
|
xmlns_stream: XMLNS,
|
2023-07-11 21:28:42 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|