diff --git a/src/api/mod.rs b/src/api/mod.rs index 6adf2d39..dda37caf 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,15 +1,14 @@ pub mod client; -mod router; -pub mod routes; +pub mod router; pub mod server; extern crate conduit_core as conduit; extern crate conduit_service as service; -pub(crate) use conduit::{debug_info, debug_warn, utils, Error, Result}; -pub(crate) use service::{pdu::PduEvent, services, user_is_local}; +pub(crate) use conduit::{debug_info, debug_warn, pdu::PduEvent, utils, Error, Result}; +pub(crate) use service::{services, user_is_local}; -pub(crate) use self::router::{Ruma, RumaResponse}; +pub(crate) use crate::router::{Ruma, RumaResponse}; conduit::mod_ctor! {} conduit::mod_dtor! {} diff --git a/src/api/routes.rs b/src/api/router.rs similarity index 93% rename from src/api/routes.rs rename to src/api/router.rs index 3a8b2c74..9b6f62a5 100644 --- a/src/api/routes.rs +++ b/src/api/router.rs @@ -1,3 +1,9 @@ +mod args; +mod auth; +mod handler; +mod request; +mod response; + use axum::{ response::IntoResponse, routing::{any, get, post}, @@ -7,7 +13,9 @@ use conduit::{err, Error, Server}; use http::Uri; use ruma::api::client::error::ErrorKind; -use crate::{client, router::RouterExt, server}; +use self::handler::RouterExt; +pub(super) use self::{ar::Ruma, response::RumaResponse}; +use crate::{client, server}; pub fn build(router: Router, server: &Server) -> Router { let config = &server.config; @@ -95,7 +103,7 @@ pub fn build(router: Router, server: &Server) -> Router { .ruma_route(client::get_member_events_route) .ruma_route(client::get_protocols_route) .route("/_matrix/client/unstable/thirdparty/protocols", - get(client::get_protocols_route_unstable)) + get(client::get_protocols_route_unstable)) .ruma_route(client::send_message_event_route) .ruma_route(client::send_state_event_for_key_route) .ruma_route(client::get_state_events_route) @@ -180,15 +188,15 @@ pub fn build(router: Router, server: &Server) -> Router { .ruma_route(client::get_relating_events_with_rel_type_route) .ruma_route(client::get_relating_events_route) .ruma_route(client::get_hierarchy_route) - .ruma_route(client::get_mutual_rooms_route) - .ruma_route(client::get_room_summary) - .route( - "/_matrix/client/unstable/im.nheko.summary/rooms/:room_id_or_alias/summary", - get(client::get_room_summary_legacy) - ) - .ruma_route(client::well_known_support) - .ruma_route(client::well_known_client) - .route("/_conduwuit/server_version", get(client::conduwuit_server_version)) + .ruma_route(client::get_mutual_rooms_route) + .ruma_route(client::get_room_summary) + .route( + "/_matrix/client/unstable/im.nheko.summary/rooms/:room_id_or_alias/summary", + get(client::get_room_summary_legacy) + ) + .ruma_route(client::well_known_support) + .ruma_route(client::well_known_client) + .route("/_conduwuit/server_version", get(client::conduwuit_server_version)) .route("/_matrix/client/r0/rooms/:room_id/initialSync", get(initial_sync)) .route("/_matrix/client/v3/rooms/:room_id/initialSync", get(initial_sync)) .route("/client/server.json", get(client::syncv3_client_server_json)); @@ -233,7 +241,7 @@ pub fn build(router: Router, server: &Server) -> Router { } async fn initial_sync(_uri: Uri) -> impl IntoResponse { - Error::BadRequest(ErrorKind::GuestAccessForbidden, "Guest access not implemented") + err!(Request(GuestAccessForbidden("Guest access not implemented"))) } async fn federation_disabled() -> impl IntoResponse { err!(Config("allow_federation", "Federation is disabled.")) } diff --git a/src/api/router/mod.rs b/src/api/router/args.rs similarity index 90% rename from src/api/router/mod.rs rename to src/api/router/args.rs index c3e08c5b..b54a6f80 100644 --- a/src/api/router/mod.rs +++ b/src/api/router/args.rs @@ -1,24 +1,18 @@ -mod auth; -mod handler; -mod request; -mod response; - use std::{mem, ops::Deref}; use axum::{async_trait, body::Body, extract::FromRequest}; use bytes::{BufMut, BytesMut}; -use conduit::{debug, debug_warn, trace, warn}; +use conduit::{debug, debug_warn, trace, warn, Error, Result}; use ruma::{ api::{client::error::ErrorKind, IncomingRequest}, CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId, UserId, }; -use self::{auth::Auth, request::Request}; -pub(super) use self::{handler::RouterExt, response::RumaResponse}; -use crate::{service::appservice::RegistrationInfo, services, Error, Result}; +use super::{auth, auth::Auth, request, request::Request}; +use crate::{service::appservice::RegistrationInfo, services}; /// Extractor for Ruma request structs -pub(crate) struct Ruma { +pub(crate) struct Args { /// Request struct body pub(crate) body: T, @@ -44,7 +38,7 @@ pub(crate) struct Ruma { } #[async_trait] -impl FromRequest for Ruma +impl FromRequest for Args where T: IncomingRequest, { @@ -65,7 +59,7 @@ where } } -impl Deref for Ruma { +impl Deref for Args { type Target = T; fn deref(&self) -> &Self::Target { &self.body } diff --git a/src/router/router.rs b/src/router/router.rs index 2f6d5c46..7dfb089b 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -10,7 +10,7 @@ extern crate conduit_api as api; pub(crate) fn build(server: &Arc) -> Router { let state = service::services(); - let router = Router::new() + api::router::build(Router::new(), server) .route("/", get(it_works)) .fallback(not_found) .with_state(state);