update rocket and lock
parent
3c236fb671
commit
15471d9ac4
File diff suppressed because it is too large
Load Diff
|
@ -14,7 +14,8 @@ edition = "2018"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Used to handle requests
|
# Used to handle requests
|
||||||
# TODO: This can become optional as soon as proper configs are supported
|
# TODO: This can become optional as soon as proper configs are supported
|
||||||
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "801e04bd5369eb39e126c75f6d11e1e9597304d8", features = ["tls"] } # Used to handle requests
|
# rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "801e04bd5369eb39e126c75f6d11e1e9597304d8", features = ["tls"] } # Used to handle requests
|
||||||
|
rocket = { version = "0.5.0-rc.1", features = ["tls"] } # Used to handle requests
|
||||||
|
|
||||||
# Used for matrix spec type definitions and helpers
|
# Used for matrix spec type definitions and helpers
|
||||||
ruma = { git = "https://github.com/ruma/ruma", rev = "174555857ef90d49e4b9a672be9e2fe0acdc2687", 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 = "174555857ef90d49e4b9a672be9e2fe0acdc2687", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
|
||||||
|
|
|
@ -21,9 +21,9 @@ use log::error;
|
||||||
use lru_cache::LruCache;
|
use lru_cache::LruCache;
|
||||||
use rocket::{
|
use rocket::{
|
||||||
futures::{channel::mpsc, stream::FuturesUnordered, StreamExt},
|
futures::{channel::mpsc, stream::FuturesUnordered, StreamExt},
|
||||||
outcome::IntoOutcome,
|
outcome::{try_outcome, IntoOutcome},
|
||||||
request::{FromRequest, Request},
|
request::{FromRequest, Request},
|
||||||
try_outcome, State,
|
State,
|
||||||
};
|
};
|
||||||
use ruma::{DeviceId, ServerName, UserId};
|
use ruma::{DeviceId, ServerName, UserId};
|
||||||
use serde::{de::IgnoredAny, Deserialize};
|
use serde::{de::IgnoredAny, Deserialize};
|
||||||
|
@ -608,7 +608,7 @@ impl<'r> FromRequest<'r> for DatabaseGuard {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
async fn from_request(req: &'r Request<'_>) -> rocket::request::Outcome<Self, ()> {
|
async fn from_request(req: &'r Request<'_>) -> rocket::request::Outcome<Self, ()> {
|
||||||
let db = try_outcome!(req.guard::<State<'_, Arc<TokioRwLock<Database>>>>().await);
|
let db = try_outcome!(req.guard::<&State<Arc<TokioRwLock<Database>>>>().await);
|
||||||
|
|
||||||
Ok(DatabaseGuard(Arc::clone(&db).read_owned().await)).or_forward(())
|
Ok(DatabaseGuard(Arc::clone(&db).read_owned().await)).or_forward(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,10 @@ where
|
||||||
{
|
{
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
async fn from_data(request: &'a Request<'_>, data: Data) -> data::Outcome<Self, Self::Error> {
|
async fn from_data(
|
||||||
|
request: &'a Request<'_>,
|
||||||
|
data: Data<'a>,
|
||||||
|
) -> data::Outcome<'a, Self, Self::Error> {
|
||||||
let metadata = T::Incoming::METADATA;
|
let metadata = T::Incoming::METADATA;
|
||||||
let db = request
|
let db = request
|
||||||
.guard::<DatabaseGuard>()
|
.guard::<DatabaseGuard>()
|
||||||
|
@ -102,7 +105,7 @@ where
|
||||||
|
|
||||||
if !db.users.exists(&user_id).unwrap() {
|
if !db.users.exists(&user_id).unwrap() {
|
||||||
// Forbidden
|
// Forbidden
|
||||||
return Failure((Status::raw(580), ()));
|
return Failure((Status::new(580), ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Check if appservice is allowed to be that user
|
// TODO: Check if appservice is allowed to be that user
|
||||||
|
@ -117,7 +120,7 @@ where
|
||||||
if let Some(token) = token {
|
if let Some(token) = token {
|
||||||
match db.users.find_from_token(&token).unwrap() {
|
match db.users.find_from_token(&token).unwrap() {
|
||||||
// Unknown Token
|
// Unknown Token
|
||||||
None => return Failure((Status::raw(581), ())),
|
None => return Failure((Status::new(581), ())),
|
||||||
Some((user_id, device_id)) => (
|
Some((user_id, device_id)) => (
|
||||||
Some(user_id),
|
Some(user_id),
|
||||||
Some(Box::<DeviceId>::from(device_id)),
|
Some(Box::<DeviceId>::from(device_id)),
|
||||||
|
@ -127,7 +130,7 @@ where
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Missing Token
|
// Missing Token
|
||||||
return Failure((Status::raw(582), ()));
|
return Failure((Status::new(582), ()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AuthScheme::ServerSignatures => {
|
AuthScheme::ServerSignatures => {
|
||||||
|
@ -149,7 +152,7 @@ where
|
||||||
warn!("No Authorization header");
|
warn!("No Authorization header");
|
||||||
|
|
||||||
// Forbidden
|
// Forbidden
|
||||||
return Failure((Status::raw(580), ()));
|
return Failure((Status::new(580), ()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -159,7 +162,7 @@ where
|
||||||
warn!("Invalid X-Matrix header origin field: {:?}", x_matrix);
|
warn!("Invalid X-Matrix header origin field: {:?}", x_matrix);
|
||||||
|
|
||||||
// Forbidden
|
// Forbidden
|
||||||
return Failure((Status::raw(580), ()));
|
return Failure((Status::new(580), ()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -172,7 +175,7 @@ where
|
||||||
);
|
);
|
||||||
|
|
||||||
// Forbidden
|
// Forbidden
|
||||||
return Failure((Status::raw(580), ()));
|
return Failure((Status::new(580), ()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -182,7 +185,7 @@ where
|
||||||
warn!("Invalid X-Matrix header key field: {:?}", x_matrix);
|
warn!("Invalid X-Matrix header key field: {:?}", x_matrix);
|
||||||
|
|
||||||
// Forbidden
|
// Forbidden
|
||||||
return Failure((Status::raw(580), ()));
|
return Failure((Status::new(580), ()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -192,7 +195,7 @@ where
|
||||||
warn!("Invalid X-Matrix header sig field: {:?}", x_matrix);
|
warn!("Invalid X-Matrix header sig field: {:?}", x_matrix);
|
||||||
|
|
||||||
// Forbidden
|
// Forbidden
|
||||||
return Failure((Status::raw(580), ()));
|
return Failure((Status::new(580), ()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -243,7 +246,7 @@ where
|
||||||
warn!("Failed to fetch signing keys: {}", e);
|
warn!("Failed to fetch signing keys: {}", e);
|
||||||
|
|
||||||
// Forbidden
|
// Forbidden
|
||||||
return Failure((Status::raw(580), ()));
|
return Failure((Status::new(580), ()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -260,7 +263,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// Forbidden
|
// Forbidden
|
||||||
return Failure((Status::raw(580), ()));
|
return Failure((Status::new(580), ()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,7 +320,7 @@ where
|
||||||
}),
|
}),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("{:?}", e);
|
warn!("{:?}", e);
|
||||||
Failure((Status::raw(583), ()))
|
Failure((Status::new(583), ()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -343,7 +346,7 @@ pub fn response<T: OutgoingResponse>(response: RumaResponse<T>) -> response::Res
|
||||||
let mut response = rocket::response::Response::build();
|
let mut response = rocket::response::Response::build();
|
||||||
|
|
||||||
let status = http_response.status();
|
let status = http_response.status();
|
||||||
response.raw_status(status.into(), "");
|
response.status(Status::new(status.as_u16()));
|
||||||
|
|
||||||
for header in http_response.headers() {
|
for header in http_response.headers() {
|
||||||
response.raw_header(header.0.to_string(), header.1.to_str().unwrap().to_owned());
|
response.raw_header(header.0.to_string(), header.1.to_str().unwrap().to_owned());
|
||||||
|
|
Loading…
Reference in New Issue