forked from lavina/lavina
				
			feat(xmpp): add stream id
This commit is contained in:
		
							parent
							
								
									99435a020e
								
							
						
					
					
						commit
						fb8329a187
					
				| 
						 | 
					@ -462,6 +462,7 @@ dependencies = [
 | 
				
			||||||
 "tokio-tungstenite",
 | 
					 "tokio-tungstenite",
 | 
				
			||||||
 "tracing",
 | 
					 "tracing",
 | 
				
			||||||
 "tracing-subscriber",
 | 
					 "tracing-subscriber",
 | 
				
			||||||
 | 
					 "uuid",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
| 
						 | 
					@ -1249,6 +1250,15 @@ version = "0.7.6"
 | 
				
			||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
					source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
				
			||||||
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
 | 
					checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "uuid"
 | 
				
			||||||
 | 
					version = "1.3.0"
 | 
				
			||||||
 | 
					source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
				
			||||||
 | 
					checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79"
 | 
				
			||||||
 | 
					dependencies = [
 | 
				
			||||||
 | 
					 "getrandom",
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "valuable"
 | 
					name = "valuable"
 | 
				
			||||||
version = "0.1.0"
 | 
					version = "0.1.0"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,6 +22,7 @@ tokio-rustls = "0.23.4"
 | 
				
			||||||
rustls-pemfile = "1.0.2"
 | 
					rustls-pemfile = "1.0.2"
 | 
				
			||||||
quick-xml = { version = "0.28.1", features = ["async-tokio"] }
 | 
					quick-xml = { version = "0.28.1", features = ["async-tokio"] }
 | 
				
			||||||
derive_more = "0.99.17"
 | 
					derive_more = "0.99.17"
 | 
				
			||||||
 | 
					uuid = { version = "1.3.0", features = ["v4"] }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[dev-dependencies]
 | 
					[dev-dependencies]
 | 
				
			||||||
assert_matches = "1.5.0"
 | 
					assert_matches = "1.5.0"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -194,6 +194,7 @@ async fn socket_force_tls(
 | 
				
			||||||
    let msg = ServerStreamStart {
 | 
					    let msg = ServerStreamStart {
 | 
				
			||||||
        from: "localhost".into(),
 | 
					        from: "localhost".into(),
 | 
				
			||||||
        lang: "en".into(),
 | 
					        lang: "en".into(),
 | 
				
			||||||
 | 
					        id: uuid::Uuid::new_v4().to_string(),
 | 
				
			||||||
        version: "1.0".into(),
 | 
					        version: "1.0".into(),
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    msg.write_xml(xml_writer).await?;
 | 
					    msg.write_xml(xml_writer).await?;
 | 
				
			||||||
| 
						 | 
					@ -225,6 +226,7 @@ async fn socket_auth(
 | 
				
			||||||
    ServerStreamStart {
 | 
					    ServerStreamStart {
 | 
				
			||||||
        from: "localhost".into(),
 | 
					        from: "localhost".into(),
 | 
				
			||||||
        lang: "en".into(),
 | 
					        lang: "en".into(),
 | 
				
			||||||
 | 
					        id: uuid::Uuid::new_v4().to_string(),
 | 
				
			||||||
        version: "1.0".into(),
 | 
					        version: "1.0".into(),
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    .write_xml(xml_writer)
 | 
					    .write_xml(xml_writer)
 | 
				
			||||||
| 
						 | 
					@ -257,6 +259,7 @@ async fn socket_final(
 | 
				
			||||||
    ServerStreamStart {
 | 
					    ServerStreamStart {
 | 
				
			||||||
        from: "localhost".into(),
 | 
					        from: "localhost".into(),
 | 
				
			||||||
        lang: "en".into(),
 | 
					        lang: "en".into(),
 | 
				
			||||||
 | 
					        id: uuid::Uuid::new_v4().to_string(),
 | 
				
			||||||
        version: "1.0".into(),
 | 
					        version: "1.0".into(),
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    .write_xml(xml_writer)
 | 
					    .write_xml(xml_writer)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,7 +14,7 @@ pub static XMLNS_XML: &'static str = "http://www.w3.org/XML/1998/namespace";
 | 
				
			||||||
#[derive(Debug, PartialEq, Eq)]
 | 
					#[derive(Debug, PartialEq, Eq)]
 | 
				
			||||||
pub struct ClientStreamStart {
 | 
					pub struct ClientStreamStart {
 | 
				
			||||||
    pub to: String,
 | 
					    pub to: String,
 | 
				
			||||||
    pub lang: String,
 | 
					    pub lang: Option<String>,
 | 
				
			||||||
    pub version: String,
 | 
					    pub version: String,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
impl ClientStreamStart {
 | 
					impl ClientStreamStart {
 | 
				
			||||||
| 
						 | 
					@ -58,7 +58,7 @@ impl ClientStreamStart {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            Ok(ClientStreamStart {
 | 
					            Ok(ClientStreamStart {
 | 
				
			||||||
                to: to.unwrap(),
 | 
					                to: to.unwrap(),
 | 
				
			||||||
                lang: lang.unwrap(),
 | 
					                lang: lang,
 | 
				
			||||||
                version: version.unwrap(),
 | 
					                version: version.unwrap(),
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
| 
						 | 
					@ -71,6 +71,7 @@ impl ClientStreamStart {
 | 
				
			||||||
pub struct ServerStreamStart {
 | 
					pub struct ServerStreamStart {
 | 
				
			||||||
    pub from: String,
 | 
					    pub from: String,
 | 
				
			||||||
    pub lang: String,
 | 
					    pub lang: String,
 | 
				
			||||||
 | 
					    pub id: String,
 | 
				
			||||||
    pub version: String,
 | 
					    pub version: String,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
impl ServerStreamStart {
 | 
					impl ServerStreamStart {
 | 
				
			||||||
| 
						 | 
					@ -97,6 +98,10 @@ impl ServerStreamStart {
 | 
				
			||||||
                key: QName(b"xml:lang"),
 | 
					                key: QName(b"xml:lang"),
 | 
				
			||||||
                value: self.lang.as_bytes().into(),
 | 
					                value: self.lang.as_bytes().into(),
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					            Attribute {
 | 
				
			||||||
 | 
					                key: QName(b"id"),
 | 
				
			||||||
 | 
					                value: self.id.as_bytes().into(),
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
        event.extend_attributes(attributes.into_iter());
 | 
					        event.extend_attributes(attributes.into_iter());
 | 
				
			||||||
        writer.write_event_async(Event::Start(event)).await?;
 | 
					        writer.write_event_async(Event::Start(event)).await?;
 | 
				
			||||||
| 
						 | 
					@ -176,7 +181,7 @@ mod test {
 | 
				
			||||||
            res,
 | 
					            res,
 | 
				
			||||||
            ClientStreamStart {
 | 
					            ClientStreamStart {
 | 
				
			||||||
                to: "vlnv.dev".to_owned(),
 | 
					                to: "vlnv.dev".to_owned(),
 | 
				
			||||||
                lang: "en".to_owned(),
 | 
					                lang: Some("en".to_owned()),
 | 
				
			||||||
                version: "1.0".to_owned()
 | 
					                version: "1.0".to_owned()
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
| 
						 | 
					@ -187,9 +192,10 @@ mod test {
 | 
				
			||||||
        let input = ServerStreamStart {
 | 
					        let input = ServerStreamStart {
 | 
				
			||||||
            from: "vlnv.dev".to_owned(),
 | 
					            from: "vlnv.dev".to_owned(),
 | 
				
			||||||
            lang: "en".to_owned(),
 | 
					            lang: "en".to_owned(),
 | 
				
			||||||
 | 
					            id: "stream_id".to_owned(),
 | 
				
			||||||
            version: "1.0".to_owned(),
 | 
					            version: "1.0".to_owned(),
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        let expected = r###"<stream:stream from="vlnv.dev" version="1.0" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" xml:lang="en">"###;
 | 
					        let expected = r###"<stream:stream from="vlnv.dev" version="1.0" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" xml:lang="en" id="stream_id">"###;
 | 
				
			||||||
        let mut output: Vec<u8> = vec![];
 | 
					        let mut output: Vec<u8> = vec![];
 | 
				
			||||||
        let mut writer = Writer::new(&mut output);
 | 
					        let mut writer = Writer::new(&mut output);
 | 
				
			||||||
        input.write_xml(&mut writer).await.unwrap();
 | 
					        input.write_xml(&mut writer).await.unwrap();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue