@ -45,7 +45,7 @@ use ruma::{
member ::{ MembershipState , RoomMemberEventContent } ,
server_acl ::RoomServerAclEventContent ,
} ,
EventType,
RoomEventType, State EventType,
} ,
int ,
receipt ::ReceiptType ,
@ -575,7 +575,7 @@ pub async fn get_server_keys_deprecated_route(db: DatabaseGuard) -> impl IntoRes
/// Lists the public rooms on this server.
pub async fn get_public_rooms_filtered_route (
db : DatabaseGuard ,
body : Ruma < get_public_rooms_filtered ::v1 :: Request< ' _ > > ,
body : Ruma < get_public_rooms_filtered ::v1 ::Incoming Request> ,
) -> Result < get_public_rooms_filtered ::v1 ::Response > {
if ! db . globals . allow_federation ( ) {
return Err ( Error ::bad_config ( "Federation is disabled." ) ) ;
@ -604,7 +604,7 @@ pub async fn get_public_rooms_filtered_route(
/// Lists the public rooms on this server.
pub async fn get_public_rooms_route (
db : DatabaseGuard ,
body : Ruma < get_public_rooms ::v1 :: Request< ' _ > > ,
body : Ruma < get_public_rooms ::v1 ::Incoming Request> ,
) -> Result < get_public_rooms ::v1 ::Response > {
if ! db . globals . allow_federation ( ) {
return Err ( Error ::bad_config ( "Federation is disabled." ) ) ;
@ -633,7 +633,7 @@ pub async fn get_public_rooms_route(
/// Push EDUs and PDUs to this server.
pub async fn send_transaction_message_route (
db : DatabaseGuard ,
body : Ruma < send_transaction_message ::v1 :: Request< ' _ > > ,
body : Ruma < send_transaction_message ::v1 ::Incoming Request> ,
) -> Result < send_transaction_message ::v1 ::Response > {
if ! db . globals . allow_federation ( ) {
return Err ( Error ::bad_config ( "Federation is disabled." ) ) ;
@ -924,7 +924,7 @@ pub(crate) async fn handle_incoming_pdu<'a>(
let create_event = db
. rooms
. room_state_get ( room_id , & EventType::RoomCreate , "" )
. room_state_get ( room_id , & State EventType::RoomCreate , "" )
. map_err ( | _ | "Failed to ask database for event." . to_owned ( ) ) ?
. ok_or_else ( | | "Failed to find create event in db." . to_owned ( ) ) ? ;
@ -1174,7 +1174,7 @@ fn handle_outlier_pdu<'a>(
} ;
match auth_events . entry ( (
auth_event . kind . clone ( ) ,
auth_event . kind . to_string( ) . into ( ) ,
auth_event
. state_key
. clone ( )
@ -1194,7 +1194,7 @@ fn handle_outlier_pdu<'a>(
// The original create event must be in the auth events
if auth_events
. get ( & ( EventType::RoomCreate , "" . to_owned ( ) ) )
. get ( & ( State EventType::RoomCreate , "" . to_owned ( ) ) )
. map ( | a | a . as_ref ( ) )
! = Some ( create_event )
{
@ -1216,9 +1216,8 @@ fn handle_outlier_pdu<'a>(
if ! state_res ::event_auth ::auth_check (
& room_version ,
& incoming_pdu ,
previous_create . as_ref ( ) ,
None ::< PduEvent > , // TODO: third party invite
| k , s | auth_events . get ( & ( k . clone ( ) , s . to_owned ( ) ) ) ,
| k , s | auth_events . get ( & ( k . to_string( ) . into ( ) , s . to_owned ( ) ) ) ,
)
. map_err ( | _e | "Auth check failed" . to_owned ( ) ) ?
{
@ -1297,7 +1296,11 @@ async fn upgrade_outlier_to_timeline_pdu(
if let Some ( state_key ) = & prev_pdu . state_key {
let shortstatekey = db
. rooms
. get_or_create_shortstatekey ( & prev_pdu . kind , state_key , & db . globals )
. get_or_create_shortstatekey (
& prev_pdu . kind . to_string ( ) . into ( ) ,
state_key ,
& db . globals ,
)
. map_err ( | _ | "Failed to create shortstatekey." . to_owned ( ) ) ? ;
state . insert ( shortstatekey , Arc ::from ( prev_event ) ) ;
@ -1342,7 +1345,11 @@ async fn upgrade_outlier_to_timeline_pdu(
if let Some ( state_key ) = & prev_event . state_key {
let shortstatekey = db
. rooms
. get_or_create_shortstatekey ( & prev_event . kind , state_key , & db . globals )
. get_or_create_shortstatekey (
& prev_event . kind . to_string ( ) . into ( ) ,
state_key ,
& db . globals ,
)
. map_err ( | _ | "Failed to create shortstatekey." . to_owned ( ) ) ? ;
leaf_state . insert ( shortstatekey , Arc ::from ( & * prev_event . event_id ) ) ;
// Now it's the state after the pdu
@ -1352,8 +1359,10 @@ async fn upgrade_outlier_to_timeline_pdu(
let mut starting_events = Vec ::with_capacity ( leaf_state . len ( ) ) ;
for ( k , id ) in leaf_state {
if let Ok ( k ) = db . rooms . get_statekey_from_short ( k ) {
state . insert ( k , id . clone ( ) ) ;
if let Ok ( ( ty , st_key ) ) = db . rooms . get_statekey_from_short ( k ) {
// FIXME: Undo .to_string().into() when StateMap
// is updated to use StateEventType
state . insert ( ( ty . to_string ( ) . into ( ) , st_key ) , id . clone ( ) ) ;
} else {
warn ! ( "Failed to get_statekey_from_short." ) ;
}
@ -1387,7 +1396,11 @@ async fn upgrade_outlier_to_timeline_pdu(
. map ( | ( ( event_type , state_key ) , event_id ) | {
let shortstatekey = db
. rooms
. get_or_create_shortstatekey ( & event_type , & state_key , & db . globals )
. get_or_create_shortstatekey (
& event_type . to_string ( ) . into ( ) ,
& state_key ,
& db . globals ,
)
. map_err ( | _ | "Failed to get_or_create_shortstatekey" . to_owned ( ) ) ? ;
Ok ( ( shortstatekey , event_id ) )
} )
@ -1441,7 +1454,11 @@ async fn upgrade_outlier_to_timeline_pdu(
let shortstatekey = db
. rooms
. get_or_create_shortstatekey ( & pdu . kind , & state_key , & db . globals )
. get_or_create_shortstatekey (
& pdu . kind . to_string ( ) . into ( ) ,
& state_key ,
& db . globals ,
)
. map_err ( | _ | "Failed to create shortstatekey." . to_owned ( ) ) ? ;
match state . entry ( shortstatekey ) {
@ -1458,7 +1475,7 @@ async fn upgrade_outlier_to_timeline_pdu(
// The original create event must still be in the state
let create_shortstatekey = db
. rooms
. get_shortstatekey ( & EventType::RoomCreate , "" )
. get_shortstatekey ( & State EventType::RoomCreate , "" )
. map_err ( | _ | "Failed to talk to db." ) ?
. expect ( "Room exists" ) ;
@ -1496,11 +1513,10 @@ async fn upgrade_outlier_to_timeline_pdu(
let check_result = state_res ::event_auth ::auth_check (
& room_version ,
& incoming_pdu ,
previous_create . as_ref ( ) ,
None ::< PduEvent > , // TODO: third party invite
| k , s | {
db . rooms
. get_shortstatekey ( k , s )
. get_shortstatekey ( & k . to_string ( ) . into ( ) , s )
. ok ( )
. flatten ( )
. and_then ( | shortstatekey | state_at_incoming_event . get ( & shortstatekey ) )
@ -1580,7 +1596,6 @@ async fn upgrade_outlier_to_timeline_pdu(
let soft_fail = ! state_res ::event_auth ::auth_check (
& room_version ,
& incoming_pdu ,
previous_create . as_ref ( ) ,
None ::< PduEvent > ,
| k , s | auth_events . get ( & ( k . clone ( ) , s . to_owned ( ) ) ) ,
)
@ -1655,7 +1670,11 @@ async fn upgrade_outlier_to_timeline_pdu(
if let Some ( state_key ) = & incoming_pdu . state_key {
let shortstatekey = db
. rooms
. get_or_create_shortstatekey ( & incoming_pdu . kind , state_key , & db . globals )
. get_or_create_shortstatekey (
& incoming_pdu . kind . to_string ( ) . into ( ) ,
state_key ,
& db . globals ,
)
. map_err ( | _ | "Failed to create shortstatekey." . to_owned ( ) ) ? ;
state_after . insert ( shortstatekey , Arc ::from ( & * incoming_pdu . event_id ) ) ;
@ -1701,7 +1720,9 @@ async fn upgrade_outlier_to_timeline_pdu(
. filter_map ( | ( k , id ) | {
db . rooms
. get_statekey_from_short ( k )
. map ( | k | ( k , id ) )
// FIXME: Undo .to_string().into() when StateMap
// is updated to use StateEventType
. map ( | ( ty , st_key ) | ( ( ty . to_string ( ) . into ( ) , st_key ) , id ) )
. map_err ( | e | warn ! ( "Failed to get_statekey_from_short: {}" , e ) )
. ok ( )
} )
@ -1732,7 +1753,11 @@ async fn upgrade_outlier_to_timeline_pdu(
. map ( | ( ( event_type , state_key ) , event_id ) | {
let shortstatekey = db
. rooms
. get_or_create_shortstatekey ( & event_type , & state_key , & db . globals )
. get_or_create_shortstatekey (
& event_type . to_string ( ) . into ( ) ,
& state_key ,
& db . globals ,
)
. map_err ( | _ | "Failed to get_or_create_shortstatekey" . to_owned ( ) ) ? ;
db . rooms
. compress_state_event ( shortstatekey , & event_id , & db . globals )
@ -2151,7 +2176,7 @@ fn append_incoming_pdu<'a>(
let matching_users = | users : & Regex | {
users . is_match ( pdu . sender . as_str ( ) )
| | pdu . kind = = EventType::RoomMember
| | pdu . kind = = Room EventType::RoomMember
& & pdu
. state_key
. as_ref ( )
@ -2298,7 +2323,7 @@ fn get_auth_chain_inner(
/// - Only works if a user of this server is currently invited or joined the room
pub async fn get_event_route (
db : DatabaseGuard ,
body : Ruma < get_event ::v1 :: Request< ' _ > > ,
body : Ruma < get_event ::v1 ::Incoming Request> ,
) -> Result < get_event ::v1 ::Response > {
if ! db . globals . allow_federation ( ) {
return Err ( Error ::bad_config ( "Federation is disabled." ) ) ;
@ -2341,7 +2366,7 @@ pub async fn get_event_route(
/// Retrieves events that the sender is missing.
pub async fn get_missing_events_route (
db : DatabaseGuard ,
body : Ruma < get_missing_events ::v1 :: Request< ' _ > > ,
body : Ruma < get_missing_events ::v1 ::Incoming Request> ,
) -> Result < get_missing_events ::v1 ::Response > {
if ! db . globals . allow_federation ( ) {
return Err ( Error ::bad_config ( "Federation is disabled." ) ) ;
@ -2414,7 +2439,7 @@ pub async fn get_missing_events_route(
/// - This does not include the event itself
pub async fn get_event_authorization_route (
db : DatabaseGuard ,
body : Ruma < get_event_authorization ::v1 :: Request< ' _ > > ,
body : Ruma < get_event_authorization ::v1 ::Incoming Request> ,
) -> Result < get_event_authorization ::v1 ::Response > {
if ! db . globals . allow_federation ( ) {
return Err ( Error ::bad_config ( "Federation is disabled." ) ) ;
@ -2462,7 +2487,7 @@ pub async fn get_event_authorization_route(
/// Retrieves the current state of the room.
pub async fn get_room_state_route (
db : DatabaseGuard ,
body : Ruma < get_room_state ::v1 :: Request< ' _ > > ,
body : Ruma < get_room_state ::v1 ::Incoming Request> ,
) -> Result < get_room_state ::v1 ::Response > {
if ! db . globals . allow_federation ( ) {
return Err ( Error ::bad_config ( "Federation is disabled." ) ) ;
@ -2521,7 +2546,7 @@ pub async fn get_room_state_route(
/// Retrieves the current state of the room.
pub async fn get_room_state_ids_route (
db : DatabaseGuard ,
body : Ruma < get_room_state_ids ::v1 :: Request< ' _ > > ,
body : Ruma < get_room_state_ids ::v1 ::Incoming Request> ,
) -> Result < get_room_state_ids ::v1 ::Response > {
if ! db . globals . allow_federation ( ) {
return Err ( Error ::bad_config ( "Federation is disabled." ) ) ;
@ -2569,7 +2594,7 @@ pub async fn get_room_state_ids_route(
/// Creates a join template.
pub async fn create_join_event_template_route (
db : DatabaseGuard ,
body : Ruma < prepare_join_event ::v1 :: Request< ' _ > > ,
body : Ruma < prepare_join_event ::v1 ::Incoming Request> ,
) -> Result < prepare_join_event ::v1 ::Response > {
if ! db . globals . allow_federation ( ) {
return Err ( Error ::bad_config ( "Federation is disabled." ) ) ;
@ -2598,7 +2623,7 @@ pub async fn create_join_event_template_route(
let create_event = db
. rooms
. room_state_get ( & body . room_id , & EventType::RoomCreate , "" ) ? ;
. room_state_get ( & body . room_id , & State EventType::RoomCreate , "" ) ? ;
let create_event_content : Option < RoomCreateEventContent > = create_event
. as_ref ( )
@ -2645,11 +2670,11 @@ pub async fn create_join_event_template_route(
. expect ( "member event is valid value" ) ;
let state_key = body . user_id . to_string ( ) ;
let kind = EventType::RoomMember ;
let kind = State EventType::RoomMember ;
let auth_events = db . rooms . get_auth_events (
& body . room_id ,
& kind ,
& kind .to_string ( ) . into ( ) ,
& body . user_id ,
Some ( & state_key ) ,
& content ,
@ -2680,7 +2705,7 @@ pub async fn create_join_event_template_route(
origin_server_ts : utils ::millis_since_unix_epoch ( )
. try_into ( )
. expect ( "time is valid" ) ,
kind ,
kind : kind . to_string ( ) . into ( ) ,
content ,
state_key : Some ( state_key ) ,
prev_events ,
@ -2704,7 +2729,6 @@ pub async fn create_join_event_template_route(
let auth_check = state_res ::auth_check (
& room_version ,
& pdu ,
create_prev_event ,
None ::< PduEvent > , // TODO: third_party_invite
| k , s | auth_events . get ( & ( k . clone ( ) , s . to_owned ( ) ) ) ,
)
@ -2849,7 +2873,7 @@ async fn create_join_event(
/// Submits a signed join event.
pub async fn create_join_event_v1_route (
db : DatabaseGuard ,
body : Ruma < create_join_event ::v1 :: Request< ' _ > > ,
body : Ruma < create_join_event ::v1 ::Incoming Request> ,
) -> Result < create_join_event ::v1 ::Response > {
let sender_servername = body
. sender_servername
@ -2866,7 +2890,7 @@ pub async fn create_join_event_v1_route(
/// Submits a signed join event.
pub async fn create_join_event_v2_route (
db : DatabaseGuard ,
body : Ruma < create_join_event ::v2 :: Request< ' _ > > ,
body : Ruma < create_join_event ::v2 ::Incoming Request> ,
) -> Result < create_join_event ::v2 ::Response > {
let sender_servername = body
. sender_servername
@ -2883,7 +2907,7 @@ pub async fn create_join_event_v2_route(
/// Invites a remote user to a room.
pub async fn create_invite_route (
db : DatabaseGuard ,
body : Ruma < create_invite ::v2 :: Request< ' _ > > ,
body : Ruma < create_invite ::v2 ::Incoming Request> ,
) -> Result < create_invite ::v2 ::Response > {
if ! db . globals . allow_federation ( ) {
return Err ( Error ::bad_config ( "Federation is disabled." ) ) ;
@ -2993,7 +3017,7 @@ pub async fn create_invite_route(
/// Gets information on all devices of the user.
pub async fn get_devices_route (
db : DatabaseGuard ,
body : Ruma < get_devices ::v1 :: Request< ' _ > > ,
body : Ruma < get_devices ::v1 ::Incoming Request> ,
) -> Result < get_devices ::v1 ::Response > {
if ! db . globals . allow_federation ( ) {
return Err ( Error ::bad_config ( "Federation is disabled." ) ) ;
@ -3041,7 +3065,7 @@ pub async fn get_devices_route(
/// Resolve a room alias to a room id.
pub async fn get_room_information_route (
db : DatabaseGuard ,
body : Ruma < get_room_information ::v1 :: Request< ' _ > > ,
body : Ruma < get_room_information ::v1 ::Incoming Request> ,
) -> Result < get_room_information ::v1 ::Response > {
if ! db . globals . allow_federation ( ) {
return Err ( Error ::bad_config ( "Federation is disabled." ) ) ;
@ -3066,7 +3090,7 @@ pub async fn get_room_information_route(
/// Gets information on a profile.
pub async fn get_profile_information_route (
db : DatabaseGuard ,
body : Ruma < get_profile_information ::v1 :: Request< ' _ > > ,
body : Ruma < get_profile_information ::v1 ::Incoming Request> ,
) -> Result < get_profile_information ::v1 ::Response > {
if ! db . globals . allow_federation ( ) {
return Err ( Error ::bad_config ( "Federation is disabled." ) ) ;
@ -3395,7 +3419,7 @@ pub(crate) async fn fetch_join_signing_keys(
fn acl_check ( server_name : & ServerName , room_id : & RoomId , db : & Database ) -> Result < ( ) > {
let acl_event = match db
. rooms
. room_state_get ( room_id , & EventType::RoomServerAcl , "" ) ?
. room_state_get ( room_id , & State EventType::RoomServerAcl , "" ) ?
{
Some ( acl ) = > acl ,
None = > return Ok ( ( ) ) ,