From 215a31c513efc4208be5cc7e3fcff280e88b8cf9 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Tue, 7 Apr 2020 13:21:05 +0200 Subject: [PATCH] Add a few dummy endpoints to make riot progress further --- src/main.rs | 68 ++++++++++++++++++++++++++++++++++++++------- src/ruma_wrapper.rs | 7 +++-- 2 files changed, 63 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6b97534..ef4f08a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,8 +16,12 @@ use ruma_client_api::{ r0::{ account::register, alias::get_alias, + filter::create_filter, + keys::get_keys, membership::join_room_by_id, message::create_message_event, + presence::set_presence, + push::get_pushrules_all, room::create_room, session::{get_login_types, login}, state::{create_state_event_for_empty_key, create_state_event_for_key}, @@ -31,10 +35,10 @@ use ruma_wrapper::{MatrixResult, Ruma}; use serde_json::json; use std::{collections::HashMap, convert::TryInto, path::PathBuf}; -const DEVICE_ID_LENGTH: usize = 16; -const SESSION_ID_LENGTH: usize = 16; -const TOKEN_LENGTH: usize = 16; -const GUEST_NAME_LENGTH: usize = 16; +const GUEST_NAME_LENGTH: usize = 10; +const DEVICE_ID_LENGTH: usize = 10; +const SESSION_ID_LENGTH: usize = 256; +const TOKEN_LENGTH: usize = 256; #[get("/_matrix/client/versions")] fn get_supported_versions_route() -> MatrixResult { @@ -49,9 +53,10 @@ fn register_route( data: State, body: Ruma, ) -> MatrixResult { + /* if body.auth.is_none() { return MatrixResult(Err(Error { - kind: ErrorKind::InvalidUsername, + kind: ErrorKind::Unknown, message: json!({ "flows": [ { "stages": [ "m.login.dummy" ] }, @@ -62,7 +67,7 @@ fn register_route( .to_string(), status_code: http::StatusCode::UNAUTHORIZED, })); - } + }*/ // Validate user id let user_id: UserId = match (*format!( @@ -120,7 +125,9 @@ fn register_route( } #[get("/_matrix/client/r0/login", data = "<_body>")] -fn get_login_route(_body: Ruma) -> MatrixResult { +fn get_login_route( + _body: Ruma, +) -> MatrixResult { MatrixResult(Ok(get_login_types::Response { flows: vec![get_login_types::LoginType::Password], })) @@ -147,7 +154,7 @@ fn login_route(data: State, body: Ruma) -> MatrixResult, body: Ruma) -> MatrixResult, body: Ruma) -> MatrixResult MatrixResult { + // TODO + MatrixResult(Ok(get_pushrules_all::Response { + global: HashMap::new(), + })) +} + +#[post("/_matrix/client/r0/user/<_user_id>/filter", data = "")] +fn create_filter_route( + body: Ruma, + _user_id: String, +) -> MatrixResult { + // TODO + MatrixResult(Ok(create_filter::Response { + filter_id: utils::random_string(10), + })) +} + +#[put("/_matrix/client/r0/presence/<_user_id>/status", data = "")] +fn set_presence_route( + body: Ruma, + _user_id: String, +) -> MatrixResult { + // TODO + MatrixResult(Ok(set_presence::Response)) +} + +#[post("/_matrix/client/r0/keys/query", data = "")] +fn get_keys_route(body: Ruma) -> MatrixResult { + // TODO + MatrixResult(Ok(get_keys::Response { + failures: HashMap::new(), + device_keys: HashMap::new(), + })) +} + #[post("/_matrix/client/r0/createRoom", data = "")] fn create_room_route( data: State, @@ -404,6 +448,10 @@ fn main() { register_route, get_login_route, login_route, + get_pushrules_all_route, + create_filter_route, + set_presence_route, + get_keys_route, create_room_route, get_alias_route, join_room_by_id_route, diff --git a/src/ruma_wrapper.rs b/src/ruma_wrapper.rs index a44a53c..e73c4da 100644 --- a/src/ruma_wrapper.rs +++ b/src/ruma_wrapper.rs @@ -63,7 +63,7 @@ where let token = match request .headers() .get_one("Authorization") - .map(|s| s.to_owned()) + .map(|s| s[7..].to_owned()) // Split off "Bearer " .or_else(|| request.get_query_value("access_token").and_then(|r| r.ok())) { // TODO: M_MISSING_TOKEN @@ -95,7 +95,7 @@ where let http_request = http_request.body(body.clone()).unwrap(); log::info!("{:?}", http_request); - match T::Incoming::try_from(http_request) { + match T::Incoming::try_from(dbg!(http_request)) { Ok(t) => Success(Ruma { body: t, user_id, @@ -151,6 +151,9 @@ where .sized_body(Cursor::new(http_response.body().clone())) .await; + let status = http_response.status(); + response.raw_status(status.into(), ""); + for header in http_response.headers() { response .raw_header(header.0.to_string(), header.1.to_str().unwrap().to_owned());