Upgrade ruma to revision 237b42

next
Charlotte Som 2021-09-22 11:27:21 +01:00
parent 47f3263396
commit f85ea2d549
13 changed files with 164 additions and 163 deletions

50
Cargo.lock generated
View File

@ -259,6 +259,7 @@ dependencies = [
"ring", "ring",
"rocket", "rocket",
"ruma", "ruma",
"ruma-events",
"rusqlite", "rusqlite",
"rust-argon2", "rust-argon2",
"rustls", "rustls",
@ -1968,7 +1969,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.4.0" version = "0.4.0"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"assign", "assign",
"js_int", "js_int",
@ -1988,8 +1989,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api" name = "ruma-api"
version = "0.18.3" version = "0.18.5"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"bytes", "bytes",
"http", "http",
@ -2004,8 +2005,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api-macros" name = "ruma-api-macros"
version = "0.18.3" version = "0.18.5"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -2016,7 +2017,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-appservice-api" name = "ruma-appservice-api"
version = "0.4.0" version = "0.4.0"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
@ -2029,8 +2030,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.12.2" version = "0.12.3"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"assign", "assign",
"bytes", "bytes",
@ -2050,7 +2051,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.6.0" version = "0.6.0"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"js_int", "js_int",
@ -2064,8 +2065,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events" name = "ruma-events"
version = "0.24.5" version = "0.24.6"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"indoc", "indoc",
"js_int", "js_int",
@ -2080,8 +2081,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events-macros" name = "ruma-events-macros"
version = "0.24.5" version = "0.24.6"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -2092,7 +2093,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.3.1" version = "0.3.1"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -2107,7 +2108,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers" name = "ruma-identifiers"
version = "0.20.0" version = "0.20.0"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"paste", "paste",
"rand 0.8.4", "rand 0.8.4",
@ -2121,7 +2122,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-macros" name = "ruma-identifiers-macros"
version = "0.20.0" version = "0.20.0"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"quote", "quote",
"ruma-identifiers-validation", "ruma-identifiers-validation",
@ -2131,12 +2132,15 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-validation" name = "ruma-identifiers-validation"
version = "0.5.0" version = "0.5.0"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [
"thiserror",
]
[[package]] [[package]]
name = "ruma-identity-service-api" name = "ruma-identity-service-api"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -2149,7 +2153,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-push-gateway-api" name = "ruma-push-gateway-api"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -2164,7 +2168,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde" name = "ruma-serde"
version = "0.5.0" version = "0.5.0"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"bytes", "bytes",
"form_urlencoded", "form_urlencoded",
@ -2178,7 +2182,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde-macros" name = "ruma-serde-macros"
version = "0.5.0" version = "0.5.0"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -2189,7 +2193,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.9.0" version = "0.9.0"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"base64 0.13.0", "base64 0.13.0",
"ed25519-dalek", "ed25519-dalek",
@ -2206,7 +2210,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-state-res" name = "ruma-state-res"
version = "0.4.1" version = "0.4.1"
source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" source = "git+https://github.com/ruma/ruma?rev=237b423996c7ccef9fc6633de675d0026c55ac1f#237b423996c7ccef9fc6633de675d0026c55ac1f"
dependencies = [ dependencies = [
"itertools 0.10.1", "itertools 0.10.1",
"js_int", "js_int",

View File

@ -19,7 +19,8 @@ rocket = { version = "0.5.0-rc.1", features = ["tls"] } # Used to handle request
# Used for matrix spec type definitions and helpers # Used for matrix spec type definitions and helpers
#ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "a6a1224652912a957b09f136ec5da2686be6e0e2", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } ruma = { git = "https://github.com/ruma/ruma", rev = "237b423996c7ccef9fc6633de675d0026c55ac1f", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
ruma-events = { git = "https://github.com/ruma/ruma", rev = "237b423996c7ccef9fc6633de675d0026c55ac1f", features = ["compat", "unstable-exhaustive-types", "unstable-pdu", "unstable-pre-spec"] }
#ruma = { git = "https://github.com/timokoesters/ruma", rev = "50c1db7e0a3a21fc794b0cce3b64285a4c750c71", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { git = "https://github.com/timokoesters/ruma", rev = "50c1db7e0a3a21fc794b0cce3b64285a4c750c71", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
#ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }

View File

@ -231,7 +231,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
.map_or(Ok::<_, Error>(None), |s| { .map_or(Ok::<_, Error>(None), |s| {
Ok(serde_json::from_value::< Ok(serde_json::from_value::<
Raw<canonical_alias::CanonicalAliasEventContent>, Raw<canonical_alias::CanonicalAliasEventContent>,
>(s.content.clone()) >(s.content_value())
.expect("from_value::<Raw<..>> can never fail") .expect("from_value::<Raw<..>> can never fail")
.deserialize() .deserialize()
.map_err(|_| { .map_err(|_| {
@ -244,7 +244,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
.room_state_get(&room_id, &EventType::RoomName, "")? .room_state_get(&room_id, &EventType::RoomName, "")?
.map_or(Ok::<_, Error>(None), |s| { .map_or(Ok::<_, Error>(None), |s| {
Ok(serde_json::from_value::<Raw<name::NameEventContent>>( Ok(serde_json::from_value::<Raw<name::NameEventContent>>(
s.content.clone(), s.content_value(),
) )
.expect("from_value::<Raw<..>> can never fail") .expect("from_value::<Raw<..>> can never fail")
.deserialize() .deserialize()
@ -268,7 +268,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
.map_or(Ok::<_, Error>(None), |s| { .map_or(Ok::<_, Error>(None), |s| {
Ok(Some( Ok(Some(
serde_json::from_value::<Raw<topic::TopicEventContent>>( serde_json::from_value::<Raw<topic::TopicEventContent>>(
s.content.clone(), s.content_value(),
) )
.expect("from_value::<Raw<..>> can never fail") .expect("from_value::<Raw<..>> can never fail")
.deserialize() .deserialize()
@ -284,7 +284,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
.map_or(Ok::<_, Error>(false), |s| { .map_or(Ok::<_, Error>(false), |s| {
Ok(serde_json::from_value::< Ok(serde_json::from_value::<
Raw<history_visibility::HistoryVisibilityEventContent>, Raw<history_visibility::HistoryVisibilityEventContent>,
>(s.content.clone()) >(s.content_value())
.expect("from_value::<Raw<..>> can never fail") .expect("from_value::<Raw<..>> can never fail")
.deserialize() .deserialize()
.map_err(|_| { .map_err(|_| {
@ -301,7 +301,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
.map_or(Ok::<_, Error>(false), |s| { .map_or(Ok::<_, Error>(false), |s| {
Ok( Ok(
serde_json::from_value::<Raw<guest_access::GuestAccessEventContent>>( serde_json::from_value::<Raw<guest_access::GuestAccessEventContent>>(
s.content.clone(), s.content_value(),
) )
.expect("from_value::<Raw<..>> can never fail") .expect("from_value::<Raw<..>> can never fail")
.deserialize() .deserialize()
@ -318,7 +318,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
.map(|s| { .map(|s| {
Ok::<_, Error>( Ok::<_, Error>(
serde_json::from_value::<Raw<avatar::AvatarEventContent>>( serde_json::from_value::<Raw<avatar::AvatarEventContent>>(
s.content.clone(), s.content_value(),
) )
.expect("from_value::<Raw<..>> can never fail") .expect("from_value::<Raw<..>> can never fail")
.deserialize() .deserialize()

View File

@ -18,7 +18,6 @@ use ruma::{
federation::{self, membership::create_invite}, federation::{self, membership::create_invite},
}, },
events::{ events::{
pdu::Pdu,
room::{create::CreateEventContent, member}, room::{create::CreateEventContent, member},
EventType, EventType,
}, },
@ -26,6 +25,7 @@ use ruma::{
state_res::{self, RoomVersion}, state_res::{self, RoomVersion},
uint, EventId, RoomId, RoomVersionId, ServerName, UserId, uint, EventId, RoomId, RoomVersionId, ServerName, UserId,
}; };
use serde_json::value::RawValue as RawJsonValue;
use std::{ use std::{
collections::{hash_map::Entry, BTreeMap, HashMap, HashSet}, collections::{hash_map::Entry, BTreeMap, HashMap, HashSet},
convert::{TryFrom, TryInto}, convert::{TryFrom, TryInto},
@ -215,8 +215,7 @@ pub async fn kick_user_route(
ErrorKind::BadState, ErrorKind::BadState,
"Cannot kick member that's not in the room.", "Cannot kick member that's not in the room.",
))? ))?
.content .content_value(),
.clone(),
) )
.expect("Raw::from_value always works") .expect("Raw::from_value always works")
.deserialize() .deserialize()
@ -291,7 +290,7 @@ pub async fn ban_user_route(
}), }),
|event| { |event| {
let mut event = serde_json::from_value::<Raw<member::MemberEventContent>>( let mut event = serde_json::from_value::<Raw<member::MemberEventContent>>(
event.content.clone(), event.content_value(),
) )
.expect("Raw::from_value always works") .expect("Raw::from_value always works")
.deserialize() .deserialize()
@ -357,8 +356,7 @@ pub async fn unban_user_route(
ErrorKind::BadState, ErrorKind::BadState,
"Cannot unban a user who is not banned.", "Cannot unban a user who is not banned.",
))? ))?
.content .content_value(),
.clone(),
) )
.expect("from_value::<Raw<..>> can never fail") .expect("from_value::<Raw<..>> can never fail")
.deserialize() .deserialize()
@ -584,10 +582,9 @@ async fn join_room_by_id_helper(
}; };
let mut join_event_stub = let mut join_event_stub =
serde_json::from_str::<CanonicalJsonObject>(make_join_response.event.json().get()) serde_json::from_str::<CanonicalJsonObject>(make_join_response.event.get()).map_err(
.map_err(|_| { |_| Error::BadServerResponse("Invalid make_join event json received from server."),
Error::BadServerResponse("Invalid make_join event json received from server.") )?;
})?;
// TODO: Is origin needed? // TODO: Is origin needed?
join_event_stub.insert( join_event_stub.insert(
@ -653,7 +650,7 @@ async fn join_room_by_id_helper(
federation::membership::create_join_event::v2::Request { federation::membership::create_join_event::v2::Request {
room_id, room_id,
event_id: &event_id, event_id: &event_id,
pdu: PduEvent::convert_to_outgoing_federation_event(join_event.clone()), pdu: PduEvent::convert_to_outgoing_federation_event(join_event.clone()).json(),
}, },
) )
.await?; .await?;
@ -787,14 +784,13 @@ async fn join_room_by_id_helper(
Ok(join_room_by_id::Response::new(room_id.clone()).into()) Ok(join_room_by_id::Response::new(room_id.clone()).into())
} }
fn validate_and_add_event_id( fn validate_and_add_event_id(
pdu: &Raw<Pdu>, pdu: &RawJsonValue,
room_version: &RoomVersionId, room_version: &RoomVersionId,
pub_key_map: &RwLock<BTreeMap<String, BTreeMap<String, String>>>, pub_key_map: &RwLock<BTreeMap<String, BTreeMap<String, String>>>,
db: &Database, db: &Database,
) -> Result<(EventId, CanonicalJsonObject)> { ) -> Result<(EventId, CanonicalJsonObject)> {
let mut value = serde_json::from_str::<CanonicalJsonObject>(pdu.json().get()).map_err(|e| { let mut value = serde_json::from_str::<CanonicalJsonObject>(pdu.get()).map_err(|e| {
error!("Invalid PDU in server response: {:?}: {:?}", pdu, e); error!("Invalid PDU in server response: {:?}: {:?}", pdu, e);
Error::BadServerResponse("Invalid PDU in server response") Error::BadServerResponse("Invalid PDU in server response")
})?; })?;
@ -884,7 +880,7 @@ pub(crate) async fn invite_helper<'a>(
let create_event_content = create_event let create_event_content = create_event
.as_ref() .as_ref()
.map(|create_event| { .map(|create_event| {
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content.clone()) serde_json::from_value::<Raw<CreateEventContent>>(create_event.content_value())
.expect("Raw::from_value always works.") .expect("Raw::from_value always works.")
.deserialize() .deserialize()
.map_err(|e| { .map_err(|e| {
@ -943,7 +939,7 @@ pub(crate) async fn invite_helper<'a>(
let mut unsigned = BTreeMap::new(); let mut unsigned = BTreeMap::new();
if let Some(prev_pdu) = db.rooms.room_state_get(room_id, &kind, &state_key)? { if let Some(prev_pdu) = db.rooms.room_state_get(room_id, &kind, &state_key)? {
unsigned.insert("prev_content".to_owned(), prev_pdu.content.clone()); unsigned.insert("prev_content".to_owned(), prev_pdu.content_value());
unsigned.insert( unsigned.insert(
"prev_sender".to_owned(), "prev_sender".to_owned(),
serde_json::to_value(&prev_pdu.sender).expect("UserId::to_value always works"), serde_json::to_value(&prev_pdu.sender).expect("UserId::to_value always works"),
@ -1035,11 +1031,11 @@ pub(crate) async fn invite_helper<'a>(
&db.globals, &db.globals,
user_id.server_name(), user_id.server_name(),
create_invite::v2::Request { create_invite::v2::Request {
room_id: room_id.clone(), room_id,
event_id: expected_event_id.clone(), event_id: &expected_event_id,
room_version: room_version_id, room_version: &room_version_id,
event: PduEvent::convert_to_outgoing_federation_event(pdu_json.clone()), event: PduEvent::convert_to_outgoing_federation_event(pdu_json.clone()).json(),
invite_room_state, invite_room_state: &invite_room_state,
}, },
) )
.await?; .await?;

View File

@ -60,8 +60,8 @@ pub async fn set_displayname_route(
room.", room.",
) )
})? })?
.content .content_value()
.clone(), ,
) )
.expect("from_value::<Raw<..>> can never fail") .expect("from_value::<Raw<..>> can never fail")
.deserialize() .deserialize()
@ -205,8 +205,8 @@ pub async fn set_avatar_url_route(
room.", room.",
) )
})? })?
.content .content_value()
.clone(), ,
) )
.expect("from_value::<Raw<..>> can never fail") .expect("from_value::<Raw<..>> can never fail")
.deserialize() .deserialize()

View File

@ -509,8 +509,8 @@ pub async fn upgrade_room_route(
db.rooms db.rooms
.room_state_get(&body.room_id, &EventType::RoomCreate, "")? .room_state_get(&body.room_id, &EventType::RoomCreate, "")?
.ok_or_else(|| Error::bad_database("Found room without m.room.create event."))? .ok_or_else(|| Error::bad_database("Found room without m.room.create event."))?
.content .content_value()
.clone(), ,
) )
.expect("Raw::from_value always works") .expect("Raw::from_value always works")
.deserialize() .deserialize()
@ -585,7 +585,7 @@ pub async fn upgrade_room_route(
// Replicate transferable state events to the new room // Replicate transferable state events to the new room
for event_type in transferable_state_events { for event_type in transferable_state_events {
let event_content = match db.rooms.room_state_get(&body.room_id, &event_type, "")? { let event_content = match db.rooms.room_state_get(&body.room_id, &event_type, "")? {
Some(v) => v.content.clone(), Some(v) => v.content_value().clone(),
None => continue, // Skipping missing events. None => continue, // Skipping missing events.
}; };
@ -616,8 +616,8 @@ pub async fn upgrade_room_route(
db.rooms db.rooms
.room_state_get(&body.room_id, &EventType::RoomPowerLevels, "")? .room_state_get(&body.room_id, &EventType::RoomPowerLevels, "")?
.ok_or_else(|| Error::bad_database("Found room without m.room.create event."))? .ok_or_else(|| Error::bad_database("Found room without m.room.create event."))?
.content .content_value()
.clone(), ,
) )
.expect("database contains invalid PDU") .expect("database contains invalid PDU")
.deserialize() .deserialize()

View File

@ -112,11 +112,11 @@ pub async fn get_state_events_route(
db.rooms db.rooms
.room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")? .room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")?
.map(|event| { .map(|event| {
serde_json::from_value::<HistoryVisibilityEventContent>(event.content.clone()) serde_json::from_value::<HistoryVisibilityEventContent>(
.map_err(|_| { event.content_value(),
Error::bad_database(
"Invalid room history visibility event in database.",
) )
.map_err(|_| {
Error::bad_database("Invalid room history visibility event in database.")
}) })
.map(|e| e.history_visibility) .map(|e| e.history_visibility)
}), }),
@ -164,11 +164,11 @@ pub async fn get_state_events_for_key_route(
db.rooms db.rooms
.room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")? .room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")?
.map(|event| { .map(|event| {
serde_json::from_value::<HistoryVisibilityEventContent>(event.content.clone()) serde_json::from_value::<HistoryVisibilityEventContent>(
.map_err(|_| { event.content_value(),
Error::bad_database(
"Invalid room history visibility event in database.",
) )
.map_err(|_| {
Error::bad_database("Invalid room history visibility event in database.")
}) })
.map(|e| e.history_visibility) .map(|e| e.history_visibility)
}), }),
@ -190,7 +190,7 @@ pub async fn get_state_events_for_key_route(
))?; ))?;
Ok(get_state_events_for_key::Response { Ok(get_state_events_for_key::Response {
content: serde_json::from_value(event.content.clone()) content: serde_json::from_value(event.content_value())
.map_err(|_| Error::bad_database("Invalid event content in database"))?, .map_err(|_| Error::bad_database("Invalid event content in database"))?,
} }
.into()) .into())
@ -220,11 +220,11 @@ pub async fn get_state_events_for_empty_key_route(
db.rooms db.rooms
.room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")? .room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")?
.map(|event| { .map(|event| {
serde_json::from_value::<HistoryVisibilityEventContent>(event.content.clone()) serde_json::from_value::<HistoryVisibilityEventContent>(
.map_err(|_| { event.content_value(),
Error::bad_database(
"Invalid room history visibility event in database.",
) )
.map_err(|_| {
Error::bad_database("Invalid room history visibility event in database.")
}) })
.map(|e| e.history_visibility) .map(|e| e.history_visibility)
}), }),
@ -246,7 +246,7 @@ pub async fn get_state_events_for_empty_key_route(
))?; ))?;
Ok(get_state_events_for_key::Response { Ok(get_state_events_for_key::Response {
content: serde_json::from_value(event.content.clone()) content: serde_json::from_value(event.content_value())
.map_err(|_| Error::bad_database("Invalid event content in database"))?, .map_err(|_| Error::bad_database("Invalid event content in database"))?,
} }
.into()) .into())

View File

@ -289,7 +289,7 @@ async fn sync_helper(
.map(|(_, pdu)| { .map(|(_, pdu)| {
let content = serde_json::from_value::< let content = serde_json::from_value::<
ruma::events::room::member::MemberEventContent, ruma::events::room::member::MemberEventContent,
>(pdu.content.clone()) >(pdu.content_value())
.map_err(|_| Error::bad_database("Invalid member event in database."))?; .map_err(|_| Error::bad_database("Invalid member event in database."))?;
if let Some(state_key) = &pdu.state_key { if let Some(state_key) = &pdu.state_key {
@ -372,7 +372,7 @@ async fn sync_helper(
)? )?
.and_then(|pdu| { .and_then(|pdu| {
serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>( serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>(
pdu.content.clone(), pdu.content_value(),
) )
.expect("Raw::from_value always works") .expect("Raw::from_value always works")
.deserialize() .deserialize()
@ -432,9 +432,10 @@ async fn sync_helper(
continue; continue;
} }
let new_membership = serde_json::from_value::< let new_membership =
serde_json::from_value::<
Raw<ruma::events::room::member::MemberEventContent>, Raw<ruma::events::room::member::MemberEventContent>,
>(state_event.content.clone()) >(state_event.content_value().clone())
.expect("Raw::from_value always works") .expect("Raw::from_value always works")
.deserialize() .deserialize()
.map_err(|_| Error::bad_database("Invalid PDU in database."))? .map_err(|_| Error::bad_database("Invalid PDU in database."))?
@ -739,7 +740,7 @@ async fn sync_helper(
presence: sync_events::Presence { presence: sync_events::Presence {
events: presence_updates events: presence_updates
.into_iter() .into_iter()
.map(|(_, v)| Raw::from(v)) .map(|(_, v)| Raw::new(&v).expect("Raw::new(PresenceEvent) always works"))
.collect(), .collect(),
}, },
account_data: sync_events::GlobalAccountData { account_data: sync_events::GlobalAccountData {

View File

@ -181,7 +181,7 @@ pub async fn send_push_notice(
.rooms .rooms
.room_state_get(&pdu.room_id, &EventType::RoomPowerLevels, "")? .room_state_get(&pdu.room_id, &EventType::RoomPowerLevels, "")?
.map(|ev| { .map(|ev| {
serde_json::from_value(ev.content.clone()) serde_json::from_value(ev.content_value())
.map_err(|_| Error::bad_database("invalid m.room.power_levels event")) .map_err(|_| Error::bad_database("invalid m.room.power_levels event"))
}) })
.transpose()? .transpose()?
@ -321,7 +321,7 @@ async fn send_notice(
let room_name = db let room_name = db
.rooms .rooms
.room_state_get(&event.room_id, &EventType::RoomName, "")? .room_state_get(&event.room_id, &EventType::RoomName, "")?
.map(|pdu| match pdu.content.get("name") { .map(|pdu| match pdu.content_value().get("name") {
Some(serde_json::Value::String(s)) => { Some(serde_json::Value::String(s)) => {
Some(Box::<RoomName>::try_from(&**s).expect("room name is valid")) Some(Box::<RoomName>::try_from(&**s).expect("room name is valid"))
} }

View File

@ -252,7 +252,13 @@ impl Rooms {
return Ok(HashMap::new()); return Ok(HashMap::new());
}; };
let auth_events = state_res::auth_types_for_event(kind, sender, state_key, content); let auth_events = state_res::auth_types_for_event(
kind,
sender,
state_key,
&serde_json::value::to_raw_value(&content).expect("content is valid raw value"),
)
.expect("content is valid json");
let mut sauthevents = auth_events let mut sauthevents = auth_events
.into_iter() .into_iter()
@ -397,7 +403,9 @@ impl Rooms {
serde_json::to_value(&pdu).expect("CanonicalJsonObj is a valid JsonValue"), serde_json::to_value(&pdu).expect("CanonicalJsonObj is a valid JsonValue"),
) { ) {
if let Some(membership) = if let Some(membership) =
pdu.content.get("membership").and_then(|membership| { pdu.content_value()
.get("membership")
.and_then(|membership| {
serde_json::from_value::<member::MembershipState>( serde_json::from_value::<member::MembershipState>(
membership.clone(), membership.clone(),
) )
@ -1272,7 +1280,7 @@ impl Rooms {
unsigned.insert( unsigned.insert(
"prev_content".to_owned(), "prev_content".to_owned(),
CanonicalJsonValue::Object( CanonicalJsonValue::Object(
utils::to_canonical_object(prev_state.content.clone()) utils::to_canonical_object(prev_state.content_value())
.expect("event is valid, we just created it"), .expect("event is valid, we just created it"),
), ),
); );
@ -1329,7 +1337,7 @@ impl Rooms {
.rooms .rooms
.room_state_get(&pdu.room_id, &EventType::RoomPowerLevels, "")? .room_state_get(&pdu.room_id, &EventType::RoomPowerLevels, "")?
.map(|ev| { .map(|ev| {
serde_json::from_value(ev.content.clone()) serde_json::from_value(ev.content_value())
.map_err(|_| Error::bad_database("invalid m.room.power_levels event")) .map_err(|_| Error::bad_database("invalid m.room.power_levels event"))
}) })
.transpose()? .transpose()?
@ -1409,7 +1417,7 @@ impl Rooms {
.expect("This state_key was previously validated"); .expect("This state_key was previously validated");
let membership = serde_json::from_value::<member::MembershipState>( let membership = serde_json::from_value::<member::MembershipState>(
pdu.content pdu.content_value()
.get("membership") .get("membership")
.ok_or(Error::BadRequest( .ok_or(Error::BadRequest(
ErrorKind::InvalidParam, ErrorKind::InvalidParam,
@ -1447,7 +1455,7 @@ impl Rooms {
} }
} }
EventType::RoomMessage => { EventType::RoomMessage => {
if let Some(body) = pdu.content.get("body").and_then(|b| b.as_str()) { if let Some(body) = pdu.content_value().get("body").and_then(|b| b.as_str()) {
let mut batch = body let mut batch = body
.split_terminator(|c: char| !c.is_alphanumeric()) .split_terminator(|c: char| !c.is_alphanumeric())
.filter(|s| !s.is_empty()) .filter(|s| !s.is_empty())
@ -1961,7 +1969,7 @@ impl Rooms {
let create_event_content = create_event let create_event_content = create_event
.as_ref() .as_ref()
.map(|create_event| { .map(|create_event| {
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content.clone()) serde_json::from_value::<Raw<CreateEventContent>>(create_event.content_value())
.expect("Raw::from_value always works.") .expect("Raw::from_value always works.")
.deserialize() .deserialize()
.map_err(|e| { .map_err(|e| {
@ -2000,7 +2008,7 @@ impl Rooms {
let mut unsigned = unsigned.unwrap_or_default(); let mut unsigned = unsigned.unwrap_or_default();
if let Some(state_key) = &state_key { if let Some(state_key) = &state_key {
if let Some(prev_pdu) = self.room_state_get(room_id, &event_type, state_key)? { if let Some(prev_pdu) = self.room_state_get(room_id, &event_type, state_key)? {
unsigned.insert("prev_content".to_owned(), prev_pdu.content.clone()); unsigned.insert("prev_content".to_owned(), prev_pdu.content_value());
unsigned.insert( unsigned.insert(
"prev_sender".to_owned(), "prev_sender".to_owned(),
serde_json::to_value(&prev_pdu.sender).expect("UserId::to_value always works"), serde_json::to_value(&prev_pdu.sender).expect("UserId::to_value always works"),
@ -2350,7 +2358,7 @@ impl Rooms {
.and_then(|create| { .and_then(|create| {
serde_json::from_value::< serde_json::from_value::<
Raw<ruma::events::room::create::CreateEventContent>, Raw<ruma::events::room::create::CreateEventContent>,
>(create.content.clone()) >(create.content_value())
.expect("Raw::from_value always works") .expect("Raw::from_value always works")
.deserialize() .deserialize()
.ok() .ok()
@ -2706,8 +2714,7 @@ impl Rooms {
ErrorKind::BadState, ErrorKind::BadState,
"Cannot leave a room you are not a member of.", "Cannot leave a room you are not a member of.",
))? ))?
.content .content_value(),
.clone(),
) )
.expect("from_value::<Raw<..>> can never fail") .expect("from_value::<Raw<..>> can never fail")
.deserialize() .deserialize()
@ -2793,10 +2800,9 @@ impl Rooms {
}; };
let mut leave_event_stub = let mut leave_event_stub =
serde_json::from_str::<CanonicalJsonObject>(make_leave_response.event.json().get()) serde_json::from_str::<CanonicalJsonObject>(make_leave_response.event.get()).map_err(
.map_err(|_| { |_| Error::BadServerResponse("Invalid make_leave event json received from server."),
Error::BadServerResponse("Invalid make_leave event json received from server.") )?;
})?;
// TODO: Is origin needed? // TODO: Is origin needed?
leave_event_stub.insert( leave_event_stub.insert(
@ -2847,7 +2853,7 @@ impl Rooms {
federation::membership::create_leave_event::v2::Request { federation::membership::create_leave_event::v2::Request {
room_id, room_id,
event_id: &event_id, event_id: &event_id,
pdu: PduEvent::convert_to_outgoing_federation_event(leave_event.clone()), pdu: PduEvent::convert_to_outgoing_federation_event(leave_event.clone()).json(),
}, },
) )
.await?; .await?;

View File

@ -656,7 +656,7 @@ impl Sending {
), ),
) )
})?, })?,
); ).into_json();
pdu_jsons.push(raw); pdu_jsons.push(raw);
} }
SendingEventType::Edu(edu) => { SendingEventType::Edu(edu) => {

View File

@ -10,7 +10,7 @@ use ruma::{
ServerSigningKeyId, UInt, UserId, ServerSigningKeyId, UInt, UserId,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::json; use serde_json::{json, value::RawValue as RawJsonValue};
use std::{cmp::Ordering, collections::BTreeMap, convert::TryFrom}; use std::{cmp::Ordering, collections::BTreeMap, convert::TryFrom};
use tracing::warn; use tracing::warn;
@ -22,7 +22,7 @@ pub struct PduEvent {
pub origin_server_ts: UInt, pub origin_server_ts: UInt,
#[serde(rename = "type")] #[serde(rename = "type")]
pub kind: EventType, pub kind: EventType,
pub content: serde_json::Value, pub content: Box<serde_json::value::RawValue>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub state_key: Option<String>, pub state_key: Option<String>,
pub prev_events: Vec<EventId>, pub prev_events: Vec<EventId>,
@ -37,6 +37,10 @@ pub struct PduEvent {
} }
impl PduEvent { impl PduEvent {
pub fn content_value(&self) -> serde_json::Value {
serde_json::from_str(self.content.get()).expect("from_str(self.content) always works")
}
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn redact(&mut self, reason: &PduEvent) -> crate::Result<()> { pub fn redact(&mut self, reason: &PduEvent) -> crate::Result<()> {
self.unsigned.clear(); self.unsigned.clear();
@ -59,8 +63,8 @@ impl PduEvent {
_ => &[], _ => &[],
}; };
let old_content = self let mut old_content = self.content_value();
.content let old_content = old_content
.as_object_mut() .as_object_mut()
.ok_or_else(|| Error::bad_database("PDU in db has invalid content."))?; .ok_or_else(|| Error::bad_database("PDU in db has invalid content."))?;
@ -77,7 +81,8 @@ impl PduEvent {
serde_json::to_value(reason).expect("to_value(PduEvent) always works"), serde_json::to_value(reason).expect("to_value(PduEvent) always works"),
); );
self.content = new_content.into(); self.content = serde_json::value::to_raw_value(&new_content)
.expect("to_raw_value(serde_json::Map) always works");
Ok(()) Ok(())
} }
@ -265,7 +270,7 @@ impl state_res::Event for PduEvent {
&self.kind &self.kind
} }
fn content(&self) -> &serde_json::Value { fn content(&self) -> &serde_json::value::RawValue {
&self.content &self.content
} }
@ -281,10 +286,6 @@ impl state_res::Event for PduEvent {
Box::new(self.prev_events.iter()) Box::new(self.prev_events.iter())
} }
fn depth(&self) -> &UInt {
&self.depth
}
fn auth_events(&self) -> Box<dyn DoubleEndedIterator<Item = &EventId> + '_> { fn auth_events(&self) -> Box<dyn DoubleEndedIterator<Item = &EventId> + '_> {
Box::new(self.auth_events.iter()) Box::new(self.auth_events.iter())
} }
@ -292,18 +293,6 @@ impl state_res::Event for PduEvent {
fn redacts(&self) -> Option<&EventId> { fn redacts(&self) -> Option<&EventId> {
self.redacts.as_ref() self.redacts.as_ref()
} }
fn hashes(&self) -> &EventHash {
&self.hashes
}
fn signatures(&self) -> BTreeMap<Box<ServerName>, BTreeMap<ruma::ServerSigningKeyId, String>> {
self.signatures.clone()
}
fn unsigned(&self) -> &BTreeMap<String, serde_json::Value> {
&self.unsigned
}
} }
// These impl's allow us to dedup state snapshots when resolving state // These impl's allow us to dedup state snapshots when resolving state
@ -329,9 +318,9 @@ impl Ord for PduEvent {
/// ///
/// Returns a tuple of the new `EventId` and the PDU as a `BTreeMap<String, CanonicalJsonValue>`. /// Returns a tuple of the new `EventId` and the PDU as a `BTreeMap<String, CanonicalJsonValue>`.
pub(crate) fn gen_event_id_canonical_json( pub(crate) fn gen_event_id_canonical_json(
pdu: &Raw<ruma::events::pdu::Pdu>, pdu: &RawJsonValue,
) -> crate::Result<(EventId, CanonicalJsonObject)> { ) -> crate::Result<(EventId, CanonicalJsonObject)> {
let value = serde_json::from_str(pdu.json().get()).map_err(|e| { let value = serde_json::from_str(pdu.get()).map_err(|e| {
warn!("Error parsing incoming event {:?}: {:?}", pdu, e); warn!("Error parsing incoming event {:?}: {:?}", pdu, e);
Error::BadServerResponse("Invalid PDU in server response") Error::BadServerResponse("Invalid PDU in server response")
})?; })?;

View File

@ -39,7 +39,6 @@ use ruma::{
}, },
directory::{IncomingFilter, IncomingRoomNetwork}, directory::{IncomingFilter, IncomingRoomNetwork},
events::{ events::{
pdu::Pdu,
receipt::{ReceiptEvent, ReceiptEventContent}, receipt::{ReceiptEvent, ReceiptEventContent},
room::{ room::{
create::CreateEventContent, create::CreateEventContent,
@ -55,6 +54,7 @@ use ruma::{
uint, EventId, MilliSecondsSinceUnixEpoch, RoomId, RoomVersionId, ServerName, uint, EventId, MilliSecondsSinceUnixEpoch, RoomId, RoomVersionId, ServerName,
ServerSigningKeyId, ServerSigningKeyId,
}; };
use serde_json::value::RawValue as RawJsonValue;
use std::{ use std::{
collections::{btree_map, hash_map, BTreeMap, BTreeSet, HashMap, HashSet}, collections::{btree_map, hash_map, BTreeMap, BTreeSet, HashMap, HashSet},
convert::{TryFrom, TryInto}, convert::{TryFrom, TryInto},
@ -1071,7 +1071,7 @@ pub(crate) async fn handle_incoming_pdu<'a>(
// and lexically by event_id. // and lexically by event_id.
println!("{}", event_id); println!("{}", event_id);
Ok(( Ok((
0, ruma::int!(0),
MilliSecondsSinceUnixEpoch( MilliSecondsSinceUnixEpoch(
eventid_info eventid_info
.get(event_id) .get(event_id)
@ -1154,7 +1154,7 @@ fn handle_outlier_pdu<'a>(
// 3. check content hash, redact if doesn't match // 3. check content hash, redact if doesn't match
let create_event_content = let create_event_content =
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content.clone()) serde_json::from_value::<Raw<CreateEventContent>>(create_event.content_value())
.expect("Raw::from_value always works.") .expect("Raw::from_value always works.")
.deserialize() .deserialize()
.map_err(|e| { .map_err(|e| {
@ -1320,7 +1320,7 @@ async fn upgrade_outlier_to_timeline_pdu(
} }
let create_event_content = let create_event_content =
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content.clone()) serde_json::from_value::<Raw<CreateEventContent>>(create_event.content_value())
.expect("Raw::from_value always works.") .expect("Raw::from_value always works.")
.deserialize() .deserialize()
.map_err(|e| { .map_err(|e| {
@ -1627,7 +1627,7 @@ async fn upgrade_outlier_to_timeline_pdu(
&incoming_pdu.kind, &incoming_pdu.kind,
&incoming_pdu.sender, &incoming_pdu.sender,
incoming_pdu.state_key.as_deref(), incoming_pdu.state_key.as_deref(),
&incoming_pdu.content, &incoming_pdu.content_value(),
) )
.map_err(|_| "Failed to get_auth_events.".to_owned())?; .map_err(|_| "Failed to get_auth_events.".to_owned())?;
@ -2387,7 +2387,7 @@ pub fn get_event_route(
Ok(get_event::v1::Response { Ok(get_event::v1::Response {
origin: db.globals.server_name().to_owned(), origin: db.globals.server_name().to_owned(),
origin_server_ts: MilliSecondsSinceUnixEpoch::now(), origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
pdu: PduEvent::convert_to_outgoing_federation_event(event), pdu: PduEvent::convert_to_outgoing_federation_event(event).into_json(),
} }
.into()) .into())
} }
@ -2458,7 +2458,7 @@ pub fn get_missing_events_route(
) )
.map_err(|_| Error::bad_database("Invalid prev_events content in pdu in db."))?, .map_err(|_| Error::bad_database("Invalid prev_events content in pdu in db."))?,
); );
events.push(PduEvent::convert_to_outgoing_federation_event(pdu)); events.push(PduEvent::convert_to_outgoing_federation_event(pdu).into_json());
} }
i += 1; i += 1;
} }
@ -2512,6 +2512,7 @@ pub fn get_event_authorization_route(
auth_chain: auth_chain_ids auth_chain: auth_chain_ids
.filter_map(|id| db.rooms.get_pdu_json(&id).ok()?) .filter_map(|id| db.rooms.get_pdu_json(&id).ok()?)
.map(PduEvent::convert_to_outgoing_federation_event) .map(PduEvent::convert_to_outgoing_federation_event)
.map(Raw::into_json)
.collect(), .collect(),
} }
.into()) .into())
@ -2562,6 +2563,7 @@ pub fn get_room_state_route(
db.rooms.get_pdu_json(&id).unwrap().unwrap(), db.rooms.get_pdu_json(&id).unwrap().unwrap(),
) )
}) })
.map(Raw::into_json)
.collect(); .collect();
let auth_chain_ids = get_auth_chain(&body.room_id, vec![Arc::new(body.event_id.clone())], &db)?; let auth_chain_ids = get_auth_chain(&body.room_id, vec![Arc::new(body.event_id.clone())], &db)?;
@ -2574,6 +2576,7 @@ pub fn get_room_state_route(
)) ))
}) })
.filter_map(|r| r.ok()) .filter_map(|r| r.ok())
.map(Raw::into_json)
.collect(), .collect(),
pdus, pdus,
} }
@ -2669,7 +2672,7 @@ pub fn create_join_event_template_route(
let create_event_content = create_event let create_event_content = create_event
.as_ref() .as_ref()
.map(|create_event| { .map(|create_event| {
serde_json::from_value::<Raw<CreateEventContent>>(create_event.content.clone()) serde_json::from_value::<Raw<CreateEventContent>>(create_event.content_value())
.expect("Raw::from_value always works.") .expect("Raw::from_value always works.")
.deserialize() .deserialize()
.map_err(|e| { .map_err(|e| {
@ -2735,7 +2738,7 @@ pub fn create_join_event_template_route(
let mut unsigned = BTreeMap::new(); let mut unsigned = BTreeMap::new();
if let Some(prev_pdu) = db.rooms.room_state_get(&body.room_id, &kind, &state_key)? { if let Some(prev_pdu) = db.rooms.room_state_get(&body.room_id, &kind, &state_key)? {
unsigned.insert("prev_content".to_owned(), prev_pdu.content.clone()); unsigned.insert("prev_content".to_owned(), prev_pdu.content_value());
unsigned.insert( unsigned.insert(
"prev_sender".to_owned(), "prev_sender".to_owned(),
serde_json::to_value(&prev_pdu.sender).expect("UserId::to_value always works"), serde_json::to_value(&prev_pdu.sender).expect("UserId::to_value always works"),
@ -2799,10 +2802,8 @@ pub fn create_join_event_template_route(
Ok(create_join_event_template::v1::Response { Ok(create_join_event_template::v1::Response {
room_version: Some(room_version_id), room_version: Some(room_version_id),
event: serde_json::from_value::<Raw<_>>( event: serde_json::value::to_raw_value(&pdu_json)
serde_json::to_value(pdu_json).expect("CanonicalJson is valid serde_json::Value"), .expect("CanonicalJson is valid raw value"),
)
.expect("Raw::from_value always works"),
} }
.into()) .into())
} }
@ -2810,7 +2811,7 @@ pub fn create_join_event_template_route(
async fn create_join_event( async fn create_join_event(
db: &DatabaseGuard, db: &DatabaseGuard,
room_id: &RoomId, room_id: &RoomId,
pdu: &Raw<ruma::events::pdu::Pdu>, pdu: &RawJsonValue,
) -> Result<RoomState> { ) -> Result<RoomState> {
if !db.globals.allow_federation() { if !db.globals.allow_federation() {
return Err(Error::bad_config("Federation is disabled.")); return Err(Error::bad_config("Federation is disabled."));
@ -2894,11 +2895,13 @@ async fn create_join_event(
auth_chain: auth_chain_ids auth_chain: auth_chain_ids
.filter_map(|id| db.rooms.get_pdu_json(&id).ok().flatten()) .filter_map(|id| db.rooms.get_pdu_json(&id).ok().flatten())
.map(PduEvent::convert_to_outgoing_federation_event) .map(PduEvent::convert_to_outgoing_federation_event)
.map(Raw::into_json)
.collect(), .collect(),
state: state_ids state: state_ids
.iter() .iter()
.filter_map(|(_, id)| db.rooms.get_pdu_json(id).ok().flatten()) .filter_map(|(_, id)| db.rooms.get_pdu_json(id).ok().flatten())
.map(PduEvent::convert_to_outgoing_federation_event) .map(PduEvent::convert_to_outgoing_federation_event)
.map(Raw::into_json)
.collect(), .collect(),
}) })
} }
@ -2947,7 +2950,7 @@ pub async fn create_join_event_v2_route(
#[tracing::instrument(skip(db, body))] #[tracing::instrument(skip(db, body))]
pub async fn create_invite_route( pub async fn create_invite_route(
db: DatabaseGuard, db: DatabaseGuard,
body: Ruma<create_invite::v2::Request>, body: Ruma<create_invite::v2::Request<'_>>,
) -> ConduitResult<create_invite::v2::Response> { ) -> ConduitResult<create_invite::v2::Response> {
if !db.globals.allow_federation() { if !db.globals.allow_federation() {
return Err(Error::bad_config("Federation is disabled.")); return Err(Error::bad_config("Federation is disabled."));
@ -3014,10 +3017,11 @@ pub async fn create_invite_route(
let mut invite_state = body.invite_room_state.clone(); let mut invite_state = body.invite_room_state.clone();
let mut event = serde_json::from_str::<serde_json::Map<String, serde_json::Value>>( let mut event =
&body.event.json().to_string(), serde_json::from_str::<serde_json::Map<String, serde_json::Value>>(body.event.get())
) .map_err(|_| {
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid invite event bytes."))?; Error::BadRequest(ErrorKind::InvalidParam, "Invalid invite event bytes.")
})?;
event.insert("event_id".to_owned(), "$dummy".into()); event.insert("event_id".to_owned(), "$dummy".into());
@ -3044,7 +3048,7 @@ pub async fn create_invite_route(
db.flush()?; db.flush()?;
Ok(create_invite::v2::Response { Ok(create_invite::v2::Response {
event: PduEvent::convert_to_outgoing_federation_event(signed_event), event: PduEvent::convert_to_outgoing_federation_event(signed_event).into_json(),
} }
.into()) .into())
} }
@ -3280,13 +3284,13 @@ pub(crate) async fn fetch_required_signing_keys(
// Gets a list of servers for which we don't have the signing key yet. We go over // Gets a list of servers for which we don't have the signing key yet. We go over
// the PDUs and either cache the key or add it to the list that needs to be retrieved. // the PDUs and either cache the key or add it to the list that needs to be retrieved.
fn get_server_keys_from_cache( fn get_server_keys_from_cache(
pdu: &Raw<Pdu>, pdu: &RawJsonValue,
servers: &mut BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, QueryCriteria>>, servers: &mut BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, QueryCriteria>>,
room_version: &RoomVersionId, room_version: &RoomVersionId,
pub_key_map: &mut RwLockWriteGuard<'_, BTreeMap<String, BTreeMap<String, String>>>, pub_key_map: &mut RwLockWriteGuard<'_, BTreeMap<String, BTreeMap<String, String>>>,
db: &Database, db: &Database,
) -> Result<()> { ) -> Result<()> {
let value = serde_json::from_str::<CanonicalJsonObject>(pdu.json().get()).map_err(|e| { let value = serde_json::from_str::<CanonicalJsonObject>(pdu.get()).map_err(|e| {
error!("Invalid PDU in server response: {:?}: {:?}", pdu, e); error!("Invalid PDU in server response: {:?}: {:?}", pdu, e);
Error::BadServerResponse("Invalid PDU in server response") Error::BadServerResponse("Invalid PDU in server response")
})?; })?;