Compare commits

...

1 Commits
next ... ruma

  1. 50
      Cargo.lock
  2. 6
      Cargo.toml
  3. 25
      src/client_server/backup.rs
  4. 13
      src/client_server/capabilities.rs
  5. 11
      src/client_server/filter.rs
  6. 8
      src/client_server/keys.rs
  7. 10
      src/client_server/media.rs
  8. 26
      src/client_server/membership.rs
  9. 6
      src/client_server/state.rs
  10. 61
      src/database/media.rs
  11. 5
      src/database/rooms.rs
  12. 6
      src/database/users.rs
  13. 4
      src/pdu.rs
  14. 13
      src/ruma_wrapper.rs
  15. 7
      src/server_server.rs

50
Cargo.lock generated

@ -1559,8 +1559,10 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#47fab87325b71b7f6c2fb3cd276d1f813e42abf7" source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [ dependencies = [
"assign",
"js_int",
"ruma-api", "ruma-api",
"ruma-appservice-api", "ruma-appservice-api",
"ruma-client-api", "ruma-client-api",
@ -1575,22 +1577,24 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api" name = "ruma-api"
version = "0.17.0-alpha.1" version = "0.17.0-alpha.1"
source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#47fab87325b71b7f6c2fb3cd276d1f813e42abf7" source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [ dependencies = [
"http", "http",
"percent-encoding", "percent-encoding",
"ruma-api-macros", "ruma-api-macros",
"ruma-common",
"ruma-identifiers", "ruma-identifiers",
"ruma-serde", "ruma-serde",
"serde", "serde",
"serde_json", "serde_json",
"strum", "strum",
"thiserror",
] ]
[[package]] [[package]]
name = "ruma-api-macros" name = "ruma-api-macros"
version = "0.17.0-alpha.1" version = "0.17.0-alpha.1"
source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#47fab87325b71b7f6c2fb3cd276d1f813e42abf7" source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1601,7 +1605,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-appservice-api" name = "ruma-appservice-api"
version = "0.2.0-alpha.1" version = "0.2.0-alpha.1"
source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#47fab87325b71b7f6c2fb3cd276d1f813e42abf7" source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [ dependencies = [
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
@ -1614,11 +1618,12 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.10.0-alpha.1" version = "0.10.0-alpha.1"
source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#47fab87325b71b7f6c2fb3cd276d1f813e42abf7" source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [ dependencies = [
"assign", "assign",
"http", "http",
"js_int", "js_int",
"maplit",
"percent-encoding", "percent-encoding",
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
@ -1633,10 +1638,10 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#47fab87325b71b7f6c2fb3cd276d1f813e42abf7" source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-common-macros",
"ruma-identifiers", "ruma-identifiers",
"ruma-serde", "ruma-serde",
"serde", "serde",
@ -1644,10 +1649,21 @@ dependencies = [
"strum", "strum",
] ]
[[package]]
name = "ruma-common-macros"
version = "0.2.0"
source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "ruma-events" name = "ruma-events"
version = "0.22.0-alpha.1" version = "0.22.0-alpha.1"
source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#47fab87325b71b7f6c2fb3cd276d1f813e42abf7" source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -1662,7 +1678,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events-macros" name = "ruma-events-macros"
version = "0.22.0-alpha.1" version = "0.22.0-alpha.1"
source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#47fab87325b71b7f6c2fb3cd276d1f813e42abf7" source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1673,7 +1689,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.0.3" version = "0.0.3"
source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#47fab87325b71b7f6c2fb3cd276d1f813e42abf7" source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -1688,7 +1704,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers" name = "ruma-identifiers"
version = "0.17.4" version = "0.17.4"
source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#47fab87325b71b7f6c2fb3cd276d1f813e42abf7" source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [ dependencies = [
"rand", "rand",
"ruma-identifiers-macros", "ruma-identifiers-macros",
@ -1700,7 +1716,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-macros" name = "ruma-identifiers-macros"
version = "0.17.4" version = "0.17.4"
source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#47fab87325b71b7f6c2fb3cd276d1f813e42abf7" source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1711,7 +1727,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-validation" name = "ruma-identifiers-validation"
version = "0.1.1" version = "0.1.1"
source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#47fab87325b71b7f6c2fb3cd276d1f813e42abf7" source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [ dependencies = [
"serde", "serde",
"strum", "strum",
@ -1720,7 +1736,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde" name = "ruma-serde"
version = "0.2.3" version = "0.2.3"
source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#47fab87325b71b7f6c2fb3cd276d1f813e42abf7" source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [ dependencies = [
"form_urlencoded", "form_urlencoded",
"itoa", "itoa",
@ -1732,10 +1748,12 @@ dependencies = [
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.6.0-dev.1" version = "0.6.0-dev.1"
source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#47fab87325b71b7f6c2fb3cd276d1f813e42abf7" source = "git+https://github.com/ruma/ruma?rev=f85d98f557b457fdf9846b851055a5fbab2eeee2#f85d98f557b457fdf9846b851055a5fbab2eeee2"
dependencies = [ dependencies = [
"base64", "base64",
"ring", "ring",
"ruma-identifiers",
"ruma-serde",
"serde_json", "serde_json",
"untrusted", "untrusted",
] ]
@ -1982,7 +2000,7 @@ checksum = "7345c971d1ef21ffdbd103a75990a15eb03604fc8b8852ca8cb418ee1a099028"
[[package]] [[package]]
name = "state-res" name = "state-res"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/timokoesters/state-res?branch=spec-comp#a7d76935f12757aecfee305838069c9bcbe7d34a" source = "git+https://github.com/timokoesters/state-res?branch=spec-comp-ruma-master#79f2c8004106b60f57b404e4f84b6225fc663e27"
dependencies = [ dependencies = [
"itertools", "itertools",
"js_int", "js_int",

6
Cargo.toml

@ -18,12 +18,12 @@ edition = "2018"
rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] } rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] }
# Used for matrix spec type definitions and helpers # Used for matrix spec type definitions and helpers
#ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"], rev = "aff914050eb297bd82b8aafb12158c88a9e480e1" } ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks", "unstable-exhaustive-types"], rev = "f85d98f557b457fdf9846b851055a5fbab2eeee2" }
ruma = { git = "https://github.com/timokoesters/ruma", features = ["rand", "client-api", "federation-api", "unstable-exhaustive-types", "unstable-pre-spec", "unstable-synapse-quirks"], branch = "timo-fed-fixes" } #ruma = { git = "https://github.com/timokoesters/ruma", features = ["rand", "client-api", "federation-api", "unstable-exhaustive-types", "unstable-pre-spec", "unstable-synapse-quirks"], branch = "timo-fed-fixes" }
#ruma = { path = "../ruma/ruma", features = ["unstable-exhaustive-types", "rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"] } #ruma = { path = "../ruma/ruma", features = ["unstable-exhaustive-types", "rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"] }
# Used when doing state resolution # Used when doing state resolution
state-res = { git = "https://github.com/timokoesters/state-res", branch = "spec-comp", features = ["unstable-pre-spec"] } state-res = { git = "https://github.com/timokoesters/state-res", branch = "spec-comp-ruma-master", features = ["unstable-pre-spec"] }
#state-res = { path = "../state-res", features = ["unstable-pre-spec"] } #state-res = { path = "../state-res", features = ["unstable-pre-spec"] }
# Used for long polling # Used for long polling

25
src/client_server/backup.rs

@ -107,7 +107,7 @@ pub async fn get_backup_route(
)] )]
pub async fn delete_backup_route( pub async fn delete_backup_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<delete_backup::Request>, body: Ruma<delete_backup::Request<'_>>,
) -> ConduitResult<delete_backup::Response> { ) -> ConduitResult<delete_backup::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -158,7 +158,7 @@ pub async fn add_backup_keys_route(
)] )]
pub async fn add_backup_key_sessions_route( pub async fn add_backup_key_sessions_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<add_backup_key_sessions::Request>, body: Ruma<add_backup_key_sessions::Request<'_>>,
) -> ConduitResult<add_backup_key_sessions::Response> { ) -> ConduitResult<add_backup_key_sessions::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -189,7 +189,7 @@ pub async fn add_backup_key_sessions_route(
)] )]
pub async fn add_backup_key_session_route( pub async fn add_backup_key_session_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<add_backup_key_session::Request>, body: Ruma<add_backup_key_session::Request<'_>>,
) -> ConduitResult<add_backup_key_session::Response> { ) -> ConduitResult<add_backup_key_session::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -232,7 +232,7 @@ pub async fn get_backup_keys_route(
)] )]
pub async fn get_backup_key_sessions_route( pub async fn get_backup_key_sessions_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<get_backup_key_sessions::Request>, body: Ruma<get_backup_key_sessions::Request<'_>>,
) -> ConduitResult<get_backup_key_sessions::Response> { ) -> ConduitResult<get_backup_key_sessions::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -249,15 +249,18 @@ pub async fn get_backup_key_sessions_route(
)] )]
pub async fn get_backup_key_session_route( pub async fn get_backup_key_session_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<get_backup_key_session::Request>, body: Ruma<get_backup_key_session::Request<'_>>,
) -> ConduitResult<get_backup_key_session::Response> { ) -> ConduitResult<get_backup_key_session::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let key_data = if let Some(key_data) =
db.key_backups db.key_backups
.get_session(&sender_user, &body.version, &body.room_id, &body.session_id)?; .get_session(&sender_user, &body.version, &body.room_id, &body.session_id)?
{
Ok(get_backup_key_session::Response { key_data }.into()) Ok(get_backup_key_session::Response { key_data }.into())
} else {
Err(Error::BadRequest(ErrorKind::NotFound, "Key not found.").into())
}
} }
#[cfg_attr( #[cfg_attr(
@ -266,7 +269,7 @@ pub async fn get_backup_key_session_route(
)] )]
pub async fn delete_backup_keys_route( pub async fn delete_backup_keys_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<delete_backup_keys::Request>, body: Ruma<delete_backup_keys::Request<'_>>,
) -> ConduitResult<delete_backup_keys::Response> { ) -> ConduitResult<delete_backup_keys::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -288,7 +291,7 @@ pub async fn delete_backup_keys_route(
)] )]
pub async fn delete_backup_key_sessions_route( pub async fn delete_backup_key_sessions_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<delete_backup_key_sessions::Request>, body: Ruma<delete_backup_key_sessions::Request<'_>>,
) -> ConduitResult<delete_backup_key_sessions::Response> { ) -> ConduitResult<delete_backup_key_sessions::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -310,7 +313,7 @@ pub async fn delete_backup_key_sessions_route(
)] )]
pub async fn delete_backup_key_session_route( pub async fn delete_backup_key_session_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<delete_backup_key_session::Request>, body: Ruma<delete_backup_key_session::Request<'_>>,
) -> ConduitResult<delete_backup_key_session::Response> { ) -> ConduitResult<delete_backup_key_session::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

13
src/client_server/capabilities.rs

@ -1,5 +1,8 @@
use crate::ConduitResult; use crate::ConduitResult;
use ruma::{api::client::r0::capabilities::get_capabilities, RoomVersionId}; use ruma::{
api::client::r0::capabilities::get_capabilities::{self, ChangePasswordCapability},
RoomVersionId,
};
use std::collections::BTreeMap; use std::collections::BTreeMap;
#[cfg(feature = "conduit_bin")] #[cfg(feature = "conduit_bin")]
@ -22,11 +25,11 @@ pub async fn get_capabilities_route() -> ConduitResult<get_capabilities::Respons
Ok(get_capabilities::Response { Ok(get_capabilities::Response {
capabilities: get_capabilities::Capabilities { capabilities: get_capabilities::Capabilities {
change_password: None, // None means it is possible change_password: ChangePasswordCapability { enabled: true },
room_versions: Some(get_capabilities::RoomVersionsCapability { room_versions: get_capabilities::RoomVersionsCapability {
default: "6".to_owned(), default: RoomVersionId::Version6,
available, available,
}), },
custom_capabilities: BTreeMap::new(), custom_capabilities: BTreeMap::new(),
}, },
} }

11
src/client_server/filter.rs

@ -1,5 +1,5 @@
use crate::{utils, ConduitResult}; use crate::{utils, ConduitResult};
use ruma::api::client::r0::filter::{self, create_filter, get_filter}; use ruma::api::client::r0::filter::{create_filter, get_filter, IncomingFilterDefinition};
#[cfg(feature = "conduit_bin")] #[cfg(feature = "conduit_bin")]
use rocket::{get, post}; use rocket::{get, post};
@ -7,14 +7,7 @@ use rocket::{get, post};
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/user/<_>/filter/<_>"))] #[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/user/<_>/filter/<_>"))]
pub async fn get_filter_route() -> ConduitResult<get_filter::Response> { pub async fn get_filter_route() -> ConduitResult<get_filter::Response> {
// TODO // TODO
Ok(get_filter::Response::new(filter::IncomingFilterDefinition { Ok(get_filter::Response::new(IncomingFilterDefinition::default()).into())
event_fields: None,
event_format: None,
account_data: None,
room: None,
presence: None,
})
.into())
} }
#[cfg_attr(feature = "conduit_bin", post("/_matrix/client/r0/user/<_>/filter"))] #[cfg_attr(feature = "conduit_bin", post("/_matrix/client/r0/user/<_>/filter"))]

8
src/client_server/keys.rs

@ -11,7 +11,7 @@ use ruma::{
uiaa::{AuthFlow, UiaaInfo}, uiaa::{AuthFlow, UiaaInfo},
}, },
}, },
encryption::IncomingUnsignedDeviceInfo, encryption::UnsignedDeviceInfo,
}; };
use std::collections::{BTreeMap, HashSet}; use std::collections::{BTreeMap, HashSet};
@ -24,7 +24,7 @@ use rocket::{get, post};
)] )]
pub async fn upload_keys_route( pub async fn upload_keys_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<upload_keys::Request<'_>>, body: Ruma<upload_keys::Request>,
) -> ConduitResult<upload_keys::Response> { ) -> ConduitResult<upload_keys::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let sender_device = body.sender_device.as_ref().expect("user is authenticated"); let sender_device = body.sender_device.as_ref().expect("user is authenticated");
@ -94,7 +94,7 @@ pub async fn get_keys_route(
Error::bad_database("all_device_keys contained nonexistent device.") Error::bad_database("all_device_keys contained nonexistent device.")
})?; })?;
keys.unsigned = IncomingUnsignedDeviceInfo { keys.unsigned = UnsignedDeviceInfo {
device_display_name: metadata.display_name, device_display_name: metadata.display_name,
}; };
@ -113,7 +113,7 @@ pub async fn get_keys_route(
), ),
)?; )?;
keys.unsigned = IncomingUnsignedDeviceInfo { keys.unsigned = UnsignedDeviceInfo {
device_display_name: metadata.display_name, device_display_name: metadata.display_name,
}; };

10
src/client_server/media.rs

@ -39,7 +39,7 @@ pub async fn create_content_route(
db.media.create( db.media.create(
mxc.clone(), mxc.clone(),
&body.filename.as_deref(), &body.filename.as_deref(),
&body.content_type, body.content_type.as_deref(),
&body.file, &body.file,
)?; )?;
@ -67,7 +67,7 @@ pub async fn get_content_route(
Ok(get_content::Response { Ok(get_content::Response {
file, file,
content_type, content_type,
content_disposition: filename.unwrap_or_default(), // TODO: Spec says this should be optional content_disposition: filename,
} }
.into()) .into())
} else if &*body.server_name != db.globals.server_name() && body.allow_remote { } else if &*body.server_name != db.globals.server_name() && body.allow_remote {
@ -84,8 +84,8 @@ pub async fn get_content_route(
db.media.create( db.media.create(
mxc, mxc,
&Some(&get_content_response.content_disposition), &get_content_response.content_disposition.as_deref(),
&get_content_response.content_type, get_content_response.content_type.as_deref(),
&get_content_response.file, &get_content_response.file,
)?; )?;
@ -135,7 +135,7 @@ pub async fn get_content_thumbnail_route(
db.media.upload_thumbnail( db.media.upload_thumbnail(
mxc, mxc,
&None, &None,
&get_thumbnail_response.content_type, get_thumbnail_response.content_type.as_deref(),
body.width.try_into().expect("all UInts are valid u32s"), body.width.try_into().expect("all UInts are valid u32s"),
body.height.try_into().expect("all UInts are valid u32s"), body.height.try_into().expect("all UInts are valid u32s"),
&get_thumbnail_response.file, &get_thumbnail_response.file,

26
src/client_server/membership.rs

@ -17,13 +17,14 @@ use ruma::{
}, },
federation, federation,
}, },
events::pdu::Pdu, events::{pdu::Pdu, room::member, EventType},
events::{room::member, EventType},
EventId, Raw, RoomId, RoomVersionId, ServerName, UserId, EventId, Raw, RoomId, RoomVersionId, ServerName, UserId,
}; };
use state_res::StateEvent; use state_res::StateEvent;
use std::{ use std::{
collections::BTreeMap, collections::HashMap, collections::HashSet, convert::TryFrom, iter, collections::{BTreeMap, HashMap, HashSet},
convert::{TryFrom, TryInto},
iter,
sync::Arc, sync::Arc,
}; };
@ -471,6 +472,10 @@ async fn join_room_by_id_helper(
let (make_join_response, remote_server) = make_join_response_and_server?; let (make_join_response, remote_server) = make_join_response_and_server?;
let room_version = make_join_response
.room_version
.unwrap_or(RoomVersionId::Version2);
let mut join_event_stub_value = let mut join_event_stub_value =
serde_json::from_str::<serde_json::Value>(make_join_response.event.json().get()) serde_json::from_str::<serde_json::Value>(make_join_response.event.json().get())
.map_err(|_| { .map_err(|_| {
@ -507,7 +512,15 @@ async fn join_room_by_id_helper(
// Generate event id // Generate event id
let event_id = EventId::try_from(&*format!( let event_id = EventId::try_from(&*format!(
"${}", "${}",
ruma::signatures::reference_hash(&join_event_stub_value) ruma::signatures::reference_hash(
&join_event_stub_value
.try_into()
.map_err(|_| Error::BadRequest(
ErrorKind::InvalidParam,
"Join event is not valid json."
))?,
&room_version
)
.expect("ruma can calculate reference hashes") .expect("ruma can calculate reference hashes")
)) ))
.expect("ruma's reference hashes are valid event ids"); .expect("ruma's reference hashes are valid event ids");
@ -520,6 +533,7 @@ async fn join_room_by_id_helper(
db.globals.server_name().as_str(), db.globals.server_name().as_str(),
db.globals.keypair(), db.globals.keypair(),
&mut join_event_stub_value, &mut join_event_stub_value,
&room_version,
) )
.expect("event is valid, we just created it"); .expect("event is valid, we just created it");
@ -542,11 +556,11 @@ async fn join_room_by_id_helper(
.await?; .await?;
let add_event_id = |pdu: &Raw<Pdu>| { let add_event_id = |pdu: &Raw<Pdu>| {
let mut value = serde_json::from_str(pdu.json().get()) let mut value = serde_json::from_str::<serde_json::Value>(pdu.json().get())
.expect("converting raw jsons to values always works"); .expect("converting raw jsons to values always works");
let event_id = EventId::try_from(&*format!( let event_id = EventId::try_from(&*format!(
"${}", "${}",
ruma::signatures::reference_hash(&value) ruma::signatures::reference_hash(&value, &room_version)
.expect("ruma can calculate reference hashes") .expect("ruma can calculate reference hashes")
)) ))
.expect("ruma's reference hashes are valid event ids"); .expect("ruma's reference hashes are valid event ids");

6
src/client_server/state.rs

@ -99,7 +99,7 @@ pub async fn send_state_event_for_empty_key_route(
)] )]
pub async fn get_state_events_route( pub async fn get_state_events_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<get_state_events::Request>, body: Ruma<get_state_events::Request<'_>>,
) -> ConduitResult<get_state_events::Response> { ) -> ConduitResult<get_state_events::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -144,7 +144,7 @@ pub async fn get_state_events_route(
)] )]
pub async fn get_state_events_for_key_route( pub async fn get_state_events_for_key_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<get_state_events_for_key::Request>, body: Ruma<get_state_events_for_key::Request<'_>>,
) -> ConduitResult<get_state_events_for_key::Response> { ) -> ConduitResult<get_state_events_for_key::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -194,7 +194,7 @@ pub async fn get_state_events_for_key_route(
)] )]
pub async fn get_state_events_for_empty_key_route( pub async fn get_state_events_for_empty_key_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<get_state_events_for_empty_key::Request>, body: Ruma<get_state_events_for_empty_key::Request<'_>>,
) -> ConduitResult<get_state_events_for_empty_key::Response> { ) -> ConduitResult<get_state_events_for_empty_key::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

61
src/database/media.rs

@ -5,7 +5,7 @@ use std::mem;
pub struct FileMeta { pub struct FileMeta {
pub filename: Option<String>, pub filename: Option<String>,
pub content_type: String, pub content_type: Option<String>,
pub file: Vec<u8>, pub file: Vec<u8>,
} }
@ -19,7 +19,7 @@ impl Media {
&self, &self,
mxc: String, mxc: String,
filename: &Option<&str>, filename: &Option<&str>,
content_type: &str, content_type: Option<&str>,
file: &[u8], file: &[u8],
) -> Result<()> { ) -> Result<()> {
let mut key = mxc.as_bytes().to_vec(); let mut key = mxc.as_bytes().to_vec();
@ -29,7 +29,7 @@ impl Media {
key.push(0xff); key.push(0xff);
key.extend_from_slice(filename.as_ref().map(|f| f.as_bytes()).unwrap_or_default()); key.extend_from_slice(filename.as_ref().map(|f| f.as_bytes()).unwrap_or_default());
key.push(0xff); key.push(0xff);
key.extend_from_slice(content_type.as_bytes()); key.extend_from_slice(content_type.map(|c| c.as_bytes()).unwrap_or(&[]));
self.mediaid_file.insert(key, file)?; self.mediaid_file.insert(key, file)?;
@ -41,7 +41,7 @@ impl Media {
&self, &self,
mxc: String, mxc: String,
filename: &Option<String>, filename: &Option<String>,
content_type: &str, content_type: Option<&str>,
width: u32, width: u32,
height: u32, height: u32,
file: &[u8], file: &[u8],
@ -53,7 +53,7 @@ impl Media {
key.push(0xff); key.push(0xff);
key.extend_from_slice(filename.as_ref().map(|f| f.as_bytes()).unwrap_or_default()); key.extend_from_slice(filename.as_ref().map(|f| f.as_bytes()).unwrap_or_default());
key.push(0xff); key.push(0xff);
key.extend_from_slice(content_type.as_bytes()); key.extend_from_slice(content_type.map(|c| c.as_bytes()).unwrap_or(&[]));
self.mediaid_file.insert(key, file)?; self.mediaid_file.insert(key, file)?;
@ -72,12 +72,17 @@ impl Media {
let (key, file) = r?; let (key, file) = r?;
let mut parts = key.rsplit(|&b| b == 0xff); let mut parts = key.rsplit(|&b| b == 0xff);
let content_type = utils::string_from_bytes( let content_type = parts
parts
.next() .next()
.ok_or_else(|| Error::bad_database("Media ID in db is invalid."))?, .ok_or_else(|| Error::bad_database("Media ID in db is invalid."))?;
)
.map_err(|_| Error::bad_database("Content type in mediaid_file is invalid unicode."))?; let content_type_parsed = if content_type.is_empty() {
None
} else {
Some(utils::string_from_bytes(content_type).map_err(|_| {
Error::bad_database("Content type in mediaid_file is invalid unicode.")
})?)
};
let filename_bytes = parts let filename_bytes = parts
.next() .next()
@ -93,7 +98,7 @@ impl Media {
Ok(Some(FileMeta { Ok(Some(FileMeta {
filename, filename,
content_type, content_type: content_type_parsed,
file: file.to_vec(), file: file.to_vec(),
})) }))
} else { } else {
@ -147,12 +152,17 @@ impl Media {
let (key, file) = r?; let (key, file) = r?;
let mut parts = key.rsplit(|&b| b == 0xff); let mut parts = key.rsplit(|&b| b == 0xff);
let content_type = utils::string_from_bytes( let content_type = parts
parts
.next() .next()
.ok_or_else(|| Error::bad_database("Invalid Media ID in db"))?, .ok_or_else(|| Error::bad_database("Media ID in db is invalid."))?;
)
.map_err(|_| Error::bad_database("Content type in mediaid_file is invalid unicode."))?; let content_type_parsed = if content_type.is_empty() {
None
} else {
Some(utils::string_from_bytes(content_type).map_err(|_| {
Error::bad_database("Content type in mediaid_file is invalid unicode.")
})?)
};
let filename_bytes = parts let filename_bytes = parts
.next() .next()
@ -169,7 +179,7 @@ impl Media {
Ok(Some(FileMeta { Ok(Some(FileMeta {
filename, filename,
content_type, content_type: content_type_parsed,
file: file.to_vec(), file: file.to_vec(),
})) }))
} else if let Some(r) = self.mediaid_file.scan_prefix(&original_prefix).next() { } else if let Some(r) = self.mediaid_file.scan_prefix(&original_prefix).next() {
@ -178,12 +188,17 @@ impl Media {
let (key, file) = r?; let (key, file) = r?;
let mut parts = key.rsplit(|&b| b == 0xff); let mut parts = key.rsplit(|&b| b == 0xff);
let content_type = utils::string_from_bytes( let content_type = parts
parts
.next() .next()
.ok_or_else(|| Error::bad_database("Media ID in db is invalid."))?, .ok_or_else(|| Error::bad_database("Media ID in db is invalid."))?;
)
.map_err(|_| Error::bad_database("Content type in mediaid_file is invalid unicode."))?; let content_type_parsed = if content_type.is_empty() {
None
} else {
Some(utils::string_from_bytes(content_type).map_err(|_| {
Error::bad_database("Content type in mediaid_file is invalid unicode.")
})?)
};
let filename_bytes = parts let filename_bytes = parts
.next() .next()
@ -269,7 +284,7 @@ impl Media {
Ok(Some(FileMeta { Ok(Some(FileMeta {
filename, filename,
content_type, content_type: content_type_parsed,
file: thumbnail_bytes.to_vec(), file: thumbnail_bytes.to_vec(),
})) }))
} else { } else {

5
src/database/rooms.rs

@ -15,7 +15,7 @@ use ruma::{
}, },
EventType, EventType,
}, },
EventId, Raw, RoomAliasId, RoomId, ServerName, UserId, EventId, Raw, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId,
}; };
use sled::IVec; use sled::IVec;
use state_res::{event_auth, Error as StateError, Requester, StateEvent, StateMap, StateStore}; use state_res::{event_auth, Error as StateError, Requester, StateEvent, StateMap, StateStore};
@ -815,13 +815,14 @@ impl Rooms {
globals.server_name().as_str(), globals.server_name().as_str(),
globals.keypair(), globals.keypair(),
&mut pdu_json, &mut pdu_json,
&RoomVersionId::Version6,
) )
.expect("event is valid, we just created it"); .expect("event is valid, we just created it");
// Generate event id // Generate event id
pdu.event_id = EventId::try_from(&*format!( pdu.event_id = EventId::try_from(&*format!(
"${}", "${}",
ruma::signatures::reference_hash(&pdu_json) ruma::signatures::reference_hash(&pdu_json, &RoomVersionId::Version6)
.expect("ruma can calculate reference hashes") .expect("ruma can calculate reference hashes")
)) ))
.expect("ruma's reference hashes are valid event ids"); .expect("ruma's reference hashes are valid event ids");

6
src/database/users.rs

@ -8,7 +8,7 @@ use ruma::{
keys::{CrossSigningKey, OneTimeKey}, keys::{CrossSigningKey, OneTimeKey},
}, },
}, },
encryption::IncomingDeviceKeys, encryption::DeviceKeys,
events::{AnyToDeviceEvent, EventType}, events::{AnyToDeviceEvent, EventType},
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, Raw, UserId, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, Raw, UserId,
}; };
@ -400,7 +400,7 @@ impl Users {
&self, &self,
user_id: &UserId, user_id: &UserId,
device_id: &DeviceId, device_id: &DeviceId,
device_keys: &IncomingDeviceKeys, device_keys: &DeviceKeys,
rooms: &super::rooms::Rooms, rooms: &super::rooms::Rooms,
globals: &super::globals::Globals, globals: &super::globals::Globals,
) -> Result<()> { ) -> Result<()> {
@ -630,7 +630,7 @@ impl Users {
&self, &self,
user_id: &UserId, user_id: &UserId,
device_id: &DeviceId, device_id: &DeviceId,
) -> Result<Option<IncomingDeviceKeys>> { ) -> Result<Option<DeviceKeys>> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.to_string().as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(device_id.as_bytes()); key.extend_from_slice(device_id.as_bytes());

4
src/pdu.rs

@ -199,9 +199,7 @@ impl PduEvent {
serde_json::from_value(json).expect("Raw::from_value always works") serde_json::from_value(json).expect("Raw::from_value always works")
} }
pub fn convert_to_outgoing_federation_event( pub fn convert_to_outgoing_federation_event<T>(mut pdu_json: serde_json::Value) -> Raw<T> {
mut pdu_json: serde_json::Value,
) -> Raw<ruma::events::pdu::PduStub> {
if let Some(unsigned) = pdu_json if let Some(unsigned) = pdu_json
.as_object_mut() .as_object_mut()
.expect("json is object") .expect("json is object")

13
src/ruma_wrapper.rs

@ -1,7 +1,9 @@
use crate::Error; use crate::Error;
use ruma::{ use ruma::{
api::{Outgoing, OutgoingRequest}, api::AuthScheme,
api::OutgoingRequest,
identifiers::{DeviceId, UserId}, identifiers::{DeviceId, UserId},
Outgoing,
}; };
use std::{convert::TryFrom, convert::TryInto, ops::Deref}; use std::{convert::TryFrom, convert::TryInto, ops::Deref};
@ -61,7 +63,8 @@ where
.await .await
.expect("database was loaded"); .expect("database was loaded");
let (sender_user, sender_device) = if T::METADATA.requires_authentication { let (sender_user, sender_device) = match T::METADATA.authentication {
AuthScheme::AccessToken => {
// Get token from header or query value // Get token from header or query value
let token = match request let token = match request
.headers() .headers()
@ -80,8 +83,10 @@ where
None => return Failure((Status::Unauthorized, ())), None => return Failure((Status::Unauthorized, ())),
Some((user_id, device_id)) => (Some(user_id), Some(device_id.into())), Some((user_id, device_id)) => (Some(user_id), Some(device_id.into())),
} }
} else { }
(None, None) AuthScheme::None => (None, None),
AuthScheme::ServerSignatures => (None, None),
AuthScheme::QueryOnlyAccessToken => (None, None),
}; };
let mut http_request = http::Request::builder() let mut http_request = http::Request::builder()

7
src/server_server.rs

@ -17,7 +17,7 @@ use ruma::{
OutgoingRequest, OutgoingRequest,
}, },
directory::{IncomingFilter, IncomingRoomNetwork}, directory::{IncomingFilter, IncomingRoomNetwork},
EventId, ServerName, EventId, RoomVersionId, ServerName,
}; };
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,
@ -375,12 +375,13 @@ pub fn send_transaction_message_route<'a>(
//dbg!(&*body); //dbg!(&*body);
for pdu in &body.pdus { for pdu in &body.pdus {
let mut value = serde_json::from_str(pdu.json().get()) let mut value = serde_json::from_str::<serde_json::Value>(pdu.json().get())
.expect("converting raw jsons to values always works"); .expect("converting raw jsons to values always works");
let event_id = EventId::try_from(&*format!( let event_id = EventId::try_from(&*format!(
"${}", "${}",
ruma::signatures::reference_hash(&value).expect("ruma can calculate reference hashes") ruma::signatures::reference_hash(&value, &RoomVersionId::Version6)
.expect("ruma can calculate reference hashes")
)) ))
.expect("ruma's reference hashes are valid event ids"); .expect("ruma's reference hashes are valid event ids");

Loading…
Cancel
Save